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
|
|
|
#
|
2017-05-08 11:08:52 +00:00
|
|
|
# Only the NOVA platform supports most of the tested features at this time.
|
2012-02-09 17:37:20 +00:00
|
|
|
#
|
|
|
|
|
2016-04-19 18:00:31 +00:00
|
|
|
if {![have_include "power_on/qemu"] ||
|
2017-05-08 11:08:52 +00:00
|
|
|
!([have_spec nova])} {
|
|
|
|
puts "Run script is only supported for NOVA in Qemu"; exit 0
|
2012-08-10 06:13:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#
|
|
|
|
# Build
|
|
|
|
#
|
|
|
|
|
2017-02-25 22:58:37 +00:00
|
|
|
set build_components {
|
2019-01-03 17:01:49 +00:00
|
|
|
core init timer
|
|
|
|
drivers/uart
|
2011-12-22 15:19:25 +00:00
|
|
|
app/gdb_monitor
|
|
|
|
test/gdb_monitor
|
2022-09-01 11:12:13 +00:00
|
|
|
lib/vfs_pipe
|
2011-12-22 15:19:25 +00:00
|
|
|
}
|
|
|
|
|
2017-02-25 22:58:37 +00:00
|
|
|
lappend build_components "lib/gdbserver_platform-$::env(KERNEL)"
|
|
|
|
|
|
|
|
build $build_components
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
create_boot_directory
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate config
|
|
|
|
#
|
|
|
|
|
|
|
|
set config {
|
|
|
|
<config verbose="yes">
|
|
|
|
<parent-provides>
|
|
|
|
<service name="ROM"/>
|
|
|
|
<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>
|
2017-05-07 20:36:11 +00:00
|
|
|
<default caps="100"/>
|
2011-12-22 15:19:25 +00:00
|
|
|
<start name="timer">
|
2016-05-17 14:13:23 +00:00
|
|
|
<resource name="RAM" quantum="2M"/>
|
2011-12-22 15:19:25 +00:00
|
|
|
<provides> <service name="Timer"/> </provides>
|
|
|
|
</start>
|
2019-05-03 14:23:51 +00:00
|
|
|
<start name="pc_uart_drv">
|
2016-05-17 14:13:23 +00:00
|
|
|
<resource name="RAM" quantum="2M"/>
|
2016-04-19 18:00:31 +00:00
|
|
|
<provides>
|
|
|
|
<service name="Terminal"/>
|
|
|
|
<service name="Uart"/>
|
|
|
|
</provides>
|
2011-12-22 15:19:25 +00:00
|
|
|
<config>
|
2016-11-24 14:28:32 +00:00
|
|
|
<policy label_prefix="gdb_monitor" uart="1"/>
|
2011-12-22 15:19:25 +00:00
|
|
|
</config>
|
|
|
|
</start>
|
2020-08-18 14:51:28 +00:00
|
|
|
<start name="gdb_monitor" caps="1000">
|
2020-02-25 17:00:03 +00:00
|
|
|
<resource name="RAM" quantum="9M"/>
|
2012-04-23 12:44:28 +00:00
|
|
|
<config>
|
2014-04-14 09:57:22 +00:00
|
|
|
<target name="test-gdb_monitor">
|
|
|
|
<config>
|
2017-05-29 14:50:12 +00:00
|
|
|
<vfs> <dir name="dev"> <log/> </dir> </vfs>
|
|
|
|
<libc stdout="/dev/log" stderr="/dev/log"/>
|
2014-04-14 09:57:22 +00:00
|
|
|
</config>
|
|
|
|
</target>
|
2020-02-25 17:00:03 +00:00
|
|
|
<preserve name="RAM" quantum="5M"/>
|
2020-07-23 13:14:54 +00:00
|
|
|
<vfs>
|
2021-05-23 19:33:55 +00:00
|
|
|
<dir name="dev">
|
|
|
|
<log/>
|
|
|
|
<terminal raw="yes"/>
|
|
|
|
<inline name="rtc">2021-01-01 00:01</inline>
|
|
|
|
</dir>
|
2020-07-23 13:14:54 +00:00
|
|
|
<dir name="pipe"> <pipe/> </dir>
|
|
|
|
</vfs>
|
2021-05-23 19:33:55 +00:00
|
|
|
<libc stdout="/dev/log" stderr="/dev/log" pipe="/pipe" rtc="/dev/rtc"/>
|
2012-04-23 12:44:28 +00:00
|
|
|
</config>
|
2011-12-22 15:19:25 +00:00
|
|
|
</start>
|
|
|
|
</config>
|
|
|
|
}
|
|
|
|
|
|
|
|
install_config $config
|
|
|
|
|
|
|
|
#
|
|
|
|
# Boot modules
|
|
|
|
#
|
|
|
|
|
2017-02-25 22:58:37 +00:00
|
|
|
# evaluated by the run tool
|
|
|
|
proc binary_name_gdbserver_platform_lib_so { } {
|
|
|
|
return "gdbserver_platform-$::env(KERNEL).lib.so"
|
|
|
|
}
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
# generic modules
|
|
|
|
set boot_modules {
|
|
|
|
core init timer
|
2020-07-23 13:14:54 +00:00
|
|
|
ld.lib.so libc.lib.so vfs.lib.so libm.lib.so
|
|
|
|
pc_uart_drv posix.lib.so stdcxx.lib.so vfs_pipe.lib.so
|
2017-02-25 22:58:37 +00:00
|
|
|
gdb_monitor gdbserver_platform.lib.so test-gdb_monitor
|
2011-12-22 15:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
build_boot_image $boot_modules
|
|
|
|
|
|
|
|
#
|
|
|
|
# Execute test case
|
|
|
|
#
|
|
|
|
#
|
|
|
|
set local_port 5555
|
|
|
|
|
|
|
|
# qemu config
|
2020-04-06 14:05:54 +00:00
|
|
|
append qemu_args " -display none "
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
# connect comport 0 to stdio
|
2020-04-06 14:05:54 +00:00
|
|
|
append qemu_args " -serial stdio "
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
# connect comport 1 with TCP port $local_port
|
|
|
|
append qemu_args " -serial chardev:uart "
|
2016-05-17 14:13:23 +00:00
|
|
|
append qemu_args " -chardev socket,id=uart,port=$local_port,host=localhost,server,nowait,ipv4 "
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2020-05-15 13:13:19 +00:00
|
|
|
run_genode_until {.*\[init -> gdb_monitor\] 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
|
|
|
|
2017-05-29 14:50:12 +00:00
|
|
|
# GDB loads symbols from 'debug/ld.lib.so'
|
2017-01-04 10:38:39 +00:00
|
|
|
if { [have_spec nova] } {
|
2017-05-29 14:50:12 +00:00
|
|
|
exec ln -sf ld-nova.lib.so debug/ld.lib.so
|
2017-01-04 10:38:39 +00:00
|
|
|
}
|
|
|
|
|
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" }
|
2021-05-23 19:33:55 +00:00
|
|
|
append gdb_cmds {-ex "set style enabled off" }
|
2017-01-04 10:38:39 +00:00
|
|
|
append gdb_cmds [gdb_initial_breakpoint_cmds $gdb_target_binary]
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2019-04-12 16:32:12 +00:00
|
|
|
# run GDB
|
|
|
|
eval spawn [gdb] debug/ld.lib.so -n $gdb_cmds
|
2016-05-17 14:13:23 +00:00
|
|
|
set gdb_id [list $spawn_id $genode_id]
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts ""
|
|
|
|
puts "----- test: breakpoint in 'main()' -----"
|
|
|
|
puts ""
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
run_genode_until {\(gdb\)} 60 $gdb_id
|
2013-10-24 13:02:59 +00:00
|
|
|
|
2017-01-04 10:38:39 +00:00
|
|
|
send "b main\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
|
|
|
send "c\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
if {![regexp {Breakpoint 2, main ()} $output]} {
|
|
|
|
puts stderr "*** Error: Breakpoint in main() did not trigger"
|
|
|
|
exit -1
|
2013-10-24 13:02:59 +00:00
|
|
|
}
|
|
|
|
|
2017-01-04 10:38:39 +00:00
|
|
|
send "delete 2\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts "\n"
|
|
|
|
puts "----- test: breakpoint in shared library -----"
|
|
|
|
puts ""
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
send "b puts\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
|
|
|
send "c\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
if {![regexp {Breakpoint 3, puts ()} $output]} {
|
|
|
|
puts "*** Error: Breakpoint in shared library did not trigger"
|
|
|
|
exit -1
|
|
|
|
}
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts "\n"
|
|
|
|
puts "----- test: stack trace when not in syscall -----"
|
|
|
|
puts ""
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
send "bt\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
if {![regexp {#0 puts} $output] ||
|
|
|
|
![regexp {in func2()} $output] ||
|
|
|
|
![regexp {in func1()} $output] ||
|
|
|
|
![regexp {in main ()} $output]} {
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts stderr "*** Error: Stack trace when not in syscall is not as expected"
|
|
|
|
exit -1
|
2012-02-09 17:37:20 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts "\n"
|
|
|
|
puts "----- test: modification of a variable value -----"
|
|
|
|
puts ""
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
send "print test_var\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
if {![regexp {\$1 = 1} $output]} {
|
|
|
|
puts stderr "*** Error: first 'print test_var' command didn't result in the expected output"
|
2012-02-09 17:37:20 +00:00
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
send "set var test_var=2\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
2012-02-09 17:37:20 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
send "print test_var\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
2013-09-26 09:11:51 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
if {![regexp {\$2 = 2} $output]} {
|
|
|
|
puts stderr "*** Error: second 'print test_var' command didn't result in the expected output"
|
2012-02-09 17:37:20 +00:00
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts "\n"
|
|
|
|
puts "----- test: 'call' command -----"
|
|
|
|
puts ""
|
2013-10-24 13:02:59 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
send "call test_var_func()\n"
|
|
|
|
run_genode_until {\(gdb\)} 60 $gdb_id
|
2013-10-24 13:02:59 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
if {![regexp {\$3 = 3} $output]} {
|
|
|
|
puts stderr "*** Error: 'call' command didn't result in the expected output"
|
2013-10-24 13:02:59 +00:00
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts "\n"
|
|
|
|
puts "----- test: thread info -----"
|
|
|
|
puts ""
|
|
|
|
|
2019-01-21 09:34:56 +00:00
|
|
|
send "b test_thread_start\n"
|
2016-05-17 14:13:23 +00:00
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
|
|
|
|
|
|
|
send "c\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
|
|
|
|
2019-01-21 09:34:56 +00:00
|
|
|
if {![regexp {Breakpoint 4, test_thread_start} $output]} {
|
2016-05-17 14:13:23 +00:00
|
|
|
puts stderr "*** Error: Breakpoint in test thread did not trigger"
|
2012-02-09 17:37:20 +00:00
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
send "info threads\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
|
|
|
|
2021-05-23 19:33:55 +00:00
|
|
|
if {![regexp {\* 4 Thread 1.4 test_thread_start} $output] ||
|
|
|
|
![regexp { 3 Thread 1.3} $output] ||
|
|
|
|
![regexp { 2 Thread 1.2} $output] ||
|
|
|
|
![regexp { 1 Thread 1.1} $output]} {
|
2016-05-17 14:13:23 +00:00
|
|
|
puts stderr "*** Error: Thread info is not as expected"
|
2012-02-09 17:37:20 +00:00
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts "\n"
|
|
|
|
puts "----- test: step into function -----"
|
|
|
|
puts ""
|
|
|
|
|
|
|
|
send "step\n"
|
|
|
|
run_genode_until {\(gdb\)} 30 $gdb_id
|
|
|
|
|
|
|
|
send "thread 2\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
|
|
|
|
2019-01-21 09:34:56 +00:00
|
|
|
if {![regexp {test_thread_step} $output]} {
|
2016-05-17 14:13:23 +00:00
|
|
|
puts stderr "*** Error: Step into function didn't result in the expected output"
|
2012-02-09 17:37:20 +00:00
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts "\n"
|
|
|
|
puts "----- test: catching a segmentation fault -----"
|
|
|
|
puts ""
|
|
|
|
|
|
|
|
send "c\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
|
|
|
|
2019-04-29 14:53:44 +00:00
|
|
|
if {![regexp {Thread 4 received signal SIGSEGV, Segmentation fault.} $output]} {
|
2016-05-17 14:13:23 +00:00
|
|
|
puts stderr "*** Error: Segmentation fault exception was not caught"
|
2012-02-09 17:37:20 +00:00
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
# does not work well on ARM yet
|
|
|
|
if {![have_spec arm]} {
|
2014-03-03 18:45:53 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts "\n"
|
|
|
|
puts "----- test: stack trace when in syscall -----"
|
|
|
|
puts ""
|
|
|
|
|
|
|
|
send "thread 2\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
2014-03-03 18:45:53 +00:00
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
send "bt\n"
|
|
|
|
run_genode_until {\(gdb\)} 20 $gdb_id
|
|
|
|
|
2020-07-06 14:09:44 +00:00
|
|
|
if {![regexp {Genode::Signal_receiver::block_for_signal} $output] ||
|
2019-04-29 14:53:44 +00:00
|
|
|
![regexp {Genode::Entrypoint::_wait_and_dispatch_one_io_signal} $output] ||
|
|
|
|
![regexp {Libc::Kernel::run} $output] } {
|
2016-05-17 14:13:23 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-05-17 14:13:23 +00:00
|
|
|
puts ""
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
# vi: set ft=tcl :
|