Dmalloc Logo
Home

Documentation
Downloads
Forums
Releases

Search this site:

Donations:
If dmalloc has saved you or your company time or money, please use your credit-card or PayPal account to donate to the cause.

Dmalloc Tutorial: 3.11 Debugging Allocations in a Daemon Process
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.11 Debugging Allocations in a Daemon Process

There are some specified challenges when trying to debug allocations in processes which do not startup, run, and then shutdown. Daemon processes are those that are spawned (often at system boot time) and run perpetually. Other processes which are difficult to debug are CGI programs which are spawned by web servers or when you want to start debugging inside of a child process.

The first issue is how to enable the library's flags to perform certain checks. Since these programs often do not run from the command line, you cannot use the dmalloc utility program and modify the process environment. See section Dmalloc Utility Program. The library provides a couple of functions to set the debugging flags when a program is running. The dmalloc_debug function allows you to set the library flags directly. For example, if dmalloc -v shows that the debug flags you want are 0x4f47d03 then you can pass this number to the dmalloc_debug function and get the same library behavior if you'd have used the environmental variable.

In version 5 and above of the library, you can also use the dmalloc_debug_setup function which takes a string in the same format of the `DMALLOC_OPTIONS'. See section Environment Variable Name and Features. So, for example, if you want to turn on high debugging and log to the file `malloc' then you would call dmalloc_debug_setup("debug=0x4f47d03,log=malloc");. Even if you get the settings enabled, you may have problems getting the logfile to be written if your program is running as `nobody' or another user without permissions for security reasons. In this case you should specify a full path to your malloc logfile in a world writable directory (ex. `/var/tmp/malloc'). Watch for programs which change into other directories and which may cause logfiles specified as relative or local paths to be dropped in other locations. You may always want to use a full path logfile.

Once you have your settings being enabled and your log is being generated, you may now want to check out how your process is doing in terms of unfreed memory. Since it is not shutting down, the automatic unfreed log entries are not being dropped to the logfile. By using the dmalloc_mark and dmalloc_log_changed functions, you can set a mark point at a certain place inside of your program, and then later see whether there are any unfreed pointers since the mark. Usually you would set the mark after the initializations are complete and before the transactions are processed. Then for each transaction you can use dmalloc_log_changed to show the unfreed memory. See section Additional Non-standard Routines.

You can also use the dmalloc_log_stats and dmalloc_log_heap_map functions to dump general information about the heap. Also, remember that you can use the dmalloc_message and dmalloc_vmessage routines to annotate the dmalloc logfile with details to help you debug memory problems. See section Additional Non-standard Routines.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by Gray Watson on May, 16 2007 using texi2html 1.76.

This work is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.
This page should be W3C Valid XHTML and should work with most browsers.