sdk-ng icon indicating copy to clipboard operation
sdk-ng copied to clipboard

GDB - Avoid reading common unmapped address from memory

Open Vge0rge opened this issue 6 months ago • 0 comments

There are cases that the stack will hold unmapped addresses in memory because of non returning functions.

An example of this is TF-M and the common_sfn_thread function here: https://github.com/zephyrproject-rtos/trusted-firmware-m/blob/069455be098383bf96eab73e3ff8e0c66c60fa5a/secure_fw/partitions/lib/runtime/sfn_common_thread.c#L20C6-L20C23

The caller of this function has return type thrd_fn_t: https://github.com/nrfconnect/sdk-trusted-firmware-m/blob/beb7825332ac2184b972e71d297564854408bffd/secure_fw/spm/core/thread.h#L40

As a result of this GDB tries to access the address 0xFFFFFFFE since it exists in the stack as a return value. There are platforms which will result to a fault when reading invalid accesses like this.

To reproduce the behavior that I am saying you can try to build the hello_world sample of Zephyr for the nRF5340. If you break at the function common_sfn_thread and you examine the stack you will see that GDB tries to access the address: image

And in the log of gdb server we can see that this memory address is failed to get read: image

We cannot filter out all the unmapped addresses but for commonly used return addresses like this is it possible to filter them out in GDB so that the call is not forwarded to the GDB server?

Vge0rge avatar Aug 19 '24 15:08 Vge0rge