Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line Number Info in ltrace and strace tools

Tags:

c

strace

ltrace

Is it possible that I can view the line number and file name (for my program running with ltrace/strace) along with the library call/system call information.

Eg:

code section :: ptr = malloc(sizeof(int)*5); (file:code.c, line:21)

ltrace or any other tool: malloc(20) :: code.c::21

I have tried all the options of ltrace/strace but cannot figure out a way to get this info.

If not possible through ltrace/strace, do we have any parallel tool option for GNU/Linux?

like image 665
Sandeep Singh Avatar asked Jul 24 '11 09:07

Sandeep Singh


2 Answers

You may be able to use the -i option (to output the instruction pointer at the time of the call) in strace and ltrace, combined with addr2line to resolve the calls to lines of code.

like image 103
Hasturkun Avatar answered Oct 13 '22 12:10

Hasturkun


No It's not possible. Why don't you use gdb for this purpose?

When you are compiling application with gcc use -ggdb flags to get debugger info into your program and then run your program with gdb or equivalent frontend (ddd or similar)

Here is quick gdb manual to help you out a bit. http://www.cs.cmu.edu/~gilpin/tutorial/

like image 22
damir Avatar answered Oct 13 '22 11:10

damir