FpDebug: reduced debugln

(cherry picked from commit 9877946d86)
This commit is contained in:
Martin 2021-12-07 23:21:42 +01:00
parent 75876c3371
commit 7d1223ef96
8 changed files with 61 additions and 50 deletions

View File

@ -3942,7 +3942,7 @@ var
Val: TByteDynArray;
LocationParser: TDwarfLocationExpression;
begin
//debugln(['TDbgDwarfIdentifier.LocationFromAttrData', ClassName, ' ',Name, ' ', DwarfAttributeToString(ATag)]);
//debugln(FPDBG_DWARF_VERBOSE, ['TDbgDwarfIdentifier.LocationFromAttrData', ClassName, ' ',Name, ' ', DwarfAttributeToString(ATag)]);
Result := False;
AnAddress := InvalidLoc;
@ -3951,7 +3951,7 @@ begin
// DW_AT_data_member_location in members [ block or const]
// DW_AT_location [block or reference] todo: const
if not InformationEntry.ReadValue(AnAttribData, Val) then begin
DebugLn([FPDBG_DWARF_VERBOSE, 'LocationFromAttrData: failed to read DW_AT_location']);
DebugLn(FPDBG_DWARF_VERBOSE, ['LocationFromAttrData: failed to read DW_AT_location']);
SetLastError(AValueObj, CreateError(fpErrAnyError));
exit;
end;
@ -3986,7 +3986,7 @@ function TFpSymbolDwarf.LocationFromTag(ATag: Cardinal;
var
AttrData: TDwarfAttribData;
begin
//debugln(['TDbgDwarfIdentifier.LocationFromTag', ClassName, ' ',Name, ' ', DwarfAttributeToString(ATag)]);
//debugln(FPDBG_DWARF_VERBOSE,['TDbgDwarfIdentifier.LocationFromTag', ClassName, ' ',Name, ' ', DwarfAttributeToString(ATag)]);
Result := False;
//TODO: avoid copying data
@ -4002,7 +4002,7 @@ begin
if not Result then
AnAddress := InvalidLoc;
if not Result then
DebugLn([FPDBG_DWARF_VERBOSE, 'LocationFromTag: failed to read DW_AT_..._location / ASucessOnMissingTag=', dbgs(ASucessOnMissingTag)]);
DebugLn(FPDBG_DWARF_VERBOSE, ['LocationFromTag: failed to read DW_AT_..._location / ASucessOnMissingTag=', dbgs(ASucessOnMissingTag)]);
exit;
end;
@ -5271,7 +5271,7 @@ end;
function TFpSymbolDwarfDataMember.GetValueAddress(AValueObj: TFpValueDwarf; out
AnAddress: TFpDbgMemLocation): Boolean;
begin
if AValueObj = nil then debugln([FPDBG_DWARF_VERBOSE, 'TFpSymbolDwarfDataMember.InitLocationParser: NO VAl Obj !!!!!!!!!!!!!!!'])
if AValueObj = nil then debugln(FPDBG_DWARF_VERBOSE, ['TFpSymbolDwarfDataMember.InitLocationParser: NO VAl Obj !!!!!!!!!!!!!!!'])
else if AValueObj.StructureValue = nil then debugln(FPDBG_DWARF_VERBOSE, ['TFpSymbolDwarfDataMember.InitLocationParser: NO STRUCT Obj !!!!!!!!!!!!!!!']);
if InformationEntry.HasAttrib(DW_AT_const_value) then begin

View File

@ -330,7 +330,7 @@ type
implementation
var
DBG_VERBOSE, DBG_WARNINGS: PLazLoggerLogGroup;
DBG_VERBOSE, DBG_WARNINGS, FPDBG_LINUX: PLazLoggerLogGroup;
GConsoleTty: string;
GSlavePTyFd: cint;
@ -492,7 +492,7 @@ begin
result := fpkill(ID, SIGSTOP)=0;
{$IFDEF DebuglnLinuxDebugEvents}
debugln('TDbgLinuxThread.RequestInternalPause fpkill(%d, SIGSTOP) => %s', [ID, dbgs(Result)]);
debugln(FPDBG_LINUX, 'TDbgLinuxThread.RequestInternalPause fpkill(%d, SIGSTOP) => %s', [ID, dbgs(Result)]);
{$ENDIF}
if not result then
begin
@ -1202,7 +1202,7 @@ begin
// check for pending events in other threads
if FPostponedSignals.Count > 0 then begin
{$IFDEF DebuglnLinuxDebugEvents}
debugln(['Exit for DEFERRED event TID']);
debugln(FPDBG_LINUX, ['Exit for DEFERRED event TID']);
{$ENDIF}
exit;
end;
@ -1218,7 +1218,7 @@ begin
while (ThreadToContinue.GetInstructionPointerRegisterValue = IP) do begin
fpseterrno(0);
{$IFDEF DebuglnLinuxDebugEvents}
Debugln(['Single-stepping other TID: ', ThreadToContinue.ID]);
Debugln(FPDBG_LINUX, ['Single-stepping other TID: ', ThreadToContinue.ID]);
{$ENDIF}
fpPTrace(PTRACE_SINGLESTEP, ThreadToContinue.ID, pointer(1), pointer(TDbgLinuxThread(ThreadToContinue).FExceptionSignal));
@ -1248,7 +1248,7 @@ begin
if FPostponedSignals.Count > 0 then begin
{$IFDEF DebuglnLinuxDebugEvents}
debugln(['Exit for DEFERRED SingleSteps event TID']);
debugln(FPDBG_LINUX, ['Exit for DEFERRED SingleSteps event TID']);
{$ENDIF}
exit;
end;
@ -1260,7 +1260,7 @@ begin
fpseterrno(0);
AThread.BeforeContinue;
{$IFDEF DebuglnLinuxDebugEvents}
Debugln(['Single-stepping current']);
Debugln(FPDBG_LINUX, ['Single-stepping current']);
{$ENDIF}
fpPTrace(PTRACE_SINGLESTEP, AThread.ID, pointer(1), pointer(TDbgLinuxThread(AThread).FExceptionSignal));
TDbgLinuxThread(AThread).ResetPauseStates;
@ -1277,7 +1277,7 @@ begin
if (ThreadToContinue <> AThread) and (ThreadToContinue.FIsPaused) then begin
fpseterrno(0);
{$IFDEF DebuglnLinuxDebugEvents}
Debugln(['RUN other TID: ', ThreadToContinue.ID]);
Debugln(FPDBG_LINUX, ['RUN other TID: ', ThreadToContinue.ID]);
{$ENDIF}
fpPTrace(PTRACE_CONT, ThreadToContinue.ID, pointer(1), pointer(ThreadToContinue.FExceptionSignal));
CheckNoError; // only log
@ -1290,7 +1290,7 @@ begin
fpseterrno(0);
//AThread.BeforeContinue;
{$IFDEF DebuglnLinuxDebugEvents}
Debugln(['RUN ']);
Debugln(FPDBG_LINUX, ['RUN ']);
{$ENDIF}
if AThread.NextIsSingleStep then
fpPTrace(PTRACE_SINGLESTEP, AThread.ID, pointer(1), pointer(TDbgLinuxThread(AThread).FExceptionSignal))
@ -1330,7 +1330,7 @@ begin
ProcessIdentifier := ProcessID;
{$IFDEF DebuglnLinuxDebugEvents}
debugln(['##### GOT EVENT FOR ',pid, ' st ', FStatus]);
debugln(FPDBG_LINUX, ['##### GOT EVENT FOR ',pid, ' st ', FStatus]);
{$ENDIF}
end;
end;
@ -1546,8 +1546,8 @@ begin
{$IFDEF DebuglnLinuxDebugEvents}
for TDbgThread(ThreadToPause) in FThreadMap do
debugln([ThreadToPause.id, ' =athrd:', ThreadToPause = AThread, ' psd:', ThreadToPause.FIsPaused,ThreadToPause.FIsInInternalPause, ' exs:', ThreadToPause.FExceptionSignal, ' sstep:',ThreadToPause.NextIsSingleStep]);
debugln('<<<<<<<<<<<<<<<<<<<<<<<<');
debugln(FPDBG_LINUX, [ThreadToPause.id, ' =athrd:', ThreadToPause = AThread, ' psd:', ThreadToPause.FIsPaused,ThreadToPause.FIsInInternalPause, ' exs:', ThreadToPause.FExceptionSignal, ' sstep:',ThreadToPause.NextIsSingleStep]);
debugln(FPDBG_LINUX, '<<<<<<<<<<<<<<<<<<<<<<<<');
{$ENDIF}
end;
@ -1555,6 +1555,7 @@ end;
initialization
DBG_VERBOSE := DebugLogger.FindOrRegisterLogGroup('DBG_VERBOSE' {$IFDEF DBG_VERBOSE} , True {$ENDIF} );
DBG_WARNINGS := DebugLogger.FindOrRegisterLogGroup('DBG_WARNINGS' {$IFDEF DBG_WARNINGS} , True {$ENDIF} );
FPDBG_LINUX := DebugLogger.FindOrRegisterLogGroup('FPDBG_LINUX' {$IFDEF DebuglnLinuxDebugEvents} , True {$ENDIF} );
RegisterDbgOsClasses(TOSDbgClasses.Create(
TDbgLinuxProcess,

View File

@ -205,8 +205,6 @@ function QuickUtf8LowerCase(const AText: String): String;
function AlignPtr(Src: Pointer; Alignment: Byte): Pointer;
function HexValue(const AValue; ASize: Byte; AFlags: THexValueFormatFlags): String;
procedure Log(const AText: String; const AParams: array of const); overload;
procedure Log(const AText: String); overload;
function FormatAddress(const AAddress): String;
function GetFpDbgGlobalWorkerQueue: TFpGlobalThreadWorkerQueue;
@ -413,16 +411,6 @@ begin
Result := Result + HexStr(i, ASize * 2);
end;
procedure Log(const AText: String; const AParams: array of const); overload;
begin
DebugLn(Format(AText, AParams));
end;
procedure Log(const AText: String); overload;
begin
DebugLn(AText);
end;
type
{ TFpThreadWorkerTerminateItem }

View File

@ -238,7 +238,7 @@ type
implementation
var
DBG_VERBOSE, DBG_WARNINGS: PLazLoggerLogGroup;
DBG_VERBOSE, DBG_WARNINGS, FPDBG_WINDOWS: PLazLoggerLogGroup;
{$ifdef cpux86_64}
const
@ -740,7 +740,7 @@ function TDbgWinProcess.Continue(AProcess: TDbgProcess; AThread: TDbgThread;
var
EventThread, t: TDbgThread;
begin
debugln(['TDbgWinProcess.Continue ',SingleStep]);
debugln(FPDBG_WINDOWS, ['TDbgWinProcess.Continue ',SingleStep]);
if assigned(AThread) and not FThreadMap.HasId(AThread.ID) then begin
AThread := nil;
end;
@ -756,7 +756,7 @@ debugln(['TDbgWinProcess.Continue ',SingleStep]);
EventThread.NextIsSingleStep := SingleStep;
if HasInsertedBreakInstructionAtLocation(EventThread.GetInstructionPointerRegisterValue) then begin
debugln(['## skip brkpoint ',AThread= EventThread, ' iss ',EventThread.NextIsSingleStep]);
debugln(FPDBG_WINDOWS and DBG_VERBOSE, ['## skip brkpoint ',AThread= EventThread, ' iss ',EventThread.NextIsSingleStep]);
TDbgWinThread(EventThread).SetSingleStepOverBreakPoint;
for t in FThreadMap do
@ -768,7 +768,7 @@ debugln(['## skip brkpoint ',AThread= EventThread, ' iss ',EventThread.NextIsSi
TDbgWinThread(EventThread).SetSingleStep;
if HasThreadInSkippingBreak then begin
debugln(['## skip brkpoint (others only) ',AThread= EventThread, ' iss ',EventThread.NextIsSingleStep]);
debugln(FPDBG_WINDOWS and DBG_VERBOSE, ['## skip brkpoint (others only) ',AThread= EventThread, ' iss ',EventThread.NextIsSingleStep]);
// But other threads are still skipping
for t in FThreadMap do
if not (SingleStep and (t = AThread) and // allow athread to single-step
@ -785,7 +785,7 @@ debugln(['## skip brkpoint (others only) ',AThread= EventThread, ' iss ',EventT
else begin // EventThread is gone
if HasThreadInSkippingBreak then begin
debugln(['## skip brkpoint (others only) ']);
debugln(FPDBG_WINDOWS and DBG_VERBOSE, ['## skip brkpoint (others only) ']);
for t in FThreadMap do
if not (SingleStep and (t = AThread) and // allow athread to single-step
not TDbgWinThread(t).FIsSkippingBreakPoint // already single stepping AND needs TempRemoveBreakInstructionCode
@ -805,7 +805,7 @@ debugln(['## skip brkpoint (others only) ']);
TDbgWinThread(AThread).SetSingleStep;
end;
AProcess.ThreadsBeforeContinue;
if AThread<>nil then debugln(['## ath.iss ',AThread.NextIsSingleStep]);
if AThread<>nil then debugln(FPDBG_WINDOWS, ['## ath.iss ',AThread.NextIsSingleStep]);
if MDebugEvent.dwDebugEventCode = EXCEPTION_DEBUG_EVENT then
case MDebugEvent.Exception.ExceptionRecord.ExceptionCode of
@ -818,7 +818,7 @@ if AThread<>nil then debugln(['## ath.iss ',AThread.NextIsSingleStep]);
end
else
result := Windows.ContinueDebugEvent(MDebugEvent.dwProcessId, MDebugEvent.dwThreadId, DBG_CONTINUE);
DebugLn(not Result, 'ContinueDebugEvent failed: %d', [Windows.GetLastError]);
DebugLn((FPDBG_WINDOWS or DBG_WARNINGS) and (not Result), 'ContinueDebugEvent failed: %d', [Windows.GetLastError]);
result := true;
MDebugEvent.dwProcessId := 0; // Flag as running // for assert in ReadThreadState
end;
@ -883,13 +883,13 @@ begin
repeat
Done := True;
result := Windows.WaitForDebugEvent(MDebugEvent, INFINITE);
DebugLn(not Result, 'WaitForDebugEvent failed: %d', [Windows.GetLastError]);
DebugLn(FPDBG_WINDOWS and (not Result), 'WaitForDebugEvent failed: %d', [Windows.GetLastError]);
if Result and FTerminated and (MDebugEvent.dwDebugEventCode <> EXIT_PROCESS_DEBUG_EVENT)
and (MDebugEvent.dwDebugEventCode <> EXIT_THREAD_DEBUG_EVENT)
then begin
// Wait for the terminate event // Do not report any queued breakpoints
DebugLn(['Terimating... Skipping event: ', dbgs(MDebugEvent)]);
DebugLn(FPDBG_WINDOWS, ['Terimating... Skipping event: ', dbgs(MDebugEvent)]);
for TDbgThread(t) in FThreadMap do
t.Suspend;
Windows.ContinueDebugEvent(MDebugEvent.dwProcessId, MDebugEvent.dwThreadId, DBG_CONTINUE);
@ -927,10 +927,10 @@ begin
ProcessIdentifier:=MDebugEvent.dwProcessId;
ThreadIdentifier:=MDebugEvent.dwThreadId;
{$IFDEF DebuglnWinDebugEvents}
DebugLn([dbgs(MDebugEvent), ' ', Result]);
DebugLn(FPDBG_WINDOWS, [dbgs(MDebugEvent), ' ', Result]);
for TDbgThread(t) in FThreadMap do begin
if t.ReadThreadState then
DebugLn('Thr.Id:%d %x SSTep %s EF %s DR6:%x DR7:%x WP:%x RegAcc: %d, SStep: %d Task: %d, ExcBrk: %d', [t.ID, t.GetInstructionPointerRegisterValue, dbgs(t.FCurrentContext^.def.EFlags and FLAG_TRACE_BIT), dbghex(t.FCurrentContext^.def.EFlags), t.FCurrentContext^.def.Dr6, t.FCurrentContext^.def.Dr7, t.FCurrentContext^.def.Dr6 and 15, t.FCurrentContext^.def.Dr6 and (1<< 13), t.FCurrentContext^.def.Dr6 and (1<< 14), t.FCurrentContext^.def.Dr6 and (1<< 15), t.FCurrentContext^.def.Dr6 and (1<< 16)]);
DebugLn(FPDBG_WINDOWS, 'Thr.Id:%d %x SSTep %s EF %s DR6:%x DR7:%x WP:%x RegAcc: %d, SStep: %d Task: %d, ExcBrk: %d', [t.ID, t.GetInstructionPointerRegisterValue, dbgs(t.FCurrentContext^.def.EFlags and FLAG_TRACE_BIT), dbghex(t.FCurrentContext^.def.EFlags), t.FCurrentContext^.def.Dr6, t.FCurrentContext^.def.Dr7, t.FCurrentContext^.def.Dr6 and 15, t.FCurrentContext^.def.Dr6 and (1<< 13), t.FCurrentContext^.def.Dr6 and (1<< 14), t.FCurrentContext^.def.Dr6 and (1<< 15), t.FCurrentContext^.def.Dr6 and (1<< 16)]);
end;
{$ENDIF}
@ -1710,7 +1710,7 @@ begin
begin
Assert(FCurrentContext <> nil, 'TDbgWinThread.BeforeContinue: none existing context was changed');
if not SetFpThreadContext(FCurrentContext) then
debugln(['Failed to SetFpThreadContext()']);
debugln(FPDBG_WINDOWS or DBG_WARNINGS, ['Failed to SetFpThreadContext()']);
end;
FThreadContextChanged := False;
FThreadContextChangeFlags := [];
@ -1881,6 +1881,7 @@ initialization
DBG_VERBOSE := DebugLogger.FindOrRegisterLogGroup('DBG_VERBOSE' {$IFDEF DBG_VERBOSE} , True {$ENDIF} );
DBG_WARNINGS := DebugLogger.FindOrRegisterLogGroup('DBG_WARNINGS' {$IFDEF DBG_WARNINGS} , True {$ENDIF} );
FPDBG_WINDOWS := DebugLogger.FindOrRegisterLogGroup('FPDBG_WINDOWS' {$IFDEF FPDBG_WINDOWS} , True {$ENDIF} );
RegisterDbgOsClasses(TOSDbgClasses.Create(
TDbgWinProcess,

View File

@ -135,6 +135,9 @@ procedure RegisterImageReaderClass(DataSource: TDbgImageReaderClass);
implementation
var
DBG_WARNINGS: PLazLoggerLogGroup;
const
// Symbol-map section name
_gnu_dbg_link = '.gnu_debuglink';
@ -460,7 +463,7 @@ function TDbgImageReader.LoadGnuDebugLink(ASearchPath, AFileName: String;
c:=Crc32(c, mem, i);
Result.UnloadMemory(mem);
DebugLn(c <> ACrc, ['Invalid CRC for ext debug info: ', AFullName]);
DebugLn(DBG_WARNINGS and (c <> ACrc), ['Invalid CRC for ext debug info: ', AFullName]);
if c <> ACrc then
FreeAndNil(Result);
end;
@ -511,6 +514,8 @@ begin
end;
initialization
DBG_WARNINGS := DebugLogger.FindOrRegisterLogGroup('DBG_WARNINGS' {$IFDEF DBG_WARNINGS} , True {$ENDIF} );
InitDebugInfoLists;
finalization

View File

@ -88,6 +88,9 @@ type
implementation
var
DBG_WARNINGS: PLazLoggerLogGroup;
type
TElf32symbol=record
st_name : longword;
@ -169,7 +172,7 @@ begin
sz := hdr.e_shetsize * hdr.e_shnum;
if sz > LongWord(length(sect)*sizeof(Elf32_shdr)) then begin
debugln(['TElfFile.Load32BitFile Size of SectHdrs is ', sz, ' expected ', LongWord(length(sect)*sizeof(Elf32_shdr))]);
debugln(DBG_WARNINGS, ['TElfFile.Load32BitFile Size of SectHdrs is ', sz, ' expected ', LongWord(length(sect)*sizeof(Elf32_shdr))]);
sz := LongWord(length(sect)*sizeof(Elf32_shdr));
end;
//ALoader.Read(sect[0], sz);
@ -208,7 +211,7 @@ begin
sz := hdr.e_shentsize * hdr.e_shnum;
if sz > LongWord(length(sect)*sizeof(Elf64_shdr)) then begin
debugln(['TElfFile.Load64BitFile Size of SectHdrs is ', sz, ' expected ', LongWord(length(sect)*sizeof(Elf64_shdr))]);
debugln(DBG_WARNINGS, ['TElfFile.Load64BitFile Size of SectHdrs is ', sz, ' expected ', LongWord(length(sect)*sizeof(Elf64_shdr))]);
sz := LongWord(length(sect)*sizeof(Elf64_shdr));
end;
//ALoader.Read(sect[0], sz);
@ -495,6 +498,8 @@ begin
end;
initialization
DBG_WARNINGS := DebugLogger.FindOrRegisterLogGroup('DBG_WARNINGS' {$IFDEF DBG_WARNINGS} , True {$ENDIF} );
RegisterImageReaderClass( TElfDbgSource );
end.

View File

@ -76,6 +76,9 @@ implementation
uses
FpDbgCommon;
var
DBG_WARNINGS: PLazLoggerLogGroup;
const
// Symbol-map section name
_symbol = '.symbols';
@ -442,7 +445,7 @@ begin
)
div SizeOf(TImageSectionHeader);
if SectionMax <> NtHeaders.Sys.FileHeader.NumberOfSections then begin
DebugLn(['Could not load all headers', NtHeaders.Sys.FileHeader.NumberOfSections, ' ', SectionMax]);
DebugLn(DBG_WARNINGS, ['Could not load all headers', NtHeaders.Sys.FileHeader.NumberOfSections, ' ', SectionMax]);
end;
for n := 0 to SectionMax - 1 do
@ -493,6 +496,8 @@ end;
initialization
DBG_WARNINGS := DebugLogger.FindOrRegisterLogGroup('DBG_WARNINGS' {$IFDEF DBG_WARNINGS} , True {$ENDIF} );
RegisterImageReaderClass(TPEFileSource);
end.

View File

@ -456,6 +456,9 @@ type
implementation
var
DBG_WARNINGS: PLazLoggerLogGroup;
const
// 1 highest
PRECEDENCE_MEMBER_OF = 1; // foo.bar
@ -2071,26 +2074,26 @@ end;
procedure TFpPascalExpression.SetError(AMsg: String);
begin
if IsError(FError) then begin
DebugLn(['Skipping error ', AMsg]);
DebugLn(DBG_WARNINGS, ['Skipping error ', AMsg]);
FValid := False;
exit;
end;
SetError(fpErrAnyError, [AMsg]);
DebugLn(['PARSER ERROR ', AMsg]);
DebugLn(DBG_WARNINGS, ['PARSER ERROR ', AMsg]);
end;
procedure TFpPascalExpression.SetError(AnErrorCode: TFpErrorCode; AData: array of const);
begin
FValid := False;
FError := ErrorHandler.CreateError(AnErrorCode, AData);
DebugLn(['Setting error ', ErrorHandler.ErrorAsString(FError)]);
DebugLn(DBG_WARNINGS, ['Setting error ', ErrorHandler.ErrorAsString(FError)]);
end;
procedure TFpPascalExpression.SetError(const AnErr: TFpError);
begin
FValid := False;
FError := AnErr;
DebugLn(['Setting error ', ErrorHandler.ErrorAsString(FError)]);
DebugLn(DBG_WARNINGS, ['Setting error ', ErrorHandler.ErrorAsString(FError)]);
end;
function TFpPascalExpression.PosFromPChar(APChar: PChar): Integer;
@ -2868,7 +2871,7 @@ function TFpPascalExpressionPartOperatorPlusMinus.DoGetResultValue: TFpValue;
TmpVal := APointerVal.Member[1];
if s1 <> (TmpVal.DataAddress.Address - APointerVal.DataAddress.Address) then begin
TmpVal.ReleaseReference;
debugln('Size mismatch for pointer math');
debugln(DBG_WARNINGS, 'Size mismatch for pointer math');
exit;
end;
TmpVal.ReleaseReference;
@ -2877,7 +2880,7 @@ function TFpPascalExpressionPartOperatorPlusMinus.DoGetResultValue: TFpValue;
m := Idx mod SizeToFullBytes(s1);
Idx := Idx div SizeToFullBytes(s1);
if m <> 0 then begin
debugln('Size mismatch for pointer math');
debugln(DBG_WARNINGS, 'Size mismatch for pointer math');
exit;
end;
end;
@ -3630,5 +3633,8 @@ begin
SetError(fpErrorNotAStructure, [MemberName, Items[0].GetText]);
end;
initialization
DBG_WARNINGS := DebugLogger.FindOrRegisterLogGroup('DBG_WARNINGS' {$IFDEF DBG_WARNINGS} , True {$ENDIF} );
end.