Skip to content

Commit 9901a6b

Browse files
committed
Merge tag 'riscv-for-linus-5.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: "I have a few KGDB-related fixes. They're mostly fixes for build warnings, but there's also: - Support for the qSupported and qXfer packets, which are necessary to pass around GDB XML information which we need for the RISC-V GDB port to fully function. - Users can now select STRICT_KERNEL_RWX instead of forcing it on" * tag 'riscv-for-linus-5.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: Avoid kgdb.h including gdb_xml.h to solve unused-const-variable warning kgdb: Move the extern declaration kgdb_has_hit_break() to generic kgdb.h riscv: Fix "no previous prototype" compile warning in kgdb.c file riscv: enable the Kconfig prompt of STRICT_KERNEL_RWX kgdb: enable arch to support XML packet.
2 parents 9599e9e + 70ee573 commit 9901a6b

File tree

7 files changed

+41
-9
lines changed

7 files changed

+41
-9
lines changed

arch/riscv/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ config RISCV
2323
select ARCH_HAS_SET_DIRECT_MAP
2424
select ARCH_HAS_SET_MEMORY
2525
select ARCH_HAS_STRICT_KERNEL_RWX if MMU
26+
select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
27+
select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
2628
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
2729
select ARCH_WANT_FRAME_POINTERS
2830
select ARCH_WANT_HUGE_PMD_SHARE if 64BIT

arch/riscv/include/asm/gdb_xml.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#ifndef __ASM_GDB_XML_H_
44
#define __ASM_GDB_XML_H_
55

6-
#define kgdb_arch_gdb_stub_feature riscv_gdb_stub_feature
7-
static const char riscv_gdb_stub_feature[64] =
6+
const char riscv_gdb_stub_feature[64] =
87
"PacketSize=800;qXfer:features:read+;";
98

109
static const char gdb_xfer_read_target[31] = "qXfer:features:read:target.xml:";

arch/riscv/include/asm/kgdb.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#ifndef __ASSEMBLY__
2121

22-
extern int kgdb_has_hit_break(unsigned long addr);
2322
extern unsigned long kgdb_compiled_break;
2423

2524
static inline void arch_kgdb_breakpoint(void)
@@ -106,7 +105,9 @@ static inline void arch_kgdb_breakpoint(void)
106105
#define DBG_REG_BADADDR_OFF 34
107106
#define DBG_REG_CAUSE_OFF 35
108107

109-
#include <asm/gdb_xml.h>
108+
extern const char riscv_gdb_stub_feature[64];
109+
110+
#define kgdb_arch_gdb_stub_feature riscv_gdb_stub_feature
110111

111112
#endif
112113
#endif

arch/riscv/kernel/kgdb.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ DECLARE_INSN(c_beqz, MATCH_C_BEQZ, MASK_C_BEQZ)
4444
DECLARE_INSN(c_bnez, MATCH_C_BNEZ, MASK_C_BNEZ)
4545
DECLARE_INSN(sret, MATCH_SRET, MASK_SRET)
4646

47-
int decode_register_index(unsigned long opcode, int offset)
47+
static int decode_register_index(unsigned long opcode, int offset)
4848
{
4949
return (opcode >> offset) & 0x1F;
5050
}
5151

52-
int decode_register_index_short(unsigned long opcode, int offset)
52+
static int decode_register_index_short(unsigned long opcode, int offset)
5353
{
5454
return ((opcode >> offset) & 0x7) + 8;
5555
}
5656

5757
/* Calculate the new address for after a step */
58-
int get_step_address(struct pt_regs *regs, unsigned long *next_addr)
58+
static int get_step_address(struct pt_regs *regs, unsigned long *next_addr)
5959
{
6060
unsigned long pc = regs->epc;
6161
unsigned long *regs_ptr = (unsigned long *)regs;
@@ -136,7 +136,7 @@ int get_step_address(struct pt_regs *regs, unsigned long *next_addr)
136136
return 0;
137137
}
138138

139-
int do_single_step(struct pt_regs *regs)
139+
static int do_single_step(struct pt_regs *regs)
140140
{
141141
/* Determine where the target instruction will send us to */
142142
unsigned long addr = 0;
@@ -320,7 +320,7 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,
320320
return err;
321321
}
322322

323-
int kgdb_riscv_kgdbbreak(unsigned long addr)
323+
static int kgdb_riscv_kgdbbreak(unsigned long addr)
324324
{
325325
if (stepped_address == addr)
326326
return KGDB_SW_SINGLE_STEP;

include/linux/kgdb.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ kgdb_arch_handle_exception(int vector, int signo, int err_code,
176176
char *remcom_out_buffer,
177177
struct pt_regs *regs);
178178

179+
/**
180+
* kgdb_arch_handle_qxfer_pkt - Handle architecture specific GDB XML
181+
* packets.
182+
* @remcom_in_buffer: The buffer of the packet we have read.
183+
* @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
184+
*/
185+
186+
extern void
187+
kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer,
188+
char *remcom_out_buffer);
189+
179190
/**
180191
* kgdb_call_nmi_hook - Call kgdb_nmicallback() on the current CPU
181192
* @ignored: This parameter is only here to match the prototype.
@@ -314,6 +325,7 @@ extern int kgdb_hex2mem(char *buf, char *mem, int count);
314325

315326
extern int kgdb_isremovedbreak(unsigned long addr);
316327
extern void kgdb_schedule_breakpoint(void);
328+
extern int kgdb_has_hit_break(unsigned long addr);
317329

318330
extern int
319331
kgdb_handle_exception(int ex_vector, int signo, int err_code,

kernel/debug/gdbstub.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,19 @@ static void gdb_cmd_query(struct kgdb_state *ks)
792792
}
793793
break;
794794
#endif
795+
#ifdef CONFIG_HAVE_ARCH_KGDB_QXFER_PKT
796+
case 'S':
797+
if (!strncmp(remcom_in_buffer, "qSupported:", 11))
798+
strcpy(remcom_out_buffer, kgdb_arch_gdb_stub_feature);
799+
break;
800+
case 'X':
801+
if (!strncmp(remcom_in_buffer, "qXfer:", 6))
802+
kgdb_arch_handle_qxfer_pkt(remcom_in_buffer,
803+
remcom_out_buffer);
804+
break;
805+
#endif
806+
default:
807+
break;
795808
}
796809
}
797810

lib/Kconfig.kgdb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
config HAVE_ARCH_KGDB
44
bool
55

6+
# set if architecture has the its kgdb_arch_handle_qxfer_pkt
7+
# function to enable gdb stub to address XML packet sent from GDB.
8+
config HAVE_ARCH_KGDB_QXFER_PKT
9+
bool
10+
611
menuconfig KGDB
712
bool "KGDB: kernel debugger"
813
depends on HAVE_ARCH_KGDB

0 commit comments

Comments
 (0)