From: Amal Raj T <amalrajt@xxxxxxxx> Add a new query `linux.vmcoreinfo` to kgdb that returns vmcoreinfo to the client using the mem2ebin encoding. Maximum size of output buffer is set to 2x the maximum size of VMCOREINFO_BYTES (kgdb_mem2ebin() requires 1x for the temporary copy plus another 1x (max) for the escaped data). Link: https://github.com/osandov/drgn/wiki/GDB-Remote-Protocol-proposal:-linux.vmcoreinfo-query-packet --- kernel/debug/gdbstub.c | 18 ++++++++++++++---- lib/Kconfig.kgdb | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/kernel/debug/gdbstub.c b/kernel/debug/gdbstub.c index f88e21d5502a..f2c80bd368e2 100644 --- a/kernel/debug/gdbstub.c +++ b/kernel/debug/gdbstub.c @@ -30,20 +30,21 @@ #include <linux/kgdb.h> #include <linux/kdb.h> #include <linux/serial_core.h> +#include <linux/string.h> #include <linux/reboot.h> #include <linux/uaccess.h> #include <asm/cacheflush.h> #include <linux/unaligned.h> +#include <linux/vmcore_info.h> #include "debug_core.h" #define KGDB_MAX_THREAD_QUERY 17 /* Our I/O buffers. */ static char remcom_in_buffer[BUFMAX]; -static char remcom_out_buffer[BUFMAX]; +static char remcom_out_buffer[MAX(VMCOREINFO_BYTES * 2, BUFMAX)]; static int gdbstub_use_prev_in_buf; static int gdbstub_prev_in_buf_pos; - /* Storage for the registers, in GDB format. */ static unsigned long gdb_regs[(NUMREGBYTES + sizeof(unsigned long) - 1) / sizeof(unsigned long)]; @@ -292,8 +293,8 @@ char *kgdb_mem2ebin(char *mem, char *buf, int count) } else { *buf++ = c; } - count -= 1; - tmp += 1; + count--; + tmp++; } return buf; @@ -777,6 +778,15 @@ static void gdb_cmd_query(struct kgdb_state *ks) *(--ptr) = '\0'; break; + case 'l': + if (strncmp(remcom_in_buffer + 1, "linux.vmcoreinfo", 17) == + 0) { + remcom_out_buffer[0] = 'Q'; + kgdb_mem2ebin(vmcoreinfo_data, remcom_out_buffer + 1, + vmcoreinfo_size); + } + break; + case 'C': /* Current thread id */ strcpy(remcom_out_buffer, "QC"); diff --git a/lib/Kconfig.kgdb b/lib/Kconfig.kgdb index 537e1b3f5734..012529eee79e 100644 --- a/lib/Kconfig.kgdb +++ b/lib/Kconfig.kgdb @@ -12,6 +12,7 @@ menuconfig KGDB bool "KGDB: kernel debugger" depends on HAVE_ARCH_KGDB depends on DEBUG_KERNEL + select VMCORE_INFO help If you say Y here, it will be possible to remotely debug the kernel using gdb. It is recommended but not required, that -- 2.43.5