c++ - Android NDK app not able to hit any breakpoint -
i using https://www.youtube.com/watch?v=kjsc-lkugm8 tutorial try debug simple ndk app. have done in video except:
- i on os x 10.9.3 instead of windows.
- i don't use
android:debuggable=true
(cause eclipse considers error) in androidmanifest.xml instead have set ndk pathpreferences->android->ndk
, inproject properties -> c/c++ build
uncheckeduse default build command
, set therendk-build ndk_debug=1 app_optim=debug
. - i don't use
x86 emulator
samsung duos s
deviceandroid 4.0.4
but breakpoiin used in video in not being hit in case. trying debug simple ndk test project 4th day. have investigated lots of material:
- android native development kit cookbook
- bunch of forums , tutorials
- videos
but can not hit single damn breakpoint. please if ever.
the following excerpt tutorial wrote our internal android development team. bulk of derived blog: http://mhandroid.wordpress.com/
important notes:
- i use linux (ubuntu 12.04) environment android work.
- i used adt bundle linux, build: v22.2.1-833290 (eclipse ide + extras)
- these steps debugging java activity jni shared object.
- i created test projects tutorial won't posted here, though references projects present in instructions follow. you'll need existing android application project jni shared object being called java code.
project setup
- enable debugging.
open androidmanifest.xml, select application tab, , set debuggable=true. make application debuggable when it's running on device that's running in user mode.
build native sources. terminal, enter project directory , enter:
ndk-build -b
you should see following output:
gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
gdbsetup : libs/armeabi/gdb.setup
compile++ thumb : debuggingtestjni <= com_sample_test_debuggingtestactivity.cpp staticlibrary : libstdc++.a
sharedlibrary : libdebuggingtestjni.so
install : libdebuggingtestjni.so => libs/armeabi/libdebuggingtestjni.soclean project. in eclipse menu strip, select project→clean. perform step anytime change/build native sources. step ensures eclipse rebuild .apk.
native debug setup
create java debug configuration. need create debug configuration stepping java source code.
- in eclipse toolbar, you'll see green bug. click little arrow next bug , select "debug configurations...".
- double-click "android application" in tree structure on left. create template new android application debug configuration.
- in "name:" field, name "debuggingtest java debug" make sure know configuration applies debuggingtest project, , targets java source.
- under "project:", click "browse..." button , select debuggingtest.
- click "apply" save changes.
- click "close".
- in eclipse toolbar, click little arrow next bug , select "organize favorites...".
- click "add..."
- select "debuggingtest java debug" , click "ok".
your new debug configuration has been created , added favorites. can access favorites clicking little arrow next bug in toolbar. "debuggingtest java debug" should @ top of list.
run ndk-gdb.
- in eclipse toolbar, click little arrow next bug , select "debuggingtest java debug". deploy , install debuggingtest.apk connected android device , start debugger.
navigate debuggingtest project directory in terminal , type following:
ndk-gdb
if command succeeds, should see following:
gnu gdb 6.6 copyright (c) 2006 free software foundation, inc. gdb free software, covered gnu general public license, , welcome change and/or distribute copies of under conditions. type "show copying" see conditions. there absolutely no warranty gdb. type "show warranty" details. gdb configured "--host=x86_64-linux-gnu --target=arm-elf-linux". (no debugging symbols found) ...
if forgot start debugging application before step, following:
error: not extract pid of application on device/emulator. sure application started? consider using --start or --launch= if not. if android.mk file malformed or contains $(info) blocks, following: cp: target
./obj/local/armeabi/gdb.setup' not directory /home/dev/ndk/ndk-gdb: 639: cannot create start debuggingtest/jni/android.mk end debuggingtest/jni/android.mk ./obj/local/armeabi/gdb.setup: directory nonexistent /home/dev/ndk/ndk-gdb: 640: cannot create start debuggingtest/jni/android.mk end debuggingtest/jni/android.mk ./obj/local/armeabi/gdb.setup: directory nonexistent start: invalid option: -x try
start --help' more information.if ndk-gdb running, following:
error: debug session running, use --force kill it.
resolve errors before continuing. ndk-gdb must run successfully.
running ndk-gdb not ensure doing right far, creates app_process, gdb.setup , libc.so files in obj/local/armeabi/ sub-directory of our project. files needed in later steps.
stop debugging.
- in terminal, type ctrl+z stop ndk-gdb.
- in eclipse, select run-->terminate.
create c/c++ debug configuration. need create debug configuration stepping c/c++ source code.
- in eclipse, click little arrow next bug , select "debug configurations...".
- double-click "c/c++ application" in tree structure on left. create template new c/c++ application debug configuration.
- in "name:" field, name "debuggingtest c , cpp debug" make sure know configuration applies debuggingtest project, , targets c/c++ source.
- in "main" tab:
- click "browse..." on "c/c++ application:" field. navigate "/home/test/testing/debuggingtest/obj/local/armeabi/app_process" , click "ok".
- click "browse..." on "project:" field.
- select "debuggingtest" , click "ok".
- check "disable auto build" box.
- at bottom of form, you'll see "using gdb (dsf) ... - select other...". press "select other..." button.
- in pop-up, check "use configuration specific settings" box.
- select "standard create process launcher" in list , press "ok".
- in "debugger" tab:
- click combo-box on "debugger:" field , select "gdbserver".
- uncheck "stop on startup at:" box.
- in "main" sub-tab:
- click "browse..." on "gdb debugger:" field.
- navigate "/home/dev/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb" , click "ok". this debugger distributed android ndk.
- in "gdb command file:" field, type "/home/test/testing/debuggingtest/obj/local/armeabi/gdb2.setup". gdb2.setup file not exist yet, we'll create shortly.
- check "use full file path set breakpoints" box.
- in "connection" sub-tab:
- set "type:" tcp
- set "port number:" 5039
- click "apply" save changes.
- click "close"
- in eclipse toolbar, click little arrow next bug , select "organize favorites...".
- click "add..."
- select "debuggingtest c , cpp debug" , click "ok".
your new debug configuration has been created , added favorites. can access favorites clicking little arrow next bug in toolbar. "debuggingtest c , cpp debug" should @ top of list.
create gdb2.setup. eclipse doesn't "target remote :5039" line in gdb setup file because wants enter command internally (that why configured port 5039 in previous step). because gdb.setup file recreated ndk scripts, have copy gdb2.setup , point eclipse gdb2.setup file (which did in previous step).
- in file explorer, navigate "/home/test/testing/debuggingtest/obj/local/armeabi/".
- copy "gdb.setup" file , paste same folder. result should file named "gdb (copy).setup".
- rename "gdb (copy).setup" "gdb2.setup".
- open gdb2.setup double-clicking file.
- replace "set solib-search-path ./obj/local/armeabi" "set solib-search-path /home/test/testing/debuggingtest/obj/local/armeabi".
- replace "file ./obj/local/armeabi/app_process" "file /home/test/testing/debuggingtest/obj/local/armeabi/app_process".
- remove line reads "target remote :5039".
- save , close file.
create ndk-gdb-eclipse. 1 last eclipse housekeeping item. eclipse run gdb binary itself, have remove execution of gdb ndk-gdb. we'll save original content doing copy-paste-rename.
- in file explorer, navigate "/home/dev/ndk".
- copy "ndk-gdb" file , paste same folder. result should file named "ndk-gdb (copy)".
- rename "ndk-gdb (copy)" "ndk-gdb-eclipse".
- open ndk-gdb-eclipse doing right-click-->open other application...
- select text editor list of applications
- in file, locate line reads "$gdbclient -x
native_path $gdbsetup
" (probably @ bottom) , comment out prefixing "#" character. - save , close file.
when debugging native sources within eclipse ide, we'll use ndk-gdb-eclipse instead of ndk-gdb.
debugging/stepping code
step java code!
- put breakpoint in debuggingtestactivity.java file @ line 20 (system.out.println("hello world!")).
- insert breakpoint in main activity before calls native code made. oncreate() best place this.
- start debuggingtest application in debug mode clicking on little arrow next bug , selecting "debuggingtest java debug".
- you'll see pop-up on screen labeled "confirm perspective switch". press "yes" if you'd switch debug perspective. recommend doing so.
- at point, should have hit breakpoint set.
warning: breakpoint hit sits inside of oncreate function. function called after static loadlibrary calls have been made. notice outside of oncreate function there system.loadlibrary("debuggingtestjni") inside of static block. loadlibrary call execute before enter our oncreate function, ensuring our native symbols loaded time hit our initial breakpoint. imperative stopped @ breakpoint before proceeding!
step c/c++ code!
- in terminal, navigate debuggingtest directory , type following command:
ndk-gdb-eclipse <-- remember created file in step 6
- if successful, command should complete without response.
- go eclipse , run c/c++ debugger clicking little arrow next bug , selecting "debuggingtest c , cpp debug"
- note: when this, see dozens of errors in eclipse console, things still seem working...
- switch java perspective.
- click double arrows @ top right of right of eclipse window , select java.
- open debuggingtest/jni/com_sample_test_debuggingtestactivity.cpp
- set breakpoint in first jni function called main activity.
- click run-->resume (f8)
- you'll perspective switch message again, feel free switch debug perspective.
- in terminal, navigate debuggingtest directory , type following command:
you should have hit breakpoint set in native code!
congratulations!!!
at point should able take you've learned , adapt existing projects may have.
Comments
Post a Comment