Commit 44679a4f authored by Vijaya Kumar K's avatar Vijaya Kumar K Committed by Catalin Marinas

arm64: KGDB: Add step debugging support

Add KGDB software step debugging support for EL1 debug
in AArch64 mode.

KGDB registers step debug handler with debug monitor.
On receiving 'step' command from GDB tool, target enables
software step debugging and step address is updated in ELR.

Software Step debugging is disabled when 'continue' command
is received
Signed-off-by: default avatarVijaya Kumar K <Vijaya.Kumar@caviumnetworks.com>
Reviewed-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent bcf5763b
...@@ -137,13 +137,26 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc) ...@@ -137,13 +137,26 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
static int compiled_break; static int compiled_break;
static void kgdb_arch_update_addr(struct pt_regs *regs,
char *remcom_in_buffer)
{
unsigned long addr;
char *ptr;
ptr = &remcom_in_buffer[1];
if (kgdb_hex2long(&ptr, &addr))
kgdb_arch_set_pc(regs, addr);
else if (compiled_break == 1)
kgdb_arch_set_pc(regs, regs->pc + 4);
compiled_break = 0;
}
int kgdb_arch_handle_exception(int exception_vector, int signo, int kgdb_arch_handle_exception(int exception_vector, int signo,
int err_code, char *remcom_in_buffer, int err_code, char *remcom_in_buffer,
char *remcom_out_buffer, char *remcom_out_buffer,
struct pt_regs *linux_regs) struct pt_regs *linux_regs)
{ {
unsigned long addr;
char *ptr;
int err; int err;
switch (remcom_in_buffer[0]) { switch (remcom_in_buffer[0]) {
...@@ -162,13 +175,36 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, ...@@ -162,13 +175,36 @@ int kgdb_arch_handle_exception(int exception_vector, int signo,
* to the next instruction else we will just breakpoint * to the next instruction else we will just breakpoint
* over and over again. * over and over again.
*/ */
ptr = &remcom_in_buffer[1]; kgdb_arch_update_addr(linux_regs, remcom_in_buffer);
if (kgdb_hex2long(&ptr, &addr)) atomic_set(&kgdb_cpu_doing_single_step, -1);
kgdb_arch_set_pc(linux_regs, addr); kgdb_single_step = 0;
else if (compiled_break == 1)
kgdb_arch_set_pc(linux_regs, linux_regs->pc + 4); /*
* Received continue command, disable single step
*/
if (kernel_active_single_step())
kernel_disable_single_step();
err = 0;
break;
case 's':
/*
* Update step address value with address passed
* with step packet.
* On debug exception return PC is copied to ELR
* So just update PC.
* If no step address is passed, resume from the address
* pointed by PC. Do not update PC
*/
kgdb_arch_update_addr(linux_regs, remcom_in_buffer);
atomic_set(&kgdb_cpu_doing_single_step, raw_smp_processor_id());
kgdb_single_step = 1;
compiled_break = 0; /*
* Enable single step handling
*/
if (!kernel_active_single_step())
kernel_enable_single_step(linux_regs);
err = 0; err = 0;
break; break;
default: default:
...@@ -191,6 +227,12 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr) ...@@ -191,6 +227,12 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr)
return 0; return 0;
} }
static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr)
{
kgdb_handle_exception(1, SIGTRAP, 0, regs);
return 0;
}
static struct break_hook kgdb_brkpt_hook = { static struct break_hook kgdb_brkpt_hook = {
.esr_mask = 0xffffffff, .esr_mask = 0xffffffff,
.esr_val = DBG_ESR_VAL_BRK(KGDB_DYN_DGB_BRK_IMM), .esr_val = DBG_ESR_VAL_BRK(KGDB_DYN_DGB_BRK_IMM),
...@@ -203,6 +245,10 @@ static struct break_hook kgdb_compiled_brkpt_hook = { ...@@ -203,6 +245,10 @@ static struct break_hook kgdb_compiled_brkpt_hook = {
.fn = kgdb_compiled_brk_fn .fn = kgdb_compiled_brk_fn
}; };
static struct step_hook kgdb_step_hook = {
.fn = kgdb_step_brk_fn
};
static void kgdb_call_nmi_hook(void *ignored) static void kgdb_call_nmi_hook(void *ignored)
{ {
kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs()); kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
...@@ -259,6 +305,7 @@ int kgdb_arch_init(void) ...@@ -259,6 +305,7 @@ int kgdb_arch_init(void)
register_break_hook(&kgdb_brkpt_hook); register_break_hook(&kgdb_brkpt_hook);
register_break_hook(&kgdb_compiled_brkpt_hook); register_break_hook(&kgdb_compiled_brkpt_hook);
register_step_hook(&kgdb_step_hook);
return 0; return 0;
} }
...@@ -271,6 +318,7 @@ void kgdb_arch_exit(void) ...@@ -271,6 +318,7 @@ void kgdb_arch_exit(void)
{ {
unregister_break_hook(&kgdb_brkpt_hook); unregister_break_hook(&kgdb_brkpt_hook);
unregister_break_hook(&kgdb_compiled_brkpt_hook); unregister_break_hook(&kgdb_compiled_brkpt_hook);
unregister_step_hook(&kgdb_step_hook);
unregister_die_notifier(&kgdb_notifier); unregister_die_notifier(&kgdb_notifier);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment