none
How to use advanced breakpoint syntax? RRS feed

  • Question

  • How can we set a breakpoint on system exported function such as MessageBox or LoadLibrary? Couldn't find it in the MSDN.

    Also, how to use the context operator for setting breakpoints? MSDN says:

    The context operator is an additional operator provided by the native debugger. When debugging native code, you can use the context operator to qualify a breakoint location , variable name, or expression;

    {[function],[source], [module]} location

    etc, etc

    I couldn't get it to work. Can anyone help?

     

    Wednesday, September 19, 2007 1:02 PM

Answers

  • Cythe,

     

    The context operator to qualify breakpoint location is used as follows

     

    {,,mydll.dll}CMyClass::MyMethod1

     

    Note that this applies to native debugging only. The example above scopes it to the DLL. More examples can be found at http://msdn2.microsoft.com/en-us/library/wztycb7f(VS.80).aspx

     

    To set breakpoints on functions dump the export using "dumpbin /exports <dll>" (in your case it dll would be user32.dll and breakpoint would be {,,user32.dll}MessageBoxW assuming application was built as unicode). Hope that helps.

     

    Azeem Khan

    VS Debugger.

     

    Wednesday, September 19, 2007 8:36 PM
    Moderator
  • In some cases (depending on your version on VS) you may need to pass the decorated name of the function. On versions of VS earlier than 2008, the decorated name is required for function exports unless you have complete private symbols. 

     

    Since MessageBoxW is a win32 api, it will be stdcall and so its decorated name would be _MessageBoxW@16. To set a function breakpoint on it, do:

     

    {,,user32.dll}_MessageBoxW@16

     

    You'll also need to have the public export symbols for user32 available on the machine. To get them, follow the instructions available here for the public symbol server:

     

    http://msdn2.microsoft.com/en-us/library/b8ttk8zy.aspx

     

     

     

    HTH

     

    Jackson

    Visual Studio Debugger

    Wednesday, September 19, 2007 8:56 PM
    Moderator

All replies

  • Cythe,

     

    The context operator to qualify breakpoint location is used as follows

     

    {,,mydll.dll}CMyClass::MyMethod1

     

    Note that this applies to native debugging only. The example above scopes it to the DLL. More examples can be found at http://msdn2.microsoft.com/en-us/library/wztycb7f(VS.80).aspx

     

    To set breakpoints on functions dump the export using "dumpbin /exports <dll>" (in your case it dll would be user32.dll and breakpoint would be {,,user32.dll}MessageBoxW assuming application was built as unicode). Hope that helps.

     

    Azeem Khan

    VS Debugger.

     

    Wednesday, September 19, 2007 8:36 PM
    Moderator
  • In some cases (depending on your version on VS) you may need to pass the decorated name of the function. On versions of VS earlier than 2008, the decorated name is required for function exports unless you have complete private symbols. 

     

    Since MessageBoxW is a win32 api, it will be stdcall and so its decorated name would be _MessageBoxW@16. To set a function breakpoint on it, do:

     

    {,,user32.dll}_MessageBoxW@16

     

    You'll also need to have the public export symbols for user32 available on the machine. To get them, follow the instructions available here for the public symbol server:

     

    http://msdn2.microsoft.com/en-us/library/b8ttk8zy.aspx

     

     

     

    HTH

     

    Jackson

    Visual Studio Debugger

    Wednesday, September 19, 2007 8:56 PM
    Moderator
  • I can't seem to get the following to work:

     

    {,main.cpp,}@7

     

    It is supposed to set the breakpoint on line 7 in file main.cpp. But it shows "Invalid Context". What am I doing wrong?

     

    MSDN also gives the same example:

    To set a breakpoint at line 301 of EXAMPLE.CPP:

    {,EXAMPLE.CPP,}@301
    Thanks for your help.
     
    Thursday, September 20, 2007 2:44 AM