Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* debug dynamically linked modules..
@ 2003-10-16 19:39 Jack J
  2003-10-16 19:44 ` Daniel Jacobowitz
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jack J @ 2003-10-16 19:39 UTC (permalink / raw)
  To: gdb

Hi,

I would like to know how to debug using gdb
(set breakpoint on routine, etc.) a dynmically linked,
relocated code.

The platform is RH Linux 9.0. There is some
application
module compiled with -fPIC and -shared, and
-export-dynamic options.  
A global structure containing functions is exported by
the DLL module.
The problem: I would like to set breakpoint on one
of the (file static) functions contained in this
structure.

From mainline code after call to dlsym(..) (to the
global structure), I try to set break point, and I
get error: "Function xxx not defined.".

I do 'info shared' on gdb and do see the file being
loaded. Also I do see that "-g" option to add
debug symbols in gcc.

Is there anything I am missing ? How does one 
normally use gdb in such scenario ?

Any tips, pointers/hints is appreciated.

Thanks,


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: debug dynamically linked modules..
  2003-10-16 19:39 debug dynamically linked modules Jack J
@ 2003-10-16 19:44 ` Daniel Jacobowitz
  2003-10-16 20:24 ` Jesse Marlin
  2003-10-17  7:11 ` Izo
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2003-10-16 19:44 UTC (permalink / raw)
  To: Jack J; +Cc: gdb

On Thu, Oct 16, 2003 at 12:39:35PM -0700, Jack J wrote:
> Hi,
> 
> I would like to know how to debug using gdb
> (set breakpoint on routine, etc.) a dynmically linked,
> relocated code.
> 
> The platform is RH Linux 9.0. There is some
> application
> module compiled with -fPIC and -shared, and
> -export-dynamic options.  
> A global structure containing functions is exported by
> the DLL module.
> The problem: I would like to set breakpoint on one
> of the (file static) functions contained in this
> structure.
> 
> >From mainline code after call to dlsym(..) (to the
> global structure), I try to set break point, and I
> get error: "Function xxx not defined.".
> 
> I do 'info shared' on gdb and do see the file being
> loaded. Also I do see that "-g" option to add
> debug symbols in gcc.
> 
> Is there anything I am missing ? How does one 
> normally use gdb in such scenario ?
> 
> Any tips, pointers/hints is appreciated.

We'd need to see a complete testcase.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 5+ messages in thread

* debug dynamically linked modules..
  2003-10-16 19:39 debug dynamically linked modules Jack J
  2003-10-16 19:44 ` Daniel Jacobowitz
@ 2003-10-16 20:24 ` Jesse Marlin
  2003-10-17  0:11   ` Jack J
  2003-10-17  7:11 ` Izo
  2 siblings, 1 reply; 5+ messages in thread
From: Jesse Marlin @ 2003-10-16 20:24 UTC (permalink / raw)
  To: Jack J; +Cc: gdb

Jack J writes:
 > Hi,
 > 
 > I would like to know how to debug using gdb
 > (set breakpoint on routine, etc.) a dynmically linked,
 > relocated code.
 > 
 > The platform is RH Linux 9.0. There is some
 > application
 > module compiled with -fPIC and -shared, and
 > -export-dynamic options.  
 > A global structure containing functions is exported by
 > the DLL module.
 > The problem: I would like to set breakpoint on one
 > of the (file static) functions contained in this
 > structure.
 > 
 > >From mainline code after call to dlsym(..) (to the
 > global structure), I try to set break point, and I
 > get error: "Function xxx not defined.".
 > 
 > I do 'info shared' on gdb and do see the file being
 > loaded. Also I do see that "-g" option to add
 > debug symbols in gcc.
 > 
 > Is there anything I am missing ? How does one 
 > normally use gdb in such scenario ?
 > 
 > Any tips, pointers/hints is appreciated.
 > 
 > Thanks,

One thing I do that is successful most of the time is place a
breakpoint on a file:line instead of on a function.  Try looking into
these:

br file:line       - place a breakpoint on a file and line number.
                     C-x SPC does this for you in (X)Emacs.

info shared        - shows which shared libraries are currently loaded.

(gdb) help sharedlibrary
Load shared object library symbols for files matching REGEXP.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: debug dynamically linked modules..
  2003-10-16 20:24 ` Jesse Marlin
@ 2003-10-17  0:11   ` Jack J
  0 siblings, 0 replies; 5+ messages in thread
From: Jack J @ 2003-10-17  0:11 UTC (permalink / raw)
  To: jesse.marlin; +Cc: gdb


yep, I have tried all these, but nothing worked.

I am wondering is this because the main routine
calls the DLL routine via function pointers
stored in structure ?

When I do:

