{"record":{"id":"2ab530f315a050d8","repo":"golang/go","slug":"examiner-fileref-malformed-file-reference-d","errorCode":null,"errorMessage":"Examiner.FileRef: malformed file reference %d","messagePattern":"Examiner\\.FileRef: malformed file reference (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/dwtest/dwtest.go","lineNumber":181,"sourceCode":"// (presumably from a decl_file or call_file attribute), looks up the\n// reference in the .debug_line file table, and returns the proper\n// string for it. We need to know which DIE is making the reference\n// so as to find the right compilation unit.\nfunc (ex *Examiner) FileRef(dw *dwarf.Data, dieIdx int, fileRef int64) (string, error) {\n\n\t// Find the parent compilation unit DIE for the specified DIE.\n\tcuDie := ex.ParentCU(dieIdx)\n\tif cuDie == nil {\n\t\treturn \"\", fmt.Errorf(\"no parent CU DIE for DIE with idx %d?\", dieIdx)\n\t}\n\t// Construct a line reader and then use it to get the file string.\n\tlr, lrerr := dw.LineReader(cuDie)\n\tif lrerr != nil {\n\t\treturn \"\", fmt.Errorf(\"d.LineReader: %v\", lrerr)\n\t}\n\tfiles := lr.Files()\n\tif fileRef < 0 || int(fileRef) > len(files)-1 {\n\t\treturn \"\", fmt.Errorf(\"Examiner.FileRef: malformed file reference %d\", fileRef)\n\t}\n\treturn files[fileRef].Name, nil\n}\n\n// Return a list of all DIEs with name 'name'. When searching for DIEs\n// by name, keep in mind that the returned results will include child\n// DIEs such as params/variables. For example, asking for all DIEs named\n// \"p\" for even a small program will give you 400-500 entries.\nfunc (ex *Examiner) Named(name string) []*dwarf.Entry {\n\tsl := ex.byname[name]\n\tret := make([]*dwarf.Entry, len(sl))\n\tfor i, k := range sl {\n\t\tret[i] = ex.entryFromIdx(k)\n\t}\n\treturn ret\n}\n\n// SubprogLoAndHighPc returns the values of the lo_pc and high_pc","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/dwtest/dwtest.go#L163-L199","documentation":"Thrown by Examiner.FileRef (dwtest.go:180-182) when the numeric file reference (typically from a decl_file/call_file attribute) is out of range for the line reader's file table: either negative or greater than len(files)-1. The file index cannot be resolved to a name, indicating the DWARF producer emitted an inconsistent index.","triggerScenarios":"A subprogram or inlined-call DIE has a DW_AT_decl_file / DW_AT_call_file value that exceeds the number of entries in the CU's .debug_line file table; a zero-based vs one-based index mismatch; fileRef computed from a malformed attribute.","commonSituations":"Linker emits a file index referencing an entry dropped during optimization; DWARF version where file table indexing differs from the reader's expectation; corrupted attribute encoding.","solutions":["Verify the DWARF producer's file index against the .debug_line file_names table length.","Check whether the index should be 0-based or 1-based for the DWARF version in use.","Inspect the line reader's Files() slice length and the offending fileRef to confirm the mismatch.","If examining an inlined-subroutine, ensure you are reading call_file (not decl_file) and that the CU's line program includes the relevant file entries."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"lr, _ := dw.LineReader(cuDie)\nif lr == nil { return \"\", nil }\nfiles := lr.Files()\nif fileRef < 0 || int(fileRef) > len(files)-1 {\n    return \"\", nil // or handle as malformed upstream\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bound-check fileRef against len(lr.Files()) before indexing.","Account for 0-based vs 1-based file indexing per DWARF version.","Treat out-of-range indices as a producer bug to investigate, not a transient error."],"tags":["dwarf","go-linker","dwtest","debug-info"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}