SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Основы отладки в GDB
Arguments & environment Stack unused memory Heap Uninitialized data Initialized data Text
int main(int argc, char *argv[]) { int number; int *pointer; number = atoi(argv[1]); pointer = number; print(number); return 0; } void print(int *x) { printf("The number supplied is %d", *x); }
$ gcc -o test test.c test.c: In function ‘main’: test.c:7:13: warning: assignment makes pointer from integer without a cast test.c: At top level: test.c:8:5: note: previous implicit declaration of ‘print’ was here test.c: In function ‘print’: test.c:15:5: warning: incompatible implicit declaration of built-in function ‘printf’ $ ./test  Segmentation fault
$ gdb test Reading symbols from /home/user/test...(no debugging symbols found)...done. (gdb) run Starting program: /home/user/test  Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7a82b35 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) backtrace #0  0x00007ffff7a82b35 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #1  0x00007ffff7a7f900 in atoi () from /lib/x86_64-linux-gnu/libc.so.6 #2  0x000000000040056b in main ()
(gdb) x/10i $rip => 0x7ffff7a82b35:  movzbl (%rbx),%eax 0x7ffff7a82b38:  mov  0x68(%r8),%r9 0x7ffff7a82b3c:  mov  %rbx,%r13 0x7ffff7a82b3f:  movsbq %al,%rcx 0x7ffff7a82b43:  testb  $0x20,0x1(%r9,%rcx,2) 0x7ffff7a82b49:  je  0x7ffff7a82b65 0x7ffff7a82b4b:  nopl  0x0(%rax,%rax,1) 0x7ffff7a82b50:  add  $0x1,%r13 0x7ffff7a82b54:  movzbl 0x0(%r13),%eax 0x7ffff7a82b59:  movsbq %al,%rcx
 
(gdb) info registers rax  0x0  0 rbx  0x0  0 rcx  0x0  0 rdx  0xa  10 rsi  0x0  0 rdi  0x0  0 rbp  0x7fffffffe160  0x7fffffffe160 rsp  0x7fffffffe0c0  0x7fffffffe0c0 rip  0x7ffff7a82b35  0x7ffff7a82b35 eflags  0x10283  [ CF SF IF RF ] cs  0x33  51 ss  0x2b  43 ...
(gdb) info locals No symbol table info available. (gdb) info args No symbol table info available. (gdb) quit A debugging session is active. Inferior 1 [process 29043] will be killed. Quit anyway? (y or n) y
$ gcc  -g  -o test test.c $ gdb test Reading symbols from /home/ium/test...done. (gdb) list 1  int main(int argc, char *argv[]) 2  { 3  int number; 4  int *pointer; 5 6  number = atoi(argv[1]); 7  pointer = number; 8  print(number); 9 10  return 0;
(gdb) break 6 Breakpoint 1 at 0x400553: file test.c, line 6. (gdb) run Starting program: /home/ium/test  Breakpoint 1, main (argc=1, argv=0x7fffffffe248) at test.c:6 6  number = atoi(argv[1]); (gdb) print argv[1] $1 = 0x0
(gdb) continue Continuing. Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7a82b35 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) delete Delete all breakpoints? (y or n) y (gdb) run 255 The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /home/user/test 255 Program received signal SIGSEGV, Segmentation fault. 0x000000000040059f in print (x=0xff) at test.c:15 15  printf("The number supplied is %d", *x);
(gdb) backtrace #0  0x000000000040059f in print (x=0xff) at test.c:15 #1  0x0000000000400588 in main (argc=2, argv=0x7fffffffe228) at test.c:8 (gdb) info args x = 0xff (gdb) frame 1 #1  0x0000000000400588 in main (argc=2, argv=0x7fffffffe228) at test.c:8 8  print(number);
(gdb) info locals number = 255 pointer = 0xff (gdb) frame 0 (gdb) x /5i $rip => 0x40059f <print+16>: mov  (%rax),%eax 0x4005a1 <print+18>: mov  %eax,%esi 0x4005a3 <print+20>: mov  $0x4006ac,%edi 0x4005a8 <print+25>: mov  $0x0,%eax 0x4005ad <print+30>: callq  0x400428 <print@plt> (gdb) x /s 0x4006ac 0x4006ac:  &quot;The number supplied is %d&quot;
(gdb) info registers rax  0xff  255 rbx  0x0  0 rcx  0x5  5 rdx  0x40058f 4195727 rsi  0x0  0 rdi  0xff  255 rbp  0x7fffffffe110  0x7fffffffe110 rsp  0x7fffffffe100  0x7fffffffe100 rip  0x40059f 0x40059f <print+16> eflags  0x10206  [ PF IF RF ] cs  0x33  51 ss  0x2b  43
 
