Sun Studio 12: Debugging a Program With dbx

Finding Memory Access Problems and Memory Leaks

Runtime checking consists of two parts: memory access checking, and memory use and leak checking. Access checking checks for improper use of memory by the debugged application. Memory use and leak checking involves keeping track of all the outstanding heap space and then on demand or at termination of the program, scanning the available data spaces and identifying the space that has no references.

Note –

Runtime checking is available only on Solaris platforms.

Memory access checking, and memory use and leak checking, are enabled with the check command. To turn on memory access checking only, type:

(dbx) check -access

To turn on memory use and memory leak checking, type:

(dbx) check -memuse

After turning on the types of runtime checking you want, run your program. The program runs normally, but slowly because each memory access is checked for validity just before it occurs. If dbx detects invalid access, it displays the type and location of the error. You can then use dbx commands such as the where command to get the current stack trace or the print command to examine variables.

Note –

You cannot use runtime checking on an application that is a mixture of Java code and C JNI code or C++ JNI code.

For detailed information on using runtime checking, see Chapter 9, Using Runtime Checking.