microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.4k stars 1.51k forks source link

[Visual C++] Allow child process debugging #1211

Open zjturner opened 6 years ago

zjturner commented 6 years ago

WinDbg has the .childdbg option which will automatically cause the debugger to attach to child processes when the parent calls CreateProcess.

GDB has a similar option, where you can set it to follow forks. #511 is related, and a workaround is offered in the comments to enable setting the follow fork mode to on. But this is not the ideal solution, because it doesn't provide any solution for the Windows Debug Engine, cppvsdbg. It would be nice if the launch.json configuration supported a simple boolean variable, debugChildProcess which you could set to true or false. By default it's false, and the user can override it.

stephanreiter commented 5 years ago

I'd like to see this, too! :) VS has it; would like to have it in VSCode, too.

johnmalatras commented 4 years ago

I (and the rest of the Edge team) would really love this!

darktears commented 4 years ago

I (and the rest of the Chromium community) would really love this!

nathanesau commented 4 years ago

Is there any update on this?

feliwir commented 4 years ago

Any news here?

Vinschni commented 4 years ago

Any news?

ashtul commented 3 years ago

Anything? Any workaround in the meantime?

kaifastromai commented 3 years ago

I agree. This would be great.

JewinH commented 3 years ago

any news?

rlabrecque commented 3 years ago

What needs to happen for this to move forward? Which part needs to be implemented and roughly where?

It seems like this mostly works in cppdbg with gdb.

cc: @WardenGnaw

More Info:

https://marketplace.visualstudio.com/items?itemName=vsdbgplat.MicrosoftChildProcessDebuggingPowerTool

https://github.com/microsoft/vscode-cpptools/issues/5505#issuecomment-629528619

https://github.com/microsoft/vscode-debugadapter-node/commit/015ff7144ca351d512e3aa3a72ad29e617531630

https://github.com/microsoft/vscode-cpptools/issues/1723


I actually found something that works fairly well for my use case, the multi-process debugging in VSCode works fairly well if both processes are started via the vscode launch config. I have a dll injector, custom dll, and third party application. I start the third party application + dll injector at the same time, now. And this is working great for my purposes. Wish I found it before I spent time adding CreateProcess support into my dll injector!

dtrottier-avigilon commented 3 years ago

Any update on this?

zeroxia commented 3 years ago

I have the main process launch the same executable with different command line options as child process, the "Microsoft Child Process Debugging Power Tool" for Visual Studio works well, hope VS Code could have this feature as well.

tustin2121 commented 2 years ago

Is this still not implemented? That's disappointing. Now I have to futz around with the gdb debugger to do something that's apparently so basic.

EDIT: Oh, AND the vsdbg is closed source, so no one else can add this feature ether?! Jesus Christ, guys, what the hell??

frankli0324 commented 2 years ago

this is WAY overdue. shame.

vinay-y commented 1 year ago

How is this still not implemented?

yizhao5 commented 1 year ago

Hello, excuse me.

The background is that I use vscode to debug chromium's CPP code, and chromium is a multi-process project. In addition, with the development of society, multi process design is also being widely adopted by apps.

When the user needs to debug a bug, but it is not clear which process it will appear in or a sub-process will die soon, so I hope vscode can automatically attach to the child process. Or when users want to debug scenarios with multiple subprocesses, it can be more convenient. But now vscode can only manually attach one by one.

11 Fig. 1. vscode cannot automatic attach subprocess, but only manually attach one by one.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach Debug",
      "type": "cppvsdbg", // "cppdbg" for GDB/LLDB, "cppvsdbg" for Windows Visual Studio debugger
      "request": "attach",
      "processId": "${command:pickProcess}",
      "args": [],
      "stopAtEntry": false,
      "environment": [],
      "console": "externalTerminal",
    }
  ]
}

Fig. 2. launch.json

Thanks.

Cc: @WardenGnaw, @sean-mcmanus

jasonwilliams commented 1 year ago

@michelleangela @sean-mcmanus do you know how likely it is we will see any development on this? It's very much needed for multi-process applications like chromium plus others. Trying to debug is painful without it.

VSCode already supports multi process, debugging js on chrome for example now shows you each tab. So it’s just for this extension to support it.

michelleangela commented 1 year ago

@WardenGnaw is one of the team members who works on the debugger portion of the extension. @WardenGnaw are there any plans for child process debugging?

