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++

  • 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 – s sato May 21 '19 at 05:24
  • wont work, as its the java command picks up and executes an executable and my so in between – Confused Programmer May 21 '19 at 06: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) – Botje May 21 '19 at 06: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 ? – Confused Programmer May 23 '19 at 10:02

0 Answers0