SERVER-112407 fix gdb vscode launch config (#43243)

GitOrigin-RevId: 116fbff35363c0fcb93535526e36123053370ae4
This commit is contained in:
Daniel Moody 2025-10-30 19:52:10 -05:00 committed by MongoDB Bot
parent 73f6d82e9e
commit b1e08aa1be
6 changed files with 122 additions and 4 deletions

4
.github/CODEOWNERS vendored
View File

@ -12,6 +12,7 @@ OWNERS.yml @10gen/server-root-ownership @svc-auto-approve-bot
.bazelignore @10gen/devprod-build @svc-auto-approve-bot .bazelignore @10gen/devprod-build @svc-auto-approve-bot
.bazeliskrc @10gen/devprod-build @svc-auto-approve-bot .bazeliskrc @10gen/devprod-build @svc-auto-approve-bot
.bazelversion @10gen/devprod-build @svc-auto-approve-bot .bazelversion @10gen/devprod-build @svc-auto-approve-bot
.vscode_defaults/** @10gen/devprod-build @svc-auto-approve-bot
.clang-format @10gen/server-programmability @svc-auto-approve-bot .clang-format @10gen/server-programmability @svc-auto-approve-bot
.clang-tidy.in @10gen/server-programmability @svc-auto-approve-bot .clang-tidy.in @10gen/server-programmability @svc-auto-approve-bot
**/.clang-tidy @10gen/server-programmability @svc-auto-approve-bot **/.clang-tidy @10gen/server-programmability @svc-auto-approve-bot
@ -43,6 +44,9 @@ WORKSPACE.bazel @10gen/devprod-build @svc-auto-approve-bot
/.github/ALLOWED_UNOWNED_FILES.yml @svc-auto-approve-bot alex.neben@mongodb.com /.github/ALLOWED_UNOWNED_FILES.yml @svc-auto-approve-bot alex.neben@mongodb.com
/.github/workflows @10gen/devprod-correctness @svc-auto-approve-bot /.github/workflows @10gen/devprod-correctness @svc-auto-approve-bot
# The following patterns are parsed from ./.vscode_defaults/OWNERS.yml
/.vscode_defaults/**/* @10gen/devprod-build @svc-auto-approve-bot
# The following patterns are parsed from ./bazel/OWNERS.yml # The following patterns are parsed from ./bazel/OWNERS.yml
/bazel/**/* @10gen/devprod-build @svc-auto-approve-bot /bazel/**/* @10gen/devprod-build @svc-auto-approve-bot
/bazel/repository_rules/profiling_data.bzl @10gen/performance @svc-auto-approve-bot /bazel/repository_rules/profiling_data.bzl @10gen/performance @svc-auto-approve-bot

View File

@ -0,0 +1,5 @@
version: 1.0.0
filters:
- "*":
approvers:
- 10gen/devprod-build

View File

@ -182,7 +182,7 @@
"ignoreFailures": false "ignoreFailures": false
}, },
], ],
"miDebuggerPath": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/gdb/v5/bin/gdb", "miDebuggerPath": "${workspaceFolder}/buildscripts/vscode_bazel_gdb.sh",
}, },
{ {
"name": "attach", "name": "attach",
@ -235,7 +235,7 @@
"ignoreFailures": false "ignoreFailures": false
}, },
], ],
"miDebuggerPath": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/gdb/v5/bin/gdb", "miDebuggerPath": "${workspaceFolder}/buildscripts/vscode_bazel_gdb.sh",
}, },
{ {
"name": "coredump", "name": "coredump",
@ -245,7 +245,7 @@
"program": "${workspaceFolder}/${input:runTargets}", "program": "${workspaceFolder}/${input:runTargets}",
"args": [], "args": [],
"MIMode": "gdb", "MIMode": "gdb",
"miDebuggerPath": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/gdb/v5/bin/gdb", "miDebuggerPath": "${workspaceFolder}/buildscripts/vscode_bazel_gdb.sh",
"preLaunchTask": "_prelaunch_task", "preLaunchTask": "_prelaunch_task",
"setupCommands": [ "setupCommands": [
{ {
@ -309,7 +309,7 @@
"id": "runTargets", "id": "runTargets",
"command": "shellCommand.execute", "command": "shellCommand.execute",
"args": { "args": {
"command": "bazel query 'attr(tags, \"mongo_binary\", //...)' union 'attr(tags, \"mongo_unittest\", //...)' | grep mongo | grep -v \"_with_debug\" | grep -v third_party | sed 's;//;bazel-bin/;g' | sed 's;:;/;g'", "command": "buildscripts/vscode_launch_targets.sh 2> /dev/null",
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"taskId": "runTargets", "taskId": "runTargets",
"rememberPrevious": true, "rememberPrevious": true,

View File

@ -24,6 +24,9 @@ filters:
- .bazelversion: - .bazelversion:
approvers: approvers:
- 10gen/devprod-build - 10gen/devprod-build
- ".vscode_defaults/**":
approvers:
- 10gen/devprod-build
- ".clang-format": - ".clang-format":
approvers: approvers:
- 10gen/server-programmability - 10gen/server-programmability

View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
# Repo root from script location
cd "$(dirname "$0")"/..
# Exec real gdb with all original args
exec bazel run gdb -- "$@"

View File

@ -0,0 +1,98 @@
#!/usr/bin/env bash
set -euo pipefail
# 1) what we want to query
QUERY=${1:-"attr(tags, \"mongo_binary\", //...) union attr(tags, \"mongo_unittest\", //...)"}
# 2) assume VSCode runs this from the repo root
WORKSPACE=$(pwd)
BAZELOUT="${WORKSPACE}/bazel-out/"
# 3) run bazel query in background and give it, say, 2 seconds to finish
OUT_FILE=$(mktemp)
ERR_FILE=$(mktemp)
(bazel query "$QUERY" >"$OUT_FILE" 2>"$ERR_FILE") &
BAZEL_PID=$!
# how long we let it run (in seconds)
TIME_BUDGET=5
SLEEP_SLICE=0.1
elapsed=0
busy=0
while kill -0 "$BAZEL_PID" 2>/dev/null; do
# still running
if (($(echo "$elapsed >= $TIME_BUDGET" | bc))); then
busy=1
break
fi
sleep "$SLEEP_SLICE"
elapsed=$(echo "$elapsed + $SLEEP_SLICE" | bc)
done
if ((busy)); then
# kill the stuck query
kill "$BAZEL_PID" >/dev/null 2>&1 || true
echo "# bazel query did not finish in $TIME_BUDGET seconds (maybe a build is running?)."
rm -f "$OUT_FILE" "$ERR_FILE"
exit 0
fi
# wait for query to exit and get status
wait "$BAZEL_PID"
Q_STATUS=$?
if ((Q_STATUS != 0)); then
echo "# bazel query failed: $(cat "$ERR_FILE")"
rm -f "$OUT_FILE" "$ERR_FILE"
exit 0
fi
# 4) now we have labels in $OUT_FILE
mapfile -t RAW_LABELS <"$OUT_FILE"
rm -f "$OUT_FILE" "$ERR_FILE"
FOUND=()
for label in "${RAW_LABELS[@]}"; do
[[ -z "$label" ]] && continue
[[ "$label" == *"_with_debug"* ]] && continue
[[ "$label" == *"_ci_wrapper"* ]] && continue
[[ "$label" == *"third_party"* ]] && continue
[[ "$label" != //* ]] && continue
rest=${label#//}
if [[ "$rest" == *:* ]]; then
pkg=${rest%%:*}
name=${rest##*:}
else
pkg=$rest
name=${rest##*/}
fi
# ONLY look in real bazel-out
if [[ -d "$BAZELOUT" ]]; then
while IFS= read -r -d '' cfg; do
[[ -d "$cfg/bin" ]] || continue
cand="$cfg/bin/$pkg/$name"
cand_exe="$cand.exe"
if [[ -f "$cand" ]]; then
rel=${cand#"$WORKSPACE/"}
FOUND+=("$rel")
elif [[ -f "$cand_exe" ]]; then
rel=${cand_exe#"$WORKSPACE/"}
FOUND+=("$rel")
fi
done < <(find "$BAZELOUT" -mindepth 1 -maxdepth 1 -type d -print0)
fi
done
if ((${#FOUND[@]} == 0)); then
echo "# no bazel-out artifacts found for query: $QUERY"
exit 0
fi
printf '%s\n' "${FOUND[@]}" | sort -u