Commit graph

278 commits

Author SHA1 Message Date
Anas Nashif
bd8597c9d7 x86: rename DEBUG_INFO to X86_DEBUG_INFO
This is an X86 specific option and should not appear as generic debug
option.

Fixes zephyrproject-rtos/zephyr#52929

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-06-20 14:43:42 -05:00
Daniel Leung
3fbd7dfb75 debug: gdbstub: add arch_gdb_post_memory_write()
This adds an architecture-specific post processing after memory
writes. This introduction is due to GDB's behavior regarding
breakpoints in code. GDB may choose to write break instructions
instead of using hardware breakpoints to interrupt code
execution (e.g. for manual breakpoint or stepping through code).
There is no separate GDB packet type for this. So we need to
make an assumption that a memory write may be to setup break
instructions. Different architectures may have their own unique
ways of dealing with instruction cache in this situation. So we
defer to the architecture code to handle this.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-06-17 16:27:27 -05:00
Guðni Már Gilbert
f32223aac5 debug: ASSERT_VERBOSE depends on PRINTK
When both PRINTK and ASSERT are disabled, the firmware image will still
contain a symbol for assert_print function which increases the memory
footprint by 14 bytes. In this case the function doesn't do anything and
so these 14 bytes are not useful.

This change also reduces the memory footprint elsewhere such as in the
bluetooth subsystem which implements BT_ASSERT_VERBOSE. Now it will be
nop. On nRF52832 this is on the order of 300 - 400 bytes when configured
for peripheral only (just as an example).

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2025-05-29 15:16:41 +01:00
Pieter De Gendt
b029d792c6 debug: coredump: coredump_backend_flash: Update checksum only on success
If the flash stream API fails to write a buffer, exclude it from the
calculated checksum.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-05-29 12:05:42 +02:00
Pieter De Gendt
125389ea32 debug: coredump: coredump_backend_flash: Keep error in context on flush
Do not override the last known value in backend_ctx.error with the result
of flushing.
Any previous error would be cleared and the coredump would appear to have
succeeded.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-05-29 12:05:42 +02:00
Anas Nashif
5fe84d5b69 arch: nios2: remove arch
Remove architecture and dependencies.
Remove altera HAL supporting nios2

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-15 20:01:05 -04:00
Anas Nashif
1938403854 debug: define thread_info offset for RX
Handling for RX architecture.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-14 14:16:03 +02:00
Damian Krolik
222e0fcd06 debug: coredump: support dumping stack top only
Add Kconfig option to dump only a portion of stack from the
current stack pointer to the stack end. This is enough to
let gdb reconstruct the stack trace and can significantly
reduce the dump size. This is crucial if the core dump needs
to be sent over radio.

Additionally, add another option to set the limit for the
dumped stack portion.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2025-05-12 19:19:25 +02:00
Keith Packard
2d64237f44 cmake: Enable undefined behavior sanitizer on all targets
GCC and Clang support the undefined behavior sanitizer in any
configuration, the only restriction is that if you want to get nice
messages printed, then you need the ubsan library routines which are only
present for posix architecture or when using picolibc.

This patch adds three new compiler properties:

 * sanitizer_undefined. Enables the undefined behavior sanitizer.
 * sanitizer_undefined_library. Calls ubsan library routines on fault.
 * sanitizer_undefined_trap. Invokes __builtin_trap() on fault.

