mirror of
https://github.com/Hizenberg469/GDB-tutorial.git
synced 2026-04-19 13:52:24 +03:00
TUI completed
This commit is contained in:
287
gdb-tui.txt
Normal file
287
gdb-tui.txt
Normal file
@@ -0,0 +1,287 @@
|
||||
Section 6: GDB Text User Interface (TUI):
|
||||
-----------------------------------------
|
||||
|
||||
-> GDB the Text User Interface (TUI):
|
||||
+++++++++++++++++++++++++++++++++
|
||||
|
||||
To run gdb along with the source code for easy analysis
|
||||
along the program execution in CLI, we can use TUI.
|
||||
|
||||
* To open gdb along with TUI...
|
||||
|
||||
Command:
|
||||
$ gdb --tui ./<program-name>
|
||||
|
||||
* If gdb is already in execution and to open source code for
|
||||
when there is already a program which is being debugged.
|
||||
|
||||
Command:
|
||||
(gdb) layout src
|
||||
|
||||
Note:
|
||||
To checkout what other things layout command perform.
|
||||
|
||||
(gdb) help layout
|
||||
|
||||
Keybindings:
|
||||
To cycle through various layout we use.
|
||||
|
||||
Key-Bind:
|
||||
CTRL + x -- 2
|
||||
|
||||
* To navigate through windows if there is different window
|
||||
present, for example, having source code and GDB CLI
|
||||
window, we can use:
|
||||
|
||||
Key-Bind:
|
||||
CTRL + x -- o
|
||||
|
||||
* To achieve the same feat without using this key binds and
|
||||
using only commands, we can use:
|
||||
|
||||
Command:
|
||||
(gdb) focus cmd -> To focus to gdb CLI
|
||||
|
||||
OR
|
||||
|
||||
(gdb) focus src -> To focus on source code.
|
||||
|
||||
|
||||
Note:
|
||||
If the focus is on source window and we want to
|
||||
navigate to previous or next command on gdb CLI.
|
||||
|
||||
We can use:
|
||||
|
||||
Key-binds:
|
||||
|
||||
CTRL + p -> To previous command
|
||||
CTRL + n -> To next command
|
||||
|
||||
* To resize the windows, we can use:
|
||||
|
||||
Command:
|
||||
(gdb) winheight <window-name> <value by which we to change the size>
|
||||
|
||||
For ex:
|
||||
(gdb) winheight src -2
|
||||
|
||||
To shrink the size of source window by 2.
|
||||
|
||||
|
||||
Note:
|
||||
|
||||
Sometimes while executing some command our screen gets
|
||||
messed up due the execution of program which is being
|
||||
debugged. To clear the mess and make it look clean
|
||||
we can use..
|
||||
|
||||
Command:
|
||||
(gdb) refresh
|
||||
|
||||
Key-bind:
|
||||
CTRL + l
|
||||
|
||||
|
||||
-> Redirecting output from GDB (to another file or terminal):
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
* While analysing the program under gdb with TUI, executing
|
||||
commands can mess up the UI making it sometime frustrating
|
||||
to debug. Instead, we can redirect the output of the
|
||||
program in gdb to other terminal using...
|
||||
|
||||
|
||||
Command:
|
||||
tty
|
||||
(Remember to type this command in another terminal.
|
||||
|
||||
To allow the output to be redirected from gdb to the terminal
|
||||
where the above command is executed we can use...
|
||||
|
||||
Command:
|
||||
(gdb)tty /dev/pts/<num>
|
||||
|
||||
Now because of the above operation all the gdb output will
|
||||
be redirected to the other intended terminal.
|
||||
|
||||
* If we want to capture the content to a file and save we can
|
||||
use command:
|
||||
|
||||
Command:
|
||||
(gdb)run > <filename>
|
||||
|
||||
-> Conditional Breakpoints:
|
||||
++++++++++++++++++++++++
|
||||
|
||||
* There are 2 types of breakpoints that we have learnt till
|
||||
now and that are:
|
||||
1. Temporary breakpoint
|
||||
Stop the execution only once.
|
||||
|
||||
2. breakpoint (permanent breakpoint)
|
||||
Stop the execution each time the breakpoint got hit
|
||||
and remains until the current gdb session or explicitly
|
||||
deleted.
|
||||
|
||||
There is another type of breakpoint that we can use.
|
||||
|
||||
==Conditional breakpoint==
|
||||
|
||||
This breakpoint will stop the execution only when certain
|
||||
condition that we define is met.
|
||||
|
||||
|
||||
Command:
|
||||
br <line-number> if <conditions>
|
||||
|
||||
The <conditions> should follow the C syntax.
|
||||
|
||||
For ex:
|
||||
|
||||
br 9 if i > 343
|
||||
Where i is some variable which is present in
|
||||
the source.
|
||||
|
||||
Note:
|
||||
|
||||
To delete any breakpoint of any type use...
|
||||
Command:
|
||||
|
||||
delete <num>
|
||||
where <num> is the index number of breakpoints
|
||||
when we print the list of breakpoint using
|
||||
command >>> info breakpoint <<<
|
||||
|
||||
|
||||
-> More ways to continue and step through code (advance, and until):
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
|
||||
Command:
|
||||
(gdb)advance <args>
|
||||
Here, <args> can be function name, line numbers.
|
||||
|
||||
* This command is used to advance our program execution till certain points.
|
||||
|
||||
Command:
|
||||
(gdb)until <args>
|
||||
Here, <args> can be numbers.
|
||||
|
||||
* This command will execute the program until we reach the location which
|
||||
is passed as an argument to the command.
|
||||
|
||||
Command:
|
||||
(gdb)jump <args>
|
||||
|
||||
Here, <args> is a address.
|
||||
|
||||
* This is helpful in terms of asm code and we can jump to certain location
|
||||
in code, directly. However, giving random address will give output that
|
||||
no function is defined in this address and providing illegal address
|
||||
leads to crash in program.
|
||||
|
||||
-> Watching (watch and rwatch) Variables:
|
||||
++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
These are great tools to inspect the memory locations and break the execution
|
||||
when there is a read or write operation performed on these memory locations.
|
||||
|
||||
Command:
|
||||
(gdb)watch <expr>
|
||||
where <expr> can be a variable name.
|
||||
|
||||
This command is used to watch a memory location when there is a change
|
||||
or write operation is performed in it.
|
||||
|
||||
(gdb)rwatch <expr>
|
||||
|
||||
This command is used to watch a memory location when there is a read
|
||||
operations is performed in it.
|
||||
|
||||
-> Breakpoints Part 2 (enable, disable and save breakpoint):
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
|
||||
Lets say while analyzing a program under gdb, we have created lot of breakpoints
|
||||
and for the the time being we don't want to stop at each breakpoints we created,
|
||||
but we also don't want to delete it.
|
||||
|
||||
For that, we can disable the breakpoint.
|
||||
|
||||
Command:
|
||||
(gdb)disable <num>
|
||||
where <num> represent the index of the breakpoint.
|
||||
|
||||
To enable the break point we can use...
|
||||
|
||||
Command:
|
||||
(gdb)enable <num>
|
||||
|
||||
|
||||
Lets say we are exiting out of the gdb for some reason, but we don't want
|
||||
to again create all the breakpoints and we can save it somewhere it
|
||||
might be helpful to use it later.
|
||||
|
||||
Command:
|
||||
(gdb)save breakpoints <filename>
|
||||
|
||||
It will save all the breakpoints with it current snapshot and we can use it for
|
||||
latter.
|
||||
|
||||
To load the saved breakpoints later, we can use...
|
||||
|
||||
Command:
|
||||
(gdb)source <filename>
|
||||
|
||||
|
||||
-> Display and undisplay:
|
||||
++++++++++++++++++++++
|
||||
|
||||
* To display the value of certain variable when the execution stop at certain
|
||||
point after the latest command, we can use...
|
||||
|
||||
Command:
|
||||
(gdb) display <expr>
|
||||
|
||||
where <expr> can be variable, address of variable..
|
||||
|
||||
* To see the list of current expression to display.
|
||||
|
||||
Command:
|
||||
(gdb)info display
|
||||
|
||||
* To undisplay the expressions if we want to, we can use...
|
||||
|
||||
Command:
|
||||
(gdb)undisplay <index>
|
||||
|
||||
where <index> correponds to particular expression
|
||||
which is used for display.
|
||||
|
||||
* To display the value of expression under expections.
|
||||
|
||||
Command:
|
||||
(gdb) display /b <expr>
|
||||
|
||||
|
||||
-> Getting help in GDB (info):
|
||||
+++++++++++++++++++++++++++
|
||||
|
||||
To know about gdb and its command:
|
||||
|
||||
Use:
|
||||
$man gdb
|
||||
This is the manual for gdb
|
||||
|
||||
|
||||
To know about gdb commands.
|
||||
|
||||
Command:
|
||||
(gdb)help <command>
|
||||
display the relivant command and information regarding that.
|
||||
|
||||
To know get more detailed information.
|
||||
(gdb)apropos <command>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user