From 8c022f5c58132750b220ed395df11ad58e45d85d Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 16 Jan 2024 16:26:20 +0100 Subject: [PATCH] FpDebug: Don't read debug info with unknown DW_FORM (cherry picked from commit 532aae621247b07fae1517b8378d0d0d398cfcc3) --- components/fpdebug/fpdbgdwarfconst.pas | 2 ++ components/fpdebug/fpdbgdwarfdataclasses.pas | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/components/fpdebug/fpdbgdwarfconst.pas b/components/fpdebug/fpdbgdwarfconst.pas index d74a243172..981e495f47 100644 --- a/components/fpdebug/fpdbgdwarfconst.pas +++ b/components/fpdebug/fpdbgdwarfconst.pas @@ -223,6 +223,8 @@ const DW_FORM_ref_udata = $15; // reference DW_FORM_indirect = $16; // + DW_FORM_MAX = $16; // + { DWARF operation encodings } diff --git a/components/fpdebug/fpdbgdwarfdataclasses.pas b/components/fpdebug/fpdbgdwarfdataclasses.pas index 5c3008d128..6d2d39c25e 100644 --- a/components/fpdebug/fpdbgdwarfdataclasses.pas +++ b/components/fpdebug/fpdbgdwarfdataclasses.pas @@ -215,6 +215,7 @@ type FMap: TMap; // Abbrevs {$Endif} FDefinitions: array of TDwarfAbbrevEntry; + FValid: Boolean; function GetEntryPointer(AIndex: Integer): PDwarfAbbrevEntry; inline; procedure LoadAbbrevs(AnAbbrevDataPtr: Pointer); public @@ -224,6 +225,7 @@ type function FindLe128bFromPointer(AnAbbrevPtr: Pointer; out AData: TDwarfAbbrev{Pointer}): Pointer; reintroduce; {$Endif} property EntryPointer[AIndex: Integer]: PDwarfAbbrevEntry read GetEntryPointer; + property Valid: Boolean read FValid; end; {%endregion Abbreviation Data / Section "debug_abbrev"} @@ -1559,6 +1561,7 @@ var DbgVerbose: Boolean; f: TDwarfAbbrevFlags; begin + FValid := False; abbrev := 0; CurAbbrevIndex := 0; DbgVerbose := (FPDBG_DWARF_VERBOSE_LOAD <> nil) and (FPDBG_DWARF_VERBOSE_LOAD^.Enabled); @@ -1615,6 +1618,10 @@ begin Include(f, dafHasAbstractOrigin); form := ULEB128toOrdinal(pbyte(AnAbbrevDataPtr)); + if form > DW_FORM_MAX then begin + DebugLn(FPDBG_DWARF_WARNINGS, ['Unknown FW_FORM: ', form, ' found. Aborting']); + exit; + end; MakeRoom(CurAbbrevIndex + 1); FDefinitions[CurAbbrevIndex].Attribute := attrib; @@ -1635,6 +1642,7 @@ begin Inc(pword(AnAbbrevDataPtr)); end; + FValid := True; end; constructor TDwarfAbbrevList.Create(AnAbbrData, AnAbbrDataEnd: Pointer; AnAbbrevOffset, @@ -4244,7 +4252,8 @@ begin Result := FCompilationUnits.Count; for i := 0 to Result - 1 do - TDwarfCompilationUnit(FCompilationUnits[i]).FComputeNameHashesWorker.MarkReadyToRun; + if TDwarfCompilationUnit(FCompilationUnits[i]).FComputeNameHashesWorker <> nil then + TDwarfCompilationUnit(FCompilationUnits[i]).FComputeNameHashesWorker.MarkReadyToRun; end; function TFpDwarfInfo.CompilationUnitForAddr(AnAddr: TDBGPtr @@ -5059,6 +5068,11 @@ begin FFirstScope.Init(nil); // invalid + if not FAbbrevList.Valid then begin + FDwarfSymbolClassMap := DwarfSymbolClassMapList.FDefaultMap.Create(Self, nil); + exit; + end; + FComputeNameHashesWorker := TFpThreadWorkerComputeNameHashes.Create(Self); FComputeNameHashesWorker.AddRef; FScanAllWorker := TFpThreadWorkerScanAll.Create(Self, FComputeNameHashesWorker); @@ -5067,6 +5081,7 @@ begin Scope := FScanAllWorker.FindCompileUnit(FScopeList); if not Scope.IsValid then begin DebugLn(FPDBG_DWARF_WARNINGS, ['WARNING compilation unit has no compile_unit tag']); + FDwarfSymbolClassMap := DwarfSymbolClassMapList.FDefaultMap.Create(Self, nil); Exit; end; FValid := True; @@ -5130,6 +5145,8 @@ destructor TDwarfCompilationUnit.Destroy; var n: Integer; begin + if FLineNumberMap = nil then + exit; for n := 0 to FLineNumberMap.Count - 1 do Dispose(PDWarfLineMap(FLineNumberMap.Objects[n])); FreeAndNil(FLineNumberMap);