debug: move debug features from misc to subsys/debug

Change-Id: I446be0202325cf3cead7ce3024ca2047e3f7660d
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2016-12-17 13:18:45 -05:00 committed by Anas Nashif
commit 569f0b4105
32 changed files with 25 additions and 26 deletions

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2015-2016 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* @brief Information necessary for debugging
*
* @internal No routine is provided for getting the current exception stack
* frame as the exception handler already has knowledge of the ESF.
*/
#ifndef __DEBUG_INFO_H
#define __DEBUG_INFO_H
#ifdef __cplusplus
extern "C" {
#endif
#include <nanokernel.h>
#ifndef _ASMLANGUAGE
/**
* @brief Get the current interrupt stack frame
*
* @details This routine (only called from an ISR) returns a
* pointer to the current interrupt stack frame.
*
* @return pointer the current interrupt stack frame
*/
extern NANO_ISF *sys_debug_current_isf_get(void);
#endif /* _ASMLANGUAGE */
#ifdef __cplusplus
}
#endif
#endif /* __DEBUG_INFO_H */

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MISC_DEBUG_GDB_SERVER__H_
#define __MISC_DEBUG_GDB_SERVER__H_
#ifdef __cplusplus
extern "C" {
#endif
/* define */
#define GDB_STOP_CHAR 0x3 /* GDB RSP default value */
#define NOT_DEBUGGING 0
#define DEBUGGING 1
#define STOP_RUNNING 2
#define SINGLE_STEP 3
#ifndef _ASMLANGUAGE
enum gdb_error_code {
GDB_ERROR_BP_LIST_FULL = 1, /* Reach max number of Hard&Soft BPs */
GDB_ERROR_INVALID_BP, /* No such BP in breakpoints list */
GDB_ERROR_HW_BP_INVALID_TYPE, /* Unsupported type/len combination */
GDB_ERROR_HW_BP_DBG_REGS_FULL, /* Debug register set full */
GDB_ERROR_HW_BP_NOT_SUP, /* hardware breakpoint not supported */
GDB_ERROR_INVALID_MEM /* trying to access invalid memory */
};
enum gdb_bp_type {
GDB_SOFT_BP, /* software breakpoint */
GDB_HW_INST_BP, /* hardware instruction breakpoint */
GDB_HW_DATA_WRITE_BP, /* write watchpoint */
GDB_HW_DATA_READ_BP, /* read watchpoint */
GDB_HW_DATA_ACCESS_BP, /* access watchpoint */
GDB_UNKNOWN_BP_TYPE = -1 /* unknown breakpoint type */
};
enum gdb_exc_mode {
GDB_EXC_TRACE, /* trace exception */
GDB_EXC_BP, /* breakpoint exception */
GDB_EXC_OTHER, /* other exceptions */
};
enum gdb_signal {
GDB_SIG_NULL = -1,
GDB_SIG_INT = 2,
GDB_SIG_TRAP = 5,
GDB_SIG_FPE = 8,
GDB_SIG_SIGSEGV = 11,
GDB_SIG_STOP = 17
};
extern volatile int gdb_debug_status;
extern void gdb_system_stop_here(void *regs);
extern void gdb_handler(enum gdb_exc_mode mode, void *esf, int signal);
#endif /* _ASMLANGUAGE */
#ifdef __cplusplus
}
#endif
#endif /* __MISC_DEBUG_GDB_SERVER__H_*/

164
include/debug/mem_safe.h Normal file
View file