(gdb) disassemble print Dump of assembler code for function print: 0x000000000040058f <+0>:  push  %rbp 0x0000000000400590 <+1>:  mov  %rsp,%rbp 0x0000000000400593 <+4>:  sub  $0x10,%rsp 0x0000000000400597 <+8>:  mov  %rdi,-0x8(%rbp) 0x000000000040059b <+12>:  mov  -0x8(%rbp),%rax => 0x000000000040059f <+16>:  mov  (%rax),%eax 0x00000000004005a1 <+18>:  mov  %eax,%esi 0x00000000004005a3 <+20>:  mov  $0x4006ac,%edi 0x00000000004005a8 <+25>:  mov  $0x0,%eax 0x00000000004005ad <+30>:  callq  0x400428 <printf> 0x00000000004005b2 <+35>:  leaveq  0x00000000004005b3 <+36>:  retq   End of assembler dump.
 
(gdb) x /4xg $rsp 0x7fffffffe170: 0x0000000000000000  0x00000000000000ff 0x7fffffffe180: 0x00007fffffffe1b0  0x0000000000400588 (gdb) print $rbp $1 = (void *) 0x7fffffffe180
 
 

Weitere ähnliche Inhalte

Was ist angesagt?

2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - englishJen Yee Hong
 
Using the Power to Prove
Using the Power to ProveUsing the Power to Prove
Using the Power to ProveKazuho Oku
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesEric Poe
 
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with PerlKazuho Oku
 
Playing 44CON CTF for fun and profit
Playing 44CON CTF for fun and profitPlaying 44CON CTF for fun and profit
Playing 44CON CTF for fun and profit44CON
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers ToolboxStefan
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話tatsunori ishikawa
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!Boy Baukema
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Lin Yo-An
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureAmaury Bouchard
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaPatrick Allaert
 

Was ist angesagt? (20)

Php engine
Php enginePhp engine
Php engine
 
Usp
UspUsp
Usp
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
 
Using the Power to Prove
Using the Power to ProveUsing the Power to Prove
Using the Power to Prove
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with Perl
 
Playing 44CON CTF for fun and profit
Playing 44CON CTF for fun and profitPlaying 44CON CTF for fun and profit
Playing 44CON CTF for fun and profit
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers Toolbox
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話
 
Php 5.6
Php 5.6Php 5.6
Php 5.6
 
node ffi
node ffinode ffi
node ffi
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
Yg byev2e
Yg byev2eYg byev2e
Yg byev2e
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heure
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 Verona
 
Virtual Machine Constructions for Dummies
Virtual Machine Constructions for DummiesVirtual Machine Constructions for Dummies
Virtual Machine Constructions for Dummies
 

Andere mochten auch

Andere mochten auch (9)

Objective-C: Good and Bad
Objective-C: Good and BadObjective-C: Good and Bad
Objective-C: Good and Bad
 
Программирование Linux
Программирование LinuxПрограммирование Linux
Программирование Linux
 
Программирование Linux
Программирование LinuxПрограммирование Linux
Программирование Linux
 
20120424 b
20120424 b20120424 b
20120424 b
 
Mach-O Internals
Mach-O InternalsMach-O Internals
Mach-O Internals
 
iOS History
iOS HistoryiOS History
iOS History
 
Кратко о Mac OS X
Кратко о Mac OS XКратко о Mac OS X
Кратко о Mac OS X
 
Nmap Basics
Nmap BasicsNmap Basics
Nmap Basics
 
