mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 17:49:27 +02:00
* Patch from Martin Friebe to buffer reading dwarf info
git-svn-id: trunk@14168 -
This commit is contained in:
parent
9fff5d989c
commit
740bd6744b
@ -53,9 +53,13 @@ uses
|
||||
type
|
||||
Bool8 = ByteBool;
|
||||
|
||||
const
|
||||
EBUF_SIZE = 100;
|
||||
var
|
||||
{ the input file to read DWARF debug info from, i.e. paramstr(0) }
|
||||
e : TExeFile;
|
||||
EBuf: Array [0..EBUF_SIZE-1] of Byte;
|
||||
EBufCnt, EBufPos: Integer;
|
||||
DwarfErr : boolean;
|
||||
{ the offset and size of the DWARF debug_line section in the file }
|
||||
DwarfOffset : longint;
|
||||
@ -177,6 +181,8 @@ begin
|
||||
limit := aLimit;
|
||||
Init := (aBase + limit) <= e.size;
|
||||
seek(e.f, base);
|
||||
EBufCnt := 0;
|
||||
EBufPos := 0;
|
||||
index := 0;
|
||||
end;
|
||||
|
||||
@ -196,39 +202,69 @@ procedure Seek(const newIndex : Int64);
|
||||
begin
|
||||
index := newIndex;
|
||||
system.seek(e.f, base + index);
|
||||
EBufCnt := 0;
|
||||
EBufPos := 0;
|
||||
end;
|
||||
|
||||
|
||||
{ Returns the next Byte from the input stream, or -1 if there has been
|
||||
an error }
|
||||
function ReadNext() : Longint;
|
||||
function ReadNext() : Longint; inline;
|
||||
var
|
||||
bytesread : SizeInt;
|
||||
b : Byte;
|
||||
begin
|
||||
ReadNext := -1;
|
||||
if (index < limit) then begin
|
||||
blockread(e.f, b, 1, bytesread);
|
||||
ReadNext := b;
|
||||
inc(index);
|
||||
if EBufPos >= EBufCnt then begin
|
||||
EBufPos := 0;
|
||||
EBufCnt := EBUF_SIZE;
|
||||
if EBufCnt > limit - index then
|
||||
EBufCnt := limit - index;
|
||||
blockread(e.f, EBuf, EBufCnt, bytesread);
|
||||
EBufCnt := bytesread;
|
||||
end;
|
||||
if (bytesread <> 1) then
|
||||
if EBufPos < EBufCnt then begin
|
||||
ReadNext := EBuf[EBufPos];
|
||||
inc(EBufPos);
|
||||
inc(index);
|
||||
end
|
||||
else
|
||||
ReadNext := -1;
|
||||
end;
|
||||
|
||||
{ Reads the next size bytes into dest. Returns true if successful,
|
||||
false otherwise. Note that dest may be partially overwritten after
|
||||
returning false. }
|
||||
function ReadNext(var dest; size : SizeInt) : Boolean;
|
||||
function ReadNext(var dest; size : SizeInt) : Boolean; inline;
|
||||
var
|
||||
bytesread : SizeInt;
|
||||
bytesread, totalread : SizeInt;
|
||||
r: Boolean;
|
||||
d: PByte;
|
||||
begin
|
||||
bytesread := 0;
|
||||
if ((index + size) < limit) then begin
|
||||
blockread(e.f, dest, size, bytesread);
|
||||
inc(index, size);
|
||||
d := @dest;
|
||||
totalread := 0;
|
||||
r := True;
|
||||
while (totalread < size) and r do begin;
|
||||
if EBufPos >= EBufCnt then begin
|
||||
EBufPos := 0;
|
||||
EBufCnt := EBUF_SIZE;
|
||||
if EBufCnt > limit - index then
|
||||
EBufCnt := limit - index;
|
||||
blockread(e.f, EBuf, EBufCnt, bytesread);
|
||||
EBufCnt := bytesread;
|
||||
if bytesread <= 0 then
|
||||
r := False;
|
||||
end;
|
||||
if EBufPos < EBufCnt then begin
|
||||
bytesread := EBufCnt - EBufPos;
|
||||
if bytesread > size - totalread then bytesread := size - totalread;
|
||||
System.Move(EBuf[EBufPos], d[totalread], bytesread);
|
||||
inc(EBufPos, bytesread);
|
||||
inc(index, bytesread);
|
||||
inc(totalread, bytesread);
|
||||
end;
|
||||
end;
|
||||
ReadNext := (bytesread = size);
|
||||
ReadNext := r;
|
||||
end;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user