GDB (xrefs)

/tmp/gdb-8.1/gdb/glibc-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for the GNU C Library (glibc).
2
3 Copyright (C) 2002-2018 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 3 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, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "frame.h"
22 #include "symtab.h"
23 #include "symfile.h"
24 #include "objfiles.h"
25
26 #include "glibc-tdep.h"
27
28 /* Calling functions in shared libraries. */
29
30 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c.
31 This function:
32 1) decides whether a PLT has sent us into the linker to resolve
33 a function reference, and
34 2) if so, tells us where to set a temporary breakpoint that will
35 trigger when the dynamic linker is done. */
36
37 CORE_ADDR
38 glibc_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
39 {
40 /* The GNU dynamic linker is part of the GNU C library, and is used
41 by all GNU systems (GNU/Hurd, GNU/Linux). An unresolved PLT
42 entry points to "_dl_runtime_resolve", which calls "fixup" to
43 patch the PLT, and then passes control to the function.
44
45 We look for the symbol `_dl_runtime_resolve', and find `fixup' in
46 the same objfile. If we are at the entry point of `fixup', then
47 we set a breakpoint at the return address (at the top of the
48 stack), and continue.
49
50 It's kind of gross to do all these checks every time we're
51 called, since they don't change once the executable has gotten
52 started. But this is only a temporary hack --- upcoming versions
53 of GNU/Linux will provide a portable, efficient interface for
54 debugging programs that use shared libraries. */
55
56 struct bound_minimal_symbol resolver
57 = lookup_minimal_symbol_and_objfile ("_dl_runtime_resolve");
58
59 if (resolver.minsym)
60 {
61 /* The dynamic linker began using this name in early 2005. */
62 struct bound_minimal_symbol fixup
63 = lookup_minimal_symbol ("_dl_fixup", NULL, resolver.objfile);
64
65 /* This is the name used in older versions. */
66 if (! fixup.minsym)
67 fixup = lookup_minimal_symbol ("fixup", NULL, resolver.objfile);
68
69 if (fixup.minsym && BMSYMBOL_VALUE_ADDRESS (fixup) == pc)
70 return frame_unwind_caller_pc (get_current_frame ());
71 }
72
73 return 0;
74 }
gdbarch
Definition: gdbarch.c:127
get_current_frame
struct frame_info * get_current_frame(void)
Definition: frame.c:1563
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
frame_unwind_caller_pc
CORE_ADDR frame_unwind_caller_pc(struct frame_info *this_frame)
Definition: frame.c:944
BMSYMBOL_VALUE_ADDRESS
#define BMSYMBOL_VALUE_ADDRESS(symbol)
Definition: symtab.h:691
glibc_skip_solib_resolver
CORE_ADDR glibc_skip_solib_resolver(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: glibc-tdep.c:38
defs.h
objfiles.h
symtab.h
lookup_minimal_symbol_and_objfile
struct bound_minimal_symbol lookup_minimal_symbol_and_objfile(const char *name)
Definition: minsyms.c:1008
bound_minimal_symbol
Definition: minsyms.h:29
frame.h
glibc-tdep.h
bound_minimal_symbol::minsym
struct minimal_symbol * minsym
Definition: minsyms.h:34
bound_minimal_symbol::objfile
struct objfile * objfile
Definition: minsyms.h:39
lookup_minimal_symbol
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition: minsyms.c:311
symfile.h