Основы Reverse Engineering
Основы Reverse EngineeringОсновы Reverse Engineering
Основы Reverse Engineering
 

Ähnlich wie Отладка в GDB

Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdbOwen Hsu
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerPriyank Kapadia
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기Ji Hun Kim
 
Data structures and algorithms unit i
Data structures and algorithms unit iData structures and algorithms unit i
Data structures and algorithms unit isonalisraisoni
 
Introduction to Debuggers
Introduction to DebuggersIntroduction to Debuggers
Introduction to DebuggersSaumil Shah
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricksdutor
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersJen Yee Hong
 
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in JavaRuntime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in JavaJuan Fumero
 
Address/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerAddress/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerPlatonov Sergey
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersAppier
 
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...Linaro
 
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdfLDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdfVedant Gavhane
 

Ähnlich wie Отладка в GDB (20)

Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdb
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
 
05-Debug.pdf
05-Debug.pdf05-Debug.pdf
05-Debug.pdf
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
 
Data structures and algorithms unit i
Data structures and algorithms unit iData structures and algorithms unit i
Data structures and algorithms unit i
 
Introduction to Debuggers
Introduction to DebuggersIntroduction to Debuggers
Introduction to Debuggers
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricks
 
Debugging TV Frame 0x0C
Debugging TV Frame 0x0CDebugging TV Frame 0x0C
Debugging TV Frame 0x0C
 
2 debugging-c
2 debugging-c2 debugging-c
2 debugging-c
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmers
 
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in JavaRuntime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 
C
CC
C
 
C
CC
C
 
Address/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerAddress/Thread/Memory Sanitizer
Address/Thread/Memory Sanitizer
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python Programmers
 
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
 
Debugging TV Frame 0x0D
Debugging TV Frame 0x0DDebugging TV Frame 0x0D
Debugging TV Frame 0x0D
 
Boosting Developer Productivity with Clang
Boosting Developer Productivity with ClangBoosting Developer Productivity with Clang
Boosting Developer Productivity with Clang
 
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdfLDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
 

