Topic
  • 3 replies
  • Latest Post - ‏2014-01-25T01:10:28Z by zlippard
dragon-knight
dragon-knight
8 Posts

Pinned topic Using mt__trce how to get function names in backtrace

‏2010-02-04T06:19:39Z |
Hi

I have the following program to get backtrace.
Compiled as:
xlC_r -g -qtbtable=full -qlist BT.c -lptools_ptr -o BT

/*
File :BT.c
*/

#include <stdio.h>
#include <signal.h>
#include <fcntl.h>

void handle(int signal)
{
int lcf_fd;
struct sigcontext *sigcontext_data;
lcf_fd = open("./tmp.txt",O_WRONLY|O_CREAT, 0666);
mt__trce(lcf_fd, signal, sigcontext_data, 0);
close(lcf_fd);
}

int foo()
{
char *s="hello";
*s='s';
}

int main()
{
signal(SIGSEGV,handle);
foo();
}

And the o/p was this, with no function names . Am i passing right
compiler options

O/p:
+++PARALLEL TOOLS CONSORTIUM LIGHTWEIGHT COREFILE FORMAT version 1.0
+++LCB 1.0 Thu Feb 4 11:08:13 2010 Generated by IBM AIX 5.3
#
+++ID Node 0 Process 278680 Thread 1
***FAULT "SIGSEGV - Segmentation violation"
+++STACK

1. At location 0x09001000a010b700 but procedure information unavailable.

---STACK
---ID Node 0 Process 278680 Thread 1
---LCB

Please help
thanks
Updated on 2012-05-22T10:19:12Z at 2012-05-22T10:19:12Z by ravi_pyapili
  • dragon-knight
    dragon-knight
    8 Posts

    Re: Using mt__trce how to get function names in backtrace

    ‏2010-02-23T07:02:50Z  
    #include <stdio.h>
    #include <signal.h>
    #include <fcntl.h>

    void handle(int signal,int code,struct sigcontext *sigcontext_data)
    {
    int fd;
    fd = open("./tmp.txt",O_WRONLY|O_CREAT, 0666);
    mt__trce(fd, signal, sigcontext_data, 0);
    close(fd);
    exit(0);
    }
    int foo()
    {
    char *s="hello";
    *s='H';
    }
    int foo1() {
    foo();
    }
    int foo2() {
    foo1();
    }
    int main()
    {
    signal(SIGSEGV,handle);
    foo2();
    }
    compiler options:
    xlc -g -qtbtable=full -qlinedebug bt.c -lptools_ptr -o bt

    o/p: cat tmp.txt
    "tmp.txt" 13 lines, 386 characters
    +++PARALLEL TOOLS CONSORTIUM LIGHTWEIGHT COREFILE FORMAT version 1.0
    +++LCB 1.0 Tue Feb 23 12:27:58 2010 Generated by IBM AIX 5.3
    #
    +++ID Node 0 Process 209052 Thread 1
    ***FAULT "SIGSEGV - Segmentation violation"
    +++STACK
    foo : 16 # in file <bt1.c>
    foo1 : 20 # in file <bt1.c>
    foo2 : 24 # in file <bt1.c>
    main : 35 # in file <bt1.c>
    ---STACK
    ---ID Node 0 Process 209052 Thread 1
    ---LCB
  • ravi_pyapili
    ravi_pyapili
    1 Post

    Re: Using mt__trce how to get function names in backtrace

    ‏2012-05-22T10:19:12Z  
    #include <stdio.h>
    #include <signal.h>
    #include <fcntl.h>

    void handle(int signal,int code,struct sigcontext *sigcontext_data)
    {
    int fd;
    fd = open("./tmp.txt",O_WRONLY|O_CREAT, 0666);
    mt__trce(fd, signal, sigcontext_data, 0);
    close(fd);
    exit(0);
    }
    int foo()
    {
    char *s="hello";
    *s='H';
    }
    int foo1() {
    foo();
    }
    int foo2() {
    foo1();
    }
    int main()
    {
    signal(SIGSEGV,handle);
    foo2();
    }
    compiler options:
    xlc -g -qtbtable=full -qlinedebug bt.c -lptools_ptr -o bt

    o/p: cat tmp.txt
    "tmp.txt" 13 lines, 386 characters
    +++PARALLEL TOOLS CONSORTIUM LIGHTWEIGHT COREFILE FORMAT version 1.0
    +++LCB 1.0 Tue Feb 23 12:27:58 2010 Generated by IBM AIX 5.3
    #
    +++ID Node 0 Process 209052 Thread 1
    ***FAULT "SIGSEGV - Segmentation violation"
    +++STACK
    foo : 16 # in file <bt1.c>
    foo1 : 20 # in file <bt1.c>
    foo2 : 24 # in file <bt1.c>
    main : 35 # in file <bt1.c>
    ---STACK
    ---ID Node 0 Process 209052 Thread 1
    ---LCB
    Hi,

    I tried to compile the same program, but I am getting below compiler errors. Pls help me in resolving this

    /home/advftp/SRCPRO_5.2_DEV/ravi>xlc -g -qtbtable=full -qlinedebug sam.c -lptools_ptr -o sam
    "sam.c", line 26.16: 1506-280 (W) Function argument assignment between types "void(*)(int)" and "void(*)(int,int,struct __sigcontext*)" is not allowed.
    If I convert the function to
    void handle(int signal,int code,struct sigcontext *sigcontext_data) to
    void handle(int signal)

    Then it is compiling but not getting complete functino call list during crash

    Basically I want to print list of function calls from stack during crash using signal handling

    Pls Help me in solving this

    Regards
    Ravi
  • zlippard
    zlippard
    1 Post

    Re: Using mt__trce how to get function names in backtrace

    ‏2014-01-25T01:10:28Z  
    Hi,

    I tried to compile the same program, but I am getting below compiler errors. Pls help me in resolving this

    /home/advftp/SRCPRO_5.2_DEV/ravi>xlc -g -qtbtable=full -qlinedebug sam.c -lptools_ptr -o sam
    "sam.c", line 26.16: 1506-280 (W) Function argument assignment between types "void(*)(int)" and "void(*)(int,int,struct __sigcontext*)" is not allowed.
    If I convert the function to
    void handle(int signal,int code,struct sigcontext *sigcontext_data) to
    void handle(int signal)

    Then it is compiling but not getting complete functino call list during crash

    Basically I want to print list of function calls from stack during crash using signal handling

    Pls Help me in solving this

    Regards
    Ravi

    I know this is a bit old but to answer Ravi's question you can cast the handler function to void (*)(int).  I ran in to the same problem and error when compiling.  Use the following line of code:

    signal(SIGSEGV, (void (*)(int))handle);

     

    That should do it.

    -Zac