GDB рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдПрдХ рд╕рдВрдХреНрд╖рд┐рдкреНрдд рдЧрд╛рдЗрдб


рдЗрд╕ рдЫреЛрдЯреЗ рдЯреНрдпреВрдЯреЛрд░рд┐рдпрд▓ рдореЗрдВ рд╣рдо GDB рдХреЗ рд╕рд╛рде рдХрд╛рдо рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдмреБрдирд┐рдпрд╛рджреА рддрдХрдиреАрдХреЛрдВ рдХреЛ рджреЗрдЦреЗрдВрдЧреЗ, рдФрд░ рдпрд╣ рднреА рджреЗрдЦреЗрдВрдЧреЗ рдХрд┐ рдЖрдк GDB рдХреЗ рд▓рд┐рдП рдбрд┐рдмрдЧрд┐рдВрдЧ рдХреЗ рд▓рд┐рдП рдлрд╛рдЗрд▓ рдХреИрд╕реЗ рддреИрдпрд╛рд░ рдХрд░ рд╕рдХрддреЗ рд╣реИрдВ (рдФрд░ рдЪрд╛рд╣рд┐рдП)ред


GDB GNU рдкреНрд░реЛрдЬреЗрдХреНрдЯ рдХрд╛ рдПрдХ рдкреЛрд░реНрдЯреЗрдмрд▓ рдбрд┐рдмрдЧрд░ рд╣реИ рдЬреЛ рдХрдИ UNIX рдЬреИрд╕реА рдкреНрд░рдгрд╛рд▓рд┐рдпреЛрдВ рдкрд░ рдЪрд▓рддрд╛ рд╣реИ рдФрд░ C, C ++, Free Pascal, FreeBASIC, Ada, Fortran, Python3, Swift, NASM рдФрд░ Rust рд╕рд╣рд┐рдд рдХрдИ рдкреНрд░реЛрдЧреНрд░рд╛рдорд┐рдВрдЧ рднрд╛рд╖рд╛рдУрдВ рдХреЛ рдбреАрдмрдЧ рдХрд░ рд╕рдХрддрд╛ рд╣реИред


gdb


GDB? , UNIX- , . , VSCode ( Vim, NeoVim ( ), Emacs, Atom )



.cpp .


G++ -g ( , , GDB).


g++ -g file_name.cpp -o output_name
gdb output_name

Python- :


gdb -ex r --args python program_name.py <arguments>

Java jdb, c JDK.


, , OnlineGDB, debug, , .


GDB


GDB :


GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from 3_Hero's_Inventory.cpp...done.

, .


, (, ), cpp main(). c list b ( b main ):


