错误:在Mono上运行应用程序时出现SIGSEGV



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

我有一个非常基本的C#Windows窗体应用程序,我可以在Windows上编译并运行它。不过,整个项目都是为了在Pi上工作而设计的,所以我把项目移到了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中编译并跨窗口复制,都会发生这种情况。此外,编译一个基本的helloworld脚本也很好,所以它可能与Windows.Forms或MySql.Data有关。此外,PI正在运行Debian。

仔细阅读您的问题后,我可以看到它是特定的segfault,表示Cannot access memory at address 0x0,所以它可能访问了由于错误而返回的指针。例如,程序要求类似的东西,给我字体X的句柄,而函数由于某种原因返回了空指针。你可以尝试一些可能的解决方案:

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

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

  • https://github.com/mono/mono/blob/master/mcs/class/System.Drawing/System.Drawing/Font.cs#L58
  • https://github.com/mono/libgdiplus/blob/master/src/font.c#L800

旧答案:

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

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

handle SIGXCPU SIG33 SIG35 SIGPWR nostop noprint

在GDB会话期间。

答案是更新到mono的最新版本,并确保它在软浮点debian上运行。

通过以下线程找到答案http://www.raspberrypi.org/phpBB3/viewtopic.php?f=66&t=11634

相关内容

最新更新