1

I am new to Linux space. My project creates 'so' (akin to our dll's) which is used by an executable. Currently to debug, I invoke gdb -tui Which puts me into the gdb terminal where I put break points and do the r with parameters ... and debug. Everything was fine, until now where the entire architecture has been changed.

Now to run our code, we execute a command $ java -jar ... and a lot many parameters. The jar files etc do not belong to us.

I am yet to find out what executable is called, or the code flow.

Question : Is there a way to invoke gdb command from within my source code ?

say

MyClass::myFunc()
{
    some calls
    <THE GDB COMMAND>

What I am looking at is, once I place my 'so' in the path and execute the said java command, the gdb is invoked the moment it hits my function.

The solution provided here wasn't clear. Invoke and control GDB from c++

4
  • I'm not sure this will work in your case. But you can use gdb -p [pid] to debug existing process. You can find your pid with ps command Commented May 21, 2019 at 5:24
  • wont work, as its the java command picks up and executes an executable and my so in between Commented May 21, 2019 at 6:08
  • Have your .so file write its PID somewhere (could be a plain file, a FIFO or a udp port) when it is loaded and then sleep for a few seconds. Have another process wait until the PID is written, then immediately invoke gdb -p PID (or gdbserver or gdb -tui or whatever) Commented May 21, 2019 at 6:25
  • So you are saying, I write the PID to a file, and when my program executes, I open the file, get the PID and the use gdb with the PID and then set the break point to the desired file ? Commented May 23, 2019 at 10:02

0

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.