From d2465d62683773ae37732cbd547a4501e3a5cdf3 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Thu, 11 Mar 2021 19:51:35 +0100 Subject: [PATCH] debug: Move away from openocd and make it generic The exported structures that were originally introduced for OpenOCD have since then been reused for other debugger plugins, including PyOCD and Segger J-Link. Rename the Kconfig option and the implementation from openocd to debug thread info, so that it reflects the fact that this is no longer specifically tied to OpenOCD. Signed-off-by: Carles Cufi --- doc/application/index.rst | 2 +- doc/releases/release-notes-2.6.rst | 3 + samples/subsys/tracing/sample.yaml | 2 +- scripts/kconfig/hardened.csv | 4 +- subsys/debug/CMakeLists.txt | 10 ++- subsys/debug/Kconfig | 14 ++-- subsys/debug/openocd.c | 114 --------------------------- subsys/debug/thread_info.c | 122 +++++++++++++++++++++++++++++ 8 files changed, 146 insertions(+), 125 deletions(-) delete mode 100644 subsys/debug/openocd.c create mode 100644 subsys/debug/thread_info.c diff --git a/doc/application/index.rst b/doc/application/index.rst index df4bed9441..ed35ead376 100644 --- a/doc/application/index.rst +++ b/doc/application/index.rst @@ -1084,7 +1084,7 @@ RTOS Awareness Support for Zephyr RTOS awareness is implemented in `pyOCD v0.11.0`_ and later. It is compatible with GDB PyOCD Debugging in Eclipse, but you must enable -CONFIG_OPENOCD_SUPPORT=y in your application. +CONFIG_DEBUG_THREAD_INFO=y in your application. .. _cmake-details: diff --git a/doc/releases/release-notes-2.6.rst b/doc/releases/release-notes-2.6.rst index 3669bafb97..9282080cba 100644 --- a/doc/releases/release-notes-2.6.rst +++ b/doc/releases/release-notes-2.6.rst @@ -54,6 +54,9 @@ Deprecated in this release * USB HID specific macros in ```` are deprecated in favor of new common HID macros defined in ````. +* The ``CONFIG_OPENOCD_SUPPORT`` Kconfig option has been deprecated in favor + of ``CONFIG_DEBUG_THREAD_INFO``. + ========================== Removed APIs in this release diff --git a/samples/subsys/tracing/sample.yaml b/samples/subsys/tracing/sample.yaml index fccefe3f68..ef92547f86 100644 --- a/samples/subsys/tracing/sample.yaml +++ b/samples/subsys/tracing/sample.yaml @@ -18,7 +18,7 @@ tests: tracing.osawareness.openocd: extra_configs: - CONFIG_MP_NUM_CPUS=1 - - CONFIG_OPENOCD_SUPPORT=y + - CONFIG_DEBUG_THREAD_INFO=y - CONFIG_SMP=n arch_exclude: posix xtensa platform_exclude: qemu_x86_64 diff --git a/scripts/kconfig/hardened.csv b/scripts/kconfig/hardened.csv index 3c2b250ec3..f62cae137a 100644 --- a/scripts/kconfig/hardened.csv +++ b/scripts/kconfig/hardened.csv @@ -20,7 +20,7 @@ ASSERT,n OBJECT_TRACING,n OVERRIDE_FRAME_POINTER_DEFAULT,y DEBUG_INFO,n -OPENOCD_SUPPORT,n +DEBUG_THREAD_INFO,n TRACING_CPU_STATS,n TRACING_CTF,n USE_SEGGER_RTT,n @@ -76,7 +76,7 @@ NET_SOCKETS_ENABLE_DTLS,n,experimental NET_SOCKETS_NET_MGMT,n,experimental NET_SOCKETS_OFFLOAD,n,experimental NET_SOCKETS_SOCKOPT_TLS,n,experimental -OPENOCD_SUPPORT,n,experimental +DEBUG_THREAD_INFO,n,experimental PERFORMANCE_METRICS,n,experimental SHELL_TELNET_SUPPORT_COMMAND,n,experimental SPI_SLAVE,n,experimental diff --git a/subsys/debug/CMakeLists.txt b/subsys/debug/CMakeLists.txt index 6e198cce9b..4d2ed6c747 100644 --- a/subsys/debug/CMakeLists.txt +++ b/subsys/debug/CMakeLists.txt @@ -1,8 +1,14 @@ # SPDX-License-Identifier: Apache-2.0 +if(CONFIG_OPENOCD_SUPPORT) + message(WARNING "CONFIG_OPENOCD_SUPPORT is deprecated + Please use DEBUG_THREAD_INFO instead." +) +endif() + zephyr_sources_ifdef( - CONFIG_OPENOCD_SUPPORT - openocd.c + CONFIG_DEBUG_THREAD_INFO + thread_info.c ) zephyr_sources_ifdef( diff --git a/subsys/debug/Kconfig b/subsys/debug/Kconfig index 99f2b38110..d538b44ed9 100644 --- a/subsys/debug/Kconfig +++ b/subsys/debug/Kconfig @@ -332,16 +332,20 @@ config EXCEPTION_STACK_TRACE # # Miscellaneous debugging options # - config OPENOCD_SUPPORT - bool "OpenOCD support [EXPERIMENTAL]" + bool "OpenOCD support (DEPRECATED)" + select DEBUG_THREAD_INFO + help + This is deprecated, please use DEBUG_THREAD_INFO instead. + +config DEBUG_THREAD_INFO + bool "Thread awareness support" depends on !SMP select THREAD_MONITOR select THREAD_NAME help - This option exports an array of offsets to kernel structs, used by - OpenOCD to determine the state of running threads. (This option - selects CONFIG_THREAD_MONITOR, so all of its caveats are implied.) + This option exports an array of offsets to kernel structs to allow + for debugger RTOS plugins to determine the state of running threads. rsource "coredump/Kconfig" endmenu diff --git a/subsys/debug/openocd.c b/subsys/debug/openocd.c deleted file mode 100644 index 87cc0996c7..0000000000 --- a/subsys/debug/openocd.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2017 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#define OPENOCD_UNIMPLEMENTED 0xffffffff - -#if defined(CONFIG_OPENOCD_SUPPORT) && defined(CONFIG_THREAD_MONITOR) -enum { - OPENOCD_OFFSET_VERSION, - OPENOCD_OFFSET_K_CURR_THREAD, - OPENOCD_OFFSET_K_THREADS, - OPENOCD_OFFSET_T_ENTRY, - OPENOCD_OFFSET_T_NEXT_THREAD, - OPENOCD_OFFSET_T_STATE, - OPENOCD_OFFSET_T_USER_OPTIONS, - OPENOCD_OFFSET_T_PRIO, - OPENOCD_OFFSET_T_STACK_PTR, - OPENOCD_OFFSET_T_NAME, - OPENOCD_OFFSET_T_ARCH, - OPENOCD_OFFSET_T_PREEMPT_FLOAT, - OPENOCD_OFFSET_T_COOP_FLOAT, -}; - -#if CONFIG_MP_NUM_CPUS > 1 -#error "This code doesn't work properly with multiple CPUs enabled" -#endif - -/* Forward-compatibility notes: 1) Only append items to this table; otherwise - * OpenOCD versions that expect less items will read garbage values. - * 2) Avoid incompatible changes that affect the interpretation of existing - * items. But if you have to do them, increment OPENOCD_OFFSET_VERSION - * and submit a patch for OpenOCD to deal with both the old and new scheme. - * Only version 1 is backward compatible to version 0. - */ -__attribute__((used, section(".openocd_dbg"))) -size_t _kernel_openocd_offsets[] = { - /* Version 0 starts */ - [OPENOCD_OFFSET_VERSION] = 1, - [OPENOCD_OFFSET_K_CURR_THREAD] = offsetof(struct _cpu, current), - [OPENOCD_OFFSET_K_THREADS] = offsetof(struct z_kernel, threads), - [OPENOCD_OFFSET_T_ENTRY] = offsetof(struct k_thread, entry), - [OPENOCD_OFFSET_T_NEXT_THREAD] = offsetof(struct k_thread, next_thread), - [OPENOCD_OFFSET_T_STATE] = offsetof(struct _thread_base, thread_state), - [OPENOCD_OFFSET_T_USER_OPTIONS] = offsetof(struct _thread_base, - user_options), - [OPENOCD_OFFSET_T_PRIO] = offsetof(struct _thread_base, prio), -#if defined(CONFIG_ARM64) - [OPENOCD_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, - callee_saved.sp), -#elif defined(CONFIG_ARM) - [OPENOCD_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, - callee_saved.psp), -#elif defined(CONFIG_ARC) - [OPENOCD_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, - callee_saved.sp), -#elif defined(CONFIG_X86) -#if defined(CONFIG_X86_64) - [OPENOCD_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, - callee_saved.rsp), -#else - [OPENOCD_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, - callee_saved.esp), -#endif -#elif defined(CONFIG_NIOS2) - [OPENOCD_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, - callee_saved.sp), -#elif defined(CONFIG_RISCV) - [OPENOCD_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, - callee_saved.sp), -#elif defined(CONFIG_SPARC) - [OPENOCD_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, - callee_saved.o6), -#else - /* Use a special value so that OpenOCD knows that obtaining the stack - * pointer is not possible on this particular architecture. - */ -#warning Please define OPENOCD_OFFSET_T_STACK_PTR for this architecture - [OPENOCD_OFFSET_T_STACK_PTR] = OPENOCD_UNIMPLEMENTED, -#endif - /* Version 0 ends */ - - [OPENOCD_OFFSET_T_NAME] = offsetof(struct k_thread, name), - [OPENOCD_OFFSET_T_ARCH] = offsetof(struct k_thread, arch), -#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING) && defined(CONFIG_ARM) - [OPENOCD_OFFSET_T_PREEMPT_FLOAT] = offsetof(struct _thread_arch, - preempt_float), - [OPENOCD_OFFSET_T_COOP_FLOAT] = OPENOCD_UNIMPLEMENTED, -#elif defined(CONFIG_FPU) && defined(CONFIG_X86) -#if defined(CONFIG_X86_64) - [OPENOCD_OFFSET_T_PREEMPT_FLOAT] = offsetof(struct _thread_arch, sse), -#else - [OPENOCD_OFFSET_T_PREEMPT_FLOAT] = offsetof(struct _thread_arch, - preempFloatReg), -#endif - [OPENOCD_OFFSET_T_COOP_FLOAT] = OPENOCD_UNIMPLEMENTED, -#else - [OPENOCD_OFFSET_T_PREEMPT_FLOAT] = OPENOCD_UNIMPLEMENTED, - [OPENOCD_OFFSET_T_COOP_FLOAT] = OPENOCD_UNIMPLEMENTED, -#endif - /* Version is still 1, but existence of following elements must be - * checked with _kernel_openocd_num_offsets. - */ -}; - -__attribute__((used, section(".openocd_dbg"))) -size_t _kernel_openocd_num_offsets = ARRAY_SIZE(_kernel_openocd_offsets); - -__attribute__((used, section(".openocd_dbg"))) -uint8_t _kernel_openocd_size_t_size = (uint8_t)sizeof(size_t); -#endif diff --git a/subsys/debug/thread_info.c b/subsys/debug/thread_info.c new file mode 100644 index 0000000000..ed87a64dac --- /dev/null +++ b/subsys/debug/thread_info.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2017 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#define THREAD_INFO_UNIMPLEMENTED 0xffffffff + +enum { + THREAD_INFO_OFFSET_VERSION, + THREAD_INFO_OFFSET_K_CURR_THREAD, + THREAD_INFO_OFFSET_K_THREADS, + THREAD_INFO_OFFSET_T_ENTRY, + THREAD_INFO_OFFSET_T_NEXT_THREAD, + THREAD_INFO_OFFSET_T_STATE, + THREAD_INFO_OFFSET_T_USER_OPTIONS, + THREAD_INFO_OFFSET_T_PRIO, + THREAD_INFO_OFFSET_T_STACK_PTR, + THREAD_INFO_OFFSET_T_NAME, + THREAD_INFO_OFFSET_T_ARCH, + THREAD_INFO_OFFSET_T_PREEMPT_FLOAT, + THREAD_INFO_OFFSET_T_COOP_FLOAT, +}; + +#if CONFIG_MP_NUM_CPUS > 1 +#error "This code doesn't work properly with multiple CPUs enabled" +#endif + +/* Forward-compatibility notes: 1) Only append items to this table; otherwise + * debugger plugin versions that expect fewer items will read garbage values. + * 2) Avoid incompatible changes that affect the interpretation of existing + * items. But if you have to do them, increment THREAD_INFO_OFFSET_VERSION + * and submit a patch for debugger plugins to deal with both the old and new + * scheme. + * Only version 1 is backward compatible to version 0. + */ +__attribute__((used, section(".openocd_dbg"))) +size_t _kernel_thread_info_offsets[] = { + /* Version 0 starts */ + [THREAD_INFO_OFFSET_VERSION] = 1, + [THREAD_INFO_OFFSET_K_CURR_THREAD] = offsetof(struct _cpu, current), + [THREAD_INFO_OFFSET_K_THREADS] = offsetof(struct z_kernel, threads), + [THREAD_INFO_OFFSET_T_ENTRY] = offsetof(struct k_thread, entry), + [THREAD_INFO_OFFSET_T_NEXT_THREAD] = offsetof(struct k_thread, + next_thread), + [THREAD_INFO_OFFSET_T_STATE] = offsetof(struct _thread_base, + thread_state), + [THREAD_INFO_OFFSET_T_USER_OPTIONS] = offsetof(struct _thread_base, + user_options), + [THREAD_INFO_OFFSET_T_PRIO] = offsetof(struct _thread_base, prio), +#if defined(CONFIG_ARM64) + [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, + callee_saved.sp), +#elif defined(CONFIG_ARM) + [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, + callee_saved.psp), +#elif defined(CONFIG_ARC) + [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, + callee_saved.sp), +#elif defined(CONFIG_X86) +#if defined(CONFIG_X86_64) + [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, + callee_saved.rsp), +#else + [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, + callee_saved.esp), +#endif +#elif defined(CONFIG_NIOS2) + [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, + callee_saved.sp), +#elif defined(CONFIG_RISCV) + [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, + callee_saved.sp), +#elif defined(CONFIG_SPARC) + [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread, + callee_saved.o6), +#else + /* Use a special value so that OpenOCD knows that obtaining the stack + * pointer is not possible on this particular architecture. + */ +#warning Please define THREAD_INFO_OFFSET_T_STACK_PTR for this architecture + [THREAD_INFO_OFFSET_T_STACK_PTR] = THREAD_INFO_UNIMPLEMENTED, +#endif + /* Version 0 ends */ + + [THREAD_INFO_OFFSET_T_NAME] = offsetof(struct k_thread, name), + [THREAD_INFO_OFFSET_T_ARCH] = offsetof(struct k_thread, arch), +#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING) && defined(CONFIG_ARM) + [THREAD_INFO_OFFSET_T_PREEMPT_FLOAT] = offsetof(struct _thread_arch, + preempt_float), + [THREAD_INFO_OFFSET_T_COOP_FLOAT] = THREAD_INFO_UNIMPLEMENTED, +#elif defined(CONFIG_FPU) && defined(CONFIG_X86) +#if defined(CONFIG_X86_64) + [THREAD_INFO_OFFSET_T_PREEMPT_FLOAT] = offsetof(struct _thread_arch, + sse), +#else + [THREAD_INFO_OFFSET_T_PREEMPT_FLOAT] = offsetof(struct _thread_arch, + preempFloatReg), +#endif + [THREAD_INFO_OFFSET_T_COOP_FLOAT] = THREAD_INFO_UNIMPLEMENTED, +#else + [THREAD_INFO_OFFSET_T_PREEMPT_FLOAT] = THREAD_INFO_UNIMPLEMENTED, + [THREAD_INFO_OFFSET_T_COOP_FLOAT] = THREAD_INFO_UNIMPLEMENTED, +#endif + /* Version is still 1, but existence of following elements must be + * checked with _kernel_thread_info_num_offsets. + */ +}; +extern size_t __attribute__((alias("_kernel_thread_info_offsets"))) + _kernel_openocd_offsets; + +__attribute__((used, section(".openocd_dbg"))) +size_t _kernel_thread_info_num_offsets = ARRAY_SIZE(_kernel_thread_info_offsets); +extern size_t __attribute__((alias("_kernel_thread_info_num_offsets"))) + _kernel_openocd_num_offsets; + +__attribute__((used, section(".openocd_dbg"))) +uint8_t _kernel_thread_info_size_t_size = (uint8_t)sizeof(size_t); +extern uint8_t __attribute__((alias("_kernel_thread_info_size_t_size"))) + _kernel_openocd_size_t_size;