Skip to content

Commit 781380d

Browse files
mssolaPaul Walmsley
authored andcommitted
riscv: kgdb: Ensure that BUFMAX > NUMREGBYTES
The current value of BUFMAX is similar as in other architectures, but as per documentation on KGDB (see 'Documentation/process/debugging/kgdb.rst'), BUFMAX has to be larger than NUMREGBYTES. Some NUMREGBYTES architectures (e.g. powerpc or hexagon) actually define BUFMAX in relation to NUMREGBYTES, and thus this condition is always guaranteed. Since 2048 is a value that is generally accepted on all architectures, and that is larger than the current value of NUMREGBYTES, we can keep this value in arch/riscv, but we can at least add an 'static_assert' as an extra measure just in case NUMREGBYTES changes in the future for some unforseen reason. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com> Link: https://lore.kernel.org/r/20250915143252.154955-1-mikisabate@gmail.com Signed-off-by: Paul Walmsley <pjw@kernel.org>
1 parent 812258f commit 781380d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

arch/riscv/include/asm/kgdb.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
#ifndef __ASM_KGDB_H_
44
#define __ASM_KGDB_H_
55

6+
#include <linux/build_bug.h>
7+
68
#ifdef __KERNEL__
79

810
#define GDB_SIZEOF_REG sizeof(unsigned long)
911

10-
#define DBG_MAX_REG_NUM (36)
11-
#define NUMREGBYTES ((DBG_MAX_REG_NUM) * GDB_SIZEOF_REG)
12+
#define DBG_MAX_REG_NUM 36
13+
#define NUMREGBYTES (DBG_MAX_REG_NUM * GDB_SIZEOF_REG)
1214
#define CACHE_FLUSH_IS_SAFE 1
1315
#define BUFMAX 2048
16+
static_assert(BUFMAX > NUMREGBYTES,
17+
"As per KGDB documentation, BUFMAX must be larger than NUMREGBYTES");
1418
#ifdef CONFIG_RISCV_ISA_C
1519
#define BREAK_INSTR_SIZE 2
1620
#else
@@ -97,6 +101,7 @@ extern unsigned long kgdb_compiled_break;
97101
#define DBG_REG_STATUS_OFF 33
98102
#define DBG_REG_BADADDR_OFF 34
99103
#define DBG_REG_CAUSE_OFF 35
104+
/* NOTE: increase DBG_MAX_REG_NUM if you add more values here. */
100105

101106
extern const char riscv_gdb_stub_feature[64];
102107

0 commit comments

Comments
 (0)