Memory Leak checker tool valgrind--General Command options

Source: Internet
Author: User
Tags socket stack trace stdin valgrind

Valgrind [Valgrind-options] [Your-program] [Your-program-options]

The bottom of the valgrind simulation of a core, a software simulation of the CPU, the debugged program is running on this fake core, also contains a series of debugging tools. Its tool runs depend on the underlying core, and because it is a modular architecture, the tools can be developed separately, as long as they match the core version. Its default tool is Memcheck, which specifies the tool to run with--tool=<toolname>.

Each tool may have its own command options, and the options available for all tools are listed below:

-H--help: Displays all the options for the core and selected tools (-H or--help), and if-H--help is equivalent to--help-debug, which shows the debug options (typically used by valgrind developers).

--version: First the core version.

-Q,--quiet: quiet operation, only print error messages (program error messages being debugged).

-V,--verbose: More information is given, as opposed to-Q. Gives comprehensive information about the program being debugged, such as which shared libraries are loaded, what suppressions are used, and the progress of execution, warning messages, and so on.

--trace-children=<yes|no>: If yes, if the program uses exec to open a subprocess, the Valgrind will track the execution of the child process. The default is no, but in any case, the Valgrind still tracks the child processes that the fork produces.

--trace-children-skip=patt1,patt2 ... : After the above option is set to Yes, this option identifies which child processes are not to be traced, and these sub-processes (names) are created by patt1,patt2 ... To decide, PATTN can contain "?" * "wildcard characters. Note that Valgrind will stop tracking all child processes that may be generated under the PATTN process.

--trace-children-skip-by-arg=patt1,patt2,... : Unlike the--trace-childrn-skip option, a skipped subprocess is made up of parameters to the child process patt1,patt2 ... To decide, not the program name.

--child-silent-after-fork=<yes|no>: If yes, any debug or log information generated by the child process generated by the fork call is not displayed. When debugging information is exported in XML format (--xml=yes), it is strongly recommended to turn this option on. The default is No.

--VGDB=<NO|YES|FULL>: If yes or Full,valgrind allows a program to run on it, use GDB to debug it (turn on gdbsever). The default is yes.

--vgdb-error=<number>: After opening the gdbsever, it is useful. The error tool freezes the program and waits for you to connect it to GDB after waiting for a number error to be reported. So, when Number=0, Gdbserver starts running before your program runs. A typical scenario is to insert a GDB breakpoint before running, and to use a tool that does not error, such as massif. The default is 999999999.

--trace-fds=<yes|no>: If yes, when the program exits, a series of information about the file descriptor that is opened by the program is printed. including where the file is opened, the name of the file or the details of the socket. The default is No.

--time-stamp=<yes|no>: If yes, a time message will be hung before each message indicating the amount of time since the program began.

--LOG-FD=<NUMBER>: The output information of the Vaolgrind is exported to the file specified by the number of this file descriptor, the default is 2, that is, stderr. Note that this may be intertwined with what the user is exporting to stderr.

--LOG-FILE=<FILENAME>: Exports the information to the file specified by filename to the right. If filename is empty, the termination is raised. There can be three format information in filename; 1,%p will be replaced with the ID of the current process. When-trace-children=yes, and useless%p, all process information is lost to the same file, it will be confusing, the information may not be complete, preferably the file name contains%p. 2,%q{foo} is replaced with the value of the environment variable foo, which can throw an exception if the contents of Foo are strange. This format is generally not used, except in rare cases, such as programs based on MPI (a parallel Program development library). If this format is used, Foo cannot be empty, or an exception is thrown. Some shells, "{" "}" may need to be escaped with backslashes. 3,%% is substituted for%,% cannot be followed by any other characters, otherwise an exception will be thrown.

--log-socket=<ip-address:port-number>: Outputs the information to the specified IP address. If Port-number is saved, the default is 1500 port number. If this IP address cannot accept the information, the information will be written to stderr.

here are the options associated with the error. These options apply to all the tools that can be used, such as Memcheck, and Cachegrind.

--xml=<yes|no>: If yes, the error message is output in XML format, not a flat document. Unimportant information (non-error messages) is printed in a flat document. The XML output target is specified by--XML-FD or--xml-file or-xml-socket, while the flat document information output target is specified by the preceding-log-fd or-log-file or-log-socket. The output format is set by Docs/internals/xml-output-protocol4.txt.

--XML-FD=<NUMBER>: Output XML information to a file specified by the file descriptor number must be--xml=yes.

--xml-file=<filename>: similar to-log-file. must also be-xml=yes.

--xml-socket=<ip-address:port-number>: Similar to-log-socket, it must be-xml=yes.

