[symbolize] Fix bug in backtrace presenter

There was a bug in the backtrace presenter where header was assumed to be
non-nil. This caused a null reference exception when I tried to test kernel
crash symbolization.

Bug: ZX-2060 #comment Fix symbolize to handle no headers
Change-Id: Ief6f1d09280f5478b56d0fe0f80e71016aa47cdb
diff --git a/symbolize/demuxer_test.go b/symbolize/demuxer_test.go
index aa3cb73..11fbfe7 100644
--- a/symbolize/demuxer_test.go
+++ b/symbolize/demuxer_test.go
@@ -223,6 +223,47 @@
 	//[131.604] 01234.05678> Error at atan2 at atan2.c:49
 }
 
+func ExampleNoHeaderBacktrace() {
+	// mock the input and outputs of llvm-symbolizer
+	symbo := newMockSymbolizer([]mockModule{
+		{"testdata/libc.elf", map[uint64][]SourceLocation{
+			0x429c0: {{NewOptStr("math.h"), 51, NewOptStr("__DOUBLE_FLOAT")}, {NewOptStr("atan2.c"), 49, NewOptStr("atan2")}},
+			0x43680: {{NewOptStr("pow.c"), 23, NewOptStr("pow")}},
+			0x44987: {{NewOptStr("memcpy.c"), 76, NewOptStr("memcpy")}},
+		}},
+	})
+
+	// mock ids.txt
+	repo := NewRepo()
+	repo.AddSource(testBinaries)
+
+	// make a demuxer
+	demuxer := NewDemuxer(repo, symbo)
+
+	// define a little message that will need to be parsed
+	msg := "{{{module:1:libc.so:elf:4fcb712aa6387724a9f465a32cd8c14b}}}\n" +
+		"{{{mmap:0x12345000:0xcf6bc:load:1:rx:0x0}}}\n" +
+		"Backtrace:\n" +
+		"{{{bt:0:0x12388680}}}\n" +
+		"{{{bt:1:0x123879c0}}}\n"
+
+	// start sending InputLines to the demuxer
+	ctx := context.Background()
+	in := StartParsing(ctx, strings.NewReader(msg))
+	// start the demuxer which will cause filters to send output lines to 'out'
+	out := demuxer.Start(ctx, in)
+
+	Consume(ComposePostProcessors(ctx, out,
+		&FilterContextElements{},
+		NewBacktracePresenter(os.Stdout, NewBasicPresenter(os.Stdout, false))))
+
+	//Output:
+	//Backtrace:
+	//     #0    0x0000000012388680 in pow pow.c:23 <libc.so>+0x43680
+	//     #1.1  0x00000000123879c0 in __DOUBLE_FLOAT math.h:51 <libc.so>+0x429c0
+	//     #1    0x00000000123879c0 in atan2 atan2.c:49 <libc.so>+0x429c0
+}
+
 func ExampleNewBacktracePresenter() {
 	// mock the input and outputs of llvm-symbolizer
 	symbo := newMockSymbolizer([]mockModule{
diff --git a/symbolize/presenter.go b/symbolize/presenter.go
index 0049ac1..abae231 100644
--- a/symbolize/presenter.go
+++ b/symbolize/presenter.go
@@ -28,13 +28,17 @@
 
 func printBacktrace(out io.Writer, hdr LineHeader, frame uint64, info addressInfo) {
 	modRelAddr := info.addr - info.seg.Vaddr + info.seg.ModRelAddr
+	var hdrString string
+	if hdr != nil {
+		hdrString = hdr.Present()
+	}
 	if len(info.locs) == 0 {
-		fmt.Fprintf(out, "%s    #%-4d %#016x in <%s>+%#x\n", hdr.Present(), frame, info.addr, info.mod.Name, modRelAddr)
+		fmt.Fprintf(out, "%s    #%-4d %#016x in <%s>+%#x\n", hdrString, frame, info.addr, info.mod.Name, modRelAddr)
 		return
 	}
 	for i, loc := range info.locs {
 		i = len(info.locs) - i - 1
-		fmt.Fprintf(out, "%s    ", hdr.Present())
+		fmt.Fprintf(out, "%s    ", hdrString)
 		var frameStr string
 		if i == 0 {
 			frameStr = fmt.Sprintf("#%d", frame)