Generate Core Dump for Mono C# Application
Asked Answered
P

4

6

I am currently working on a c# linux application being run under mono. Although, I believe I've handled any possible exceptions that might be thrown within my program, but should I have missed any, I was wondering if there is a way that when the C# application crashes it creates a core dump file so I can see the exception and go through it to try and determine what caused the problem like GDB does for C programs.

I'm using OpenSuse 12.1 for my application.

Thanks for any help you can provide.

Plumley answered 20/8, 2012 at 21:52 Comment(0)
S
0

Yes, you can, but you can only find out what .NET exception happened, dunno if you can do a core dump without third-party softwere though.

Depending on the type of the application you can hook one of the following events:

  • if you use Windows Forms Application you could subscribe to System.Windows.Forms.Application.ThreadException

  • if you use WPF you could subscribe to System.Windows.Threading.Dispatcher UnhandledException

  • if you want to subscribe to a general UnhandledException event, you could subscribe to System.AppDomain.UnhandledException (but I guess if the application don't have enough access can't access this event).

Stunner answered 31/8, 2012 at 7:12 Comment(1)
Thanks for your help, this was the perfect solution, although doesn't generate a coredump but in some ways this works better as I can handle what to do if an unhandled exception occurs. I.e. write to my log file with the stacktrace and innerexception. Thanks againPlumley
P
1

Sounds like you want a SuperAssert for Mono. I could only find this Mono mail thread. They discuss the possible conversion of the Managed Debugger to Mono. Unfortunately the Microsoft EULA appears to have prevented them from porting this one. Therefore it looks like you'll need to use the Operating System directly. Here is the official guide on how you capture a core dump

The following steps should be taken to prepare for capturing a core dump:

-Disable the limit for the maximum size of a core dump file
-Configure a fixed location for storing core dumps
-Disable AppArmor
-Enable core dumps for setuid and setgid processes

The quick step guide for this is as follows:

Run

ulimit -c unlimited

Run

install -m 1777 -d /var/local/dumps

Run

echo "/var/local/dumps/core.%e.%p"> /proc/sys/kernel/core_pattern

Run

rcapparmor stop

Run

sysctl -w kernel.suid_dumpable=2

(Re)start problematic processes.

Also take a look at this thread: Core dump in Linux - if you think the app might crash, maybe you could setup a technical support helper script/exe to perform all the above actions and launch the Mono application. This would make it easy for end user to reproduce the problem and send you the dump to diagnose the problem.

Pedro answered 2/9, 2012 at 2:5 Comment(0)
T
0

You may want to look at the sources of bug-buddy.

Tjirebon answered 21/8, 2012 at 11:52 Comment(0)
T
0

Have you seen the following?

http://www.mono-project.com/Debugging#Debugging_with_GDB

Transhumance answered 29/8, 2012 at 11:19 Comment(0)
S
0

Yes, you can, but you can only find out what .NET exception happened, dunno if you can do a core dump without third-party softwere though.

Depending on the type of the application you can hook one of the following events:

  • if you use Windows Forms Application you could subscribe to System.Windows.Forms.Application.ThreadException

  • if you use WPF you could subscribe to System.Windows.Threading.Dispatcher UnhandledException

  • if you want to subscribe to a general UnhandledException event, you could subscribe to System.AppDomain.UnhandledException (but I guess if the application don't have enough access can't access this event).

Stunner answered 31/8, 2012 at 7:12 Comment(1)
Thanks for your help, this was the perfect solution, although doesn't generate a coredump but in some ways this works better as I can handle what to do if an unhandled exception occurs. I.e. write to my log file with the stacktrace and innerexception. Thanks againPlumley

© 2022 - 2024 — McMap. All rights reserved.