« Previous Next »

Thread: Debugging Native Code Modules

Last post 07-17-2006 1:25 PM by mvolo. 8 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (9 items)

Sort Posts:

  • 07-13-2006, 6:28 AM

    Debugging Native Code Modules

    Could we have a 101 on debugging IIS 7.0 modules somewhere? I've followed the Walkthrough for Creating a Native-Code HTTP Module, and now I'd like to see it execute in the debuggerr.

    I'm having a few problems with this. I'm assuming that the correct way to do this is to attach to the W3WP.EXE process. However...

    Most of the time this process doesn't appear in the Visual Studio attach to process dialog (I'm running it with Admin privileges) and I've got Show processes from all users and Show processes in all sessions selected. One time  I did manage to attach to it (if only I could remember what exact sequence for bouncing the web server I followed!), the debugger listed my module as loaded with symbols in the output window, but when I tried to set breakpoints in VS they were marked as disabled because the module was not loaded.

    I haven't done any serious IIS programming for several years (IIS 5.0 on Windows 2000), but I don't remember having this sort of pain debugging ISAPI filters then.

    Help! Thanks!

  • 07-13-2006, 11:04 AM In reply to

    • mvolo
    • Top 25 Contributor
    • Joined on 09-17-2003, 1:48 PM
    • Philadelphia, PA
    • Posts 584
    • IIS MVPs

    Re: Debugging Native Code Modules

    Make sure you are compiling in the debug configuration, so that the PDB file is produced during compilation.  Copy the PDB file to the same location as the DLL file when installing the module on the server (using APPCMD I presume if you followed the walkthrough).

    Make a request to the server to load the module.

    In VIsual Studio, go to Tools > Attach to Process > 
       (select show processes from all sessions, and all users checkboxes at the bottom of the dialog)
       (Make sure Attach Type is Native, or Managed And Native)

    Select the W3WP.exe process, and click Attach.

    Go to Debug > Windows > Modules (the naming coincidence is accidental), and make sure that the symbols for your DLL are loaded.  If not, Right Click and do Load Symbols, and manually browse to your symbol file.

    Put the breakpoint and debug away.

    In some cases, you will need to attach to your module in RegisterModule, which executes once on worker process startup.  You cannot do this with VS since by the time the WP is started, and you attach, this has already executed, so its easiest to use a native command line debugger like NTSD.exe to do this.

    Thanks,

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 07-13-2006, 12:06 PM In reply to

    Re: Debugging Native Code Modules

    Mike -

    Thanks. I've tried this, and everything appears to be working apart from the fact that I still can't set breakpoints :-(  The executive summary is that VS reports that it has loaded the module and its symbols, but behaves as though it hasn't.

    Are there any known bugs with Vista Beta 2 and debugging?

    The detailed steps I've tried are outlined below...

     

    I deployed the module using the IIS Configuration Manager. After I attach to W3WP, the VS Modules Window reports that IIS7NativeModuleSample.dll is loaded, together with its symbols file (dll & pdb are in the same location). I've also tried moving the PDB, and then loading it manually using Load Symbols on the Modules window context menu... same behaviour.

    I also changed the sample code so that it will throw an access violation, and set VS to break on Win32 exceptions; this broke into the sample code, but only shows me assembly code....

  • 07-13-2006, 12:16 PM In reply to

    • mvolo
    • Top 25 Contributor
    • Joined on 09-17-2003, 1:48 PM
    • Philadelphia, PA
    • Posts 584
    • IIS MVPs

    Re: Debugging Native Code Modules

    When you set the breakpoint, does it show it as a full breakpoint (red filled circle)?  If not, can you mouseover the breakpoint circle and check the error message?

    Sometimes this kind of thing will happen if you have certain debugging options set, or if you sources are out of date with your PDB or DLL files.

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 07-13-2006, 12:35 PM In reply to

    Re: Debugging Native Code Modules

    Mike -

    The breakpoint shows as disabled - the error message in the tooltip for the breakpoint is "The breakpoint will not currently be hit. No symbols have been loaded for this document.", contradicting the info in the modules window. I'm pretty baffled at this point...

    I've deployed to IIS directly from the project's debug directory, so the PDB and the DLL are in step (I just deleted and rebuilt everything to make absolutely sure), and the path to the dll and the PDB file shown in the modules window is the same - here's the information cut & pasted from the modules window:

    Name:  IIS7NativeModule.dll  

    Path: C:\Source\IIS7NativeModuleSample\Debug\IIS7NativeModule.dll 

    Optimized:   N/A 

    User Code: N/A 

    Symbol Status: Symbols loaded. 

    Symbol file: C:\Source\IIS7NativeModuleSample\Debug\IIS7NativeModule.pdb 

    76  13/07/2006 17:24 10000000-1002E000 [2800] w3wp.exe: Native 

  • 07-14-2006, 4:02 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Debugging Native Code Modules

    Not sure why visual studio cannot set break-points, but you can try debugger package from http://www.microsoft.com/whdc/devtools/debugging/default.mspx - it includes a GUI based debugger tool (windbg) - it shouldn't be too different than visual studio for debugging.
    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 07-14-2006, 5:37 PM In reply to

    • thomad
    • Top 25 Contributor
    • Joined on 08-20-2002, 11:28 AM
    • Redmond
    • Posts 503

    Re: Debugging Native Code Modules

    Did you add your module to the <globalModules> AND <modules> section?

    If you didn't put your module in the <modules> section your module is loaded, but will never be notified.

    Also, when did you download the module starter kit? I should have been updated a couple of weeks ago because it contained a bunch of weird settings that might cause your misery. Here are the updates I made. You might want to check:

    1) Added #define for WIN32 – otherwise there is a data alignment problem with HTTP.SYS structures and you might run into AV’s etc.

    2) Made precompiled headers work. The old project settings only created them, but never use them.

    3) Turned off compiler optimizations in debug builds. Optimized code can make debugging pretty meaningless.

    Hope this helps.

    Thomas Deml
    Program Manager
    Internet Information Services
    Microsoft Corp.
  • 07-17-2006, 12:17 PM In reply to

    Re: Debugging Native Code Modules

    Thomas -

    Aha! I discovered on Friday that one of the project settings was Debug Information Format: Disabled . Changing this enabled me to actually start debugging, but breakpoints were still flaky and fussy about where they were put. Removing optimizations from the project as you suggest has fixed that.

    I suppose if I hadn't been so lazy and I'd created my own project from scratch I wouldn't have hit any of these problems. Thanks for helping me get it sorted.

     

  • 07-17-2006, 1:25 PM In reply to

    • mvolo
    • Top 25 Contributor
    • Joined on 09-17-2003, 1:48 PM
    • Philadelphia, PA
    • Posts 584
    • IIS MVPs

    Re: Debugging Native Code Modules

    Hehe - but we want you to be lazy and we want our default project to work :) We will post an updated version of the kit that fixes this issue shortly.  Not sure how this managed to slip through though ...

    Thanks for finding this.
    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (9 items)
Microsoft Communities