--xml-user-comment-<string>: At the beginning of the output XML file, add the comment information, without-xml=yes words, will be ignored.

--demangle=<yes|no>: If this option is turned on, it will attempt to restore the C + + symbol name in the target code so that it is consistent with the relevant symbol name in the source. The default is yes.

--num-callers=<number>: Defines the maximum number of nested calls that are displayed during a stack trace. Note that Valgrind only displays error messages for four-layer nested calls, so this option does not affect the amount of error information that is ultimately reported. The number maximum is 50, and the default value is 12.

--error-limit=<yes|no>: If yes, the error is stopped when the total number of errors reported exceeds 10000000 or there are 1000 different types. So many wrong programs will not need to be debugged, the default is yes.

--error-exitcode=<number>: Sets the return code of the Valgrind when any error message is found. The default is 0, so that the return code is the return code of the program being transferred. If set to a value other than 0, this value will replace the default return code.

--show-below-main=<yes|no>: Default is no, when tracking stack errors, do not display the error message for those function calls that are in the next layer of the main function.

The default value for--fullpath-after=<string>:string is "don't show source Paths", which shows only the file name during the stack trace, not the full path of the source file. For large projects, many source files are distributed across different paths, and this default behavior is inconvenient. When a string is set, the path to each source file is displayed, but if the path contains a string, the coincident portion of the path to the string will be omitted until the beginning of the path (root directory). If the full path of a source file is/home/janedoe/blah/src/foo/bar/xyzzy.c and the option is set to--fullpath-after=/home/janedoe/blash/src/, the file name displayed is foo/ Bar/xyzzy.c. Because the string does not need to add a path prefix, so--fullpath-after=/blash/src/, the effect is the same. To display the full path, do not assign a value to string, that is,--fullpath-after=. This option can also be used multiple times to truncate the path in the order in which they appear in the command line, followed by the rules above.

--GEN-SUPPRESSIONS=<YES|NO|ALL>: If you select Yes, a error,valgrind is paused and one line is printed:----Print suppression?---[return/n/n ? Y/Y/C/C]---(y=yes,n=no,c=cancle) This message is the same as the--db-attach option below, select Y to print the suppressions for this error. If this option is all, the suppression of each error is printed and is not queried. Also, the suppression name is given as <insert a suppression name here>; The name doesn ' t really matter, it's only used with THE-V option which prints off all used suppression records.

--DB-ATTACH=<YES|NO>: If you select Yes, a error,valgrind is paused and one line is printed:----Attach to Debugger?---[regurnn/n/y/y/c/c]---。 If Y is selected, the debugger is started here and debugging is done to exit the debugger before Valgrind can continue. If you are using GDB, the option--vgdb=yes or ful will make the debugger more powerful (it starts the gdbsever inside the valgrind and almost simulates the full functionality of GDB).

--db-command=<command>: When the--db-attach option is turned on, the actual command used is "GDB-NW%f%p", where%f is the program name being debugged,%p is the ID of the process being tuned, The default debugger is Valgrind installed when it discovers, generally/usr/bin/gdb. The command should be enclosed in double quotation marks.

--input-fd=<number>: When--db-attach=yes or--gen-suppressions=yes, Valgrind waits for keyboard input when an error is found, even though the next step is that number defaults to 0 ( stdin), by modifying number, allows Valgrind to read the specified file to perform the next operation, which is useful when stdin is turned off.

--dsymutil=no|yes: This option is only useful for running Valgrind on MacOS.

--MAX-STACKFRAME=<NUMBER>: This option specifies the maximum stack frame space that the program can use. The default is 2000000. This option is generally recommended when you use the debug output of Valgrind. In fact, if the Valgrind suggested that your program has a problem, it is best not to allocate too large data structure on the stack, large data is best allocated on the heap.

--MAIN-STACKSIZE=<NUMBER>: Specifies the stack size of the main thread. By default, the Ulimit value is usually 16MB or lower. The general use of 8~16m can meet the needs of most applications. The maximum application for Linux is 2GB. If Valgrid cannot allocate so much space, it will terminate. This option only affects initial thread and has no effect on other thread stacks. You'll have a to-work out of the--main-stacksize value for yourself (usually, if your applications segfaults). But Valgrind'll tell you the needed--max-stackframe size, if necessary.

Options related to the malloc () function:

--alignment=<number>: Default is 8 or 16, depending on the system platform. This option is useful for tools that have their own version of malloc, such as Memcheck and Massif, which set the alignment requirements for assigned addresses. Number must be greater than or equal to the default value, less than 4096, and must be several times 2.

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.