06.gdb Getting Started (bottom)

Source: Internet
Author: User

◊ 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.