Overhead for using the trapping sanitizer is fairly low and should be
considered for use in CI once all of the undefined behavior faults in
Zephyr are fixed.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-05-02 01:16:18 +02:00
Krzysztof Chruściński
2ccc3ce6aa debug: cpu_load: Add missing static keyword
Local variable for counter device is missing static keyword.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-04-16 14:53:30 +02:00
Krzysztof Chruściński
73d19acce7 debug: cpu_load: Add configurable log level
Add Kconfig for configuring cpu_load log level.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-04-14 13:06:06 +02:00
Anas Nashif
7c68855053 debug: thread_analyzer: move thread analyzer to own folder
Move to own directory to prepare for new related code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-04-04 07:42:20 +02:00
Cla Mattia Galliard
f3a3ad308c thread_analyzer: Allow to override the auto-analysis thread priority
By default the thread priority is still the lowest application thread
priority. Allow the priority to be increase by specifying both, the
`override` option as well as the desired `priority`. This pattern was taken
from the shell thread.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-04-01 11:59:39 +02:00
Tomasz Bursztyka
6ad72847e9 coredump: Add an in-memory backend
Only meant to be used on platforms that would not wipe the RAM on reboot.
This won't work if the platform is halted and restarted as RAM is
volatile, obviously. A relevant fatal error handler needs to be provided
to reboot.

Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
2025-03-29 07:44:11 -04:00
Tomasz Bursztyka
9bab18d5c8 coredump: Have a dedicated log module for coredump
To enable/disable any coredump logging while debugging the kernel.

Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
2025-03-29 07:44:11 -04:00
Tomasz Bursztyka
13abd7fe73 coredump: Generalize the shell module
This might come in handy for other coredump backends too, not only flash
one. Obviously: changing the logic to use the coredump generic API instead
of the flash backend's internal functions.

Adding a better output, following how the coredump is actually created:
parsing and printing headers, and their respective content.

Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
2025-03-29 07:44:11 -04:00
Krzysztof Chruściński
0b866648e1 debug: cpu_load: Fix CPU_LOAD_USE_COUNTER config
dt_chosen_enabled argument was incorrect and it was always returning
n so option could not be used.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-03-28 21:52:30 +01:00
Krzysztof Chruściński
4026daa42e arch: riscv: Add support for CPU load measuring
Add sys_trace_idle_exit to RISCV cpu_idle functions and allow
enabling CPU_LOAD module for RISCV and disable it for SMP.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-03-20 17:14:52 +01:00
Krzysztof Chruściński
c7d7aac2bd debug: Add cpu_load module
Add module which can measure CPU idle time. Idle time is measured in
the pre/post CPU idle hooks but they are not provided by this module.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-03-12 14:03:48 +00:00
Tom Hughes
4aefbbe3a9 debug: gdbstub: Re-enable warning
The warning no longer seems to be needed. CI passes without it.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-21 04:46:12 +01:00
Pieter De Gendt
4fb6ce39df drivers: coredump: Place API into iterable section
Add wrapper DEVICE_API macro to all coredump_driver_api instances.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-12-03 02:36:38 +01:00
Ryan McClelland
952daca695 debug: symtab: fix ignored type qualifiers on func return type
const is ignored on the function return type. A warning is reported with
-Wignored-qualifers. Remove the ignored const.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2024-11-06 09:52:36 -08:00
Krzysztof Chruściński
ddf753cdac debug: mipi_stp_decoder: Avoid potential 64bit unaligned access
Decoder was casting uint8_t pointers to uint64_t pointers which could
result in double word instruction which does not support unaligned
access on Cortex-M. Issue was revealed when -O3 optimization was
used instead of -Os. In size optimized version, compiler was
using word load and store instructions which support unaligned
access and issue was not visible.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-10-09 13:45:04 +02:00
Daniel Leung
4f52860fe0 debug: coredump: dump privileged stack
This adds the bits to call into architecture code to dump
the privileged stack for user threads.

The weak implementation is simply there as a stub until
all architectures have implemented the associated function.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-09-21 11:29:39 +02:00
Pisit Sawangvonganan
ead0dfc889 style: subsys: comply with MISRA C:2012 Rule 15.6
Add missing braces to comply with MISRA C:2012 Rule 15.6 and
also following Zephyr's style guideline.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-09-11 07:40:35 -04:00
Yong Cong Sin
ff2cbf9445 debug: symtab: add shell command
Implement shell commands to access the symbol table.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-09-10 11:43:55 +02:00
Krzysztof Chruściński
fc162f74c0 debug: mipi_stp_decoder: Align naming to 2.4 standard
Align naming to STP v2.4. Changing Master to Major.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-09-06 11:31:27 -04:00
Daniel Leung
d26b7d4ed1 debug: thread_analyzer: display privileged stack usage
This adds the bits to display privileged stack usage for
architectures that support obtaining this information.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-08-28 06:50:30 -04:00
Daniel Leung
aa65842e95 debug: thread_analyzer: align output
The per-thread output after the first stack usage line is not
aligned which makes it harder to decipher the content.
So align them for easier reading.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-08-28 06:50:30 -04:00
Yong Cong Sin
074931057c subsys/debug: remove CONFIG_EXCEPTION_STACK_TRACE_SYMTAB
Having `CONFIG_EXCEPTION_STACK_TRACE_SYMTAB` to select the
`CONFIG_SYMTAB` or to explicitly not print the symbol name
during exception stack unwind seems unnecessary, as the extra
code to print the symbol name is negligible when compared with
the symbol table, so just remove it.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-26 14:44:53 -04:00
Yong Cong Sin
ab676fdb86 arch: arm64: implement arch_stack_walk()
Currently it supports `esf` based unwinding only.

