In Linux, mtrace is used to check general program memory overflow.
Source: Internet
Author: User
In Linux, mtrace is used to check general program memory overflow-general Linux technology-Linux programming and kernel information. The following is a detailed description. You may encounter problems such as memory overflow when writing complex programs with many pointers. Debugging is also quite tiring. In fact, there is a tool in linux that can be used for debugging. This is mtrace. Mtrace can detect memory allocation and leakage failures. Next, let's take a look at its usage.
There are four basic steps to debug a program using mtrace. Some auxiliary function functions in the gnu c function library are required.
1. Include the header file in the program to be tracked In addition, the main () function contains a function call at the very beginning: mtrace (). Mtrace () is called at the beginning of the main function. Therefore, mtrace can trace and analyze all memory allocation and release operations after the process.
2. Define an environment variable to indicate a file. This file is used to output log information. Example:
$ Export MALLOC_TRACE = mymemory. log
3. The program runs normally. The memory allocation and release operations in the program can be recorded.
4. Use mtrace to analyze log files. For example:
$ Mtrace testmem $ MALLOC_TRACE
Here is an example:
[Hwang @ langchao test] $ cat tew.trace. c
# Include
# Include
# Include
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.