Skip to content

Commit d33b263

Browse files
committed
ham-gdb: Improve RemedyBG session handling and add the 'gui' command.
1 parent 1e3374c commit d33b263

File tree

1 file changed

+102
-35
lines changed

1 file changed

+102
-35
lines changed

bin/ham-gdb

+102-35
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ fi
99
find_remedybg() {
1010
local path
1111
for path in \
12-
"c:/Utils/Apps/remedybg/remedybg.exe" \
13-
"$WORK/Playground/data/_tools/remedybg/remedybg.exe" \
14-
"$SHARED_WORK/../bin/nt-x64/remedybg.exe"; do
12+
"$HAM_HOME/toolsets/remedybg/nt-x64/remedybg.exe" \
13+
"c:/Utils/Apps/remedybg/remedybg.exe"; do
1514
if [ -f "$path" ]; then
1615
echo "$path"
1716
return 0
@@ -20,13 +19,22 @@ find_remedybg() {
2019
echo ""
2120
}
2221

22+
find_msvc_ide() {
23+
if [ -e "$HAM_HOME/toolsets/msvc_19_x64/msvc-find-ide-dir" ]; then
24+
"$HAM_HOME/toolsets/msvc_19_x64/msvc-find-ide-dir"
25+
else
26+
echo ""
27+
fi
28+
}
29+
2330
usage() {
2431
echo "usage:"
2532
echo " ${0##*/} EXE [ARGS]"
26-
echo " ${0##*/} bring-to-front"
2733
echo " ${0##*/} open-file filename [line-number]"
2834
echo " ${0##*/} add-breakpoint filename line-number"
2935
echo " ${0##*/} remove-breakpoint filename line-number"
36+
echo " ${0##*/} bring-to-front"
37+
echo " ${0##*/} gui"
3038
echo ""
3139
echo "Supported platforms:"
3240
echo " Windows:"
@@ -40,7 +48,7 @@ usage() {
4048
case $HAM_OS in
4149
NT*)
4250
REMEDYBG_PATH=$(find_remedybg)
43-
MSVC_IDE_DIR=$(msvc-find-ide-dir)
51+
MSVC_IDE_DIR=$(find_msvc_ide)
4452
echo "Local environment:"
4553
echo " REMEDYBG_PATH: $REMEDYBG_PATH"
4654
echo " MSVC_IDE_DIR: $MSVC_IDE_DIR"
@@ -71,22 +79,31 @@ command_open_file() {
7179
NT*)
7280
REMEDYBG_PATH=$(find_remedybg)
7381
if [ -n "$REMEDYBG_PATH" ]; then
74-
(set -x ; "$REMEDYBG_PATH" open-file "$FILENAME" $LINE_NUMBER)
82+
(
83+
set -x
84+
# shellcheck disable=SC2086
85+
"$REMEDYBG_PATH" open-file "$FILENAME" $LINE_NUMBER
86+
)
7587
else
76-
IDE_DIR=$(msvc-find-ide-dir)
88+
IDE_DIR=$(find_msvc_ide)
7789
if [ -n "$IDE_DIR" ]; then
7890
if [ -n "$LINE_NUMBER" ]; then
79-
(set -x ; "$IDE_DIR/Common7/IDE/devenv.exe" -Edit "$FILENAME" -Command "GotoLine $LINE_NUMBER")
91+
(
92+
set -x
93+
"$IDE_DIR/devenv.exe" -Edit "$FILENAME" -Command "edit.goto $LINE_NUMBER"
94+
)
8095
else
81-
(set -x ; "$IDE_DIR/Common7/IDE/devenv.exe" -Edit "$FILENAME")
96+
(
97+
set -x
98+
"$IDE_DIR/devenv.exe" -Edit "$FILENAME"
99+
)
82100
fi
83101
else
84102
log_error "Neither RemedyBG nor Visual Studio found"
85103
exit 1
86104
fi
87105
fi
88106
;;
89-
90107
*)
91108
log_error "open-file command not supported on this platform"
92109
exit 1
@@ -99,13 +116,17 @@ command_bring_to_front() {
99116
NT*)
100117
REMEDYBG_PATH=$(find_remedybg)
101118
if [ -n "$REMEDYBG_PATH" ]; then
102-
(set -x ; "$REMEDYBG_PATH" bring-debugger-to-foreground)
119+
(
120+
set -x
121+
"$REMEDYBG_PATH" bring-debugger-to-foreground
122+
)
103123
else
104-
log_warning "bring-to-front not supported for Visual Studio."
124+
log_warning "bring-to-front not supported for Visual Studio"
105125
fi
106126
;;
127+
107128
*)
108-
log_error "bring-to-front command not supported on this platform."
129+
log_error "bring-to-front command not supported on this platform"
109130
exit 1
110131
;;
111132
esac
@@ -124,9 +145,10 @@ command_add_breakpoint() {
124145
NT*)
125146
REMEDYBG_PATH=$(find_remedybg)
126147
if [ -n "$REMEDYBG_PATH" ]; then
127-
(set -x ;
128-
"$REMEDYBG_PATH" add-breakpoint-at-file "$FILENAME" "$LINE_NUMBER"
129-
"$REMEDYBG_PATH" open-file "$FILENAME" "$LINE_NUMBER"
148+
(
149+
set -x
150+
"$REMEDYBG_PATH" add-breakpoint-at-file "$FILENAME" "$LINE_NUMBER"
151+
"$REMEDYBG_PATH" open-file "$FILENAME" "$LINE_NUMBER"
130152
)
131153
else
132154
log_warning "add-breakpoint not supported for Visual Studio"
@@ -153,9 +175,10 @@ command_remove_breakpoint() {
153175
NT*)
154176
REMEDYBG_PATH=$(find_remedybg)
155177
if [ -n "$REMEDYBG_PATH" ]; then
156-
(set -x ;
157-
"$REMEDYBG_PATH" remove-breakpoint-at-file "$FILENAME" "$LINE_NUMBER"
158-
"$REMEDYBG_PATH" open-file "$FILENAME" "$LINE_NUMBER"
178+
(
179+
set -x
180+
"$REMEDYBG_PATH" remove-breakpoint-at-file "$FILENAME" "$LINE_NUMBER"
181+
"$REMEDYBG_PATH" open-file "$FILENAME" "$LINE_NUMBER"
159182
)
160183
else
161184
log_warning "remove-breakpoint not supported for Visual Studio"
@@ -169,6 +192,47 @@ command_remove_breakpoint() {
169192
esac
170193
}
171194

195+
command_gui() {
196+
case $HAM_OS in
197+
NT*)
198+
REMEDYBG_PATH=$(find_remedybg)
199+
if [ -n "$REMEDYBG_PATH" ]; then
200+
(
201+
set -x
202+
"$REMEDYBG_PATH" "$@"
203+
)
204+
else
205+
IDE_DIR=$(find_msvc_ide)
206+
if [ -n "$IDE_DIR" ]; then
207+
(
208+
set -x
209+
"$IDE_DIR/devenv.exe" "$@"
210+
)
211+
else
212+
log_error "Neither RemedyBG nor Visual Studio found"
213+
exit 1
214+
fi
215+
fi
216+
;;
217+
LINUX*)
218+
(
219+
set -x
220+
gdb "$@"
221+
)
222+
;;
223+
OSX*)
224+
(
225+
set -x
226+
lldb "$@"
227+
)
228+
;;
229+
*)
230+
log_error "gui command not supported on '$HAM_OS'."
231+
exit 1
232+
;;
233+
esac
234+
}
235+
172236
########################################################################
173237
## Handle commands
174238
########################################################################
@@ -193,6 +257,11 @@ case "$1" in
193257
command_remove_breakpoint "$@"
194258
exit 0
195259
;;
260+
gui)
261+
shift
262+
command_gui "$@"
263+
exit 0
264+
;;
196265
*)
197266
EXE_PATH="$1"
198267
if [ ! -e "$EXE_PATH" ]; then
@@ -229,41 +298,39 @@ case $HAM_OS in
229298
## Windows: Use RemedyBG if available otherwise try to use devenv.exe
230299
########################################################################
231300
NT*)
232-
if [ -z "$REMEDYBG_PATH" ]; then
233-
REMEDYBG_PATH=$(find_remedybg)
234-
fi
235-
301+
REMEDYBG_PATH=$(find_remedybg)
236302
if [ -n "$REMEDYBG_PATH" ]; then
237303
RDBG_SESSION_FILE="${OUT_DIR}/${OUT_BASENAME}.rdbg"
304+
RDBG_GEN_EXE="$(dirname "$REMEDYBG_PATH")/rdbg_gen.exe"
238305
log_info "REMEDYBG_PATH: $REMEDYBG_PATH"
239306
log_info "RDBG_SESSION_FILE: $RDBG_SESSION_FILE"
240-
mkdir -p "$(dirname "$RDBG_SESSION_FILE")"
241307

