Why your Android NDK breakpoints might fail and how to fix them

android-build-debug.apk 毕业设计成果安装包 立即下载

Why your Android NDK breakpoints might fail and how to fix them

Ivan Shcherbakov,  1 Nov 2013  CPOL
Rate this:  
This article explains why the breakpoints in native Android code might fail and how to fix them

Overview

This article shows why your breakpoints in native Android code might fail and how to fix them.

Introduction

First of all, let's get an overview of the structure of a typical Android app containing native code:

The app code is stored inside a .apk file that is essentially a Zip archive containing the classes.dex file (with all the Java code) and one or more native libraries in the lib\<EABI name> subdirectory. The typical lifecycle of an application with native code is the following:

  1. The Android OS loads the Java code and starts executing it
  2. The Java code calls System.loadLibrary() to load a native library.
  3. The Java code starts calling functions from the native code.

Each native library exists in two versions:

  •  A "full" version debugging information that associates code addresses inside the library with source files and lines. This version resides in obj\local\armeabi under your project directory.
  • A "stripped" version without the debugging information that resides in libs\armeabi and gets packaged into the APK file.

While the Android device runs the smaller "stripped" version of the library, the GDB debugger needs the larger "non-stripped" version to map source files into addresses and vice versa:

Setting breakpoints 

When you set a breakpoint on a given line of a source file, the GDB debugger needs to perform certain computations before the breakpoint can be physically created and starts triggering. Assume libNative1 is loaded at address 0x10000 and the user is setting a breakpoint in line 24 of c:\main.cpp. GDB will do the following before it can set a breakpoint:

  1. GDB starts searching all loaded libraries for the file called "c:\main.cpp". In this example the Android OS only reports the libNative1.so library.
  2. GDB looks inside obj\local\armeabi for a file called libNative1.so which is the "non-stripped" version of the library containing the debug information. GDB reads the symbol table from it and finds c:\main.cpp inside it.
  3. Based on the symbol table GDB computes that line 24 corresponds to offset +0x2. It adds 0x2 to the load address of libNative1.so (0x10000) and sets the breakpoint at 0x10002.

If any of the three steps fail, the breakpoint will not be created, or will be created wrongly and will never be hit. The next section explains how to diagnose and fix the related problems.

Diagnosing the problems

This section provides detailed instructions how to check for the most common problems with breakpoints caused by non-standard configurations or missing files:

A. Ensure that the library is loaded

First thing to do is to determine if the native library has been actually loaded and if GDB knows about it. It is done by running the "info shared" command in GDB:

The output from the info shared command should include three important lines:

  1. Loaded symbols for "linker"
  2. Loaded symbols for "libc.so"
  3. Loaded symbols for all native libraries you want to debug.

Here's an example of those lines:

From       To         Syms Read       Shared Object Library
                       No com.visualgdb.example.MyAndroidApp
0xb0001000 0xb00069d0 Yes C:/.../AndroidBinaryCache/.../linker
0x40073300 0x400a12fc Yes C:/.../AndroidBinaryCache/.../libc.so
0x5148fccc 0x51491198 Yes E:/.../obj/local/armeabi/libMyAndroidApp.so

If some of the libraries are not present, you can force GDB to manually reload the symbols by running the following command in GDB:

sharedlibrary 

If your .so library (e.g., libMyAndroidApp.so) is listed, but the symbols are not loaded ("Syms read" states "no"), GDB was not able to find a non-stripped version of the library. To fix it please run the "show solib-search-path" command in GDB:

The obj/local/armeabi directory of your project should be present among the reported directories and it should contain the .so file with symbols. If not, copy the correct .so file into a directory listed here and rerun the "sharedlibrary" command.

You can alternatively force GDB to search additional directories for the .so file using the set solib-search-pathcommand.

If your .so library is not present in the list, it has not been loaded by the Java code yet. Please ensure thatSystem.loadLibrary() is called from your Java code and that it succeeds without any Java exceptions.

B. Ensure that you are using correct file paths

