I have a windows PC that is connected to a Linux server in LAN. The Windows is running Windows 10 64 bit while the Linux is Ubuntu 12.04 LTS (GNU/Linux 3.2.0-24-generic x86_64) CPU: Intel(R) Xeon(R) CPU E3-1505M v6 @ 3.00GHz.
I am trying to debug an .so file that is written in C targeted for the Linux server.
I get the process that accessing my .so file's PID and I run the gdbserver with this command gdbserver --attach :9999 <pid>.
From my windows PC using cygwin64 gdb I used file command to read the local copy of the .so file and connect to the gdbserver using gdb target attach <linuxServerIp>:9999.
The problem is I cannot add breakpoint remotely from the windows pc. Any command to add breakpoint will cause Fail to access memory.
(gdb) break my_func
Breakpoint 1 at 0x36a13: my_func. (2 locations)
(gdb) c
Continuing.
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x36a13
Upon some inspection I try to run
(gdb) print my_func
$1 = {int ()} 0x369ff <my_func>
Then I try to run the gdb locally in the linux server. I run the print my_func and same address is retrieved
(gdb) print my_func
$1 = {int ()} 0x369ff <my_func>
Then I try to connect to the process using attach PID
(gdb) attach 28290
Attaching to process 28290
And then try to print my_func address and add breakpoint to it.
(gdb) print my_func
$2 = false
(gdb) break my_func
Breakpoint 1 at 0x7fffe5b46a13: file src/myFlow/my_func.c, line 55.
(gdb) c
Continuing.
Notice here the address is not same as previously. Using this new memory, I able to break and inspect line by line. I then restarted the gdbserver, reconnect from my windows's gdb and try to break using this address in host PC. Now it able to break correctly.
(gdb) break *0x7fffe5b46a13
Breakpoint 1 at 0x7fffe5b46a13
Why my SO file change the function address when it is been loaded by external process? Why gdb in Linux PC able to translate the function address correctly when attaching to the PID while gdb in my windows PC that is connected using GDBServer cannot translate the address?
ps aux | grep <mySoFileName>-- this wouldn't work -- the.sodoes not run by itself; it's loaded by some process and the.sowill not appear inpsoutput.