Commit | Line | Data |
---|---|---|
a3640c75 MK |
1 | /* Target-dependent code for the GNU C Library (glibc). |
2 | ||
4c38e0a4 JB |
3 | Copyright (C) 2002, 2003, 2007, 2008, 2009, 2010 |
4 | Free Software Foundation, Inc. | |
a3640c75 MK |
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 | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
a3640c75 MK |
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 | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
a3640c75 MK |
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 | /* Find the minimal symbol named NAME, and return both the minsym | |
32 | struct and its objfile. This probably ought to be in minsym.c, but | |
33 | everything there is trying to deal with things like C++ and | |
34 | SOFUN_ADDRESS_MAYBE_TURQUOISE, ... Since this is so simple, it may | |
35 | be considered too special-purpose for general consumption. */ | |
36 | ||
37 | static struct minimal_symbol * | |
38 | find_minsym_and_objfile (char *name, struct objfile **objfile_p) | |
39 | { | |
40 | struct objfile *objfile; | |
41 | ||
42 | ALL_OBJFILES (objfile) | |
43 | { | |
44 | struct minimal_symbol *msym; | |
45 | ||
46 | ALL_OBJFILE_MSYMBOLS (objfile, msym) | |
47 | { | |
48 | if (SYMBOL_LINKAGE_NAME (msym) | |
49 | && strcmp (SYMBOL_LINKAGE_NAME (msym), name) == 0) | |
50 | { | |
51 | *objfile_p = objfile; | |
52 | return msym; | |
53 | } | |
54 | } | |
55 | } | |
56 | ||
57 | return 0; | |
58 | } | |
59 | ||
60 | /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c. | |
61 | This function: | |
62 | 1) decides whether a PLT has sent us into the linker to resolve | |
63 | a function reference, and | |
64 | 2) if so, tells us where to set a temporary breakpoint that will | |
65 | trigger when the dynamic linker is done. */ | |
66 | ||
67 | CORE_ADDR | |
bb41a796 | 68 | glibc_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) |
a3640c75 MK |
69 | { |
70 | /* The GNU dynamic linker is part of the GNU C library, and is used | |
71 | by all GNU systems (GNU/Hurd, GNU/Linux). An unresolved PLT | |
72 | entry points to "_dl_runtime_resolve", which calls "fixup" to | |
73 | patch the PLT, and then passes control to the function. | |
74 | ||
75 | We look for the symbol `_dl_runtime_resolve', and find `fixup' in | |
76 | the same objfile. If we are at the entry point of `fixup', then | |
77 | we set a breakpoint at the return address (at the top of the | |
78 | stack), and continue. | |
79 | ||
80 | It's kind of gross to do all these checks every time we're | |
81 | called, since they don't change once the executable has gotten | |
82 | started. But this is only a temporary hack --- upcoming versions | |
83 | of GNU/Linux will provide a portable, efficient interface for | |
84 | debugging programs that use shared libraries. */ | |
85 | ||
86 | struct objfile *objfile; | |
87 | struct minimal_symbol *resolver | |
88 | = find_minsym_and_objfile ("_dl_runtime_resolve", &objfile); | |
89 | ||
90 | if (resolver) | |
91 | { | |
bdfb3870 | 92 | /* The dynamic linker began using this name in early 2005. */ |
a3640c75 | 93 | struct minimal_symbol *fixup |
bdfb3870 JB |
94 | = lookup_minimal_symbol ("_dl_fixup", NULL, objfile); |
95 | ||
96 | /* This is the name used in older versions. */ | |
97 | if (! fixup) | |
98 | fixup = lookup_minimal_symbol ("fixup", NULL, objfile); | |
a3640c75 MK |
99 | |
100 | if (fixup && SYMBOL_VALUE_ADDRESS (fixup) == pc) | |
c7ce8faa | 101 | return frame_unwind_caller_pc (get_current_frame ()); |
a3640c75 MK |
102 | } |
103 | ||
104 | return 0; | |
105 | } |