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

Guzowski Adrian adrian.guzowski at exatel.pl
Tue May 4 06:23:28 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: Adrian Guzowski <adrian.guzowski at exatel.pl>
---
 tutorial/ovs-sandbox | 47 ++++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/tutorial/ovs-sandbox b/tutorial/ovs-sandbox
index 09e9773ce..f25917b2b 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,21 @@ 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 +178,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 +284,7 @@ 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 +305,7 @@ 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



Spółka wpisana do rejestru przedsiębiorców w Sądzie Rejonowym dla m. st. Warszawy, XIII Wydział Gospodarczy, pod numerem KRS: 0000044577, kapitał zakładowy: 576 854 559 PLN, kapitał opłacony w całości, NIP: 527-010-45-68, BDO: 000250055, EXATEL SA, ul. Perkuna 47, 04-164 Warszawa.

Niniejsza wiadomość jest własnością EXATEL SA i może zawierać informacje poufne i/lub prawnie chronione. Jeśli nie są Państwo właściwym adresatem (lub otrzymali Państwo tę wiadomość na skutek pomyłki), prosimy o tym fakcie niezwłocznie poinformować nadawcę i usunąć otrzymaną wiadomość. Każde nieautoryzowane kopiowanie, ujawnianie lub rozpowszechnianie załączonej informacji jest zabronione.

This e-mail is a property of EXATEL SA and may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail by mistake) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


More information about the dev mailing list