diff --git a/ports/run/gdb_monitor.inc b/ports/run/gdb_monitor.inc new file mode 100644 index 000000000..d73efd056 --- /dev/null +++ b/ports/run/gdb_monitor.inc @@ -0,0 +1,50 @@ +# +# \brief GDB command line arguments for setting a breakpoint in the 'main()' function +# \author Christian Prochaska +# \date 2013-09-04 +# + +proc gdb_main_breakpoint_cmds { target_binary_name } { + + # + # We set a break in the 'main()' function of a dynamically linked + # application by using the following gdb command sequence. It's important that + # the 'main()' breakpoint gets set before the 'sharedlibrary' command is + # executed. Otherwise the breakpoint would get set in ld.lib.so's main() + # function. + # + + set gdb_cmds "" + + # don't ask for y/n when loading a new symbol file + append gdb_cmds {-ex "set interactive-mode off" } + + # load the symbols of ld.lib.so + append gdb_cmds {-ex "symbol-file bin/ld.lib.so" } + + # set a breakpoint in the 'call_main()' function + append gdb_cmds {-ex "b call_main" } + + # continue execution until the breakpoint triggers + append gdb_cmds {-ex "c" } + + # delete the 'call_main()' breakpoint + append gdb_cmds {-ex "delete 1" } + + # load the symbols of the test application + append gdb_cmds "-ex \"symbol-file bin/$target_binary_name\" " + + # set a breakpoint in the application's 'main()' function + append gdb_cmds {-ex "b main" } + + # load the symbols of loaded shared libraries + append gdb_cmds {-ex "sharedlibrary" } + + # continue execution until the breakpoint triggers + append gdb_cmds {-ex "c" } + + # delete the 'main()' breakpoint + append gdb_cmds {-ex "delete 2" } + + return $gdb_cmds +} diff --git a/ports/run/gdb_monitor.run b/ports/run/gdb_monitor.run index f2256f57e..2e58ee41d 100644 --- a/ports/run/gdb_monitor.run +++ b/ports/run/gdb_monitor.run @@ -107,47 +107,15 @@ run_genode_until {.*Remote debugging using /dev/terminal.*} 30 puts "GDB monitor is up, starting GDB" +source ${genode_dir}/ports/run/gdb_monitor.inc + +set gdb_target_binary "test-gdb_monitor" + # sequence of GDB commands to execute at startup set gdb_cmds "" append gdb_cmds {-ex "target remote localhost:$local_port" } -# -# The test breaks into the 'main()' function of the dynamically linked test -# application by using the following gdb command sequence. It's important that -# the 'main()' breakpoint gets set before the 'sharedlibrary' command is -# executed. Otherwise the breakpoint would get set in ld.lib.so's main() -# function. -# - -# don't ask for y/n when loading a new symbol file -append gdb_cmds {-ex "set interactive-mode off" } - -# load the symbols of ld.lib.so -append gdb_cmds {-ex "symbol-file bin/ld.lib.so" } - -# set a breakpoint in the 'call_main()' function -append gdb_cmds {-ex "b call_main" } - -# continue execution until the breakpoint triggers -append gdb_cmds {-ex "c" } - -# delete the 'call_main()' breakpoint -append gdb_cmds {-ex "delete 1" } - -# load the symbols of the test application -append gdb_cmds {-ex "symbol-file bin/test-gdb_monitor" } - -# set a breakpoint in the application's 'main()' function -append gdb_cmds {-ex "b main" } - -# load the symbols of loaded shared libraries -append gdb_cmds {-ex "sharedlibrary" } - -# continue execution until the breakpoint triggers -append gdb_cmds {-ex "c" } - -# delete the 'main()' breakpoint -append gdb_cmds {-ex "delete 2" } +append gdb_cmds [gdb_main_breakpoint_cmds $gdb_target_binary] # # Test commands @@ -179,7 +147,7 @@ append gdb_cmds {-ex "bt" } append gdb_cmds {-ex "q" } # run GDB and redirect stderr to stdio to get the relevant output into the expect buffer -eval spawn [gdb] bin/test-gdb_monitor -batch $gdb_cmds 2&>1 +eval spawn [gdb] bin/$gdb_target_binary -batch $gdb_cmds 2&>1 set timeout 60 expect { diff --git a/ports/run/gdb_monitor_interactive.run b/ports/run/gdb_monitor_interactive.run index d84db0ad3..a8e3d550d 100644 --- a/ports/run/gdb_monitor_interactive.run +++ b/ports/run/gdb_monitor_interactive.run @@ -97,52 +97,20 @@ run_genode_until {.*Remote debugging using /dev/terminal.*} 30 puts "GDB monitor is up, starting GDB in a new terminal" +source ${genode_dir}/ports/run/gdb_monitor.inc + +set gdb_target_binary "test-gdb_monitor" + # sequence of GDB commands to execute at startup set gdb_cmds "" append gdb_cmds "-ex \"target remote localhost:$local_port\" " -# -# The test breaks into the 'main()' function of the dynamically linked test -# application by using the following gdb command sequence. It's important that -# the 'main()' breakpoint gets set before the 'sharedlibrary' command is -# executed. Otherwise the breakpoint would get set in ld.lib.so's main() -# function. -# - -# don't ask for y/n when loading a new symbol file -append gdb_cmds {-ex "set interactive-mode off" } - -# load the symbols of ld.lib.so -append gdb_cmds {-ex "symbol-file bin/ld.lib.so" } - -# set a breakpoint in the 'call_main()' function -append gdb_cmds {-ex "b call_main" } - -# continue execution until the breakpoint triggers -append gdb_cmds {-ex "c" } - -# delete the 'call_main()' breakpoint -append gdb_cmds {-ex "delete 1" } - -# load the symbols of the test application -append gdb_cmds {-ex "symbol-file bin/test-gdb_monitor" } - -# set a breakpoint in the application's 'main()' function -append gdb_cmds {-ex "b main" } - -# load the symbols of loaded shared libraries -append gdb_cmds {-ex "sharedlibrary" } - -# continue execution until the breakpoint triggers -append gdb_cmds {-ex "c" } - -# delete the 'main()' breakpoint -append gdb_cmds {-ex "delete 2" } +append gdb_cmds [gdb_main_breakpoint_cmds $gdb_target_binary] # ask the user for confirmations again append gdb_cmds {-ex "set interactive-mode auto" } -puts "command: [gdb] bin/test-gdb_monitor $gdb_cmds" +puts "command: [gdb] bin/$gdb_target_binary $gdb_cmds" exec [terminal] -e "[gdb] bin/test-gdb_monitor $gdb_cmds" &