dereferencing null

Jonathan M Davis jmdavisProg at gmx.com
Mon Mar 5 19:51:28 PST 2012


On Monday, March 05, 2012 21:04:20 Steven Schveighoffer wrote:
> On Mon, 05 Mar 2012 20:17:32 -0500, Michel Fortin
> 
> <michel.fortin at michelf.com> wrote:
> > That said, throwing an exception might not be a better response all the
> > time. On my operating system (Mac OS X) when a program crashes I get a
> > nice crash log with the date, a stack trace for each thread with named
> > functions, the list of all loaded libraries, and the list of VM regions
> > dumped into ~/Library/Logs/CrashReporter/. That's very useful when you
> > have a customer experiencing a crash with your software, as you can ask
> > for the crash log. Can't you do the same on other operating systems?
> 
> It depends on the OS facilities and the installed libraries for such
> features.  It's eminently possible, and I think on Windows, you can catch
> such exceptions too in external programs to do the same sort of dumping.
> On Linux, you get a "Segmentation Fault" message (or nothing if you have
> no terminal showing the output), and the program goes away.  That's the
> default behavior.  I think it's better in any case to do *something* other
> than just print "Segmentation Fault" by default.  If someone has a way to
> hook this in a better fashion, we can include that, but I hazard to guess
> it will not be on stock Linux boxes.

All you have to do is add a signal handler which handles SIGSEV and have it 
print out a stacktrace. It's pretty easy to do. It _is_ the sort of thing that 
programs may want to override (to handle other signals), so I'm not quite sure 
what the best way to handle that is without causing problems for them (e.g. 
initialization order could affect which handler is added last and is therefore 
the one used). Maybe a function should be added to druntime which wraps the 
glibc function so that programs can add their signal handler through _it_, and 
if that happens, the default one won't be used.

Regardless, I'm not sure whether the functions involved are POSIX or not, so I 
don't know whether it'll work on anything besides Linux. It would still be of 
benefit even if it were Linux-only though.

- Jonathan M Davis


More information about the Digitalmars-d mailing list