Eqbal
Eqbal

Reputation: 4880

gdbserver: Error while mapping shared library section

I am having trouble debugging when using gdbserver. gdb shows error loading one of the shared libraries.

Error while mapping shared library sections:
`target:<path to library>': not in executable format: Invalid argument

I have no problem when attaching with gdb using PID. But gdbserver throws the above error and then I am unable to set any breakpoints in that shared lib.

Any idea what could be wrong? I have other libraries from the same application that don't seem to have any problem.

I am running on

Centos 6.7
gdb version 7.11.1
gcc version 4.4.7

Upvotes: 3

Views: 1736

Answers (2)

Rob W
Rob W

Reputation: 348962

I encountered this error in GDB 7.11 (the one that ships with Android's NDK-r20), and it was caused by my library being relatively large (300MB), which tripped a bug in gdbserver's integer parser that prevented gdbserver from loading any library larger than 268MB. The bug got fixed in GDB 8.2, by raising the limit to 2GB (https://sourceware.org/bugzilla/show_bug.cgi?id=23198).

I used GDB's sysroot feature to work around this issue: https://sourceware.org/gdb/current/onlinedocs/gdb/Files.html#index-set-sysroot
I copied the libraries from the remote target to my local system* and used set sysroot sysroot-here (where "sysroot-here" is a directory containing the directories/files that I had copied). This forces GDB to read symbols locally instead of from the target.

With this sysroot approach, I did not only work around the bug, but I was also able to use the library with full debugging symbols (about 3GB, which would probably also have tripped newer GDB versions).

* I copied all system libraries and the app's libraries, while preserving the full directory structure / file paths. I wanted to only copy the specific library that triggered the bug, but with sysroot it is all or nothing: Either all libraries are to be found locally on the host, or none. See also: A way to have GDB load libraries from local sysroot and remote gdbserver

Upvotes: 1

Eqbal
Eqbal

Reputation: 4880

I found that gdb version 7.10+ has this problem with my particular binary. Still not sure why. This works fine with 7.9 so I downgraded to overcome this issue.

Upvotes: 0

Related Questions