当前位置: 首页 > 面试题库 >

为什么Java应用程序在gdb中崩溃但在现实生活中可以正常运行?

衡修洁
2023-03-14
问题内容

尝试从gdb运行Java应用程序会导致segfault,但单独运行应用程序不会。这个应用程序是一个.JAR文件,它使用JOGL和一些内存映射与GPU通讯。

下面的Stacktrace暗示了某种内存访问问题,但是我不明白为什么它出现在GDB中而不是在现实生活中出现。gdb是否需要知道一些环境因素以允许正确执行?

这个问题在JVM OpenJDK 6和7以及Oracle JRE 7之间仍然存在。oracle
JRE在段故障之前运行到启动为止。否则,所有段之间在试验之间的发生和位置都是一致的。

Segfault在GPU和驱动程序之间持续存在(!!):nvidia,radeon,fglrx current和fglrx
beta(14.xx)。GDB将成功地附加到我的程序的一个已经在运行的实例,但是gDEBugger似乎无法做到这一点,这最终是需要工作的。

没有意图使用gdb进行实际调试。而是我尝试使用gDEBugger进行OpenGL调试。gDEBugger显然依赖于GDB作为其后端的一部分,因此,如果GDB失败,则gDEBugger也是如此。这导致尝试单独运行gdb来隔离问题。

gDEBugger output:
GDB String:  [Thread debugging using libthread_db enabled]  
GDB String:  Using host libthread_db library  /lib/x86_64-linux-gnu/libthread_db.so.1 .  
Thread Created: 140737353893632 (LWP: 3265)
Thread Created: 140737294624512 (LWP: 3266)
Thread Created: 140737293571840 (LWP: 3267)
Thread Created: 140737292519168 (LWP: 3268)
Thread Created: 140737155180288 (LWP: 3269)
Thread Created: 140737154127616 (LWP: 3270)
Thread Created: 140736913602304 (LWP: 3271)
Thread Created: 140736909629184 (LWP: 3272)
Thread Created: 140736908576512 (LWP: 3273)
Thread Created: 140736907523840 (LWP: 3274)
Thread Created: 140736906471168 (LWP: 3275)
Thread Created: 140736905418496 (LWP: 3276)
Thread Created: 140736278275840 (LWP: 3277)
Thread Created: 140736272963328 (LWP: 3278)
Thread Created: 140736271910656 (LWP: 3279)
Thread Created: 140736270857984 (LWP: 3280)
Thread Created: 140736269805312 (LWP: 3281)
Thread Created: 140737287657216 (LWP: 3285)
Thread Created: 140736261945088 (LWP: 3289)
GDB String:  [Thread 0x7fffb6e67700 (LWP 3289) exited]  
Thread Created: 140736261945088 (LWP: 3290)
API Connection Established: gDEBugger Servers Manager
Thread Created: 140736234641152 (LWP: 3291)
GDB String:  [Thread 0x7fffb6e67700 (LWP 3290) exited]  
API Connection Established: gDEBugger OpenGL Server
GDB String:  [Thread 0x7fffb77e8700 (LWP 3279) exited]  
GDB String:  [Thread 0x7fffb76e7700 (LWP 3280) exited]  
Debug String: gDEBugger OpenGL Server was initialized
Thread Created: 140736270857984 (LWP: 3292)
Thread Created: 140735692441344 (LWP: 3294)
Thread Created: 140735582430976 (LWP: 3295)
Thread Created: 140735574038272 (LWP: 3296)
OpenGL Render Context 1 Created
Signal: SIGSEGV
Process Exit


$ java -versionjava version "1.6.0_33"
OpenJDK Runtime Environment (IcedTea6 1.13.5) (6b33-1.13.5-1ubuntu0.14.04)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

$ gdb -version
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"

$ fglrxinfo
display: :0.0  screen: 0
OpenGL vendor string: Advanced Micro Devices, Inc.
OpenGL renderer string: AMD Radeon HD 5570     
OpenGL version string: 4.4.12967 Compatibility Profile Context 14.20


$ gdb --args java -jar RunMe.jar
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from java...Reading symbols from /usr/lib/debug//usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java...done.
done.
(gdb) show configuration
This GDB was configured as follows:
   configure --host=x86_64-linux-gnu --target=x86_64-linux-gnu
             --with-auto-load-dir=$debugdir:$datadir/auto-load
             --with-auto-load-safe-path=$debugdir:$datadir/auto-load
             --with-expat
             --with-gdb-datadir=/usr/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/lib/gdb (relocatable)
             --without-libunwind-ia64
             --with-lzma
             --with-python=/usr (relocatable)
             --with-separate-debug-dir=/usr/lib/debug (relocatable)
             --with-system-gdbinit=/etc/gdb/gdbinit
             --with-zlib
             --without-babeltrace
