From 14d9c1881d476e606c6665c80449bfc55db3babd Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Thu, 15 Jun 2023 17:28:35 +0200 Subject: [PATCH] proc: only print warning when gopclntab can not be read for first image (#3420) Only print the warning that gopclntab can not be read for the first image (i.e. the executable file), also change the returned when neither DWARF nor gopclntab are found to preserve the DWARF error. --- pkg/proc/bininfo.go | 11 +++++++---- pkg/proc/pclntab.go | 5 ++--- pkg/proc/proc_test.go | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/proc/bininfo.go b/pkg/proc/bininfo.go index 3deafc67..9ade7bdc 100644 --- a/pkg/proc/bininfo.go +++ b/pkg/proc/bininfo.go @@ -1443,16 +1443,19 @@ func loadBinaryInfoElf(bi *BinaryInfo, image *Image, path string, addr uint64, w bi.loadBuildID(image, elfFile) var debugInfoBytes []byte - image.dwarf, err = elfFile.DWARF() - if err != nil { + var dwerr error + image.dwarf, dwerr = elfFile.DWARF() + if dwerr != nil { var sepFile *os.File var serr error sepFile, dwarfFile, serr = bi.openSeparateDebugInfo(image, elfFile, bi.DebugInfoDirectories) if serr != nil { - fmt.Fprintln(os.Stderr, "Warning: no debug info found, some functionality will be missing such as stack traces and variable evaluation.") + if len(bi.Images) <= 1 { + fmt.Fprintln(os.Stderr, "Warning: no debug info found, some functionality will be missing such as stack traces and variable evaluation.") + } symTable, err := readPcLnTableElf(elfFile, path) if err != nil { - return fmt.Errorf("could not create symbol table from %s ", path) + return fmt.Errorf("could not read debug info (%v) and could not read go symbol table (%v)", dwerr, err) } image.symTable = symTable for _, f := range image.symTable.Funcs { diff --git a/pkg/proc/pclntab.go b/pkg/proc/pclntab.go index 34515332..a2f23b94 100644 --- a/pkg/proc/pclntab.go +++ b/pkg/proc/pclntab.go @@ -61,10 +61,9 @@ func readPcLnTableElf(exe *elf.File, path string) (*gosym.Table, error) { // Find .gopclntab by magic number even if there is no section label magic := magicNumber(bi.GoVersion) pclntabIndex := bytes.Index(tableData, magic) - if pclntabIndex < 0 { - return nil, fmt.Errorf("could not find magic number in %s ", path) + if pclntabIndex >= 0 { + tableData = tableData[pclntabIndex:] } - tableData = tableData[pclntabIndex:] addr := exe.Section(".text").Addr lineTable := gosym.NewLineTable(tableData, addr) symTable, err := gosym.NewTable([]byte{}, lineTable) diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index 10f7876d..6c5065fb 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -3169,6 +3169,7 @@ func TestDebugStripped(t *testing.T) { // Currently only implemented for Linux ELF executables. // TODO(derekparker): Add support for Mach-O and PE. skipUnlessOn(t, "linux only", "linux") + skipOn(t, "does not work with PIE", "pie") withTestProcessArgs("testnextprog", t, "", []string{}, protest.LinkStrip, func(p *proc.Target, grp *proc.TargetGroup, f protest.Fixture) { setFunctionBreakpoint(p, t, "main.main") assertNoError(grp.Continue(), t, "Continue")