当前位置:网站首页>GDB common commands

GDB common commands

2022-07-26 13:50:00 one point zero one

GDB It mainly completes the following four functions :

  • Start your program , You can run the program according to your custom requirements .
  • You can make the debugged program stop at the breakpoint you specified .( Breakpoints can be conditional expressions )
  • When the program is stopped , You can check what's going on in your program at this point .
  • Dynamically change the execution environment of your program .

Common commands :

 Insert picture description here
A good blog

——————————————————————————————————————————————————

Linux How to use gdb debugging core file

**

1.core file

**
core Files are in the running state of the program Memory Image appears when the program is running segmentation fault(core dumped) When it's wrong , The program stops running , And produce core file .

Use gdb debugging core Files can help us quickly locate the program Segment error The location of . Executable programs should be compiled with -g Compilation options , Generate debugging information .
When the memory accessed by the program exceeds the memory space given by the system , It will produce Segmentation fault(core dumped), therefore , The main situations of segment errors are :

  1. Access to non-existent memory address
  2. Access system protected memory address
  3. Array access out of bounds, etc
    core dumped It's also called core dump , When an exception occurs while the program is running , When the program exits abnormally , The operating system stores the current memory status of the program in a core In file .
    **

2. control core Whether the file is generated

**

  1. Use ulimit -c The command can be viewed core File generation switch . If the result is 0, This function is turned off , Will not generate core file .
  2. Use ulimit -c filesize command , Can restrict core File size (filesize The unit is kb). If the generated information exceeds this size , Will be cut , In the end, the process is incomplete core file . example :ulimit -c 1024
  3. Use ulimit -c unlimited said core Unlimited file size .
  4. By command at the terminal ulimit -c unlimited It's just a temporary change , Invalid after restart , There are three ways to permanently modify .
  5.  stay /etc/rc.local Add a line to the list ulimit -c unlimited
     stay /etc/profile Add a line to the list ulimit -c unlimited
    
        
         
    • 1
    • 2

3.core File name and build path

core The default file name is core.pid,pid It refers to the process number of the program that generated the segment error .

The default path is the current directory of the program that generated the segment error .

modify core File name and path

4.gdb debugging core Document steps

Use gdb debugging core File to find the location of the segment error in the program , Need executable program plus -g Compile command options .
The common ones are the following ( Recommend the first ):
Step one :
(1) start-up gdb Get into core file , Command format :gdb [exec file] [ core file]
example :gdb ./test test.core
(2) After entering , Find segment error location :where perhaps bt
You can locate the specific location of specific files in the source program , A segment error occurred .
Step two :
(1) start-up gdb Get into core file , Command format :gdb -core=[core file]
example :gdb -core=test.core
(2) When entering gdb after , Appoint core Symbol table corresponding to the file , Command format :file [exec file]

 stay gdb Input bt command    When encountering segment errors , Input bt command , You can track errors 

Reprint here , Please click to check

原网站

版权声明
本文为[one point zero one]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/207/202207261345511239.html