Gdb linux shared library

Need to load debugging symbols for shared library in GDB

I am using GDB to debug a program that uses libpthread. There is an error happening in pthread_create and need to step into that function. Unfortunately when I am debugging my program, it does not load the shared library symbols properly so I can’t step over the source code and examine program behaviour meaningfully.. This is the output as soon as I start gdb.

Remote debugging using 127.0.0.1:21293 warning: limiting remote suggested packet size (206696 bytes) to 16384 Failed to read a valid object file image from memory. 

So I believe the last message is related to the failure to read debugging symbols. This is despite having the libc6-dbg package installed. This is the truncated output of «where» at a point just before a SIGSEGV is encountered (in pthread_create, the function I want to examine in the debugger)

#0 0x68200ce2 in ?? () #1 0x68403cbf in ?? () #2 0x687571b0 in ?? () #3 0x6874c638 in ?? () #4 0x68867a72 in ?? () . 
683f8000-68410000 r-xp 00000000 08:01 3017052 /lib/i386-linux-gnu/i686/cmov/libpthread-2.19.so 68410000-68411000 r--p 00017000 08:01 3017052 /lib/i386-linux-gnu/i686/cmov/libpthread-2.19.so 68411000-68412000 rw-p 00018000 08:01 3017052 /lib/i386-linux-gnu/i686/cmov/libpthread-2.19.so 

I believe that if I could only manually load the debugging symbols into gdb, then I will be able to step over the source code and find the source of my memory error. However I am unsure about how to do this. I am debugging a 32 bit program on x86_64 Debian. What should I do to load libpthread symbols into GDB so that I can debug it meaningfully?

Источник

How to runtime debug shared libraries?

Can anyone tell me how to do runtime debugging on shared libraries? I need to runtime-debug a function in my shared library, but its called by another program. How can I do something like dbx with shared libraries? I m using dbx on AIX. is gdb better than dbx for what I m trying to do?.

6 Answers 6

You just need to call gdb with the executable (it does not matter if it is yours or a 3rd party one). Here is an example where I debug the ls command and set a breakpoint in the (shared) c library. This example uses gdb 6.8 which supports deferred (pending) breakpoints which makes this easy:

gdb /bin/ls GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". (no debugging symbols found) (gdb) b write Function "write" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (write) pending. (gdb) r Starting program: /bin/ls (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) [Thread debugging using libthread_db enabled] (no debugging symbols found) (no debugging symbols found) [New Thread 0x7f98d2d23780 (LWP 7029)] [Switching to Thread 0x7f98d2d23780 (LWP 7029)] Breakpoint 1, 0x00007f98d2264bb0 in write () from /lib/libc.so.6 (gdb) 

As you can see gdb automatically manages all threads used by the executable. You don’t have to do anything special for threads there. The breakpoint will work in any thread.

Читайте также:  Поставить часовой пояс linux

Alternatively if you want to attach the debugger to an already running application (I use tail -f /tmp/ttt here as an example):

ps ux | grep tail lothar 8496 0.0 0.0 9352 804 pts/3 S+ 12:38 0:00 tail -f /tmp/ttt lothar 8510 0.0 0.0 5164 840 pts/4 S+ 12:39 0:00 grep tail gdb GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". (no debugging symbols found) (gdb) attach 8496 Attaching to program: /usr/bin/tail, process 8496 Reading symbols from /lib/librt.so.1. (no debugging symbols found). done. Loaded symbols for /lib/librt.so.1 Reading symbols from /lib/libc.so.6. (no debugging symbols found). done. Loaded symbols for /lib/libc.so.6 Reading symbols from /lib/libpthread.so.0. (no debugging symbols found). done. [Thread debugging using libthread_db enabled] [New Thread 0x7f24853f56e0 (LWP 8496)] Loaded symbols for /lib/libpthread.so.0 Reading symbols from /lib/ld-linux-x86-64.so.2. (no debugging symbols found). done. Loaded symbols for /lib64/ld-linux-x86-64.so.2 (no debugging symbols found) 0x00007f2484d2bb50 in nanosleep () from /lib/libc.so.6 (gdb) b write Breakpoint 1 at 0x7f2484d57bb0 (gdb) c Continuing. [Switching to Thread 0x7f24853f56e0 (LWP 8496)] Breakpoint 1, 0x00007f2484d57bb0 in write () from /lib/libc.so.6 (gdb) 

Источник

sharedlibrary command

Forces GDB to load symbols for the specified shared libraries or all loaded shared libraries.

Syntax

sharedlibrary
sharedlibrary [Library Name]
sharedlibrary [Regular Expression]
share [. ]

Parameters

Library Name Specifies the library to load debugging symbols for. Regular Expression When specified, GDB will load the symbols for all currently loaded libraries matching the specified expression.

Читайте также:  What is scp command in linux

Remarks

