Skip to content

Instantly share code, notes, and snippets.

@styxyang
Created October 22, 2013 08:49
Show Gist options
  • Save styxyang/7097293 to your computer and use it in GitHub Desktop.
Save styxyang/7097293 to your computer and use it in GitHub Desktop.
tcl script to test gdb-like breakpoint function for jos lab
#!/usr/bin/expect -f
set timeout 10; # set timeout to -1 to wait forever
set hda "obj/kern/kernel.img"
# spawn qemu -nographic -hda $hda -serial "file:jos.out" -monitor null -no-reboot
spawn qemu -nographic -hda $hda -monitor null -no-reboot
# interact
expect {
-re "&a equals (.*)\n" { set addr $expect_out(1,string) }
timeout { exec pkill -9 qemu; exit 1 }
}
expect {
-re "eip (.*)\n" {
set eip $expect_out(1,string)
set nexteip [format %x [expr $eip + 7]]; # tcl manipulation
}
timeout { exec pkill -9 qemu; exit 1 }
}
expect {
"K> " { send "x $addr\r" }
timeout { exec pkill -9 qemu; exit 1 }
}
expect {
"10" { }
timeout { exec pkill -9 qemu; exit 1 }
}
expect {
"K> " { send "si\r" }
timeout { exec pkill -9 qemu; exit 1 }
}
expect {
"$nexteip" { }
timeout { exec pkill -9 qemu; exit 1 }
}
expect {
"K> " { send "c\r" }
timeout { exec pkill -9 qemu; exit 1 }
}
expect {
"Finally , a equals 20\r" { }
timeout { exec pkill -9 qemu; exit 1 }
}
# send $expect_out(0,string)
exec pkill -9 qemu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment