碰到调试JNI_CreateJavaVM时SIGSEGV fault错误的解决方案

调试时出现 Signal received: SIGSEGV (Segmentation fault) 比较烦。在 jni.cpp 的 JNI_CreateJavaVM 设置断点调试。不同 jdk 版本路径不同。(编译调试 openjdk 的惨痛经历 - 简书)

这是因为:

测试本来就是要触发SIGSEGV的。而GDB在调试的时候会在程序注册的signal handler之前先获取到signal,要continue才会跑到应用注册的signal handler去。

解决方法

在openjdk的根目录上创建一个.gdbinit,这个文件的作用是为gdb在运行前提供配置信息

在Netbeans里面设置,右键项目->属性->调试,在“Gdb初始化文件”里面设置刚创建的文件

handle SIGSEGV pass noprint nostop
handle SIGUSR1 pass noprint nostop
handle SIGUSR2 pass noprint nostop
set logging on
set breakpoint pending on

为了方便其他国家的程序员,我翻译英文如下:

It is annoying to encounter "Signal received: SIGSEGV (Segmentation fault)" when you make a breakpoint at JNI_CreateJavaVM in jni.cpp.

Reason:

Because the purpose of debuging is to trigger SIGSEGV, and gbd must catch the signal before the program registers signal handler.

Solution:

Create a .gdbinit in the root of openjdk, this is for providing configuring infomation for gdb running.

In Netbeans, right click the project that you made, select "properties", select "debug", fill in the .gdbinit file path and the name in the "Gdb initial file"

handle SIGSEGV pass noprint nostop
handle SIGUSR1 pass noprint nostop
handle SIGUSR2 pass noprint nostop
set logging on
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
在安卓JNI中,__FUNCTION__是一个预定义的宏,它可以返回当前函数的名称。它通常用于在调试或日志输出中显示当前函数的名称。在引用中,__FUNCTION__被用于显示正在执行的函数名称为AndroidRuntime::startVm。这个函数是用来启动虚拟机的,并且它的执行流程与sigchain_dummy不同,因此不会调用到sigchain_dummy这里。在引用中,__FUNCTION__没有被直接使用,但是在初始化操作的过程中,可能会使用其它函数来回调Java函数,并且使用__FUNCTION__来记录相关的日志信息。因此,__FUNCTION__主要是用来在日志或调试中标识当前函数的名称。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [安卓高版本c/c++调用java,通过JNI_CreateJavaVM/JNI_GetCreatedJavaVMs创建虚拟机实例](https://blog.csdn.net/zs787055144/article/details/131322208)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [JNI_OnLoad和JNI_OnUnload](https://blog.csdn.net/zhao007z5/article/details/80064818)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值