Add `gdb_q_packet` function to handle proccessing of query packets. Also
add `gdb_qsupported` function to serve as a single place to process and
respond to `qSupported` packets.
Signed-off-by: Robert Zieba <robertzieba@google.com>
Make the current gdb loop enum public under the name `gdb_loop_state`.
This will allow for extending the current stub with further
functionality in the future as new features will require control over
the loop state.
Signed-off-by: Robert Zieba <robertzieba@google.com>
Simple rename to align the kernel naming scheme. This is being
used throughout the tree, especially in the architecture code.
As this is not a private API internal to kernel, prefix it
appropriately with K_.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
The current implementation can raise a warning as the compiler sees
an attempt to index an array with a size of zero. This can be fixed by
giving `gdb_mem_num_regions` a default value of zero, but this gets
flagged by CI checks. Disable the warning around the array access.
Signed-off-by: Robert Zieba <robertzieba@google.com>
By default `GDBSTUB_SERIAL_BACKEND` will be selected as it's the only
option here. This can cause problems for code that wants to provide its
own custom backend. Add a choice for a custom backend.
Signed-off-by: Robert Zieba <robertzieba@google.com>
Add GDBSTUB_TRACE config option to extend GDB backend debug logging
for remote commands received and to debug the GDB stub itself.
Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
Do not enable subsystem/driver shell modules by default and stop abusing
CONFIG_SHELL_MINIMAL, which is internal to the shell subsystem, to decide
when to enable a driver shell.
The list of shell modules has grown considerably through the
years. Enabling CONFIG_SHELL for doing e.g. an interactive debug session
leads to a large number of shell modules also being enabled unless
explicitly disabled, which again leads to non-negligible increases in
RAM/ROM usage.
This commit attempts to establish a policy of subsystem/driver shell
modules being disabled by default, requiring the user/application to
explicitly enable only those needed.
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Enabling the core dump via memory window backend only makes sense on
Intel ADSP platform wtih memory windows enabled.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The DEBUG_COREDUMP_BACKEND_LOGGING option should automatically
select LOG Kconfig instead of just depending on it.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The loop in `coredump_flash_backend_buffer_output` might fail without
any alerts. This could be due to e.g. a too small coredump-partion.
Add a LOG_ERR if an error occurs.
Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
Zephyr's code base uses MP_MAX_NUM_CPUS to
know how many cores exists in the target. It is
also expected that both symbols MP_MAX_NUM_CPUS
and MP_NUM_CPUS have the same value, so lets
just use MP_MAX_NUM_CPUS and simplify it.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
The variables are usually placed into an output region located in FLASH
memory when linking, but the variables are not marked `const`, so the
section ends up with `W` writeable section flag:
```bash
❯ arm-zephyr-eabi-readelf --section-headers build/zephyr/zephyr.elf | \
grep -E '(Section Headers:)|( \[Nr\])|(zephyr_dbg_info)'
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[10] zephyr_dbg_info PROGBITS 60012298 01238c 000040 00 WA 0 0 4
```
Set them as const to set the output section to read-only:
```bash
❯ arm-zephyr-eabi-readelf --section-headers build/zephyr/zephyr.elf | \
grep -E '(Section Headers:)|( \[Nr\])|(zephyr_dbg_info)'
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[10] zephyr_dbg_info PROGBITS 60012298 01238c 000040 00 A 0 0 4
```
Signed-off-by: Noah Pendleton <noah.pendleton@gmail.com>
When a thread is preempted on ARC, caller-saved registers
are saved on the stack automatically (RIRQ) or manually
by the kernel ISR (FIRQ).
Exposing the thread's relinquish cause hints the debugger
that it can read more or less register values.
Signed-off-by: Bruno Mendes <bd_mendes@outlook.com>
When enabling thread analyzer, use printk by default. Otherwise logging
subsystem is enabled which might not be desired.
Fixes#59919
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This code is meant to run in the context of a exception.
Most architectures will fail the asertion made in z_impl_k_sem_take()
when timeout is not K_NO_WAIT.
This commit ensures K_NO_WAIT is used when arch_is_in_isr() is true.
Signed-off-by: Lucas Tamborrino <lucas.tamborrino@espressif.com>
The buffer_output interface is called a few times during one core dump,
so we need to maintain a memory write pointer to prevent data overwriting.
Signed-off-by: Rander Wang <rander.wang@intel.com>
The MPU stack guard can move the start address of a thread stack.
Don't allow both options to be enabled at the same time.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
For debug usage is added backend for memory window.
Coredump is being dumped in raw data. It needs to be converted to
ACSII for later analysis. Data is written to telemetry slot
in memory window which is a space where is located all debbug
information.
Signed-off-by: PawelX Dobrowolski <pawelx.dobrowolski@intel.com>
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The init infrastructure, found in `init.h`, is currently used by:
- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices
They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:
```c
struct init_entry {
int (*init)(const struct device *dev);
/* only set by DEVICE_*, otherwise NULL */
const struct device *dev;
}
```
As a result, we end up with such weird/ugly pattern:
```c
static int my_init(const struct device *dev)
{
/* always NULL! add ARG_UNUSED to avoid compiler warning */
ARG_UNUSED(dev);
...
}
```
This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:
```c
static int my_init(void)
{
...
}
```
This is achieved using a union:
```c
union init_function {
/* for SYS_INIT, used when init_entry.dev == NULL */
int (*sys)(void);
/* for DEVICE*, used when init_entry.dev != NULL */
int (*dev)(const struct device *dev);
};
struct init_entry {
/* stores init function (either for SYS_INIT or DEVICE*)
union init_function init_fn;
/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
* to know which union entry to call.
*/
const struct device *dev;
}
```
This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.
**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
init: convert SYS_INIT functions to the new signature
Conversion scripted using scripts/utils/migrate_sys_init.py.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
manifest: update projects for SYS_INIT changes
Update modules with updated SYS_INIT calls:
- hal_ti
- lvgl
- sof
- TraceRecorderSource
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: devicetree: devices: adjust test
Adjust test according to the recently introduced SYS_INIT
infrastructure.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: kernel: threads: adjust SYS_INIT call
Adjust to the new signature: int (*init_fn)(void);
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
When FPU is enabled for Arm64, the saved_fp_context must be tracked by
thread info to visualize correctly the FPU context of threads.
Signed-off-by: Manuel Arguelles <manuel.arguelles@nxp.com>
The thread analyzer cannot be really used with the
POSIX architecture.
As:
* Code takes 0 simulated time to execute.
So the analyzer will report 0 cycles being used.
* The stack allocated by Zephyr is not actually used
(except for a tiny part used by the arch code itself
to do a bit of thread bookkeeping).
The POSIX architecture uses a separate stack
(from an underlying Linux pthread) which Zephyr is blind
about. So the thread analyzer is going to only report
a tiny stack utilization.
Prevent users from selecting them together to avoid confusion.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Store the offset of mode_exc_return in the arch struct. This is required
to restore the link register to the original value, as `swap_helper.S`
saves the LSB to this field when `CONFIG_ARM_STORE_EXC_RETURN=y`.
Failing to account for this results in broken debugging when
`FPU_SHARING` or `ARM_NONSECURE_PREEMPTIBLE_SECURE_CALLS`.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Change for loops of the form:
for (i = 0; i < CONFIG_MP_NUM_CPUS; i++)
...
to
unsigned int num_cpus = arch_num_cpus();
for (i = 0; i < num_cpus; i++)
...
We do the call outside of the for loop so that it only happens once,
rather than on every iteration.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
Spin locks held for any lengthy duration prevent interrupts and
in a real time system where interrupts drive tasks this can be
problematic. Add an option to assert if a spin lock is held for
a duration longer than the configurable number of microseconds.
Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
The commit switches flash area access from FLASH_AREA_ macros
to FIXED_PARTITION_ macros and to usage of DTS node labels,
to identify partitions, instead of label property.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Wire this up the same way ASAN works. Right now it's support only by
recent clang versions (not gcc), and only in 64 bit mode. But it's
capable of detecting uninitialized data reads, which ASAN is not.
This support is wired into the sys_heap (and thus k_heap/k_malloc)
layers, allowing detection of heap misuse like use-after-free. Note
that there is one false negative lurking: due to complexity, in the
case where a sys_heap_realloc() call is able to shrink memory in
place, the now-unused suffix is not marked uninitialized immediately,
making it impossible to detect use-after-free of those particular
bytes. But the system will recover cleanly the next time the memory
gets allocated.
Also no attempt was made to integrate this handling into the newlib or
picolibc allocators, though that should hopefully be possible via
similar means.
Signed-off-by: Andy Ross <andyross@google.com>
This had bitrotten a bit, and didn't build as shipped. Current
libasan implementations want -fsanitize=address passed as a linker
argument too. We have grown a "lld" linker variant that needs the
same cmake treatment as the "ld" binutils one, but never got it. But
the various flags had been cut/pasted around to different places, with
slightly different forms. That's really sort of a mess, as sanitizer
support was only ever support with host toolchains for native_posix
(and AFAICT no one anywhere has made this work on cross compilers in
an embedded environment). And the separate "gcc" vs. "llvm" layers
were silly, as there has only ever been one API for this feature (from
LLVM, then picked up compatibly by gcc).
Pull this stuff out and just do it in one place in the posix arch for
simplicity.
Also recent sanitizers are trying to add instrumentation padding
around data that we use linker trickery to pack tightly
(c.f. SYS_INIT, STRUCT_SECTION_ITERABLE) and we need a way
("__noasan") to turn that off. Actually for gcc, it was enough to
just make the records const (already true for most of them, except a
native_posix init struct), but clang apparently isn't smart enough.
Finally, add an ASAN_RECOVER kconfig that enables the use of
"halt_on_error=0" in $ASAN_OPTIONS, which continues execution past the
first error.
Signed-off-by: Andy Ross <andyross@google.com>
This commit adds the `CODE_UNREACHABLE` hint at the end of the
assertion failure branch so that the compiler takes note of the assert
function not returning when an assertion fails.
This prevents the compiler from generating misguided warnings assuming
the asserted execution paths.
It also introduces the `ASSERT_TEST` Kconfig symbol, which indicates
that the "assert test mode" is enabled. This symbol may be selected by
the tests that require the assert post action function to return
without aborting so that the test can proceed.
Note that the `CODE_UNREACHABLE` hint is specified only when the assert
test mode is disabled in order to prevent the tests from crashing when
the assert post action function returns.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
Move from using Kconfig GDBSTUB_SERIAL_BACKEND_NAME to a devicetree
chosen property ("zephyr,gdbstub-uart"). This is similar to a number
of other functions like "zephyr,shell-uart" or "zephyr,bt-uart".
Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
Any project with Kconfig option CONFIG_LEGACY_INCLUDE_PATH set to n
couldn't be built because some files were missing zephyr/ prefix in
includes
Re-run the migrate_includes.py script to fix all legacy include paths
Signed-off-by: Tomislav Milkovic <milkovic@byte-lab.com>
Add a new coredump query and command type to retrieve the raw data
stored to the flash backend
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Following zephyr's style guideline, all if statements, including single
line statements shall have braces.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Adds compatibility with Intel ADSP GDB from Zephyr SDK and
from Cadence toolchain to coredump_gdbserver.py.
Adds CAVS 15-25 (APL) register definitions. Implements
handle_register_single_read_packet to serve ADSP GDB
p packets.
Prevents BSA from changing between stack dump printout
and coredump by taking lock. Observed to be necessary for
accurate results on slower simulated platforms.
Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit corrects all `extern K_KERNEL_STACK_ARRAY_DEFINE` macro
usages to use the `K_KERNEL_STACK_ARRAY_DECLARE` macro instead.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>