Debian Codegraph @

tools/extractdwrflnfo.lpr

raw
1 {
2 This file is part of the chelinfo library.
3
4 Copyright (c) 2008 by Anton Rzheshevski
5
6 Dwarf LineInfo Extractor
7
8 See the file COPYING.FPC, included in this distribution,
9 for details about the copyright.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 **********************************************************************}
16 {
17 2008, Anton Rzheshevski aka Cheb:
18 Like dr. Frankenshtein I sewn this library together
19 from the dead meat of the the FPC RTL modules
20 lineinfo.pp and lnfodwrf.pp.
21 These (as of Jan. 2008 / FPC 2.2.0) both didn't work
22 and had several limitations (e.g. inability to be used
23 from a DLL)
24
25 }
26
27 {note: DON'T FORGET to compile your program with the -gw key
28 Lazarus: you must type it in
29 Project -> Compiler Options -> Other -> User parameters
30 }
31
32 {$mode delphi}
33 {$longstrings on}
34 {$ifndef unix}
35 {$apptype console}
36 {$endif}
37
38 //extracts the line info in the dwarf format from the executable
39
40
41 program extractdwrflnfo;
42
43 uses
44 SysUtils, Classes, un_xtrctdwrflnfo, zstream;
45
46 var
47 _dwarf: pointer;
48 DwarfSize, CompressedDwarfSize: QWord;
49 base_addr: QWord;
50 f: TFileStream;
51 CS: TCompressionStream;
52 dllname, iname: ansistring;
53 begin
54
55 if Paramcount = 0 then
56 begin
57 WriteLn('Usage: ' + ExtractFileName(GetModuleName(0)) + ' <executable name>');
58 exit;
59 end;
60
61 dllname:= ParamStr(1);
62
63 WriteLn('Extracting Dwarf line info from ', dllname);
64 try
65 iname:= DlnNameByExename(dllname);
66
67 if ExtractDwarfLineInfo(dllname, _dwarf, DwarfSize, base_addr) then begin
68
69 f:= TFileStream.Create(iname , fmCreate);
70 CS:= TCompressionStream.Create(clMax, f);
71 CS.Write(dwarfsize, sizeof(dwarfsize)); // 8 bytes (QWORD)
72 CS.Write(base_addr, sizeof(base_addr)); // 8 bytes (QWORD)
73 CS.Write(_dwarf^, dwarfsize);
74 CS.Free;
75 CompressedDwarfSize := f.Size;
76 f.free;
77
78 WriteLn('Ok, saved ', CompressedDwarfSize, ' bytes to ', iname);
79 end
80 else begin
81 if FileExists(iname) then DeleteFile(iname);
82 WriteLn('Error: ' + ExtractDwarfLineInfoError);
83 end;
84 except
85 WriteLn((ExceptObject as Exception).Message);
86 end;
87 end.
88