Re:D 2.069.0 released, compiler automatically ported from C+...
by WalterBright on Wednesday November 04, 2015 @12:02PM
(#10507909)
Replace: Greetings g = null;
with: auto g = new Greetings();
[ Parent
| on HN ]
Re:D 2.069.0 released, compiler automatically ported from C+...
by thepumpkin1979 on Wednesday November 04, 2015 @12:18PM
(#10508015)
I'm intentionally making it null to see how the new backtraces work.
I know it's because I'm trying to call a method on "null", but If I'm working on a huge code base, how do I debug this kind of issues if I don't have stack trace with line and error number of the error?
I'd like to get at least the stack trace and the error number with the line of the source code that caused the problem, like in golang:
$ cat main.go
package main
type Greetings struct {
}
func (g Greetings) hello() {
}
func main() {
g := &Greetings{} // heap instance
g = nil // intentionally shooting myself in the foot like I did in D
g.hello()
}
$ go run main.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x2025]
goroutine 1 [running]:
main.main()
/Users/ride/Documents/main.go:13 +0x15
goroutine 2 [runnable]:
runtime.forcegchelper()
/opt/boxen/homebrew/Cellar/go/1.4.2/libexec/src/runtime/proc.go:90
runtime.goexit()
/opt/boxen/homebrew/Cellar/go/1.4.2/libexec/src/runtime/asm_amd64.s:2232 +0x1
exit status 2
Re:D 2.069.0 released, compiler automatically ported from C+...
by destructionator on Wednesday November 04, 2015 @01:48PM
(#10508603)
null deference in D doesn't throw exceptions by default on Unix so you won't see the backtrace there.
If you are working in a big codebase and have this come up, you can enable core dumps and run it in a debugger to get far more information than just a line number (and line numbers are there too at least if compiled in debug mode).
Re:D 2.069.0 released, compiler automatically ported from C+...
by thepumpkin1979 on Wednesday November 04, 2015 @02:31PM
(#10508978)
does this mean there is not a way to get stack trace on OSX?
Re:D 2.069.0 released, compiler automatically ported from C+...
by EvenThisAcronym on Wednesday November 04, 2015 @03:20PM
(#10509362)
I have not tried it myself but there seem to be ways to get a stack trace on Linux.
Re:D 2.069.0 released, compiler automatically ported from C+...
by destructionator on Wednesday November 04, 2015 @06:24PM
(#10510543)
I don't know about an automatic one, but running the debugger would still work there too. Or at least it should.