A common cause of many breakpoint problems is a configuration when the directories using for building and debugging your project are different. E.g., if the library was compiled from c:\projects and then the sources were moved to d:\projects, setting a breakpoint in d:\projects\main.cpp will fail, as GDB will not acceptc:\projects\main.cpp as a substitute.

Those problems can be diagnosed by looking into the source file lists and comparing them with the file used to set a breakpoint. First of all, remove your breakpoint, try setting your breakpoint again and watch what GDB command is issued by your IDE:

The -break-insert command used to set a breakpoint will specify a path to your source file.

Run the "info sources" command to see the source files discovered by GDB:

Copy the output of the command to the clipboard (Ctrl-A, Ctrl-C), paste it into a text editor and search for the source file you are trying to debug (e.g., MyAndroidApp.c):

If the file is not present in the list, you have loaded a wrong version of the .so file (see previous section). If the file is present, but the path is different from the one used in -break-insert command, you have found the cause of your problem. Rebuild your app using the new path, or move the file back to an old location so that the path used for creating breakpoints matches the path reported by the "info sources" command.

Note that GDB requires the file path to be EXACTLY the same as reported by "info sources", including double slash before "jni".

C. Recheck file versions and do a clean build

If your breakpoints are set, but never hit, there is probably a mismatch between the .so file version loaded into the Android application and the .so file version used by GDB to compute addresses from source lines. The most common cause for it is the bug in the Android loader that loads the armeabi library instead of the armeabi-v7aversion. If you suspect this to happen, change your build configuration to build either armeabi, or armeabi-v7aplatform, but not both at the same time and rebuild your application.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Android Studio导入Project与Module的方法及实例 主要介绍了Android Studio导入Project与Module的方法及实例的相关资料,需要的朋友可以参考下 立即下载

相关推荐

显卡代码43故障全面解析与解决方案

显卡代码43是Windows系统中常见的硬件报错,通常由驱动问题或硬件异常引起。驱动作为硬件与操作系统间的桥梁,其兼容性和完整性直接影响显卡性能。通过DDU工具彻底卸载旧驱动、安装WHQL认证版本等操作可解决大部分软件问题。在硬件层面,检查PCIe插槽连接、电源供电等基础设置同样关键。对于游戏玩家和内容创作者,定期更新专用驱动能提升系统稳定性。本文详细介绍了从驱动管理到硬件检测的全套解决方案,帮助用户高效排除代码43故障。

weixin_28684825的博客 132

Navicat 连接Oracle时提示oracle library is not loaded的问题解决

一、我连接的是阿里云服务器上的Oracle数据库 二、刚开始我下载最新版本Instant Client 发现不好用还是报oracle library is not loaded。换了个低版本的可以连接不在报错。 下面具体步骤 1.连接Oracle时提示“oracle library is not loaded”。 2.直接下载Oracle Instant Client Downloads。...

未曾远去 7万+

在Windows 11上用VirtualBox搞定WRF-Hydro 5.2.0:一个水文模型小白的Ubuntu 22.04虚拟机避坑实录

本文详细记录了在Windows 11上使用VirtualBox和Ubuntu 22.04虚拟机成功编译安装WRF-Hydro 5.2.0水文模型的全过程。从虚拟环境配置、依赖库安装到环境变量设置,作者分享了针对Linux新手的实用避坑技巧和关键命令,帮助科研人员高效完成水文模型的环境搭建。

weixin_30733003的博客 359

Android 问题集(最新更新2020-9-28)

记录一些代码小细节 1.Android 启动页android.intent.action.MAIN,启动模式不能设置为singleTask 这样会使你每次回到手机主页,再次进入APP,回到启动页。 如果真的要将之前的启动页设置singleTask。可以将启动页换成一张空白页。 空白页上直接调转到之前的启动页上。 例子:我之前的启动页是一张登录页面。登录页面需要将启动模式设置为single...

R_ine的博客 569

西红柿成熟度检测数据集总结

成熟度类别标注数量semiripe(半成熟)10275rotten(腐烂)13470fullyripe(完全成熟)35031unripe(未成熟)26212。

crz1336768325的博客 2146

信号完整性仿真SI之Cadence Sigrity SPEED2000_眼图仿真(四)

