Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 935133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:06:36+00:00 2026-05-15T21:06:36+00:00

GNU libc’s backtrace and In-circuit emulators/debuggers are not always available when porting code to

  • 0

GNU libc’s backtrace and In-circuit emulators/debuggers are not always available when porting code to a new platform, especially when the target is a micro C compiler such as for the Z80. (Typically a program bug would “just hang” somewhere, or crash the gadget.)

Is there an alternative to the classic “wolf fencing” method of manually inserting printf? Something simple and portable (using no C extensions) that a coder can do while developing a program that includes tracing and backtracing into a C program?

BTW: Here are a couple of other question on stackoverflow that are related, but these both use GNU GLIBC’s backtrace and backtrace is often compiler/implementation specific:

  • Is there a function to invoke a stack dump in C?
  • How to generate a stacktrace when my gcc C++ app crashes
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:06:37+00:00Added an answer on May 15, 2026 at 9:06 pm

    There is an implementation at RosettaCode.org which uses the same basic idea as @jsl4tv’s suggestion.

    Example, given the following classic C code with built in “hang“:

    #include <stdio.h>
    #include <stdlib.h>
    
    void inner(int k)
    {
       for(;;){} /* hang */
    }
    
    void middle(int x, int y)
    {
      inner(x*y);
    }
    
    void outer(int a, int b, int c)
    {
      middle(a+b, b+c);
    }
    
    int main()
    {
      outer(2,3,5);
      return(EXIT_SUCCESS);
    }
    

    #define STACK_TRACE_ON and #include “stack_trace.h” from RosettaCode.org then insert BEGIN(f)/ENDs where required:

    #include <stdio.h>
    #include <stdlib.h>
    
    #define STACK_TRACE_ON /* compile in these "stack_trace" routines */
    #include "stack_trace.h"
    
    void inner(int k)
    BEGIN(inner)
       print_indent(); printf("*** Now dump the stack ***\n");
       print_stack_trace();
       for(;;){} /* hang */
    END
    
    void middle(int x, int y)
    BEGIN(middle)
      inner(x*y);
    END
    
    void outer(int a, int b, int c)
    BEGIN(outer)
      middle(a+b, b+c);
    END
    
    int main()
    BEGIN(main)
      stack_trace.on = TRUE; /* turn on runtime tracing */
      outer(2,3,5);
      stack_trace.on = FALSE;
      RETURN(EXIT_SUCCESS);
    END
    

    Produces:

    stack_trace_test.c:19: BEGIN outer[0x80487b4], stack(depth:1, size:60)
    stack_trace_test.c:14:   BEGIN middle[0x8048749], stack(depth:2, size:108)
    stack_trace_test.c:8:     BEGIN inner[0x80486d8], stack(depth:3, size:156)
    stack_trace_test.c:8:       *** Now dump the stack ***
    stack_trace_test.c:8:   inner[0x80486d8]        --- stack(depth:4, size:156) ---
    stack_trace_test.c:14:  middle[0x8048749]       --- stack(depth:3, size:108) ---
    stack_trace_test.c:19:  outer[0x80487b4]        --- stack(depth:2, size:60) ---
    stack_trace_test.c:24:  main[0x804882a] --- stack(depth:1, size:0) ---
    stack_trace_test.c:8:       --- (depth 4) ---
    

    A well polished [open source] version of this BEGIN ~ END method would be perfect. (Esp if it has a “FINALLY” clause for exception handling).

    Hints/URLs appreciated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm new to gnu make. i searched around but i cannot find anything working...
GNU Emacs 23.1.1 I am maintaining someones code. There are many files and directories
I started to look into glibc ( GNU Libc ) to understand how it's
I don't know what's wrong my simple std::thread code (listed below). It always crashes
GNU Emacs 23.1 I am using iswitchb. However, when I press C-x b I
Gnu Emacs is insisting on indenting my typedef as follows: typedef enum { horizontal,
GNU bash, version 4.2.24: $> printf %.0f, %.0f\n 48.5 49.5 48, 50 Ruby 1.8.7
The GNU/Linux version of cp has a nice --update flag: -u, --update copy only
The GNU case range extension allows case ranges in switch statements: switch (value) {
I am using GNU grep on Windows 7 command prompt. I have a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.