#!/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