From 8ac6452acebd3f392388333dafe9d663442117d4 Mon Sep 17 00:00:00 2001 From: Hizenberg Date: Sun, 12 Oct 2025 17:46:37 +0000 Subject: [PATCH] TUI completed --- gdb-tui.txt | 287 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gdb.txt | 6 ++ 2 files changed, 293 insertions(+) create mode 100644 gdb-tui.txt diff --git a/gdb-tui.txt b/gdb-tui.txt new file mode 100644 index 0000000..0eacb56 --- /dev/null +++ b/gdb-tui.txt @@ -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 ./ + + * 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 + + 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/ + + 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 > + +-> 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 if + + The 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 + where 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 + Here, can be function name, line numbers. + + * This command is used to advance our program execution till certain points. + + Command: + (gdb)until + Here, 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 + + Here, 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 + where 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 + + 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 + where represent the index of the breakpoint. + + To enable the break point we can use... + + Command: + (gdb)enable + + + 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 + + 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 + + +-> 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 + + where 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 + + where correponds to particular expression + which is used for display. + + * To display the value of expression under expections. + + Command: + (gdb) display /b + + +-> 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 + display the relivant command and information regarding that. + + To know get more detailed information. + (gdb)apropos + + diff --git a/gdb.txt b/gdb.txt index 7c78593..6d33615 100644 --- a/gdb.txt +++ b/gdb.txt @@ -211,6 +211,12 @@ Command: break These are permanent breakpoint + Note: To delete a breakpoint we can use + command + + Command: + (gdb)delete + Command: layout src To open the TUI with src code.