GDB QEMU Remote target doesn't support qGetTIBAddr packet - rust

I'm trying to debug an EFI application in qemu with gdb. QEMU is started with -s and -S flags and gdb is started with
gdb ./target/x86_64-unknown-uefi/debug/application.efi
and qemu is targeted with
target remote :1234
GDB resonds with Remote target doesn't support qGetTIBAddr packet.
I verified that the efi file contains debug symbols. I can't find anything about this online so any help is appreciated.

Related

Debugging linux kernel with gdb via QEMU issue

I am newbie in Linux kernel and I'm trying to debug it with gdb via QEMU. My problem is gdb doesn't stop after break start_kernel. More details is below.
My host system is ArchLinux 5.0.10-arch1-1-ARCH x86_64.
Qemu is QEMU emulator version 4.0.0
gdb is GNU gdb (GDB) 8.2.1.
Debugged kernel is linux-4.20.12
I have done following steps:
Compile kernel with
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_KERNEL=y
CONFIG_GDB_SCRIPTS=y
# CONFIG_DEBUG_INFO_REDUCED is not set
Try to run LFS-8.4 system with it kernel via QEMU
qemu-system-x86_64 lfs-8.4-08052019.raw
System starts good.
Run this system with stop CPU and gdbserver options via QEMU
qemu-system-x86_64 lfs-8.4-08052019.raw -S -s
Start gdb
$ gdb
Load symbols
(gdb) file /mnt/lfs/sources/linux-4.20.12/vmlinux
Reading symbols from /mnt/lfs/sources/linux-4.20.12/vmlinux...done.
Connect to QEMU
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x000000000000fff0 in cpu_hw_events ()
Set break point
(gdb) break start_kernel
Breakpoint 1 at 0xffffffff82761ab5: file init/main.c, line 538.
(I have tried hardware break point hbreak, but result is the same)
Continue
(gdb) c
Continuing.
Further system loads login prompt without any breaks and gdb doesn't show any new messages.
What I do wrong?
UPD: starting QEMU with embed -kernel facility give the same result
qemu-system-x86_64 -kernel /mnt/lfs/sources/linux-4.20.12/arch/x86/boot/bzImage -append 'root=/dev/sda3' -drive file=lfs-8.4-08052019.raw -S -s
UPD2: I have tried to start QEMU without -S key and run target remote localhost:1234 in gdb immediately. QEMU have stopped loading at
Decompressing Linux... Parsing ELF... Performing relocations... done.
Booting kernel.
When I type s in gdb it says
(gdb) s
Cannot find bounds of current function
I suspect that debug symbols in vmlinux isn't related to bzImage. Maybe they was made wrong, but I don't how to make them another way.
UPD3: I have built kernel 2.6 in LFS-8.4 chroot environment. System isn't loaded, but kernel is successfully debugged by method described above! So, I think that it is problem of new kernels. Maybe I should switch off/on something in my 4.20.12 kernel, but I don't know what is exactly. For my purpose (reading Robert Love "Linux Kernel Development") kernel version 2.6 is enough.
You need to pass nokaslr to kernel cmdline.
qemu-system-x86_64 -kernel /mnt/lfs/sources/linux-4.20.12/arch/x86/boot/bzImage -append 'root=/dev/sda3 nokaslr' -drive file=lfs-8.4-08052019.raw -S -s

gdb can't resolve symbols for linux kernel

I have setup Linux Kernel debug environment with VMware Workstation. But When I tried to connect with gdb that connects correctly but I can't set any breakpoint or examine any kernel symbol.
Target Machine (debugee) Ubuntu 18:
I have compiled linux kernel 5.0-0 with the following directives:
CONFIG_DEBUG_INFO=y
# CONFIG_DEBUG_INFO_REDUCED is not set
# CONFIG_DEBUG_INFO_SPLIT is not set
CONFIG_DEBUG_INFO_DWARF4=y
CONFIG_DEBUG_FS=y
# CONFIG_DEBUG_SECTION_MISMATCH is not set
# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
Also my VMX file configuration:
debugStub.listen.guest64 = "TRUE"
debugStub.listen.guest64.remote="TRUE"
After that I transfered vmlinux to debugger machine and use gdb:
bash$ gdb vmlinux
gdb-peda$ target remote 10.251.31.28:8864
Remote debugging using 10.251.31.28:8864
Warning: not running or target is remote
0xffffffff9c623f36 in ?? ()
gdb-peda$ disas sys_open
No symbol "do_sys_open" in current context.
First you need to install kernel-debug-devel, kernel-debuginfo, kernel-debuginfo-common for corresponding kernel version.
Then you can use crash utility to debug kernel, which internally uses gdb
The symbol name you're looking for is sometimes not exactly what you expect it to be. You can use readelf or other similar tools to find the full name of the symbol in the kernel image. These names sometimes differ from the names in the code because of various architecture level differences and their related header and C definitions in kernel code. For example you might be able to disassemble the open() system call by using:
disas __x64_do_sys_open
if you've compiled it for x86-64 architecture.
Also keep in mind that these naming conventions are subject to change in different versions of kernel.

