]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/glibc-tdep.c
run copyright.sh for 2011.
[thirdparty/binutils-gdb.git] / gdb / glibc-tdep.c
1 /* Target-dependent code for the GNU C Library (glibc).
2
3 Copyright (C) 2002, 2003, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include "defs.h"
22 #include "frame.h"
23 #include "symtab.h"
24 #include "symfile.h"
25 #include "objfiles.h"
26
27 #include "glibc-tdep.h"
28
29 /* Calling functions in shared libraries. */
30
31 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c.
32 This function:
33 1) decides whether a PLT has sent us into the linker to resolve
34 a function reference, and
35 2) if so, tells us where to set a temporary breakpoint that will
36 trigger when the dynamic linker is done. */
37
38 CORE_ADDR
39 glibc_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
40 {
41 /* The GNU dynamic linker is part of the GNU C library, and is used
42 by all GNU systems (GNU/Hurd, GNU/Linux). An unresolved PLT
43 entry points to "_dl_runtime_resolve", which calls "fixup" to
44 patch the PLT, and then passes control to the function.
45
46 We look for the symbol `_dl_runtime_resolve', and find `fixup' in
47 the same objfile. If we are at the entry point of `fixup', then
48 we set a breakpoint at the return address (at the top of the
49 stack), and continue.
50
51 It's kind of gross to do all these checks every time we're
52 called, since they don't change once the executable has gotten
53 started. But this is only a temporary hack --- upcoming versions
54 of GNU/Linux will provide a portable, efficient interface for
55 debugging programs that use shared libraries. */
56
57 struct objfile *objfile;
58 struct minimal_symbol *resolver
59 = lookup_minimal_symbol_and_objfile ("_dl_runtime_resolve", &objfile);
60
61 if (resolver)
62 {
63 /* The dynamic linker began using this name in early 2005. */
64 struct minimal_symbol *fixup
65 = lookup_minimal_symbol ("_dl_fixup", NULL, objfile);
66
67 /* This is the name used in older versions. */
68 if (! fixup)
69 fixup = lookup_minimal_symbol ("fixup", NULL, objfile);
70
71 if (fixup && SYMBOL_VALUE_ADDRESS (fixup) == pc)
72 return frame_unwind_caller_pc (get_current_frame ());
73 }
74
75 return 0;
76 }