Debugging and debugging of C ++ programs in Linux

Source: Internet
Author: User

There are many causes of program crash, mainly including the following reasons (refer to eventhelix.com)
1. Invalid array indexing the array index is invalid.

Data1 A; // writable upted when B is indexed with 0 xffffffff (-1) due to the incorrect array index, such as B [-1] may destroy
Int B [100]; // declaration of B. Keep in mind that array indexing is a signed operation
Data2 C; // specified upted when index into B is greater than 99 due to the incorrect array index, such as B [100] may damage C

2. Un-initialized pointer operations uninitialized pointer operations

3. Unauthorized buffer operations unauthorized buffer operations

4. The illegal stack operations operation is invalid.

5. Invalid processor operations invalid processor operation
-- Divide by zero attempted by Application
-- Program running in user mode attempted to execute an instruction that can only be executed in supervisor (kernel) mode.
-- Program attempted access to an illegal address. the address might be out of range or the program might not have the privilege to perform the access. for example, a program attempting to write to read only segment will result in an exception.
-- Misaligned access to memory also results in an exception. most modern processors restrict long word reads to addresses divisible by 4. an exception will be raised if a long word operation is attempted at an address that is not divisible by 4. (See the byte alignment and ordering article for details)

6. Infinite Loop

Common detection and troubleshooting methods

1. Assert

2. output intermediate results print/log

3. Use the Debugger GDB/ddd

4. Use the detection tools memwatch, valgrind, parasoft C ++ test/insure C ++

FAQ:

1. How to make the program generate a core dump file when an error occurs
VI/etc/profile
# No core files by default
# Ulimit-s-c 0>/dev/null 2> & 1
Ulimit-s-c unlimited>/dev/null 2> & 1

2. If the required information is obtained from the Core File
GDB program core. xxx
BT
Info locals
Frame x

Links:
Http://www.eventhelix.com/RealtimeMantra/Basics/debugging_software_crashes.htm
Http://www.eventhelix.com/RealtimeMantra/Basics/debugging_software_crashes_2.htm

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.