2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# \brief Test for using the GDB monitor
|
|
|
|
# \author Christian Prochaska
|
|
|
|
# \author Norman Feske
|
|
|
|
# \date 2011-05-24
|
|
|
|
#
|
|
|
|
|
2012-02-09 17:37:20 +00:00
|
|
|
#
|
2012-08-10 06:13:37 +00:00
|
|
|
# Only Genode/Fiasco.OC and Genode/NOVA supports all the tested features
|
|
|
|
# at this time
|
2012-02-09 17:37:20 +00:00
|
|
|
#
|
|
|
|
|
2015-01-08 21:09:08 +00:00
|
|
|
if {![have_include "power_on/qemu"] || (![have_spec foc] && ![have_spec nova])} {
|
2013-09-26 09:11:51 +00:00
|
|
|
puts "Run script is only supported for foc or nova in Qemu"; exit 0
|
2012-08-10 06:13:37 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 09:11:51 +00:00
|
|
|
assert_spec 32bit
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# Build
|
|
|
|
#
|
|
|
|
|
|
|
|
build {
|
|
|
|
core init
|
|
|
|
drivers/timer drivers/uart
|
|
|
|
app/gdb_monitor
|
|
|
|
test/gdb_monitor
|
|
|
|
}
|
|
|
|
|
|
|
|
create_boot_directory
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate config
|
|
|
|
#
|
|
|
|
|
|
|
|
set config {
|
|
|
|
<config verbose="yes">
|
|
|
|
<parent-provides>
|
|
|
|
<service name="ROM"/>
|
|
|
|
<service name="RAM"/>
|
|
|
|
<service name="IRQ"/>
|
|
|
|
<service name="IO_MEM"/>
|
|
|
|
<service name="IO_PORT"/>
|
|
|
|
<service name="PD"/>
|
|
|
|
<service name="RM"/>
|
|
|
|
<service name="CPU"/>
|
|
|
|
<service name="LOG"/>
|
|
|
|
</parent-provides>
|
|
|
|
<default-route>
|
|
|
|
<any-service> <parent/> <any-child/> </any-service>
|
|
|
|
</default-route>
|
|
|
|
<start name="timer">
|
2013-03-11 11:36:15 +00:00
|
|
|
<resource name="RAM" quantum="1M"/>
|
2011-12-22 15:19:25 +00:00
|
|
|
<provides> <service name="Timer"/> </provides>
|
|
|
|
</start>
|
|
|
|
<start name="uart_drv">
|
|
|
|
<resource name="RAM" quantum="1M"/>
|
|
|
|
<provides> <service name="Terminal"/> </provides>
|
|
|
|
<config>
|
|
|
|
<policy label="gdb_monitor" uart="1"/>
|
|
|
|
</config>
|
|
|
|
</start>
|
|
|
|
<start name="gdb_monitor">
|
|
|
|
<resource name="RAM" quantum="4M"/>
|
2012-04-23 12:44:28 +00:00
|
|
|
<config>
|
2014-04-14 09:57:22 +00:00
|
|
|
<target name="test-gdb_monitor">
|
|
|
|
<config>
|
|
|
|
<libc stdout="/dev/log" stderr="/dev/log">
|
|
|
|
<vfs> <dir name="dev"> <log/> </dir> </vfs>
|
|
|
|
</libc>
|
|
|
|
</config>
|
|
|
|
</target>
|
2012-11-13 13:38:39 +00:00
|
|
|
<preserve name="RAM" quantum="3M"/>
|
2014-04-14 09:57:22 +00:00
|
|
|
<libc stdout="/dev/log" stderr="/dev/log">
|
|
|
|
<vfs> <dir name="dev"> <log/> </dir> </vfs>
|
|
|
|
</libc>
|
2012-04-23 12:44:28 +00:00
|
|
|
</config>
|
2011-12-22 15:19:25 +00:00
|
|
|
</start>
|
|
|
|
</config>
|
|
|
|
}
|
|
|
|
|
|
|
|
install_config $config
|
|
|
|
|
|
|
|
#
|
|
|
|
# Boot modules
|
|
|
|
#
|
|
|
|
|
|
|
|
# generic modules
|
|
|
|
set boot_modules {
|
|
|
|
core init timer
|
2016-03-06 14:21:23 +00:00
|
|
|
ld.lib.so libc.lib.so libc_pipe.lib.so libc_terminal.lib.so
|
2011-12-22 15:19:25 +00:00
|
|
|
uart_drv
|
|
|
|
gdb_monitor test-gdb_monitor
|
|
|
|
}
|
|
|
|
|
|
|
|
build_boot_image $boot_modules
|
|
|
|
|
|
|
|
#
|
|
|
|
# Execute test case
|
|
|
|
#
|
|
|
|
#
|
|
|
|
set local_port 5555
|
|
|
|
|
|
|
|
# qemu config
|
|
|
|
append qemu_args " -m 128 -nographic "
|
|
|
|
|
|
|
|
# connect comport 0 to stdio
|
|
|
|
append qemu_args " -serial mon:stdio "
|
|
|
|
|
|
|
|
# connect comport 1 with TCP port $local_port
|
|
|
|
append qemu_args " -serial chardev:uart "
|
|
|
|
append qemu_args " -chardev socket,id=uart,port=$local_port,host=localhost,server,nowait "
|
|
|
|
|
|
|
|
run_genode_until {.*Remote debugging using /dev/terminal.*} 30
|
2015-02-06 12:24:28 +00:00
|
|
|
set genode_id [output_spawn_id]
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2012-02-09 17:37:20 +00:00
|
|
|
puts "GDB monitor is up, starting GDB"
|
|
|
|
|
2014-05-07 09:48:19 +00:00
|
|
|
source ${genode_dir}/repos/ports/run/gdb_monitor.inc
|
2013-09-04 10:25:28 +00:00
|
|
|
|
|
|
|
set gdb_target_binary "test-gdb_monitor"
|
|
|
|
|
2012-02-09 17:37:20 +00:00
|
|
|
# sequence of GDB commands to execute at startup
|
|
|
|
set gdb_cmds ""
|
|
|
|
append gdb_cmds {-ex "target remote localhost:$local_port" }
|
|
|
|
|
2013-09-04 10:25:28 +00:00
|
|
|
append gdb_cmds [gdb_main_breakpoint_cmds $gdb_target_binary]
|
2012-02-09 17:37:20 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Test commands
|
|
|
|
#
|
|
|
|
|
|
|
|
# test: breakpoint in shared library
|
|
|
|
append gdb_cmds {-ex "b puts" }
|
|
|
|
append gdb_cmds {-ex "c" }
|
|
|
|
|
|
|
|
# test: stack trace when not in syscall
|
|
|
|
append gdb_cmds {-ex "bt" }
|
|
|
|
|
2013-10-24 13:02:59 +00:00
|
|
|
# test: modify variable
|
|
|
|
append gdb_cmds {-ex "print test_var" }
|
|
|
|
append gdb_cmds {-ex "set var test_var=2" }
|
|
|
|
append gdb_cmds {-ex "print test_var" }
|
|
|
|
|
|
|
|
# test: 'call' command
|
|
|
|
if {![have_spec nova]} {
|
|
|
|
append gdb_cmds {-ex "call test_var_func()" }
|
|
|
|
}
|
|
|
|
|
2012-02-09 17:37:20 +00:00
|
|
|
# test: thread info
|
|
|
|
append gdb_cmds {-ex "b Test_thread::entry()" }
|
|
|
|
append gdb_cmds {-ex "c" }
|
|
|
|
append gdb_cmds {-ex "info threads" }
|
|
|
|
|
|
|
|
# test: single stepping
|
|
|
|
append gdb_cmds {-ex "step" }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2012-02-09 17:37:20 +00:00
|
|
|
# test: catch segmentation fault
|
|
|
|
append gdb_cmds {-ex "c" }
|
|
|
|
|
|
|
|
# test: stack trace when in syscall
|
|
|
|
append gdb_cmds {-ex "thread 1" }
|
|
|
|
append gdb_cmds {-ex "bt" }
|
|
|
|
|
|
|
|
# quit
|
|
|
|
append gdb_cmds {-ex "q" }
|
|
|
|
|
|
|
|
# run GDB and redirect stderr to stdio to get the relevant output into the expect buffer
|
2014-01-16 13:46:24 +00:00
|
|
|
eval spawn [gdb] bin/$gdb_target_binary -n -batch $gdb_cmds 2&>1
|
2015-02-06 12:24:28 +00:00
|
|
|
set gdb_id $spawn_id
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2013-10-24 13:02:59 +00:00
|
|
|
set timeout 120
|
2012-02-09 17:37:20 +00:00
|
|
|
expect {
|
2015-02-06 12:24:28 +00:00
|
|
|
-i [list $genode_id $gdb_id]
|
2012-02-09 17:37:20 +00:00
|
|
|
timeout { puts stderr "Error: Test execution timed out"; exit -2 }
|
|
|
|
}
|
|
|
|
|
|
|
|
set gdb_output $expect_out(buffer)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Evaluate the test results
|
|
|
|
#
|
|
|
|
|
|
|
|
if {![regexp {Breakpoint 2, main ()} $gdb_output]} {
|
|
|
|
puts stderr "Error: Breakpoint in main() did not trigger"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2015-02-06 12:24:28 +00:00
|
|
|
if {![regexp {Breakpoint 3, puts (.*)} $gdb_output]} {
|
2012-02-09 17:37:20 +00:00
|
|
|
puts "Error: Breakpoint in shared library did not trigger"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if {![regexp {#0 puts} $gdb_output] ||
|
2015-05-12 14:25:30 +00:00
|
|
|
![regexp {in func2()} $gdb_output] ||
|
|
|
|
![regexp {in func1()} $gdb_output] ||
|
2012-02-09 17:37:20 +00:00
|
|
|
![regexp {in main ()} $gdb_output]} {
|
2013-09-26 09:11:51 +00:00
|
|
|
|
2012-02-09 17:37:20 +00:00
|
|
|
puts stderr "Error: Stack trace when not in syscall is not as expected"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2013-10-24 13:02:59 +00:00
|
|
|
if {![regexp {\$1 = 1} $gdb_output]} {
|
|
|
|
puts stderr "Error: first 'print test_var' command didn't result in the expected output"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if {![regexp {\$2 = 2} $gdb_output]} {
|
|
|
|
puts stderr "Error: second 'print test_var' command didn't result in the expected output"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if {![have_spec nova]} {
|
|
|
|
if {![regexp {\$3 = 3} $gdb_output]} {
|
|
|
|
puts stderr "Error: 'call' command didn't result in the expected output"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-09 17:37:20 +00:00
|
|
|
if {![regexp {Breakpoint 4, Test_thread::entry()} $gdb_output]} {
|
|
|
|
puts stderr "Error: Breakpoint in test thread did not trigger"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if {![regexp {\* 2 Thread 2 Test_thread::entry} $gdb_output] ||
|
|
|
|
![regexp { 1 Thread 1} $gdb_output]} {
|
|
|
|
puts stderr "Error: Thread info is not as expected"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2015-05-12 14:25:30 +00:00
|
|
|
if {![regexp {38 static Timer::Connection timer} $gdb_output]} {
|
2012-02-09 17:37:20 +00:00
|
|
|
puts stderr "Error: Single stepping didn't result in the expected output"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if {![regexp {Program received signal SIGSEGV, Segmentation fault.} $gdb_output]} {
|
|
|
|
puts stderr "Error: Segmentation fault exception was not catched"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2015-05-12 14:25:30 +00:00
|
|
|
if {![regexp {Genode::Cancelable_lock::lock\(\)} $gdb_output] ||
|
2016-05-04 10:27:17 +00:00
|
|
|
![regexp {Genode::Thread::join\(\)} $gdb_output] ||
|
2014-03-03 18:45:53 +00:00
|
|
|
![regexp {in main \(\)} $gdb_output]} {
|
|
|
|
|
|
|
|
puts stderr "Error: Stack trace when in syscall is not as expected"
|
|
|
|
exit -1
|
|
|
|
|
2012-02-09 17:37:20 +00:00
|
|
|
}
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
# vi: set ft=tcl :
|