今天给大家分享一个仿真的操作流程,是关于Cadence Sigrity SPEED2000的时域波形仿真和眼图仿真。我们会经常看见硬件工程师调试示波器上的一些信号的波形变化,其实这些也可以通过仿真电路的搭建来做出投板前的仿真,来优化走线,以减少版本的迭代次数。如果要和实际的信号保持一致,就要求仿真设置的参数和实际的参数保持一致,这也是仿真的重点和难点。下面先让我们了解一下Cadence Sigrity SPEED2000时域仿真的操作流程: 1.仿真模式选择与文件导入 选择Cadence Sigrity下的

刘小同学的博客 1万+

Android 实战开发 第三方SDK 30分钟集成融云IM 即时通讯

使用融云 IMKit 集成了会话界面,并且提供了丰富的自定义功能, IMKit 方便集成和开发,30分钟打造一个IM 强大的即时通讯聊天功能。

奈曼-皮尔逊准则

奈曼-皮尔逊准则 如果各个假设的先验概率P(Hi)(i=0,1)P(H_i)(i=0,1)P(Hi​)(i=0,1)已知,并且每种判决的代价函数已知,这时,可以用贝叶斯准则进行判决。 如果进一步假设正确判决不付出的代价,而错误判决代价相同,即c00=c11=0,c01=c10=1c_{00}=c_{11}=0,c_{01}=c_{10}=1c00​=c11​=0,c01​=c10​=1,这时可以用最小平均错误概率准则进行判决。 在不知道先验概率P(Hi)(i=0,1)P(H_i)(i=0,1)P(Hi​)(

little_soldier的专栏 1万+

android studio 错误总结

minSdkVersion 15 cannot be smaller than version 16 Error:Execution failed for task':app:processDebugManifest'. &gt; Manifest merger failed :uses-sdk:minSdkVersion 15 cannot be smaller than version 1...

aidezhanxian的博客 8855

SwinTransformer改进(5):与CBAM结合的视觉模型

这个模型的核心思想是将Swin Transformer的强大特征提取能力与CBAM的注意力机制相结合,以提升模型对重要特征的关注度。​​CBAM模块​​:包含通道注意力和空间注意力两个子模块​​Swin Transformer主干网络​​:作为基础特征提取器​​集成结构​​:在Swin Transformer的不同阶段插入CBAM模块使用移动窗口(Moving Window)机制减少计算量层次化设计,特征图逐渐缩小,通道数逐渐增加在不同阶段使用Patch Merging进行下采样。

2401_82355416的博客 693

【从零开始vnpy量化投资】十一. 实盘接入测试与正式实盘

本篇主要讲解如何使用vnpy进行实盘交易,由于上一节我们已经学习了模拟盘运行,如果一切顺利的话,只需要通过穿透测试,就可以正式部署实盘了。

魔落的博客 4237

AndroidStudio2022 导入OpenCV3.2

去,然后进行编译,编译的时候有可能会报错,错误是Cannot read packageName from XXXX\XXX.....\AndroidManifest.xml。第二中方法就是把代码直接复制到android studio中。

蜗牛牛的博客 823

Python 爬虫实战:分析 AJAX 请求抓取搜狐新闻数据

在Web 2.0时代,大量网站采用AJAX技术实现动态内容加载。传统基于静态HTML解析的爬虫技术(如BeautifulSoup)已无法应对这类场景。本文将以搜狐新闻为实战目标,详解如何通过分析AJAX请求接口实现动态新闻数据的精准抓取。

yansideyucsdn的博客 1756

从intellij转as的一个问题

导入module的时候提示 specify location of the gradle or android 经测试时因为该module文件目录下缺少 src 文件夹

u011833275的博客 1581

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

关于向android studio导入项目,gradle报错的问题

重新导入项目时,android studio报了这个错误,gradle project sync failed.Basic functionality(e.g.editing,debugging) will not work properly.  和Gradle project sync failed.  按照网上找到方法点击file->settings,搜索Gradle,在右侧选择    

suoliwa的专栏 1709

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Android:从Eclipse到Android Studio迁移工程

Migrating from Eclipse See also Eclipse Compatibility ModeFAQ on Migrating If you've previously developed for Android using Eclipse and would like to migrate to Android Studio, you sh

ultrapro的专栏 1429

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Cannot create android app from an archive...containing both DEX and Java-bytecode content

问题描述 D8: Cannot create android app from an archive 'C:\Users\ado\.gradle\caches\transforms-2\files-2.1\3aa879f694b1137d653976ac38fcf06f\xxx\jars\classes.jar' containing both DEX and Java-bytecode content FAILURE: Build failed with an exception. * What we

adojayfan的博客 868

containing both DEX and Java-bytecode content 错误

场景: 1、在framework中添加自定义的jar 2、需要在源码环境下生成jar包,但是不能暴露源代码。 生成jar包的android.mk: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(call all-java-files-under, core/java) #LOCAL_MODULE_TAGS := optinal LOCAL_MODULE := xxframework inc

zyfzhangyafei的专栏 636

Flutter如何使用本地公共项目

正在制作的游戏分为两个项目,一是游戏本体,二是关卡编辑器,两个项目需要共用文件,但是事情进行的并不顺利,最终采用了下面的方法 在pubspec.yaml中直接导入package项目 dependencies: meaty_plant_public_package: path: 完整本地路径,到项目文件夹 之前采用的方式是import moudle,但是不好使。 发生过如下问题: 1、...

流浪的独角兽的博客 2312

Android Gradle学习(四) Project详解

每一个 build.gradle 脚本文件被 Gradle 加载解析后,都会对应生成一个 Project 对象,在脚本中的配置方法其实都对应着 Project 中的API,如果想详细了解这些脚本的配置含义,有必要对 Project 类做些深入的剖析。 1. Project类图 当构建进程启动后,Gradle基于build.gradle中的配置实例化org.gradle.api.Project类,先...

假装你是大灰狼的专栏 2757

Android Studio导入Project、Module的正确方法

Gradle Project项目、Module模块导入最近看到网上很多人在抱怨,Android Studio很难导入github上下载下来的一些项目,主要包括:1、导入就在下载Gradle2、根本导不进下面我分2部分来讲解正确的导入姿势:1、导入完整的Github Project我们在github上找一个项目工程目录如上,里面的东西其实分为2部分,工程相关和项目相关工程相关用于配置整个项目的编译环

eclipse_xu 11万+

Java bytecode library

最近恰巧看到关于java字节码

流浪的咖啡的专栏 676

解决:The specified Gradle installation directory

编译老项目出现的如下异常:The specified Gradle installation directory 'D:\开发软件\android-studio-ide-141.2456560-windows\android-studio\gradle\gradle-2.8' does not exist。1、打开顶部菜单:File -> Setting -> Build,Execution,Deployment -> BuildTools -> Gradle。

shenggaofei的博客 4561

Android开发中遇到的错误处理汇总(持续更新)

————————————- read the fucking source code——————————– Android开发中经常会遇到一些没处理过的错误,一时也不知道怎么处理,后来通过百度才知其所以然。为了方便在Android开发过程中提高错误处理效率,特在这篇文章中汇总错误的现象及处理的办法。欢迎评论补充修正。 1.Error:Unrecognized Windows Socke...

技术总结之路~ 9402

eclipse集成安卓环境

所以希望在下载eclipse的时候,一定要看清楚eclipse的版本。Android SDK提供了开发Android应用程序所需的API库和构建、测试和调试Android应用程序所需的开发工具。ADT 需要安装ADT开发工具,打造了一个安卓开发环境,包括创建安卓开发实例,执行和除错,全部添加到eclipse环境中。这个问题新建项目的时候,最低版本不要选择太低,否则就回出现这个问题。上一步装完之后,就可以新建android项目,如下所示。8、先运行自己的虚拟机,然后再运行自己的项目。工具栏中有这两个按钮。

weixin_51357991的博客 1200
上一篇: Quick tips on changing ndk-gdb interface
下一篇: Eclipse+CDT+GDB调试android NDK程序
xingxiliang
博客等级 码龄20年 321粉丝 113原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值