www.digitalmars.com         C & C++   DMDScript  

D.gnu - Debugging D with valgrind

reply wscott wscott1.homeip.net (Wayne Scott) writes:
I just started using D and gdc this week, but I noticed something that
I haven't seen mentioned before.

valgrind works on simple D programs.  

Consider this trivial example:

$ cat err.d
void
main()
{
        int     *j;

        *j = 4;
}


 $ valgrind --tool=memcheck ./a.out
==27778== Memcheck, a memory error detector for x86-linux.
==27778== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward.
==27778== Using valgrind-2.1.1, a program supervision framework for x86-linux.
==27778== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward.
==27778== For more details, rerun with: -v
==27778== 
==27778== Invalid write of size 4
==27778==    at 0x8049294: _Dmain (err.d:7)
==27778==    by 0x80492BA: main (dmain2.d:43)
==27778==  Address 0x0 is not stack'd, malloc'd or free'd
==27778== 
==27778== Process terminating with default action of signal 11 (SIGSEGV):
dumping core
==27778==  Access not within mapped region at address 0x0
==27778==    at 0x8049294: _Dmain (in /home/wscott/Dlang/a.out)
==27778==    by 0x80492BA: main (dmain2.d:43)
==27778== 
==27778== ERROR SUMMARY: 2 errors from 2 contexts 
==27778== malloc/free: in use at exit: 33440 bytes in 13 blocks.
==27778== malloc/free: 13 allocs, 0 frees, 33440 bytes allocated.
==27778== For a detailed leak analysis,  rerun with: --leak-check=yes
==27778== For counts of detected errors, rerun with: -v

The checks work fine and the debug information works.

I haven't had a lot of luck with gdb, so this is handle.
Now we just need to teach valgrind about D's name mangling.

I will try some more complicated ones that invoke the GC and see if
it still works.

-Wayne
Jul 17 2004
parent Sha Chancellor <schancel pacific.net> writes:
In article <cdb0cq$184r$1 digitaldaemon.com>,
 wscott wscott1.homeip.net (Wayne Scott) wrote:

 I just started using D and gdc this week, but I noticed something that
 I haven't seen mentioned before.
 
 valgrind works on simple D programs.  
 
 Consider this trivial example:
 
 $ cat err.d
 void
 main()
 {
         int     *j;
 
         *j = 4;
 }
 
 
  $ valgrind --tool=memcheck ./a.out
 ==27778== Memcheck, a memory error detector for x86-linux.
 ==27778== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward.
 ==27778== Using valgrind-2.1.1, a program supervision framework for 
 x86-linux.
 ==27778== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward.
 ==27778== For more details, rerun with: -v
 ==27778== 
 ==27778== Invalid write of size 4
 ==27778==    at 0x8049294: _Dmain (err.d:7)
 ==27778==    by 0x80492BA: main (dmain2.d:43)
 ==27778==  Address 0x0 is not stack'd, malloc'd or free'd
 ==27778== 
 ==27778== Process terminating with default action of signal 11 (SIGSEGV): 
 dumping core
 ==27778==  Access not within mapped region at address 0x0
 ==27778==    at 0x8049294: _Dmain (in /home/wscott/Dlang/a.out)
 ==27778==    by 0x80492BA: main (dmain2.d:43)
 ==27778== 
 ==27778== ERROR SUMMARY: 2 errors from 2 contexts 
 ==27778== malloc/free: in use at exit: 33440 bytes in 13 blocks.
 ==27778== malloc/free: 13 allocs, 0 frees, 33440 bytes allocated.
 ==27778== For a detailed leak analysis,  rerun with: --leak-check=yes
 ==27778== For counts of detected errors, rerun with: -v
 
 The checks work fine and the debug information works.
 
 I haven't had a lot of luck with gdb, so this is handle.
 Now we just need to teach valgrind about D's name mangling.
 
 I will try some more complicated ones that invoke the GC and see if
 it still works.
 
 -Wayne
Sweet. :) I hope it works well
Jul 26 2004