Kürzlich hochgeladen

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Kürzlich hochgeladen (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Отладка в GDB

  • 2. Arguments & environment Stack unused memory Heap Uninitialized data Initialized data Text
  • 3. int main(int argc, char *argv[]) { int number; int *pointer; number = atoi(argv[1]); pointer = number; print(number); return 0; } void print(int *x) { printf(&quot;The number supplied is %d&quot;, *x); }
  • 4. $ gcc -o test test.c test.c: In function ‘main’: test.c:7:13: warning: assignment makes pointer from integer without a cast test.c: At top level: test.c:8:5: note: previous implicit declaration of ‘print’ was here test.c: In function ‘print’: test.c:15:5: warning: incompatible implicit declaration of built-in function ‘printf’ $ ./test Segmentation fault
  • 5. $ gdb test Reading symbols from /home/user/test...(no debugging symbols found)...done. (gdb) run Starting program: /home/user/test Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7a82b35 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
  • 6. (gdb) backtrace #0 0x00007ffff7a82b35 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff7a7f900 in atoi () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x000000000040056b in main ()
  • 7. (gdb) x/10i $rip => 0x7ffff7a82b35: movzbl (%rbx),%eax 0x7ffff7a82b38: mov 0x68(%r8),%r9 0x7ffff7a82b3c: mov %rbx,%r13 0x7ffff7a82b3f: movsbq %al,%rcx 0x7ffff7a82b43: testb $0x20,0x1(%r9,%rcx,2) 0x7ffff7a82b49: je 0x7ffff7a82b65 0x7ffff7a82b4b: nopl 0x0(%rax,%rax,1) 0x7ffff7a82b50: add $0x1,%r13 0x7ffff7a82b54: movzbl 0x0(%r13),%eax 0x7ffff7a82b59: movsbq %al,%rcx
  • 8.  
  • 9. (gdb) info registers rax 0x0 0 rbx 0x0 0 rcx 0x0 0 rdx 0xa 10 rsi 0x0 0 rdi 0x0 0 rbp 0x7fffffffe160 0x7fffffffe160 rsp 0x7fffffffe0c0 0x7fffffffe0c0 rip 0x7ffff7a82b35 0x7ffff7a82b35 eflags 0x10283 [ CF SF IF RF ] cs 0x33 51 ss 0x2b 43 ...
  • 10. (gdb) info locals No symbol table info available. (gdb) info args No symbol table info available. (gdb) quit A debugging session is active. Inferior 1 [process 29043] will be killed. Quit anyway? (y or n) y
  • 11. $ gcc -g -o test test.c $ gdb test Reading symbols from /home/ium/test...done. (gdb) list 1 int main(int argc, char *argv[]) 2 { 3 int number; 4 int *pointer; 5 6 number = atoi(argv[1]); 7 pointer = number; 8 print(number); 9 10 return 0;
  • 12. (gdb) break 6 Breakpoint 1 at 0x400553: file test.c, line 6. (gdb) run Starting program: /home/ium/test Breakpoint 1, main (argc=1, argv=0x7fffffffe248) at test.c:6 6 number = atoi(argv[1]); (gdb) print argv[1] $1 = 0x0
  • 13. (gdb) continue Continuing. Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7a82b35 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
  • 14. (gdb) delete Delete all breakpoints? (y or n) y (gdb) run 255 The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /home/user/test 255 Program received signal SIGSEGV, Segmentation fault. 0x000000000040059f in print (x=0xff) at test.c:15 15 printf(&quot;The number supplied is %d&quot;, *x);
  • 15. (gdb) backtrace #0 0x000000000040059f in print (x=0xff) at test.c:15 #1 0x0000000000400588 in main (argc=2, argv=0x7fffffffe228) at test.c:8 (gdb) info args x = 0xff (gdb) frame 1 #1 0x0000000000400588 in main (argc=2, argv=0x7fffffffe228) at test.c:8 8 print(number);
  • 16. (gdb) info locals number = 255 pointer = 0xff (gdb) frame 0 (gdb) x /5i $rip => 0x40059f <print+16>: mov (%rax),%eax 0x4005a1 <print+18>: mov %eax,%esi 0x4005a3 <print+20>: mov $0x4006ac,%edi 0x4005a8 <print+25>: mov $0x0,%eax 0x4005ad <print+30>: callq 0x400428 <print@plt> (gdb) x /s 0x4006ac 0x4006ac: &quot;The number supplied is %d&quot;
  • 17. (gdb) info registers rax 0xff 255 rbx 0x0 0 rcx 0x5 5 rdx 0x40058f 4195727 rsi 0x0 0 rdi 0xff 255 rbp 0x7fffffffe110 0x7fffffffe110 rsp 0x7fffffffe100 0x7fffffffe100 rip 0x40059f 0x40059f <print+16> eflags 0x10206 [ PF IF RF ] cs 0x33 51 ss 0x2b 43
  • 18.  
  • 19. (gdb) disassemble print Dump of assembler code for function print: 0x000000000040058f <+0>: push %rbp 0x0000000000400590 <+1>: mov %rsp,%rbp 0x0000000000400593 <+4>: sub $0x10,%rsp 0x0000000000400597 <+8>: mov %rdi,-0x8(%rbp) 0x000000000040059b <+12>: mov -0x8(%rbp),%rax => 0x000000000040059f <+16>: mov (%rax),%eax 0x00000000004005a1 <+18>: mov %eax,%esi 0x00000000004005a3 <+20>: mov $0x4006ac,%edi 0x00000000004005a8 <+25>: mov $0x0,%eax 0x00000000004005ad <+30>: callq 0x400428 <printf> 0x00000000004005b2 <+35>: leaveq 0x00000000004005b3 <+36>: retq End of assembler dump.
  • 20.  
  • 21. (gdb) x /4xg $rsp 0x7fffffffe170: 0x0000000000000000 0x00000000000000ff 0x7fffffffe180: 0x00007fffffffe1b0 0x0000000000400588 (gdb) print $rbp $1 = (void *) 0x7fffffffe180
  • 22.  
  • 23.