Changes between Version 4 and Version 5 of OsgDebugging


Ignore:
Timestamp:
Aug 3, 2010, 8:42:18 PM (14 years ago)
Author:
Torben Dannhauer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OsgDebugging

    v4 v5  
    33= Short Introduction to Debugging and Hunting Memory Leaks on Windows and Linux =
    44
    5 Debugging the application for memory leak is quite easy. This indroduction adressess debugging beginners but assumes your are familiar with basic debugging techniques (stop and go, watching values..)
     5This indroduction adresses beginners but assumes they are familiar at least with basic debugging techniques (stop and go, watching values..). If you are searching for advanced tips, please use the MSDN and Valgrind documentation.
    66
    77== Windows ==
    88
    9 The windows debugging how to is based on Microsoft Visual Studio 2008 Professional. Using another MSVC Version should be possible without modification. Should... :)
     9The windows debugging !HowTo is based on Microsoft Visual Studio 2008 Professional. Using another MSVC Version should be possible without modification. ...should... :)
    1010
    11 The standart program debugging regarding software errors is easy:
    12  * On Crashes: Start the software with the debugger, use it until it crashes. The debugger will stop and you can go back at the call stack and look for the first function located in your programm. This function is your first approach to search for your error :)
    13  * On program logic errors without crash: Place debug messages in your code, and set breakpoints at interesting lines so you can watch variable values when the debugger break at that points.
     11In debug builds MSVC outputs memoryleaks automatically. Unfortunately the message do not contain filenames or line numbers but only lost bytes by default. Additionally MSVC stops the memory accounting to early, so the satic elements of OSG are not freed already and result in a lot of false memory leak reports. This behaviour can only be correct with crude workarounds like linking to MFC or similar.
    1412
    15 === Memory Leak Debugging ===
    16 While MSVC outputs memoryleaks automatically. it is very hard to modify it's behaviour to get useful leak reports.
     13At least MSVC can be configured to report all memory leaks inside the source files with filenames and line numbers to a output file. This allows to identify some of the "true" memory leaks and correct hem already on the windows platform.
    1714
    18 What do wo want? A report of every leak with the following information
    19 * Filename whre the leak was caused.
    20 * Function name where the leak was caused.
    21 * Linenumer where the leak was caused.
     15'''The best practice on windows is to use MSVC to eliminate all obvious memory leaks and to continue with Valgrind on Linux for final checks'''
    2216
    23 todo: how to modify sourcecode to get the informations.
     17What do we need to hunt the memory leaks? A report of every leak with the following information
     18 * Filename whre the leak was caused.
     19 * Function name where the leak was caused.
     20 * Line number where the leak was caused.
    2421
    25 pre main()
     22To achieve this, we have to perform two steps:
     23 * Manipulation main.cpp to start memory leak detection
     24 * Adding some definitions to each source file to replace the new operator with a debug version which outputs the requiered information.
     25
     26=== main.cpp ===
     27To enable the debug memory allocation, the following codelines are required '''before''' the main function:
    2628{{{
    2729#!cpp
     
    3638}}}
    3739
    38 Inside main()
     40Inside the main() function wo have to specify in detail how to track the memory. Because the MSVC debug windows is quite slow for large outputs, we use the file output:
    3941{{{
    4042#!cpp
    4143#ifdef _DEBUG
    4244        #ifdef WIN32
    43                 #include <leakDetection.h>      // for main: must be inside function. In classes: headerfile inside calss is sufficient
     45                #include <leakDetection.h>      // Must be inside main function. In classes: headerfile inside class is sufficient
    4446                int tmp_flag;
    4547