{"record":{"id":"f93ea745e9d8292c","repo":"go-delve/delve","slug":"reading-debug-info-file-index-d-out-of-range-i","errorCode":null,"errorMessage":"reading debug_info: file index (%d) out of range in compile unit file table at %#x","messagePattern":"reading debug_info: file index \\((.+?)\\) out of range in compile unit file table at %#x","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/bininfo.go","lineNumber":3253,"sourceCode":"\n// cuFilePath takes a compilation unit \"cu\" and a file index reference\n// \"fileidx\" and returns the corresponding file name entry from the\n// DWARF line table associated with the unit; \"entry\" is the offset of\n// the attribute where the file reference originated, for logging\n// purposes. Return value is the file string and an error value; error\n// will be non-nil if the file could not be recovered, perhaps due to\n// malformed DWARF.\nfunc (cu *compileUnit) filePath(fileidx int, entry *dwarf.Entry) (string, error) {\n\tif cu.lineInfo == nil {\n\t\treturn \"\", fmt.Errorf(\"reading debug_info: file reference within a compilation unit without debug_line section at %#x\", entry.Offset)\n\t}\n\t// File numbering is slightly different before and after DWARF 5;\n\t// account for this here. See section 6.2.4 of the DWARF 5 spec.\n\tif cu.Version < 5 {\n\t\tfileidx--\n\t}\n\tif fileidx < 0 || fileidx >= len(cu.lineInfo.FileNames) {\n\t\treturn \"\", fmt.Errorf(\"reading debug_info: file index (%d) out of range in compile unit file table at %#x\", fileidx, entry.Offset)\n\t}\n\treturn cu.lineInfo.FileNames[fileidx].Path, nil\n}\n","sourceCodeStart":3235,"sourceCodeEnd":3257,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/bininfo.go#L3235-L3257","documentation":"Returned by (*compileUnit).filePath (pkg/proc/bininfo.go:3253) when a DIE's file index, after DWARF<5 decrement adjustment, is negative or beyond the CU's line-program FileNames table. This means the DWARF references a file that the debug_line file table does not contain — i.e., inconsistent DWARF between debug_info and debug_line.","triggerScenarios":"A DW_AT_decl_file / DW_AT_call_file attribute value that exceeds the number of entries in the CU's file_names list (DWARF 2-4 indices are 1-based, DWARF 5 is 0-based; the code adjusts with fileidx-- for Version<5); mixing object files compiled with different DWARF versions into one binary; a truncated debug_line section.","commonSituations":"Linking C/C++ or assembly objects compiled with a different DWARF version than the Go objects (e.g. old gcc emitting DWARF 4 into a DWARF 5 link), partial LTO/objcopy processing that rewrote one section but not the other, third-party prebuilt static libraries with stale DWARF.","solutions":["Rebuild all objects with a consistent DWARF version (e.g. force -gdwarf-4 or -gdwarf-5 uniformly across gcc/cgo flags).","Check for stale third-party .a/.o files compiled with mismatched DWARF and rebuild them from source.","Upgrade Delve — file-index handling across DWARF versions has had fixes; an older Delve may mis-handle DWARF 5 tables.","Inspect the failing CU with `readelf --debug-dump=info` and `--debug-dump=rawline` to confirm the file index vs table size mismatch and identify the offending object."],"exampleFix":"// before: mixed DWARF versions from cgo\ngo env -w CGO_CFLAGS=\"-O2\"\n\n// after: pin DWARF version for all C bits\ngo env -w CGO_CFLAGS=\"-O2 -gdwarf-4\"","handlingStrategy":"validation","validationCode":"# Check DWARF version consistency across objects in the binary:\nreadelf --debug-dump=info ./app | grep -m5 \"Version:\"   # CU versions\nreadelf --debug-dump=rawline ./app | head -40           # file table vs DIE file indices","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"out of range in compile unit file table\") {\n    return fmt.Errorf(\"inconsistent DWARF (file index vs line table); rebuild with uniform -gdwarf-4/-gdwarf-5: %w\", err)\n}","preventionTips":["Pin one DWARF version for the whole build (all cgo/C flags and linker inputs).","Rebuild vendored/third-party static libraries from source instead of using stale prebuilt objects.","Upgrade Delve when switching to a toolchain emitting newer DWARF (e.g. DWARF 5).","Sanity-check fresh builds with readelf dumps in CI before shipping debug artifacts."],"tags":["go","dwarf","debug-info","file-index","version-mismatch"],"backgroundTag":"dwarf-file-index-out-of-range","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}