]> xenbits.xensource.com Git - rumpuser-xen.git/commitdiff
Add -D option to attach gdbsx to domU
authorMartin Lucina <martin@lucina.net>
Thu, 8 Jan 2015 11:25:39 +0000 (12:25 +0100)
committerMartin Lucina <martin@lucina.net>
Thu, 8 Jan 2015 11:25:39 +0000 (12:25 +0100)
Signed-off-by: Martin Lucina <martin@lucina.net>
app-tools/rumprun

index b15b4d0db9a01df76bc6440ab0a2471331416b1f..3579a309d99418f5ffb4b8801ac9925f80441ecd 100755 (executable)
@@ -35,7 +35,7 @@ err() {
 
 usage() {
        cat <<EOM
-usage: rumprun STACK [ -ipd ] [ -N NAME ] [ -M MEM ] [ -b BLKSPEC ] [ -n NETSPEC ] [ -- ] APP [ args ]
+usage: rumprun STACK [ -ipd ] [ -D PORT ] [ -N NAME ] [ -M MEM ] [ -b BLKSPEC ] [ -n NETSPEC ] [ -- ] APP [ args ]
     STACK is the rumprun stack to use. Only "xen" is currently supported
     APP is the rumprun application to start
     args will be passed to the application command line
@@ -48,6 +48,7 @@ usage: rumprun STACK [ -ipd ] [ -N NAME ] [ -M MEM ] [ -b BLKSPEC ] [ -n NETSPEC
     -i attaches to domain console on startup
     -p creates the domain but leaves it paused
     -d destroys the domain on poweroff
+    -D PORT attaches a GDB server on PORT to the domain, implies -p
     
     When run without -i the local domain id is printed to standard output
 EOM
@@ -140,7 +141,8 @@ run_xen() {
        opt_destroy='on_poweroff="preserve"'
        opt_mem=16
        opt_name=
-       while getopts "n:b:pidN:M:" opt; do
+       opt_debug=
+       while getopts "n:b:pidD:N:M:" opt; do
                case "$opt" in
                        # -n: NETSPEC
                        n)
@@ -185,6 +187,14 @@ run_xen() {
                        M)
                                opt_mem=${OPTARG}
                                ;;
+                       # -D PORT: attach gdbsx to domain.
+                       D)
+                               if ! type gdbsx >/dev/null 2>&1; then
+                                       err "'gdbsx' is required for -D, please install it."
+                               fi
+                               opt_debug=${OPTARG}
+                               opt_pause=1
+                               ;;
                        *)
                                usage
                                ;;
@@ -226,6 +236,15 @@ EOM
                xenstore-write ${prefix}/${line}
        done
        rm ${xenstore}
+       # Attach debugger if requested.
+       if [ -n "$opt_debug" ]; then
+               if objdump -f ${app} | grep -q elf64; then
+                       bits=64
+               else
+                       bits=32
+               fi
+               gdbsx -a ${domid} ${bits} ${opt_debug} &
+       fi
        # Go go go!
        [ -z "$opt_pause" ] && xl unpause ${domid}
        if [ -n "$opt_interactive" ]; then