summaryrefslogtreecommitdiff
path: root/wrappers
diff options
context:
space:
mode:
authorMika Westerberg <ext-mika.1.westerberg@nokia.com>2008-11-07 13:02:49 +0200
committerLauri Leukkunen <lle@rahina.org>2008-12-07 04:32:46 +0200
commitae06ff19cae24b8f1227b4dd6115f57ce8481554 (patch)
treed3d4d66e7518498b365726c59fcf6151fcfdf252 /wrappers
parent10092ed4daf1da4558f8c5a28ec98743a8c983c3 (diff)
Added support for debugging x86 binaries under emulation mode.
Diffstat (limited to 'wrappers')
-rw-r--r--wrappers/gdb84
1 files changed, 84 insertions, 0 deletions
diff --git a/wrappers/gdb b/wrappers/gdb
new file mode 100644
index 0000000..ef2bd91
--- /dev/null
+++ b/wrappers/gdb
@@ -0,0 +1,84 @@
+#!/bin/sh
+#
+# Copyright (c) 2008 Nokia Corporation.
+# All rights reserved.
+#
+# Licensed under GPL version 2
+
+args="$*"
+prog="$0"
+progbase=`basename $0`
+
+error_not_inside_sb2()
+{
+ echo "SB2: $progbase wrapper: This wrapper can only be used from inside"
+ echo "the scratchbox 2'ed environment"
+ exit 1
+}
+
+if [ -z "$SBOX_SESSION_DIR" ]
+then
+ error_not_inside_sb2
+fi
+
+. $SBOX_SESSION_DIR/sb2-session.conf
+
+if [ -z "$sbox_mapmode" -o -z "$sbox_dir" ]
+then
+ error_not_inside_sb2
+fi
+
+# read-in mode-specific settings
+if [ -f $sbox_dir/share/scratchbox2/modeconf/sb2rc.$sbox_mapmode ]
+then
+ . $sbox_dir/share/scratchbox2/modeconf/sb2rc.$sbox_mapmode "$progbase"
+fi
+
+#
+# Create initialization file for gdb that provides helper
+# macro that is used to stop running process before main()
+# gets called.
+#
+cat > $SBOX_SESSION_DIR/gdbinit << EOF
+def sb2-prepare
+ set breakpoint pending on
+ tbreak sb2_debug_breakpoint_marker
+ set breakpoint pending off
+end
+
+document sb2-prepare
+Prepares target process to being debugged
+
+Run this command before starting the target program.
+Example:
+(sb2-emulate-gdb) sb2-prepare
+(sb2-emulate-gdb) run
+...
+and now gdb stops and you are able to set further breakpoints etc.
+end
+
+set prompt (sb2-$sbox_mapmode-gdb)
+echo \n
+echo ===========================================================\n
+echo Welcome to scratchbox2 enabled gdb!\n\n
+echo Before starting target program you should run command\n
+echo 'sb2-prepare' that sets breakpoint which is used\n
+echo to stop target before its main() gets called. After\n
+echo the breakpoint is hit, you are able to set further
+echo breakpoints and do normal debugging actions.\n
+echo \n
+echo If you are attaching to already running process or\n
+echo examining a core dump, this step is not necessary.\n
+echo ===========================================================\n\n
+EOF
+
+#
+# sb2 script sets SHELL to tools by default but in emulation
+# mode, we don't have access there so we reset SHELL to correct
+# value in case we are in emulation mode.
+#
+if [ "$sbox_mapmode" = "emulate" ]
+then
+ SHELL=/bin/sh
+fi
+exec $sbox_target_root/usr/bin/gdb -command $SBOX_SESSION_DIR/gdbinit $args