[PATCH] arm kgdb: fix breakpoint for thumb2

Johannes Stezenbach js at sig21.net
Mon Feb 14 10:33:17 PST 2022


On Mon, Feb 14, 2022 at 12:56:33PM +0000, Russell King (Oracle) wrote:
> The kgdb code needs to register an undef hook for the Thumb UDF
> instruction that will fault, in addition to the ARM version. Probably
> something like this (untested). Please let me know if this works.
>
> diff --git a/arch/arm/kernel/kgdb.c b/arch/arm/kernel/kgdb.c
> index 7bd30c0a4280..a3602cacda0b 100644
> --- a/arch/arm/kernel/kgdb.c
> +++ b/arch/arm/kernel/kgdb.c
> @@ -154,22 +154,38 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int instr)
>  	return 0;
>  }
>  
> -static struct undef_hook kgdb_brkpt_hook = {
> +static struct undef_hook kgdb_brkpt_arm_hook = {
>  	.instr_mask		= 0xffffffff,
>  	.instr_val		= KGDB_BREAKINST,
> -	.cpsr_mask		= MODE_MASK,
> +	.cpsr_mask		= PSR_T_BIT | MODE_MASK,
>  	.cpsr_val		= SVC_MODE,
>  	.fn			= kgdb_brk_fn
>  };
>  
> -static struct undef_hook kgdb_compiled_brkpt_hook = {
> +static struct undef_hook kgdb_brkpt_thumb_hook = {
> +	.instr_mask		= 0xffff,
> +	.instr_val		= KGDB_BREAKINST & 0xffff,
> +	.cpsr_mask		= PSR_T_BIT | MODE_MASK,
> +	.cpsr_val		= PSR_T_BIT | SVC_MODE,
> +	.fn			= kgdb_brk_fn
> +};
> +
> +static struct undef_hook kgdb_compiled_brkpt_arm_hook = {
>  	.instr_mask		= 0xffffffff,
>  	.instr_val		= KGDB_COMPILED_BREAK,
> -	.cpsr_mask		= MODE_MASK,
> +	.cpsr_mask		= PSR_T_BIT | MODE_MASK,
>  	.cpsr_val		= SVC_MODE,
>  	.fn			= kgdb_compiled_brk_fn
>  };
>  
> +static struct undef_hook kgdb_compiled_brkpt_thumb_hook = {
> +	.instr_mask		= 0xffff,
> +	.instr_val		= KGDB_COMPILED_BREAK & 0xffff,
> +	.cpsr_mask		= PSR_T_BIT | MODE_MASK,
> +	.cpsr_val		= PSR_T_BIT | SVC_MODE,
> +	.fn			= kgdb_compiled_brk_fn
> +};
> +
>  static int __kgdb_notify(struct die_args *args, unsigned long cmd)
>  {
>  	struct pt_regs *regs = args->regs;
> @@ -210,8 +226,10 @@ int kgdb_arch_init(void)
>  	if (ret != 0)
>  		return ret;
>  
> -	register_undef_hook(&kgdb_brkpt_hook);
> -	register_undef_hook(&kgdb_compiled_brkpt_hook);
> +	register_undef_hook(&kgdb_brkpt_arm_hook);
> +	register_undef_hook(&kgdb_brkpt_thumb_hook);
> +	register_undef_hook(&kgdb_compiled_brkpt_arm_hook);
> +	register_undef_hook(&kgdb_compiled_brkpt_thumb_hook);
>  
>  	return 0;
>  }

It has compile errors, but with those fixed up your patch works nicely.

arch/arm/kernel/kgdb.c: In function ‘kgdb_arch_exit’:
arch/arm/kernel/kgdb.c:245:25: error: ‘kgdb_brkpt_hook’ undeclared (first use in this function); did you mean ‘kgdb_brkpt_arm_hook’?
  245 |  unregister_undef_hook(&kgdb_brkpt_hook);
      |                         ^~~~~~~~~~~~~~~
      |                         kgdb_brkpt_arm_hook
arch/arm/kernel/kgdb.c:245:25: note: each undeclared identifier is reported only once for each function it appears in
arch/arm/kernel/kgdb.c:246:25: error: ‘kgdb_compiled_brkpt_hook’ undeclared (first use in this function); did you mean ‘
kgdb_compiled_brkpt_arm_hook’?
  246 |  unregister_undef_hook(&kgdb_compiled_brkpt_hook);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~
      |                         kgdb_compiled_brkpt_arm_hook


Thanks,
Johannes



More information about the linux-arm-kernel mailing list