X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fscore-tdep.c;h=9b7008cb3efe9ca5fd9b24867efe52455d40b934;hb=11cf4ffb5e256d268a8f4cea0fc88a0a46bf824c;hp=fb25806d38df5e27314c1b68851f81fef7eaccb3;hpb=22e048c9ddfdfd4e4580998f543f80e70f9770f7;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c index fb25806d38..9b7008cb3e 100644 --- a/gdb/score-tdep.c +++ b/gdb/score-tdep.c @@ -1,7 +1,7 @@ /* Target-dependent code for the S+core architecture, for GDB, the GNU Debugger. - Copyright (C) 2006-2012 Free Software Foundation, Inc. + Copyright (C) 2006-2016 Free Software Foundation, Inc. Contributed by Qinwei (qinwei@sunnorth.com.cn) Contributed by Ching-Peng Lin (cplin@sunplus.com) @@ -22,7 +22,6 @@ along with this program. If not, see . */ #include "defs.h" -#include "gdb_assert.h" #include "inferior.h" #include "symtab.h" #include "objfiles.h" @@ -137,11 +136,11 @@ score_print_insn (bfd_vma memaddr, struct disassemble_info *info) } static inst_t * -score7_fetch_inst (struct gdbarch *gdbarch, CORE_ADDR addr, char *memblock) +score7_fetch_inst (struct gdbarch *gdbarch, CORE_ADDR addr, gdb_byte *memblock) { enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); static inst_t inst = { 0, 0, 0 }; - char buf[SCORE_INSTLEN] = { 0 }; + gdb_byte buf[SCORE_INSTLEN] = { 0 }; int big; int ret; @@ -738,8 +737,10 @@ score3_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) return pc; } +/* Implement the stack_frame_destroyed_p gdbarch method. */ + static int -score7_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc) +score7_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc) { inst_t *inst = score7_fetch_inst (gdbarch, cur_pc, NULL); @@ -762,8 +763,10 @@ score7_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc) return 0; } +/* Implement the stack_frame_destroyed_p gdbarch method. */ + static int -score3_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc) +score3_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc) { CORE_ADDR pc = cur_pc; inst_t *inst @@ -807,11 +810,11 @@ score3_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc) return 0; } -static char * +static gdb_byte * score7_malloc_and_get_memblock (CORE_ADDR addr, CORE_ADDR size) { int ret; - char *memblock = NULL; + gdb_byte *memblock = NULL; if (size < 0) { @@ -822,7 +825,7 @@ score7_malloc_and_get_memblock (CORE_ADDR addr, CORE_ADDR size) else if (size == 0) return NULL; - memblock = (char *) xmalloc (size); + memblock = (gdb_byte *) xmalloc (size); memset (memblock, 0, size); ret = target_read_memory (addr & ~0x3, memblock, size); if (ret) @@ -835,13 +838,13 @@ score7_malloc_and_get_memblock (CORE_ADDR addr, CORE_ADDR size) } static void -score7_free_memblock (char *memblock) +score7_free_memblock (gdb_byte *memblock) { xfree (memblock); } static void -score7_adjust_memblock_ptr (char **memblock, CORE_ADDR prev_pc, +score7_adjust_memblock_ptr (gdb_byte **memblock, CORE_ADDR prev_pc, CORE_ADDR cur_pc) { if (prev_pc == -1) @@ -877,8 +880,8 @@ score7_analyze_prologue (CORE_ADDR startaddr, CORE_ADDR pc, int fp_offset_p = 0; int inst_len = 0; - char *memblock = NULL; - char *memblock_ptr = NULL; + gdb_byte *memblock = NULL; + gdb_byte *memblock_ptr = NULL; CORE_ADDR prev_pc = -1; /* Allocate MEMBLOCK if PC - STARTADDR > 0. */ @@ -1319,7 +1322,7 @@ score_make_prologue_cache (struct frame_info *this_frame, void **this_cache) struct score_frame_cache *cache; if ((*this_cache) != NULL) - return (*this_cache); + return (struct score_frame_cache *) (*this_cache); cache = FRAME_OBSTACK_ZALLOC (struct score_frame_cache); (*this_cache) = cache; @@ -1335,15 +1338,17 @@ score_make_prologue_cache (struct frame_info *this_frame, void **this_cache) return cache; if (target_mach == bfd_mach_score3) - score3_analyze_prologue (start_addr, pc, this_frame, *this_cache); + score3_analyze_prologue (start_addr, pc, this_frame, + (struct score_frame_cache *) *this_cache); else - score7_analyze_prologue (start_addr, pc, this_frame, *this_cache); + score7_analyze_prologue (start_addr, pc, this_frame, + (struct score_frame_cache *) *this_cache); } /* Save SP. */ trad_frame_set_value (cache->saved_regs, SCORE_SP_REGNUM, cache->base); - return (*this_cache); + return (struct score_frame_cache *) (*this_cache); } static void @@ -1398,85 +1403,70 @@ score_prologue_frame_base_sniffer (struct frame_info *this_frame) return &score_prologue_frame_base; } -/* Core file support (dirty hack) - - The core file MUST be generated by GNU/Linux on S+core. */ +/* Core file support. */ + +static const struct regcache_map_entry score7_linux_gregmap[] = + { + /* FIXME: According to the current Linux kernel, r0 is preceded by + 9 rather than 7 words. */ + { 7, REGCACHE_MAP_SKIP, 4 }, + { 32, 0, 4 }, /* r0 ... r31 */ + { 1, 55, 4 }, /* CEL */ + { 1, 54, 4 }, /* CEH */ + { 1, 53, 4 }, /* sr0, i.e. cnt or COUNTER */ + { 1, 52, 4 }, /* sr1, i.e. lcr or LDCR */ + { 1, 51, 4 }, /* sr2, i.e. scr or STCR */ + { 1, 49, 4 }, /* PC (same slot as EPC) */ + { 1, 38, 4 }, /* EMA */ + { 1, 32, 4 }, /* PSR */ + { 1, 34, 4 }, /* ECR */ + { 1, 33, 4 }, /* COND */ + { 0 } + }; + +#define SCORE7_LINUX_EPC_OFFSET (44 * 4) +#define SCORE7_LINUX_SIZEOF_GREGSET (49 * 4) static void score7_linux_supply_gregset(const struct regset *regset, - struct regcache *regcache, - int regnum, const void *gregs_buf, size_t len) + struct regcache *regcache, + int regnum, const void *buf, + size_t size) { - int regno; - elf_gregset_t *gregs; - - gdb_assert (regset != NULL); - gdb_assert ((regcache != NULL) && (gregs_buf != NULL)); - - gregs = (elf_gregset_t *) gregs_buf; - - for (regno = 0; regno < 32; regno++) - if (regnum == -1 || regnum == regno) - regcache_raw_supply (regcache, regno, gregs->regs + regno); + regcache_supply_regset (regset, regcache, regnum, buf, size); + + /* Supply the EPC from the same slot as the PC. Note that the + collect function will store the PC in that slot. */ + if ((regnum == -1 || regnum == SCORE_EPC_REGNUM) + && size >= SCORE7_LINUX_EPC_OFFSET + 4) + regcache_raw_supply (regcache, SCORE_EPC_REGNUM, + (const gdb_byte *) buf + + SCORE7_LINUX_EPC_OFFSET); +} +static const struct regset score7_linux_gregset = { - struct sreg { - int regnum; - void *buf; - } sregs [] = { - { 55, &(gregs->cel) }, /* CEL */ - { 54, &(gregs->ceh) }, /* CEH */ - { 53, &(gregs->sr0) }, /* sr0, i.e. cnt or COUNTER */ - { 52, &(gregs->sr1) }, /* sr1, i.e. lcr or LDCR */ - { 51, &(gregs->sr1) }, /* sr2, i.e. scr or STCR */ - - /* Exception occured at this address, exactly the PC we want */ - { 49, &(gregs->cp0_epc) }, /* PC */ - - { 38, &(gregs->cp0_ema) }, /* EMA */ - { 37, &(gregs->cp0_epc) }, /* EPC */ - { 34, &(gregs->cp0_ecr) }, /* ECR */ - { 33, &(gregs->cp0_condition) }, /* COND */ - { 32, &(gregs->cp0_psr) }, /* PSR */ - }; - - for (regno = 0; regno < sizeof(sregs)/sizeof(sregs[0]); regno++) - if (regnum == -1 || regnum == sregs[regno].regnum) - regcache_raw_supply (regcache, - sregs[regno].regnum, sregs[regno].buf); - } -} + score7_linux_gregmap, + score7_linux_supply_gregset, + regcache_collect_regset + }; -/* Return the appropriate register set from the core section identified - by SECT_NAME and SECT_SIZE. */ +/* Iterate over core file register note sections. */ -static const struct regset * -score7_linux_regset_from_core_section(struct gdbarch *gdbarch, - const char *sect_name, size_t sect_size) +static void +score7_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, + iterate_over_regset_sections_cb *cb, + void *cb_data, + const struct regcache *regcache) { - struct gdbarch_tdep *tdep; - - gdb_assert (gdbarch != NULL); - gdb_assert (sect_name != NULL); - - tdep = gdbarch_tdep (gdbarch); - - if (strcmp(sect_name, ".reg") == 0 && sect_size == sizeof(elf_gregset_t)) - { - if (tdep->gregset == NULL) - tdep->gregset = regset_alloc (gdbarch, - score7_linux_supply_gregset, NULL); - return tdep->gregset; - } - - return NULL; + cb (".reg", SCORE7_LINUX_SIZEOF_GREGSET, &score7_linux_gregset, + NULL, cb_data); } static struct gdbarch * score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) { struct gdbarch *gdbarch; - struct gdbarch_tdep *tdep; target_mach = info.bfd_arch_info->mach; arches = gdbarch_list_lookup_by_info (arches, &info); @@ -1484,8 +1474,7 @@ score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) { return (arches->gdbarch); } - tdep = xcalloc(1, sizeof(struct gdbarch_tdep)); - gdbarch = gdbarch_alloc (&info, tdep); + gdbarch = gdbarch_alloc (&info, NULL); set_gdbarch_short_bit (gdbarch, 16); set_gdbarch_int_bit (gdbarch, 32); @@ -1511,20 +1500,20 @@ score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) case bfd_mach_score7: set_gdbarch_breakpoint_from_pc (gdbarch, score7_breakpoint_from_pc); set_gdbarch_skip_prologue (gdbarch, score7_skip_prologue); - set_gdbarch_in_function_epilogue_p (gdbarch, - score7_in_function_epilogue_p); + set_gdbarch_stack_frame_destroyed_p (gdbarch, + score7_stack_frame_destroyed_p); set_gdbarch_register_name (gdbarch, score7_register_name); set_gdbarch_num_regs (gdbarch, SCORE7_NUM_REGS); /* Core file support. */ - set_gdbarch_regset_from_core_section (gdbarch, - score7_linux_regset_from_core_section); + set_gdbarch_iterate_over_regset_sections + (gdbarch, score7_linux_iterate_over_regset_sections); break; case bfd_mach_score3: set_gdbarch_breakpoint_from_pc (gdbarch, score3_breakpoint_from_pc); set_gdbarch_skip_prologue (gdbarch, score3_skip_prologue); - set_gdbarch_in_function_epilogue_p (gdbarch, - score3_in_function_epilogue_p); + set_gdbarch_stack_frame_destroyed_p (gdbarch, + score3_stack_frame_destroyed_p); set_gdbarch_register_name (gdbarch, score3_register_name); set_gdbarch_num_regs (gdbarch, SCORE3_NUM_REGS); break;