Gdbserver exits on start and causes hangs - android

I'm trying to debug an ARMv7 Android app .so with gdbserver. I've downloaded the android NDK for Mac and and pushed the gdbserver located at prebuilt/android-arm/gdbserver/gdbserver to the machine. I'm using Nox App Player v3.0 Mac version.
When attaching to the process, it produces this output:
$ adb shell gdbserver :5055 --attach 2289
Attached; pid = 2289
ptrace(regsets_fetch_inferior_registers) PID=4034: Device or resource busy
ptrace(regsets_fetch_inferior_registers) PID=4034: Function not implemented
ptrace(regsets_fetch_inferior_registers) PID=4034: Function not implemented
Warning: ptrace(regsets_store_inferior_registers): Device or resource busy
Warning: ptrace(regsets_store_inferior_registers): Function not implemented
Warning: ptrace(regsets_store_inferior_registers): Function not implemented
writing register 0: Function not implemented
Exiting
The app I tried to attach to then hangs. The rest of the emulator/phone works, and I can use the home and menu buttons to close the app. It's just the app that it tried to attach to that stops working until I restart it. I can attach to other random process numbers, even if it does complain a bit about it. Apps have this problem even if I attach while they are suspended. Checking the /data/data/ folder for the application shows that the .so the running app is using is ARMv7.
I tried using the prebuilt/android-x86/gdbserver/gdbserver version of gdbserver to see what would happen. This version loads the process fine with no hangs, and I can connect to it with the GDB the NDK provides. Of course, this also means I can't load the .so, because the gdbserver version is x86 instead of ARM. Is there any way to fix this?

Maybe you can compile the gdbserver for your target machine.
You can type uname -m for checking platform.

Related

Attach to Android process from Qt Creator

