Search code examples
visual-studiowindbgvisual-studio-2019visual-studio-extensions

Porting WinDbg plugin to Visual Studio 2019 extension


I wrote a WinDbg plugin to assist my developers in debugging our applications. More specifically, it helps in running special diagnostics on the data structures found in our application, and prevents that developers have to manually check lots of data structure information.

I am now considering porting this WinDbg to Visual Studio 2019 (as a VSIX extension), but I don't know where to start. I can investigate how to write such an extension, but I don't know where to start looking for the debugger-related API in Visual Studio.

  • Is there a simple way to reuse a WinDbg plugin in Visual Studio 2019? That would make it very easy for me?
  • If not, what is the API in Visual Studio to get debugging information? Think about: reading memory, getting symbols, getting the address of a vtable, searching memory, getting the call stack, getting generic information? I can do all of this in WinDbg via the IDebug... COM interfaces, but where do I start in Visual Studio 2019?

Solution

  • @Patrick i was googling after i wrote the comment but forgot to update

    it appears vs has its set of own IDebugInterfaces called IDebugEngine1,2 etc

    i never coded a vs extension but is trying to cobble one will update when i get time

    in the meanwhile you may read through this documentation

    it appears to be c# and again that isnt my strong point either

    Requirements
    
    Header: Msdbg.h
    
    Namespace: Microsoft.VisualStudio.Debugger.Interop
    
    Assembly: Microsoft.VisualStudio.Debugger.Interop.dll
    

    there are two samples provided which you can refer to here

    i downloaded this sample but haven't given it enough time

    and it appears the apis are completely different wrt windbg a sample Attach looks like below

    /* static */
    DebuggedProcess^ Worker::AttachToProcess(ISampleEngineCallback^ callback, int processId)
    {
        ASSERT(Worker::MainThreadId != Worker::CurrentThreadId);
    
        HANDLE hProcess = Win32HandleCall( ::OpenProcess(
            PROCESS_ALL_ACCESS, 
            FALSE, 
            processId
            ));
    
        String^ nameFromHandle = GetProcessName(hProcess);
    
        String^ processName = System::IO::Path::GetFullPath(nameFromHandle);
    
        Win32BoolCall( ::DebugActiveProcess(
            processId
            ) );
    
        DebuggedProcess^ process = gcnew DebuggedProcess(Attach, callback, hProcess, processId, processName);
    
        return process;
    }