Re: Breakpoint not hit

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Oleg Starodumov (oleg_staro_at_hotmail.com)
Date: 06/15/04


Date: Tue, 15 Jun 2004 13:17:00 +0300


> This may not make sense, but hear me out. I am wondering if VC++ treats the
> library code linked into one DLL differently from the same code linked into
> another DLL. The reason I bring this up is that this would mean that I
> would somehow have to specify the breakpoint as being in DLL1 rather than
> DLL2.
>
> As I said, maybe the above doesn't make sense. If it does, however, I
> wonder how one would specify which DLL the breakpoint is to be set in?
>

It is possible to specify this information, using breakpoint context:
http://msdn.microsoft.com/library/en-us/vccore98/html/_core_setting_breakpoints_outside_the_current_scope.asp

In brief, in Breakpoints window you will see the following information
for every location breakpoint:
{function,source_file,module}@source_line

You can use "module" field to specify the module the breakpoint
should be set in (e.g. "{,MyLib.cpp,MyDll.dll}@15").

(Note that in normal circumstances, the debugger itself should be able
to determine that the breakpoint should be set in several modules,
and create several instances of the breakpoint in Breakpoints window,
with module field set properly).

To solve the problem with the breakpoint, also try to check the following:

* Check that the library (.LIB file) is built with debug information (I recommend
   to use /Z7 compiler option)

* Check that the library (.LIB file) is up-to-date in all DLL projects
   (IMO this is the most error-prone moment in library debugging)

* Check that the DLLs are built with debug information (default Debug configuration
   is good enough) and linked to the latest .LIB file of the library

* Add all DLLs into Additional DLLs list (Project settings | Debug | Additional DLLs)
   of the project that you use for debugging

* Check that debug information for the DLLs is loaded when you are debugging
   ("Loaded symbols for Xxx.dll" message must be in Debug output window)

* Check that when the DLLs are loaded, they are loaded from the expected location
   (use Modules window)

* Check that you can set and hit breakpoints in the DLLs, in the code
   that does not belong to the library

If the steps above work but the breakpoint still doesn't, try a workaround:

* Determine the address in the DLL that corresponds to the source line where
   you want to set the breakpoint (the line that belongs to the library)

   (You can use .MAP file, or simply create a little stub application which calls LoadLibrary()
   for the given DLL, run it under debugger, select the needed source line and
   R-Click + Go to Disassembly, and you will see the address) (of course, check that
   the DLL is not relocated to another base address when you debug it in the real project,
   or take relocation into account)

* When debugging, after the DLL is loaded, use Breakpoints window to set a new breakpoint
   at the given address

* Optionally, in Breakpoints window you can press Edit Code, to check which
   source file/line corresponds to this address from the debugger's point of view
   (it is good to close all source files before pressing Edit Code)

Regards,
Oleg



Relevant Pages