title: Debugging Android Native C++: activate breakpoint
body: <p>I am trying to debug a C++ native code on Android device using NDK.</p>
  
  <p>The Android.mk already has the debug flags:</p>
  
  <pre><code>APP_OPTIM:= debug
  LOCAL_CFLAGS    := -DRAPIDXML_NO_EXCEPTIONS
  LOCAL_CFLAGS    += -g
  LOCAL_CFLAGS    += -ggdb
  LOCAL_CFLAGS    += -O1
  </code></pre>
  
  <p>I also tried with the flag -O0 instead of -O1.</p>
  
  <p>And the AndroidManifest.xml has also the debug mode:</p>
  
  <pre><code>     android:debuggable="true"
  </code></pre>
  
  <p>So, here we go... I put some breakpoints in the code to watch it step by step. Went to the terminal and typed:</p>
  
  <pre><code>$ adb shell ps |grep packtpub
  app_57    24084 117   467368 49136 ffffffff 00000000 S com.packtpub.app3D
  </code></pre>
  
  <p>Then run the debug:</p>
  
  <pre><code>$ ndk-gdb --verbose --force
  ...
  Launched gdbserver succesfully.
  Setup network redirection
  ## COMMAND: /home/android-sdks/platform-tools/adb forward tcp:5039 localfilesystem:/data/data/com.packtpub.app3D/debug-socket
  ## COMMAND: /home/android-sdks/platform-tools/adb shell run-as com.packtpub.app3D lib/gdbserver +debug-socket --attach 1822
  ## COMMAND: /home/android-sdks/platform-tools/adb pull /system/bin/app_process ./obj/local/armeabi/app_process
  Attached; pid = 1822
  Listening on sockaddr socket debug-socket
  Pulled app_process from device/emulator.
  ## COMMAND: /home/android-sdks/platform-tools/adb pull /system/lib/libc.so ./obj/local/armeabi/libc.so
  Pulled libc.so from device/emulator.
  </code></pre>
  
  <p>The application starts and run. But no break points show up. Neither the (gdb) prompt appears to allow me to set commands.</p>
  
  <p>I tried both ways: from Eclipse IDE, and from console using the command line. And the same happens.</p>
  
  <p>Any suggestion how to spot what is missing to put the debug on and have the breakpoints working?</p>
  
  <p>All comments and suggestions are highly appreciated.</p>
  
  <hr>
  
  <p>So... I keep fighting to solve why the ndk-debug is not running. Maybe I came across something that can shed a little light on it:</p>
  
  <p>I have also added to Android.mk:</p>
  
  <pre><code>APP_MODULES := callbacks
  APP_PLATFORM := android-14
  </code></pre>
  
  <p>On command line in the terminal:</p>
  
  <pre><code>$ android update project -p . --target android-14
  </code></pre>
  
  <p>It gives the message:</p>
  
  <pre><code>Error: Target id 'android-14' is not valid. Use 'android list targets' to get the target ids.
  </code></pre>
  
  <p>Then we obtain the output when running the list targets:</p>
  
  <pre><code>$ android list targets
  id: 1 or "android-15"
  Name: Android 4.0.3
  Type: Platform
  API level: 15
  ...
  id: 2 or "Google Inc.:Google APIs:15"
  </code></pre>
  
  <p>On the other hand it compiles and builds on command line only if I put 'android-15', but it will not run in the device (a Samsung Nexus), which has the 'android-14'. In the AndroidManifest.xml it was setup as 14, to allow the App to compile, load and run in the device from the Eclipse IDE:</p>
  
  <pre><code>&lt;uses-sdk android:targetSdkVersion="14" android:minSdkVersion="14"&gt;
  </code></pre>
  
  <p>In Eclipse IDE it compiles and runs with no complaints as Android-14. When asked to run ndk-debug on Eclipse IDE, it also doesn't complaint as shown mentioned in my previous post, but neither the (gdb) appears.</p>
  
  <p>However, when I try to run the ndk-debug on command line it complains and shows that it is not attaching the debugger:</p>
  
  <pre><code>$ ndk-gdb --verbose --force
  ...
  Launched gdbserver successfully.
  ## COMMAND: /home/android-sdks/platform-tools/adb shell run-as com.packtpub.app3D lib/gdbserver +debug-socket --attach 7722
  ## COMMAND: /home/android-sdks/platform-tools/adb pull /system/bin/app_process ./obj/local/armeabi/app_process
  Cannot attach to process 7722: Operation not permitted (1)
  Pulled app_process from device/emulator.
  </code></pre>
  
  <p>The ndk-gdb not working has something to do with the target version?</p>
  
  <p>Any suggestions or workaround that might fix it and make possible to have active breakpoint to debug NDK? </p>
  
  <p>Thanks in advance.</p>