title: Get backtrace under Tiny C
body: <pre><code>nptrs = backtrace(buffer, SIZE);
  </code></pre>
  
  <p>Standard <code>backtrace</code> function does not work under Tiny C, (it only returns a single address). How do you get a current stack trace in a Tiny C compiled program?</p>
  
  <p>Update:</p>
  
  <p>I tried manual stack walk like this <a href="https://github.com/Michocio/Stack-trace/blob/master/show_stack.c" rel="nofollow noreferrer">found on git hub</a>, again it only works on GCC but not under Tiny:</p>
  
  <pre><code>#include &lt;stdint.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;inttypes.h&gt;
  #define CALL_OFFSET 5
  #define RELATIVE_ADDR_OFFSET 4
  #define CALL_CMD 0xe8
  
  extern uint8_t _start;
  extern uint8_t _etext;
  extern void *__libc_stack_end;
  
  typedef uint8_t * pointer;
  
  void stack_show() {
      uint8_t shift = 1;
      uint8_t stack_top = 0;
      pointer ptr = &amp;stack_top;
      while((ptr + 3) &lt;= (pointer)__libc_stack_end) {
          uint32_t * lbs = (uint32_t *)ptr;
          uint32_t * mbs = (uint32_t *)(ptr+3);
          uint64_t addr = ((*(mbs))&lt;&lt;16) | *lbs;
          if(addr &gt; CALL_OFFSET &amp;&amp;
              (addr - CALL_OFFSET) &gt;= (uint64_t)&amp;_start &amp;&amp;
                  addr &lt; (uint64_t)&amp;_etext) {
              if(*(pointer)(addr - CALL_OFFSET) == CALL_CMD) {
                  uint64_t fun_addr = *(int*)(addr - RELATIVE_ADDR_OFFSET) + *(int*)ptr;
                  if(fun_addr &gt;= (uint64_t)&amp;_start &amp;&amp; fun_addr &lt; (uint64_t)&amp;_etext)
                      printf("%016llx\n", fun_addr);
              }
          }
          ptr += shift;
      }
      return;
  }
  </code></pre>