X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=gdb%2Fppc-linux-tdep.c;h=6d3a64c4f0dfb15181b7dc9a78b476c439781824;hb=f6ac5f3d63e03a81c4ff3749aba234961cc9090e;hp=0e43a64b690a9cc0449bca762bb759705d7388c9;hpb=ed0f427344d0befead629d9267aecd01bfb72721;p=thirdparty%2Fbinutils-gdb.git diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 0e43a64b690..6d3a64c4f0d 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -1,6 +1,6 @@ /* Target-dependent code for GDB, the GNU debugger. - Copyright (C) 1986-2017 Free Software Foundation, Inc. + Copyright (C) 1986-2018 Free Software Foundation, Inc. This file is part of GDB. @@ -41,7 +41,7 @@ #include "trad-frame.h" #include "frame-unwind.h" #include "tramp-frame.h" -#include "observer.h" +#include "observable.h" #include "auxv.h" #include "elf/common.h" #include "elf/ppc64.h" @@ -256,8 +256,8 @@ ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function, readbuf, writebuf); } -/* PLT stub in executable. */ -static struct ppc_insn_pattern powerpc32_plt_stub[] = +/* PLT stub in an executable. */ +static const struct ppc_insn_pattern powerpc32_plt_stub[] = { { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */ { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */ @@ -266,16 +266,30 @@ static struct ppc_insn_pattern powerpc32_plt_stub[] = { 0, 0, 0 } }; -/* PLT stub in shared library. */ -static struct ppc_insn_pattern powerpc32_plt_stub_so[] = +/* PLT stubs in a shared library or PIE. + The first variant is used when the PLT entry is within +/-32k of + the GOT pointer (r30). */ +static const struct ppc_insn_pattern powerpc32_plt_stub_so_1[] = { { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */ { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ { 0xffffffff, 0x4e800420, 0 }, /* bctr */ - { 0xffffffff, 0x60000000, 0 }, /* nop */ { 0, 0, 0 } }; -#define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub) + +/* The second variant is used when the PLT entry is more than +/-32k + from the GOT pointer (r30). */ +static const struct ppc_insn_pattern powerpc32_plt_stub_so_2[] = + { + { 0xffff0000, 0x3d7e0000, 0 }, /* addis r11, r30, xxxx */ + { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */ + { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ + { 0xffffffff, 0x4e800420, 0 }, /* bctr */ + { 0, 0, 0 } + }; + +/* The max number of insns we check using ppc_insns_match_pattern. */ +#define POWERPC32_PLT_CHECK_LEN (ARRAY_SIZE (powerpc32_plt_stub) - 1) /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt section. For secure PLT, stub is in .text and we need to check @@ -306,13 +320,13 @@ powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc) When the execution direction is EXEC_REVERSE, scan backward to check whether we are in the middle of a PLT stub. Currently, - we only look-behind at most 4 instructions (the max length of PLT + we only look-behind at most 4 instructions (the max length of a PLT stub sequence. */ static CORE_ADDR ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) { - unsigned int insnbuf[POWERPC32_PLT_STUB_LEN]; + unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN]; struct gdbarch *gdbarch = get_frame_arch (frame); struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); @@ -323,40 +337,47 @@ ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) /* When reverse-debugging, scan backward to check whether we are in the middle of trampoline code. */ if (execution_direction == EXEC_REVERSE) - scan_limit = 4; /* At more 4 instructions. */ + scan_limit = 4; /* At most 4 instructions. */ for (i = 0; i < scan_limit; i++) { if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf)) { - /* Insn pattern is + /* Calculate PLT entry address from lis r11, xxxx - lwz r11, xxxx(r11) - Branch target is in r11. */ - - target = (ppc_insn_d_field (insnbuf[0]) << 16) - | ppc_insn_d_field (insnbuf[1]); - target = read_memory_unsigned_integer (target, 4, byte_order); + lwz r11, xxxx(r11). */ + target = ((ppc_insn_d_field (insnbuf[0]) << 16) + + ppc_insn_d_field (insnbuf[1])); + } + else if (i < ARRAY_SIZE (powerpc32_plt_stub_so_1) - 1 + && ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_1, + insnbuf)) + { + /* Calculate PLT entry address from + lwz r11, xxxx(r30). */ + target = (ppc_insn_d_field (insnbuf[0]) + + get_frame_register_unsigned (frame, + tdep->ppc_gp0_regnum + 30)); } - else if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so, + else if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_2, insnbuf)) { - /* Insn pattern is - lwz r11, xxxx(r30) - Branch target is in r11. */ - - target = get_frame_register_unsigned (frame, - tdep->ppc_gp0_regnum + 30) - + ppc_insn_d_field (insnbuf[0]); - target = read_memory_unsigned_integer (target, 4, byte_order); + /* Calculate PLT entry address from + addis r11, r30, xxxx + lwz r11, xxxx(r11). */ + target = ((ppc_insn_d_field (insnbuf[0]) << 16) + + ppc_insn_d_field (insnbuf[1]) + + get_frame_register_unsigned (frame, + tdep->ppc_gp0_regnum + 30)); } else { - /* Scan backward one more instructions if doesn't match. */ + /* Scan backward one more instruction if it doesn't match. */ pc -= 4; continue; } + target = read_memory_unsigned_integer (target, 4, byte_order); return target; } @@ -1182,7 +1203,7 @@ ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order, /* Look up cached address of thread-local variable. */ if (!ptid_equal (spe_context_cache_ptid, inferior_ptid)) { - struct target_ops *target = ¤t_target; + struct target_ops *target = target_stack; TRY { @@ -1193,9 +1214,9 @@ ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order, Instead, we have cached the lm_addr value, and use that to directly call the target's to_get_thread_local_address. */ spe_context_cache_address - = target->to_get_thread_local_address (target, inferior_ptid, - spe_context_lm_addr, - spe_context_offset); + = target->get_thread_local_address (inferior_ptid, + spe_context_lm_addr, + spe_context_offset); spe_context_cache_ptid = inferior_ptid; } @@ -1241,7 +1262,7 @@ ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order, struct ppu2spu_cache { struct frame_id frame_id; - struct regcache *regcache; + readonly_detached_regcache *regcache; }; static struct gdbarch * @@ -1269,11 +1290,7 @@ ppu2spu_prev_register (struct frame_info *this_frame, buf = (gdb_byte *) alloca (register_size (gdbarch, regnum)); - if (regnum < gdbarch_num_regs (gdbarch)) - regcache_raw_read (cache->regcache, regnum, buf); - else - gdbarch_pseudo_register_read (gdbarch, cache->regcache, regnum, buf); - + cache->regcache->cooked_read (regnum, buf); return frame_unwind_got_bytes (this_frame, regnum, buf); } @@ -1346,16 +1363,16 @@ ppu2spu_sniffer (const struct frame_unwind *self, return 0; xsnprintf (annex, sizeof annex, "%d/regs", data.id); - if (target_read (¤t_target, TARGET_OBJECT_SPU, annex, + if (target_read (target_stack, TARGET_OBJECT_SPU, annex, data.gprs, 0, sizeof data.gprs) == sizeof data.gprs) { struct ppu2spu_cache *cache = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache); - std::unique_ptr regcache - (new struct regcache (data.gdbarch)); - - regcache_save (regcache.get (), ppu2spu_unwind_register, &data); + std::unique_ptr regcache + (new readonly_detached_regcache (data.gdbarch, + ppu2spu_unwind_register, + &data)); cache->frame_id = frame_id_build (base, func); cache->regcache = regcache.release (); @@ -1809,6 +1826,10 @@ ppc_linux_init_abi (struct gdbarch_info info, /* Cell/B.E. cross-architecture unwinder support. */ frame_unwind_prepend_unwinder (gdbarch, &ppu2spu_unwind); + + /* We need to support more than "addr_bit" significant address bits + in order to support SPUADDR_ADDR encoded values. */ + set_gdbarch_significant_addr_bit (gdbarch, 64); } set_gdbarch_displaced_step_location (gdbarch, @@ -1836,9 +1857,9 @@ _initialize_ppc_linux_tdep (void) ppc_linux_init_abi); /* Attach to observers to track __spe_current_active_context. */ - observer_attach_inferior_created (ppc_linux_spe_context_inferior_created); - observer_attach_solib_loaded (ppc_linux_spe_context_solib_loaded); - observer_attach_solib_unloaded (ppc_linux_spe_context_solib_unloaded); + gdb::observers::inferior_created.attach (ppc_linux_spe_context_inferior_created); + gdb::observers::solib_loaded.attach (ppc_linux_spe_context_solib_loaded); + gdb::observers::solib_unloaded.attach (ppc_linux_spe_context_solib_unloaded); /* Initialize the Linux target descriptions. */ initialize_tdesc_powerpc_32l ();