(gdb) list
1   #include <iostream>
2   #include <string>
3   
4   using namespace std;
5   
6   int main(int argc, char *argv[])
7   {
8       // Hero's Inventory - ,     
9   
10      const int MAX_ITEMS = 10; //  ,    

(gdb) b 6
Breakpoint 1 at 0xcb5: file ./3_Hero's_Inventory.cpp, line 6.

r:


(gdb) r
Starting program: /home/username77177/gitprojects/learning/cpp/build_folder/3_Hero's_Inventory.cpp 

Breakpoint 1, main (argc=1, argv=0x7fffffffdd18) at ./3_Hero's_Inventory.cpp:7
7   {

TUI, <Ctrl-x a>


, , f:


(gdb) f
#0  main (argc=1, argv=0x7fffffffdd18) at ./3_Hero's_Inventory.cpp:14
14      items[itemnum++] = "Sword";

, , n ( next):


(gdb) n
10      const int MAX_ITEMS = 10; //  ,    

GDB ( ) .
, , n , , " " (step-in) s:


(gdb) s
11      string items[MAX_ITEMS]; //     c 10 

( , step-in , )


() info locals:


(gdb) info locals
MAX_ITEMS = 10
items = {"", "", "", "", "", "", "", "", "", ""}
itemnum = 0
game = 247

, print _:


(gdb) print MAX_ITEMS 
$1 = 10

set:


(gdb) set x = 77177
(gdb) print x
$1 = 77177

watch:


watch x

, (info registers):


(gdb) info registers 
rax            0x7fffffffdc00   140737488346112
rbx            0xffffffffffffffff   -1
rcx            0xa0 160
rdx            0x7fffffffdd28   140737488346408
rsi            0x7fffffffdd18   140737488346392
rdi            0x7fffffffdbf0   140737488346096
rbp            0x7fffffffdc30   0x7fffffffdc30
rsp            0x7fffffffdab0   0x7fffffffdab0
r8             0x7ffff782fd80   140737345944960
r9             0x0  0
r10            0x6  6
r11            0x7ffff7b77020   140737349382176
r12            0x7fffffffdc10   140737488346128
r13            0x7fffffffdd10   140737488346384
r14            0x0  0
r15            0x0  0
rip            0x555555554cfe   0x555555554cfe <main(int, char**)+100>
eflags         0x286    [ PF SF IF ]
cs             0x33 51
ss             0x2b 43
ds             0x0  0
es             0x0  0
fs             0x0  0
gs             0x0  0

breakpoints ( ) info breakpoints:


(gdb) info breakpoints 
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000555555554cb5 in main(int, char**) 
                                                   at ./3_Hero's_Inventory.cpp:6
    breakpoint already hit 1 time
2       breakpoint     keep y   0x0000555555554cfe in main(int, char**) 
                                                   at ./3_Hero's_Inventory.cpp:14

del breakpoint_num:


(gdb) info breakpoints 
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000555555554cb5 in main(int, char**) 
                                                   at ./3_Hero's_Inventory.cpp:6
    breakpoint already hit 1 time
2       breakpoint     keep y   0x0000555555554cfe in main(int, char**) 
                                                   at ./3_Hero's_Inventory.cpp:14

(gdb) del 1

(gdb) info breakpoints 
Num     Type           Disp Enb Address            What
2       breakpoint     keep y   0x0000555555554cfe in main(int, char**) 
                                                   at ./3_Hero's_Inventory.cpp:14

c:


(gdb) r
Starting program: /home/username77177/gitprojects/learning/cpp/build_folder/3_Hero's_Inventory.cpp 

Breakpoint 3, main (argc=1, argv=0x7fffffffdd18) at ./3_Hero's_Inventory.cpp:7
7   {
(gdb) c
Continuing.

Breakpoint 2, main (argc=1, argv=0x7fffffffdd18) at ./3_Hero's_Inventory.cpp:14
14      items[itemnum++] = "Sword";

() call:


(gdb) call MyFunction()

рдлрд╝рдВрдХреНрд╢рди рдХреЗ рдирд┐рд╖реНрдкрд╛рджрди рдХреЛ рдЬрд╛рд░реА рд░рдЦрдиреЗ рдХреЗ рд▓рд┐рдП рдФрд░ рдЬрдм рдпрд╣ (рдлрд╝рдВрдХреНрд╢рди) рд╕рдорд╛рдкреНрдд рд╣реЛрддрд╛ рд╣реИ, рддреЛ рдЖрдкрдХреЛ рдкреНрд░реЛрдЧреНрд░рд╛рдо рдХреЛ рд░реЛрдХрдирд╛ рд╣реЛрдЧрд╛, рдЖрдкрдХреЛ рд▓рд┐рдЦрдирд╛ рд╣реЛрдЧрд╛ finishрдпрд╛ fin:


(gdb) fin

рдпрд╣ рд╕реНрдкрд╖реНрдЯ рдХрд░рдиреЗ рдпреЛрдЧреНрдп рд╣реИ рдХрд┐ рдЗрд╕рдХрд╛ рдЙрдкрдпреЛрдЧ finishрдореБрдЦреНрдп рд╡рд┐рдзрд┐ рдореЗрдВ рдирд╣реАрдВ рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИ ред


рдХрд╛рд░реНрдпрдХреНрд░рдо рдХреЛ рдкреВрд░рд╛ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП, рдЖрдкрдХреЛ рд▓рд┐рдЦрдирд╛ рд╣реЛрдЧрд╛ kill:


(gdb) kill
Kill the program being debugged? (y or n) y

рдЖрдк helpрдХрд┐рд╕реА рднреА рд╕рдордп рд▓рд┐рдЦ рд╕рдХрддреЗ рд╣реИрдВ рдФрд░ рдбрд┐рдмрдЧрд░ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдиреЗ рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдПрдХ рд╕рдВрдХреНрд╖рд┐рдкреНрдд рд╕рд╣рд╛рдпрддрд╛ рдкреНрд░рд╛рдкреНрдд рдХрд░ рд╕рдХрддреЗ рд╣реИрдВ


(gdb) help
List of classes of commands:

aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
user-defined -- User-defined commands

Type "help" followed by a class name for a list of commands in that class.
Type "help all" for the list of all commands.
Type "help" followed by command name for full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.

All Articles