I cannot break with GDB and QEMU

I am debugging the Linux Kernel (latest version) using GDB and QEMU.
I have set DEBUG_INFO to yes in the configuration file.
Here is how I call QEMU:
$> qemu-system-x86_64 -snapshot -m 4G -serial stdio -kernel ~/Documents/kernel/arch/x86_64/boot/bzImage -initrd ~/D\
ocuments/kernel/initrd/initrd_x86_64.gz -append "root=/dev/sda1 ignore_loglevel" -s
And GDB of course:
$> gdb vmlinux
Then inside gdb:
(gdb)> target remote :1234
So nothing amazing.
It stops QEMU. I set my breakpoints, which seems to work as usual, and I type "continue". The QEMU execution resumes.
But then, even if my function is reached (I see the kernel message printk I set inside the function), gdb does not stop.
$> qemu-system-x86_64 --version
QEMU emulator version 2.12.0 (Debian 1:2.12+dfsg-3)
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
And
$> gdb --version
GNU gdb (Debian 8.1-4) 8.1
I don't know what to try next.
Any help would be appreciated.
PS: for information, I am writing a keylogger as a Linux driver. So I am registering a new keyboard notifier, and this is the keyboard notifier that is failing.
PS2: I also tried what they recommend here stack overflow question about setting hardware breakpoints instead, but it did not change anything, same problem.
Thank you.
Julien

could not to setup crash dump on centos7 for debug kernel

I am trying to setup kdump to generate the vmcore for kernel-3.10.0-123.el7. For the perf kernel kernel-3.10.0-123.el7.x86_64.rpm i setup kdump and kdump is working fine too, generating vmcore.
Then i installed
kernel-debug-3.10.0-123.el7.x86_64.rpm
using yum install kernel-debug-3.10.0-123.el7.x86_64.rpm and kdump worked fine.
But then i didnt have vmlinux to read vmcore of debug kernel.
Then I build source using rpmbuild from the source
kernel-3.10.0-123.el7.src.rpm
But I see the vmlinux in
~/rpmbuild/BUILD/kernel-3.10.0-123.el7/linux-3.10.0-123.el7.x86_64/vmlinux
for perf kernel only not for debug kernel
So from ~/rpmbuild/SOURCES
i copied linux-3.10.0-123.el7.x86_64.tar.xz and used
kernel-3.10.0-x86_64-debug.config as .config to get vmlinux
When i used this newly built vmlinux for debug kernel with crash it threw error that kernel version mismatch. Now I am stuck.
Please help me in setting up the kdump on centos7 with debug kernel & debug vmlinux.
Since I am new to centos I was not aware of debug pakages has vmlinux. i have installed debug rpms using following command:
yum --enablerepo=debug install kexec-tools crash kernel-debug kernel-debuginfo-`uname -r`
I notice kernel-debuginfo-3.10.0-123.el7.x86_64 has vmlinux at location:
/usr/lib/debug/lib/modules/3.10.0-123.el7.x86_64/vmlinux
So i got the vmlinux.
This vmlinux works with non-debug kernel.

How to use kgdb over ethernet (kgdboe)?

i am using ubuntu 12.04 and kernel version is 3.12.6, i want to learn how to use kgdb to debug kernel. I didn't get much info. regarding kgdboe (kgdb over ethernet). I have compiled kernel and enabled kgdb in menuconfig, i have created kernel image using make bzImage on development machine and copied same on target machine, now problem is how to connect both target and development machine. i m not getting parameter set for kgbdoe. Plz help if anybody know how to use kgdb over ethernet
Have you read this:
https://www.kernel.org/pub/linux/kernel/people/jwessel/kgdb/ch03s04.html
?
You have to run debugged kernel with special options - like for example:
kgdbwait kgdbcon kgdboe=#192.168.248.76/,#192.168.242.24/00:11:22:33:44:55
and on debugging side you run following commands:
gdb
file vmlinux
target remote udp:192.168.248.76:6443
it has worked for me.
You can get the kgdboe source from here, build it and load it into your kernel:
make -C /lib/modules/$(uname -r)/build M=$(pwd)
sudo insmod kgdboe.ko
Then type 'dmesg' to see the load log and get instructions on connecting from gdb.

Resources