Merge from TIZEN 2.3
[platform/core/uifw/e17.git] / xdebug.sh
1 #!/usr/bin/env bash
2
3
4 debugger_default="b"
5 geo_default="800x600+0+0"
6
7
8 echo
9 xserver="Xephyr"
10 if [ `type $xserver &>/dev/null; echo $?` -ne 0 ]; then
11         xserver="Xnest"
12         if [ `type $xserver &>/dev/null; echo $?` -ne 0 ]; then
13                 echo "Please install either Xephyr (recommended) or Xnest!"
14                 exit 1
15         fi
16 fi
17
18
19 for arg in $@; do
20    option=`echo "'$arg'" | cut -d'=' -f1 | tr -d "'"`
21    value=`echo "'$arg'" | cut -d'=' -f2- | tr -d "'"`
22    if [ "$value" == "$option" ]; then
23       value=""
24    fi
25
26    case $option in
27       "--dbg-display")
28          if [ -z "$value" ]; then
29             echo "Missing value for $option= !"
30                         exit 1
31          fi
32                  dbg_display=$value
33          ;;
34           "--dbg-geo")
35          if [ -z "$value" ]; then
36             echo "Missing value for $option= !"
37                         exit 1
38          fi
39                  dbg_geo=$value
40          ;;
41       "--dbg-mode")
42          if [ -z "$value" ]; then
43             echo "Missing value for $option= !"
44                         exit 1
45          fi
46                  debugger=$value
47          ;;
48           "--dbg-ecore-errors")  export ECORE_ERROR_ABORT=1 ;;
49           "--dbg-ecore-noclean") export ECORE_NOCLEAN=1 ;;
50       "--dbg-redraw")        export REDRAW_DEBUG=1 ;;
51           "--help")
52              echo "Usage: $0 [DEBUG-OPTION] ..."
53                  echo "      --dbg-display=<NUMBER>    = set the used display number"
54                  echo "      --dbg-geo=<WxH+X+Y>       = set xserver geometry"
55                  echo "      --dbg-mode=<CHAR>         = b: text debugger with auto backtrace (gdb)"
56                  echo "                                  c: curses debugger (cgdb)"
57                  echo "                                  d: GUI debugger (ddd)"
58                  echo "                                  e: no debugging"
59                  echo "                                  g: text debugger (gdb)"
60                  echo "                                  l: leak check (valgrind)"
61                  echo "                                  m: memory check (valgrind)"
62                  echo "                                  p: memory profiling (memprof)"
63                  echo "                                  r: raster's memory profiling (memprof_raster)"
64                  echo "                                  s: show syscalls (strace)"
65                  echo "                                  v: GUI memory check (valkyrie)"
66                  echo "      --dbg-ecore-errors        = to cause ecore to abort on errors"
67                  echo "      --dbg-ecore-noclean       = to cause ecore to not unload modules"
68                  echo "      --dbg-redraw              = to cause redraw to happen slovly and obviously"
69                  echo "      --help                    = wysiwyg"
70                  echo
71              echo "Usage: $0 [ENLIGHTENMENT-OPTION] ..."
72                  enlightenment --help
73                  exit 0
74              ;;
75       *) enlightenment_args="$enlightenment_args $arg" ;;
76    esac
77 done
78
79
80 if [ -z "$dbg_display" ]; then 
81    if [ -z "$DISPLAY" ]; then
82       echo "Couldn't read your \$DISPLAY env variable, are you running X?"
83           exit 1
84    fi
85
86    dcnt=`echo "$DISPLAY" | tr -d ':' | cut -d '.' -f1`
87    dbg_display=$(($dcnt+1))
88 fi
89 if [ -z "$dbg_geo" ]; then
90         dbg_geo=$geo_default
91 fi
92 if [ -z "$debugger" ]; then
93         debugger=$debugger_default
94 fi
95 case $debugger in
96    "b")
97       tmpfile=`mktemp`
98           if [ -z "$tmpfile" ]; then
99          echo "Can't create tmp file!"
100                  exit 1
101       fi
102       echo -e "run\nbt\nq\ny" > $tmpfile
103       debugcmd="gdb -x $tmpfile --args"
104           ;;
105    "c") debugcmd="cgdb" ;;
106    "d") debugcmd="ddd -display $DISPLAY --args" ;;
107    "e") debugcmd="" ;;
108    "g") debugcmd="gdb --args" ;;
109    "l") debugcmd="valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --log-file=valgrind_log" ;;
110    "m") debugcmd="valgrind --tool=memcheck --log-file=valgrind_log" ;;
111    "p") debugcmd="memprof --display=$DISPLAY" ;;
112    "r") debugcmd="memprof_raster --display=$DISPLAY" ;;
113    "s") debugcmd="strace -F -o strace_log" ;;
114    "v") debugcmd="valkyrie -display $DISPLAY" ;;
115 esac
116
117
118 echo "- DISPLAY: $dbg_display"
119 echo "- XSERVER GEOMETRY: $dbg_geo"
120 echo -n "- DEBUGMODE: "
121 if [ "$debugcmd" ]; then
122         echo "$debugcmd"
123 else
124         echo "NONE"
125 fi
126 if [ "$enlightenment_args" ]; then
127         echo "- ENLIGHTENMENT ARGUMENTS: $enlightenment_args"
128 fi
129 if [ "$ECORE_ERROR_ABORT" ]; then
130         echo "- ECORE ERROR ABORT"
131 fi
132 if [ "$ECORE_NOCLEAN" ]; then
133         echo "- ECORE NOCLEAN"
134 fi
135 if [ "$REDRAW_DEBUG" ]; then
136         echo "- REDRAW DEBUG"
137 fi
138 echo "======================================================"
139 echo
140 sleep 1
141
142
143 case $xserver in
144         "Xephyr")       $xserver :$dbg_display -ac -screen $dbg_geo & ;;
145         "Xnest")        $xserver :$dbg_display -ac -geometry $dbg_geo & ;;
146 esac
147 sleep 2 # Someone reported that it starts E before X has started properly.
148
149 export DISPLAY=":$dbg_display"
150 export E_START="enlightenment_start"
151 $debugcmd enlightenment $enlightenment_args
152
153 if [ "$tmpfile" ]; then
154         rm "$tmpfile"
155 fi
156 killall -TERM $xserver
157 echo