【问题标题】:Error: SIGSEGV when running application on Mono错误:在 Mono 上运行应用程序时出现 SIGSEGV
【发布时间】:2012-11-12 11:47:26
【问题描述】:

经过几个小时的努力,我决定是时候发布了。

我有一个非常基本的 C# Windows 窗体应用程序,我可以在 Windows 上编译和运行它。整个项目设计为在 Pi 上工作,所以我将项目移到它上面并编译。经过几个小时终于让它编译(发现我必须引用 MySql.Data.dll 文件)它编译没有错误!

然后我跑了

Mono Administration.exe

我遇到了这个巨大的错误,我在网上几乎找不到:

pi@raspberrypi /media/WAYNEIO/pi/ProjectNibiru/ProjectNibiru $ mono Administration.exe
Stacktrace:

  at System.Drawing.Font.CreateFont (string,single,System.Drawing.FontStyle,System.Drawing.GraphicsUnit,byte,bool) <0x00143>
  at System.Drawing.Font..ctor (string,single,System.Drawing.FontStyle,System.Drawing.GraphicsUnit,byte,bool) <0x0007f>
  at System.Drawing.Font..ctor (string,single,string) <0x00057>
  at (wrapper remoting-invoke-with-check) System.Drawing.Font..ctor (string,single,string) <0xffffffff>
  at System.Drawing.SystemFonts.get_DefaultFont () <0x00073>
  at System.Windows.Forms.Theme..ctor () <0x0002f>
  at System.Windows.Forms.ThemeWin32Classic..ctor () <0x00013>
  at System.Windows.Forms.ThemeVisualStyles..ctor () <0x00013>
  at System.Windows.Forms.ThemeEngine..cctor () <0x0007f>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
  at System.Windows.Forms.X11DesktopColors..cctor () <0x000bb>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
  at System.Windows.Forms.XplatUIX11..ctor () <0x001af>
  at System.Windows.Forms.XplatUIX11.GetInstance () <0x00073>
  at System.Windows.Forms.XplatUI..cctor () <0x00157>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
  at System.Windows.Forms.Application.EnableVisualStyles () <0x00023>
  at ProjectNibiru.Program.Main () <0x0000b>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:


Debug info from gdb:

Cannot access memory at address 0x0
Cannot access memory at address 0x0
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
[New Thread 0x4093b460 (LWP 2224)]
0x40085f30 in read () from /lib/arm-linux-gnueabihf/libpthread.so.0
  Id   Target Id         Frame
  2    Thread 0x4093b460 (LWP 2224) "mono" 0x40084d84 in sem_wait@@GLIBC_2.4 () from /lib/arm-linux-gnueabihf/libpthread.so.0
* 1    Thread 0x400cd000 (LWP 2223) "mono" 0x40085f30 in read () from /lib/arm-linux-gnueabihf/libpthread.so.0

Thread 2 (Thread 0x4093b460 (LWP 2224)):
#0  0x40084d84 in sem_wait@@GLIBC_2.4 () from /lib/arm-linux-gnueabihf/libpthread.so.0
#1  0x00195a40 in mono_sem_wait ()
#2  0x000ea384 in ?? ()
#3  0x000ea384 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 1 (Thread 0x400cd000 (LWP 2223)):
#0  0x40085f30 in read () from /lib/arm-linux-gnueabihf/libpthread.so.0
#1  0x40085770 in __pthread_enable_asynccancel () from /lib/arm-linux-gnueabihf/libpthread.so.0
#2  0x00000000 in ?? ()

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

Aborted

谁能提供关于为什么会出现这种情况以及如何解决问题的建议?

注意事项;无论我是使用“Xbuild”还是使用“dmcs”编译,还是在 Windows 中编译并复制,都会发生这种情况。编译一个基本的 hello world 脚本也可以正常工作,所以它可能与 Windows.Forms 或 MySql.Data 有关。 PI 也在运行 Debian。

【问题讨论】:

  • 更好的问题可能是,如何在 linux 中调试 SIGSEGV
  • 您可以使用mono --trace 更好地了解正在发生的事情。对于大多数细节,您需要一个支持单声道的 gdb 和带有调试信息的单声道库。

标签: c# mono debian segmentation-fault raspberry-pi


【解决方案1】:

更仔细地阅读您的问题后,我可以看到它是特定的段错误说Cannot access memory at address 0x0,所以它可能访问指针因为错误而返回。例如,程序要求像 give me handle to font X 和函数出于某种原因返回空指针。您可以尝试一些可能的解决方案:

  • 从源代码编译单声道,在失败的函数附近设置断点并在观察变量值的同时进行单步执行,也许它们会告诉你一些事情;
  • 如果你还没有安装mono-complete 包;
  • 尝试安装此应用程序使用的字体(尽管可以从堆栈跟踪中得知该应用程序正在寻找默认字体;))

您还可以查看来源。有趣的部分可能是:

旧答案:

这里没有太多细节,但是每当我遇到 Windows 窗体应用程序的段错误时,我的第一个猜测是某些 UI 控件是从不同的 UI 线程访问的。很多时候,相同的应用程序不会在 Windows 窗体的 MS 实现上崩溃,但这种方法是不正确的。也许这是你的问题?

其他可能的错误原因列表包括 Mono 错误(给我们版本号)或第三方本机库中的某种错误(如果使用)。对于后一种情况,确实值得使用 GDB(以前使用一些调试选项编译这些库,如 g3)。为了不受垃圾收集器发送的信号的干扰,请记住发出

handle SIGXCPU SIG33 SIG35 SIGPWR nostop noprint

在 GDB 会话期间。

【讨论】:

  • 谢谢,很好的回复。如何确保所有 UI 控件都在同一个线程上运行?至于第三方本机库,我也尝试了一个基本的 Windows 窗体应用程序,但仍然出现错误。单声道版本是 Mono JIT 编译器版本 2.10.8.1 (Debian 2.10.8.1-5)。错误提到系统字体
  • @Wayneio 至于“如何从同一个线程运行所有 UI 控件”:如果您想从另一个线程操作 UI,请使用具有合适委托函数的 Control.Invoke()。这会将委托交给拥有您要影响的控件的线程并在那里运行它:正是您要查找的内容。有点像他们为这样的情况做的:D
【解决方案2】:

这个问题的答案是更新到最新版本的 mono,并确保它在 soft-float debian 上运行。

通过关注这个帖子http://www.raspberrypi.org/phpBB3/viewtopic.php?f=66&t=11634找到答案

【讨论】:

  • 几年前 Raspberry Pi 映像曾经是 armel(软浮点),但现在似乎所有现成的 Raspberry Pi 映像都是 armhf(硬件浮点)。您是否知道仍在维护的 Raspberry Pi 的良好软浮动映像,或者您是否听说过此 SIGSEGV 的任何其他解决方案?
猜你喜欢
  • 2017-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-14
  • 2018-08-26
  • 1970-01-01
相关资源
最近更新 更多