Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging child processes #317

Open
gilescope opened this issue May 31, 2020 · 13 comments
Open

Debugging child processes #317

gilescope opened this issue May 31, 2020 · 13 comments
Labels
enhancement Enchancement request

Comments

@gilescope
Copy link

When running integration tests on a rust exe, the tests will invoke separate processes to start the executable. This is good because it's testing the external interface, but it really sucks for debugging.

E.g.: https://github.com/ChrisGreenaway/cargo-local-registry/blob/master/tests/all.rs

(As far as I know this approch is the 'right' way to code integration tests for a command line app in rust)

Is there a way that we can launch a child process from a debugged rust process and somehow flag to the debugger that we'd really really like you to debug that also?

(I guess the follow up question is could we then hide that implementation in a crate so that it could support a range of debuggers.)

I don't think we should change how rust does the integration testing because there are many other times where I've created a subprocess that I'd ideally like to be included in the debugging session by default.

If we could find a nice mechanism for this it would be a real step forward for debugging.

@gilescope
Copy link
Author

@vadimcn
Copy link
Owner

vadimcn commented Jun 1, 2020

LLDB does not support child debugging; this isn't something I can implement in the extension on my own.
You could try this though. Not as convenient, but does the job.

@SK83RJOSH
Copy link

LLDB does not support child debugging; this isn't something I can implement in the extension on my own. You could try this though. Not as convenient, but does the job.

I've spent literally hours trying to get this working to no avail. I can only get the debugger to attach if I manually breakpoint and copy out the PID and open the URI in a shell. Is there really no way for this to be exposed via the extension by monitoring what child processes the target has?

@vadimcn
Copy link
Owner

vadimcn commented Jan 25, 2022

Is there really no way for this to be exposed via the extension by monitoring what child processes the target has?

Not really. Intercepting fork() and attaching to the child process before it starts executing requires debugger support. If you don't care about such things, you can probably create a script that does the monitoring and starts new debug sessions.

@SK83RJOSH
Copy link

SK83RJOSH commented Jan 25, 2022 via email

@vadimcn
Copy link
Owner

vadimcn commented Jan 25, 2022

If opening the URI does not work, you can try the RPC server option.

@connorjclark
Copy link

lldb now supports this: llvm/llvm-project@4a2a947

@SK83RJOSH
Copy link

lldb now supports this: llvm/llvm-project@4a2a947

I saw this, but unfortunately it's Linux only and doesn't support Mac OS or Windows. At least not as of that commit, not sure it's been expanded since then. My primary use is so I can debug injected payloads in Windows apps though, as I'm typically working on QoL patches for older games – so unfortunately RPC and URI solutions are the only workarounds for now.

@jasonwilliams
Copy link

Would also love to see this, but can understand that it may need to be implemented one level lower.

Discussions:

@thebestnom
Copy link

thebestnom commented Jun 24, 2023

Wrote a workaround using an extension that listen to process tree and auto attaches
https://marketplace.visualstudio.com/items?itemName=thebestnom.auto-attach-child-processes
(it does means that it will not attach on start but it is good enough for me 😅)

@jasonwilliams
Copy link

jasonwilliams commented Sep 18, 2023

@thebestnom I tried the extension, it does seem to work but uses too much memory and eventually crashes on large applications that spawn many processes (like Chromium). I will continue to keep trying it out though.

I came across this: https://stackoverflow.com/questions/74366554/debug-a-c-child-process-using-vs-code
has it actually worked for anyone?

If you're using LLDB or codeLLDB, here is the LLDB command that mirrors the above except the detach feature:

{
    "configurations": [
        {

            "initCommands": [
                "settings set target.process.follow-fork-mode child"
            ]
        }
    ]
}

@thebestnom
Copy link

thebestnom commented Sep 18, 2023

@jasonwilliams as for my extension open issue there, I can probably make it way quicker and more efficient, it's not the most complicated thing 😂

As for the follow fork, it allows lldb to follow the child by debugging it instead of the main process

@jasonwilliams
Copy link

Thanks @thebestnom I've added an idea here thebestnom/vscode-auto-attach-child-processes#1. As for follow fork, you're right, that won't be useful for this usecase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enchancement request
Projects
None yet
Development

No branches or pull requests

6 participants