DebuggerGdbmi/DebugIntf: fix address calculation, do not calc negative addresses. Patch by Christo Crause Issue #0032240

git-svn-id: trunk@64545 -
This commit is contained in:
martin 2021-02-11 23:27:25 +00:00
parent ac0e547a58
commit d4fabf2c65
2 changed files with 23 additions and 8 deletions

View File

@ -2314,7 +2314,7 @@ function TDBGDisassemblerRangeExtender.DisassembleRange(ALinesBefore,
ALinesAfter: integer; AStartAddr: TDBGPtr; AnEndAddr: TDBGPtr): boolean;
var
TryStartAt, TryEndAt: TDisassemblerAddress;
TmpAddr: TDBGPtr;
TmpAddr, TmpOffset: TDBGPtr;
GotCnt, LastGotCnt: Integer;
RngBefore, RngAfter: TDBGDisassemblerEntryRange;
begin
@ -2335,7 +2335,11 @@ begin
and (TryStartAt.Value - RngBefore.EntriesPtr[RngBefore.Count - 1]^.Addr > ALinesBefore * DAssBytesPerCommandAvg)
then RngBefore := nil;
{$POP}
TmpAddr := AStartAddr - Min(ALinesBefore * DAssBytesPerCommandAvg, DAssMaxRangeSize);
TmpOffset := Min(ALinesBefore * DAssBytesPerCommandAvg, DAssMaxRangeSize);
if TmpOffset > AStartAddr then
TmpAddr := 0
else
TmpAddr := AStartAddr - TmpOffset;
TryStartAt.GuessedValue := TmpAddr;
AdjustToRangeOrKnowFunctionStart(TryStartAt, RngBefore);
// check max size
@ -2445,7 +2449,11 @@ begin
end;
TryEndAt := InitAddress(RngAfter.RangeStartAddr, avFoundRange);
TmpAddr := TryEndAt.Value - Min((ALinesBefore - GotCnt) * DAssBytesPerCommandAvg, DAssMaxRangeSize);
TmpOffset := Min((ALinesBefore - GotCnt) * DAssBytesPerCommandAvg, DAssMaxRangeSize);
if TryEndAt.Value > TmpOffset then
TmpAddr := TryEndAt.Value - TmpOffset
else
TmpAddr := 0;
TryStartAt := InitAddress(TryEndAt.Value - 1, avGuessed);
TryStartAt.GuessedValue := TmpAddr;
// and adjust

View File

@ -4493,7 +4493,10 @@ function TGDBMIDebuggerCommandDisassemble.DoExecute: Boolean;
begin
Result := False;
// TODO: maybe try "info symbol <addr>
s := (AStartAddr.GuessedValue -1) div 4 * 4; // 4 byte boundary
if AStartAddr.GuessedValue = 0 then
s := 0
else
s := (AStartAddr.GuessedValue -1) div 4 * 4; // 4 byte boundary
DisAssList := ExecDisassmble(s, s+1, False);
if DisAssList.Count > 0 then begin
DisAssItm := DisAssList.Item[0];
@ -4788,7 +4791,7 @@ function TGDBMIDebuggerCommandDisassemble.DoExecute: Boolean;
i, Cnt, DisAssStartIdx: Integer;
NewRange: TDBGDisassemblerEntryRange;
OrigLastAddress, OrigFirstAddress: TDisassemblerAddress;
TmpAddr: TDBGPtr;
TmpAddr, TmpOffset: TDBGPtr;
BlockOk, SkipDisAssInFirstLoop, ContinueAfterSource: Boolean;
Itm: TDisassemblerEntry;
begin
@ -4809,8 +4812,8 @@ function TGDBMIDebuggerCommandDisassemble.DoExecute: Boolean;
// No nice startingpoint found, just start to disassemble aprox 5 instructions before it
// and hope that when we started in the middle of an instruction it get sorted out.
// If so, the 4st for lines from the result must be discarded
if not (AFirstAddr.Validity in TrustedValidity)
// If so, the 1st four lines from the result must be discarded
if not (AFirstAddr.Validity in TrustedValidity) and (AFirstAddr.Value > 5 * DAssBytesPerCommandMax)
then PadAddress(AFirstAddr, - 5 * DAssBytesPerCommandMax);
// Adjust ALastAddr
@ -4833,7 +4836,11 @@ function TGDBMIDebuggerCommandDisassemble.DoExecute: Boolean;
// TODO: limit offset ONLY, if previous range known (already have disass)
if (AFirstAddr.Offset >= 0)
then begin
TmpAddr := AFirstAddr.Value - Min(AFirstAddr.Offset, DAssRangeOverFuncTreshold * DAssBytesPerCommandAvg);
TmpOffset := Min(AFirstAddr.Offset, DAssRangeOverFuncTreshold * DAssBytesPerCommandAvg);
if AFirstAddr.Value > TmpOffset then
TmpAddr := AFirstAddr.Value - TmpOffset
else
TmpAddr := 0;
DisAssListWithSrc := ExecDisassmble(TmpAddr, ALastAddr.Value, True);
end;