xref: /openbsd-src/gnu/usr.bin/binutils/gdb/glibc-tdep.c (revision b725ae7711052a2233e31a66fefb8a752c388d7a)
1*b725ae77Skettenis /* Target-dependent code for the GNU C Library (glibc).
2*b725ae77Skettenis 
3*b725ae77Skettenis    Copyright 2002, 2003 Free Software Foundation, Inc.
4*b725ae77Skettenis 
5*b725ae77Skettenis    This file is part of GDB.
6*b725ae77Skettenis 
7*b725ae77Skettenis    This program is free software; you can redistribute it and/or modify
8*b725ae77Skettenis    it under the terms of the GNU General Public License as published by
9*b725ae77Skettenis    the Free Software Foundation; either version 2 of the License, or
10*b725ae77Skettenis    (at your option) any later version.
11*b725ae77Skettenis 
12*b725ae77Skettenis    This program is distributed in the hope that it will be useful,
13*b725ae77Skettenis    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*b725ae77Skettenis    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*b725ae77Skettenis    GNU General Public License for more details.
16*b725ae77Skettenis 
17*b725ae77Skettenis    You should have received a copy of the GNU General Public License
18*b725ae77Skettenis    along with this program; if not, write to the Free Software
19*b725ae77Skettenis    Foundation, Inc., 59 Temple Place - Suite 330,
20*b725ae77Skettenis    Boston, MA 02111-1307, USA.  */
21*b725ae77Skettenis 
22*b725ae77Skettenis #include "defs.h"
23*b725ae77Skettenis #include "frame.h"
24*b725ae77Skettenis #include "symtab.h"
25*b725ae77Skettenis #include "symfile.h"
26*b725ae77Skettenis #include "objfiles.h"
27*b725ae77Skettenis 
28*b725ae77Skettenis #include "glibc-tdep.h"
29*b725ae77Skettenis 
30*b725ae77Skettenis /* Calling functions in shared libraries.  */
31*b725ae77Skettenis 
32*b725ae77Skettenis /* Find the minimal symbol named NAME, and return both the minsym
33*b725ae77Skettenis    struct and its objfile.  This probably ought to be in minsym.c, but
34*b725ae77Skettenis    everything there is trying to deal with things like C++ and
35*b725ae77Skettenis    SOFUN_ADDRESS_MAYBE_TURQUOISE, ...  Since this is so simple, it may
36*b725ae77Skettenis    be considered too special-purpose for general consumption.  */
37*b725ae77Skettenis 
38*b725ae77Skettenis static struct minimal_symbol *
find_minsym_and_objfile(char * name,struct objfile ** objfile_p)39*b725ae77Skettenis find_minsym_and_objfile (char *name, struct objfile **objfile_p)
40*b725ae77Skettenis {
41*b725ae77Skettenis   struct objfile *objfile;
42*b725ae77Skettenis 
43*b725ae77Skettenis   ALL_OBJFILES (objfile)
44*b725ae77Skettenis     {
45*b725ae77Skettenis       struct minimal_symbol *msym;
46*b725ae77Skettenis 
47*b725ae77Skettenis       ALL_OBJFILE_MSYMBOLS (objfile, msym)
48*b725ae77Skettenis 	{
49*b725ae77Skettenis 	  if (SYMBOL_LINKAGE_NAME (msym)
50*b725ae77Skettenis 	      && strcmp (SYMBOL_LINKAGE_NAME (msym), name) == 0)
51*b725ae77Skettenis 	    {
52*b725ae77Skettenis 	      *objfile_p = objfile;
53*b725ae77Skettenis 	      return msym;
54*b725ae77Skettenis 	    }
55*b725ae77Skettenis 	}
56*b725ae77Skettenis     }
57*b725ae77Skettenis 
58*b725ae77Skettenis   return 0;
59*b725ae77Skettenis }
60*b725ae77Skettenis 
61*b725ae77Skettenis /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c.
62*b725ae77Skettenis    This function:
63*b725ae77Skettenis    1) decides whether a PLT has sent us into the linker to resolve
64*b725ae77Skettenis       a function reference, and
65*b725ae77Skettenis    2) if so, tells us where to set a temporary breakpoint that will
66*b725ae77Skettenis       trigger when the dynamic linker is done.  */
67*b725ae77Skettenis 
68*b725ae77Skettenis CORE_ADDR
glibc_skip_solib_resolver(struct gdbarch * gdbarch,CORE_ADDR pc)69*b725ae77Skettenis glibc_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
70*b725ae77Skettenis {
71*b725ae77Skettenis   /* The GNU dynamic linker is part of the GNU C library, and is used
72*b725ae77Skettenis      by all GNU systems (GNU/Hurd, GNU/Linux).  An unresolved PLT
73*b725ae77Skettenis      entry points to "_dl_runtime_resolve", which calls "fixup" to
74*b725ae77Skettenis      patch the PLT, and then passes control to the function.
75*b725ae77Skettenis 
76*b725ae77Skettenis      We look for the symbol `_dl_runtime_resolve', and find `fixup' in
77*b725ae77Skettenis      the same objfile.  If we are at the entry point of `fixup', then
78*b725ae77Skettenis      we set a breakpoint at the return address (at the top of the
79*b725ae77Skettenis      stack), and continue.
80*b725ae77Skettenis 
81*b725ae77Skettenis      It's kind of gross to do all these checks every time we're
82*b725ae77Skettenis      called, since they don't change once the executable has gotten
83*b725ae77Skettenis      started.  But this is only a temporary hack --- upcoming versions
84*b725ae77Skettenis      of GNU/Linux will provide a portable, efficient interface for
85*b725ae77Skettenis      debugging programs that use shared libraries.  */
86*b725ae77Skettenis 
87*b725ae77Skettenis   struct objfile *objfile;
88*b725ae77Skettenis   struct minimal_symbol *resolver
89*b725ae77Skettenis     = find_minsym_and_objfile ("_dl_runtime_resolve", &objfile);
90*b725ae77Skettenis 
91*b725ae77Skettenis   if (resolver)
92*b725ae77Skettenis     {
93*b725ae77Skettenis       struct minimal_symbol *fixup
94*b725ae77Skettenis 	= lookup_minimal_symbol ("fixup", NULL, objfile);
95*b725ae77Skettenis 
96*b725ae77Skettenis       if (fixup && SYMBOL_VALUE_ADDRESS (fixup) == pc)
97*b725ae77Skettenis 	return frame_pc_unwind (get_current_frame ());
98*b725ae77Skettenis     }
99*b725ae77Skettenis 
100*b725ae77Skettenis   return 0;
101*b725ae77Skettenis }
102