1

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?

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222

1 Answers1

2

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.

Χpẘ
  • 3,403
  • 1
  • 13
  • 22
  • I'd be thrilled to get some help. Code is at https://github.com/powercode/PSExt. And yes, I have read the docs but all I get to work is getting called back for input (so that I can return input with ReturnInput). Feel like I'm missing something. – Staffan Gustafsson Jan 14 '16 at 20:58
  • Did this answer your question? (I'll take a look at the link. Do you have a set of features or other goals defined?) – Χpẘ Jan 14 '16 at 21:01
  • My goal is to create a more strongly typed interface to the debuggers, that is easy to script. As of now, I have a generic Invoke-DbgCommand that justs get me debugger output on the PowerShell pipeline, and implementations of 'k' and 'lm'. TabCompletion would be awesome :) – Staffan Gustafsson Jan 14 '16 at 21:05
  • I see you already are using InputWide in Debugger.ReadLine, so I'm probably not understanding your question in the OP. Or is it not working as expected. I'll dig up our old source and see what we did. – Χpẘ Jan 14 '16 at 21:12