diff mbox

[ovs-dev] ovs-ctl: allow gdb as a wrapper

Message ID 20170612203951.17253-1-aconole@redhat.com
State Changes Requested
Headers show

Commit Message

Aaron Conole June 12, 2017, 8:39 p.m. UTC
It has been useful to attach gdb to the running process.  With this commit
we make it a little easier, as the daemon will have a gdbserver process
attached and listening on a specific port.

Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 utilities/ovs-ctl.in |  2 +-
 utilities/ovs-lib.in | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

Comments

Ben Pfaff June 14, 2017, 9:13 p.m. UTC | #1
On Mon, Jun 12, 2017 at 04:39:51PM -0400, Aaron Conole wrote:
> It has been useful to attach gdb to the running process.  With this commit
> we make it a little easier, as the daemon will have a gdbserver process
> attached and listening on a specific port.
> 
> Signed-off-by: Aaron Conole <aconole@redhat.com>

Will you please document this in ovs-ctl.8?

Thanks,

Ben.
Aaron Conole June 14, 2017, 10:03 p.m. UTC | #2
Ben Pfaff <blp@ovn.org> writes:

> On Mon, Jun 12, 2017 at 04:39:51PM -0400, Aaron Conole wrote:
>> It has been useful to attach gdb to the running process.  With this commit
>> we make it a little easier, as the daemon will have a gdbserver process
>> attached and listening on a specific port.
>> 
>> Signed-off-by: Aaron Conole <aconole@redhat.com>
>
> Will you please document this in ovs-ctl.8?

Whoops.  Sure thing.

> Thanks,
>
> Ben.
diff mbox

Patch

diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
index 575ffa0..a192ead 100755
--- a/utilities/ovs-ctl.in
+++ b/utilities/ovs-ctl.in
@@ -589,7 +589,7 @@  Less important options for "start", "restart" and "force-reload-kmod":
 Debugging options for "start", "restart" and "force-reload-kmod":
   --ovsdb-server-wrapper=WRAPPER
   --ovs-vswitchd-wrapper=WRAPPER
-     run specified daemon under WRAPPER (either 'valgrind' or 'strace')
+     run specified daemon under WRAPPER (either 'valgrind', 'strace', or 'gdb')
 
 File location options:
   --db-file=FILE     database file name (default: $DB_FILE)
diff --git a/utilities/ovs-lib.in b/utilities/ovs-lib.in
index 93085ca..638b118 100644
--- a/utilities/ovs-lib.in
+++ b/utilities/ovs-lib.in
@@ -167,6 +167,7 @@  start_daemon () {
     shift; shift
     daemon=$1
     strace=""
+    gdbserver=""
 
     # drop core files in a sensible place
     install_dir "$DAEMON_CWD"
@@ -208,6 +209,14 @@  start_daemon () {
         glibc)
             set env MALLOC_CHECK_=2 MALLOC_PERTURB_=165 "$@"
             ;;
+        gdb)
+            if (gdbserver --version) > /dev/null 2>&1; then
+                gdbserver="gdbserver --attach :5432"
+            else
+                log_failure_msg \
+                    "gdbserver not installed, running $daemon without it"
+            fi
+            ;;
         '')
             ;;
         *)
@@ -227,6 +236,11 @@  start_daemon () {
         setsid $strace -o "$logdir/$daemon.strace.log" \
             -p `cat $rundir/$daemon.pid` > /dev/null 2>&1 &
     fi
+
+    if test X"$gdbserver" != X; then
+        # gdbserver needs to attach after the fact.
+        setsid $gdbserver `cat $rundir/$daemon.pid` > /dev/null 2>&1 &
+    fi
 }
 
 stop_daemon () {