◊ Basic framework:
A) View run-time data
b) Program error type
c) gdb Debug segment Error
d) core file debugging
6.1 viewing run-time data
1) Print view variable values
2) PType View variable type
3) Print array view static array
4) Print *[email protected] View dynamic memory (malloc), or you can view a static array.
5) Print x=5 dynamically changes runtime data
6.2 program Error Type
1) Compile error : Error in program syntax, you can use GCC to find errors.
2) Run -time error : The compiler does not check out, but may cause the program to crash at run time.
For example, illegal address access.
3) logic error : Compile and run smoothly, but the program didn't do what it had to do.
6.3 Gdb Debug Segment Error
A segment error is caused by an error accessing an illegal address, and there are two main types:
1) access to the system data area
For example: Write data to the memory address protected by the system;
2) memory out of bounds
For example, an array is out of bounds and accesses an area of memory that does not belong to the array.
Note : When writing a program, try to avoid the memory out of bounds, because sometimes even if the memory out of bounds, the system does not error.
6.4 Core file Debugging
1) Core file
The current memory state information (memory impressions) When the process crashes is output to the core file (the body of the process), and then the executable and core files of the error can be submitted to GDB so that the error can be accurately located.
The core file generation process is called core dump.
2) Set the build core file
Ulimit–c View the size of the core file that the system generates by default.
Ulimit-a View all parameter statuses
Ulimit-c Unlimited Sets the default generated core file size to unlimited.
3) GDB uses core file debugging
First: Gdb + executable file +core file;
Then: Use the BT (backtrace) command to find out the function call relationship of the fault.
06.gdb Getting Started (bottom)