Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to confirm action (answer "Y") in gdb script?

I use gdb to debug my cpp code. I set breakpoints in this way:

(gdb) break ParseDriver.cc:60 No source file named ParseDriver.cc. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (ParseDriver.cc:60) pending. 

To simplify setting breakpoints, I wrote a simple gdb script(named breakpoints.gdb), it simply contains only one line:

break ParseDriver.cc:60 

I source this script in gdb terminal, but it failed.

(gdb) source ~/breakpoints.gdb No source file named ParseDriver.cc. Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal] 

It seems that we need to answer Y in script in order to set breakpoint.

So, how can I answer Y in gdb script ? Thank you in advance.

like image 561
hellojinjie Avatar asked Jul 06 '12 05:07

hellojinjie


People also ask

How do you add a break point in GDB?

You can also set breakpoints on function names. To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.

What is watchpoint in GDB?

If GDB creates a software watchpoint, it can only watch the value of an expression in a single thread. If you are confident that the expression can only change due to the current thread's activity (and if you are also confident that no other thread can become current), then you can use software watchpoints as usual.

How do I run a script in GDB?

Use the run command to start your program under GDB. You must first specify the program name (except on VxWorks) with an argument to GDB (see section Getting In and Out of GDB), or by using the file or exec-file command (see section Commands to specify files).


1 Answers

(gdb) set breakpoint pending on 

This will make gdb skip asking for confirmation, quote from the docs:

This indicates that an unrecognized breakpoint location should automatically result in a pending breakpoint being created.

like image 103
matt Avatar answered Oct 04 '22 07:10

matt