delorie.com is funded by banner ads.
  www.delorie.com/djgpp/v2faq/faq094.html   search  

| Previous | Next | Up | Top |

12.1 How to run a DJGPP program under debugger

Q: How do I debug my programs?


A: First, remember to use the -g switch when you compile and link. This puts debugging information into your executable. When linking, don't use the -s switch. Here are a few examples of compilation and link command lines when you intend to debug a program:
      gcc -Wall -c -g -O myfile.c
     
      gcc -Wall -O2 -g -o myprog.exe mymain.c mysub1.c mysub2.c -lm
     
      gcc -g -o myprog myprog.o mysub.o

Note that with gcc, you can use optimization switches when compiling with -g. To use stabs debugging, compile with -gstabs3 or -gstabs+ instead of -g.

Then, to debug the program, use a command line like this (here for gdb):

      gdb myprog.exe

Beginning with v2.01, DJGPP debuggers can debug both unstubbed COFF images and DOS-style .exe executables (v2.0 only supported COFF files). To debug a COFF file, name it without the .exe extension, like so:
      gdb myprog

You can use one of several available debuggers with DJGPP:
  1. RHIDE, the DJGPP IDE by Robert Hoehne is available from the DJGPP archives. It includes an integrated source-level debugger based on GDB code and presents a user interface like that of Borland's IDE or Turbo Debugger.
  2. RHGDB, a stand-alone version of GDB with a Turbo Vision user interface. RHGDB is part of the RHIDE distribution; it only supports part of GDB features.
  3. FSDB, the full-screen debugger, from the djdev distribution. This presents a user interface like that of Borland's Turbo Debugger, but unlike TD, it isn't a source-level debugger (although it will show the source code together with the machine instructions). It also supports data-write breakpoints: a powerful feature for hunting down code which overwrites data it shouldn't touch. Another advantage of FSDB is that you can easily debug programs that grab the screen, because it can switch between the debugger screen and the application screen. Also, it allows to examine the FPU registers. The main disadvantage of FSDB is that you cannot easily examine the contents of complex data structures. Remember to prepend an underscore _ to the names of C identifiers when you use them with FSDB; for C++ programs you will have to find out the mangled names of static class variables and methods to make FSDB understand them.
  4. GDB, the GNU Debugger. This is a powerful source-level debugger, but it uses a line-oriented user interface. People who are familiar with using GDB on Unix should know about the following important differences in its operation on MS-DOS:
  5. EDEBUG32 is the most basic debugger you can use with DJGPP. One case when you would need to use it is when you debug a DXE module (see explanation of what a DXE is), because GDB doesn't support debugging DXEs.
You invoke any debugger like this:
      <debugger-name> <program> <args...>


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright ⌐ 1998   by Eli Zaretskii     Updated Sep 1998  

Powered by Apache!

You can help support this site by visiting the advertisers that sponsor it! (only once each, though)