Skip to content

Commit 842b4ac

Browse files
committed
Improve VS Code debugger support
1 parent bbe3584 commit 842b4ac

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

.vscode/launch.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
"configurations": [
44
{
55
"type": "rdbg",
6-
"name": "Attach with rdbg",
6+
"name": "Debug Homebrew command",
7+
"request": "launch",
8+
"rdbgPath": "${workspaceFolder}/Library/Homebrew/shims/gems/rdbg",
9+
"command": "brew debugger --",
10+
"script": "${fileBasenameNoExtension}",
11+
"askParameters": true
12+
},
13+
{
14+
"type": "rdbg",
15+
"name": "Attach to Homebrew debugger",
716
"request": "attach",
8-
"rdbgPath": "${workspaceFolder}/Library/Homebrew/vendor/portable-ruby/current/lib/ruby/gems/3.3.0/gems/debug-1.9.1/exe/rdbg",
17+
"rdbgPath": "${workspaceFolder}/Library/Homebrew/shims/gems/rdbg",
918
"env": {
1019
"TMPDIR": "/private/tmp/",
1120
}

Library/Homebrew/dev-cmd/debugger.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ class Debugger < AbstractCommand
1111
To pass flags to the command, use `--` to separate them from the `brew` flags.
1212
For example: `brew debugger -- list --formula`.
1313
EOS
14-
switch "-s", "--stop",
15-
description: "Stop at the beginning of the script."
1614
switch "-O", "--open",
1715
description: "Start remote debugging over a Unix socket."
1816

@@ -28,14 +26,17 @@ def run
2826
end
2927

3028
brew_rb = (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path
31-
nonstop = "1" unless args.stop?
3229
debugger_method = if args.open?
3330
"open"
3431
else
3532
"start"
3633
end
3734

38-
with_env RUBY_DEBUG_NONSTOP: nonstop, RUBY_DEBUG_FORK_MODE: "parent" do
35+
env = {}
36+
env[:RUBY_DEBUG_FORK_MODE] = "parent"
37+
env[:RUBY_DEBUG_NONSTOP] = "1" unless ENV["HOMEBREW_RDBG"]
38+
39+
with_env(**env) do
3940
system(*HOMEBREW_RUBY_EXEC_ARGS,
4041
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR),
4142
"-rdebug/#{debugger_method}",

Library/Homebrew/shims/gems/rdbg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
export HOMEBREW_RDBG="1"
4+
5+
HOMEBREW_PORTABLE_RUBY_BIN="$(cd "$(dirname "$0")"/../../ && pwd)/vendor/portable-ruby/current/bin/"
6+
exec "${HOMEBREW_PORTABLE_RUBY_BIN}"rdbg "$@"

bin/brew

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ then
258258
FILTERED_ENV+=("${VAR}=${!VAR}")
259259
done
260260
fi
261+
262+
if [[ -n "${HOMEBREW_RDBG:-}" ]]
263+
then
264+
for VAR in "${!RUBY_DEBUG_@}"
265+
do
266+
# Skip if variable value is empty.
267+
[[ -z "${!VAR:-}" ]] && continue
268+
269+
FILTERED_ENV+=("${VAR}=${!VAR}")
270+
done
271+
fi
272+
261273
unset VAR ENV_VAR_NAMES
262274

263275
exec /usr/bin/env -i "${FILTERED_ENV[@]}" /bin/bash -p "${HOMEBREW_LIBRARY}/Homebrew/brew.sh" "$@"

0 commit comments

Comments
 (0)