cmd/compile: improve debugging output for GOSSAFUNC

This changes the assembly language output to use the
innermost (instead of outermost) position for line
number and file.

The file is printed separately, only when it changes,
to remove redundant and space-consuming noise from the
output.

Unknown positions have line number "?"

The output format was changed slightly to make it
easier to read.

One source of gratuitous variation in debugging output was
removed.

Change-Id: I1fd9c8b0ddd82766488582fb684dce4b04f35723
Reviewed-on: https://go-review.googlesource.com/78895
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
David Chase 2017-11-20 16:47:08 -05:00
parent 4a3d408d18
commit bd41c6783b
6 changed files with 40 additions and 19 deletions

View file

@ -18,26 +18,25 @@ func (p *Prog) Line() string {
return p.Ctxt.OutermostPos(p.Pos).Format(false, true)
}
// LineNumber returns a string containing the line number for p's position
func (p *Prog) LineNumber() string {
pos := p.Ctxt.OutermostPos(p.Pos)
// InnermostLineNumber returns a string containing the line number for the
// innermost inlined function (if any inlining) at p's position
func (p *Prog) InnermostLineNumber() string {
pos := p.Ctxt.InnermostPos(p.Pos)
if !pos.IsKnown() {
return "?"
}
return fmt.Sprintf("%d", pos.Line())
}
// FileName returns a string containing the filename for p's position
func (p *Prog) FileName() string {
// TODO LineNumber and FileName cases don't handle full generality of positions,
// but because these are currently used only for GOSSAFUNC debugging output, that
// is okay. The intent is that "LineNumber()" yields the rapidly varying part,
// while "FileName()" yields the longer and slightly more constant material.
pos := p.Ctxt.OutermostPos(p.Pos)
// InnermostFilename returns a string containing the innermost
// (in inlining) filename at p's position
func (p *Prog) InnermostFilename() string {
// TODO For now, this is only used for debugging output, and if we need more/better information, it might change.
// An example of what we might want to see is the full stack of positions for inlined code, so we get some visibility into what is recorded there.
pos := p.Ctxt.InnermostPos(p.Pos)
if !pos.IsKnown() {
return "<unknown file name>"
}
return pos.Filename()
}