kvm tools: Lookup symbol based on RIP for 'kill -3'
PATCH 1/1 kvm tools: Lookup symbol based on RIP for 'kill -3'
To make debugging easier, look up symbol from guest kernel image based on RIP when user does 'kill -3' to the hypervisor.
Example output looks as follows:
Code:
-----
rip: [<ffffffff812cb3a0>] delay_loop+30 (/home/penberg/linux/arch/x86/lib/delay.c:32)
--- tools/kvm/Makefile | 2 + tools/kvm/include/kvm/kvm.h | 2 + tools/kvm/include/kvm/symbol.h | 12 +++++ tools/kvm/kvm-cpu.c | 9 ++++ tools/kvm/kvm-run.c | 43 +++++++++++++++-- tools/kvm/symbol.c | 98 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 tools/kvm/include/kvm/symbol.h create mode 100644 tools/kvm/symbol.c
tools/kvm/Makefile +2 -0
@@ -24,6 +24,7 @@ OBJS += main.o OBJS += mmio.o OBJS += pci.o OBJS += rtc.o +OBJS += symbol.o OBJS += term.o OBJS += util.o OBJS += virtio/blk.o
@@ -50,6 +51,7 @@ OBJS += bios/bios.o LIBS += -lrt LIBS += -lpthread +LIBS += -lbfd # Additional ARCH settings for x86 ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
tools/kvm/include/kvm/kvm.h +2 -0
@@ -28,6 +28,8 @@ struct kvm {u16 boot_sp;struct interrupt_table interrupt_table; + +const char *vmlinux; };struct kvm *kvm__init (const char *kvm_dev,unsigned long ram_size);
tools/kvm/include/kvm/symbol.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef KVM__SYMBOL_H +#define KVM__SYMBOL_H + +#include <stddef.h> + +struct kvm ; + +void symbol__init (const char *vmlinux); + +char *symbol__lookup (struct kvm *kvm,unsigned long addr,char *sym,size_t size); + +#endif /* KVM__SYMBOL_H */
tools/kvm/kvm-cpu.c +9 -0
@@ -1,5 +1,6 @@#include "kvm/kvm-cpu.h" +#include "kvm/symbol.h" #include "kvm/util.h" #include "kvm/kvm.h"
@@ -9,6 +10,7 @@#include <sys/mman.h> #include <signal.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <stdio.h>
@@ -282,11 +284,14 @@ void kvm_cpu__show_registers(struct kvm_cpu *vcpu)printf ("\n" ); } +#define MAX_SYM_LEN 128 +void kvm_cpu__show_code (struct kvm_cpu *vcpu) {unsigned int code_bytes =64 ;unsigned int code_prologue = code_bytes *43 /64 ;unsigned int code_len = code_bytes; +char sym[MAX_SYM_LEN ];unsigned char c;unsigned int i;u8 *ip;
@@ -302,6 +307,10 @@ void kvm_cpu__show_code(struct kvm_cpu *vcpu)printf ("\n Code:\n" );printf (" -----\n" ); +symbol__lookup (vcpu->kvm, vcpu->regs.rip, sym,MAX_SYM_LEN ); + +printf (" rip: [<%016lx>] %s\n\n" , (unsigned long ) vcpu->regs.rip, sym); +for (i =0 ; i < code_len; i++, ip++) {if (!host_ptr_in_ram (vcpu->kvm, ip))break ;
tools/kvm/kvm-run.c +38 -5
104 lines not on this page · raw message
tools/kvm/symbol.c new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Quoted 5 lines · Pekka Enberg
To make debugging easier, look up symbol from guest kernel image based on RIP when user does 'kill -3' to the hypervisor.
Example output looks as follows:
FWIW, works pretty well for me. Probably we need some -e option for vmlinux path in future.
Signature · 1 line
Cyrill
Quoted 8 lines · Pekka Enberg
To make debugging easier, look up symbol from guest kernel image based on RIP when user does 'kill -3' to the hypervisor.
Example output looks as follows:
Code:
-----
rip: [<ffffffff812cb3a0>] delay_loop+30 (/home/penberg/linux/arch/x86/lib/delay.c:32)
Hm, it does not work here:
rip: [<ffffffff8103921f>] <unknown>
While ../../vmlinux definitely has it:
ffffffff810391d9 <default_idle>:
ffffffff8103921f: eb 01 jmp ffffffff81039222 <default_idle+0x49>
Does libbfd require debug symbols? That's sad as i almost never use debug symbols.
It would be nice to import the relevant elflib magic from tools/perf/.
Thanks,
Ingo
Another suggestion: would anyone be interested in adding a 'kvm debug' command that does the kill -3 magic?
Initially it could be something very simple like:
int cmd_debug()
{
system("kill -3 $(pidof kvm)");
}:-)
as i always have to remember this sequence to debug the guest - while typing 'kvm debug' would be a no-brainer.
(Maybe make it 'kvm debug guest', to keep the 'kvm debug' namespace clean.)
Thanks,
Ingo