I want to debug some program. I need backtraces from all calls to some function, e.g. puts.

Now I use such gdb script:

set width 0
set height 0
set verbose off
break puts
commands 1
backtrace
continue
end

But starting it with

gdb --batch --command=script --args ./some_program arguments

Gives a error:

Function "puts" not defined.
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
/root/script:5: Error in sourced command file:
No breakpoint number 1.

How can I set breakpoint in script for library call?

share|improve this question
up vote 18 down vote accepted

Try this instead:

set width 0
set height 0
set verbose off
start  # runs to main, so shared libraries are loaded
       # after you reach main, GDB should have libc symbols, "puts" among them
break puts
commands 1
backtrace
continue
end

If this doesn't work, please state operating system version.

EDIT: as osgx correctly points out, the other alternative is to add

set breakpoint pending on

before break puts

share|improve this answer
1  
And what about " breakpoint pending" setting? А еще - спасибо. – osgx Mar 9 '10 at 19:14
6  
You can use start instead of break main; run – R Samuel Klatchko Mar 10 '10 at 1:02
    
Yes, start is better. Answer fixed, thanks! – Employed Russian Mar 10 '10 at 7:28
1  
On my system, the start command created a breakpoint, so commands needed 2 instead of 1. – doug65536 Jun 1 '13 at 7:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.