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.
This commit is contained in:
Alessandro Arzilli 2023-06-15 17:28:35 +02:00 committed by GitHub
parent 95dac8f19b
commit 14d9c1881d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

@ -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 {

@ -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)

@ -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")