-
Notifications
You must be signed in to change notification settings - Fork 211
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
Updated debug instructions #882
Conversation
@oliviernotteghem I believe you originally added these instructions, mind taking a look? |
7. Same for the output, you might want to edit output paths to specify writable path location, to avoid 'Permission denied' error when rule is creating output(s). | ||
8. When you get command to succeed, add `--debug=5005` to command line to have action spwan debugger, ex: `bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/io_bazel_rules_kotlin/src/main/kotlin/build --debug=5005 '--flagfile=bazel-out/darwin_arm64-fastbuild/bin/lib/mylib/main_kt-kt.jar-0.params'`. Note: if command invokes `java` toolchain directly, use `-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005` instead. | ||
9. You should see in output that action is waiting for debugger. Use a default `Remote JVM Debug` configuration in Android Studio, set breakpoint in kotlin action java/kt code, and attach debugger. Breakpoints should be hit. | ||
5. Copy the command line, ex : `bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/io_bazel_rules_kotlin/src/main/kotlin/build '--flagfile=bazel-out/darwin_arm64-fastbuild/bin/lib/mylib/main_kt-kt.jar-0.params'` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW you don't have to do this, you can add JVM args directly using bazel flags. Here is an example of a flag to add this to the bazel worker directly, you'll probably want to couple this with flags to limit the number of workers. I've used similar flags for profiling with success.
--worker_extra_flag='KotlinCompile=--wrapper_script_flag=--jvm_flags=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rockwotj : Your approach would be much simpler! Do you mind checking the worker extra flag as it doesn't work for me?
./bazelw build //experimental/sample/simple/ktlib4:src_main --worker_extra_flag='KotlinCompile=--wrapper_script_flag=--jvm_flags=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005'
ERROR: /Users/oliviern/Uber/android/experimental/sample/simple/ktlib4/BUILD.bazel:3:20: KotlinCompile //experimental/sample/simple/ktlib4:src_main { kt: 2, java: 0, srcjars: 0 } for darwin_arm64 failed: Worker process returned an unparseable WorkResponse!
Did you try to print something to stdout? Workers aren't allowed to do this, as it breaks the protocol between Bazel and the worker process.
---8<---8<--- Start of response ---8<---8<---
Listening for transport dt_socket at address: 5005
---8<---8<--- End of response ---8<---8<---
---8<---8<--- Exception details ---8<---8<---
com.google.protobuf.InvalidProtocolBufferException$InvalidWireTypeException: Protocol message tag had invalid wire type.
at com.google.protobuf.InvalidProtocolBufferException.invalidWireType(InvalidProtocolBufferException.java:134)
at com.google.protobuf.UnknownFieldSet$Builder.mergeFieldFrom(UnknownFieldSet.java:527)
at com.google.protobuf.GeneratedMessageV3.parseUnknownField(GeneratedMessageV3.java:320)
at com.google.devtools.build.lib.worker.WorkerProtocol$WorkResponse.<init>(WorkerProtocol.java:2637)
at com.google.devtools.build.lib.worker.WorkerProtocol$WorkResponse$1.parsePartialFrom(WorkerProtocol.java:3405)
at com.google.devtools.build.lib.worker.WorkerProtocol$WorkResponse$1.parsePartialFrom(WorkerProtocol.java:3399)
Thanks @pettermahlen. Changes look good to me. This is indeed a better/simpler workflow. Verified it worked for me. |
README.md
Outdated
8. When you get command to succeed, add `--debug=5005` to command line to have action spwan debugger, ex: `bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/io_bazel_rules_kotlin/src/main/kotlin/build --debug=5005 '--flagfile=bazel-out/darwin_arm64-fastbuild/bin/lib/mylib/main_kt-kt.jar-0.params'`. Note: if command invokes `java` toolchain directly, use `-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005` instead. | ||
9. You should see in output that action is waiting for debugger. Use a default `Remote JVM Debug` configuration in Android Studio, set breakpoint in kotlin action java/kt code, and attach debugger. Breakpoints should be hit. | ||
5. Copy the command line, ex : `bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/io_bazel_rules_kotlin/src/main/kotlin/build '--flagfile=bazel-out/darwin_arm64-fastbuild/bin/lib/mylib/main_kt-kt.jar-0.params'` | ||
6. Change directory into the [execRoot](https://bazel.build/remote/output-directories#layout-diagram), normally `bazel-MYPROJECT`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit : can you please mention that one can quickly lookup the execroot via './bazelw info | grep execution_root'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done; I don't have a ./bazelw
, so I just mentioned plain bazel
.
Could this perhaps be merged? While I'm pretty sure there are better ways to support debugging, I'm also pretty sure that this represents an improvement over the current status. :) |
@pettermahlen merged! |
Fixes #881