dereferencing null

Walter Bright newshound2 at digitalmars.com
Mon Mar 5 02:38:20 PST 2012


On 3/4/2012 11:50 PM, Chad J wrote:
> Problems:
> - I have to rerun the program in a debugger to see the stack trace. This is a
> slow workflow. It's a big improvement if the segfault is hard to find, but only
> a small improvement if the segfault is easy to find. Very bad if I'm prototyping
> experimental code and I have a bunch to go through.

I don't get this at all. I find it trivial to run the program with a debugger:

   gdb foo
   >run

that's it.

> - It only gives one line number. I imagine there's a way to get it to spill the
> rest? At least it's the most important line number. Nonetheless, I commonly
> encounter cases where the real action is happening a few levels into the stack,
> which means I want to see ALL the line numbers /at one time/.

That's because the runtime library is compiled without debug symbols in it. If 
it was compiled with -g, the line numbers would be there. You of course can 
compile the library that way if you want. Debug symbols substantially increase 
your program size.


> - As I mentioned in another post, it is unreasonable to expect others to run
> your programs in a debugger. I like it when my users can send me stacktraces.
> (And they need to have ALL the line numbers displayed with no extra coercion.)
> There are a number of occasions where I don't even need to ask how to reproduce
> the bug, because I can just tell by looking at the trace. Super useful!

I agree that customers emailing you a stack trace is a reasonable point. Andrei 
also brought up the point of the problems with using a debugger on a remote 
server machine.


> I wouldn't even expect ALL hardware errors to be instrumented in the compiler.
> At least get the common ones. Null dereference is remarkably common. I can't
> actually think of others I care about right now. Array boundary errors and
> assertions already seem to have their own exceptions now; they were great pests
> back in the day when this was not so.

No hardware support for them, so no choice.


> The error messages could use a lot of work
> though. (Range Violation should print the index used and the index boundaries,
> and simpler assertions such as equality should print the values of their operands.)

The added bloat for this would be substantial.


> I'm pretty sure other languages like C# and Java get this right. Haven't used
> those two in a while though. Haxe... totally got this right. Also Actionscript 3
> by proxy. Hell, even Synergy/DE, the DIBOL (!!) derivative that I use at work,
> /gets this right/. I get stacktraces for null dereferences in these languages.
> It's /really/ convenient and useful. I consider D to be very backwards in this
> regard.

Notably, C and C++ do not do what you suggest.


More information about the Digitalmars-d mailing list