(gdb) dir ~/dll-directory
Source directories searched:
~/dll-directory:$cdir:$cwd
(gdb) l foo_test.c:10
No source file named foo_test.c.

Actually foo_test.c is part of dll-directory.
Doing 'info shared', I do see that dll is loaded.

Thanks,


--- Jesse Marlin <jesse.marlin@intec.us> wrote:
> Jack J writes:
>  > Hi,
>  > 
>  > I would like to know how to debug using gdb
>  > (set breakpoint on routine, etc.) a dynmically
> linked,
>  > relocated code.
>  > 
>  > The platform is RH Linux 9.0. There is some
>  > application
>  > module compiled with -fPIC and -shared, and
>  > -export-dynamic options.  
>  > A global structure containing functions is
> exported by
>  > the DLL module.
>  > The problem: I would like to set breakpoint on
> one
>  > of the (file static) functions contained in this
>  > structure.
>  > 
>  > >From mainline code after call to dlsym(..) (to
> the
>  > global structure), I try to set break point, and
> I
>  > get error: "Function xxx not defined.".
>  > 
>  > I do 'info shared' on gdb and do see the file
> being
>  > loaded. Also I do see that "-g" option to add
>  > debug symbols in gcc.
>  > 
>  > Is there anything I am missing ? How does one 
>  > normally use gdb in such scenario ?
>  > 
>  > Any tips, pointers/hints is appreciated.
>  > 
>  > Thanks,
> 
> One thing I do that is successful most of the time
> is place a
> breakpoint on a file:line instead of on a function. 
> Try looking into
> these:
> 
> br file:line       - place a breakpoint on a file
> and line number.
>                      C-x SPC does this for you in
> (X)Emacs.
> 
> info shared        - shows which shared libraries
> are currently loaded.
> 
> (gdb) help sharedlibrary
> Load shared object library symbols for files
> matching REGEXP.
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: debug dynamically linked modules..
  2003-10-16 19:39 debug dynamically linked modules Jack J
  2003-10-16 19:44 ` Daniel Jacobowitz
  2003-10-16 20:24 ` Jesse Marlin
@ 2003-10-17  7:11 ` Izo
  2 siblings, 0 replies; 5+ messages in thread
From: Izo @ 2003-10-17  7:11 UTC (permalink / raw)
  To: Jack J; +Cc: gdb

There is the difference between the dll loaded at programs start or 
loaded in runtime via dlopen.

1. SO loaded at start

set the 1st breakpoint somewhere at the start into the main program, 
e.g. the first line after the main (... )
then open the source you want to debug and reset the breakpoint there
voila - if you use the gcc-2.95.3 the chances are good that the program 
stops where desired; if you use gcc-3.x/gdb-5.2.x you should compile 
with the -g -g3 -O0 -ggdb (I am using -gstabs+ too since the stabs 
assembly source is more readable than dwarf) and chances are somewhere 
50/50 to program being stopped at right place ...

2. SO loaded at runtime with dlopen

Run the program. Lead it over the point where the SO in question is 
loaded. If you have access to the source code, I suggest to put a 
sleep() at some point that the program would not run away. GDB attach to 
the process. Only then the symbols from SO are loaded. Pretty shitty, 
isn't it ? Maybe Daniel can explain why so ! I am the first that wants 
to know why the GDB can not load the symbols in run time, t.i. - when SO 
is loaded - I have tried to dlopen with all three options possible - 
without single difference in behaviour. :-(

Izo

Jack J wrote:

>Hi,
>
>I would like to know how to debug using gdb
>(set breakpoint on routine, etc.) a dynmically linked,
>relocated code.
>
>The platform is RH Linux 9.0. There is some
>application
>module compiled with -fPIC and -shared, and
>-export-dynamic options.  
>A global structure containing functions is exported by
>the DLL module.
>The problem: I would like to set breakpoint on one
>of the (file static) functions contained in this
>structure.
>
>>From mainline code after call to dlsym(..) (to the
>global structure), I try to set break point, and I
>get error: "Function xxx not defined.".
>
>I do 'info shared' on gdb and do see the file being
>loaded. Also I do see that "-g" option to add
>debug symbols in gcc.
>
>Is there anything I am missing ? How does one 
>normally use gdb in such scenario ?
>
>Any tips, pointers/hints is appreciated.
>
>Thanks,
>
>
>__________________________________
>Do you Yahoo!?
>The New Yahoo! Shopping - with improved product search
>http://shopping.yahoo.com
>
>
>  
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-10-17  7:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-16 19:39 debug dynamically linked modules Jack J
2003-10-16 19:44 ` Daniel Jacobowitz
2003-10-16 20:24 ` Jesse Marlin
2003-10-17  0:11   ` Jack J
2003-10-17  7:11 ` Izo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox