Skip to content
Snippets Groups Projects
Commit 50ccbe1f authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder
Browse files

cmd/internal/objfile: emit trailing tab outside of Disasm.Decode

Disasm.Decode currently always appends a tab to the formatted instruction,
although not to any relocations after it.

Decode has two clients: objdump and pprof.
pprof emits plain text, so it would be better not to have a trailing tab.
objdump wants the trailing tab for text/tabwriter,
but it is easy to add that to the Fprintf call.

Shifting the responsibility for the trailing tab to the caller
simplifies the code, increases correctness, and slightly improves
performance by reducing and coalescing string concatenations.

Change-Id: I0c85518ee185949e385de819e2e703bce757eba9
Reviewed-on: https://go-review.googlesource.com/106983


Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 4c15fdb3
No related branches found
No related tags found
No related merge requests found
...@@ -253,7 +253,7 @@ func (d *Disasm) Print(w io.Writer, filter *regexp.Regexp, start, end uint64, pr ...@@ -253,7 +253,7 @@ func (d *Disasm) Print(w io.Writer, filter *regexp.Regexp, start, end uint64, pr
fmt.Fprintf(tw, "%08x", d.byteOrder.Uint32(code[i+j:])) fmt.Fprintf(tw, "%08x", d.byteOrder.Uint32(code[i+j:]))
} }
} }
fmt.Fprintf(tw, "\t%s\n", text) fmt.Fprintf(tw, "\t%s\t\n", text)
}) })
tw.Flush() tw.Flush()
} }
...@@ -274,15 +274,10 @@ func (d *Disasm) Decode(start, end uint64, relocs []Reloc, f func(pc, size uint6 ...@@ -274,15 +274,10 @@ func (d *Disasm) Decode(start, end uint64, relocs []Reloc, f func(pc, size uint6
i := pc - d.textStart i := pc - d.textStart
text, size := d.disasm(code[i:], pc, lookup, d.byteOrder) text, size := d.disasm(code[i:], pc, lookup, d.byteOrder)
file, line, _ := d.pcln.PCToLine(pc) file, line, _ := d.pcln.PCToLine(pc)
text += "\t" sep := "\t"
first := true
for len(relocs) > 0 && relocs[0].Addr < i+uint64(size) { for len(relocs) > 0 && relocs[0].Addr < i+uint64(size) {
if first { text += sep + relocs[0].Stringer.String(pc-start)
first = false sep = " "
} else {
text += " "
}
text += relocs[0].Stringer.String(pc - start)
relocs = relocs[1:] relocs = relocs[1:]
} }
f(pc, uint64(size), file, line, text) f(pc, uint64(size), file, line, text)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment