From 9076056c7086253cf8ec9c8cb63f7ec87fffcb48 Mon Sep 17 00:00:00 2001 From: tschundler Date: Thu, 30 May 2019 08:11:21 -0700 Subject: [PATCH] proc: Less confusing error message for requesting break on blank line. (#1556) The current wording is confusing - the file exists and the line exists, so what is the problem? I suspect this ambiguity is behind #1496 and likely others. Also I updated the style to return values like the rest of the code in the file, which is also more readable (IMO and per https://github.com/golang/go/wiki/CodeReviewComments#named-result-parameters) --- pkg/proc/bininfo.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/proc/bininfo.go b/pkg/proc/bininfo.go index 8a729230..724864f9 100644 --- a/pkg/proc/bininfo.go +++ b/pkg/proc/bininfo.go @@ -381,28 +381,30 @@ func (bi *BinaryInfo) PCToLine(pc uint64) (string, int, *Function) { // LineToPC converts a file:line into a memory address. func (bi *BinaryInfo) LineToPC(filename string, lineno int) (pc uint64, fn *Function, err error) { + fileFound := false for _, cu := range bi.compileUnits { if cu.lineInfo.Lookup[filename] != nil { - pc = cu.lineInfo.LineToPC(filename, lineno) + fileFound = true + pc := cu.lineInfo.LineToPC(filename, lineno) if pc == 0 { // Check to see if this file:line belongs to the call site // of an inlined function. for _, ifn := range cu.concreteInlinedFns { if strings.Contains(ifn.CallFile, filename) && ifn.CallLine == int64(lineno) { - pc = ifn.LowPC - fn = ifn.Parent - return + return ifn.LowPC, ifn.Parent, nil } } } - fn = bi.PCToFunc(pc) - if fn != nil { - return + if fn := bi.PCToFunc(pc); fn != nil { + return pc, fn, nil } } } - err = fmt.Errorf("could not find %s:%d", filename, lineno) - return + if fileFound { + return 0, nil, fmt.Errorf("could not find statement at %s:%d, please use a line with a statement", filename, lineno) + } else { + return 0, nil, fmt.Errorf("could not find file %s", filename) + } } // AllPCsForFileLine returns all PC addresses for the given filename:lineno.