Search code examples
powershellwindbgdbgeng

How can I read user input from a debugger extension (dbgeng) in a debugger agnostic way?


I am writing a debugger extension and is looking for a way to get user input from the debugger extension after the extension has started executing.

I am hosting PowerShell in a debugger extension and try to implement support for Read-Host which requires input from the user.

In the debugger I can for example write a script in PSExt_profile.ps1: function Foo{ Read-Host -Prompt "Enter your address" }

and on the debugger command line: !ps Foo

That will invoke PowerShell which runs the Read-Host command.

I don't understand how I can ask the get input from WinDbg from the extension. In cdb I can use the console functions.

Is there a generic way do handle this that is agnostic of the debugger that is loading the extension?


Solution

  • I wrote a debugger extension that hosted PS around 5 years ago. It was specifically designed for Windbg, since there were already solutions for KD and CDB (I think they just redirected stdin and stdout into the driver PS script). Since the code is owned by the company I work for, I'm answering by looking at the API. I see that IDebugControl4::InputWide is an input method.

    The doc for that method refers you to "Using Input and Output". That topic talks about IDebugInputCallbacks. Suggest you read the topic if you haven't already.

    These APIs are in the debug engine so should be generic across all debuggers using the engine.

    We ended up writing a PS Host that used the various debug engine APIs to do input/output. We also hooked the WinProc for the input window in Windbg so we could do tab completion. This allowed both PS and Windbg commands to be entered and tab completed in the input window. There were only a couple of commands that overlapped between the two command sets. ls was one of them. So we had an escape mechanism, something like an extra space at the beginning of the command, to handle the overlap.

    BTW, if you're interested in collaborating on this, let me know. My role at my company changed shortly after we had alpha-ish level code, so never really got to see this to the end. I've been meaning to get back to it (and have my company open source it), but haven't.