Skip to content

Commit 63ab25e

Browse files
vapiertorvalds
authored andcommitted
kgdbts: unify/generalize gdb breakpoint adjustment
The Blackfin arch, like the x86 arch, needs to adjust the PC manually after a breakpoint is hit as normally this is handled by the remote gdb. However, rather than starting another arch ifdef mess, create a common GDB_ADJUSTS_BREAK_OFFSET define for any arch to opt-in via their kgdb.h. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Jason Wessel <jason.wessel@windriver.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Acked-by: Paul Mundt <lethal@linux-sh.org> Acked-by: Dongdong Deng <dongdong.deng@windriver.com> Cc: Sergei Shtylyov <sshtylyov@mvista.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3cea45c commit 63ab25e

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

arch/blackfin/include/asm/kgdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static inline void arch_kgdb_breakpoint(void)
108108
#else
109109
# define CACHE_FLUSH_IS_SAFE 1
110110
#endif
111+
#define GDB_ADJUSTS_BREAK_OFFSET
111112
#define HW_INST_WATCHPOINT_NUM 6
112113
#define HW_WATCHPOINT_NUM 8
113114
#define TYPE_INST_WATCHPOINT 0

arch/sh/include/asm/kgdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ static inline void arch_kgdb_breakpoint(void)
3434

3535
#define CACHE_FLUSH_IS_SAFE 1
3636
#define BREAK_INSTR_SIZE 2
37+
#define GDB_ADJUSTS_BREAK_OFFSET
3738

3839
#endif /* __ASM_SH_KGDB_H */

arch/x86/include/asm/kgdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static inline void arch_kgdb_breakpoint(void)
7777
}
7878
#define BREAK_INSTR_SIZE 1
7979
#define CACHE_FLUSH_IS_SAFE 1
80+
#define GDB_ADJUSTS_BREAK_OFFSET
8081

8182
extern int kgdb_ll_trap(int cmd, const char *str,
8283
struct pt_regs *regs, long err, int trap, int sig);

drivers/misc/kgdbts.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -285,33 +285,26 @@ static void hw_break_val_write(void)
285285
static int check_and_rewind_pc(char *put_str, char *arg)
286286
{
287287
unsigned long addr = lookup_addr(arg);
288+
unsigned long ip;
288289
int offset = 0;
289290

290291
kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs,
291292
NUMREGBYTES);
292293
gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
293-
v2printk("Stopped at IP: %lx\n", instruction_pointer(&kgdbts_regs));
294-
#ifdef CONFIG_X86
295-
/* On x86 a breakpoint stop requires it to be decremented */
296-
if (addr + 1 == kgdbts_regs.ip)
297-
offset = -1;
298-
#elif defined(CONFIG_SUPERH)
299-
/* On SUPERH a breakpoint stop requires it to be decremented */
300-
if (addr + 2 == kgdbts_regs.pc)
301-
offset = -2;
294+
ip = instruction_pointer(&kgdbts_regs);
295+
v2printk("Stopped at IP: %lx\n", ip);
296+
#ifdef GDB_ADJUSTS_BREAK_OFFSET
297+
/* On some arches, a breakpoint stop requires it to be decremented */
298+
if (addr + BREAK_INSTR_SIZE == ip)
299+
offset = -BREAK_INSTR_SIZE;
302300
#endif
303-
if (strcmp(arg, "silent") &&
304-
instruction_pointer(&kgdbts_regs) + offset != addr) {
301+
if (strcmp(arg, "silent") && ip + offset != addr) {
305302
eprintk("kgdbts: BP mismatch %lx expected %lx\n",
306-
instruction_pointer(&kgdbts_regs) + offset, addr);
303+
ip + offset, addr);
307304
return 1;
308305
}
309-
#ifdef CONFIG_X86
310-
/* On x86 adjust the instruction pointer if needed */
311-
kgdbts_regs.ip += offset;
312-
#elif defined(CONFIG_SUPERH)
313-
kgdbts_regs.pc += offset;
314-
#endif
306+
/* Readjust the instruction pointer if needed */
307+
instruction_pointer_set(&kgdbts_regs, ip + offset);
315308
return 0;
316309
}
317310

0 commit comments

Comments
 (0)