Debugging with GDB (September 2007)
Chapter 14: HP-UX Configuration-Specific Information 171
14.20 De bugging support for shared libraries
On HP-UX, shared libraries are special. Until the library is loaded, GDB does not
know the names of symbols. However, GDB gives you two ways to se t breakpoints in
shared libraries:
• deferred breakpoints
• catch load command
14.20.1 Using shared library as main program
If the main program is in a shared library and you try to load it as follows:
(gdb) symbol-file main.sl
Load new symbol table from "main.sl"? (y or n) y
Reading symbols from main.sl
done.
Things don’t appear to work.
This command is not the correct thing to do. This command assumes that main.sl is
loaded at its link time address. This is not not true for shared libraries.
Do not use symbol-file with shared libraries.
Instead, what you should do is to use the deferred breakpoint feature to set breakpoints
on any functions necessary before the program starts running.
(gdb) b main
Breakpoint 1 (deferred) at "main" ("main" was not found).
Breakpoint deferred until a shared library containing "main" is loaded.
(gdb) r
Once the program has started running, it will hit the breakpoint. In addition, the de-
bugger will then already know about the sources for main, since it gets this information
when the shared library is loaded.
14.20.2 Setting Deferred Breakpoints in Shared Library
On HP-UX, GDB automatically loads symbol definitions from shared libraries when
you use the run command, or when you examine a core file. (Before you issue the run
command, GDB does not understand references to a function in a shared library—
unless you are debugging a core file.)
When you specify a breakpoint using a name that GDB does not recognize, the debug-
ger warns you with a message that it is setting a deferred breakpoint on the name you
specified. If any shared library is loaded with a matching name, then GDB sets the
breakpoint.
For example, if you type:
‘break foo’
the debugger does not know whether foo is a misspelled name or whether it is the name
of a routine that has not yet been loaded from a shared library. The debugger displays