Commandes GDB que vous ne connaissez peut-être pas







Le débogage du code est comme la chasse. Chasse aux insectes.

- Amit Kalantri


Qu'est-ce que GDB



GNU Debugger est un débogueur portable pour le projet GNU qui fonctionne sur de nombreux systèmes de type UNIX et peut déboguer de nombreux langages de programmation, notamment C, C ++, Free Pascal, FreeBASIC, Ada, Fortran et Rust. GDB est un logiciel libre publié sous licence GPL.

Source: Débogueur GNU - Wikipédia







GDB — , .







, , , GDB.







, — , . , , :







Caesar::shift Caesar
Caesar::ChangeShift Caesar
Caesar::Crypt Caesar


(TUI)



TUI, GDB, , , . TUI GDB tui enable









( ) - . Ctrl + p (previous), Ctrl + n (next), ( ).







: - tui enable



, — tui disable



.









breakpoint



( — b).

:







  • ()
  • ,


, — .







b Method if variable == value



— .







:







(gdb) b Crypt if Caesar::shift == 1
Note: breakpoint 2 also set at pc 0x4026e3.
Breakpoint 4 at 0x4026e3: file Caesar.h, line 55.
      
      





Crypt()



, Caesar



shift



1.







: delete



, d



.







: : , , , .







Scope,



next



step



(: n s) , next Scope ( ), step Step In .







: continue



, finish



fin



.







: step



, — next



.









. print



p



, .







display



display



,







(gdb) display Caesar::shift
1: Caesar::shift = <error: Cannot reference non-static field "shift">
(gdb) n

Breakpoint 2, Caesar::Crypt (this=0x7fffffffdc30, text="Crypt this text! Btw, xyz") at Caesar.h:55
1: Caesar::shift = 1
(gdb) n
1: Caesar::shift = 1
(gdb)
      
      





:







(gdb) display *stringArrayForOutput@lengthOfArray
1: *stringArrayForOutput@lengthOfArray = {"Etarv vjku vgzv! Dvy, zab", "Fubsw wklv whaw! Ewz, abc", "Gvctx xlmw xibx! Fxa, bcd"}
(gdb) 
      
      





, lengthOfArray



( ) . GDB .







explore



, , , explore



.







explore



,







(gdb) explore Caesar::shift
'Caesar::shift' is a scalar value of type 'int'.
Caesar::shift = 6

(gdb) explore Caesar
'Caesar' is a struct/class with the following fields:

letters = <Enter 0 to explore this field of type 'std::string'>
shift = <Enter 1 to explore this field of type 'int'>
      
      





: print



explore



display



.









" " , , record



, ,







(gdb) target record-full
(gdb) p Caesar::shift
$1 = 6
(gdb) n
(gdb) p Caesar::shift
$2 = 7
(gdb) reverse-next

No more reverse-execution history.
(gdb) p Caesar::shift
$3 = 6
      
      





, — record stop



, , record save < >



.







: GDB , , .









info local



:







(gdb) info local
mainObj = {letters = "abcdefghijklmnopqrstuvwxyz", shift = 1}
textForC = "Crypt this text! Btw, xyz"
cryptedText = "Dszqu uijt ufyu! Cux, yza"
outputVariants = 0x402280 <_start>
      
      





, info variables



:







(gdb) info variables
All defined variables:

File /usr/include/c++/10/bits/basic_string.h:
101:    const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size_type std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::npos;

File /usr/include/c++/10/bits/stl_pair.h:
83:     static const std::piecewise_construct_t std::piecewise_construct;

File /usr/include/c++/10/iostream:
74:     static std::ios_base::Init std::__ioinit;

Non-debugging symbols:
0x00000000004002e8  __abi_tag
0x0000000000403000  _IO_stdin_used
0x00000000004031b8  typeinfo for std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
0x00000000004031e0  typeinfo name for std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
--Type <RET> for more, q to quit, c to continue without paging--
      
      





info b



:







(gdb) info b   
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000402633 in Caesar::ChangeShift() at Caesar.h:31
        breakpoint already hit 1 time
2       breakpoint     keep y   0x00000000004026e3 in Caesar::Crypt(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) at Caesar.h:55
        breakpoint already hit 1 time
      
      





whatis



:







(gdb) whatis Caesar::shift
type = int
(gdb) whatis Caesar
type = Caesar
      
      





, info address



:







(gdb) info address Caesar::Crypt
Symbol "Caesar::Crypt(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)" is a function at address 0x4026be.
      
      







, , , , , . Linux -, . - , Unix- .







Cet article n'inclut pas certaines commandes faciles à comprendre , par exemple: exécuter, arrêter, quitter, etc. Je ne les ai pas spécifiés exprès, car l'article tente de transmettre des informations que les utilisateurs de GDB pourraient ne pas connaître. Si vous avez des suggestions pour compléter l'article, je lirai volontiers les commentaires.








All Articles