1

Is there a way to statically compile a C++ binary that embeds gbd or lldb, so that the debugger can be launched from within the code?

Essentially, I'd like to be able to spawn the debugger from the code without having to run the code from the debugger.

The best analogy is pasting import ipdb; ipdb.set_trace in python code to start a debugger at that line of code.

1

1 Answer 1

1

You don't need to compile in GDB or LLDB for this to work: you can invoke external binary on yourself:

if (some_condition_that_requires_debugging) {
  char cmd[100];
  sprintf(cmd, "/usr/bin/gdb -p %d", getpid());
  // invoke debugger on itself
  system(cmd);
}
Sign up to request clarification or add additional context in comments.

1 Comment

This does not answer the OP's question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.