jasonwilliams commented 1 year ago

@xisui-MSFT may have an idea also as they seem to have been doing some work in the same area

sean-mcmanus commented 1 year ago

Andrew didn't respond yet...I'll ping him...

jasonwilliams commented 1 year ago

Hey @sean-mcmanus how did you get on pinging Andrew?

sean-mcmanus commented 1 year ago

@jasonwilliams There is no additional news/update on this issue.

linxin2020 commented 1 year ago

I also urgently need this feature. I use vscode to debug Chromium, which feels much smoother than on Visual Studio 2019, but cannot support sub processes, which is troublesome.

jasonwilliams commented 1 year ago

My understanding is it calls into vsdbg.exe which is the VS Debugger. But I don't see Visual Studio ever call into this binary when debugging, so is vsdbg specifically for vscode?

Either way, I'm guessing support needs to happen there (but it's closed source). Visual Studio does support child process debugging so I don't understand how that has the capabilities but this doesn't, are they using the same underlying debugger? If so, does this just need to be surfaced at VSCode level? Is this doable via the Debug Adaptor Protocol?

albertziegenhagel commented 1 year ago

My understanding is it calls into vsdbg.exe which is the VS Debugger. But I don't see Visual Studio ever call into this binary when debugging, so is vsdbg specifically for vscode?

My understanding is that the analog binary for Visual Studio is msvsmon.exe. But underneath both use the "VSDebugEngine" (i.e. for debugging Windows binaries, aka. the cppvsdbg debugger type in VS Code. If debugging on Linux or with gdb/lldb in general, as far as I know, thinks work differently).

Anyways, it is possible to write extensions to that debugging engine that work in both VS as well as VS Code (see https://github.com/microsoft/ConcordExtensibilitySamples). And I think the "Child Process Debugging Power Tool 2022" extension for VS does actually employ such a "Concord extension", that in theory should work for VS Code as well. But unfortunately the concord extension is only half the story, because when the extension figures out that a child process has launched and it wants to attach to it, it needs to pass that information to the editor, and to my understanding that is currently missing in vscode-cpptools (or vsdbg.exe. I am note sure exactly sure about that part).

I do have a (very rough) prototype of such a concord extension that works with VS Code. The basic idea is that it internally sets a breakpoint at CreateChildProcess (and similar) calls and reads the returned PID after the call finished. Hence it knows the process it needs to attach to. But when I want to make VS Code attach to that process via the API call DkmDebugProcessRequest I do get a "not implemented" error for VS Code. I implemented some ugly workarounds that kind of work, but due to the communication between the concord extension and VS Code being limited, I run in several other problems that I could not resolve yet.

If there is interest, I can open source what I have so far, but as I said it is all very rough prototypes, is not usable at the moment and I am not sure when I will be able to continue working on it.

jasonwilliams commented 1 year ago

@albertziegenhagel that's incredible, thanks for the explanation, and yes, I would be interested in seeing it, even if it is unfinished. I doubt I'd be able to help much but there may be others in this thread who can!

albertziegenhagel commented 1 year ago

I have pushed the code for the "Concord" extension to

https://github.com/albertziegenhagel/childdebugger-concord

and the regular VS Code extension that is supposed to work together with the Concord extension can be found at

https://github.com/albertziegenhagel/childdebugger-vscode

As I said: These are just prototypes! But if anyone wants to pick that work up or has any questions, feel free to open issues there.

And of course I would be more than happy if anyone from Microsoft (or just anyone for that matter) who has a deeper understanding of how the debug engine extension can work together with the actual VS Code extension could give any hints how to make all that a "production ready" implementation.

jo-pillar commented 1 year ago

仍然没有新进展

neuxys commented 11 months ago

Any news?

ener-jay commented 5 months ago

Hi. Any update on this?

albertziegenhagel commented 5 days ago

Do you have instructions on how to setup the concord extension? Did you build it then put the binary in a particular directory? It would be great if you had some steps on how we can test these out

Both projects do actually have pre-build binaries in their respective GitHub releases (but of course you could build them from source if you want. There is no documentation on how to build from source yet, but the Github action workflows should give you a good idea of what needs to be done).

Additionally, I have just added a very rough getting started guide to the README of the vscode extension project which you can find here:

https://github.com/albertziegenhagel/childdebugger-vscode?tab=readme-ov-file#getting-started

Let me know if there are any issues or something is unclear.