0

I'm using bazel 7.4.1-homebrew on MacOS 15.1.1 within VS Code. The issue I'm having, is that I want to debug a target with lldb. I have setup my launch.json like this:

    {
      "name": "Bazel debug with lldb (MacOS)",
      "type": "cppdbg",
      "request": "launch",
      "targetArchitecture": "arm64",
      "program": "${workspaceFolder}/bazel-bin/${relativeFileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "preLaunchTask": "Build current Bazel file (debug)",
      "stopAtEntry": true,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "lldb",
      "sourceFileMap": {
        ".": "${workspaceFolder}"
      }

I have already disabled sandboxing since that generates ever changing paths with the different sandboxes.

Now my issue is that the paths I'm getting are not consistent: The correct relative symlink path to the binary is: bazel-bin/src/main/main

If that path is being resolved, the path is: /private/var/tmp/_bazel_username/a400ea441e3cbaea85fa60d80a42ac3a/execroot/_main/bazel-out/darwin_arm64-dbg/bin/src/main

If I print the path of the binary at runtime it prints: /Users/username/repos/cpp_udemy2/bazel-bin/src/main/main

The debug symbol queried from lldb - this path is existing and correct. /private/var/tmp/_bazel_username/a400ea441e3cbaea85fa60d80a42ac3a/execroot/_main/src/main/main.cc

Now the confusion is, that VS Code is expecting source code being at this path. Note the missing /private in front of the path. /var/tmp/_bazel_username/a400ea441e3cbaea85fa60d80a42ac3a/execroot/_main/src/main/main.cc Even more confusing to me, is that this path is existing.

Why are there two different paths to debug symbols? One in /private/var/tmp/... and one in /var/tmp/...?

Is there any way to reliably resolve the symlink to the bazel-bin directory on launch, so that the path of the debug symbol is aligned with the source file I'm currently working on?

More information just in case:

.bazelrc

build --action_env=BAZEL_CXXOPTS="-std=c++20"

build --copt=-fdiagnostics-color=always
run --copt=-fdiagnostics-color=always

build --strip=never
build --spawn_strategy=standalone
build --sandbox_debug
build --features=oso_prefix_is_pwd

test --test_output=streamed

tasks.json

    {
      "label": "Build current Bazel file (debug)",
      "type": "shell",
      "command": "bazel",
      "args": [
        "build",
        "-c",
        "dbg",
        "//${relativeFileDirname}:${fileBasenameNoExtension}"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "presentation": {
        "reveal": "always",
        "panel": "shared"
      },
      "problemMatcher": []
    }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.