Dmalloc Logo


Search this site:

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.10 Using the library with Cygwin environment.
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.10 Using the library with Cygwin environment.

The Cygwin environment is a Linux-like environment for Windows. It provides Linux look and feel as well as a programming environment. See URL for more details.

The challenge with using dmalloc to debug Cygwin programs is that when it initializes, dmalloc makes a call to getenv to read the environmental variables. It is looking for the value of the `DMALLOC_OPTIONS' variable which sets the debugging options. See section Environment Variable Name and Features. Because Cygwin calls a memory allocation function while it is loading it's shared libraries, it goes recursive when getenv is called from within malloc causing a segfault.

To work around this, I have added to the configure script a check to make sure that calls to getenv are okay inside of malloc. See GETENV_SAFE in `conf.h'. If they are not then you are going to have to add some code into the main function in your program to initialize the dmalloc flags yourself. Here is a code sample:

main(int argc, char **argv)
#ifdef DMALLOC
   * Get environ variable DMALLOC_OPTIONS and pass the settings string
   * on to dmalloc_debug_setup to setup the dmalloc debugging flags.

  /* rest of code in main starts here */

The #ifdef is just a good idea. I means that when debugging with dmalloc you need to compile your code with -DDMALLOC. When you are done debugging you can remove the flag and the call to dmalloc_debug_setup will be removed.

Please let me know if there is a different way to read the environment in Cygwin without calling getenv or if there is a better way to do this.

[ < ] [ > ]   [ << ] [ 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.