问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/32277008/attach-to-android-process-from-qt-creator