question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CLion Fails to Debug `cc_binary` target on macOS

See original GitHub issue

The Problem

I’ve written a hello world cc_binary target, but my attempts to debug it from within CLion fail.

I’ve created a repository, dwtj/clwb-bugs-example, to demonstrate the problem. It includes analogous CMake and Bazel builds of this program.

When I use CLion+CMake, I can debug hello_world just fine, but when I try to debug it with CLion+Bazel, I get a red popup error. The image below shows these two projects side-by-side:

cmake_vs_bazel-debugger_executable_not_specified

The red popup error says:

Error running ‘Bazel run :hello_world’: Debugger executable not specified Configure

Here, “Configure” is a link to CLion’s “Preferences” > “Build, Execution, Deployment” > “Toolchains”. Here’s what that looks like for me:

clion_toolchains_default

There are three choices in the “Debugger” drop-down menu:

  • Bundled LLDB
  • Bundled GDB
  • Custom GDB Executable

Note that there doesn’t seem to be a “Custom LLDB” option. For varying reasons, all of these options fail in my CLion+Bazel project.

Bundled LLDB

As described above, “Bundled LLDB” seems to work fine in CLion+CMake, but it fails with the red popup error in CLion+Bazel.

Bundled GDB

When I chose this option, I get “a file format not recognized error.” This happens for both CLion+CMake and CLion+Bazel.

I guess this makes sense, since my Clang/LLVM toolchain is building the program in either case, and evidently GDB won’t work on a Clang-built executable. Here’s the image:

cmake_vs_bazel-debugger_bundled_gdb

Custom GDB Executable:

I don’t have GCC/GDB installed on my system, so I don’t have a “Custom GDB Executable” to select.

However, if I try to use /usr/bin/lldb as a Custom GDB Executable, I get an error: lldb: unrecognized option '-interpreter=mi2'. As you might expect, this happens for both CLion+CMake and CLion+Bazel. Here’s the image:

cmake_vs_bazel-debugger_custom_gdb

My Testing Environment

  • macOS 10.14.2 (Mojave)
  • CLion v2018.2.7 (Though CLion v2018.3.0+ are more recent, they don’t seem to be compatible with the latest versions of the plugin.)
  • Two versions of the plugin, https://github.com/bazelbuild/intellij:
    • v2018.12.03.0.2 (latest pre-built release, retrieved within CLion)
    • 0f45ef4 (built from source)
  • File System: APFS (Case-sensitive, Encrypted)
$ xcodebuild -version
Xcode 10.1
Build version 10B61
$ c++ --version
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ bazel version
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
INFO: Invocation ID: d1b8eba4-dc65-4103-9351-c84a51b0c384
Build label: 0.21.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Dec 19 12:57:09 2018 (1545224229)
Build timestamp: 1545224229
Build timestamp as int: 1545224229

Questions

  • Is it possible that my Clang/LLVM/LLDB toolchain just isn’t yet supported by the plugin?
  • If that is the case, how can I work around this?
  • Do I need to instead use a GCC/GDB toolchain?
  • If so, how should I configure my Bazel workspace, a cc_binary target, and a cc_library target to use another toolchain?
  • Is this related to bazelbuild/bazel#6327? When I use CLI lldb on my hello_world project, I see the same kind of thing in that issue. Might switching to a GCC/GDB toolchain at least let me use CLI gdb on my Bazel cc_binary targets?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:25

github_iconTop GitHub Comments

2reactions
steevecommented, Jun 4, 2019

@chaoren Happy to report that it’s working!

Attaching the build from the PR for other to use until it’s released.

clwb_bazel.zip

1reaction
CaichaoGitHubcommented, Sep 29, 2020

@dwtj could you debug on macos with clion ?

i built your project < example > successfully and i could run it directly , but i can’t debug it clion just stuck on debug state and disable my breakpoints,

my environment: xcode : 12.0 clion: v2019.3.6 bazel plugin : v2020.07.13 bazel : release 3.5.0

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

CLion Debug - Couldn't create target
I am currently running the latest version of CLion on MacOS 10.15 Beta (19A512f), with the standard debug CMake configuration.
Read more >
How to enable debugging for CLion - Stack Overflow
I'm using out of the box CLion installation on my Apple MacBook, creating new C++ project, selecting proper build configuration, ...
Read more >
Clion Debug: Lldb Attach To A Process, Breakpoint Is Grey ...
built on May 6 2019 macOS 10.14.4 Build label: 0.26.0homebrew Build target: Bazel build is failing due to ln error ln: failed to...
Read more >
Debugging fails with "Error 1" if hardened runtime is enabled
I encountered this error too running XCode 10.2.1 on macOS 10.14.5. In my case, this didn't have to do with Hardened Runtime, but...
Read more >
CLion IDE setup - Drake
The Bazel plugin for CLion does not support macOS, ... To run a specific target in the debugger, create a configuration as above,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found