Linux debug tool and linuxdebug Tool

Source: Internet
Author: User
Tags valgrind

Linux debug tool and linuxdebug Tool

Development in linux will inevitably encounter bugs, but debugging becomes difficult because there is no graphical IDE. In fact, as long as you master some common debug tools, some errors can be quickly solved, this article describes some common tools for debugging:

Log

The output log is always the simplest and fastest debugging method. You can quickly locate bugs and set the log level to control the log output details, combined with some text analysis tools awk/sed/grep, you can quickly find error messages in a large number of logs.

Strace

Is a simple tool used to track system calls. Its simplest purpose is to track all system calls of a program throughout the life cycle, and output the call parameters and return values in the form of text. Strace can also track signals sent to processes. Supports the strace-p <pid> process in which attach is running. In a multi-threaded environment, you need to track the system calls of a thread, you can first ps-efL | grep <Process Name> to find the thread in the Process, and then call starace-p <pid> for analysis.

Pstack

This command is used to track the process stack. For example, if we find that a service is always in the working state (such as a false dead state or an endless loop), we can use this command to easily locate the problem. Within a period of time, execute pstack several times more. If you find that the Code stack is always in the same position, you need to pay attention to the position, which is probably the cause of the problem;

Gdb

The classic debugging tool has powerful functions. Note that the-g option should be used during compilation and optimized with-Og. Multi-thread debugging can be performed by attach to the process.

Core dump File

When a process stops running after receiving a signal, it writes the content of the process address space and other information about the process status to the core file, for example, if we encounter a segment fault error when we access the memory illegally at ordinary times, we can use gdb to see where the exception occurred. Sometimes you can manually send a signal kill-11 <pid> to the process to check the running status of the system. For example, if the program suddenly stops under multiple threads, a deadlock may occur, we can generate signals manually and analyze core dump.

Valgrind

There are many tools:

Memcheck. This is the most widely used tool of valgrind. A heavyweight memory Checker can find the vast majority of memory usage errors during development, such as using uninitialized memory and released memory, memory Access out of bounds. This is also the focus of this article.

Callgrind. It is mainly used to check the problems encountered during function calls in the program.

Cachegrind. It is mainly used to check the Cache Usage problems in the program.

Helgrind. It is mainly used to check competition problems in multi-threaded programs.

Massif. It is mainly used to check the problems that occur in the use of stacks in the program.

Extension. You can use the functions provided by core to compile specific memory debugging tools.

The memcheck tool is used by default. When using pointers in c ++, memcheck can be used to check exceptions. Generally, -- track-origins = yes is used to locate uninitialized variables.

Tcpdump

Packet Capture is useful when developing network applications. Combined with awk/sed/grep, you can quickly find network data packets.

Stackoverflow

This website is a Q & A website in the field of programming. You can find the answer to all the questions you encounter! There is a strong technical atmosphere and we can learn a lot from it.

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.