Is there a way to set break point via cmd line on using GDB.
Currently on running GDB, I need to set
(gdb) b fun1
(gdb) b fun2
(gdb) b fun3
and If I close and open the GDB again, I need to set all the break points :( . Is there a way to set break point for GDB in cmd line itself, like
$> gdb -break fun1 -break fun2 -break fun3 ./myprog
Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main.
Creates a breakpoint at a specified line, address or function.
You can use breakpoint commands to start your program up again. Simply use the continue command, or step , or any other command that resumes execution. Any other commands in the command list, after a command that resumes execution, are ignored.
break function-name will set a breakpoint at the start of the function.
GDB Provides -ex option to set GDB commands such as 'break' 'info' 'set print' 'display x' on invoking GDB from command line, as shown below
$> gdb -ex 'break main' -ex 'info b' -ex 'set print pretty on' ./myprog
The option of -ex option is not specified in man page or in GDB help :(
Put your break
commands in a file, and pass the file to gdb on the command line using the -x
flag.
From man gdb
:
-x file Execute GDB commands from file file.
It turns out that there is a command for similarly passing commands, but on the command line: both -ex
and -eval-command
allow you to pass an individual command. It appears to have been introduced in version 7: it's unavailable on gdb 6.3.5, but available in 7.3.1. -ex
and -eval-command
are documented in the online gdb docs with the other command-line arguments here.
So, for your example:
$> gdb -ex 'break fun1' -ex 'break fun2' -ex 'break fun3' ./myprog
The other answers schooled me on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With