Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Debugging drivers in Visual studio + WinDBG woes

IkkepopIkkepop Member Posts: 22

Once I started my driver project I was able to debug the driver in source and with breakpoints etc, it was loading symbols fine. At some point the symbols stopped loading and I have no idea what happened. What I tried so far :

  • Altering symbol cache path to include location of my pdb
  • Pushing my pdb to the VM and adding it's path to the sympath
  • Forcing a reload of all symbols after the changes
  • Enabling and disabling "Require source files to exactly match original version"
  • Changing symbol cache path
  • Adding _NT_SYMBOL_PATH and _NT_ALT_SYMBOL_PATH to point to a directory containing pdb
  • Using Ld command (altough I wasnt able to make load absolutely anything, it just complains that module isn't found).

The only temporary fix I managed to get working was setting SYMOPT_LOAD_ANYTHING and using "reload /f /i mydriver.sys", and it cached the exact binary version of the symbol file under a hash, and that is not great as it changes every recompile obviously. That's a pain in the ass, and I want to get automatic loading back, what am I missing, this is gonna give me a stomach ulcer, I'm loosing days of productive work due to the damn debugger failing all the time.

Comments

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,013

    Don’t know what could “just suddenly break” like that.

    Let’s start with the basics: every time you build your driver, a new PDB and executable are generated... and those get a GUID to uniquely identify them. So they have to match exactly.

    If you’re developing and debugging in the same machine, which is ideal, and you’re doing debug builds, the executable will have a debug section that contains a path to the PDB... so finding the PDB should be automatic.

    My best advice: set !sym noisy and watch the search for your PDB. This should solve the mystery.

    And never try to debug a driver from within VS... always use WinDbg.

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • IkkepopIkkepop Member Posts: 22
    edited February 27

    I test the drive in VMWare workstation, cause I crash the kernel constantly, and I need to rollback to a snapshot many many times.
    I debug from my local machine to a VM on the same machine. Yes I do build in debug mode. I do get a .pdb file that I can load.
    I had it working with VS, it was working, and now It's not. I was able to do source level debugging with it, and now I can't. It's as if a moon phase has shifted. Has anyone ever had any positive experience with using Visual Studio for driver debugging or is it just so broken everyone gave up ?
    I can force reload the module and then do it, but it's slow as molases, and VS freezes completely every 2nd or 3rd time i try.
    And I have no idea how to do source level debugging in WinDBG, it's so arcane, looks like it was coded in 1992, and breaks my concentration to have to keep switching between VS and WinDBG. I want to fix it to the state it was before if at all possible.
    And even in PURE WinDBG, it's not loading the symbols automatically, I have to force it.

  • Jason_StephensonJason_Stephenson Member Posts: 74

    Has anyone ever had any positive experience with using Visual Studio for driver debugging or is it just so broken everyone gave up ?

    Personally, I gave up. Take the plunge, WINDBG is far superior in this realm.

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,013

    Did you follow my advice and set !sym noisy?

    I teach people how to write and debug drivers. The first few times they have to do so, they struggle with getting WinDbg set up. After that... smooth sailing.

    Take the advice of somebody who's been doing this a long time: Do not try to debug your driver from within VS. Use WinDbg. It's what it's designed for. If switching back and force "breaks [your] concentration" I recommend you work a little harder on developing your focus.

    I have no idea how to do source level debugging in WinDBG, it's so arcane,

    Really? You ever debug a driver in Linux? Source level debugging is simple. It works the almost identically to the way it works in VS. You click a line. You set a breakpoint. You single-step with F10 or F11. How hard is that?

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • IkkepopIkkepop Member Posts: 22
    edited February 28

    Sorry for ranting, I was just super frustrated. I got the preview WinDBG of the windows store, and thank god that is working pretty well so far.
    Thank you for the reply, much appretiated. For the record I was using the old WinDBG included in Win DDK, and that one was pretty hard to figure out.
    I never debugged anything in linux besides some basic apps. This is my first driver ever.
    I am too used to nice things i guess :neutral:
    Sorry for sounding like a whiny baby :sweat_smile:

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 15 Jun 2020 LIVE ONLINE
Writing WDF Drivers 22 June 2020 LIVE ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA