在Cygwin下能不能使用Android NDK包里面的ndk-gdb命令对so库文件进行调试?

解决方案 »

  1.   

    ndk-gdb Overview 
    http://blog.csdn.net/xqhrs232/article/details/7612745原文地址::E:\DirectX\Android_NDK_JNI\android-ndk-r5-windows\android-ndk-r5\documentation.html 'ndk-gdb' OverviewIMPORTANT: IF YOU ARE DEBUGGING THREADED PROGRAMS, PLEASE READ THE
               SECTION BELOW TITLED 'Thread Support'.I. Usage:
    ---------The Android NDK r4 introduced a helper shell script named 'ndk-gdb' to
    easily launch a native debugging session for your NDK-generated machine code.The script is located at the top-level directory of the NDK, and shall
    be invoked from the command-line when in your application project
    directory, or any of its sub-directories. For example:    cd $PROJECT
        $NDK/ndk-gdbWhere $NDK points to your NDK installation path. You can also create an
    alias or add $NDK to your PATH to avoid typing it every time.IMPORTANT: Native debugging can only work if *all* these conditions are met:    1. Your application is built with the 'ndk-build' script:        Building with the legacy "make APP=<name>" method is not
            supported by ndk-gdb.    2. Your application is debuggable:        In other words, your AndroidManifest.xml has an <application>
            element that sets the android:debuggable attribute to "true"    3. You are running your application on Android 2.2 (or higher):        ndk-gdb will not work if you try to run your application on
            previous versions of the system. That does not mean that your
            application should target the Android 2.2. API level, just
            that the debugging session should happen on a 2.2+ device or
            emulator system image.        IMPORTANT IMPORTANT IMPORTANT !!            If you are using the ADT Eclipse plug-in to build your
                application, make sure you're using version 0.9.7 or
                later.            If you are using the 'ant' build tool, make sure that you
                have the latest revision of the SDK Platform components.
                The following minimal revisions are required:                Android 1.5      r4
                    Android 1.6      r3
                    Android 2.1      r2
                    Android 2.2      r1            These should be available through the SDK updater.            If these conditions are not met, the generated .apk will
                not contain required support files and native debugging
                will not be possible.'ndk-gdb' handles many error conditions and will dump an informative error
    message if it finds a problem. For example, it:    - checks that adb is in your path.    - checks that your application is declared debuggable in its manifest.    - checks that, on the device, the installed application with the same
          package name is also debuggable.
    By default, ndk-gdb will search for an already-running application process,
    and will dump an error if it doesn't find one. You can however use the --start
    or --launch=<name> option to automatically start your activity before the
    debugging session.When it successfully attaches to your application process, ndk-gdb will give
    you a normal GDB prompt, after setting up the session to properly look for
    your source files and symbol/debug versions of your generated native
    libraries.You can set breakpoints with 'b <location>' and resume execution with 'c'
    (for 'continue'). See the GDB manual for a list of commands.IMPORTANT: When quitting the GDB prompt, your debugged application process
               will be stopped! This is a gdb limitation.IMPORTANT: The GDB prompt will be preceded by a long list of error messages,
               where gdb complains that it cannot find various system libraries
               (e.g. libc.so, libstdc++.so, liblog.so, libcutils.so, etc...)           This is normal, because there are no symbol/debug versions of
               these libraries corresponding to your target device on your
               development machine. You can safely ignore these messages.II. Options:
    ------------To see a list of options, type 'ndk-gdb --help'. Notable ones are:  --verbose:
        Print verbose information about the native debugging session setup.
        Only needed to debug problems when you can't connect and that the
        error messages printed by ndk-gdb are not enough.  --force:
        By default, ndk-gdb aborts if it finds that another native debugging
        session is running on the same device. Using --force will kill the
        session, and replace it with a new one. Note that the debugged program
        is *not* killed and will be stopped again.  --start:
        By default, ndk-gdb will try to attach to an existing running instance
        of your application on the target device. You can use --start to
        explicitly launch your application before the debugging session.    NOTE: This launches the first launchable activity listed from your
              application manifest. Use --launch=<name> to start another one.
              See --launch-list to dump the list of such activities.  --launch=<name>:
        This is similar to --start, except that it allows you to start a specific
        activity from your application. This is only useful if your manifest
        defines several launchable activities.  --launch-list:
        Convenience option that prints the list of all launchable activity names
        found in your application manifest. The first one will be used by --start  --project=<path>:
        Specify application project directory. Useful if you want to launch
        the script without cd-ing to the directory before that.  --port=<port>:
        By default, ndk-gdb will use local TCP port 5039 to communicate with
        the debugged application. By using a different port, it is possible
        to natively debug programs running on different devices/emulators
        connected to the same development machine.  --adb=<file>:
        Specify the adb tool executable, in case it is not in your path.  -d, -e, -s <serial>:
        These flags are similar to the ADB ones and allow you to handle the
        case where you have several devices/emulators connected to your
        development machine.        -d:          Connect to a single physical device
            -e:          Connect to a single emulator device
            -s <serial>: Connect to a specific device or emulator
                         where <serial> is the device's name as listed
                         by the "adb devices" command.    Alternatively, you can define the ADB_SERIAL environment variable
        to list a specific device, without the need for a specific option.  --exec=<file>:
      -x <file>:
        After connecting to the debugged process, run the GDB initialization
        commands found in <file>. This is useful if you want to do something
        repeatedly, e.g. setting up a list of breakpoints then resuming
        execution automatically.
    III. Requirements:
    ------------------At the moment 'ndk-gdb' requires a Unix shell to run. This means that
    Cygwin is required to run it on Windows. We hope to get rid of this
    limitation in a future NDK release.The other NDK requirements apply: e.g. GNU Make 3.81 or higher.
    IV. Thread Support:
    -------------------If your application runs on a platform older than Android 2.3, ndk-gdb will
    not be able to debug native threads properly. Instead, the debugger will only
    be able to put breakpoints on the main thread, completely ignoring the
    execution of other ones.The root of the problem is complex, but is essentially due to a very unfortunate
    bug in the platform, which was only discovered lately.The gdbserver binary that comes with this NDK has special code to detect this
    condition at runtime and adapt its behaviour automatically (in other words,
    you don't have anything special to do when building your code).What this means in practical terms are:- If you are on Android 2.3, or a prior platform release which has had the
      platform bugfix back-ported to it, you will be able to debug native
      threads automatically.- If you are not, you will only be able to debug the main thread
      (as in previous NDK releases). You will also see the following message
      when launching ndk-gdb (just before the gdb prompt):     Thread debugging is unsupported on this Android platform!  If you place a breakpoint on a function executed on a non-main thread, the
      program will exit with the following message in GDB:        Program terminated with signal SIGTRAP, Trace/breakpoint trap.
            The program no longer exists.
      

  2.   

    好消息,android平台从froyo 2.2开始支持jni单步调试了
    http://blog.chinaunix.net/space.php?uid=8272118&do=blog&id=2033358&page=1
      

  3.   

    hello-gdbserver:A debuggable JNI example for Android
    http://vilimpoc.org/blog/2010/09/23/hello-gdbserver-a-debuggable-jni-example-for-android/
      

  4.   

    How to attach gdb? 
    http://forum.openframeworks.cc/index.php?topic=8555.0Not able to attach the ndk-gdb to the android application
    http://stackoverflow.com/questions/8266852/not-able-to-attach-the-ndk-gdb-to-the-android-application很多时候可以使用$ $NDK/ndk-gdb --verbose进行调试
    --verbose:
        Print verbose information about the native debugging session setup.
        Only needed to debug problems when you can't connect and that the
        error messages printed by ndk-gdb are not enough.
      

  5.   


    $ $NDK/ndk-gdb --verbose
    Android NDK installation path: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5
    Using default adb command: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb
    ADB version found: Android Debug Bridge version 1.0.29
    Using final ADB command: '/cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb'
    Using auto-detected project path: .
    Found package name: com.KT.NDKOpenGL_Test
    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.KT.NDKOpenGL_Test/lib/gdbserver: No such file or directory
    ERROR: Non-debuggable application installed on the target device.
           Please re-install the debuggable version!如何解决上面的问题----把NDK下设置NDK_DEBUG=1编译开关多编译出来的gdb.setup及gdbserver文件跟SO库文件一样一起COPY到APK的LIBS的目录下!!!
      

  6.   

    举一个ndk-gdb成功连接的例子How to attach gdb? 
    http://forum.openframeworks.cc/index.php?topic=8555.0
    $ /c/Development/android-ndk-r6b-custom/ndk-gdb --verbose  
    Android NDK installation path: /c/Development/android-ndk-r6b-custom  
    Using default adb command: /c/Development/android-sdk/platform-tools/adb.exe  
    ADB version found: Android Debug Bridge version 1.0.29  
    Using final ADB command: '/c/Development/android-sdk/platform-tools/adb.exe'  
    Using auto-detected project path: .  
    Found package name: com.AB.NB  
    ABIs targetted by application: armeabi  
    Device API Level: 8  
    Device CPU ABI: armeabi  
    Compatible device ABI: armeabi  
    Found debuggable flag: true  
    Found device gdbserver: //data/data/com.AB.NB/lib/gdbserver  
    Using gdb setup init: /e/projects/AB/NB/trunk/OF/apps/android/No  
    deBeatPhone/libs/armeabi/gdb.setup  
    Using toolchain prefix: /c/Development/android-ndk-r6b-custom/toolchains/arm-lin  
    ux-androideabi-4.6.2/prebuilt/windows/bin/arm-linux-androideabi-  
    Using app out directory: /e/projects/AB/NB/trunk/OF/apps/android  
    /NBPhone/obj/local/armeabi  
    Found data directory: '/data/data/com.AB.NB'  
    Found running PID: 918  
    gdbserver version is  
    Launched gdbserver succesfully.  
      

  7.   

    举一个ndk-gdb成功连接的例子How to attach gdb? 
    http://forum.openframeworks.cc/index.php?topic=8555.0
    $ /c/Development/android-ndk-r6b-custom/ndk-gdb --verbose  
    Android NDK installation path: /c/Development/android-ndk-r6b-custom  
    Using default adb command: /c/Development/android-sdk/platform-tools/adb.exe  
    ADB version found: Android Debug Bridge version 1.0.29  
    Using final ADB command: '/c/Development/android-sdk/platform-tools/adb.exe'  
    Using auto-detected project path: .  
    Found package name: com.AB.NB  
    ABIs targetted by application: armeabi  
    Device API Level: 8  
    Device CPU ABI: armeabi  
    Compatible device ABI: armeabi  
    Found debuggable flag: true  
    Found device gdbserver: //data/data/com.AB.NB/lib/gdbserver  
    Using gdb setup init: /e/projects/AB/NB/trunk/OF/apps/android/No  
    deBeatPhone/libs/armeabi/gdb.setup  
    Using toolchain prefix: /c/Development/android-ndk-r6b-custom/toolchains/arm-lin  
    ux-androideabi-4.6.2/prebuilt/windows/bin/arm-linux-androideabi-  
    Using app out directory: /e/projects/AB/NB/trunk/OF/apps/android  
    /NBPhone/obj/local/armeabi  
    Found data directory: '/data/data/com.AB.NB'  
    Found running PID: 918  
    gdbserver version is  
    Launched gdbserver succesfully.  
      

  8.   

    目前我的状况如下:$ $NDK/ndk-gdb --verbose
    Android NDK installation path: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5
    Using default adb command: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb
    ADB version found: Android Debug Bridge version 1.0.29
    Using final ADB command: '/cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb'
    Using auto-detected project path: .
    Found package name: com.KT.NDKOpenGL_Test
    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.KT.NDKOpenGL_Test/lib/gdbserver
    Using gdb setup init: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test/libs/armeabi/gdb.setup
    Using toolchain prefix: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/wind
    ows/bin/arm-linux-androideabi-
    Using app out directory: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test/obj/local/armeabi
    Found data directory: '/data/data/com.KT.NDKOpenGL_Test'
    Found running PID: 0
    ERROR: Could not extract PID of application on device/emulator.
           Are you sure the application is already started?
           Consider using --start or --launch=<name> if not.
      

  9.   

    ndk-gdb fail on real device
    http://comments.gmane.org/gmane.comp.handhelds.android.ndk/13685Can you try the command adb shell ps and post what you get.Personally I am using a rooted device and I don't know if that makes a
    difference but I know I had to alter the awk script NDK\build\awk\extract-
    pid.awk to make it work, That script assumes that the PID will be in
    the second column while I was finding that to not be true. If you also
    experience this then you may need to change that script or come up
    with another solution.
      

  10.   

    Add ndk-gdb script to the NDK
    http://nv-tegra.nvidia.com/gitweb/?p=android/platform/ndk.git;a=commitdiff;h=a08d605794902f5c7ed79b3d894adb722e1b6cac
    This is a helper script used to launch a native debugging session.
    To use it, follow these steps:1. Make your application debuggable
    2. Build the machine code with 'ndk-build'  (make APP=<name> is not supported)
    3. Build the package with ant or the ADT Eclipse plugin
    4. Install it on your device/emulator
    5. Launch it
    6. Run 'ndk-gdb' from your application project directory.Change-Id: Ie3b0557e70cefa0080075a34ad0ca46bebef3c42
    NOTE: To work properly, a modified gdbserver binary must be used
          (one that binds to Unix sockets instead of TCP ones). Patch
          upcoming.
      

  11.   

    Problems with ndk-gdb - gdb.setup, putpkt, running PIDhttp://stackoverflow.com/questions/10273318/problems-with-ndk-gdb-gdb-setup-putpkt-running-pid have built a native library with ndk-build, and it is ed as debuggable in Android.mk. If I go into the cygwin shell and run cd (PROJDIR)  ndk-gdb --start --verbose  I get the following:Android NDK installation path: /cygdrive/c/Android/android-ndk-r7b  Using default adb command: /cygdrive/c/Android/android-sdk/platform-tools/adb  ADB version found: Android Debug Bridge version 1.0.29  Using ADB flags:   Using auto-detected project path: .  Found package name: tiny.test2  ABIs targetted by application: armeabi  Device API Level: 15  Device CPU ABIs: armeabi-v7a armeabi  Compatible device ABI: armeabi  Found debuggable flag: true  Found device gdbserver: /data/data/tiny.test2/lib/gdbserver  Using gdb setup init: ./libs/armeabi/gdb.setup  Using toolchain prefix: /cygdrive/c/Android/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-  Using app out directory: ./obj/local/armeabi  Found data directory: '/data/data/tiny.test2'  Found first launchable activity: .Test2Activity  Launching activity: tiny.test2/.Test2Activity  ## COMMAND: /cygdrive/c/Android/android-sdk/platform-tools/adb shell am start -n tiny.test2/.Test2Activity  Starting: Intent { cmp=tiny.test2/.Test2Activity }    ## COMMAND: /cygdrive/c/Android/android-sdk/platform-tools/adb shell sleep 2  Found running PID: 0  ERROR: Could not extract PID of application on device/emulator.         Weird, this probably means one of these:             - The installed package does not match your current manifest.           - The application process was terminated.           Try using the --verbose option and look at its output for details.  It doesn't reach the gdb prompt for debugging. I tried launching it from Eclipse with a breakpoint in the .java file before the first C++ function call, and then while it was at the java breakpoint running ndk-gdb, and it successfully found running PID 1977, connected to the device through port 5039, and pulled libc.so from the device, but then got a swag of Error while mapping shared library sections: libxxxx.so: No such file or directory. The symbols are not found in info sharedLibrary. 
      

  12.   

    Android真机执行ndk-gdb后出现”found running pid:0 could not extract pid of application…”的解决方法
    http://blog.k-res.net/wap/index-wap2.php?p=920
    问题描述:按着Sequoyah Native Debug的教程走,到执行ndk-gdb起服务的时候,提示”found running pid:0 could not extract pid of application…”说找不到程序的PID(顺带一提,之前还有一次是提示could not extract package’s data directory…,经查发现原因应该是设备没有root),执行adb shell ps发现要调试程序的进程就在那里,PID也看到正常,为什么ndk-gdb说获取不到PID呢?
    翻了一下ndk-gdb的脚本,发现它获取PID的方法是通过执行这个:\android-ndk-r6\build\awk\extract-pid.awk,打开awk一看,里面这样写着:# We use the fact that the 9th column of the 'ps' output
    # contains the package name, while the 2nd one contains the pid
    #
    $9 ~ PACKAGE {
        PID=$2
    }又看了一下adb shell里ps的输出:
    ps
      PID USER       VSZ STAT COMMAND
        1 0          352 S    /init
        2 0            0 SW   [kthreadd]
        3 0            0 SW   [ksoftirqd/0]
        4 0            0 SW   [watchdog/0]
        5 0            0 SW   [events/0]
        6 0            0 SW   [khelper]
        9 0            0 SW   [async/mgr]
       12 0            0 SW   [suspend]
       13 0            0 SW   [npa/0]
      229 0            0 SW   [sync_supers]我勒个去,是因为版本变更年代久远,还是这脚本在坑我的爹?PID和程序包名分明应该是对应第1列和第5列,怎么就说是2和9列呢?
    改了一下awk脚本:
    $5 ~ PACKAGE {
        PID=$1
    }
    再次执行ndk-gdb,这下ok了,PID正常获得,gdb server正常启动并attach上了!UPDATE1:有幸检查了一下emulator上的ps输出,确实是2-9对应关系,唉,无语...
    UPDATE2:又查了一个机器,Win7上看WildFire G8,官方2.2系统,shell ps也是2-9对应,不知道是什么原因了...
      

  13.   

    我的问题的解决也是通过修改NDK\build\extract-pid.awk文件,因为PS查看我的包名在第11列,所以要把$9修改为$11.这样就可以找到PID了。
      

  14.   

    最后我的情况如下:GDB符已经出来了,但没法调试啊!不知道为什么???
    $ $NDK/ndk-gdb --verbose
    Android NDK installation path: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5
    Using default adb command: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb
    ADB version found: Android Debug Bridge version 1.0.29
    Using final ADB command: '/cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb'
    Using auto-detected project path: .
    Found package name: com.KT.NDKOpenGL_Test
    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.KT.NDKOpenGL_Test/lib/gdbserver
    Using gdb setup init: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test/libs/armeabi/gdb.setup
    Using toolchain prefix: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/wind
    ows/bin/arm-linux-androideabi-
    Using app out directory: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test/obj/local/armeabi
    Found data directory: '/data/data/com.KT.NDKOpenGL_Test'
    Found running PID: 10603
    Launched gdbserver succesfully.
    Setup network redirection
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb shell run-as com.KT.NDKOpenGL_Test lib/gdbs
    erver +debug-socket --attach 10603
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb forward tcp:5039 localfilesystem:/data/data
    /com.KT.NDKOpenGL_Test/debug-socket
    [1]   Segmentation fault      run-as com.KT.ND...
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb pull /system/bin/app_process E:/DirectX/And
    roid_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test/obj/local/armeabi/app_process
    5 KB/s (5720 bytes in 1.000s)
    Pulled app_process from device/emulator.
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb pull /system/lib/libc.so E:/DirectX/Android
    _NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test/obj/local/armeabi/libc.so
    2445 KB/s (273880 bytes in 0.109s)
    Pulled libc.so from device/emulator.
    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=i586-mingw32msvc --target=arm-elf-linux".
    Warning: G:/IMX53_Smd_PatchAll_SourceCode/home/xqhrs232/IMX53_Smd/external/skia/include/config: No such file or directory.
    (no debugging symbols found)
    E:/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test/obj/local/armeabi/gdb.setup:4: Error in sourced command file:
    Remote communication error: Bad file descriptor.
    (gdb) ls
    Undefined command: "ls".  Try "help".
    (gdb) list
    No symbol table is loaded.  Use the "file" command.
    (gdb)
      

  15.   

    Sequoyah/ndk guide
    A step-by-step guide for debugging native code 
    http://wiki.eclipse.org/Sequoyah/ndk_guide
    Integrating the Android NDK C++ Native Support into Eclipse Using Sequoyahhttp://www.aton.com/integrating-the-android-ndk-c-native-support-into-eclipse-using-sequoyah/
      

  16.   

    我现在的情况如下:
    $ $NDK/ndk-gdb
    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=i586-mingw32msvc --target=arm-elf-linux".
    Warning: G:/IMX53_Smd_PatchAll_SourceCode/home/xqhrs232/IMX53_Smd/external/skia/include/config: No such file or directory.
    (no debugging symbols found)
    E:/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test/obj/local/armeabi/gdb.setup:4: Error in sourced command file:
    Remote communication error: Bad file descriptor.
    (gdb) list
    No symbol table is loaded.  Use the "file" command.
    (gdb) continue
    Continuing.
    putpkt: write failed: No such file or directory.
    (gdb) p
    The history is empty.
    (gdb) x
    0x0:    putpkt: write failed: No error.
    (gdb)
      

  17.   

    NDK-GDB 调试 list命令 报错<<C++-namespaces>>: No such file or directory
    http://topic.csdn.net/u/20110702/09/362528d5-0256-411b-a822-4cd2cd94efd0.html?seed=708353934&r=78713369#r_78713369
    简单的说就是先在JAVA端设置断点.最好是你即将要调用的C++ 本地代码函数那个位置设好断点.
    然后运行APK.停在断点处,再$NDK/ndk-gdb.等启动完毕后,输入  
    b cpp文件全称 :函数名(不需要括号)
    回车用c命令.
    最后再在JAVA端释放断点,然后就可以跟进你的本地C代码函数了.你需要先进入全局函数,再用你说的那种方式就可以了.
    比如.
    先 ndk-gdb后
    b tiros_gis_vos_SkView.cpp :Java_tiros_gis_vos_SkView_showMap
    待进入Java_tiros_gis_vos_SkView_showMap这个全局函数的断点后.
    再设某一类的函数为断点.比如:b CVOSStr::Init
    就OK了.
    我的就是这么做的.不知是不是你要的答案.
      

  18.   

    gdb.setup:4: Error in sourced command file: http://groups.google.com/group/android-ndk/browse_thread/thread/1d1d00998e2f226f/bb2f9a705682ecfb
      

  19.   

    gdb.setup:4: Error in sourced command file:Remote communication error: Bad file descriptor.Debugging C++ code using Eclipse on Windows 
    http://groups.google.com/group/android-ndk/browse_thread/thread/ff824d758fe1e79f/b542a480fbcfdcbd
      

  20.   

    Remote communication error: Bad file descriptor.
    http://sqbing.diandian.com/post/2012-04-18/17690370
    Remote communication error: Bad file descriptor.遇到这个错误的时候,可以试试删除jni/obj/local/armeabi/gdb.setup,再运行ndk-gdb20120502补充:出现问题的根源是在错误的目录调用了ndk-gdb。//-----------------------
    确实是这样的,我在jni目录调用了ndk-gdb,出现此问题;我转移到项目的根目录,就没有这个问题了;
      

  21.   

    Hi, Yes I do have experience with debugging on the Native side of Android. 
    Can you answer me these following questions that will help me help you? 
    1. Did you copy the first gdb.setup to gdb2.setup and configure the 
    Native Debugger to use this setup? 
    2. Did you take out the target remote:5039 line from gdb2.setup? 
    3. Did you start the Java (Application) debug mode first, then run 
    $NDK/ndk-gdb from your projects directory, then return to your project 
    (in Eclipse) and run the second debugger? 
    4. Did you issue adb forward tcp:5039 tcp:5039? 
    5. Is your windows firewall completely disabled? 
    Thanks 
    Kevin 
    On 9/8/2011 3:50 PM, Ike Starnes wrote: 
      

  22.   


    Launched gdbserver succesfully.
    Setup network redirection
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb shell run-as com.KT.NDKOpenGL_Test lib/gdbs
    erver +debug-socket --attach 10603
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb forward tcp:5039 localfilesystem:/data/data
    /com.KT.NDKOpenGL_Test/debug-socket
    [1]   Segmentation fault      run-as com.KT.ND...
    还是出现Segmentation fault的错误?gdbserver有问题???自己编译Android gdbserver(解决运行 gdbserver时 Segmentation fault 问题)
    http://blog.csdn.net/xqhrs232/article/details/7495804 
      

  23.   

    ndk-gdb对java/native code联合调试 
    http://blog.csdn.net/xqhrs232/article/details/75322762.  调试工具 及调试环境           在搭建android调试环境过程中,很多文章中原理上做了比较好的介绍,但开始始终无法成功,最后发现运行的平台,使用的工具等一些细节方面是失败的主要原因。            运行环境 :   cygwin             ndk  :   android-ndk-r7b             gdb  :   ${ndk-home}\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin\arm-linux-androideabi-gdb                             (version = 6.6)            gdbserver : 每个模拟器上, 在system/bin/gdbserver 有默认的程序                      失败配置: gdbserver (version 7.1)    :     android emulator : 4.0 (version)     14 (API level)                     成功配置:   gdbserver()                    :     android emulator : 2.3.3 (version)    10 (API level)        注意:经过尝试必须注意 gdb  vs  gdbserver版本的匹配,                  如果system/bin下的gdbserver 不匹配,可以把匹配的gdbserver push   emulator 然后指定./gdbserver ,                 必须指定"./",因为linux下面,默认是寻找 system目录  (第一个陷阱)
      

  24.   

    Android下用gdb远程调试 
    http://blog.csdn.net/xqhrs232/article/details/7531345gdb在android中的使用 
    http://blog.csdn.net/xqhrs232/article/details/7531358
      

  25.   

    Issue 15894:  Segmentation fault when starting gdb on native code (easy to reproduce)  http://code.google.com/p/android/issues/detail?id=15894
    Android 2.2 ndk-gdb on real hardware target 
    http://groups.google.com/group/android-ndk/browse_thread/thread/cb62db99ff91f228
      

  26.   

    Issue 15894:  Segmentation fault when starting gdb on native code (easy to reproduce)  http://code.google.com/p/android/issues/detail?id=15894
    Android 2.2 ndk-gdb on real hardware target 
    http://groups.google.com/group/android-ndk/browse_thread/thread/cb62db99ff91f228
      

  27.   

    使用gdb调试程序详解 ----GDB命令介绍
    http://blog.csdn.net/xqhrs232/article/details/7492955(gdb)
    Display all 128 possibilities? (y or n)
    actions                      directory                    init-if-undefined            quit                         tbreak
    add-shared-symbol-files      disable                      inspect                      rbreak                       tcatch
    add-symbol-file              disassemble                  interpreter-exec             remote                       tdump
    add-symbol-file-from-memory  disconnect                   interrupt                    restore                      tfind
    advance                      display                      jump                         return                       thbreak
    append                       document                     kill                         reverse-search               thread
    apropos                      dont-repeat                  list                         run                          tp
    attach                       down                         load                         rwatch                       trace
    awatch                       down-silently                macro                        save-tracepoints             tstart
    backtrace                    dump                         maintenance                  search                       tstatus
    break                        echo                         make                         section                      tstop
    bt                           edit                         mem                          select-frame                 tty
    call                         enable                       monitor                      set                          undisplay
    catch                        end                          next                         sharedlibrary                unset
    cd                           exec-file                    nexti                        shell                        until
    clear                        file                         ni                           show                         up
    collect                      finish                       nosharedlibrary              si                           up-silently
    commands                     flushregs                    output                       signal                       watch
    compare-sections             forward-search               overlay                      source                       whatis
    complete                     frame                        passcount                    start                        where
    condition                    handle                       path                         step                         while
    continue                     hbreak                       print                        stepi                        while-stepping
    core-file                    help                         print-object                 stepping                     ws
    define                       if                           printf                       stop                         x
    delete                       ignore                       ptype                        symbol-file
    detach                       info                         pwd                          target
    (gdb)
      

  28.   

    贴一个我在模拟器下试的情况
    qhx@eng-xiong-qh /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/myjni
    $ $NDK/ndk-gdb --verbose
    Android NDK installation path: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5
    Using default adb command: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb
    ADB version found: Android Debug Bridge version 1.0.29
    Using final ADB command: '/cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb'
    Using auto-detected project path: .
    Found package name: com.example.JNI
    ABIs targetted by application: armeabi
    Device API Level: 10
    Device CPU ABI: armeabi
    Compatible device ABI: armeabi
    Found debuggable flag: false
    Found gdbserver under libs/armeabi, assuming app was built with NDK_DEBUG=1
    Found device gdbserver: /data/data/com.example.JNI/lib/gdbserver
    Using gdb setup init:
    Using toolchain prefix: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/wind
    ows/bin/arm-linux-androideabi-
    Using app out directory: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/myjni/obj/local/armeabi
    Found data directory: '/data/data/com.example.JNI'
    Found running PID: 7836
    Launched gdbserver succesfully.
    Setup network redirection
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb shell run-as com.example.JNI lib/gdbserver
    +debug-socket --attach 7836
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb forward tcp:5039 localfilesystem:/data/data
    /com.example.JNI/debug-socket
    Attached; pid = 7836
    Listening on sockaddr socket debug-socket
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb pull /system/bin/app_process E:/DirectX/And
    roid_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/myjni/obj/local/armeabi/app_process
    35 KB/s (5660 bytes in 0.156s)
    Pulled app_process from device/emulator.
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb pull /system/lib/libc.so E:/DirectX/Android
    _NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/myjni/obj/local/armeabi/libc.so
    120 KB/s (273868 bytes in 2.218s)
    Pulled libc.so from device/emulator.
    cp: missing destination file operand after `/cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/myjni/obj/local/armeabi/
    gdb.setup'
    Try `cp --help' for more information.
    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=i586-mingw32msvc --target=arm-elf-linux".
    (no debugging symbols found)
    Error while mapping shared library sections:
    /system/bin/linker: No such file or directory.
    Error while mapping shared library sections:
    libc.so: No error.
    Error while mapping shared library sections:
    libstdc++.so: No error.
    Error while mapping shared library sections:
    libm.so: No error.
    Error while mapping shared library sections:
    liblog.so: No error.
    Error while mapping shared library sections:
    libcutils.so: No error.
    Error while mapping shared library sections:
    libz.so: No error.
    Error while mapping shared library sections:
    libutils.so: No error.
    Error while mapping shared library sections:
    libbinder.so: No error.
    Error while mapping shared library sections:
    libexpat.so: No error.
    Error while mapping shared library sections:
    libcrypto.so: No error.
    Error while mapping shared library sections:
    libicuuc.so: No error.
    Error while mapping shared library sections:
    libicui18n.so: No error.
    Error while mapping shared library sections:
    libsqlite.so: No error.
    Error while mapping shared library sections:
    libssl.so: No error.
    Error while mapping shared library sections:
    libnativehelper.so: No error.
    Error while mapping shared library sections:
    libnetutils.so: No error.
    Error while mapping shared library sections:
    libEGL.so: No error.
    Error while mapping shared library sections:
    libwpa_client.so: No error.
    Error while mapping shared library sections:
    libhardware_legacy.so: No error.
    Error while mapping shared library sections:
    libpixelflinger.so: No error.
    Error while mapping shared library sections:
    libhardware.so: No error.
    Error while mapping shared library sections:
    libui.so: No error.
    Error while mapping shared library sections:
    libgui.so: No error.
    Error while mapping shared library sections:
    libsurfaceflinger_client.so: No error.
    Error while mapping shared library sections:
    libcamera_client.so: No error.
    Error while mapping shared library sections:
    libemoji.so: No error.
    Error while mapping shared library sections:
    libjpeg.so: No error.
    Error while mapping shared library sections:
    libskia.so: No error.
    Error while mapping shared library sections:
    libGLESv1_CM.so: No error.
    Error while mapping shared library sections:
    libskiagl.so: No error.
    Error while mapping shared library sections:
    libdvm.so: No error.
    Error while mapping shared library sections:
    libGLESv2.so: No error.
    Error while mapping shared library sections:
    libETC1.so: No error.
    Error while mapping shared library sections:
    libsonivox.so: No error.
    Error while mapping shared library sections:
    libmedia.so: No error.
    Error while mapping shared library sections:
    libnfc_ndef.so: No error.
    Error while mapping shared library sections:
    libandroid_runtime.so: No error.
    Error while mapping shared library sections:
    libvorbisidec.so: No error.
    Error while mapping shared library sections:
    libstagefright_amrnb_common.so: No error.
    Error while mapping shared library sections:
    libstagefright_enc_common.so: No error.
    Error while mapping shared library sections:
    libstagefright_avc_common.so: No error.
    Error while mapping shared library sections:
    libstagefright_foundation.so: No error.
    Error while mapping shared library sections:
    libstagefright_color_conversion.so: No error.
    Error while mapping shared library sections:
    libstagefright.so: No error.
    Error while mapping shared library sections:
    libmedia_jni.so: No error.
    Error while mapping shared library sections:
    libexif.so: No error.
    Error while mapping shared library sections:
    libsoundpool.so: No error.
    Error while mapping shared library sections:
    libstlport.so: No error.
    Error while mapping shared library sections:
    libwebcore.so: No error.
    Error while mapping shared library sections:
    libmyjni.so: No error.
    warning: Unable to find dynamic linker breakpoint function.
    GDB will be unable to debug shared library initializers
    and track explicitly loaded dynamic code.
    warning: shared library handler failed to enable breakpoint
    0xafd0c738 in ?? ()
    gdb: Unable to get location for thread creation breakpoint: requested event is not supported
    (no debugging symbols found)
    gdb: Unable to get location for thread creation breakpoint: requested event is not supported
    gdb: Unable to get location for thread creation breakpoint: requested event is not supported
    Killing inferior
    E:/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/myjni/obj/local/armeabi/gdb.setup:4: Error in sourced command file:
    Remote communication error: Bad file descriptor.
    (gdb)
      

  29.   

    CSDN上有人走通了这个流程NDK-GDB 调试 list命令 报错<<C++-namespaces>>: No such file or directory
    http://topic.csdn.net/u/20110702/09/362528d5-0256-411b-a822-4cd2cd94efd0.html?seed=1398963705&r=78722315#r_78722315
      

  30.   

    gdb错误:Error while mapping shared library sections: /system/bin/linker: No such file or directory.http://hi.baidu.com/njjiangwenna/blog/item/a95d328443e3512266096ecc.html
    参考http://iunknown.iteye.com/blog/73064。在详细看了当前版本的ndk-gdb.html之后,发现有这样一段话:IMPORTANT: The GDB prompt will be preceded by a long list of error messages, where gdb complains that it cannot find various system libraries (e.g. libc.so, libstdc++.so, liblog.so, libcutils.so, etc...) This is normal, because there are no symbol/debug versions of these libraries corresponding to your target device on your development machine. You can safely ignore these messages.也就是说,当前的这些错误信息可以忽略。
      

  31.   

    gdb错误:Error while mapping shared library sections: /system/bin/linker: No such file or directory.http://hi.baidu.com/njjiangwenna/blog/item/a95d328443e3512266096ecc.html
    参考http://iunknown.iteye.com/blog/73064。在详细看了当前版本的ndk-gdb.html之后,发现有这样一段话:IMPORTANT: The GDB prompt will be preceded by a long list of error messages, where gdb complains that it cannot find various system libraries (e.g. libc.so, libstdc++.so, liblog.so, libcutils.so, etc...) This is normal, because there are no symbol/debug versions of these libraries corresponding to your target device on your development machine. You can safely ignore these messages.也就是说,当前的这些错误信息可以忽略。
      

  32.   

    是乎我在模拟器上已经成功了
    (no debugging symbols found)
    warning: Unable to find dynamic linker breakpoint function.
    GDB will be unable to debug shared library initializers
    and track explicitly loaded dynamic code.
    warning: shared library handler failed to enable breakpoint
    0xafd0c738 in __futex_syscall3 ()
       from E:/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test_lib/obj/local/armeabi/libc.so
    (gdb) b com_KT_NDKOpenGL_Test_NDKOpenGL.cpp:Java_com_KT_NDKOpenGL_1Test_NDKOpenGL_nativeInit
    Breakpoint 1 at 0x80406e3c: file E:/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test/jni/com_KT_NDKOpenGL_Test_NDK
    OpenGL.cpp, line 578.
    (gdb) list
      

  33.   

    存在的几个疑问!!!1。在什么那个目录下执行$NDK/ndk-gdb --start命令?在SO库文件的工程下,还是在ECLIPSE IDE的工程下,应用工程文件应该放什么地方?ECLIPSE IDE/NDK SAMPLE下?2。模拟器的GDBSERVER跟实际设备的GDBSERVER有没区别?在实际的设备上进行ndk-gdb要不要重新编译gdbserver?每个SO库文件工程自带的gdbserver是个什么东西?起什么作用?3。进行ndk-gdb要不要ECLIPSE IDE的配合?如果要,ECLIPSE IDE要不要装CDT插件?4。编译应用工程用到的SO库文件应该用那个地方的?那个地方的SO库文件包含有调试符号
        obj\local\armeabi还是libs\armeabi
    5。针对gdb.setup文件也有类似于上面第4项的问题,到底该用那一个?要不要进行修改?为什么要进行修改?因为两个gdb.setup还是不一样的6。为什么在模拟下进行ndk-gdb对应的包名下面有debug-socket文件,而在实际的设备上却没有
       具体路径为/data/data/packagename/debug-socket7。每个SO工程设置调试编译出来的gdbserver文件跟系统的/system/bin/gdbserver文件有什么不同,进行ndk-gdb用的是那一个?8。ndk-gdb脚本文件会执行gdbserver程序,但为什么我用PS命令没看到跑起来的gdbserver进程在进程列表呢?难道gdbserver只需要跑一下就OK?gdbserver不是要做服务器的意思吗?那在ndk-gdb的整个过程中都应该运行的啊!
      

  34.   

    存在的几个疑问!!!1。在什么那个目录下执行$NDK/ndk-gdb --start命令?在SO库文件的工程下,还是在ECLIPSE IDE的工程下,应用工程文件应该放什么地方?ECLIPSE IDE/NDK SAMPLE下?2。模拟器的GDBSERVER跟实际设备的GDBSERVER有没区别?在实际的设备上进行ndk-gdb要不要重新编译gdbserver?每个SO库文件工程自带的gdbserver是个什么东西?起什么作用?3。进行ndk-gdb要不要ECLIPSE IDE的配合?如果要,ECLIPSE IDE要不要装CDT插件?4。编译应用工程用到的SO库文件应该用那个地方的?那个地方的SO库文件包含有调试符号
        obj\local\armeabi还是libs\armeabi
    5。针对gdb.setup文件也有类似于上面第4项的问题,到底该用那一个?要不要进行修改?为什么要进行修改?因为两个gdb.setup还是不一样的6。为什么在模拟下进行ndk-gdb对应的包名下面有debug-socket文件,而在实际的设备上却没有
       具体路径为/data/data/packagename/debug-socket7。每个SO工程设置调试编译出来的gdbserver文件跟系统的/system/bin/gdbserver文件有什么不同,进行ndk-gdb用的是那一个?8。ndk-gdb脚本文件会执行gdbserver程序,但为什么我用PS命令没看到跑起来的gdbserver进程在进程列表呢?难道gdbserver只需要跑一下就OK?gdbserver不是要做服务器的意思吗?那在ndk-gdb的整个过程中都应该运行的啊!
      

  35.   

    9。很多文章中提到了gdbclient不知道这个起什么作用,用在什么地方,在ndk-gdb起什么角色与作用10。ndk-gdb到底是通过TCP:5039还是socket?这两者有什么本质的区别与联系?端口重定向指的怎么一回事?
      

  36.   

    11。有些地方显示
    This GDB was configured as "--host=i686-pc-cygwin --target=arm-elf-linux".
    ----http://blog.csdn.net/xqhrs232/article/details/7618136 但为什么我的显示却是如下,不明白!
    This GDB was configured as "--host=i586-mingw32msvc --target=arm-elf-linux".
    我的明明是在cygwin下进行ndk-gdb,为什么显示i586-mingw32msvc ?
      

  37.   

    在模拟器下gdbserver是可以被执行的!!!
    #./gdbserver
    ./gdbserver
    Usage:gdbserver COMM PROG[ARGS...]
          gdbserver COMM --attach PID [--close-fd FD]COMM may either be a tty device <for serial debugging>, or
    HOST:POST to listen for a TCP connection.
    Exiting
    #pwd
    pwd
    /system/bin
      

  38.   

    在我的实际上gdbserver执行就报错Segmentation fault
    # pwd
    pwd
    /system/bin# ./gdbserver
    ./gdbserver
    [1]   Segmentation fault      ./gdbserver#
      

  39.   

    在我的实际上gdbserver执行就报错Segmentation fault
    # pwd
    pwd
    /system/bin# ./gdbserver
    ./gdbserver
    [1]   Segmentation fault      ./gdbserver#
      

  40.   

    NDK下的工程设置为NDK_DEBUG=1编译多出来的gdbserver是直接从android-ndk-r5\toolchains\arm-linux-androideabi-4.4.3\prebuilt COPY过来的,发生如下的错误就表明gdbserver版本有问题。[1] Segmentation fault run-as com.KT.ND...老外也发现了这个问题,下面这个帖子不仅教我们怎么自己去下载gdbserver的源代码,怎么打补丁,怎么编译,怎么替换NDK中的不可用的gdbserver版本,还提到了在新一点的NDK版本r5c里面已经修订了这个问题,并提供了他们编译好的gdbserver文件给我们下载使用,就是不知道能不能用,得试一下!!!Issue 15894:  Segmentation fault when starting gdb on native code (easy to reproduce)  http://code.google.com/p/android/issues/detail?id=15894The 'gdbserver' that comes in NDK r5b is stripped of symbols, so I cannot confirm that what I'm about to say is absolutely the cause of this particular segfault, but I do have an interesting data-point to share:Back in early February I discovered that the AOSP's prebuilt 'gdbserver' for Gingerbread had been statically linked against a libc from Cupcake.  This caused an impedance mismatch between libc and the kernel, causing segfaults.  (During this time I was unaware of the 'ndk-build' and 'ndk-gdb' scripts, and was doing things "the hard way".)My solution was to rebuild my own gdbserver (from 7.2 gdb,) applying Google's 7.1.x libthread_db patches.  The result was a usable gdbserver.    I now find that I can also work around this new segfault (with NDK r5b's "ndk-gdb script") by again using that self-built gdbserver.See below for details captured in February.This brings up an interesting point:  It makes sense for gdbserver to be statically linked to libc, for the purpose of minimizing gdbserver's dependence on the system being debugged.  But at the same time, I think maybe it makes it a little risky to use the same gdbserver binary for all Android OS versions, particularly when there are kernel differences?  If my concern has merit, then perhaps the NDK should come supplied with multiple copies of gdbserver, and then the appropriate one should get used for a given target device.   rbissell@rvb-android-dev0:~/src/android$ nm -a ./gdbserver | grep fork
       0003c460 T fork
       00000000 a fork.c
       rbissell@rvb-android-dev0:~/src/android$ addr2line -e ./gdbserver 0003c460
       /opt/digit/android/main/cupcake/android/bionic/libc/bionic/fork.c:34 (Again, the was the gdbserver taken from the Gingerbread AOSP tree, back in early February 2011.)Hope that helps in some way.
      

  41.   

    Eclispe+CDT+gdb调试android ndk程序----包括CDT组件跟Sequoyah Android Native Code Support组件安装-----基于UBUNTU环境下安装http://www.cnblogs.com/shadox/archive/2011/12/02/2272564.html
      

  42.   

    把android-ndk-r5\toolchains\arm-linux-androideabi-4.4.3\prebuilt下的gdbserver换成r5c版本下就可以了,下面是我Attach成功的过程----在我自己实际的设备上,设备上安装包的地方/data/data/packagename/debug-socket文件也出来了。qhx@eng-xiong-qh /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI
    $ $NDK/ndk-gdb --verbose
    Android NDK installation path: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5
    Using default adb command: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb
    ADB version found: Android Debug Bridge version 1.0.29
    Using final ADB command: '/cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb'
    Using auto-detected project path: .
    Found package name: com.example.JNI
    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.JNI/lib/gdbserver
    Using gdb setup init: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI/libs/armeabi/gdb.setup
    Using toolchain prefix: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/wind
    ows/bin/arm-linux-androideabi-
    Using app out directory: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI/obj/local/armeabi
    Found data directory: '/data/data/com.example.JNI'
    Found running PID: 2707
    Launched gdbserver succesfully.
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb shell run-as com.example.JNI lib/gdbserver
    Setup network redirection07
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb forward tcp:5039 localfilesystem:/data/data
    /com.example.JNI/debug-socket
    Attached; pid = 2707
    Listening on sockaddr socket debug-socket
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb pull /system/bin/app_process E:/DirectX/And
    roid_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI/obj/local/armeabi/app_process
    357 KB/s (5720 bytes in 0.015s)
    Pulled app_process from device/emulator.
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb pull /system/lib/libc.so E:/DirectX/Android
    _NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI/obj/local/armeabi/libc.so
    3423 KB/s (273880 bytes in 0.078s)
    Pulled libc.so from device/emulator.
    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=i586-mingw32msvc --target=arm-elf-linux".
    (no debugging symbols found)
    Error while mapping shared library sections:
    /system/bin/linker: No such file or directory.
    Error while mapping shared library sections:
    libstdc++.so: No such file or directory.
    Error while mapping shared library sections:
    libm.so: No such file or directory.
    Error while mapping shared library sections:
    liblog.so: No such file or directory.
    Error while mapping shared library sections:
    libcutils.so: No such file or directory.
    Error while mapping shared library sections:
    libz.so: No such file or directory.
    Error while mapping shared library sections:
    libutils.so: No such file or directory.
    Error while mapping shared library sections:
    libbinder.so: No such file or directory.
    Error while mapping shared library sections:
    libexpat.so: No such file or directory.
    Error while mapping shared library sections:
    libcrypto.so: No such file or directory.
    Error while mapping shared library sections:
    libicuuc.so: No such file or directory.
    Error while mapping shared library sections:
    libicui18n.so: No such file or directory.
    Error while mapping shared library sections:
    libsqlite.so: No such file or directory.
    Error while mapping shared library sections:
    libssl.so: No such file or directory.
    Error while mapping shared library sections:
    libnativehelper.so: No such file or directory.
    Error while mapping shared library sections:
    libnetutils.so: No such file or directory.
    Error while mapping shared library sections:
    libEGL.so: No such file or directory.
    Error while mapping shared library sections:
    libwpa_client.so: No such file or directory.
    Error while mapping shared library sections:
    libipu.so: No such file or directory.
    Error while mapping shared library sections:
    libhardware_legacy.so: No such file or directory.
    Error while mapping shared library sections:
    libpixelflinger.so: No such file or directory.
    Error while mapping shared library sections:
    libhardware.so: No such file or directory.
    Error while mapping shared library sections:
    libui.so: No such file or directory.
    Error while mapping shared library sections:
    libgui.so: No such file or directory.
    Error while mapping shared library sections:
    libsurfaceflinger_client.so: No such file or directory.
    Error while mapping shared library sections:
    libcamera_client.so: No such file or directory.
    Error while mapping shared library sections:
    libemoji.so: No such file or directory.
    Error while mapping shared library sections:
    libjpeg.so: No such file or directory.
    Error while mapping shared library sections:
    libskia.so: No such file or directory.
    Error while mapping shared library sections:
    libGLESv1_CM.so: No such file or directory.
    Error while mapping shared library sections:
    libskiagl.so: No such file or directory.
    Error while mapping shared library sections:
    libdvm.so: No such file or directory.
    Error while mapping shared library sections:
    libGLESv2.so: No such file or directory.
    Error while mapping shared library sections:
    libETC1.so: No such file or directory.
    Error while mapping shared library sections:
    libsonivox.so: No such file or directory.
    Error while mapping shared library sections:
    libmedia.so: No such file or directory.
    Error while mapping shared library sections:
    libnfc_ndef.so: No such file or directory.
    Error while mapping shared library sections:
    libbluedroid.so: No such file or directory.
    Error while mapping shared library sections:
    libdbus.so: No such file or directory.
    Error while mapping shared library sections:
    libandroid_runtime.so: No such file or directory.
    Error while mapping shared library sections:
    libvorbisidec.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright_amrnb_common.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright_enc_common.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright_avc_common.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright_foundation.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright_color_conversion.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_osal_v2_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_utils_v2_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_core_mgr_v2_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_res_mgr_v2_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    libfsl_jpeg_enc_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_client_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    libsurfaceflinger.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_player_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    lib_id3_parser_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    libmedia_jni.so: No such file or directory.
    Error while mapping shared library sections:
    libexif.so: No such file or directory.
    Error while mapping shared library sections:
    libsoundpool.so: No such file or directory.
    Error while mapping shared library sections:
    libacc.so: No such file or directory.
    Error while mapping shared library sections:
    libRS.so: No such file or directory.
    Error while mapping shared library sections:
    librs_jni.so: No such file or directory.
    Error while mapping shared library sections:
    libstlport.so: No such file or directory.
    Error while mapping shared library sections:
    libwebcore.so: No such file or directory.
    (no debugging symbols found)
    warning: Unable to find dynamic linker breakpoint function.
    GDB will be unable to debug shared library initializers
    and track explicitly loaded dynamic code.
    warning: shared library handler failed to enable breakpoint
    0xafd0c738 in __futex_syscall3 () from E:/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI/obj/local/armeabi/libc.so
    (gdb) list
    1
      

  43.   

    把android-ndk-r5\toolchains\arm-linux-androideabi-4.4.3\prebuilt下的gdbserver换成r5c版本下就可以了,下面是我Attach成功的过程----在我自己实际的设备上,设备上安装包的地方/data/data/packagename/debug-socket文件也出来了。qhx@eng-xiong-qh /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI
    $ $NDK/ndk-gdb --verbose
    Android NDK installation path: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5
    Using default adb command: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb
    ADB version found: Android Debug Bridge version 1.0.29
    Using final ADB command: '/cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb'
    Using auto-detected project path: .
    Found package name: com.example.JNI
    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.JNI/lib/gdbserver
    Using gdb setup init: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI/libs/armeabi/gdb.setup
    Using toolchain prefix: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/wind
    ows/bin/arm-linux-androideabi-
    Using app out directory: /cygdrive/e/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI/obj/local/armeabi
    Found data directory: '/data/data/com.example.JNI'
    Found running PID: 2707
    Launched gdbserver succesfully.
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb shell run-as com.example.JNI lib/gdbserver
    Setup network redirection07
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb forward tcp:5039 localfilesystem:/data/data
    /com.example.JNI/debug-socket
    Attached; pid = 2707
    Listening on sockaddr socket debug-socket
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb pull /system/bin/app_process E:/DirectX/And
    roid_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI/obj/local/armeabi/app_process
    357 KB/s (5720 bytes in 0.015s)
    Pulled app_process from device/emulator.
    ## COMMAND: /cygdrive/e/DirectX/Android_SDK/android-sdk_r07-windows/android-sdk-windows/platform-tools/adb pull /system/lib/libc.so E:/DirectX/Android
    _NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI/obj/local/armeabi/libc.so
    3423 KB/s (273880 bytes in 0.078s)
    Pulled libc.so from device/emulator.
    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=i586-mingw32msvc --target=arm-elf-linux".
    (no debugging symbols found)
    Error while mapping shared library sections:
    /system/bin/linker: No such file or directory.
    Error while mapping shared library sections:
    libstdc++.so: No such file or directory.
    Error while mapping shared library sections:
    libm.so: No such file or directory.
    Error while mapping shared library sections:
    liblog.so: No such file or directory.
    Error while mapping shared library sections:
    libcutils.so: No such file or directory.
    Error while mapping shared library sections:
    libz.so: No such file or directory.
    Error while mapping shared library sections:
    libutils.so: No such file or directory.
    Error while mapping shared library sections:
    libbinder.so: No such file or directory.
    Error while mapping shared library sections:
    libexpat.so: No such file or directory.
    Error while mapping shared library sections:
    libcrypto.so: No such file or directory.
    Error while mapping shared library sections:
    libicuuc.so: No such file or directory.
    Error while mapping shared library sections:
    libicui18n.so: No such file or directory.
    Error while mapping shared library sections:
    libsqlite.so: No such file or directory.
    Error while mapping shared library sections:
    libssl.so: No such file or directory.
    Error while mapping shared library sections:
    libnativehelper.so: No such file or directory.
    Error while mapping shared library sections:
    libnetutils.so: No such file or directory.
    Error while mapping shared library sections:
    libEGL.so: No such file or directory.
    Error while mapping shared library sections:
    libwpa_client.so: No such file or directory.
    Error while mapping shared library sections:
    libipu.so: No such file or directory.
    Error while mapping shared library sections:
    libhardware_legacy.so: No such file or directory.
    Error while mapping shared library sections:
    libpixelflinger.so: No such file or directory.
    Error while mapping shared library sections:
    libhardware.so: No such file or directory.
    Error while mapping shared library sections:
    libui.so: No such file or directory.
    Error while mapping shared library sections:
    libgui.so: No such file or directory.
    Error while mapping shared library sections:
    libsurfaceflinger_client.so: No such file or directory.
    Error while mapping shared library sections:
    libcamera_client.so: No such file or directory.
    Error while mapping shared library sections:
    libemoji.so: No such file or directory.
    Error while mapping shared library sections:
    libjpeg.so: No such file or directory.
    Error while mapping shared library sections:
    libskia.so: No such file or directory.
    Error while mapping shared library sections:
    libGLESv1_CM.so: No such file or directory.
    Error while mapping shared library sections:
    libskiagl.so: No such file or directory.
    Error while mapping shared library sections:
    libdvm.so: No such file or directory.
    Error while mapping shared library sections:
    libGLESv2.so: No such file or directory.
    Error while mapping shared library sections:
    libETC1.so: No such file or directory.
    Error while mapping shared library sections:
    libsonivox.so: No such file or directory.
    Error while mapping shared library sections:
    libmedia.so: No such file or directory.
    Error while mapping shared library sections:
    libnfc_ndef.so: No such file or directory.
    Error while mapping shared library sections:
    libbluedroid.so: No such file or directory.
    Error while mapping shared library sections:
    libdbus.so: No such file or directory.
    Error while mapping shared library sections:
    libandroid_runtime.so: No such file or directory.
    Error while mapping shared library sections:
    libvorbisidec.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright_amrnb_common.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright_enc_common.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright_avc_common.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright_foundation.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright_color_conversion.so: No such file or directory.
    Error while mapping shared library sections:
    libstagefright.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_osal_v2_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_utils_v2_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_core_mgr_v2_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_res_mgr_v2_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    libfsl_jpeg_enc_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_client_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    libsurfaceflinger.so: No such file or directory.
    Error while mapping shared library sections:
    lib_omx_player_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    lib_id3_parser_arm11_elinux.so: No such file or directory.
    Error while mapping shared library sections:
    libmedia_jni.so: No such file or directory.
    Error while mapping shared library sections:
    libexif.so: No such file or directory.
    Error while mapping shared library sections:
    libsoundpool.so: No such file or directory.
    Error while mapping shared library sections:
    libacc.so: No such file or directory.
    Error while mapping shared library sections:
    libRS.so: No such file or directory.
    Error while mapping shared library sections:
    librs_jni.so: No such file or directory.
    Error while mapping shared library sections:
    libstlport.so: No such file or directory.
    Error while mapping shared library sections:
    libwebcore.so: No such file or directory.
    (no debugging symbols found)
    warning: Unable to find dynamic linker breakpoint function.
    GDB will be unable to debug shared library initializers
    and track explicitly loaded dynamic code.
    warning: shared library handler failed to enable breakpoint
    0xafd0c738 in __futex_syscall3 () from E:/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/JNI/obj/local/armeabi/libc.so
    (gdb) list
    1
      

  44.   

    发现一个怪情况,好像必须把APP工程(含jni目录)弄到NDK下,然后在CYGWIN下进行对应的JNI编译把对应的SO库文件COPY给ECLIPSE使用才可以,并且在CYGWIN下进行NDK-GDB也必须在NDK的APP工程(含jni目录)根目录下才可以,要不然报各种错误出来!!!
      

  45.   

    发现一个怪情况,好像必须把APP工程(含jni目录)弄到NDK下,然后在CYGWIN下进行对应的JNI编译把对应的SO库文件COPY给ECLIPSE使用才可以,并且在CYGWIN下进行NDK-GDB也必须在NDK的APP工程(含jni目录)根目录下才可以,要不然报各种错误出来!!!
      

  46.   

    NDK下的几个脚本可以好好看看,包括ndk-build++++ndk-gdb++++extract-pid.awk++++build-gdbserver.sh++++gdb.setup
      

  47.   

    用GDB调试程序之系列文章----跟gdb使用手册.pdf差不多http://blog.csdn.net/xqhrs232/article/details/7491732
      

  48.   

    用GDB调试程序----举例
    http://blog.csdn.net/xqhrs232/article/details/7491732
    使用GDB调试:hchen/test> gdb tst  <---------- 启动GDB
    GNU gdb 5.1.1
    Copyright 2002 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 "i386-suse-linux"...
    (gdb) l     <-------------------- l命令相当于list,从第一行开始例出原码。
    1        #include <stdio.h>
    2
    3        int func(int n)
    4        {
    5                int sum=0,i;
    6                for(i=0; i<n; i++)
    7                {
    8                        sum+=i;
    9                }
    10               return sum;
    (gdb)       <-------------------- 直接回车表示,重复上一次命令
    11       }
    12
    13
    14       main()
    15       {
    16               int i;
    17               long result = 0;
    18               for(i=1; i<=100; i++)
    19               {
    20                       result += i;    
    (gdb) break 16    <-------------------- 设置断点,在源程序第16行处。
    Breakpoint 1 at 0x8048496: file tst.c, line 16.
    (gdb) break func  <-------------------- 设置断点,在函数func()入口处。
    Breakpoint 2 at 0x8048456: file tst.c, line 5.
    (gdb) info break  <-------------------- 查看断点信息。
    Num Type           Disp Enb Address    What
    1   breakpoint     keep y   0x08048496 in main at tst.c:16
    2   breakpoint     keep y   0x08048456 in func at tst.c:5
    (gdb) r           <--------------------- 运行程序,run命令简写
    Starting program: /home/hchen/test/tstBreakpoint 1, main () at tst.c:17    <---------- 在断点处停住。
    17               long result = 0;
    (gdb) n          <--------------------- 单条语句执行,next命令简写。
    18               for(i=1; i<=100; i++)
    (gdb) n
    20                       result += i;
    (gdb) n
    18               for(i=1; i<=100; i++)
    (gdb) n
    20                       result += i;
    (gdb) c          <--------------------- 继续运行程序,continue命令简写。
    Continuing.
    result[1-100] = 5050       <----------程序输出。Breakpoint 2, func (n=250) at tst.c:5
    5                int sum=0,i;
    (gdb) n
    6                for(i=1; i<=n; i++)
    (gdb) p i        <--------------------- 打印变量i的值,print命令简写。
    $1 = 134513808
    (gdb) n
    8                        sum+=i;
    (gdb) n
    6                for(i=1; i<=n; i++)
    (gdb) p sum
    $2 = 1
    (gdb) n
    8                        sum+=i;
    (gdb) p i
    $3 = 2
    (gdb) n
    6                for(i=1; i<=n; i++)
    (gdb) p sum
    $4 = 3
    (gdb) bt        <--------------------- 查看函数堆栈。
    #0  func (n=250) at tst.c:5
    #1  0x080484e4 in main () at tst.c:24
    #2  0x400409ed in __libc_start_main () from /lib/libc.so.6
    (gdb) finish    <--------------------- 退出函数。
    Run till exit from #0  func (n=250) at tst.c:5
    0x080484e4 in main () at tst.c:24
    24              printf("result[1-250] = %d /n", func(250) );
    Value returned is $6 = 31375
    (gdb) c     <--------------------- 继续运行。
    Continuing.
    result[1-250] = 31375    <----------程序输出。Program exited with code 027. <--------程序退出,调试结束。
    (gdb) q     <--------------------- 退出gdb。
    hchen/test>好了,有了以上的感性认识,还是让我们来系统地认识一下gdb吧。
      

  49.   

    用GDB调试程序----举例
    http://blog.csdn.net/xqhrs232/article/details/7491732
    使用GDB调试:hchen/test> gdb tst  <---------- 启动GDB
    GNU gdb 5.1.1
    Copyright 2002 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 "i386-suse-linux"...
    (gdb) l     <-------------------- l命令相当于list,从第一行开始例出原码。
    1        #include <stdio.h>
    2
    3        int func(int n)
    4        {
    5                int sum=0,i;
    6                for(i=0; i<n; i++)
    7                {
    8                        sum+=i;
    9                }
    10               return sum;
    (gdb)       <-------------------- 直接回车表示,重复上一次命令
    11       }
    12
    13
    14       main()
    15       {
    16               int i;
    17               long result = 0;
    18               for(i=1; i<=100; i++)
    19               {
    20                       result += i;    
    (gdb) break 16    <-------------------- 设置断点,在源程序第16行处。
    Breakpoint 1 at 0x8048496: file tst.c, line 16.
    (gdb) break func  <-------------------- 设置断点,在函数func()入口处。
    Breakpoint 2 at 0x8048456: file tst.c, line 5.
    (gdb) info break  <-------------------- 查看断点信息。
    Num Type           Disp Enb Address    What
    1   breakpoint     keep y   0x08048496 in main at tst.c:16
    2   breakpoint     keep y   0x08048456 in func at tst.c:5
    (gdb) r           <--------------------- 运行程序,run命令简写
    Starting program: /home/hchen/test/tstBreakpoint 1, main () at tst.c:17    <---------- 在断点处停住。
    17               long result = 0;
    (gdb) n          <--------------------- 单条语句执行,next命令简写。
    18               for(i=1; i<=100; i++)
    (gdb) n
    20                       result += i;
    (gdb) n
    18               for(i=1; i<=100; i++)
    (gdb) n
    20                       result += i;
    (gdb) c          <--------------------- 继续运行程序,continue命令简写。
    Continuing.
    result[1-100] = 5050       <----------程序输出。Breakpoint 2, func (n=250) at tst.c:5
    5                int sum=0,i;
    (gdb) n
    6                for(i=1; i<=n; i++)
    (gdb) p i        <--------------------- 打印变量i的值,print命令简写。
    $1 = 134513808
    (gdb) n
    8                        sum+=i;
    (gdb) n
    6                for(i=1; i<=n; i++)
    (gdb) p sum
    $2 = 1
    (gdb) n
    8                        sum+=i;
    (gdb) p i
    $3 = 2
    (gdb) n
    6                for(i=1; i<=n; i++)
    (gdb) p sum
    $4 = 3
    (gdb) bt        <--------------------- 查看函数堆栈。
    #0  func (n=250) at tst.c:5
    #1  0x080484e4 in main () at tst.c:24
    #2  0x400409ed in __libc_start_main () from /lib/libc.so.6
    (gdb) finish    <--------------------- 退出函数。
    Run till exit from #0  func (n=250) at tst.c:5
    0x080484e4 in main () at tst.c:24
    24              printf("result[1-250] = %d /n", func(250) );
    Value returned is $6 = 31375
    (gdb) c     <--------------------- 继续运行。
    Continuing.
    result[1-250] = 31375    <----------程序输出。Program exited with code 027. <--------程序退出,调试结束。
    (gdb) q     <--------------------- 退出gdb。
    hchen/test>好了,有了以上的感性认识,还是让我们来系统地认识一下gdb吧。
      

  50.   

    gdb基本常用命令介绍1。break(b) line/b func----设置断点,在代码行处/函数处
    2。info break----列出所有设置的断点情况
    3。next(n)----程序单步执行,跳过函数调用,对应step
    4。step----程序单步执行,进入函数调用
    5。continue(c)----程序执行执行,停在下一个断点处,没断点就执行完成
    6。print(p) /x i/j/k----打印调试上下文的临时变量
    7。x /u 0x30000000----按格式查看内存地址存储的数值
    8。list----列出程序的源代码,按行
    9。bt Backtrace----显示程序堆栈信息
    10。watch----使你能监视一个变量的值而不管它何时被改变
    11。finish---- 继续执行,直到当前函数返回
    12。quit----退出gdb.
      

  51.   

    使用gdb调试程序详解----gdb基本命令介绍
    http://blog.csdn.net/xqhrs232/article/details/7492955三.gdb的命令字介绍
    我们简要介绍一下在gdb调试中需要用到的命令字
    file [filename]
          装入想要调试的可执行文件
    kill [filename]
          终止正在调试的程序
    break [file:]function
          在(file文件的)function函数中设置一个断点
    clear
          删除一个断点,这个命令需要指定代码行或者函数名作为参数
    run [arglist]
          运行您的程序 (如果指定了arglist,则将arglist作为参数运行程序)
    bt Backtrace
          显示程序堆栈信息
    print expr
          打印表达式的值
    continue
          继续运行您的程序 (在停止之后,比如在一个断点之后)
    list
          列出产生执行文件的源代码的一部分
    next
          单步执行 (在停止之后); 跳过函数调用(与step相对应,step会进入函数内部)
    nexti
          执行下一行的源代码中的一条汇编指令
    set
          设置变量的值。例如:set nval=54 将把54保存到nval变量中;设置输入参数也可以通过这个命令(例如当三个入参分别为a、b、c的话,set args a b c)
    step
          单步执行 (在停止之后); 进入函数调用
    stepi
          继续执行程序下一行源代码中的汇编指令。如果是函数调用,这个命令将进入函数的内部,单步执行函数中的汇编代码
    watch
          使你能监视一个变量的值而不管它何时被改变
    rwatch
          指定一个变量,如果这个变量被读,则暂停程序运行,在调试器中显示信息,并等待下一个调试命令。参考rwatch和watch命令
    awatch
          指定一个变量,如果这个变量被读或者被写,则暂停程序运行,在调试器中显示信息,并等待下一个调试命令。参考rwatch和watch命令
    Ctrl-C
          在当前位置停止执行正在执行的程序,断点在当前行
    disable
          禁止断点功能,这个命令需要禁止的断点在断点列表索引值作为参数
    display
          在断点的停止的地方,显示指定的表达式的值。(显示变量)
    undisplay
          删除一个display设置的变量显示。这个命令需要将display list中的索引做参数
    enable
          允许断点功能,这个命令需要允许的断点在断点列表索引值作为参数
    finish
          继续执行,直到当前函数返回
    ignore
          忽略某个断点制定的次数。例:ignore 4 23 忽略断点4的23次运行,在第24次的时候中断
    info [name]
          查看name信息
    load
          动态载入一个可执行文件到调试器
    xbreak
          在当前函数的退出的点上设置一个断点
    whatis
          显示变量的值和类型
    ptype
          显示变量的类型
    return
          强制从当前函数返回
    txbreak
          在当前函数的退出的点上设置一个临时的断点(只可使用一次)
    make
          使你能不退出 gdb 就可以重新产生可执行文件
    shell
          使你能不离开 gdb 就执行 UNIX shell 命令
    help [name]
          显示GDB命令的信息,或者显示如何使用GDB的总体信息
    quit
          退出gdb.
      

  52.   

    显示下面基本可以表明成功----包括JAVA层断点设置是OK的了0xafd0c738 in __futex_syscall3 ()
       from E:/DirectX/Android_NDK_JNI/android-ndk-r5-windows/android-ndk-r5/samples/NDKOpenGL_Test/obj/local/armeabi/libc.so
    (gdb) b 639
      

  53.   

    通过malloc分配的指针free释放后,在GDB下print怎么是下面的情况(gdb) p change_data
    $7 = (unsigned char *) 0x4ae02008 <Address 0x4ae02008 out of bounds>
      

  54.   


    上面的表示内存没有分配成功,已经释放的意思?因为malloc的情况如下
    (gdb) p change_data
    $3 = (unsigned char *) 0x4ae02008 ""是不是表明不存在什么内存没释放的问题?
      

  55.   

    logcat输出如下消息,不知道为什么。
    call to OpenGL ES API with no current context (logged once per thread)
      

  56.   

    释放使用指针的指针所分配到的空间
    http://blog.sina.com.cn/s/blog_5fd9454d0100drfw.html  delete 指针的指针(或者指针数组)  这几天碰到程序中内存被不断吞噬的问题,怎么找都没发现,后来经一个一个排除,抓出了这个内鬼,释放指针的指针的空间时,只释放了一次,以下是一个例子,说明如何解决这个问题。以指针的指针为例,指针数组的原理也一样。  假设:char **p=new char *[total*pa*sizeof(char)];       for(int i=0,i<total;i++)       {           p[i]=new int[pa];        }  .........................................以上定义了一个指针的指针p,并为他分配了空间。下面进行空间的释放。       for(int i=0,i<total;i++)       {          delete []p[i];        }         delete []p;        p=NULL;.....................................到此分配的空间完全被吐了出来(小样,看你下次还敢吃我内存)一定要记住,对于指针的指针这类空间的释放问题,不是一次释放就可以的,要与分配时相对应。呵呵,就到这了。