user545199
user545199

Reputation:

Missing symbol names in gdbserver but not with gdb

I wanted to start using gdbserver for remote debugging and so I tested-out its functionality on my local machine with a simple test program that generates a segfault shown below:

segfault.c -- compiles to elf named "test"

#define NULL ((void*)0)
int main()
{
    int value = *((int*)NULL);
    return value;
}

Now when I run:

#gdb test

(gdb)run

I get:

Starting program: /home/awaibel/digiworkspace/test/Debug/test 

Program received signal SIGSEGV, Segmentation fault.
0x080483bf in main () at ../segfault.c:4
4       int value = *((int*)NULL);

however if I debug it with gdb server like so:

#gdbserver :65535 test

#gdb test

(gdb)target remote 127.0.0.1:65535

(gdb)continue

it gives me the debug info:

Program received signal SIGSEGV, Segmentation fault.
0x080483bf in ?? ()

it seems to give the same function address for the segfault, but the name and line number is omitted when debugging with the remote debugger. is it possible to have the remote debugger display this information, and if so, how?

I guess I should add that the program was compiled with GCC using the "-g" debug flag

Upvotes: 1

Views: 1919

Answers (2)

GAB1BB0
GAB1BB0

Reputation: 1

Even if this question was asked a lot of time ago, I will answer by giving my context, it may be useful to someone else. Thanks to @user545199 for giving me the right way to solve this problem.

Context (Android device):

  • Server: Google Pixel 7 (ARM-v8) no root access - c file to execute compiled with ndk-build - gdb-server: 12.1 configured as "aarch64-linux-gnu"
  • Client: Ubuntu with gdb-multiarch: GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1

Executed commands:

  • (device setup): adb forward tcp:<port-A> tcp:<port-B>
  • Server: gdb-server :<port-A> <exe-file> --multi
  • Client (w/ GEF installed):
    • gdb-multiarch <same exe file in the Pixel>
    • gef-remote <127.0.0.1> <port-B> (or equivalent)

Upvotes: 0

user545199
user545199

Reputation:

Thanks to markys' comments I was able to figure out the problem. Since the gdb client is what parses the symbols and not the server, I had to make sure the client knew the full path to a copy of the executable. Since 'test' was not in the current directory for the command prompt that was used to run gdbtest it did not have a copy of the symbols to use. adding the the binary to PATH for the terminal running the client solved the problem. Thanks.

Summarizing:

  • server side:

gdbserver --multi :port "path-to-executable"

  • client side:

gdb "path-to-executable" (gdb)> target remote "ip-of-the-remote-device:port"

Upvotes: 2

Related Questions