@ -0,0 +1,164 @@
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _debug__mem_safe__h_
#define _debug__mem_safe__h_
#include <errno.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file
* @brief Safe memory access routines
*
* This module provides functions for safely writing to and reading from
* memory, as well as probing if a memory address is accessible. For the
* latter, permissions can be specified (read/write).
*/
#define SYS_MEM_SAFE_READ 0
#define SYS_MEM_SAFE_WRITE 1
/**
* @brief verify memory at an address is accessible
*
* Probe memory for read or write access by specifying the @a perm, either
* SYS_MEM_SAFE_WRITE or SYS_MEM_SAFE_READ. A size @a num_bytes specifying
* the number of bytes to access must also be specified: for a 32-bit system,
* it can only take the values 1,2 or 4 (8/16/32 bits). Both @a p and @a buf
* must be naturally aligned to @a num_bytes.
*
* On a read, the value read from the memory location @a p is returned through
* @a buf; on a write, the value contained in @a buf is written to memory at
* memory location @a p.
*
* @param p The pointer (address) to the location to probe
* @param perm Either SYS_MEM_PROBE_READ or SYS_MEM_PROBE_WRITE
* @param num_bytes The number of bytes to probe, must be either 1, 2 or 4
* @param buf On reads, will contain the value read; on writes, contains the
* value to write
*
* @retval 0 OK
* @retval -EINVAL If an invalid parameter is passed
* @retval -EFAULT If the address is not accessible.
*/
extern int _mem_probe(void *p, int perm, size_t num_bytes, void *buf);
/**
* @brief safely read memory
*
* @details Read @a num_bytes bytes at address @a src from buffer pointed to
* by @a buf. The @a width parameter specifies bus width of each memory access
* in bytes. If @a width is 0 a target optimal access width is used. All other
* values of access width are target dependent and optional. When @a width is
* non-zero, the both @a num_bytes and @a src must be a multiple of @a width.
*
* @param src The address to read from
* @param buf The destination buffer to receive the data read
* @param num_bytes The number of bytes to read
* @param width The access width
*
* @retval 0 OK
* @retval -EFAULT If there was an error reading memory
* @retval -EINVAL If access width, num_bytes and addresses are not compatible.
*/
extern int _mem_safe_read(void *src, char *buf, size_t num_bytes,
int width);
/**
* @brief safely write memory
*
* @details Write @a num_bytes bytes to address @a dest from buffer pointed to
* by @a buf. The @a width parameter specifies bus width of each memory access
* in bytes. If @a width is 0 a target optimal access width is used. All other
* values of access width are target dependent and optional. When @a width is
* non-zero, the both @a num_bytes and @a dest must be a multiple of @a width.
*
* @param dest The address to write to
* @param buf The source buffer to write in memory
* @param num_bytes The number of bytes to write
* @param width The access width
*
* @retval 0 OK
* @retval -EFAULT If there was an error writing memory
* @retval -EINVAL If access width, num_bytes and addresses are not compatible.
*/
extern int _mem_safe_write(void *dest, char *buf, size_t num_bytes,
int width);
/**
* @brief write to text section
*
* @details Write @a num_bytes bytes to address @a dest from buffer pointed to
* by @a buf.
*
* @param dest The address to write to
* @param buf The source buffer to write in memory
* @param num_bytes The number of bytes to write
*
* @retval 0 Success
* @retval -EFAULT If there was an error writing memory
*/
extern int _mem_safe_write_to_text_section(void *dest, char *buf,
size_t num_bytes);
/**
* @brief add to the table of valid regions
*
* @details Add a new region that is considered valid to read from or both
* read from and write to. The region starts at @a addr and its size is @a
* num_bytes. The read/write permissions are specified via @a perm and can
* take the values either SYS_MEM_SAFE_READ or SYS_MEM_SAFE_WRITE.
*
* The table size is specified via the CONFIG_MEM_SAFE_NUM_REGIONS kconfig
* option.
*
* If the implementation of safe memory access chosen does not need this API,
* it is still available, but results in a no-op and always returns success
* (0).
*
* @param addr The address to write to
* @param num_bytes The size of the region in bytes
* @param perm The access permissions, either SYS_MEM_SAFE_WRITE or
* SYS_MEM_SAFE_READ
*
* @retval 0 OK
* @retval -ENOMEM If there there is no space left in the table of regions
* @retval -EINVAL If passing invalid permissions
*/
#ifdef CONFIG_MEM_SAFE_CHECK_BOUNDARIES
extern int _mem_safe_region_add(void *addr, size_t num_bytes, int perm);
#else
static inline int _mem_safe_region_add(void *addr, size_t num_bytes,
int perm)
{
return 0;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* _debug__mem_safe__h_ */

View file

@ -0,0 +1,99 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* @brief APIs used when examining the objects in a debug tracing list.
*/
#ifndef _OBJECT_TRACING_H_
#define _OBJECT_TRACING_H_
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
#include <kernel.h>
extern struct k_timer *_trace_list_k_timer;
extern struct k_mem_slab *_trace_list_k_mem_slab;
extern struct k_mem_pool *_trace_list_k_mem_pool;
extern struct k_sem *_trace_list_k_sem;
extern struct k_mutex *_trace_list_k_mutex;
extern struct k_alert *_trace_list_k_alert;
extern struct k_fifo *_trace_list_k_fifo;
extern struct k_lifo *_trace_list_k_lifo;
extern struct k_stack *_trace_list_k_stack;
extern struct k_msgq *_trace_list_k_msgq;
extern struct k_mbox *_trace_list_k_mbox;
extern struct k_pipe *_trace_list_k_pipe;
extern struct ring_buf *_trace_list_sys_ring_buf;
/**
* @def SYS_TRACING_HEAD
*
* @brief Head element of a trace list.
*
* @details Access the head element of a given trace list.
*
* @param type Data type of the trace list to get the head from.
* @param name Name of the trace list to get the head from.
*/
#define SYS_TRACING_HEAD(type, name) ((type *) _CONCAT(_trace_list_, name))
/**
* @def SYS_TRACING_NEXT
*
* @brief Gets a node's next element.
*
* @details Given a node in a trace list, gets the next element
* in the list.
*
* @param type Data type of the trace list
* @param name Name of the trace list to get the head from.
* @param obj Object to get next element from.
*/
#define SYS_TRACING_NEXT(type, name, obj) (((type *)obj)->__next)
#endif /*CONFIG_DEBUG_TRACING_KERNEL_OBJECTS*/
#ifdef CONFIG_THREAD_MONITOR
#include <kernel_structs.h>
/**
* @def SYS_THREAD_MONITOR_HEAD
*
* @brief Head element of the thread monitor list.
*
* @details Access the head element of the thread monitor list.
*
*/
#define SYS_THREAD_MONITOR_HEAD ((struct k_thread *)(_kernel.threads))
/**
* @def SYS_THREAD_MONITOR_NEXT
*
* @brief Gets a thread node's next element.
*
* @details Given a node in a thread monitor list, gets the next
* element in the list.
*
* @param obj Object to get the next element from.
*/
#define SYS_THREAD_MONITOR_NEXT(obj) (((struct k_thread *)obj)->next_thread)
#endif /*CONFIG_THREAD_MONITOR*/
#endif /*_OBJECT_TRACING_H_*/

View file

@ -0,0 +1,121 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* @brief APIs used to add or remove an object in a debug tracing list.
*/
#ifndef _OBJECT_TRACING_COMMON_H_
#define _OBJECT_TRACING_COMMON_H_
#ifndef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
#define SYS_TRACING_OBJ_INIT(name, obj) do { } while ((0))
#define SYS_TRACING_OBJ_INIT_DLL(name, obj) do { } while ((0))
#define SYS_TRACING_OBJ_REMOVE_DLL(name, obj) do { } while ((0))
#else
/**
* @def SYS_TRACING_OBJ_INIT
*
* @brief Adds a new object into the trace list
*
* @details The object is added for tracing into
* a trace list. This is usually called at the
* moment of object initialization.
*
* @param name Name of the trace list.
* @param obj Object to be added in the trace list.
*/
#define SYS_TRACING_OBJ_INIT(name, obj) \
do { \
unsigned int key; \
\
key = irq_lock(); \
(obj)->__next = _trace_list_##name;\
_trace_list_##name = obj; \
irq_unlock(key); \
} \
while (0)
/**
* @def SYS_TRACING_OBJ_INIT_DLL
*
* @brief Adds a new object into the trace list
* as a double linked list.
*
* @details The object is added for tracing into
* a trace list. This is usually called at the
* moment of object initialization. This list is
* used for objects that can be removed from the
* tracing list dynamically.
*
* @param name Name of the trace list.
* @param obj Object to be added in the trace list.
*/
#define SYS_TRACING_OBJ_INIT_DLL(name, obj) \
do { \
unsigned int key; \
\
key = irq_lock(); \
if (_trace_list_##name) { \
_trace_list_##name->__prev = (obj);\
} \
(obj)->__next = _trace_list_##name;\
(obj)->__prev = NULL; \
_trace_list_##name = obj; \
irq_unlock(key); \
} \
while (0)
/**
* @def SYS_TRACING_OBJ_REMOVE_DLL
*
* @brief Removes an object from a double linked
* trace list.
*
* @details The object is remove from the trace list.
* It needs to be used with DEBUG_TRACING_OBJ_INIT_DLL
* as a pair.
*
* @param name Name of the trace list.
* @param obj Object to be removed from the trace list.
*/
#define SYS_TRACING_OBJ_REMOVE_DLL(name, obj) \
do { \
unsigned int key; \
\
key = irq_lock(); \
if (obj->__next) { \
obj->__next->__prev = (obj)->__prev;\
} \
if (obj->__prev) { \
obj->__prev->__next = (obj)->__next;\
} else { \
_trace_list_##name = (obj)->__next;\
} \
irq_unlock(key); \
} \
while (0)
struct ring_buf;
struct ring_buf *_trace_list_sys_ring_buf;
#endif /*CONFIG_DEBUG_TRACING_KERNEL_OBJECTS*/
#endif /*_OBJECT_TRACING_COMMON_H_*/