I use Qt Creator to develop an Android dynamic library, i.e. a .so file. This .so file is then used by an Android application, but that is developed in Eclipse.
I need to debug my native code, but since it's a library, I can't start the application from Qt Creator, I must attach to the already running process.
Now, if it were a desktop application, I'd use Debug->Start Debugging->Attach to Running Application, but how do I attach to an Android process, which would be running on the emulator or on a connected phone, which is more like remote-debugging?
I think that I should use Debug->Start Debugging->Attach to Running Debug Server:
However, I'm not sure what the exact steps are - how do I start a debug server for ADB, and which port do I connect to?
So it looks like there may be another way to set up a debugger that can connect properly.
http://lists.qt-project.org/pipermail/qt-creator/2012-June/001017.html
Set a toolchain with this version of gdb, and set your project to use it.
In Tools -> Options -> Debugger -> GDB insert your commands in "Additional
Startup Commands"
...
I use Debug -> Start Debugging -> Attach to Remote. All the fields are
there (solib-absolute-prefix is an alias for sysroot, and "location of
debugging information" is solib-search-path), and the last few
"configurations" are stored, so you can call them back easily. I have
to start gdbserver on the target manually, set a shortcut to open the
'attach to remote' dialog, and it is been working great for me so for.
It's old (June 2012), but it goes into better detail about how the gdbserver is started and the setup for a debugger and attaching to a process in Qt. It also mentions some of the relevant environment variables:
set solib-absolute-prefix $ANDROID_SRC/out/target/product/MYPRODUCT/symbols/
set solib-search-path $ANDROID_SRC/out/target/product/MYPRODUCT/symbols/system/lib/
Hope that helps.
Attaching to a adb logcat is independent of Qt and what Android source you are using. Make sure adb.exe can be found on your path such as: C:\Android\SDK\platform-tools, and you have the adb drivers for the device you are debugging with. Try this one if you are struggling: http://www.koushikdutta.com/post/universal-adb-driver
Command Line ADB commands
This should print out any connected devices that can be found:
adb devices
This clears the current logcat logs:
adb logcat -c
This starts a connection to logcat:
adb logcat
Usually you don't have to worry about which port to connect to, because it is automatically found by adb.
Attaching to logcat over wifi is also do-able.
adb tcpip
adb connect 192.168.XX.XX:5555
Hope that helps.

How to run an app when it does not show under Apps?

I used ant to build my Eclipse project from the command line in a debug configuration. (Eclipse Luna and Android NDK-R10d is broken, so I can't use Eclipse any longer. Confer, Eclipse/ADT plugin cannot locate symbols for r10d NDK).
I then performed an install using adb:
<Project Directory>$ adb install bin/AndroidPrng-debug.apk
When I rummage for the program on the device in Apps, the program is not offered. When I attempt to search for it by name on the device (AndroidPrng and com.example.prng), I'm provided with useless web search results. When I go to Settings → Apps, the app is shown under the Downloaded tab (it shows the name as com.example.prng). It has the familiar Force Stop and Uninstall.
I have DDMS running and waiting to capture LogCat output from the program. But even though the app is on the device, I cannot figure out how to run it.
How do I run and debug the app when it does not show up under Apps?
Assuming that your app do have an Activity from where you can navigate into other parts of your app.
Try using below command:
$ adb shell am start -n com.example.yourpackagename/.YourMainActivity
or $ adb shell am start -n com.package.yourpackagename/com.example.yourpackagename.YourMainActivity
This am start command, is a command-line interface to the ActivityManager.

Not able to attach the ndk-gdb to the android application

I am trying to attach the ndk-gdb to my Android application.
I am using is Android-ndk-r6b and device is Android 2.3,Samsung Galaxy S II.
I followed all the steps in this example Click here for the example
And also I tried with one application, when I am trying to attach gdb with another application but the verbose showing that it is always getting attached to the first application itself
Found package name: <1st attached package name>
I tried to launch the ndk-gdb using this command for the first time:
ndk-gdb --start --force --verbose
I tried to attach to another application with the below command but not able to succeed:
ndk-gdb --launch=com.example.hellogdbserver.HelloGdbServer --force --verbose
I am always getting the below error with first application:
ERROR: Non-debuggable application installed on the target device.Please re-install the debuggable version!
This is complete shell log which i am getting
sh-4.1$ ndk-gdb --verbose --start --force
Android NDK installation path: /cygdrive/c/Android/android-ndk
Using default adb command: /cygdrive/c/Android/android-sdk-windows/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.26
Using final ADB command: '/cygdrive/c/Android/android-sdk-windows/platform-tools/adb'
Using auto-detected project path: /cygdrive/d/EclipseTestWorkspace/hello-gdbserver
Found package name: com.example.hellogdbserver
ABIs targetted by application: armeabi
Device API Level: 10
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi
Found debuggable flag: true
Found device gdbserver: /data/data/com.example.hellogdbserver/lib/gdbserver
Using gdb setup init: /cygdrive/d/EclipseTestWorkspace/hello-gdbserver/libs/armeabi/gdb.setup
Using toolchain prefix: /cygdrive/c/Android/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-
Using app out directory: /cygdrive/d/EclipseTestWorkspace/hello-gdbserver/obj/local/armeabi
ERROR: Could not extract package's data directory. Are you sure that
your installed application is debuggable?
sh-4.1$
Please let me know how can I resolve the above error and also how to attach to new package.
My phone is not rooted. Hope this wont affect the gdb.
This was not helpful as well Link to similar problem. As my phone is new phone and dont have any app, other than the current developing app. (Only packages which come along with the Samsung phone are present. No app is downloaded from the market. )
Thanks & Regards,
SSuman185
Please go through the link Debugging native code in android app using the android ndk gdb
Please first ensure that you are building the debuggable version of the app. The AndroidManifest.xml file should include the android:debuggable="true" tag.
You can also check it by finding the APK file in the bin directory, unpacking it (it's just a renamed ZIP file) and ensuring that lib\armeabi folder contains the gdbserver file.
If both conditions above are met, try installing the package on the device manually:
<android-sdk>\platform-tools\adb.exe install -r <your-package-file.APK>
Please carefully observe the output of adb.exe. If it displays an error, it might explain your problem.
This problem will arise if you try to debug a library project.
ndk-gdb is unable to attach to a project that is not the "main" one.
You have to put your jni code into the starting application project.
make sure you have APP_OPTIM in jni/Application.mk set to debug
According to http://developer.samsung.com/forum/thread/ndk-debugging-with-gdb/77/178834 some Samsung phones are not native debuggable without rooting because run-as is broken
See run-as Package 'a.b.c' is unknown - Galaxy S4 Jellybean or Android 4.3 for my solution

Debugging Android native applications built with vs-android

I am using vs-android for building native C++ Android applications. I would like to debug from the command line by launching gdbserver on the emulator and connecting to that GDB server. Since I'm not using the Android build scripts I don't get the gdbserver delivered by default. So I added gdbserver to the lib folder from where vs-android collects it and pushes it into the APK. The file is now found on the emulator in the lib folder of the application where my SO is also located when I deploy the application with adb install.
I now try to run gdbserver with run-as but I get the error "Cannot attach to process 924: Operation not permitted (1)".
According to this http://ian-ni-lewis.blogspot.com/2011/05/ndk-debugging-without-root-access.html the server should be able to attach to the process when gdbserver is started with run-as.
Any ideas as to what I could still be doing wrong?
adb shell
su -c setenforce 0
it will solve the problem
To figure out if the problem is with run-as or with gdbserver, try using run-as to execute 'ps' instead of gdbserver, and then see if the 'ps' process is listed as having the same userid as the application's process. If not, you have a problem with run-as. If it is the same userid as the app, then the problem is more likely with gdbserver.

gdbserver - command not found

I would like to perform debug operations on the Android open source platform.
I am trying to run "gdbserver :5039 --attach" in my terminal but I keep receiving "command not found".
I have built the Android OS using the "full_crespo-userdebug" configuration, which according to the android docs, should provide me with root access on my Nexus S phone?
How can I set things up so that I can debug?
You can copy it from "$NDK_HOME/prebuild/$PLATFORM/gdbserver/gdbserver"
then use adb to push it to device and make it executable
To debug an android device you first need to run gdbserver on the device.
gdbserver :5039 --attach pid
then in your gingerbread source folder you need to run
source build/envsetup.sh
this will allow you to now run
gdbclient
which should connect to the gdbserver on device

Categories

Resources