<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to generate full thread stack trace to log on crash</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/114252/how-to-generate-full-thread-stack-trace-to-log-on-crash</link><description>Using Zephyr (cf2149caf2) / nrfSDKConnect on a nrf5340DK board. 
 I need to know how to get a direct stack trace (with file/line numbers if possible for a debug build). 
 Currently I only get this type of log output: 
 [00:51:03.271,972] &amp;lt;err&amp;gt; os: **</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 02 Sep 2024 06:16:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/114252/how-to-generate-full-thread-stack-trace-to-log-on-crash" /><item><title>RE: How to generate full thread stack trace to log on crash</title><link>https://devzone.nordicsemi.com/thread/500682?ContentTypeID=1</link><pubDate>Mon, 02 Sep 2024 06:16:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5561b159-1eed-440f-8fd1-a55152578a05</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Seems that way. There is this config &lt;a href="https://docs.zephyrproject.org/2.7.5/reference/kconfig/CONFIG_EXCEPTION_STACK_TRACE.html"&gt;CONFIG_EXCEPTION_STACK_TRACE&lt;/a&gt;&amp;nbsp;but I tried to test this with the blinky sample but it does not give any additional functional call trace. I see that this config have additional handling on RISC5 and X86 based fault handling code, so probably it is missing handling on ARM Cortex cores.&lt;/p&gt;
