Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use GDB to debug QEMU with SMP (symmetric multiple processors)?

I am in a graduate operating systems class, and we are emulating our kernel using QEMU, and debugging it using gdb. Debugging has been straight-forward enough.. up until now. How can I connect gdb to the other CPUs I have running in QEMU?

Our makefile allows us to start qemu with either "make qemu-nox" or "make qemu-nox-gdb" in one terminal, and if we used the latter, then to connect to it with gdb using just "gdb" in another terminal (in the same directory). Thus, I'm not quite sure how to connect to the same QEMU, again, but to a different processor (I'm running with a total of 4 right now).

like image 956
vasia Avatar asked Mar 15 '17 03:03

vasia


1 Answers

Each qemu CPU is visible as a separate thread within gdb. To inspect the state of another CPU, use the thread command to switch CPUs.

(gdb) info thread
  Id   Target Id         Frame 
* 1    Thread 1 (CPU#0 [running]) 0x80105163 in stosl (addr=0x89c3e000, data=16843009, cnt=1024) at x86.h:44
  2    Thread 2 (CPU#1 [halted ]) halt () at x86.h:127
  3    Thread 3 (CPU#2 [halted ]) halt () at x86.h:127
  4    Thread 4 (CPU#3 [halted ]) halt () at x86.h:127

(gdb) where
#0  0x80105163 in stosl (addr=0x89c3e000, data=16843009, cnt=1024) at x86.h:44
#1  0x801051bf in memset (dst=0x89c3e000, c=1, n=4096) at string.c:8
#2  0x80102b5a in kfree (v=0x89c3e000 "\001\001\001\001") at kalloc.c:63
#3  0x80102af4 in freerange (vstart=0x80400000, vend=0x8e000000) at kalloc.c:47
#4  0x80102ac1 in kinit2 (vstart=0x80400000, vend=0x8e000000) at kalloc.c:38
#5  0x8010386a in main () at main.c:37

(gdb) thread 3
[Switching to thread 3 (Thread 3)]
#0  halt () at x86.h:127
127 }

(gdb) where
#0  halt () at x86.h:127
#1  0x80104aeb in scheduler () at proc.c:288
#2  0x801038f6 in mpmain () at main.c:59
#3  0x801038b0 in mpenter () at main.c:50
#4  0x0000705a in ?? ()
like image 107
sigjuice Avatar answered Sep 29 '22 11:09

sigjuice