Normally, GDB will load the shared library symbols automatically. You can control this behavior using set auto-solib-add command. However, in some cases (e.g. when debugging with gdbserver and having incompatible symbols or using old Android toolchains) GDB will not load the symbols automatically. In this case you can use the info sharedlibrary command to list the loaded shared libraries and the sharedlibrary command to force the symbols to be loaded.

If GDB does not automatically load debugging symbols for your library when debugging with gdbserver, please check the search path using the set solib-search-path command.

Examples

In this example we will disable shared library loading using the set auto-solib-add command, then run the application, list the source files and load the symbols manually:

(gdb) set auto-solib-add off
(gdb) break main
Breakpoint 1 at 0x80484ed: file main.cpp, line 7.
(gdb) run
Starting program: /home/testuser/libtest/testApp

Breakpoint 1, main () at main.cpp:7
7 printf(«In main()\n»);
(gdb) info sources
Source files for which symbols have been read in:

Source files for which symbols will be read in on demand:

(gdb) info sharedlibrary
From To Syms Read Shared Object Library
0xb7fde820 0xb7ff6b9f No /lib/ld-linux.so.2
0xb7fd83a0 0xb7fd84c8 No /home/testuser/libtest/libTest.so
0xb7e30f10 0xb7f655cc No /lib/i386-linux-gnu/libc.so.6
(gdb) sharedlibrary libTest
Reading symbols from /home/testuser/libtest/libTest.so. done.
Loaded symbols for /home/testuser/libtest/libTest.so
(gdb) info sources
Source files for which symbols have been read in:

Source files for which symbols will be read in on demand:

/home/testuser/libtest/lib.cpp
(gdb) break lib.cpp:5
Breakpoint 2 at 0xb7fd846e: file lib.cpp, line 5.
(gdb) continue
Continuing.
In main()

Breakpoint 2, func () at lib.cpp:5
5 printf(«In func()\n»);

Compatibility with VisualGDB

Normally VisualGDB automatically manages the shared library symbol loading. Alternatively you can always issue the sharedlibrary command using the GDB Session window.

Источник

How to make gdb print symbols in shared libraries loaded with dlopen?

I want to debug a process running on Linux 2.6 using GDB. attach PID (where PID is the process ID), print main , print sin , print gzopen and print dlopen work (i.e. they find the respective symbols). But print myfoo doesn’t work, where myfoo is a function loaded by the process from an .so file using dlopen . Here is what I get:

(gdb) print main $3 = 0x805ba90 (gdb) print sin $4 = > 0xb7701230 (gdb) print gzopen $5 = > 0xb720df50 (gdb) print dlopen $6 = > 0xb77248e0 (gdb) print myfoo No symbol "myfoo" in current context. 

How do I get GDB to find myfoo ? The function myfoo does indeed exist, because in the program I managed to get its address using dlsym (after dlopen ), and I managed to call it. Only after that I attached GDB to the process. It turned out that there was a mydir/mylib.so: No such file or directory error message printed by the attach $PID command of GDB. Apparently GDB was started in the wrong directory. Doing the proper cd before starting GDB fixed the problem, and print myfoo started working. I’d like to automate this: I want GDB figure out where my .so files (loaded with dlopen ) are. An approximation I can think of is examining /proc/$PID/maps (on Linux), finding possible directories, and adding all of them to the GDB library search path before starting GDB. Extending LD_LIBRARY_PATH and doing a set solib-search-path /tmp/parent didn’t work ( ls -l /tmp/parent/mydir/myfoo.so does work), GDB still reported the No such file or directory . How do I tell GDB where to look for mydir/myfoo.so ? My other question is how do I get the list of possible directories? On Linux, /proc/$PID/maps contains them — but what about other operating systems like FreeBSD and the Mac OS X?

Читайте также:  Computer network commands linux

Источник

Debugging shared libraries remotely with gdb/gdbserver

My question is about remote debugging an application on an embedded arm processor using gdb/gdbserver. I can debug the application itself, but the application dynamically links to a shared library which implements an in house communications protocol. I want to be able to set breakpoints within the shared library functions so try to figure out some device discovery problems. I have made sure that the library is compiled with debug symbols and is loaded by gdb on the host side, I can list functions within the library and even set the breakpoints but as soon as I try to run the application I get an error message to the effect of: Cannot insert breakpoint X. Error accessing memory address [Hex address]: Input/output error. where X is the breakpoint number in gdb and [Hex address] is an address far to small to be valid.
I am using the new library on both the target and the host machine, but via mount -o bind newlib oldlib on the target from an nfs mount.
Does anyone have an idea about what could be wrong? Thanks in advance.

4 Answers 4

I see this question is from 2009, but the current answers are out-of-date, so here’s an update:

@Employed Russian suggested that you must use stop-on-solib-event . This is no longer true; NDK r8d supports pending breakpoints in yet-to-be-loaded solibs.

@Brent Piddy says that stop-on-solib-event doesn’t work with gdbserver. This is also no longer true since at least r8c. My company has a product that relies on this NDK behavior from GDB, we would be in big trouble without it.

Источник

Оцените статью
Adblock
detector