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

3

尝试了几个小时都无法让它正常工作后,我决定是时候发帖求助了。

我有一个相当基础的 C# Windows Forms 应用程序,在Windows上可以编译和运行得很好。整个项目的设计是为了在树莓派上运行,所以我将项目移到了树莓派上并进行了编译。花费了几个小时终于使其编译成功(发现我需要引用 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有关。另外,树莓派正在运行Debian。


1
更好的问题可能是,如何在Linux中调试SIGSEGV。 - Wayneio
你可以使用 mono --trace 来更好地了解正在发生的事情。要获取最详细的信息,您需要一个带有 mono 支持和带有调试信息的 mono 库的 gdb - Jester
2个回答

2
仔细阅读您的问题后,我发现出现了一个特定的段错误,提示“无法访问地址0x0的内存”,因此可能是由于错误返回的指针导致的。例如,程序要求类似“给我字体X的句柄”的东西,但某个函数由于某种原因返回了空指针。以下是您可以尝试的一些可能解决方案:
  • 从源代码编译mono,在失败的函数附近设置断点并逐步观察变量值,也许它们会告诉您一些信息;
  • 如果还没有安装,请安装“mono-complete”软件包;
  • 尝试安装应用程序使用的字体(虽然可以从堆栈跟踪中看出应用程序正在寻找默认字体;))

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

旧回答:

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

其他可能导致错误的原因列表包括Mono bug(请提供版本号)或第三方本地库中的某种错误。对于后一种情况,确实值得使用GDB(以前使用某些调试选项编译这些库,如g3)。为了不被垃圾收集器发送的信号打扰,请记住发出以下命令:

handle SIGXCPU SIG33 SIG35 SIGPWR nostop noprint

在 GDB 会话期间。

谢谢,非常好的回复。我该如何确保所有UI控件都在同一个线程上运行?至于第三方本地库,我也尝试了基本的Windows窗体应用程序,但仍然出现错误。Mono版本是Mono JIT编译器版本2.10.8.1(Debian 2.10.8.1-5)。错误提到了系统字体。 - Wayneio
1
@Wayneio 关于“如何从同一线程中运行所有 UI 控件”的问题:如果您想从另一个线程操纵 UI,请使用 Control.Invoke() 与适当的委托函数。这将把委托传递给拥有您要影响的控件的线程,并在那里运行它:正是您所需要的。有点像他们为这些情况设计了这个功能 :D - Mark

1

树莓派镜像在几年前曾经是armel(软浮点),但现在似乎所有可用的树莓派镜像都是armhf(硬件浮点)。您知道是否有一个良好的软浮点镜像适用于树莓派并且仍在维护中,或者您听说过其他解决此SIGSEGV问题的方法吗? - David Grayson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接