GDB (xrefs)

/tmp/gdb-8.1/gdb/hppa-bsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for HP PA-RISC BSD's.
2
3 Copyright (C) 2004-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 "objfiles.h"
22 #include "target.h"
23 #include "value.h"
24
25 #include "elf/common.h"
26
27 #include "hppa-tdep.h"
28 #include "hppa-bsd-tdep.h"
29 #include "dwarf2-frame.h"
30 #include "solib-svr4.h"
31
32 static CORE_ADDR
33 hppabsd_find_global_pointer (struct gdbarch *gdbarch, struct value *function)
34 {
35 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
36 CORE_ADDR faddr = value_as_address (function);
37 struct obj_section *faddr_sec;
38 gdb_byte buf[4];
39
40 /* Is this a plabel? If so, dereference it to get the Global Pointer
41 value. */
42 if (faddr & 2)
43 {
44 if (target_read_memory ((faddr & ~3) + 4, buf, sizeof buf) == 0)
45 return extract_unsigned_integer (buf, sizeof buf, byte_order);
46 }
47
48 /* If the address is in the .plt section, then the real function
49 hasn't yet been fixed up by the linker so we cannot determine the
50 Global Pointer for that function. */
51 if (in_plt_section (faddr))
52 return 0;
53
54 faddr_sec = find_pc_section (faddr);
55 if (faddr_sec != NULL)
56 {
57 struct obj_section *sec;
58
59 ALL_OBJFILE_OSECTIONS (faddr_sec->objfile, sec)
60 {
61 if (strcmp (sec->the_bfd_section->name, ".dynamic") == 0)
62 break;
63 }
64
65 if (sec < faddr_sec->objfile->sections_end)
66 {
67 CORE_ADDR addr = obj_section_addr (sec);
68 CORE_ADDR endaddr = obj_section_endaddr (sec);
69
70 while (addr < endaddr)
71 {
72 gdb_byte buf[4];
73 LONGEST tag;
74
75 if (target_read_memory (addr, buf, sizeof buf) != 0)
76 break;
77
78 tag = extract_signed_integer (buf, sizeof buf, byte_order);
79 if (tag == DT_PLTGOT)
80 {
81 CORE_ADDR pltgot;
82
83 if (target_read_memory (addr + 4, buf, sizeof buf) != 0)
84 break;
85
86 /* The NetBSD/OpenBSD ld.so doesn't relocate DT_PLTGOT, so
87 we have to do it ourselves. */
88 pltgot = extract_unsigned_integer (buf, sizeof buf,
89 byte_order);
90 pltgot += ANOFFSET (sec->objfile->section_offsets,
91 SECT_OFF_TEXT (sec->objfile));
92
93 return pltgot;
94 }
95
96 if (tag == DT_NULL)
97 break;
98
99 addr += 8;
100 }
101 }
102 }
103
104 return 0;
105 }
106
107
108 static void
109 hppabsd_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
110 struct dwarf2_frame_state_reg *reg,
111 struct frame_info *this_frame)
112 {
113 if (regnum == HPPA_PCOQ_HEAD_REGNUM)
114 reg->how = DWARF2_FRAME_REG_RA;
115 else if (regnum == HPPA_SP_REGNUM)
116 reg->how = DWARF2_FRAME_REG_CFA;
117 }
118
119 void
120 hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
121 {
122 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
123
124 /* OpenBSD and NetBSD have a 64-bit 'long double'. */
125 set_gdbarch_long_double_bit (gdbarch, 64);
126 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
127
128 /* OpenBSD and NetBSD use ELF. */
129 tdep->is_elf = 1;
130 tdep->find_global_pointer = hppabsd_find_global_pointer;
131 tdep->in_solib_call_trampoline = hppa_in_solib_call_trampoline;
132 set_gdbarch_skip_trampoline_code (gdbarch, hppa_skip_trampoline_code);
133
134 /* OpenBSD and NetBSD use SVR4-style shared libraries. */
135 set_solib_svr4_fetch_link_map_offsets
136 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
137
138 /* Hook in the DWARF CFI frame unwinder. */
139 dwarf2_frame_set_init_reg (gdbarch, hppabsd_dwarf2_frame_init_reg);
140 dwarf2_append_unwinders (gdbarch);
141 }
gdbarch_tdep::find_global_pointer
CORE_ADDR(* find_global_pointer)(struct gdbarch *, struct value *)
Definition: hppa-tdep.h:97
gdbarch
Definition: gdbarch.c:127
SECT_OFF_TEXT
#define SECT_OFF_TEXT(objfile)
Definition: objfiles.h:686
hppa-tdep.h
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
dwarf2_frame_state_reg
Definition: dwarf2-frame.h:70
floatformats_ieee_double
const struct floatformat * floatformats_ieee_double[BFD_ENDIAN_UNKNOWN]
Definition: gdbtypes.c:76
obj_section::the_bfd_section
struct bfd_section * the_bfd_section
Definition: objfiles.h:126
hppa_skip_trampoline_code
CORE_ADDR hppa_skip_trampoline_code(struct frame_info *frame, CORE_ADDR pc)
Definition: hppa-tdep.c:2952
set_gdbarch_skip_trampoline_code
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype skip_trampoline_code)
Definition: gdbarch.c:3316
gdbarch_tdep::in_solib_call_trampoline
int(* in_solib_call_trampoline)(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: hppa-tdep.h:102
obj_section_endaddr
#define obj_section_endaddr(s)
Definition: objfiles.h:146
gdbarch_tdep
Definition: aarch64-tdep.h:55
frame_info
Definition: frame.c:85
svr4_ilp32_fetch_link_map_offsets
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3183
ALL_OBJFILE_OSECTIONS
#define ALL_OBJFILE_OSECTIONS(objfile, osect)
Definition: objfiles.h:630
HPPA_PCOQ_HEAD_REGNUM
Definition: hppa-tdep.h:44
hppabsd_dwarf2_frame_init_reg
static void hppabsd_dwarf2_frame_init_reg(struct gdbarch *gdbarch, int regnum, struct dwarf2_frame_state_reg *reg, struct frame_info *this_frame)
Definition: hppa-bsd-tdep.c:109
defs.h
hppabsd_init_abi
void hppabsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: hppa-bsd-tdep.c:120
gdbarch_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
objfiles.h
hppa_in_solib_call_trampoline
int hppa_in_solib_call_trampoline(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: hppa-tdep.c:2924
solib-svr4.h
extract_unsigned_integer
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
Definition: defs.h:577
DWARF2_FRAME_REG_CFA
Definition: dwarf2-frame.h:64
gdbarch_byte_order
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1509
ANOFFSET
#define ANOFFSET(secoff, whichone)
Definition: symtab.h:1276
set_solib_svr4_fetch_link_map_offsets
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3137
regnum
int regnum
Definition: aarch64-tdep.c:77
find_pc_section
struct obj_section * find_pc_section(CORE_ADDR pc)
Definition: objfiles.c:1395
hppa-bsd-tdep.h
gdbarch_tdep::is_elf
int is_elf
Definition: hppa-tdep.h:93
reg
Definition: regdef.h:22
value
Definition: value.c:169
objfile
Definition: objfiles.h:286
obj_section
Definition: objfiles.h:123
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
dwarf2-frame.h
hppabsd_find_global_pointer
static CORE_ADDR hppabsd_find_global_pointer(struct gdbarch *gdbarch, struct value *function)
Definition: hppa-bsd-tdep.c:33
target_read_memory
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: target.c:1370
in_plt_section
static int in_plt_section(CORE_ADDR pc)
Definition: objfiles.h:542
obj_section_addr
#define obj_section_addr(s)
Definition: objfiles.h:140
obj_section::objfile
struct objfile * objfile
Definition: objfiles.h:129
dwarf2_append_unwinders
void dwarf2_append_unwinders(struct gdbarch *gdbarch)
Definition: dwarf2-frame.c:1384
extract_signed_integer
static LONGEST extract_signed_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
Definition: defs.h:570
target.h
value.h
DWARF2_FRAME_REG_RA
Definition: dwarf2-frame.h:62
gdbarch_info
Definition: gdbarch.h:1626
set_gdbarch_long_double_bit
void set_gdbarch_long_double_bit(struct gdbarch *gdbarch, int long_double_bit)
Definition: gdbarch.c:1756
dwarf2_frame_set_init_reg
void dwarf2_frame_set_init_reg(struct gdbarch *gdbarch, void(*init_reg)(struct gdbarch *, int, struct dwarf2_frame_state_reg *, struct frame_info *))
Definition: dwarf2-frame.c:743
value_as_address
CORE_ADDR value_as_address(struct value *val)
Definition: value.c:2762
set_gdbarch_long_double_format
void set_gdbarch_long_double_format(struct gdbarch *gdbarch, const struct floatformat **long_double_format)
Definition: gdbarch.c:1772
objfile::section_offsets
struct section_offsets * section_offsets
Definition: objfiles.h:396
LONGEST
long long LONGEST
Definition: common-types.h:52
objfile::sections_end
struct obj_section * sections_end
Definition: objfiles.h:424
HPPA_SP_REGNUM
Definition: hppa-tdep.h:40