It is some times useful to leverage the sandbox facility to experiment and explore the internals of ovs-vswitchd. Since GDB requires console access for user inputs, this patch launch an xterm for GDB, The main terminal continue to run the sub-shell as before. Exiting the sub-shell will also kill the ovs-vswitchd under GDB (but not GDB itself currently)
Signed-off-by: Andy Zhou <az...@nicira.com> ---- I have been making similar changes in my private tree for a while. It may be worth while to upstream it others can benefit as well. Instead of launching xterm, we could probably leave the main console for GDB, and allow user to start another sub-shell in a separate terminal. However, this won't scale to multiple programs, in case one wants to debug both ovs-vswitchd and ovsdb-server. --- tutorial/Tutorial.md | 20 ++++++++++++++++++++ tutorial/ovs-sandbox | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/tutorial/Tutorial.md b/tutorial/Tutorial.md index d6a963b..6c844f1 100644 --- a/tutorial/Tutorial.md +++ b/tutorial/Tutorial.md @@ -104,6 +104,26 @@ The sandbox directory contains log files for the Open vSwitch dameons. You can examine them while you're running in the sandboxed environment or after you exit. +Using GDB +========== +GDB support is not required to go through the tutorial. It is added in case +user also wants to explore the internals of OVS programs. + +Once OVS process is launched by ovs-sandbox, GDB can be used to attach a +running process as usual: 'gdb <program> <process-id>' + +For debugging ovs-vswitchd, it may be necessary to launch the program +under gdb, so one can set break points early or catch early segfaults. This +can be accomplished in the following two ways: +1) use '-g' command line option with ovs-sandbox script. +2) Set a environment variable, do 'export GDB_OVS_VSWITCHD=y' before launching + the ovs-sandbox script. + +No 2 option is most convenient when launching the sandbox with 'make sandbox'. + +Program running under GDB will be opening in its own xterm. For systems +that does not have X windows server running, GDB support is effectively +disabled. Motivation ---------- diff --git a/tutorial/ovs-sandbox b/tutorial/ovs-sandbox index 45bb234..e767d35 100755 --- a/tutorial/ovs-sandbox +++ b/tutorial/ovs-sandbox @@ -16,16 +16,44 @@ set -e -run () { - echo "$@" +run() { (cd "$sandbox" && "$@") || exit 1 } +run_xterm() { + run xterm -e "$@" & +} + +rungdb() { + under_gdb=$1 + shift + under_Xwindows=true + xpid=`pidof X` + if [ $? != 0 ]; then + under_Xwindows=false + fi + # Remove the --detach and to put the process under gdb control. + # Also remove --vconsole:off to allow error message to show up + # on the console. + if $under_gdb && $under_Xwindows; then + args=`echo $@ |sed s/--detach//g | sed s/--vconsole:off//g` + run_xterm gdb --args $args + else + run $@ + fi +} + +gdb_vswitchd=false; builddir= srcdir= schema= installed=false built=false + +if [ "X$GDB_OVS_VSWITCHD" != "X" ]; then + gdb_vswitchd=true +fi + for option; do # This option-parsing mechanism borrowed from a Autoconf-generated # configure script under the following license: @@ -63,6 +91,7 @@ These options force ovs-sandbox to use a particular OVS build: -s, --srcdir=DIR specify Open vSwitch source directory These options force ovs-sandbox to use an installed Open vSwitch: -i, --installed use installed Open vSwitch + -g, --gdb-vswitchd run ovs-vswitchd under gdb -S, --schema=FILE use FILE as vswitch.ovsschema Other options: @@ -98,6 +127,9 @@ EOF prev=schema installed=: ;; + -g|--gdb-v*) + gdb_vswitchd=true + ;; -*) echo "unrecognized option $option (use --help for help)" >&2 exit 1 @@ -204,7 +236,7 @@ run ovsdb-server --detach --no-chdir --pidfile -vconsole:off --log-file \ --remote=punix:"$sandbox"/db.sock # Start ovs-vswitchd. -run ovs-vswitchd --detach --no-chdir --pidfile -vconsole:off --log-file \ +rungdb $gdb_vswitchd ovs-vswitchd --detach --no-chdir --pidfile -vconsole:off --log-file \ --enable-dummy=override -vvconn -vnetdev_dummy cat <<EOF -- 1.9.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev