Debug library file C/C++ code via a small demo

In C/C++ cross-platform development, we know that it is very convenient to perform single-step breakpoint debugging through VS on Windows. But if we compile the dynamic library so, we want to track its process and various stages, for example, how to track the internal demux process of FFmpeg/VLC, or the Codec process? Today, the Debug library file C/C++ code is used through a small demo.

First, download the NDK and build tools To compile and debug the native code (naTIve code), you need the following components:

1. The Android NaTIve Development Kit (NDK): A tool set that allows you to use C and C++ code on Android.

2. CMake external build tool. If you are going to use only ndk-build, you can not use it.

3, LLDB: Android Studio above to debug the native code of the craftsman.

Note: To use CMake or ndk-build in Android Studio, you need to use Android Studio 2.2 or higher and also need to use Android Plugin for Gradle 2.2.0 and above.

Install the above components:

If SDK Tools does not display LLDB, CMake and NDK, you have configured a domestic mirror site!

To be able to display on the official website of google, before through the domestic image, has not been displayed!

Tools > Android > SDK Manager > Click on the SDK Tools tab. Check LLDB, CMake and NDK.

Debug library file C/C++ code via a small demo

I have downloaded android-ndk-r11b separately and no longer download NDK! (preferably check the latest NDK) Click Apply, then click OK.

Second, new projects:

1, hook include C + + support

2, in the final step you can choose a different C + + library

Android Studio how to debug the corresponding so file C / C + + code

Note: Although it supports C/C++, it does not fully support all the features of C/C++. It must be in accordance with the jni convention: you can refer to the jni manual C++ Standard: Select the C++ library.

Toolchain Default: Default CMake settings

C++ 11: Support for C++11 features!

ExcepTIons Support(-fexcepTIons):

Check this if you want to use support for C++ exception handling. When checked, Android Studio adds the -fexcetions flag to cppFlags in the build.gradle file of the module layer.

Runtime Type Information Support (-frtti): Check this if you want to support RTTI. When checked, Android Studio adds the -frtti flag to cppFlags in the build.gradle file of the module layer.

Description:

Native-lib.cpp: automatically generated C++ source files

CMakeLists.txt: The CMake script compiles a C++ source file, which is native-lib.cpp, according to the instructions of the build script, and throws the compiled product into the shared object library and names it libnative-lib.so. Gradle then packages it into the APK.

External Build Files The place to store CMake or ndk-build build scripts. A bit like the build.gradle file tells Gradle how to compile your app, CMake and ndk-build also need a script to tell you how to compile your native library.

1, just configure the buildTypes under the android tag node

Debug library file C/C++ code via a small demo

a, select run drop item, select Edit Configurations, pop up the configuration form

b, click âž•New configuraionts, select android native entry

c. Configure the name of the native execution as follows: hellojniNative.

d, select the real machine or simulator debugging.

Breakpoint debugging run

Debug library file C/C++ code via a small demo

Figure 1, Figure 2 is two ways to run app-native, select app-native, debug->app-native; Next you can step through the C/C++ file.

Here is a question, if it is a compiled dynamic library .so file with signed tables, how to debug? Interested readers can leave a message.

310V 40Ah High Voltage Lithium Battery

310v high voltage Lithium Battery , 40Ah

310V 40ah stakable lithium ion battery


high voltage lithium ion battery

ShenZhen UFO Power Technology Co., Ltd. , https://www.ufobattery.com

Posted on