-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cortex_m: Add debug symbols for OpenOCD/GDB thread support #4058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I just realized that |
very nice! |
Works like charm on the iotlab-m3 with gnrc_networking: (gdb) info threads
Id Target Id Frame
7 Thread 7 (at86rfxx : : Blocked receive) 0x08001716 in _msg_receive (m=0x20000ed0 <_nomac_stacks+868>, block=1) at /home/oleg/git/RIOT/core/msg.c:329
6 Thread 6 (udp : : Blocked receive) 0x08001716 in _msg_receive (m=0x20004714 <_stack+850>, block=1) at /home/oleg/git/RIOT/core/msg.c:329
5 Thread 5 (ipv6 : : Blocked receive) 0x08001716 in _msg_receive (m=0x20001304 <_stack+858>, block=1) at /home/oleg/git/RIOT/core/msg.c:329
4 Thread 4 (6lo : : Blocked receive) 0x08001716 in _msg_receive (m=0x20003f64 <_stack+842>, block=1) at /home/oleg/git/RIOT/core/msg.c:329
3 Thread 3 (pktdump : : Blocked receive) 0x08001716 in _msg_receive (m=0x20003b80 <_stack+1384>, block=1) at /home/oleg/git/RIOT/core/msg.c:329
2 Thread 2 (main : : Blocked mutex) mutex_lock (mutex=0x20000390 <_rx_mutex>) at /home/oleg/git/RIOT/core/mutex.c:53
* 1 Thread 1 (idle : : Running) idle_thread (arg=<optimized out>) at /home/oleg/git/RIOT/core/kernel_init.c:74 |
@OlegHahm |
9ae526b
to
8593160
Compare
Wow! |
http://openocd.zylin.com/#/c/3000/, but seems they take more time to review contributions than we do :P |
So what's your opinion on this? Waiting for the OpenOCD change will not make sense I would say. I can't estimate how long they'll take for reviewing my commit and in the end it has to match the RIOT "interface". So it would make sense to agree on this first and then maybe accelerate the OpenOCD change. |
will |
@@ -181,6 +190,12 @@ void sched_switch(uint16_t other_prio) | |||
|
|||
NORETURN void sched_task_exit(void) | |||
{ | |||
/* Prevent optimization of these symbols */ | |||
max_threads = max_threads; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause warnings from various static analyzers. Does adding __attribute__((used))
help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't work. It is caused by the linker garbage collection:
export CFLAGS_LINK = -ffunction-sections -fdata-sections
export LINKFLAGS += -Wl,--gc-sections
So there doesn't seem to be a way to prevent optimization from within the compiler other than removing -fdata-sections
. But that's no option.
Adding
export LINKFLAGS += -Wl,-u,max_threads
to boards/Makefile.include.cortexm_common
keeps the variable from being optimized away, but that's not a nice solution either.
Another possible solution would be to define a new section in RAM (linker script) with KEEP(this-section)
and moving the variable into that section.
I would rather like to have a solution where it's only marked next to variable in source, but there doesn't seem to be a way. The latter solution is not far away from that at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think still attribute((used)) will be necessary when building with LTO. |
In general this does no harm. I switched from |
e3a2dcf
to
0d25acd
Compare
To get the OpenOCD patches reviewed I was told to send some RIOT guys over to them to review my patches, as you are really using RIOT. So please head over to OpenOCD RIOT support You need to register at their Gerrit but you can use your Github account via OAuth. |
7ae1937
to
6abdde4
Compare
@gebart |
Anyone with an opinion here? I would vote for merging this PR ASAP. At least one could use this nice feature on RIOT with a locally patched OpenOCD version. |
I'm currently not using RIOT in any project, but when working with it this was a crucial feature for me. Concerning the OpenOCD part: they are preparing the 0.10 release right now so I guess it's to late to get RIOT-support merged into 0.10 anymore. But still, when it's merged here it's certainly possible to get the patch accepted for the next release. |
I agree, this should be merged. Might need updates to some boards which were added after last rebase though. |
@daniel-k, you could cherry-pick OlegHahm@6c22e3f to add the missing new boards. |
@OlegHahm cherry-picked it is. Thanks! |
0980fcc
to
9d403d9
Compare
If I understood this correctly you need a patched version of openocd to have this feature, but without the patch it is still working (just tested it with |
(But I leave the actual ACK to a person more knowledgeable with OpenOCD) |
I'm without hardware right now. Can anyone just briefly check with any board using OpenOCD for flashing and an unpatched version, in order to assure that it is indeed not breaking anything? If the result is positive, I'm willing to ACK. |
I just tested this PR and it didn't break anything, however it seems to succeed always, even if it didn't. |
What do you mean by "succeed"? |
When the flashing was successful. In current master it returns an error which stops make immediately. With this change openocd returns success even if the flashing failed. It's related to what we had before #2897. |
This sounds odd. Have you locally merged this PR into master or just checked it out? |
Just checked it out locally, with a rebase it works ok. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
The changeset looks good and @kYc0o verified that it doesn't break anything.
Finally \o/ Thanks guys :) |
Well, thank you for the endurance. ;) |
It seems that openocd PR has never been merged |
leads seemingly to detection of a different RTOS with Ubuntu upstream openocd-0.10.0-6
provides following backtrace
|
GDB has the ability to inspect threads, but to use this feature with RIOT the GDB-server, in this case OpenOCD, needs to know about the thread structures and the stacking. This PR introduces 2 new symbols in order to provide support for GDB threads.
To use this feature you need my patched OpenOCD version found here. I'm working on getting these patches upstream to OpenOCD so that one day this will be a default feature.
I added the needed
-rtos auto
line to every board that has aopenocd.cfg
file, but only testedstm32f4discovery
andsamr21-xpro
yet.OpenOCD can only access symbols, no struct offsets or define macros, so I introduced
max_threads
to iterate oversched_threads
and_tcb_name_offset
that will only be available when compiled withDEVELHELP
to access the thread name. Although both symbols are declared asvolatile
they will be optimized away, so that's why I added the hack insched_task_exit()
. I'm sure there's a better way, so please tell me :)