Let’s start small, how to screw the Android NDK to C::B

There are two ways:

Solution features with ndk-build:

Android NDK Integration



The ideology and manner of building an application using the Android NDK toolchain is as close as possible to the typical behavior of C::B, the process logic:

Template files:

The project itself C::B, important sections:

The <Extensions><debugger><remote_debugging> section contains settings for remote debugging implemented with GDB:

AndroidNdkTemplate.cbp - the project file C::B.

If during the launch of the assembled application on the device you experience the following errors:

WARNING: linker: /data/local/tmp/youprog: unused DT entry: type 0x6ffffef5 arg 0x4040
WARNING: linker: /data/local/tmp/youprog: unused DT entry: type 0x6ffffffe arg 0x5a34
WARNING: linker: /data/local/tmp/youprog: unused DT entry: type 0x6fffffff arg 0x2

Use android-elf-cleaner
These errors are typical for the binary file of the platform armeabi-v7a, they were later corrected in the latest versions of libraries.

Download android-elf-cleaner v.0.0.14.79/win32 (07.03.2019)

Source assembly control files in the NDK project directory:


Application.mk - set the build parameters.
Android.mk - this is the make-up file unique for each NDK project (application).
Makefile - C::B starts directly:

The Application.mk and Makefile files are universal for all projects collected using NDK and do not require revisions.
To understand the structure of where the application lies in the project NDK, I will give a tree

│   Android.mk
│   AndroidNdkTemplate.cbp
│   Application.mk
│   main.c
│   Makefile
│   
├───libs
│   ├───arm64-v8a
│   │       gdb.setup
│   │       gdbserver
│   │       hello_world
│   ├───armeabi-v7a
│   │       gdb.setup
│   │       gdbserver
│   │       hello_world
│   ├───x86
│   │       gdb.setup
│   │       gdbserver
│   │       hello_world
│   └───x86_64
│           gdb.setup
│           gdbserver
│           hello_world
│           
└───obj
    └───local
        ├───arm64-v8a
        │   │   hello_world
        │   ├───objs
        │   │   └───hello_world
        │   └───objs-debug
        │       └───hello_world
        │               main.o
        │               main.o.d
        ├───armeabi-v7a
        │   │   hello_world
        │   │   
        │   ├───objs
        │   │   └───hello_world
        │   └───objs-debug
        │       └───hello_world
        │               main.o
        │               main.o.d
        ├───x86
        │   │   hello_world
        │   │   
        │   ├───objs
        │   │   └───hello_world
        │   └───objs-debug
        │       └───hello_world
        │               main.o
        │               main.o.d
        └───x86_64
            │   hello_world
            │   
            ├───objs
            │   └───hello_world
            └───objs-debug
                └───hello_world
                        main.o
                        main.o.d

View of project settings from GUI C::B:


Image1

Image2

Image3

Image4

Be sure to indicate the possible paths where the object files with debugging symbols are located:

Image5

It is necessary to add the GDB commands that transmit information about the finding of debugging symbols for the platform of the connected device:

Type of compiler settings in C::B:


Image6

Image7

Image8

Additional NDK application debug menu:


Both scripts used in the menu have a fixed name and are automatically generated during execution of Makefile, for convenience, it is reasonable to add them to the menu:

Image11

Image12

The debugging method of the application consists of standard actions, for example through F8 or the menu Debugging -> Start. As soon as the debugger is launched, you need to call the ADB Debug Remote server item from the created menu; with this command you will start the GDB server on the device that will start your application. You connect to the GDB server remotely and can conduct a debugging session.
In Debug mode, the remote server is started automatically and does not require calling this menu item.
See a screenshot of the debugger settings in the project above.

This debugger startup scheme supports non-rooted devices.

Global debager settings for NDK look like this:


Image13

Debugging on device:


Image14

Result of assembling an application with NDK:


Image10

The advantages of using NDK in contrast to the static assembly for a specific platform:

Download:


The full code NDK C::B template is located in the C::B template directory
The installer page NDK C::B template

Discussion on ru.stackoverflow.com

License

MIT