<?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>Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/63036/running-into-a-sigtrap-backtrace-shows-only-main-apparently-happening-in-libgloss-arm-crt0-s</link><description>I&amp;#39;m using SDK v16 on an nRF52832 and occasionally run into a SIGTRAP with my custom application mainly forwarding BLE traffic from/to UART. 
 It works fine, only after quite a few interactions (can be 3 can be 30) - initiated by a BLE UART client running</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 05 Aug 2020 15:06:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/63036/running-into-a-sigtrap-backtrace-shows-only-main-apparently-happening-in-libgloss-arm-crt0-s" /><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/263283?ContentTypeID=1</link><pubDate>Wed, 05 Aug 2020 15:06:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4dd5464d-9cb4-4c05-8576-b21312b49a3e</guid><dc:creator>run_ar</dc:creator><description>&lt;p&gt;Sorry for the late reply, Just back from vacation.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="daten"]Hardware is an nRF52832.[/quote]
&lt;p&gt;&amp;nbsp;Ok, so custom board then I suppose. I do not necessarily think it is a hardware issue, but it could be related to clock source/timing. Asking in case we would like to try to recreate the issue here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/259768?ContentTypeID=1</link><pubDate>Mon, 13 Jul 2020 22:06:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4dcf40f5-a40d-40fc-bb46-f74731fa0b58</guid><dc:creator>daten</dc:creator><description>&lt;p&gt;Hardware is an nRF52832.&lt;/p&gt;
&lt;p&gt;I now ordered a PCA10040 and will then try to reproduce. Can you elaborate on why you think this might be hardware specific?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/258976?ContentTypeID=1</link><pubDate>Wed, 08 Jul 2020 11:27:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3f22b17-e953-41e8-bed0-e679b4f3b7ed</guid><dc:creator>run_ar</dc:creator><description>&lt;p&gt;Are you able to recreate this issue on a nordic DK? and what hardware are you currently running your code on?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/258771?ContentTypeID=1</link><pubDate>Tue, 07 Jul 2020 09:59:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d293aa2a-57ad-4fbc-b133-dfc0ee6a1e86</guid><dc:creator>daten</dc:creator><description>&lt;p&gt;Re a) I don&amp;#39;t know what else to tell from the GDB output, so yes, fairly sure&lt;/p&gt;
&lt;p&gt;Re b) it&amp;#39;s the same corrupted stacktrace I get /without/ the breakpoint. See initial post (corrupted stacktrace without breakpoints set) and the one with breakpoints right after the break point in noop() is called only a line later. It&amp;#39;s the same corrupted backtrace within APP_ERROR_CHECK(). Doesn&amp;#39;t look like a co-incidence or GDB/breakpoint related (timing-)issue to me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/258760?ContentTypeID=1</link><pubDate>Tue, 07 Jul 2020 09:25:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e2a4235-c1f8-4a7a-984a-6ebc1a875d7f</guid><dc:creator>run_ar</dc:creator><description>&lt;p&gt;a) Are you sure ret is actually 0x01 in this case? Here is the error codes that can be returned by &lt;span&gt;&lt;a title="sd_ble_gatts_hvx" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.0.1/group___b_l_e___g_a_t_t_s___f_u_n_c_t_i_o_n_s.html?cp=4_7_3_1_2_4_2_4#ga313fe43c2e93267da668572e885945db"&gt;sd_ble_gatts_hvx&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;b) This will happen as the timing in the SD will be messed up when you halt at a breakpoint. i.e. the timers will continue to run and the event manager will be lost.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/258198?ContentTypeID=1</link><pubDate>Thu, 02 Jul 2020 21:18:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:491823e6-fd06-458f-a287-35b335f51976</guid><dc:creator>daten</dc:creator><description>&lt;p&gt;Ok, so after having debugged and fixed the firmware of my debugger, back to the actual issue:&lt;/p&gt;
&lt;p&gt;When setting a breakpoint on app_error_fault_handler I get the following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Starting program: /data/src/nrf5x-sdk-vanilla/[..]/s132/armgcc/_build/nrf52832_xxaa.out 
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, app_error_fault_handler (id=16385, pc=225911, info=536936392) at ../../../../../../components/libraries/util/app_error_weak.c:58
58	    __disable_irq();&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;while the backtrace still looks messy:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) bt
#0  app_error_fault_handler (id=16385, pc=225911, info=536936392) at ../../../../../../components/libraries/util/app_error_weak.c:58
#1  0x0002cce4 in app_error_handler (error_code=16385, line_num=225911, p_file_name=0x2000ffc8 &amp;quot;\226\006&amp;quot;)
    at ../../../../../../components/libraries/util/app_error_handler_gcc.c:49
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So I again went for the noop(), which results into the following code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;            ret = ble_nus_data_send(&amp;amp;m_nus, m_uart_buf[uart_buf_id], (uint16_t *)(&amp;amp;(m_uart_buf_pos[uart_buf_id])), m_conn_handle);
            if ((ret != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
                (ret != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
                (ret != NRF_ERROR_NOT_FOUND))
            {
              if(ret != 0)
                noop(ret);
              APP_ERROR_CHECK(ret);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;resulting in:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Starting program: /data/src/nrf5x-sdk-vanilla/sensorberg/projects/smartspaces/sdg03/s132/armgcc/_build/nrf52832_xxaa.out 
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, noop (err_code=1 &amp;#39;\001&amp;#39;) at ../../../main.c:1568
1568	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;having a seemingly not (yet) messed up stack:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) bt
#0  noop (err_code=1 &amp;#39;\001&amp;#39;) at ../../../main.c:1568
#1  0x00037266 in main () at ../../../main.c:1686&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So at that point we know that ble_nus_data_send() sometimes returns 0x01.&lt;/p&gt;
&lt;p&gt;Continuing execution now leads me right into the NRF_BREAKPOINT_COND with the corrupt stack:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0002ce56 in app_error_fault_handler (id=16385, pc=225917, info=536936392) at ../../../../../../components/libraries/util/app_error_weak.c:100
100	    NRF_BREAKPOINT_COND;
(gdb) bt
#0  0x0002ce56 in app_error_fault_handler (id=16385, pc=225917, info=536936392)
    at ../../../../../../components/libraries/util/app_error_weak.c:100
#1  0x0002cce4 in app_error_handler (error_code=16385, line_num=225917, 
    p_file_name=0x4001 &amp;quot;\211\240\201hh\200\211\340\201\233\346\020&amp;amp;O\360#\b&amp;quot;)
    at ../../../../../../components/libraries/util/app_error_handler_gcc.c:49
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So there&amp;#39;s 2 questions now:&lt;/p&gt;
&lt;p&gt;a) why does ble_nus_data_send() sometimes returns 0x01?&lt;br /&gt;b) why does APP_ERROR_CHECK() /appear/* to end up with a corrupted stack?&lt;/p&gt;
&lt;p&gt;*obviously the actual root cause can be somewhere else and APP_ERROR_CHECK() only accesses memory already corrupted somewhere/-when before&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/258195?ContentTypeID=1</link><pubDate>Thu, 02 Jul 2020 20:13:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:782d2460-4447-4d17-a810-3441c81df9a4</guid><dc:creator>daten</dc:creator><description>&lt;p&gt;This comment is obsolete (while the actual issue still exists and is further discussed in the reply/replies after this one), but leaving it here for reference if somebody else is having issues with the Black Magic Probe and breakpoints not working:&lt;/p&gt;
&lt;p&gt;=========&lt;/p&gt;
&lt;p&gt;For the following code snippet:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;          do
          {
            ret = ble_nus_data_send(&amp;amp;m_nus, m_uart_buf[uart_buf_id], (uint16_t *)(&amp;amp;(m_uart_buf_pos[uart_buf_id])), m_conn_handle);
            if ((ret != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
                (ret != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
                (ret != NRF_ERROR_NOT_FOUND))
            {
              noop(ret);
              APP_ERROR_CHECK(ret);
            }
          } while (ret == NRF_ERROR_BUSY);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I set a breakpoint in noop() via&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) break noop
Breakpoint 1 at 0x370d6: file ../../../main.c, line 1568.
(gdb) r&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;but still end up in&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;0x0002ce56 in app_error_fault_handler (id=16385, pc=225911, info=536936392) at ../../../../../../components/libraries/util/app_error_weak.c:100
100	    NRF_BREAKPOINT_COND;
(gdb) bt
#0  0x0002ce56 in app_error_fault_handler (id=16385, pc=225911, info=536936392)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;addr2line still points to the &amp;quot;} while (ret == NRF_ERROR_BUSY);&amp;quot; line.&lt;/p&gt;
&lt;p&gt;What I can say, though, is, that removing the APP_ERROR_CHECK() call seems to make this issue go away. However this obviously isn&amp;#39;t the solution. Also I wonder about why the breakpoint doesn&amp;#39;t trigger. Compiled with -O0 and -DDEBUG. Also, GDB seems to see the noop symbol, so I&amp;#39;d say it&amp;#39;s there.&lt;/p&gt;
&lt;p&gt;I went for the noop() instead of setting a breakpoint on APP_ERROR_CHECK() as GDB doesn&amp;#39;t appear to see the macro:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) break APP_ERROR_CHECK
Function &amp;quot;APP_ERROR_CHECK&amp;quot; not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (APP_ERROR_CHECK) pending.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;which makes sense, as it&amp;#39;s not a symbol ending up in the binary.&lt;/p&gt;
&lt;p&gt;Setting a breakpoint on app_error_fault_handler also doesn&amp;#39;t trigger a break, I still end up in NRF_BREAKPOINT_COND with a corrupt stack.&lt;/p&gt;
&lt;p&gt;For completeness here the definition of noop():&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void noop(uint8_t err_code) {
  UNUSED_VARIABLE(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPDATE: &lt;/strong&gt;Neither does &amp;quot;break main&amp;quot; actually break on main() - so I assume that&amp;#39;s a different issue.&lt;/p&gt;
&lt;p&gt;=========================&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPDATE 2:&lt;/strong&gt; Ok, this appears to be a problem with the debugger I use - the Black Magic Probe. The issue was fixed in a later version, for reference and the record: &lt;a href="https://github.com/blacksphere/blackmagic/issues/230"&gt;https://github.com/blacksphere/blackmagic/issues/230 &lt;br /&gt;&lt;/a&gt;Having breakpoints working now! Actual issue further investigated as part of the next comment.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/257310?ContentTypeID=1</link><pubDate>Mon, 29 Jun 2020 09:25:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc99d708-0ff8-41f0-94d7-bbb8e80a82fb</guid><dc:creator>run_ar</dc:creator><description>&lt;p&gt;Could you place a breakpoint at APP_ERROR_CHECK(ret); to check that you do not enter that? And if you enter, what is the value of ret?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/257198?ContentTypeID=1</link><pubDate>Fri, 26 Jun 2020 17:04:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d610686-6042-47aa-8ace-a2f43b7a218c</guid><dc:creator>daten</dc:creator><description>&lt;p&gt;Thank you for your reply!&lt;/p&gt;
&lt;p&gt;it translates to line 12 in the following snippet:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        if(m_conn_handle != BLE_CONN_HANDLE_INVALID)
        {
          do
          {
            ret = ble_nus_data_send(&amp;amp;m_nus, m_uart_buf[uart_buf_id], (uint16_t *)(&amp;amp;(m_uart_buf_pos[uart_buf_id])), m_conn_handle);
            if ((ret != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
                (ret != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
                (ret != NRF_ERROR_NOT_FOUND))
            {
              APP_ERROR_CHECK(ret);
            }
          } while (ret == NRF_ERROR_BUSY); // &amp;lt;&amp;lt;&amp;lt;---------------
        }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/257136?ContentTypeID=1</link><pubDate>Fri, 26 Jun 2020 12:35:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3ab57f9-a0cd-49d1-b0c7-08e5c71ed215</guid><dc:creator>run_ar</dc:creator><description>&lt;p&gt;What is at pc: 225711 if you use addr2line to check?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/257024?ContentTypeID=1</link><pubDate>Thu, 25 Jun 2020 23:03:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98176926-f76a-4234-97bf-ed5da0fcac36</guid><dc:creator>daten</dc:creator><description>&lt;p&gt;So&amp;nbsp;error_code=16385 is 0x4001 which according to components/libraries/util/app_error.h is&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;(NRF_FAULT_ID_SDK_RANGE_START + 1) /**&amp;lt; An error stemming from a call to @ref APP_ERROR_CHECK or @ref APP_ERROR_CHECK_BOOL. The info parameter is a pointer to an @ref error_info_t variable. */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;which is already bringing me closer - telling me it&amp;#39;s a result from an APP_ERROR_CHECK() call (not explaining the corrupted stack yet, though). Now trying to figure out which APP_ERROR_CHECK() call.&lt;/p&gt;
&lt;p&gt;Unfortunately the info appears to be screwed. According to above comment for the define, info=536936400 is supposed to be a pointer to an instance of struct error_info_t, containing the information I&amp;#39;m looking for. Trying to access it via GDB however results in;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) p *((error_info_t*)(info))
Cannot access memory at address 0x2000ffd0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Besides I do wonder about p_file_name=0x4001. How did the error_code make it as arg towards p_file_name which appears to actually contain a pointer?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Running into a SIGTRAP, backtrace shows only main(), apparently happening in libgloss/arm/crt0.S</title><link>https://devzone.nordicsemi.com/thread/256960?ContentTypeID=1</link><pubDate>Thu, 25 Jun 2020 13:55:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47b9eaaf-5247-4738-a859-f6b2b5f31858</guid><dc:creator>daten</dc:creator><description>&lt;p&gt;Compiling with -DDEBUG, -g3 and -O0 reveals some more:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Program received signal SIGTRAP, Trace/breakpoint trap.
warning: while parsing target memory map (at line 1): Required element &amp;lt;memory&amp;gt; is missing
0x0002ce36 in app_error_fault_handler (id=16385, pc=225711, info=536936400)
    at ../../../../../../components/libraries/util/app_error_weak.c:100
100	    NRF_BREAKPOINT_COND;
(gdb) bt
#0  0x0002ce36 in app_error_fault_handler (id=16385, pc=225711, info=536936400)
    at ../../../../../../components/libraries/util/app_error_weak.c:100
#1  0x0002ccc4 in app_error_handler (error_code=16385, line_num=225711, 
    p_file_name=0x4001 &amp;quot;\211\240\201hh\200\211\340\201\233\346\020&amp;amp;O\360#\b&amp;quot;)
    at ../../../../../../components/libraries/util/app_error_handler_gcc.c:49
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>