[ovs-dev] [PATCH v2] Add support for gdbserver in ovs-sandbox script

Guzowski Adrian adrian.guzowski at exatel.pl
Thu May 27 05:08:45 UTC 2021


Using gdbserver instead of plain gdb allows two new use cases:
1. Ability to debug vSwitch running on remote/virtual machines
2. Ability to debug vSwitch with IDE (tested on CLion)

Signed-off-by: Guzowski Adrian <adrian.guzowski at exatel.pl>
---
 tutorial/ovs-sandbox | 51 +++++++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/tutorial/ovs-sandbox b/tutorial/ovs-sandbox
index 09e9773ce..f0d78aea3 100755
--- a/tutorial/ovs-sandbox
+++ b/tutorial/ovs-sandbox
@@ -30,6 +30,8 @@ run_xterm() {
 rungdb() {
     under_gdb=$1
     gdb_run=$2
+    gdbserver_addr=$3
+    shift
     shift
     shift
 
@@ -41,12 +43,19 @@ rungdb() {
         args=`echo $@ |sed s/--detach//g | sed s/--vconsole:off//g`
         xterm_title=$1
 
-        gdb_cmd=""
-        if $gdb_run; then
-            gdb_cmd="-ex run"
+        if [ "$gdbserver_addr" ]; then
+            gdb_cmd="gdbserver"
+            gdb_args="$gdbserver_addr"
+        else
+            gdb_cmd="gdb"
+            if $gdb_run; then
+                gdb_args="-ex run --args"
+            else
+                gdb_args="--args"
+            fi
         fi
 
-        run_xterm $xterm_title gdb $gdb_cmd --args $args
+        run_xterm $xterm_title $gdb_cmd $gdb_args $args
     else
         run $@
     fi
@@ -56,6 +65,7 @@ gdb_vswitchd=false
 gdb_ovsdb=false
 gdb_vswitchd_ex=false
 gdb_ovsdb_ex=false
+gdbserver_addr=
 builddir=
 srcdir=
 schema=
@@ -96,21 +106,23 @@ you built.  Otherwise, if you have an installed Open vSwitch, it uses
 the installed version.
 
 These options force ovs-sandbox to use a particular OVS build:
-  -b, --builddir=DIR   specify Open vSwitch build directory
-  -s, --srcdir=DIR     specify Open vSwitch source directory
+  -b, --builddir=DIR          specify Open vSwitch build directory
+  -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
+  -i, --installed             use installed Open vSwitch
 
 General options:
-  -g, --gdb-vswitchd   run ovs-vswitchd under gdb
-  -d, --gdb-ovsdb      run ovsdb-server under gdb
-  --dummy=ARG          pass --enable-dummy=ARG to vswitchd (default: override)
-  -R, --gdb-run        automatically start running the daemon in gdb
-                       for any daemon set to run under gdb
-  -S, --schema=FILE    use FILE as vswitch.ovsschema
-
+  -g, --gdb-vswitchd          run ovs-vswitchd under gdb
+  -d, --gdb-ovsdb             run ovsdb-server under gdb
+  --dummy=ARG                 pass --enable-dummy=ARG to vswitchd
+                              (default: override)
+  -R, --gdb-run               automatically start running the daemon in gdb
+                              for any daemon set to run under gdb
+  -S, --schema=FILE           use FILE as vswitch.ovsschema
+  -L, --gdbserver-addr=ADDR   run gdbserver instead of gdb
+                              on specified address
 Other options:
-  -h, --help           Print this usage message.
+  -h, --help                  Print this usage message.
 EOF
             exit 0
             ;;
@@ -168,6 +180,9 @@ EOF
             gdb_vswitchd_ex=true
             gdb_ovsdb_ex=true
             ;;
+        --gdbserver-addr*=*)
+            gdbserver_addr=$optarg
+            ;;
         -*)
             echo "unrecognized option $option (use --help for help)" >&2
             exit 1
@@ -271,7 +286,8 @@ trap 'kill `cat "$sandbox"/*.pid`' 0 1 2 3 13 14 15
 touch "$sandbox"/.conf.db.~lock~
 run ovsdb-tool create conf.db "$schema"
 ovsdb_server_args=
-rungdb $gdb_ovsdb $gdb_ovsdb_ex ovsdb-server --detach --no-chdir --pidfile -vconsole:off --log-file
-vsyslog:off \
+rungdb $gdb_ovsdb $gdb_ovsdb_ex "$gdbserver_addr" ovsdb-server --detach \
+       --no-chdir --pidfile -vconsole:off --log-file -vsyslog:off \
        --remote=punix:"$sandbox"/db.sock \
        --remote=db:Open_vSwitch,Open_vSwitch,manager_options \
        $ovsdb_server_args
@@ -292,7 +308,8 @@ fi
 run ovs-vsctl --no-wait -- init
 
 # Start ovs-vswitchd.
-rungdb $gdb_vswitchd $gdb_vswitchd_ex ovs-vswitchd --detach --no-chdir --pidfile -vconsole:off --
log-file -vsyslog:off \
+rungdb $gdb_vswitchd $gdb_vswitchd_ex "$gdbserver_addr" ovs-vswitchd --detach \
+    --no-chdir --pidfile -vconsole:off --log-file -vsyslog:off \
     --enable-dummy=$dummy -vvconn -vnetdev_dummy
 
 cat <<EOF
-- 
2.30.2




More information about the dev mailing list