Open Bug 1506009 Opened Last year Updated Last month

Rust source debugging does not work with Android Studio

Categories

(Core :: Graphics: WebRender, defect, P4)

defect

Tracking

()

People

(Reporter: sotaro, Unassigned)

References

(Blocks 1 open bug)

Details

When I looked into Bug 1505559. I tried to set break point in rust source code, but it did not work. Break point of C++ worked well.

I set up Android Studio with the following url.
https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Simple_Firefox_for_Android_build#Developing_Firefox_for_Android_in_Android_Studio
Blocks: wr-android
Priority: -- → P4
Michael, can you think of any reason this would be?
Flags: needinfo?(mwoerister)
I'm going to forward this question to Tom, who knows the most about GDB and Rust. I could imagine it being some subtle problem with remote debugging?
Flags: needinfo?(mwoerister) → needinfo?(ttromey)
I need more details to know what the problem is.
What version of gdb are you using; what exactly did you try; what were the results?
Flags: needinfo?(ttromey)
Android Studio uses lldb:

lldb version 7.0.0 (https://us3-mirror-partner-android.googlesource.com/a/platform/external/lldb revision 3fcb389d934b423a1c88d0b83590b518f43b0c40)
  clang revision 4a4f14fd51a577b70a4c2464720a31fbf09a7bdf
  llvm revision 4df1b8f01ec06673f219d12d3b527f6a73cbc769

Basically, follow the instructions in the MDN link in comment 0 to set up Android Studio with an Android build, then try to set a breakpoint in rust code. It won't even let you set breakpoints (clicking in the gutter with the line numbers has no effect), whereas it works for C++.

Also note that for C++ stuff to work well in both parent and content process you need to put this in your ~/.lldbinit:

  settings append target.exec-search-paths /home/kats/zspace/gecko-fennec/obj-android-debug/toolkit/library
  settings append target.exec-search-paths /home/kats/zspace/gecko-fennec/obj-android-debug/mozglue/build

(replace paths as needed to patch your local objdir).

Does comment 4 answer your question? If so, is this something you can look at, or redirect to somebody who can? Getting Rust debugging working on Android in some form would really help with the big mobile push that Mozilla is doing this year.

Flags: needinfo?(tom)

Update on this:

Looks like rust debugging works in Android Studio, but is a bit cumbersome.
Currently my workflow is:

  • Start Debugger and wait for lldb to break at initial process launch (Only works if you've setup lldb symbol folders in AS and .lldbinit file in home as documented here.
  • Lookup symbol of function you want to break in using for example: > readelf -Ws obj-aarch64-unknown-linux-android/toolkit/library/build/libxul.so | grep pre_update, using regexp if you need finer grain search
  • In Android studio add symbol breakpoint in lldb debug console: b _symbolnamehere
  • Continue and breakpoint should hit at beginning of function.
  • From there use run to cursor for getting to the line you want to break at.

This is a very rough flow and I'm sure there are more tips/tricks. Debugging using this method often takes way more time than debugging C++ code and is very error-prone.

@Eric Rahm: Is this something your team handles?

Flags: needinfo?(tom) → needinfo?(erahm)

(In reply to Kris Taeleman (:kris/kris) from comment #6)

Update on this:

Looks like rust debugging works in Android Studio, but is a bit cumbersome.
Currently my workflow is:

  • Start Debugger and wait for lldb to break at initial process launch (Only works if you've setup lldb symbol folders in AS and .lldbinit file in home as documented here.
  • Lookup symbol of function you want to break in using for example: > readelf -Ws obj-aarch64-unknown-linux-android/toolkit/library/build/libxul.so | grep pre_update, using regexp if you need finer grain search
  • In Android studio add symbol breakpoint in lldb debug console: b _symbolnamehere
  • Continue and breakpoint should hit at beginning of function.
  • From there use run to cursor for getting to the line you want to break at.

This is a very rough flow and I'm sure there are more tips/tricks. Debugging using this method often takes way more time than debugging C++ code and is very error-prone.

@Eric Rahm: Is this something your team handles?

We might be able to help out with low level problems with rust lldb integration (really this was Tom's area, but he is no longer an active contributor). I'd like to determine if this is an Android Studio UI issue or lower level. How well does using the lldb command line directly work for you?

Also note: rust itself ships some pretty printers that you might want to setup.

Flags: needinfo?(erahm) → needinfo?(ktaeleman)

I'm pretty sure this is an Android Studio UI issue. I've seen some forum comments that Jetbrains has rust debugging UI support in CLion, but they have not implemented it in Android Studio (See https://github.com/intellij-rust/intellij-rust/issues/3399).

I'm very new to lldb debugging, so not sure how well it works, I make do, but line breakpoints are probably the biggest gap.

If Android Studio Rust debugging UI is not possible (due to being out of our control), maybe the easier path is to create a gdb debug workflow for android with ./mach that wraps all of the adb commands required to start? That would allow us to easily hook up other visual debuggers like VS Code.

Thanks for the pretty-printer info, I did not know that!

Flags: needinfo?(ktaeleman) → needinfo?(erahm)

Okay, so Android Studio is out of our realm, but you could attempt to file a bug for better rust support.

From the command-line I think what you're looking for is mach run --debug. I'm not 100% sure that still works for Android, but the GeckoView folks might be able to give your more guidance.

Flags: needinfo?(erahm)
You need to log in before you can comment on or make changes to this bug.