Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6169957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:56:52+00:00 2026-05-23T22:56:52+00:00

I failed to debug the native program with NDK toolchain. Follows are my detailed

  • 0

I failed to debug the native program with NDK toolchain. Follows are my detailed steps and output.

Env Setting:

NDK_ROOT=/opt/android/ndk
SYSROOT=$NDK_ROOT/platforms/android-8/arch-arm
TOOLCHAIN=$NDK_ROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
PATH=$TOOLCHAIN:$NDK_ROOT:$PATH

Source: hello.c

 1    #include <stdio.h>
 2   
 3    int main() {
 4      printf("Hello World!\n");
 5      return 0;
 6    }

Build by the standalone toolchain provied by NDK.

#arm-linux-androideabi-gcc -g hello.c -o hello --sysroot $SYSROOT 

Push to the emulator and start the gdbserver (I forward the port already)

#adb push hello /data/hello
#adb shell gdbserver 10.0.2.15:10000 /data/hello

Debug remotely in another terminal:

#arm-linux-androideabi-gdb
#(gdb) target remote localhost:10000
Remote debugging using :10000
0xb0001000 in ?? ()       ------------------------------------what is this?
#(gdb) symbol-file hello
Reading symbols from hello...done.
#(gdb) l
1    #include <stdio.h>
2   
3    int main() {
4      printf("Hello World!\n");
5      return 0;
6    }
#(gdb)  b main
Breakpoint 1 at 0x8318: file hello.c, line 4.
#(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.  -------It should be break at main function, but segmentation falut.  

0xafd0f5f0 in ?? ()
#(gdb) bt
#0  0xafd0f5f0 in ?? ()

And I test it with NDK Android.mk style, it woks fine. Here is the output

Android.mk

1. LOCAL_PATH := $(call my-dir)
2.
3. include $(CLEAR_VARS)
4.
5. LOCAL_MODULE    := hello
6. LOCAL_SRC_FILES := hello.c
7. LOCAL_MODULE_TAGS := optional
8.
9. include $(BUILD_EXECUTABLE)

Build, push to emulator, start debug server

   #ndk-build
   #push obj/local/armeabi/hello /data/hello
   #adb shell gdbserver 10.0.2.15:10000 /data/hello

Debug remote:

#arm-linux-androideabi-gdb
(gdb) target remote :10000
Remote debugging using :10000
0xb0001000 in ?? ()  --------------still here
(gdb) symbol-file hello
Reading symbols from hello...done.
(gdb) l
1    #include <stdio.h>
2   
3    int main() {
4      printf("Hello World!\n");
5      return 0;
6    }
(gdb) b main
Breakpoint 1 at 0x8372: file hello.c, line 4.
(gdb) c
Continuing.

Breakpoint 1, main () at hello.c:4
4      printf("Hello World!\n");
(gdb) c
Continuing.

Program exited normally.      -------Yes, erverything is normal, Hello World is output.

Still build with Android.mk by ndk-build, when i do something else in gdb remote, still failed.

(gdb) target remote :10000
Remote debugging using :10000
0xb0001000 in ?? ()
(gdb) symbol-file hello
Reading symbols from hello...done.
(gdb) l
1    #include <stdio.h>
2   
3    int main() {
4      printf("Hello World!\n");
5      return 0;
6    }
(gdb) b main
Breakpoint 1 at 0x8372: file hello.c, line 4.
(gdb) next
Cannot access memory at address 0x0
Cannot find bounds of current function
(gdb) c
Continuing.

Breakpoint 1, main () at hello.c:4
4      printf("Hello World!\n");
(gdb) next
6    }
(gdb) next

Program received signal SIGSEGV, Segmentation fault. ------Again fault. And no "Hello World" output in gdbserver.
0x0000832c in ?? ()
(gdb) next
Cannot find bounds of current function

===============================================================

I am fresh on android, anyone can tell me what is happening ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:56:53+00:00Added an answer on May 23, 2026 at 10:56 pm

    I don’t know why gdb works with the binary by ndk-build, but use file command instead of symbol-file command, it might work. gdb needs to know the image of the remote executed program.

    (gdb) file hello
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any failed ASSERT statements on Windows cause the below debug message to appear and
Any suggestions? C:\Users\Steve\barcoden>gem install ruby-debug Building native extensions. This could take a while... ERROR:
Sometimes my c++ program crashes in debug mode, and what I got is a
I have a native c++ program exe which builds successfully and runs successfully in
I am concatenating several strings. When running the program it gives me a Debug
I'm trying to use new OpenCV feature on Android: native camera access. According to
Exception: Failed to compare two elements in the array. private void assignNames(DropDownList ddl, Hashtable
I failed to find a way to disable the browser detection feature added by
Target failed to run: Remote exception encountered: Faild to get task for pid 3103
My Google-fu has failed me. In Python, are the following two tests for equality

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.