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