242-
if [ ! -e "$EXE_PATH" ]; then
243-
log_error "Can't find the exe at '$EXE_PATH'."
244-
usage
308+
if [ ! -e "$RDBG_SESSION_FILE" ]; then
309+
log_info "Generating the session file."
310+
(
311+
mkdir -p "$(dirname "$RDBG_SESSION_FILE")"
312+
"$RDBG_GEN_EXE" "$RDBG_SESSION_FILE" "$EXE_DIR" "$EXE_PATH" "${EXE_ARGS[@]}"
313+
)
245314
fi
246315

247316
if [ -e "$RDBG_SESSION_FILE" ]; then
248-
log_info "Found the session file so opening that."
317+
log_info "Opening the existing session file."
249318
(
250319
set -x
251-
"$REMEDYBG_PATH" -g -q "$RDBG_SESSION_FILE" &
252-
true
320+
"$REMEDYBG_PATH" -g -q "$RDBG_SESSION_FILE"
253321
)
254322
else
255323
log_info "No session file, opening the exe directly."
256324
(
257325
set -x
258-
"$REMEDYBG_PATH" -g -q "$EXE_PATH" "${EXE_ARGS[@]}" &
259-
true
326+
"$REMEDYBG_PATH" -g -q "$EXE_PATH" "${EXE_ARGS[@]}"
260327
)
261328
fi
262329
else
263330
if [ -z "$MSVC_DEVENV_PATH" ]; then
264-
MSVC_IDE_DIR=$(msvc-find-ide-dir)
331+
MSVC_IDE_DIR=$(find_msvc_ide)
265332
if [ -n "$MSVC_IDE_DIR" ]; then
266-
MSVC_DEVENV_PATH="$MSVC_IDE_DIR/Common7/IDE/devenv.exe"
333+
MSVC_DEVENV_PATH="$MSVC_IDE_DIR/devenv.exe"
267334
else
268335
log_error "Neither RemedyBG nor Visual Studio found"
269336
usage
@@ -279,7 +346,7 @@ case $HAM_OS in
279346
;;
280347

281348
########################################################################
282-
## macOS: Use gdb with a decent setup
349+
## Linux: Use gdb with a decent setup
283350
########################################################################
284351
LINUX*)
285352
GDB_FILE="${OUT_DIR}/${OUT_BASENAME}.gdb"

0 commit comments

Comments
 (0)