Open topic with navigation

TIBCO GridServer® 7.1.0

# Creating a Native Stack Trace in Linux

Sometimes when you are troubleshooting native C/C++ code on Linux, you want to generate a stack trace, for example when a SIGSEGV is thrown. Since the JVM on the Engine already traps SIGSEGV and prints out a Java (not native) stack trace, you must override the actions of the JVM and install your own SIGSEGV handler for debugging. The `backtrace_fd()` and `backtrace_symbols_fd()` methods from glibc can be used for this purpose.

To install your own SIGSEGV handler for debugging, add code to your Service initialization method similar to this:

    #include <execinfo.h>
    #include <stdio.h>
    #include <signal.h>
    #define TRACE_DEPTH 50
    void MyService::segv_handler(int signum) {
        void *trace[TRACE_DEPTH];
        int depth;
        FILE *fp;
        depth = backtrace(trace, TRACE_DEPTH);
        fp = fopen("trace.log", "w");
        backtrace_symbols_fd(trace, depth, fileno(fp));
        fclose(fp);
        abort();
    }
    void MyService::init() {
        signal(SIGSEGV, segv_handler);
        signal(SIGBUS, segv_handler);
    }

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO GridServer®

Copyright © 2001-2022. TIBCO Software Inc. All Rights Reserved.