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

Launch or attach target using bazel run does not work #371

Closed
JanJamaszyk-FlyNow opened this issue Sep 29, 2020 · 5 comments
Closed

Launch or attach target using bazel run does not work #371

JanJamaszyk-FlyNow opened this issue Sep 29, 2020 · 5 comments
Labels
Not a bug Everything works as intended, not a bug.

Comments

@JanJamaszyk-FlyNow
Copy link

System Specs

  • OS: Linux fb3848ed2f0f 5.4.0-47-generic Set sys modul default encoding to UTF-8 so umlauts etc. can be used in args too #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020 x86_64 GNU/Linux
  • VSCode version: Version: 1.49.2
  • Commit: e5e9e69aed6e1984f7499b7af85b3d05f9a6883a
  • Date: 2020-09-24T16:26:09.944Z
  • Electron: 9.2.1
  • Chrome: 83.0.4103.122
  • Node.js: 12.14.1
  • V8: 8.3.110.13-electron.0
  • OS: Linux x64 5.4.0-47-generic snap
  • Extension version: v1.5.3
  • Toolchain version: clang version 10.0.1
  • Target: x86_64-pc-linux-gnu
  • Thread model: posix
  • InstalledDir: /usr/sbin
  • Build target: x86_64 GNU/Linux
  • Python version:Python 3.8.5

Issue

We are using bazel to build our project and want to use this extension to debug inside the bazel sandbox.
In order to use the bazel sandbox the application needs to be launched using:

bazel run --config=debug //test:test

If we add this command to our launch.json the extension gives the following error:
bazel_launch_error

If we however try to launch the application as a preLaunchTask (run_test_test) the extension can also not find the executable. Even using the ${command:pickProcess} we cannot select the process. I believe the picker is executed before the preLaunchTask ist finished.

Can we add bazel support to launch our application directly using bazel?

launch.json
        {
            "name": "Attach to Test",
            "type": "lldb",
            "request": "attach",
            "preLaunchTask": "run_test_test",
            "sourceMap": {
                "/proc/self/cwd": "${workspaceFolder}",
            },
            "initCommands": [
                "settings set target.disable-aslr false"
            ],
            "program": "${workspaceFolder}/bazel-bin/test/test",
            //"pid": "${command:pickProcess}"
        },
        {
            "name": "Launch Test",
            "type": "lldb",
            "request": "launch",
            "sourceMap": {
                "/proc/self/cwd": "${workspaceFolder}",
            },
            "initCommands": [
                "settings set target.disable-aslr false"
            ],
            "program": "bazel",
            "args": [
                "run",
                "--config=debug",
                "//test:test"
            ],
        },
@vadimcn
Copy link
Owner

vadimcn commented Oct 14, 2020

You've set up launch config to debug bazel itself, not the process it runs. lldb currently does not support debugging of child processes. You will need to locate the actual executable under bazel-bin// and launch it directly.

@vadimcn vadimcn added the Not a bug Everything works as intended, not a bug. label Oct 14, 2020
@JanJamaszyk-FlyNow
Copy link
Author

Thanks Vadim,
this is what we are doing today, unfortunately this does not respect the bazel sandbox.
Especially using things like bazel runfiles:
https://github.com/bazelbuild/bazel/blob/master/tools/cpp/runfiles/runfiles_src.h
becomes impossible. The only clean solution we currently see is "native bazel support" the same way you support rust cargo.
Could you please look into the feasibility of this? We absolutely could support you with providing stripped down minimal examples!
Best,
Jan

@vadimcn
Copy link
Owner

vadimcn commented Oct 15, 2020

Cargo has a mode in which it logs compilation outputs in JSON format, which is parsed by CodeLLDB and used to locate the binary to launch. As far as I know, Bazel does not provide anything like that.

This might help in your case. If you can find a way to inject a custom wrapper script into bazel run, you could use the uri interface to start a debug session. In the worst case, you could put debugger attach into your binary (see the first example).

@vadimcn
Copy link
Owner

vadimcn commented Dec 24, 2020

Specifically, try this:

  • Create codelldb.sh:
    #!/bin/bash
    code --open-url "vscode://vadimcn.vscode-lldb/launch/command?LD_LIBRARY_PATH=$LD_LIBRARY_PATH&$*"
  • chmod +x codelldb.sh
  • bazel run --run_under=codelldb.sh //<package>:<target>

@vadimcn vadimcn closed this as completed Dec 24, 2020
@JanJamaszyk-FlyNow
Copy link
Author

Thanks Vadim,
especially for the sample, I tried that before but got stuck on another related error:
#404
Thank you so much for your help!
Jan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not a bug Everything works as intended, not a bug.
Projects
None yet
Development

No branches or pull requests

2 participants