push latest gdb commander changes to fix 32bit build

This commit is contained in:
Basile Burg 2016-03-27 18:55:24 +02:00
parent 2699a0a2d5
commit 7131f5b956
1 changed files with 119 additions and 59 deletions

View File

@ -8,7 +8,7 @@ uses
Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, Graphics, RegExpr, Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, Graphics, RegExpr,
ComCtrls, PropEdits, GraphPropEdits, RTTIGrids, Dialogs, ExtCtrls, Menus, strutils, ComCtrls, PropEdits, GraphPropEdits, RTTIGrids, Dialogs, ExtCtrls, Menus, strutils,
Buttons, StdCtrls, process ,ce_common, ce_interfaces, ce_widget, ce_processes, Buttons, StdCtrls, process ,ce_common, ce_interfaces, ce_widget, ce_processes,
ce_observer, ce_synmemo, ce_sharedres; ce_observer, ce_synmemo, ce_sharedres, ce_stringrange;
type type
@ -20,11 +20,11 @@ type
{$ENDIF} {$ENDIF}
{$IFDEF CPU32} {$IFDEF CPU32}
TCpuRegs = (eax, ebx, ecx, edx, esi, edi, ebp, esp, eip); TCpuRegister = (eax, ebx, ecx, edx, esi, edi, ebp, esp, eip);
{$ENDIF} {$ENDIF}
TFLAG = (F_ID, F_VIP, F_VIF, F_AC, F_VM, F_RF, F_NT, F_IOPL, F_OF, F_DF, F_IF, TFLAG = (CS, PF, AF, ZF, SF, TF, IF_, DF, OF_, NT, RF, VM,
F_TF, F_SF, F_ZF, F_AF, F_PF, F_CF); AC, VIF, VIP, ID);
TEFLAG = set of TFLAG; TEFLAG = set of TFLAG;
TSegmentRegister = (S_CS, S_SS, S_DS, S_ES, S_FS, S_GS); TSegmentRegister = (S_CS, S_SS, S_DS, S_ES, S_FS, S_GS);
@ -277,67 +277,127 @@ var
str: string; str: string;
reg: string; reg: string;
val: string; val: string;
rng: TStringRange = (ptr: nil; pos: 0; len: 0);
begin begin
rdr := TStringList.Create;
try setLength(str, stream.Size);
rdr.LoadFromStream(stream); stream.Read(str[1], str.length);
if (rdr.Count = 0) or (pos('(gdb)', rdr[0]) = -1) then rng.init(str);
if rng.empty then
exit;
if not rng.startsWith('&"info registers\n"') then
exit;
rng.popUntil(#10)^.popFront;
while not rng.empty do
begin
if rng.front <> '~' then
exit; exit;
// fix first line rng.popFront;
str := rdr[0]; if rng.front <> '"' then
rdr[0] := str[7 .. str.length]; exit;
// each line = reg hex dec rng.popFront;
for str in rdr do
reg := rng.takeUntil([' ', #9]).yield;
if (reg = 'rip') or (reg = 'eip') then
begin begin
reg := ''; rng.popUntil(#10)^.popFront;
if fWordSpliter.Exec(str) then rng.popUntil(#10)^.popFront;
continue;
end;
rng.popUntil(#10)^.popFront;
if rng.front <> '~' then
exit;
rng.popFront;
if rng.front <> '"' then
exit;
rng.popFront;
if rng.front <> '\' then
exit;
rng.popFront;
if rng.front <> 't' then
exit;
rng.popFront;
if reg = 'eflags' then
begin
fFlags := [];
if rng.front <> '[' then
exit;
rng.popFront;
while rng.front <> ']' do
begin begin
reg := fWordSpliter.Match[0]; val := rng.popWhile([' ', #9])^.takeUntil([' ', #9, ']']).yield;
if fWordSpliter.ExecNext and fWordSpliter.ExecNext then case val of
begin 'CS': include(fFlags, TFLAG.CS);
val := fWordSpliter.Match[0]; 'PF': include(fFlags, TFLAG.PF);
case reg of 'AF': include(fFlags, TFLAG.AF);
'cs': fSegment[TSegmentRegister.S_CS] := StrToInt(val); 'ZF': include(fFlags, TFLAG.ZF);
'ds': fSegment[TSegmentRegister.S_DS] := StrToInt(val); 'SF': include(fFlags, TFLAG.SF);
'es': fSegment[TSegmentRegister.S_ES] := StrToInt(val); 'TF': include(fFlags, TFLAG.TF);
'fs': fSegment[TSegmentRegister.S_FS] := StrToInt(val); 'IF': include(fFlags, TFLAG.IF_);
'gs': fSegment[TSegmentRegister.S_GS] := StrToInt(val); 'DF': include(fFlags, TFLAG.DF);
'ss': fSegment[TSegmentRegister.S_SS] := StrToInt(val); 'OF': include(fFlags, TFLAG.OF_);
{$IFDEF CPU64} //'NT': include(fFlags, TFLAG.NT);
'rax': fRegisters[TCpuRegister.rax] := StrToInt64(val); //'RF': include(fFlags, TFLAG.RF);
'rbx': fRegisters[TCpuRegister.rbx] := StrToInt64(val); //'VM': include(fFlags, TFLAG.VM);
'rcx': fRegisters[TCpuRegister.rcx] := StrToInt64(val); //'AC': include(fFlags, TFLAG.AC);
'rdx': fRegisters[TCpuRegister.rdx] := StrToInt64(val); //'VIF':include(fFlags, TFLAG.VIF);
'rdi': fRegisters[TCpuRegister.rdi] := StrToInt64(val); //'VIP':include(fFlags, TFLAG.VIP);
'rsi': fRegisters[TCpuRegister.rsi] := StrToInt64(val); //'ID': include(fFlags, TFLAG.ID);
'rbp': fRegisters[TCpuRegister.rbp] := StrToInt64(val);
'rsp': fRegisters[TCpuRegister.rsp] := StrToInt64(val);
'r8': fRegisters[TCpuRegister.r8] := StrToInt64(val);
'r9': fRegisters[TCpuRegister.r9] := StrToInt64(val);
'r10': fRegisters[TCpuRegister.r10] := StrToInt64(val);
'r11': fRegisters[TCpuRegister.r11] := StrToInt64(val);
'r12': fRegisters[TCpuRegister.r12] := StrToInt64(val);
'r13': fRegisters[TCpuRegister.r13] := StrToInt64(val);
'r14': fRegisters[TCpuRegister.r14] := StrToInt64(val);
'r15': fRegisters[TCpuRegister.r15] := StrToInt64(val);
'rip': fRegisters[TCpuRegister.rip] := StrToInt64(val);
{$ELSE}
'eax': fRegisters[TCpuRegister.eax] := StrToInt(val);
'ebx': fRegisters[TCpuRegister.ebx] := StrToInt(val);
'ecx': fRegisters[TCpuRegister.ecx] := StrToInt(val);
'edx': fRegisters[TCpuRegister.edx] := StrToInt(val);
'edi': fRegisters[TCpuRegister.edi] := StrToInt(val);
'esi': fRegisters[TCpuRegister.esi] := StrToInt(val);
'ebp': fRegisters[TCpuRegister.ebp] := StrToInt(val);
'esp': fRegisters[TCpuRegister.esp] := StrToInt(val);
'eip': fRegisters[TCpuRegister.eip] := StrToInt(val);
{$ENDIF}
end;
end; end;
end; end;
rng.popUntil(#10)^.popFront;
rng.popUntil(#10)^.popFront;
continue;
end; end;
finally
rdr.free; val := rng.takeWhile(['0','1','2','3','4','5','6','7','8','9']).yield;
rng.popUntil(#10)^.popFront;
rng.popUntil(#10)^.popFront;
case reg of
'cs': fSegment[TSegmentRegister.S_CS] := StrToInt(val);
'ds': fSegment[TSegmentRegister.S_DS] := StrToInt(val);
'es': fSegment[TSegmentRegister.S_ES] := StrToInt(val);
'fs': fSegment[TSegmentRegister.S_FS] := StrToInt(val);
'gs': fSegment[TSegmentRegister.S_GS] := StrToInt(val);
'ss': fSegment[TSegmentRegister.S_SS] := StrToInt(val);
{$IFDEF CPU64}
'rax': fRegisters[TCpuRegister.rax] := StrToInt64(val);
'rbx': fRegisters[TCpuRegister.rbx] := StrToInt64(val);
'rcx': fRegisters[TCpuRegister.rcx] := StrToInt64(val);
'rdx': fRegisters[TCpuRegister.rdx] := StrToInt64(val);
'rdi': fRegisters[TCpuRegister.rdi] := StrToInt64(val);
'rsi': fRegisters[TCpuRegister.rsi] := StrToInt64(val);
'rbp': fRegisters[TCpuRegister.rbp] := StrToInt64(val);
'rsp': fRegisters[TCpuRegister.rsp] := StrToInt64(val);
'r8': fRegisters[TCpuRegister.r8] := StrToInt64(val);
'r9': fRegisters[TCpuRegister.r9] := StrToInt64(val);
'r10': fRegisters[TCpuRegister.r10] := StrToInt64(val);
'r11': fRegisters[TCpuRegister.r11] := StrToInt64(val);
'r12': fRegisters[TCpuRegister.r12] := StrToInt64(val);
'r13': fRegisters[TCpuRegister.r13] := StrToInt64(val);
'r14': fRegisters[TCpuRegister.r14] := StrToInt64(val);
'r15': fRegisters[TCpuRegister.r15] := StrToInt64(val);
'rip': fRegisters[TCpuRegister.rip] := StrToInt64(val);
{$ELSE}
'eax': fRegisters[TCpuRegister.eax] := StrToInt(val);
'ebx': fRegisters[TCpuRegister.ebx] := StrToInt(val);
'ecx': fRegisters[TCpuRegister.ecx] := StrToInt(val);
'edx': fRegisters[TCpuRegister.edx] := StrToInt(val);
'edi': fRegisters[TCpuRegister.edi] := StrToInt(val);
'esi': fRegisters[TCpuRegister.esi] := StrToInt(val);
'ebp': fRegisters[TCpuRegister.ebp] := StrToInt(val);
'esp': fRegisters[TCpuRegister.esp] := StrToInt(val);
'eip': fRegisters[TCpuRegister.eip] := StrToInt(val);
{$ENDIF}
end;
end; end;
end; end;
{$ENDREGION} {$ENDREGION}
@ -494,7 +554,7 @@ begin
fGdb.Executable:= 'gdb' + exeExt; fGdb.Executable:= 'gdb' + exeExt;
fgdb.Options:= [poUsePipes, poStderrToOutPut]; fgdb.Options:= [poUsePipes, poStderrToOutPut];
fgdb.Parameters.Add(str); fgdb.Parameters.Add(str);
//fgdb.Parameters.Add('--interpreter=mi'); fgdb.Parameters.Add('--interpreter=mi');
fGdb.OnReadData:= @gdbOutput; fGdb.OnReadData:= @gdbOutput;
fGdb.OnTerminate:= @gdbOutput; fGdb.OnTerminate:= @gdbOutput;
fgdb.execute; fgdb.execute;