qemu-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Linux Kernel debugging using (K)GDB, symbols zeroed out


From: Aijaz Baig
Subject: Linux Kernel debugging using (K)GDB, symbols zeroed out
Date: Mon, 30 Oct 2023 10:53:47 +0530

I'm trying to debug the Linux kernel (v3.13) via QEMU. I am using [this][1], [this][2] and [this][3] as reference. Since my host is Linux Mint Victoria, it was too much of a hassle trying to compile the kernel as well as rootfs for v3.13 (circa 2014). Which is why I resorted to using a docker container to get Ubuntu Trusty Tahr like so:

```
mkdir docker
FROM ubuntu:14.04" > docker/Dockerfile
RUN apt-get update && apt-get install -y vim wget unzip bc git python rsync build-essential libncurses5-dev locales" >> docker/Dockerfile
docker build --tag "ubuntu-trusty" docker/
```
Once inside the container I clone buildroot, checkout tag `2014/08`. Then I let buildroot build the kernel for me (v3.13.5). Here are my buildroot [config][4] and the kernel [config][5] options.

FYI I choose to integrate the rootfs into the kernel *as an initramfs* as described [here][6]. Once done, I see a `rootfs.cpio` archive and a `bzImage` under `output/images`.  Once everything is complete, I invoke qemu like so:
`sudo qemu-system-x86_64 --enable-kvm -serial tcp::1234,server,nowait -m 512M -kernel ./bzImage -append "kgdbwait kgdboc=ttyS0,115200 nokaslr ip=dhcp" -net nic,model=virtio -device virtio-blk,drive=drive0 -drive file=./disk.img,format=raw,if=none,id=drive0`

This opens a new window which displays the start-up log and ultimately runs the getty process allowing me to log in. So here are my queries

 1. If I pass `-nographic` to QEMU, I do not see the login prompt. Why?
 2. if I use `-s` which is equivalent to `-gdb tcp:1234`, the gdb client doesn't seem to connect to it properly (it breaks in at a different place in the kernel as compared to when I use `-serial tcp::1234,server,nowait` instead); although qemu is apparently paused, waiting for a connection from remote gdb
 3. Most of the backtrace stack symbols are '??' even though I've enabled debug info and frame pointers in the kernel. I even compiled using COPTS=-O0 which increased the size of the binary but to no avail as far as qemu gdb is concerned.

Keen to hear what you folks have to say!

  [1]: https://stackoverflow.com/a/44197715/1794617
  [2]: https://stackoverflow.com/a/33203642/1794617
  [3]: https://stackoverflow.com/questions/60988342/qemu-doesnt-recognize-block-device-file
  [4]: https://raw.githubusercontent.com/redbilledpanda/SetupScripts/Unix/BUILDROOT_CONFIG
  [5]: https://raw.githubusercontent.com/redbilledpanda/SetupScripts/Unix/KERNEL_CONFIG
  [6]: https://raw.githubusercontent.com/maximeh/buildroot/master/fs/initramfs/Config.in

--

Best Regards,
Aijaz Baig

reply via email to

[Prev in Thread] Current Thread [Next in Thread]