How to debug bazel itself using intellij + bazel plugin?

2,701 views
Skip to first unread message

Evan Torrie

unread,
Jul 2, 2018, 6:13:54 PM7/2/18
to bazel-dev
I have Intellij CE 2018.1 and the Intellij Bazel plugin installed in my environment.
I'm trying to understand how to get source level debugging within Intellij of bazel itself.

Since the //src:bazel target ends up being a C++ program, the Intellij plugin doesn't give me the option of trying to debug that at all (i.e. the "bug" icon is grayed out).

I presume there's either some other build target or some special startup incantation I need to do to get into the source level debugger, but I can't work out what it is.  Does anyone have pointers about what my Run Configuration should look like?

Chloé Calvarin

unread,
Jul 2, 2018, 10:39:33 PM7/2/18
to eto...@gmail.com, baze...@googlegroups.com
If you want to attach a debugger to the Bazel JVM, run the Bazel you're debugging with the startup option --host_jvm_debug. There is more information available at https://bazel.build/contributing.html#debugging-bazel.

Hope that helps,
Chloe

--
You received this message because you are subscribed to the Google Groups "bazel-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-dev+...@googlegroups.com.
To post to this group, send email to baze...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-dev/863dc152-1061-4551-8ba9-09bdd18b1461%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Evan Torrie

unread,
Jul 3, 2018, 6:44:47 PM7/3/18
to bazel-dev
Yes, I can run it with --host_jvm_debug, and then connect to it using jdb -attach localhost:5005.  Interestingly, I don't seem to be able to connect to it with Intellij's IDE debugger using "Run -> Attach to Local Process".  I get just a dialog box with "No processes to attach to", even though I see the bazel server running with "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=5005" in the output of ps.

Moreover, on the Contributing Page, it says 

  "Our IntelliJ plugin has built-in debugging support"

which I took to mean that one would be able to just use Run->Debug... for a bazel run configuration consisting of "run //src:bazel". With the packaging of bazel into an ELF binary and embedded zip package (with A-server.jar) though, that definitely doesn't seem to be the case.

I was wondering if someone can give their standard bazel development Intellij run/debug configurations and process by which they use to debug bazel.

Thanks
E>

Chloé Calvarin

unread,
Jul 4, 2018, 10:24:29 AM7/4/18
to Evan Torrie, baze...@googlegroups.com
I generally run Bazel with --host_jvm_debug from the terminal, and only use the IDE local debugger for debugging unit tests, which don't have the c++ client layer and are pure-java. I believe this is standard practice on the team. 

Reply all
Reply to author
Forward
0 new messages