I am developing a fully native application in using C++ and pure CMake as the build system - no Android Studio involved at all (proof of concept here)
The code builds, apk is generated and can be installed and run via ADB without issue but I cannot get gdbserver64 to attach to the process for debugging.
More details:
App is built against SDK/NDK API level 30
Attempting to debug on an Android 11 emulator instance without Google Play
I can run adb root just fine
Image already includes gdbserver and gdbserver64, attempting to use those
Developer options and USB debugging enebled in emulator
App has android:debuggable="true" in manifest
But every time I try gdbserver64 :5039 --attach $(pidof my.app.id)
I get /bin/sh: <app_pid>: inaccessible or not found
What am I missing? And no, I cannot just move to Android Studio - this is a cross platform project that needs to be buildable using only CMake.
According to my observation, this may be a bug of prebuilt gdbserver. It treats the parameter after --attach as a program name and tries to start it.
It's not really an answer, but in similar configuration to yours I got same error message and unable to overcome this. For me, switching to lldb helped, see e.g.
Related
When creating a new project using the Android Studio Native C++ template I'm unable to debug the project on any device I own. Logcat reports not much info as to why.
Are there any extra steps I need to take to setup breakpoint debugging?
Could someone try create a new native template using android studio and see if they can get it debugging?
Android Studio was also reporting:
Debugger process finished with exit code 127. A library required by the native debugger might be missing on your system. See idea.log file for more details.
I found this stackoverflow post after a quick google:
Android Studio Debugger process finished with exit code 127
I couldn't find libncurses5 on my current distribution: Fedora, so instead opted to symlink the v6 libraries to v5:
ln -s /usr/lib64/libncurses6.so /usr/lib64/libncurses5.so
After doing this for all libraries listed in the idea.log (one after another) I was able to get debugging working in Android Studio
I would like to know how I can debug an Android app by using lldb.
I mean using lldb from console not over Android Studio.
From what I found out, Android Studio is doing this:
Pushing the app to the device
Starting this app
Pushing lldb-server to the device
Starting lldb-server on the remote device
Forwarding the ports
Connecting to the local port which is forwarded to the device
I would like to achieve the same using lldb from the console.
Let's say I have already lldb-server on the remote device (because Android Studio did this already for me), what do I need to do is to connect to an App using lldb from the console?
Never tried, but maybe this could help:
LLDB remote debugging
Debugging C++ native libraries in Android using command line
Additionally:
ensure that APK's native libraries (lib*.so) are having debug info/symbols. I pull the apk locally, locate .so file, and check the output of binutils nm utility. When you get familiar with your .so files only checking the size of the .so file could be enough.
one can debug by attaching to a running process/application (attach) and in some cases you need to debug application on application start (run).
in some debugging cases phone/emulator requires root access (file manipulations)
if you manage to debug C++ libs within Android Studio - check Debug+Console and Debug+LLDB output tabs to find interesting commands/options/steps
the procedure looks quite complicated and fragile - arm yourself with patience, don't ignore warnings and don't skip steps.
I am trying to understand the working details of the Package Manager API on Android. I'm using Android Studio to debug it. I have built the AOSP code and am running it on an emulator. Android Studio provides a way to attach to Android processes; however, I am not sure which process to connect to to debug the PackageManager. I assumed the name of the process would be com.android.packageinstaller, but it never shows up on the list of debuggable processes, even when I try to install an apk on the side via adb although my print lines in the AOSP code seems to show up (which means the process is running). Could somebody please explain me how I should be going about debugging the Package Manager? Which process should I be connecting to?
Thanks very much!
Try connecting to the system_process. Most of the core services that compose Android all run in that process.
The Package Manager as well as many other critical services are built off of frameworks/base/services/ (see: http://androidxref.com/6.0.1_r10/xref/frameworks/base/services/) into a services.jar artifact which is a library (http://androidxref.com/6.0.1_r10/xref/frameworks/base/services/Android.mk#7) and not an app.
The "app" that runs this code happens to be a custom instantiation of the core Dalvik virtual machine that you'll find in Zygote.java (the "Main" class for the Dalvik VM). See here: http://androidxref.com/6.0.1_r10/xref/frameworks/base/core/java/com/android/internal/os/ZygoteInit.java#514.
When the Zygote process (the root process of all Android Java processes) is started it is named app_process but when started for running the core system services, then it is run with a special command line argument that causes it to call itself system_server.
So if you want to debug the Package Manager code, best is to attach to that process. You might also consider sprinkling log statements into the package manager code in the framework and looking at those as well or instead.
I'm interested in learning about the Android runtime (ART) and I'd like to be able to put a debugger on it so I can step through the code. I have an AOSP build that I've been running on an emulator.
What's the best way to attach and run source? Should I just use gdbserver on the emulator? Are there any IDEs that people use for native debugging?
Looks like you figured this out, but just for completeness, here's a link to some official documentation which basically covers what you said: http://source.android.com/devices/tech/debug/index.html
If you want to debug native code, you're going to need the source, which of course means getting the AOSP. After you've setup the AOSP, do the following:
In your AOSP directory, run "choosecombo". Select "debug" and pick an "eng" build of your choice.
Build the AOSP
Start the emulator (ie: on Linux, "emulator &")
adb shell into the emulator and run "setprop debug.db.uid 32767". This prevents debuggerd from attaching to a process that it thinks has halted and causing problems. See system/core/debuggerd/debuggerd.cpp in the AOSP for more info.
In the same shell that you built the AOSP, run "gdbclient [process name]". This will attach and load the debugging information for the process you are interested in. You can also attach to a pid, but you will end up having to load the symbol information yourself.
Enjoy debugging native Android platform code
I'm supposed to develop an android app using QtCreator in C++. QtCreator is, however, very user unfriendly and permanently confronts me with bugs and errors that I did not cause and do not understand. I'm still in the phase if building plain new project. The error that occurs when I build it is:
The process "C:/Qt/android.5.5.1/5.5/android_armv7/bin/androiddeployqt.exe" exited normally.
Pulling files necessary for debugging.
Package deploy: Running command "C:/Users/username/AppData/Local/Android/android-sdk/platform-tools/adb.exe -s 520592f0406021ce pull /system/bin/sh: readlink: not found D:/projects/build-androidtest-Android_for_armeabi_v7a_GCC_4_9_Qt_5_5_1-Debug/app_process".
Packaging error: Command "C:/Users/username/AppData/Local/Android/android-sdk/platform-tools/adb.exe -s 520592f0406021ce pull /system/bin/sh: readlink: not found D:/projects/build-androidtest-Android_for_armeabi_v7a_GCC_4_9_Qt_5_5_1-Debug/app_process" failed.Exit code: 1
Package deploy: Failed to pull "/system/bin/sh: readlink: not found" to "D:/projects/build-androidtest-Android_for_armeabi_v7a_GCC_4_9_Qt_5_5_1-Debug/app_process".
I have a suspicion that a piece of unix oriented code propagated into Windows version of QtCreator. It's a reported bug marked as fixed, but not in any released version, so I need to get it to work anyway.
Any ideas? I mean, is there actually anyone who uses Qt C++ android librarie in QtCreator on Windows? Because google searches are not very helpful on these topics.
Well it seems this is Qt creator bug to connect and debug the app you can try using qt libraries with visual studio and debug your application with VS.
UPDATE
it's a little bit hard but you can find the full process of doing that in here