&lt;p&gt;additional prj.conf I included to test this&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_DEBUG_INFO=y
CONFIG_EXCEPTION_STACK_TRACE=y
CONFIG_ASSERT_ON_ERRORS=y
CONFIG_ASSERT=y
CONFIG_LOG=y
CONFIG_RESET_ON_FATAL_ERROR=n&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to generate full thread stack trace to log on crash</title><link>https://devzone.nordicsemi.com/thread/500652?ContentTypeID=1</link><pubDate>Sat, 31 Aug 2024 14:09:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00b447d5-5899-47bf-8fdc-05af62fa408d</guid><dc:creator>BrianW</dc:creator><description>[quote userid="6207" url="~/f/nordic-q-a/114252/how-to-generate-full-thread-stack-trace-to-log-on-crash/500529"]No, the fault handler does not give the full call trace like gdb does. for getting a context function call trace, I start the debugger and set the breakpoint in the hardfault handler. If everything goes right and if the stack memory is not corrupted, then some of the IDE&amp;#39;s debuggers show the call trace or setup GDB session if that is your preference.&amp;nbsp;[/quote]
&lt;p&gt;Ok.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Does this means there is &lt;strong&gt;definitively&lt;/strong&gt; no way to get a call trace in the firmware itself?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to generate full thread stack trace to log on crash</title><link>https://devzone.nordicsemi.com/thread/500529?ContentTypeID=1</link><pubDate>Fri, 30 Aug 2024 08:02:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d9f14fb6-463c-47de-8337-e9335a6125cc</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="BrianW"]fault @ strlen, called by sprintf, called by my_code_fn, called by my_other_fn, called by task_my_thread.[/quote]
&lt;p&gt;No, the fault handler does not give the full call trace like gdb does. for getting a context function call trace, I start the debugger and set the breakpoint in the hardfault handler. If everything goes right and if the stack memory is not corrupted, then some of the IDE&amp;#39;s debuggers show the call trace or setup GDB session if that is your preference.&amp;nbsp;&lt;/p&gt;
[quote user="BrianW"]&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;C:\work\dev\if-device-nrf53&amp;gt;arm-none-eabi-addr2line -e cc1-med/build/zephyr/zephyr.elf -a 0x3fda3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;0x0003fda3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;??:?&lt;/span&gt;[/quote]
&lt;p&gt;Hmm, try to add &amp;quot;-f&amp;quot; option to attempt to get function names.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to generate full thread stack trace to log on crash</title><link>https://devzone.nordicsemi.com/thread/500434?ContentTypeID=1</link><pubDate>Thu, 29 Aug 2024 13:22:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8ebde68-0342-4267-9124-a764bc4853a0</guid><dc:creator>BrianW</dc:creator><description>&lt;p&gt;I compile with CONFIG_DEBUG=y, CONFIG_DEBUG_INFO=y, and I see the -Og in the gcc options.&lt;/p&gt;
[quote userid="6207" url="~/f/nordic-q-a/114252/how-to-generate-full-thread-stack-trace-to-log-on-crash/500402"]Normally the hardfault handler unwinds the last stack frame for you and gives you detail of the instruction causing fault.[/quote]
&lt;p&gt;Do you mean that you see a full call stack? or just the instruction pointer for the function with the fault (which is not helpful if its strlen or sprintf!)&lt;/p&gt;
&lt;p&gt;I&amp;#39;m looking for something like:&lt;/p&gt;
&lt;p&gt;fault @ strlen, called by sprintf, called by my_code_fn, called by my_other_fn, called by task_my_thread.&lt;/p&gt;
&lt;p&gt;Even if the function names are not printed but only the addresses....&lt;/p&gt;
&lt;p&gt;btw, addr2line gave me nothing:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;C:\work\dev\if-device-nrf53&amp;gt;arm-none-eabi-addr2line -e cc1-med/build/zephyr/zephyr.elf -a 0x3fda3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;0x0003fda3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;??:?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;But a find in the cc1-med/build/zephyr/zephyr.map works to find the function for the address.... just not so scriptable...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to generate full thread stack trace to log on crash</title><link>https://devzone.nordicsemi.com/thread/500402?ContentTypeID=1</link><pubDate>Thu, 29 Aug 2024 10:44:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f88ad638-e728-44a3-8d80-6614a9271cc2</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Normally the hardfault handler unwinds the last stack frame for you and gives you detail of the instruction causing fault. How did you compile your project? Did you compile it adding the debug symbols?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am always using Visual Studio code at my end these days so when prototyping I always choose &amp;quot;Optimize for debugging (-Og)&amp;quot; for the whole project. You can do this in your cmake files aswell.&lt;/p&gt;
&lt;p&gt;Also make sure you have&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/kconfig/index.html#CONFIG_DEBUG"&gt;CONFIG_DEBUG&lt;/a&gt;&lt;span&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/kconfig/index.html#CONFIG_DEBUG"&gt;&amp;nbsp;&lt;/a&gt;and&amp;nbsp;&lt;/span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/CONFIG_DEBUG_INFO.html"&gt;CONFIG_DEBUG_INFO&lt;/a&gt;&amp;nbsp;added to your prj.conf&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to generate full thread stack trace to log on crash</title><link>https://devzone.nordicsemi.com/thread/500400?ContentTypeID=1</link><pubDate>Thu, 29 Aug 2024 10:37:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9785a45-56ae-4073-8146-77255014063b</guid><dc:creator>BrianW</dc:creator><description>[quote userid="6207" url="~/f/nordic-q-a/114252/how-to-generate-full-thread-stack-trace-to-log-on-crash/500358"]That seems odd, yes.&amp;nbsp;&lt;br /&gt;The main use of this config is where to pull the fatal_error.c file in or not as seen inside the file&amp;nbsp;nrf\lib\fatal_error\CMakeLists.txt. I did not think that it had any other dependencies or side effects of setting it to &amp;quot;n&amp;quot;[/quote]
&lt;p&gt;if you have&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_RESET_ON_FATAL_ERROR&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;then you also need to explicitly define&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_REBOOT&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;The fatal error then indeed halts the system, rather than rebooting it.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;However, this still does NOT produce a full stack trace for the offending thread.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Is there a way do do this stack unwind for a log? Otherwise knowing it failed in strcpy or another lib function is not very helpful to know how it got there... (which is all the addr2line untility gives you!)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Is this really impossible to do on the device?? gdb knows how to do it (but of course you have to have a gbd server connected to be able to get that!)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to generate full thread stack trace to log on crash</title><link>https://devzone.nordicsemi.com/thread/500358?ContentTypeID=1</link><pubDate>Thu, 29 Aug 2024 07:58:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a7adab5-85c6-4af5-810c-98dad97d974e</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Easiest is to open a command prompt in your project folder an ddo&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;path_to_gnuarmemb/bin/arm-none-eabi-addr2line -e build/zephyr/zephyr.elf -a 0x000143a6&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You would then get the exact context of your fault.&lt;/p&gt;
[quote user="BrianW"]&lt;p&gt;CONFIG_RESET_ON_FATAL_ERROR=n&amp;nbsp;&lt;/p&gt;
&lt;p&gt;as this causes the function sys_reboot() to be not found by the linker (which I use to... reboot...). This seems odd - any ideas why?&lt;/p&gt;[/quote]
&lt;p&gt;That seems odd, yes.&amp;nbsp;&lt;br /&gt;The main use of this config is where to pull the fatal_error.c file in or not as seen inside the file&amp;nbsp;nrf\lib\fatal_error\CMakeLists.txt. I did not think that it had any other dependencies or side effects of setting it to &amp;quot;n&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to generate full thread stack trace to log on crash</title><link>https://devzone.nordicsemi.com/thread/500252?ContentTypeID=1</link><pubDate>Wed, 28 Aug 2024 15:04:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc319338-954a-401c-b659-41678b4af6a2</guid><dc:creator>BrianW</dc:creator><description>&lt;p&gt;Its been discussed a lot, but I don&amp;#39;t see any answer that shows how to move from the basic log output to one with (at least) a full stack trace for the thread that caused the error.&lt;/p&gt;
&lt;p&gt;I&amp;nbsp; already used the thread analyzer setup (just was missing the thread name option)&lt;/p&gt;
&lt;p&gt;With the options you suggest, except for CONFIG_RESET_ON_FATAL_ERROR=n, a crash now gives&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[00:14:33.928,344] &amp;lt;inf&amp;gt; base: DV : request to render current page systest2.1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;* buffer overflow detected *&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[00:14:33.944,885] &amp;lt;err&amp;gt; os: r0/a1: 0x00000003 r1/a2: 0x00000000 r2/a3: 0x00000001&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[00:14:33.953,582] &amp;lt;err&amp;gt; os: r3/a4: 0x2000fa29 r12/ip: 0x0000000a r14/lr: 0x000208eb&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[00:14:33.962,280] &amp;lt;err&amp;gt; os: xpsr: 0x61000000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[00:14:33.967,529] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x000143a6&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[00:14:33.975,463] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[00:14:33.983,123] &amp;lt;err&amp;gt; os: Current thread: 0x20003a68 (sysworkq)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;ie compared to my previous log, only the name of the current thread is shown as well. Still no stack trace/unwind as desired... any more things I can try?&lt;/p&gt;
&lt;p&gt;BTW, I have not yet used:&lt;/p&gt;
&lt;p&gt;CONFIG_RESET_ON_FATAL_ERROR=n&amp;nbsp;&lt;/p&gt;
&lt;p&gt;as this causes the function sys_reboot() to be not found by the linker (which I use to... reboot...). This seems odd - any ideas why?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to generate full thread stack trace to log on crash</title><link>https://devzone.nordicsemi.com/thread/500174?ContentTypeID=1</link><pubDate>Wed, 28 Aug 2024 10:27:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c95fb3d9-224e-42d9-b079-10316c8f4fd5</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;This has been discussed a lot in this forum and few config options were given (for example) &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/95533/preciserr-due-to-the-address-violation-at-0x40009500-bfar-cause-hardfault-for-nrf9160ns/404451"&gt;here &lt;/a&gt;and &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/82034/how-to-monitor-the-size-of-a-thread-stack-in-ncs/340537"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Can you try something like below&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Debugging configuration
CONFIG_THREAD_NAME=y
CONFIG_THREAD_ANALYZER=y
CONFIG_THREAD_ANALYZER_AUTO=y
CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y
CONFIG_THREAD_ANALYZER_USE_PRINTK=y

# Add asserts
CONFIG_ASSERT=y
CONFIG_ASSERT_VERBOSE=y
CONFIG_ASSERT_NO_COND_INFO=n
CONFIG_ASSERT_NO_MSG_INFO=n
CONFIG_RESET_ON_FATAL_ERROR=n
CONFIG_THREAD_NAME=y
CONFIG_STACK_SENTINEL=y&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>