(gdb) run
Starting program: /usr/bin/java -jar RunMe.jar
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
process 6866 is executing new program: /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7fc4700 (LWP 6870)]
[New Thread 0x7ffff486c700 (LWP 6871)]
[New Thread 0x7ffff476b700 (LWP 6872)]
[New Thread 0x7ffff466a700 (LWP 6873)]
[New Thread 0x7fffea2d6700 (LWP 6874)]
[New Thread 0x7fffea1d5700 (LWP 6875)]
[New Thread 0x7fffea0d4700 (LWP 6876)]
[New Thread 0x7fffe9d0a700 (LWP 6877)]
[New Thread 0x7fffe9c09700 (LWP 6878)]
[New Thread 0x7fffe9b08700 (LWP 6879)]
[New Thread 0x7fffe9a07700 (LWP 6880)]
[New Thread 0x7fffe9906700 (LWP 6881)]
...
[New Thread 0x7fffe8110700 (LWP 6882)]
[New Thread 0x7fffe3169700 (LWP 6883)]
[New Thread 0x7fffe3068700 (LWP 6884)]
[New Thread 0x7fffe2f67700 (LWP 6885)]
[New Thread 0x7fffe2e66700 (LWP 6886)]
[New Thread 0x7fffe2d65700 (LWP 6887)]
[Thread 0x7fffe2d65700 (LWP 6887) exited]
[New Thread 0x7fffe2d65700 (LWP 6891)]
[Thread 0x7fffe2d65700 (LWP 6891) exited]
[New Thread 0x7fffe2d65700 (LWP 6895)]
[Thread 0x7fffe2d65700 (LWP 6895) exited]
[New Thread 0x7fffe2d65700 (LWP 6896)]
[New Thread 0x7fffe0efd700 (LWP 6897)]
libEGL warning: DRI2: failed to authenticate
[New Thread 0x7fff9799f700 (LWP 6898)]
[New Thread 0x7fff9719e700 (LWP 6899)]
[New Thread 0x7fff9699d700 (LWP 6900)]
[Thread 0x7fffe2d65700 (LWP 6896) exited]
[New Thread 0x7fffe2d65700 (LWP 6901)]
[New Thread 0x7fffe01ab700 (LWP 6902)]
[New Thread 0x7fff92f00700 (LWP 6903)]
[New Thread 0x7fff92dff700 (LWP 6904)]
[New Thread 0x7fff92cfe700 (LWP 6905)]
Setting up sound system...[New Thread 0x7fff92bfd700 (LWP 6906)]

[New Thread 0x7fff92afc700 (LWP 6907)]
[New Thread 0x7fff929fb700 (LWP 6908)]
[New Thread 0x7fff928fa700 (LWP 6909)]
[New Thread 0x7fff927f9700 (LWP 6910)]
[New Thread 0x7fff926f8700 (LWP 6911)]
[New Thread 0x7fff925f7700 (LWP 6912)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe2f67700 (LWP 6885)]
0x00007ffff6b3a770 in acl_CopyRight ()
   from /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/amd64/server/libjvm.so
(gdb) where
#0  0x00007ffff6b3a770 in acl_CopyRight ()
   from /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/amd64/server/libjvm.so
#1  0x00007ffff6d51309 in Unsafe_CopyMemory2 (env=<optimized out>, 
    unsafe=<optimized out>, srcObj=0x0, srcOffset=140737008618496, dstObj=0x0, 
    dstOffset=140737006779392, size=1024)
    at /build/buildd/openjdk-6-6b33-1.13.5/build/openjdk/hotspot/src/share/vm/prims/unsafe.cpp:689
#2  0x00007fffed011790 in ?? ()
#3  0x0000000000000400 in ?? ()
#4  0x0000000000000000 in ?? ()
Warning: the current language does not match this frame.
(gdb) quit
A debugging session is active.

    Inferior 1 [process 6866] will be killed.

Quit anyway? (y or n) y

更新: 切换到AMD CodeXL(基本上是gDEBugger的最新形式),情况并没有太大变化。


问题答案:

为什么Java应用程序在gdb中崩溃但在现实生活中可以正常运行?

因为它 实际上 并没有崩溃。

Java使用推测性负载。如果指针指向可寻址内存,则加载成功。指针很少指向可寻址的内存,并且尝试的加载会生成SIGSEGV…,java运行时会拦截它,使内存可再次寻址,然后重新启动加载指令。

在调试Java程序时,通常必须这样做:

(gdb) handle SIGSEGV nostop noprint pass

不幸的是,如果涉及到某些JNI代码,并且
代码SIGSEGV,GDB也将很乐意忽略该信号,从而导致劣等(正在调试)进程的死亡。对于后一个问题,我尚未找到可接受的解决方案。



 类似资料:
  • 我查看了错误,但我不能理解为什么它崩溃,因为它指的是主要的原因之一。 这就是我调用onCreate()中的代码以供参考的地方:

  • 问题内容: 当我从移动应用程序或Web浏览器中调用SQL存储过程时,它会返回NULL,但是使用SQLPro for MSSQL软件调用该过程时,该过程将返回它所需要的内容。 问题答案: 说明: 您需要将第一行放在存储过程中,以防止返回T-SQL语句影响的行数作为结果集的一部分。这就是产生NULL结果的原因。 如果您无法更改存储过程,请使用激活下一个结果,然后获取数据。 注意,请始终使用准备好的语句

  • 这里是我的主要活动 } 我感觉runOnUiThread方法有问题。感谢你的帮助.

  • 我试图调用ViewModel中片段中的函数,但每次调用时它都会崩溃,我不知道为什么。下面是代码: 呼吁协程: 函数的代码: 如果我不使用协同程序,只使用我收到一个错误,说我必须从其他挂起函数或协同程序调用这个函数。 这就是错误: 我的ViewModel是: 在我称之为协程的片段中,我这样声明它:

  • 问题内容: 我有以下代码: 在模拟器中工作正常。但是当我在手机上尝试时,它崩溃了。这是控制台: 这行: NSNumberFormatter()。numberFromString(display.text!)! 返回nil,这导致应用程序崩溃,导致无法打开可选包装。我真的不知道怎么了 我正在关注iTunes U中的一些教程。 任何帮助,将不胜感激。 问题答案: 尝试: 因为默认情况下使用设备区域设置

  • 我是Android开发的新手。我能够使这个应用程序在Android5.1中工作,但是,当我试图在Android4.1中部署这个应用程序时,它在主活动本身就会崩溃。我理解它,因为我使用的是矢量图像和Android4.1不兼容它。为了克服这一点,我设置了如下所述的代码: 我现在收到这个错误 代码文件 XML文件 请帮助我调试这个。我有点被困住了,需要你的帮助。