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

How do I connect to a running C or C++ process / one that requires input? #177

Open
stmonty opened this issue Dec 2, 2024 · 2 comments
Open

Comments

@stmonty
Copy link

stmonty commented Dec 2, 2024

Hey, I have been enjoying use Dape, but I am not really an expert in debugging and the debugger adapter protocol.
One thing I have been having a hard time figuring out is how do I connect to a currently running C or C++ process?
Is this documented anywhere?

And in particular, how do you get a process to work that requires values from STDIN or some sort of input?

For example, imagine a REPL for a simple language that you could start with ./mylang repl and then type input into.

With gdb you could do something like gdb ./mylang and then gdb run repl and it will allow you to write things in the repl.

However, I am not expecting that level of functionality, but presumably if you could attach to an already running repl process, that should work?

I tried to add the :request "attach" and :pid <mylang's pid> to the minibuffer prompt after starting Dape, and then tried writing something in the repl to see if that would do anything, but it didn't seem to.

Maybe I am just fundamentally misunderstanding how this works. Any help would be appreciated!
(Also I am debugging with debug symbols).

@svaante
Copy link
Owner

svaante commented Dec 9, 2024

Hi!
These things are not under dapes control so each adapter works differently when it comes to stdin and attaching.

If we only want stdin:

  • cpptools :externalConsole t - mylang - An external terminal should launch which the debugged program
  • codelldb-cc - mylang - The debugged program is launched in dape-shell buffer

If we want to attach:

  • cpptools :request "attach" :processId <PID> - mylang
  • codelldb-cc :request "attach" :processId <PID> - mylang
  • lldb-dap :request "attach" :pid <PID> - mylang

But I expect none of this is useful as you are using gdb which I currently do not have a machine which I can test with.

@dvzubarev
Copy link

Attach for gdb:

gdb :request "attach" :pid <PID> - ./a.out

You might need to enable attaching on your system.

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

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

No branches or pull requests

3 participants