[gdb/testsuite] Fix gdb.dwarf2/locexpr-data-member-location.exp with nopie
[binutils-gdb.git] / gdb / arm-fbsd-nat.c
1 /* Native-dependent code for FreeBSD/arm.
2
3 Copyright (C) 2017-2022 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 "inferior.h"
22 #include "target.h"
23
24 #include "elf/common.h"
25
26 #include <sys/types.h>
27 #include <sys/ptrace.h>
28 #include <machine/reg.h>
29
30 #include "fbsd-nat.h"
31 #include "arm-tdep.h"
32 #include "arm-fbsd-tdep.h"
33 #include "inf-ptrace.h"
34
35 struct arm_fbsd_nat_target : public fbsd_nat_target
36 {
37 void fetch_registers (struct regcache *, int) override;
38 void store_registers (struct regcache *, int) override;
39 const struct target_desc *read_description () override;
40 };
41
42 static arm_fbsd_nat_target the_arm_fbsd_nat_target;
43
44 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
45 for all registers. */
46
47 void
48 arm_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
49 {
50 fetch_register_set<struct reg> (regcache, regnum, PT_GETREGS,
51 &arm_fbsd_gregset);
52 #ifdef PT_GETVFPREGS
53 fetch_register_set<struct vfpreg> (regcache, regnum, PT_GETVFPREGS,
54 &arm_fbsd_vfpregset);
55 #endif
56 #ifdef PT_GETREGSET
57 gdbarch *gdbarch = regcache->arch ();
58 arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
59
60 if (tdep->tls_regnum > 0)
61 {
62 const struct regcache_map_entry arm_fbsd_tlsregmap[] =
63 {
64 { 1, tdep->tls_regnum, 4 },
65 { 0 }
66 };
67
68 const struct regset arm_fbsd_tlsregset =
69 {
70 arm_fbsd_tlsregmap,
71 regcache_supply_regset, regcache_collect_regset
72 };
73
74 fetch_regset<uint32_t> (regcache, regnum, NT_ARM_TLS, &arm_fbsd_tlsregset);
75 }
76 #endif
77 }
78
79 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
80 this for all registers. */
81
82 void
83 arm_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
84 {
85 store_register_set<struct reg> (regcache, regnum, PT_GETREGS, PT_SETREGS,
86 &arm_fbsd_gregset);
87 #ifdef PT_GETVFPREGS
88 store_register_set<struct vfpreg> (regcache, regnum, PT_GETVFPREGS,
89 PT_SETVFPREGS, &arm_fbsd_vfpregset);
90 #endif
91 #ifdef PT_GETREGSET
92 gdbarch *gdbarch = regcache->arch ();
93 arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
94
95 if (tdep->tls_regnum > 0)
96 {
97 const struct regcache_map_entry arm_fbsd_tlsregmap[] =
98 {
99 { 1, tdep->tls_regnum, 4 },
100 { 0 }
101 };
102
103 const struct regset arm_fbsd_tlsregset =
104 {
105 arm_fbsd_tlsregmap,
106 regcache_supply_regset, regcache_collect_regset
107 };
108
109 store_regset<uint32_t> (regcache, regnum, NT_ARM_TLS, &arm_fbsd_tlsregset);
110 }
111 #endif
112 }
113
114 /* Implement the to_read_description method. */
115
116 const struct target_desc *
117 arm_fbsd_nat_target::read_description ()
118 {
119 const struct target_desc *desc;
120 bool tls = false;
121
122 #ifdef PT_GETREGSET
123 tls = have_regset (inferior_ptid, NT_ARM_TLS) != 0;
124 #endif
125 desc = arm_fbsd_read_description_auxv (this, tls);
126 if (desc == NULL)
127 desc = this->beneath ()->read_description ();
128 return desc;
129 }
130
131 void _initialize_arm_fbsd_nat ();
132 void
133 _initialize_arm_fbsd_nat ()
134 {
135 add_inf_child_target (&the_arm_fbsd_nat_target);
136 }