Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 1 | From 4f0e06249d23629e1d56b296e7a040b6968484e9 Mon Sep 17 00:00:00 2001 |
| 2 | From: Mark Hatle <mark.hatle@xilinx.com> |
| 3 | Date: Mon, 20 Jan 2020 12:48:13 -0800 |
| 4 | Subject: [PATCH 44/45] gdb/microblaze-linux-nat.c: Fix target compilation of |
| 5 | gdb |
| 6 | |
| 7 | Add the nat to the configure file |
| 8 | |
| 9 | Remove gdb_assert.h and gdb_string.h. |
| 10 | |
| 11 | Adjust include for opcodes as well. |
| 12 | |
| 13 | Update to match latest style of components, similar to ppc-linux-nat.c |
| 14 | |
| 15 | Update: |
| 16 | get_regcache_arch(regcache) to regcache->arch() |
| 17 | regcache_raw_supply(regcache, ...) to regcache->raw_supply(...) |
| 18 | regcache_raw_collect(regcache, ...) to regcache->raw_collect(...) |
| 19 | |
| 20 | Signed-off-by: Mark Hatle <mark.hatle@xilinx.com> |
| 21 | --- |
| 22 | gdb/configure.nat | 4 + |
| 23 | gdb/microblaze-linux-nat.c | 149 +++++++++++++------------------------ |
| 24 | gdb/microblaze-tdep.c | 3 +- |
| 25 | 3 files changed, 57 insertions(+), 99 deletions(-) |
| 26 | |
| 27 | diff --git a/gdb/configure.nat b/gdb/configure.nat |
| 28 | index 3118263ac6..b8dc7398a5 100644 |
| 29 | --- a/gdb/configure.nat |
| 30 | +++ b/gdb/configure.nat |
| 31 | @@ -260,6 +260,10 @@ case ${gdb_host} in |
| 32 | # Host: Motorola m68k running GNU/Linux. |
| 33 | NATDEPFILES="${NATDEPFILES} m68k-linux-nat.o" |
| 34 | ;; |
| 35 | + microblaze*) |
| 36 | + # Host: Microblaze, running Linux |
| 37 | + NATDEPFILES="${NATDEPFILES} microblaze-linux-nat.o" |
| 38 | + ;; |
| 39 | mips) |
| 40 | # Host: Linux/MIPS |
| 41 | NATDEPFILES="${NATDEPFILES} linux-nat-trad.o \ |
| 42 | diff --git a/gdb/microblaze-linux-nat.c b/gdb/microblaze-linux-nat.c |
| 43 | index e9b8c9c522..e09a86bb3f 100644 |
| 44 | --- a/gdb/microblaze-linux-nat.c |
| 45 | +++ b/gdb/microblaze-linux-nat.c |
| 46 | @@ -36,11 +36,9 @@ |
| 47 | #include "dwarf2-frame.h" |
| 48 | #include "osabi.h" |
| 49 | |
| 50 | -#include "gdb_assert.h" |
| 51 | -#include "gdb_string.h" |
| 52 | #include "target-descriptions.h" |
| 53 | -#include "opcodes/microblaze-opcm.h" |
| 54 | -#include "opcodes/microblaze-dis.h" |
| 55 | +#include "../opcodes/microblaze-opcm.h" |
| 56 | +#include "../opcodes/microblaze-dis.h" |
| 57 | |
| 58 | #include "linux-nat.h" |
| 59 | #include "target-descriptions.h" |
| 60 | @@ -61,34 +59,27 @@ |
| 61 | /* Defines ps_err_e, struct ps_prochandle. */ |
| 62 | #include "gdb_proc_service.h" |
| 63 | |
| 64 | -/* On GNU/Linux, threads are implemented as pseudo-processes, in which |
| 65 | - case we may be tracing more than one process at a time. In that |
| 66 | - case, inferior_ptid will contain the main process ID and the |
| 67 | - individual thread (process) ID. get_thread_id () is used to get |
| 68 | - the thread id if it's available, and the process id otherwise. */ |
| 69 | - |
| 70 | -int |
| 71 | -get_thread_id (ptid_t ptid) |
| 72 | -{ |
| 73 | - int tid = TIDGET (ptid); |
| 74 | - if (0 == tid) |
| 75 | - tid = PIDGET (ptid); |
| 76 | - return tid; |
| 77 | -} |
| 78 | - |
| 79 | -#define GET_THREAD_ID(PTID) get_thread_id (PTID) |
| 80 | - |
| 81 | /* Non-zero if our kernel may support the PTRACE_GETREGS and |
| 82 | PTRACE_SETREGS requests, for reading and writing the |
| 83 | general-purpose registers. Zero if we've tried one of |
| 84 | them and gotten an error. */ |
| 85 | int have_ptrace_getsetregs = 1; |
| 86 | |
| 87 | +struct microblaze_linux_nat_target final : public linux_nat_target |
| 88 | +{ |
| 89 | + /* Add our register access methods. */ |
| 90 | + void fetch_registers (struct regcache *, int) override; |
| 91 | + void store_registers (struct regcache *, int) override; |
| 92 | + |
| 93 | + const struct target_desc *read_description () override; |
| 94 | +}; |
| 95 | + |
| 96 | +static microblaze_linux_nat_target the_microblaze_linux_nat_target; |
| 97 | + |
| 98 | static int |
| 99 | microblaze_register_u_addr (struct gdbarch *gdbarch, int regno) |
| 100 | { |
| 101 | int u_addr = -1; |
| 102 | - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 103 | /* NOTE: cagney/2003-11-25: This is the word size used by the ptrace |
| 104 | interface, and not the wordsize of the program's ABI. */ |
| 105 | int wordsize = sizeof (long); |
| 106 | @@ -105,18 +96,16 @@ microblaze_register_u_addr (struct gdbarch *gdbarch, int regno) |
| 107 | static void |
| 108 | fetch_register (struct regcache *regcache, int tid, int regno) |
| 109 | { |
| 110 | - struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 111 | - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 112 | + struct gdbarch *gdbarch = regcache->arch(); |
| 113 | /* This isn't really an address. But ptrace thinks of it as one. */ |
| 114 | CORE_ADDR regaddr = microblaze_register_u_addr (gdbarch, regno); |
| 115 | int bytes_transferred; |
| 116 | - unsigned int offset; /* Offset of registers within the u area. */ |
| 117 | - char buf[MAX_REGISTER_SIZE]; |
| 118 | + char buf[sizeof(long)]; |
| 119 | |
| 120 | if (regaddr == -1) |
| 121 | { |
| 122 | memset (buf, '\0', register_size (gdbarch, regno)); /* Supply zeroes */ |
| 123 | - regcache_raw_supply (regcache, regno, buf); |
| 124 | + regcache->raw_supply (regno, buf); |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | @@ -149,14 +138,14 @@ fetch_register (struct regcache *regcache, int tid, int regno) |
| 129 | { |
| 130 | /* Little-endian values are always found at the left end of the |
| 131 | bytes transferred. */ |
| 132 | - regcache_raw_supply (regcache, regno, buf); |
| 133 | + regcache->raw_supply (regno, buf); |
| 134 | } |
| 135 | else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
| 136 | { |
| 137 | /* Big-endian values are found at the right end of the bytes |
| 138 | transferred. */ |
| 139 | size_t padding = (bytes_transferred - register_size (gdbarch, regno)); |
| 140 | - regcache_raw_supply (regcache, regno, buf + padding); |
| 141 | + regcache->raw_supply (regno, buf + padding); |
| 142 | } |
| 143 | else |
| 144 | internal_error (__FILE__, __LINE__, |
| 145 | @@ -175,8 +164,6 @@ fetch_register (struct regcache *regcache, int tid, int regno) |
| 146 | static int |
| 147 | fetch_all_gp_regs (struct regcache *regcache, int tid) |
| 148 | { |
| 149 | - struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 150 | - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 151 | gdb_gregset_t gregset; |
| 152 | |
| 153 | if (ptrace (PTRACE_GETREGS, tid, 0, (void *) &gregset) < 0) |
| 154 | @@ -204,8 +191,6 @@ fetch_all_gp_regs (struct regcache *regcache, int tid) |
| 155 | static void |
| 156 | fetch_gp_regs (struct regcache *regcache, int tid) |
| 157 | { |
| 158 | - struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 159 | - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 160 | int i; |
| 161 | |
| 162 | if (have_ptrace_getsetregs) |
| 163 | @@ -219,17 +204,29 @@ fetch_gp_regs (struct regcache *regcache, int tid) |
| 164 | fetch_register (regcache, tid, i); |
| 165 | } |
| 166 | |
| 167 | +/* Fetch registers from the child process. Fetch all registers if |
| 168 | + regno == -1, otherwise fetch all general registers or all floating |
| 169 | + point registers depending upon the value of regno. */ |
| 170 | +void |
| 171 | +microblaze_linux_nat_target::fetch_registers (struct regcache *regcache, int regno) |
| 172 | +{ |
| 173 | + pid_t tid = get_ptrace_pid (regcache->ptid ()); |
| 174 | + |
| 175 | + if (regno == -1) |
| 176 | + fetch_gp_regs (regcache, tid); |
| 177 | + else |
| 178 | + fetch_register (regcache, tid, regno); |
| 179 | +} |
| 180 | |
| 181 | static void |
| 182 | store_register (const struct regcache *regcache, int tid, int regno) |
| 183 | { |
| 184 | - struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 185 | - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 186 | + struct gdbarch *gdbarch = regcache->arch(); |
| 187 | /* This isn't really an address. But ptrace thinks of it as one. */ |
| 188 | CORE_ADDR regaddr = microblaze_register_u_addr (gdbarch, regno); |
| 189 | int i; |
| 190 | size_t bytes_to_transfer; |
| 191 | - char buf[MAX_REGISTER_SIZE]; |
| 192 | + char buf[sizeof(long)]; |
| 193 | |
| 194 | if (regaddr == -1) |
| 195 | return; |
| 196 | @@ -242,13 +239,13 @@ store_register (const struct regcache *regcache, int tid, int regno) |
| 197 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE) |
| 198 | { |
| 199 | /* Little-endian values always sit at the left end of the buffer. */ |
| 200 | - regcache_raw_collect (regcache, regno, buf); |
| 201 | + regcache->raw_collect (regno, buf); |
| 202 | } |
| 203 | else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
| 204 | { |
| 205 | /* Big-endian values sit at the right end of the buffer. */ |
| 206 | size_t padding = (bytes_to_transfer - register_size (gdbarch, regno)); |
| 207 | - regcache_raw_collect (regcache, regno, buf + padding); |
| 208 | + regcache->raw_collect (regno, buf + padding); |
| 209 | } |
| 210 | |
| 211 | for (i = 0; i < bytes_to_transfer; i += sizeof (long)) |
| 212 | @@ -281,8 +278,6 @@ store_register (const struct regcache *regcache, int tid, int regno) |
| 213 | static int |
| 214 | store_all_gp_regs (const struct regcache *regcache, int tid, int regno) |
| 215 | { |
| 216 | - struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 217 | - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 218 | gdb_gregset_t gregset; |
| 219 | |
| 220 | if (ptrace (PTRACE_GETREGS, tid, 0, (void *) &gregset) < 0) |
| 221 | @@ -319,8 +314,6 @@ store_all_gp_regs (const struct regcache *regcache, int tid, int regno) |
| 222 | static void |
| 223 | store_gp_regs (const struct regcache *regcache, int tid, int regno) |
| 224 | { |
| 225 | - struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 226 | - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 227 | int i; |
| 228 | |
| 229 | if (have_ptrace_getsetregs) |
| 230 | @@ -335,33 +328,10 @@ store_gp_regs (const struct regcache *regcache, int tid, int regno) |
| 231 | } |
| 232 | |
| 233 | |
| 234 | -/* Fetch registers from the child process. Fetch all registers if |
| 235 | - regno == -1, otherwise fetch all general registers or all floating |
| 236 | - point registers depending upon the value of regno. */ |
| 237 | - |
| 238 | -static void |
| 239 | -microblaze_linux_fetch_inferior_registers (struct target_ops *ops, |
| 240 | - struct regcache *regcache, int regno) |
| 241 | -{ |
| 242 | - /* Get the thread id for the ptrace call. */ |
| 243 | - int tid = GET_THREAD_ID (inferior_ptid); |
| 244 | - |
| 245 | - if (regno == -1) |
| 246 | - fetch_gp_regs (regcache, tid); |
| 247 | - else |
| 248 | - fetch_register (regcache, tid, regno); |
| 249 | -} |
| 250 | - |
| 251 | -/* Store registers back into the inferior. Store all registers if |
| 252 | - regno == -1, otherwise store all general registers or all floating |
| 253 | - point registers depending upon the value of regno. */ |
| 254 | - |
| 255 | -static void |
| 256 | -microblaze_linux_store_inferior_registers (struct target_ops *ops, |
| 257 | - struct regcache *regcache, int regno) |
| 258 | +void |
| 259 | +microblaze_linux_nat_target::store_registers (struct regcache *regcache, int regno) |
| 260 | { |
| 261 | - /* Get the thread id for the ptrace call. */ |
| 262 | - int tid = GET_THREAD_ID (inferior_ptid); |
| 263 | + pid_t tid = get_ptrace_pid (regcache->ptid ()); |
| 264 | |
| 265 | if (regno >= 0) |
| 266 | store_register (regcache, tid, regno); |
| 267 | @@ -373,59 +343,44 @@ microblaze_linux_store_inferior_registers (struct target_ops *ops, |
| 268 | thread debugging. */ |
| 269 | |
| 270 | void |
| 271 | -fill_gregset (const struct regcache *regcache, |
| 272 | - gdb_gregset_t *gregsetp, int regno) |
| 273 | +supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp) |
| 274 | { |
| 275 | - microblaze_collect_gregset (NULL, regcache, regno, gregsetp); |
| 276 | + microblaze_supply_gregset (NULL, regcache, -1, gregsetp); |
| 277 | } |
| 278 | |
| 279 | void |
| 280 | -supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp) |
| 281 | +fill_gregset (const struct regcache *regcache, |
| 282 | + gdb_gregset_t *gregsetp, int regno) |
| 283 | { |
| 284 | - microblaze_supply_gregset (NULL, regcache, -1, gregsetp); |
| 285 | + microblaze_collect_gregset (NULL, regcache, regno, gregsetp); |
| 286 | } |
| 287 | |
| 288 | void |
| 289 | -fill_fpregset (const struct regcache *regcache, |
| 290 | - gdb_fpregset_t *fpregsetp, int regno) |
| 291 | +supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp) |
| 292 | { |
| 293 | /* FIXME. */ |
| 294 | + return; |
| 295 | } |
| 296 | |
| 297 | void |
| 298 | -supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp) |
| 299 | +fill_fpregset (const struct regcache *regcache, |
| 300 | + gdb_fpregset_t *fpregsetp, int regno) |
| 301 | { |
| 302 | /* FIXME. */ |
| 303 | + return; |
| 304 | } |
| 305 | |
| 306 | -static const struct target_desc * |
| 307 | -microblaze_linux_read_description (struct target_ops *ops) |
| 308 | +const struct target_desc * |
| 309 | +microblaze_linux_nat_target::read_description () |
| 310 | { |
| 311 | - CORE_ADDR microblaze_hwcap = 0; |
| 312 | - |
| 313 | - if (target_auxv_search (ops, AT_HWCAP, µblaze_hwcap) != 1) |
| 314 | - return NULL; |
| 315 | - |
| 316 | return NULL; |
| 317 | } |
| 318 | |
| 319 | - |
| 320 | -void _initialize_microblaze_linux_nat (void); |
| 321 | - |
| 322 | void |
| 323 | _initialize_microblaze_linux_nat (void) |
| 324 | { |
| 325 | - struct target_ops *t; |
| 326 | - |
| 327 | - /* Fill in the generic GNU/Linux methods. */ |
| 328 | - t = linux_target (); |
| 329 | - |
| 330 | - /* Add our register access methods. */ |
| 331 | - t->to_fetch_registers = microblaze_linux_fetch_inferior_registers; |
| 332 | - t->to_store_registers = microblaze_linux_store_inferior_registers; |
| 333 | - |
| 334 | - t->to_read_description = microblaze_linux_read_description; |
| 335 | + linux_target = &the_microblaze_linux_nat_target; |
| 336 | |
| 337 | /* Register the target. */ |
| 338 | - linux_nat_add_target (t); |
| 339 | + add_inf_child_target (linux_target); |
| 340 | } |
| 341 | diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c |
| 342 | index 7a0c2527f4..23deb24d26 100644 |
| 343 | --- a/gdb/microblaze-tdep.c |
| 344 | +++ b/gdb/microblaze-tdep.c |
| 345 | @@ -657,7 +657,7 @@ static std::vector<CORE_ADDR> |
| 346 | microblaze_software_single_step (struct regcache *regcache) |
| 347 | { |
| 348 | // struct gdbarch *arch = get_frame_arch(frame); |
| 349 | - struct gdbarch *arch = get_regcache_arch (regcache); |
| 350 | + struct gdbarch *arch = regcache->arch(); |
| 351 | struct address_space *aspace = get_regcache_aspace (regcache); |
| 352 | // struct address_space *aspace = get_frame_address_space (frame); |
| 353 | struct gdbarch_tdep *tdep = gdbarch_tdep (arch); |
| 354 | @@ -876,7 +876,6 @@ microblaze_regset_from_core_section (struct gdbarch *gdbarch, |
| 355 | static void |
| 356 | make_regs (struct gdbarch *arch) |
| 357 | { |
| 358 | - struct gdbarch_tdep *tdep = gdbarch_tdep (arch); |
| 359 | int mach = gdbarch_bfd_arch_info (arch)->mach; |
| 360 | |
| 361 | if (mach == bfd_mach_microblaze64) |
| 362 | -- |
| 363 | 2.17.1 |
| 364 | |