Then, update the exception stack unwinding to use
`arch_stack_walk()`, and update the Kconfigs & testcase
accordingly.

Also, `EXCEPTION_STACK_TRACE_MAX_FRAMES` is unused and
made redundant after this change, so remove it.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-26 14:44:53 -04:00
Yong Cong Sin
06a8c35316 arch: x86: implement arch_stack_walk()
Currently it supports `esf` based unwinding only.

Then, update the exception stack unwinding to use
`arch_stack_walk()`, and update the Kconfigs & testcase
accordingly.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-26 14:44:53 -04:00
Yong Cong Sin
6fae891c7e arch: reorg the dependencies around (exception) stack trace
This commit introduces a new ARCH_STACKWALK Kconfig which
determines if the `arch_stack_walk()` is available should the
arch supports it.

Starting from RISCV, this will be able to converge the exception
stack trace implementation & stack walking features. Existing
exception stack trace implementation will be updated later.
Eventually we will end up with the following:

1. If an arch implements `arch_stack_walk()`
   `ARCH_HAS_STACKWALK` should be selected.
2. If the above is enabled, `ARCH_SUPPORTS_STACKWALK` indicates
   if the dependencies are met for arch to enable stack walking.
   This Kconfig replaces `<arch>_EXCEPTION_STACK_TRACE`
2. If the above is enabled, then, `ARCH_STACKWALK` determines
   if `arch_stack_walk()` should be compiled.
3. `EXCEPTION_STACK_TRACE` should build on top of the
   `ARCH_STACKWALK`, stack traces will be printed when it
   is enabled.
4. `ARCH_STACKWALK_MAX_FRAMES` will be removed as it is
   replaced by `ARCH_STACKWALK_MAX_FRAMES`

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-26 14:44:53 -04:00
Pisit Sawangvonganan
8f197c955d style: subsys: comply with MISRA C:2012 Rule 15.6
Add missing braces to comply with MISRA C:2012 Rule 15.6 and
also following Zephyr's style guideline.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-08-20 10:33:51 +02:00
Krzysztof Chruściński
530b8ccbed debug: coresight: Add coresight_trace_deformatter
Add module which decodes data encoded using Coresight Trace
Formatter.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-08-12 19:23:19 -04:00
Mark Holden
e6b683d310 coredump: Guard new kconfig for only supported arch
Add new config, ARCH_SUPPORTS_COREDUMP_THREADS, and
only enable it for ARM CORTEX M where the gdb server
can support it.

Signed-off-by: Mark Holden <mholden@meta.com>
2024-08-02 03:32:09 -04:00
Mark Holden
c35f6d1cac coredump: Add test for threads core dump config
Add z_test which uses new configs to capture multiple
threads in a core dump and with all of the context
necessary to debug the threads.

Signed-off-by: Mark Holden <mholden@meta.com>
2024-08-02 03:32:09 -04:00
Mark Holden
45684a598d coredump: Add config for capturing thread data in core dump
Update core dump file format to support a new section which contains
metadata about threads necessary for debugging.

Define configs to capture that metadata and include it in the dumps
when enabled.

Update documentation to reflect the changes.

Signed-off-by: Mark Holden <mholden@meta.com>
2024-08-02 03:32:09 -04:00
Armin Brauns
cd7a6a4d55 coredump: use memmove instead of memcpy
With CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_LINKER_RAM, buffer_output() is
called on the entire RAM memory area. This includes the stack for the
coredump thread, which is where tmp_buf is stored. Eventually, it will copy
(parts of) tmp_buf into tmp_buf itself, which invokes Undefined Behaviour
in memcpy():

