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