title: gdb Input/Output error remote debugging to Android
body: <p>I'm trying to debug an android app that call native code to do some GL rendering.  The native code is existing code that I'm trying to port (and that I don't really know that well).  I've got the existing code compiling, linking, and installing correctly, and I've got some native functions that call in to that code that are being correctly called from my Java code.  I'm getting a segfault that I'm trying to track down, and having some problems getting gdb to set a breakpoint in the program.  This is on windows XP with Cygwin - and I should probably mention I'm still learning gdb.</p>
  
  <p>I started with the directions at <a href="http://honeypod.blogspot.com/2008/01/debug-native-application-for-android.html" rel="nofollow noreferrer">http://honeypod.blogspot.com/2008/01/debug-native-application-for-android.html</a>; here's what I'm currently doing.</p>
  
  <p>Start the app in the emulator.</p>
  
  <p>In a cmd prompt:</p>
  
  <pre><code>&gt; adb forward tcp:1234 tcp:1234
  &gt; adb shell
  # gdbserver localhost:1234 --attach 2120
  gdbserver localhost:1234 --attach 2120
  Attached; pid = 2120
  Listening on port 1234
  </code></pre>
  
  <p>In a cygwin shell:</p>
  
  <pre><code>arm-eabi-4.2.1/bin/arm-eabi-gdb.exe out/apps/app-android/libDM.so
  GNU gdb 6.6
  Copyright (C) 2006 Free Software Foundation, Inc.
  GDB is free software, covered by the GNU General Public License, and you are
  welcome to change it and/or distribute copies of it under certain conditions.
  Type "show copying" to see the conditions.
  There is absolutely no warranty for GDB.  Type "show warranty" for details.
  This GDB was configured as "--host=i686-pc-cygwin --target=arm-elf-linux"...
  (gdb) target remote localhost:1234
  Remote debugging using localhost:1234
  warning: shared library handler failed to enable breakpoint
  0xafe0da04 in AppRefCounted::unref () at ../../stlport/stl/_iosfwd.h:39
  39      class basic_ostream;
  Current language:  auto; currently c++
  (gdb) b Java_com_app_AppRenderer_onCreate
  Breakpoint 1 at 0xafff1b1a: file apps/app-android/../../../app-Android/jni/DMJNI/DMInterface.cpp, line 75.
  (gdb) c
  Continuing.
  Warning:
  Cannot insert breakpoint 1.
  Error accessing memory address 0xafff1b1a: Input/Output error.
  </code></pre>
  
  <p>So it looks like the breakpoint gets set ok, and that the symbols are ok, but maybe the address is wrong when it tries to insert the breakpoint.  I've tried several variations of different commands from the webpage referenced above, but so far, no luck.</p>
  
  <p>Any ideas what's going on?</p>
  
  <p>Thanks</p>