Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 1 | From 5c3a08f407e1cbee5b0a4ca6092165b97acddda5 Mon Sep 17 00:00:00 2001 |
| 2 | From: "Edgar E. Iglesias" <edgar@axis.com> |
| 3 | Date: Fri, 24 Feb 2012 11:52:30 +0100 |
| 4 | Subject: [PATCH 05/16] [Patch, microblaze]: Add mb singlestepping. |
| 5 | |
| 6 | Fix prologue analysis for little-endian. |
| 7 | Always provide a frame base. |
| 8 | |
| 9 | Signed-off-by: Edgar E. Iglesias <edgar@axis.com> |
| 10 | Upstream-Status: Pending |
| 11 | --- |
| 12 | gdb/microblaze-tdep.c | 123 ++++++++++++++++++++++++++++++++++++++++++++------ |
| 13 | 1 file changed, 108 insertions(+), 15 deletions(-) |
| 14 | |
| 15 | diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c |
| 16 | index 76e87b3..50b68d2 100644 |
| 17 | --- a/gdb/microblaze-tdep.c |
| 18 | +++ b/gdb/microblaze-tdep.c |
| 19 | @@ -243,9 +243,7 @@ microblaze_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 20 | int save_hidden_pointer_found = 0; |
| 21 | int non_stack_instruction_found = 0; |
| 22 | int n_insns; |
| 23 | - unsigned long *insn_block; |
| 24 | - gdb_byte *buf_block; |
| 25 | - int ti, tj; |
| 26 | + unsigned int *insn_block; |
| 27 | |
| 28 | /* Find the start of this function. */ |
| 29 | find_pc_partial_function (pc, &name, &func_addr, &func_end); |
| 30 | @@ -287,23 +285,16 @@ microblaze_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 31 | |
| 32 | /* Do a block read to minimize the transaction with the Debug Agent */ |
| 33 | n_insns = (stop == func_addr) ? 1 : ((stop - func_addr) / INST_WORD_SIZE); |
| 34 | - insn_block = (unsigned long *)calloc(n_insns, sizeof(unsigned long)); |
| 35 | - buf_block = (gdb_byte *)calloc(n_insns * INST_WORD_SIZE, sizeof(gdb_byte)); |
| 36 | + insn_block = calloc(n_insns, sizeof(unsigned long)); |
| 37 | |
| 38 | - target_read_memory (func_addr, buf_block, n_insns * INST_WORD_SIZE ); |
| 39 | - |
| 40 | - for(ti = 0; ti < n_insns; ti++){ |
| 41 | - insn_block[ti] = 0; |
| 42 | - for( tj = ti * INST_WORD_SIZE; tj < (ti + 1) * INST_WORD_SIZE; tj++ ) |
| 43 | - insn_block[ti] = (insn_block[ti] << 8) | buf_block[tj]; |
| 44 | - } |
| 45 | + target_read_memory (func_addr, (void*) insn_block, n_insns * INST_WORD_SIZE ); |
| 46 | |
| 47 | for (addr = func_addr; addr < stop; addr += INST_WORD_SIZE) |
| 48 | { |
| 49 | //insn = microblaze_fetch_instruction (addr); |
| 50 | insn = insn_block[(addr - func_addr) / INST_WORD_SIZE]; |
| 51 | op = microblaze_decode_insn (insn, &rd, &ra, &rb, &imm); |
| 52 | - microblaze_debug ("%s %08lx\n", paddress (gdbarch, pc), insn); |
| 53 | + microblaze_debug ("%s %08lx op=%x r%d r%d imm=%d\n", paddress (gdbarch, addr), insn, op, rd, ra, imm); |
| 54 | |
| 55 | /* This code is very sensitive to what functions are present in the |
| 56 | prologue. It assumes that the (addi, addik, swi, sw) can be the |
| 57 | @@ -428,7 +419,6 @@ microblaze_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 58 | if (save_hidden_pointer_found) |
| 59 | prologue_end_addr -= INST_WORD_SIZE; |
| 60 | free(insn_block); |
| 61 | - free(buf_block); |
| 62 | return prologue_end_addr; |
| 63 | } |
| 64 | |
| 65 | @@ -502,6 +492,7 @@ microblaze_frame_cache (struct frame_info *next_frame, void **this_cache) |
| 66 | |
| 67 | func = get_frame_func (next_frame); |
| 68 | |
| 69 | + cache->base = get_frame_register_unsigned (next_frame, gdbarch_sp_regnum (gdbarch)); |
| 70 | cache->pc = get_frame_address_in_block (next_frame); |
| 71 | |
| 72 | return cache; |
| 73 | @@ -518,7 +509,7 @@ microblaze_frame_this_id (struct frame_info *next_frame, void **this_cache, |
| 74 | if (cache->base == 0) |
| 75 | return; |
| 76 | |
| 77 | - (*this_id) = frame_id_build (cache->base, cache->pc); |
| 78 | + (*this_id) = frame_id_build (cache->base, get_frame_pc (next_frame)); |
| 79 | } |
| 80 | |
| 81 | static struct value * |
| 82 | @@ -661,6 +652,107 @@ microblaze_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type) |
| 83 | return (TYPE_LENGTH (type) == 16); |
| 84 | } |
| 85 | |
| 86 | +int |
| 87 | +microblaze_software_single_step (struct frame_info *frame) |
| 88 | +{ |
| 89 | + struct gdbarch *arch = get_frame_arch (frame); |
| 90 | + struct address_space *aspace = get_frame_address_space (frame); |
| 91 | + struct gdbarch_tdep *tdep = gdbarch_tdep (arch); |
| 92 | + static char le_breakp[] = MICROBLAZE_BREAKPOINT_LE; |
| 93 | + static char be_breakp[] = MICROBLAZE_BREAKPOINT; |
| 94 | + enum bfd_endian byte_order = gdbarch_byte_order (arch); |
| 95 | + char *breakp = byte_order == BFD_ENDIAN_BIG ? be_breakp : le_breakp; |
| 96 | + int ret = 0; |
| 97 | + |
| 98 | + /* Save the address and the values of the next_pc and the target */ |
| 99 | + static struct sstep_breaks |
| 100 | + { |
| 101 | + CORE_ADDR address; |
| 102 | + bfd_boolean valid; |
| 103 | + /* Shadow contents. */ |
| 104 | + char data[INST_WORD_SIZE]; |
| 105 | + } stepbreaks[2]; |
| 106 | + int ii; |
| 107 | + |
| 108 | + if (1) |
| 109 | + { |
| 110 | + CORE_ADDR pc; |
| 111 | + long insn; |
| 112 | + enum microblaze_instr minstr; |
| 113 | + bfd_boolean isunsignednum; |
| 114 | + enum microblaze_instr_type insn_type; |
| 115 | + short delay_slots; |
| 116 | + int imm; |
| 117 | + bfd_boolean immfound = FALSE; |
| 118 | + |
| 119 | + /* Set a breakpoint at the next instruction */ |
| 120 | + /* If the current instruction is an imm, set it at the inst after */ |
| 121 | + /* If the instruction has a delay slot, skip the delay slot */ |
| 122 | + pc = get_frame_pc (frame); |
| 123 | + insn = microblaze_fetch_instruction (pc); |
| 124 | + minstr = get_insn_microblaze (insn, &isunsignednum, &insn_type, &delay_slots); |
| 125 | + if (insn_type == immediate_inst) |
| 126 | + { |
| 127 | + int rd, ra, rb; |
| 128 | + immfound = TRUE; |
| 129 | + minstr = microblaze_decode_insn (insn, &rd, &ra, &rb, &imm); |
| 130 | + pc = pc + INST_WORD_SIZE; |
| 131 | + insn = microblaze_fetch_instruction (pc); |
| 132 | + minstr = get_insn_microblaze (insn, &isunsignednum, &insn_type, &delay_slots); |
| 133 | + } |
| 134 | + stepbreaks[0].address = pc + (delay_slots * INST_WORD_SIZE) + INST_WORD_SIZE; |
| 135 | + if (insn_type != return_inst) { |
| 136 | + stepbreaks[0].valid = TRUE; |
| 137 | + } else { |
| 138 | + stepbreaks[0].valid = FALSE; |
| 139 | + } |
| 140 | + |
| 141 | + microblaze_debug ("single-step insn_type=%x insn=%x\n", insn_type, insn); |
| 142 | + /* Now check for branch or return instructions */ |
| 143 | + if (insn_type == branch_inst || insn_type == return_inst) { |
| 144 | + int limm; |
| 145 | + int lrd, lra, lrb; |
| 146 | + int ra, rb; |
| 147 | + bfd_boolean targetvalid; |
| 148 | + bfd_boolean unconditionalbranch; |
| 149 | + microblaze_decode_insn(insn, &lrd, &lra, &lrb, &limm); |
| 150 | + if (lra >= 0 && lra < MICROBLAZE_NUM_REGS) |
| 151 | + ra = get_frame_register_unsigned (frame, lra); |
| 152 | + else |
| 153 | + ra = 0; |
| 154 | + if (lrb >= 0 && lrb < MICROBLAZE_NUM_REGS) |
| 155 | + rb = get_frame_register_unsigned (frame, lrb); |
| 156 | + else |
| 157 | + rb = 0; |
| 158 | + stepbreaks[1].address = microblaze_get_target_address (insn, immfound, imm, pc, ra, rb, &targetvalid, &unconditionalbranch); |
| 159 | + microblaze_debug ("single-step uncondbr=%d targetvalid=%d target=%x\n", unconditionalbranch, targetvalid, stepbreaks[1].address); |
| 160 | + if (unconditionalbranch) |
| 161 | + stepbreaks[0].valid = FALSE; /* This is a unconditional branch: will not come to the next address */ |
| 162 | + if (targetvalid && (stepbreaks[0].valid == FALSE || |
| 163 | + (stepbreaks[0].address != stepbreaks[1].address)) |
| 164 | + && (stepbreaks[1].address != pc)) { |
| 165 | + stepbreaks[1].valid = TRUE; |
| 166 | + } else { |
| 167 | + stepbreaks[1].valid = FALSE; |
| 168 | + } |
| 169 | + } else { |
| 170 | + stepbreaks[1].valid = FALSE; |
| 171 | + } |
| 172 | + |
| 173 | + /* Insert the breakpoints */ |
| 174 | + for (ii = 0; ii < 2; ++ii) |
| 175 | + { |
| 176 | + |
| 177 | + /* ignore invalid breakpoint. */ |
| 178 | + if (stepbreaks[ii].valid) { |
| 179 | + insert_single_step_breakpoint (arch, aspace, stepbreaks[ii].address); |
| 180 | + ret = 1; |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + return ret; |
| 185 | +} |
| 186 | + |
| 187 | static void |
| 188 | microblaze_write_pc (struct regcache *regcache, CORE_ADDR pc) |
| 189 | { |
| 190 | @@ -809,6 +901,7 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
| 191 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
| 192 | |
| 193 | set_gdbarch_breakpoint_from_pc (gdbarch, microblaze_breakpoint_from_pc); |
| 194 | + set_gdbarch_software_single_step (gdbarch, microblaze_software_single_step); |
| 195 | |
| 196 | set_gdbarch_frame_args_skip (gdbarch, 8); |
| 197 | |
| 198 | -- |
| 199 | 1.9.0 |
| 200 | |