To start gdb and attach to a program that is not running
gdb applicationName
To start gdb and attach to an Already Running Process
Firstly, get the pid of the running process;
ps -C processName -o pid h
then;
gdb -p [pid from above]
alternatively, in one go;
gdb -p $(ps -C processName -o pid h)
The following from https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/developer_guide/debugging-running-application
GDB Commands to Step Through the Code
r
(run)- Start the execution of the program. If
run
is executed with any arguments, those arguments are passed on to the executable as if the program has been started normally. Users normally issue this command after setting breakpoints. start
- Start the execution of the program, and stop at the beginning of the program’s main function. If
start
is executed with any arguments, those arguments are passed on to the executable as if the program has been started normally.
c
(continue)Continue the execution of the program from the current state. The execution of the program will continue until one of the following becomes true:
- A breakpoint is reached
- A specified condition is satisfied
- A signal is received by the program
- An error occurs
- The program terminates
n
(next)Continue the execution of the program from the current state, until next line of code in the current source file is reached. The execution of the program will continue until one of the following becomes true:
- A breakpoint is reached
- A specified condition is satisfied
- A signal is received by the program
- An error occurs
- The program terminates
s
(step)- The
step
command also halts execution at each sequential line of code in the current source file. However, if the execution is currently stopped at a source line containing a function call, GDB stops the execution after entering the function call (rather than executing it). until
location- Continue the execution until the code location specified by the location option is reached.
fini
(finish)- Resume the execution of the program and halt when execution returns from a function.
- The execution of the program will continue until one of the following becomes true:
- A breakpoint is reached
- A specified condition is satisfied
- A signal is received by the program
- An error occurs
- The program terminates
q
(quit)- Terminate the execution and exit GDB.
To see variable values, use;
print varName
To set a variable values, use;
set varName = newValue
No comments:
Post a Comment
Note: only a member of this blog may post a comment.