Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve VS Code debugger support #18057

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
"configurations": [
{
"type": "rdbg",
"name": "Attach with rdbg",
"name": "Debug Homebrew command",
"request": "launch",
"rdbgPath": "${workspaceFolder}/Library/Homebrew/shims/gems/rdbg",
"command": "brew debugger --",
"script": "${fileBasenameNoExtension}",
"askParameters": true
},
{
"type": "rdbg",
"name": "Attach to Homebrew debugger",
"request": "attach",
"rdbgPath": "${workspaceFolder}/Library/Homebrew/vendor/portable-ruby/current/lib/ruby/gems/3.3.0/gems/debug-1.9.1/exe/rdbg",
"rdbgPath": "${workspaceFolder}/Library/Homebrew/shims/gems/rdbg",
"env": {
"TMPDIR": "/private/tmp/",
}
Expand Down
9 changes: 5 additions & 4 deletions Library/Homebrew/dev-cmd/debugger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
To pass flags to the command, use `--` to separate them from the `brew` flags.
For example: `brew debugger -- list --formula`.
EOS
switch "-s", "--stop",
description: "Stop at the beginning of the script."
switch "-O", "--open",
description: "Start remote debugging over a Unix socket."

Expand All @@ -28,14 +26,17 @@
end

brew_rb = (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path
nonstop = "1" unless args.stop?
debugger_method = if args.open?
"open"
else
"start"
end

with_env RUBY_DEBUG_NONSTOP: nonstop, RUBY_DEBUG_FORK_MODE: "parent" do
env = {}
env[:RUBY_DEBUG_FORK_MODE] = "parent"

Check warning on line 36 in Library/Homebrew/dev-cmd/debugger.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/debugger.rb#L35-L36

Added lines #L35 - L36 were not covered by tests
env[:RUBY_DEBUG_NONSTOP] = "1" unless ENV["HOMEBREW_RDBG"]

with_env(**env) do

Check warning on line 39 in Library/Homebrew/dev-cmd/debugger.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/debugger.rb#L39

Added line #L39 was not covered by tests
system(*HOMEBREW_RUBY_EXEC_ARGS,
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR),
"-rdebug/#{debugger_method}",
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/shims/gems/rdbg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

export HOMEBREW_RDBG="1"

HOMEBREW_PORTABLE_RUBY_BIN="$(cd "$(dirname "$0")"/../../ && pwd)/vendor/portable-ruby/current/bin/"
exec "${HOMEBREW_PORTABLE_RUBY_BIN}"rdbg "$@"
12 changes: 12 additions & 0 deletions bin/brew
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ then
FILTERED_ENV+=("${VAR}=${!VAR}")
done
fi

if [[ -n "${HOMEBREW_RDBG:-}" ]]
then
for VAR in "${!RUBY_DEBUG_@}"
do
# Skip if variable value is empty.
[[ -z "${!VAR:-}" ]] && continue

FILTERED_ENV+=("${VAR}=${!VAR}")
done
fi

unset VAR ENV_VAR_NAMES

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