> The memory areas must not overlap.  Use memmove(3) if the memory areas do
> overlap.
- memcpy(3)

With picolibc, this is detected in __memcpy_chk() and causes a fault in
__chk_fail().

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2024-08-01 16:43:41 +02:00
Armin Brauns
12435442d2 coredump: significantly increase efficiency for small write block sizes
With FLASH_WRITE_SIZE==1, this would do a separate flash write for every
single byte.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2024-08-01 16:40:26 +02:00
Fabio Baltieri
60df679366 debug: thread_analyzer: fix incorrect k_thread_foreach_unlocked argument
Fix the second k_thread_foreach_unlocked argument, it's supposed to be
an instance of ta_cb_user_data as that's what's it casted back to in
thread_analyze_cb. Current code results in an exception and crash for
single core applications.

This is a regression introduced in 1b6e0f6479.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-08-01 12:35:45 +02:00
Daniel Leung
d2b072078d debug: thread_analyzer: fix casting pointer to int warning
In thread_analyzer_auto(), it casts one function argument
directly into unsigned int. However, on 64-bit platforms,
the compiler complains about casting from pointer of
different size (-Wpointer-to-int-cast). So cast it first to
uintptr_t before casting it into unsigned int.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-08-01 12:35:34 +02:00
Jyri Sarha
1b6e0f6479 debug: thread_analyzer: Option to analyze threads on each core separately
Add implementation to analyze threads on each cpu separately. This
feature can be enabled with THREAD_ANALYZER_AUTO_SEPARATE_CORES Kconfig
option. If enabled, an analyzer thread is started for each cpu, and
the threads will only analyze thread on the cpu its running on.

This feature is needed for Intel ADSP platform, where cpu specific
caches are not synchronized between the cpu. It is also probably
needed by other platforms having CONFIG_KERNEL_COHERENCE=y, so default
to THREAD_ANALYZER_AUTO_SEPARATE_CORES=y for those platform.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
2024-07-30 18:25:40 +01:00
Francois Ramu
9e03abb8cb debug: no UNALIGNED_ACCESS_SUPPORTED for cortex M0 or M0plus
Set the UNALIGNED_ACCESS_SUPPORTED only for MCU with cortex M
that are neither M0 nor M0plus
Cortex M0 or M0plus mcus do not support un-aligned address access

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2024-06-28 12:21:18 -04:00
Jordan Yates
07870934e3 everywhere: replace double words
Treewide search and replace on a range of double word combinations:
    * `the the`
    * `to to`
    * `if if`
    * `that that`
    * `on on`
    * `is is`
    * `from from`

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-22 05:40:22 -04:00
Yong Cong Sin
5121de6e73 arch: introduce arch_stack_walk()
An architecture can indicate that it has an implementation for
the `arch_stack_walk()` function by selecting
`ARCH_HAS_STACKWALK`.

Set the default value of `EXCEPTION_STACK_TRACE_MAX_FRAMES` to
`ARCH_STACKWALK_MAX_FRAMES` if the latter is available.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-13 16:46:48 -04:00
Yong Cong Sin
3cb2c04fc1 subsys/debug: relocate symtab Kconfig
Move the symtab Kcofig into the symtab folder.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-04 22:36:51 -04:00
Yong Cong Sin
9d9576b442 subsys/debug: relocate gdbstub stuff into its folder
Move the gdbstub files into the gdbstub folder, and relocated
its Kconfig as well.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-04 22:36:51 -04:00
Yong Cong Sin
e54b27b967 arch: define struct arch_esf and deprecate z_arch_esf_t
Make `struct arch_esf` compulsory for all architectures by
declaring it in the `arch_interface.h` header.

After this commit, the named struct `z_arch_esf_t` is only used
internally to generate offsets, and is slated to be removed
from the `arch_interface.h` header in the future.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-04 14:02:51 -05:00
Dominik Ermel
743d66a7e5 debug/coredump/flash_backend: Switch to flash_area_flatten
Replace usage of flash_area_erase with flash_area_flatten to
allow code to work with devices that do not provide erase
callback.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2024-06-04 08:00:46 +02:00