Browse Source

Implements qemu debug support

tags/v0.2
dump_stack() 1 year ago
parent
commit
4a247b229a
2 changed files with 56 additions and 0 deletions
  1. 12
    0
      qemu/qemu-kernel.go
  2. 44
    0
      qemu/qemu-kernel_test.go

+ 12
- 0
qemu/qemu-kernel.go View File

@@ -67,6 +67,9 @@ type QemuSystem struct {
Cpus int
Memory int

debug bool
gdb string // tcp::1234

// Timeout works after Start invocation
Timeout time.Duration
KilledByTimeout bool
@@ -184,6 +187,10 @@ func (q *QemuSystem) Start() (err error) {
"-netdev", "user,id=n1," + hostfwd,
}

if q.debug {
qemuArgs = append(qemuArgs, "-gdb", q.gdb)
}

if q.kernel.InitrdPath != "" {
qemuArgs = append(qemuArgs, "-initrd", q.kernel.InitrdPath)
}
@@ -338,3 +345,8 @@ func (q *QemuSystem) CopyAndRun(user, path string) (output string, err error) {

return q.Command(user, "chmod +x "+remotePath+" && "+remotePath)
}

func (q *QemuSystem) Debug(conn string) {
q.debug = true
q.gdb = conn
}

+ 44
- 0
qemu/qemu-kernel_test.go View File

@@ -299,3 +299,47 @@ func TestQemuSystemRun(t *testing.T) {
}

}

func openedPort(port int) bool {
conn, err := net.Dial("tcp", fmt.Sprintf(":%d", port))
if err != nil {
return false
}
conn.Close()
return true
}

func TestQemuSystemDebug(t *testing.T) {
t.Parallel()
kernel := Kernel{
KernelPath: testConfigVmlinuz,
InitrdPath: testConfigInitrd,
}
q, err := NewQemuSystem(X86_64, kernel, testConfigRootfs)
if err != nil {
return
}

port := 45256

q.Debug(fmt.Sprintf("tcp::%d", port))

if openedPort(port) {
t.Fatal("Port opened before qemu starts")
}

if err = q.Start(); err != nil {
return
}
defer q.Stop()

if !openedPort(port) {
t.Fatal("Qemu debug port does not opened")
}

q.Stop()

if openedPort(port) {
t.Fatal("Qemu listens after die")
}
}

Loading…
Cancel
Save