Changeset 418 for ExceptionLogger/CustomLineInfo.pas
- Timestamp:
- Sep 4, 2012, 1:16:13 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ExceptionLogger/CustomLineInfo.pas
r64 r418 71 71 dirstab, { stab with current directory info } 72 72 filestab : tstab; { stab with current file info } 73 filename, 74 dbgfn : shortstring; 75 73 filename: shortstring; 74 dbgfn : string; 75 76 77 var 78 Crc32Tbl : array[0..255] of cardinal; 79 80 procedure MakeCRC32Tbl; 81 var 82 crc : cardinal; 83 i,n : integer; 84 begin 85 for i:=0 to 255 do 86 begin 87 crc:=i; 88 for n:=1 to 8 do 89 if (crc and 1)<>0 then 90 crc:=(crc shr 1) xor cardinal($edb88320) 91 else 92 crc:=crc shr 1; 93 Crc32Tbl[i]:=crc; 94 end; 95 end; 96 97 Function UpdateCrc32(InitCrc:cardinal;const InBuf;InLen:LongInt):cardinal; 98 var 99 i : LongInt; 100 p : pchar; 101 begin 102 if Crc32Tbl[1]=0 then 103 MakeCrc32Tbl; 104 p:=@InBuf; 105 Result:=not InitCrc; 106 for i:=1 to InLen do 107 begin 108 UpdateCrc32:=Crc32Tbl[byte(Result) xor byte(p^)] xor (Result shr 8); 109 inc(p); 110 end; 111 Result:=not Result; 112 end; 113 114 function CheckDbgFile(var e:TExeFile;const fn:string;dbgcrc:cardinal):boolean; 115 var 116 c : cardinal; 117 ofm : word; 118 g : file; 119 begin 120 CheckDbgFile:=false; 121 assign(g,fn); 122 {$I-} 123 ofm:=filemode; 124 filemode:=$40; 125 reset(g,1); 126 filemode:=ofm; 127 {$I+} 128 if ioresult<>0 then 129 exit; 130 { We reuse the buffer from e here to prevent too much stack allocation } 131 c:=0; 132 repeat 133 blockread(g,e.buf,e.bufsize,e.bufcnt); 134 c:=UpdateCrc32(c,e.buf,e.bufcnt); 135 until e.bufcnt<e.bufsize; 136 close(g); 137 CheckDbgFile:=(dbgcrc=c); 138 end; 139 140 function ReadDebugLink(var e:TExeFile;var dbgfn:string):boolean; 141 var 142 dbglink : array[0..512] of char; 143 i, 144 dbglinklen, 145 dbglinkofs : longint; 146 dbgcrc : cardinal; 147 begin 148 ReadDebugLink:=false; 149 if not FindExeSection(e,'.gnu_debuglink',dbglinkofs,dbglinklen) then 150 exit; 151 if dbglinklen>sizeof(dbglink)-1 then 152 exit; 153 fillchar(dbglink,sizeof(dbglink),0); 154 seek(e.f,dbglinkofs); 155 blockread(e.f,dbglink,dbglinklen); 156 dbgfn:=strpas(dbglink); 157 if length(dbgfn)=0 then 158 exit; 159 i:=align(length(dbgfn)+1,4); 160 if (i+4)>dbglinklen then 161 exit; 162 move(dbglink[i],dbgcrc,4); 163 { current dir } 164 if CheckDbgFile(e,dbgfn,dbgcrc) then 165 begin 166 ReadDebugLink:=true; 167 exit; 168 end; 169 { executable dir } 170 i:=length(e.filename); 171 while (i>0) and not(e.filename[i] in AllowDirectorySeparators) do 172 dec(i); 173 if i>0 then 174 begin 175 dbgfn:=copy(e.filename,1,i)+dbgfn; 176 if CheckDbgFile(e,dbgfn,dbgcrc) then 177 begin 178 ReadDebugLink:=true; 179 exit; 180 end; 181 end; 182 end; 76 183 77 184 function OpenStabs(addr : pointer) : boolean; … … 243 350 Delete(func,i,255); 244 351 end; 245 if e.isopen then246 CloseStabs;352 // if e.isopen then 353 // CloseStabs; 247 354 GetLineInfo:=true; 248 355 end;
Note:
See TracChangeset
for help on using the changeset viewer.