summaryrefslogtreecommitdiff
path: root/wrappers/gdb
blob: ef2bd91177cc60980af75f30d8e7611b343bcb13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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