File: testdbgconfig.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (251 lines) | stat: -rw-r--r-- 6,472 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
unit TestDbgConfig;

{$mode objfpc}{$H+}

(*
  fpclist.txt contains lines of format:
    [Name]
    exe=/path/fpc.exe
    symbols=none,gs,gw,gwset,gw3


  optional
  gdblist.txt contains lines of format:
    [Name]
    exe=/path/fpc.exe
    version=070201
    symbols=none,gs,gw,gwset,gw3

*)

interface

uses
  Classes, SysUtils, LCLProc;

var
  AppDir, ConfDir: String;

type
  TSymbolType = (stNone, stStabs, stDwarf, stDwarfSet, stDwarf3, stDwarf4);
  TSymbolTypes = set of TSymbolType;

  TCpuBitType = (cpu32, cpu64);
  TCpuBitTypes = set of TCpuBitType;

const
  SymbolTypeNames: Array [TSymbolType] of String = ('No_Dbg', 'Stabs', 'Dwarf', 'Dwarf+Sets', 'Dwarf3', 'Dwarf4');
  SymbolTypeSwitches: Array [TSymbolType] of String = ('', '-gs', '-gw', '-gw -godwarfsets', '-gw3', '-gw4');
  CpuBitNames: Array [TCpuBitType] of String = ('32Bit', '64Bit');

  stDwarf2 = [stDwarf, stDwarfSet];
  stDwarf3Up = [stDwarf3, stDwarf4];

type
  TExternalExeInfo = record
    Name: string;
    Version: Integer;
    ExeName: string;
    SymbolTypes: TSymbolTypes;
    CpuBitTypes: TCpuBitTypes;
    ExtraOpts: string;
  end;

type
  { TBaseList }

  TBaseList = class
  private
    FList: array of TExternalExeInfo;
    function GetCpuBitTypes(Index: Integer): TCpuBitTypes;
    function GetExeName(Index: Integer): string;
    function GetExtraOpts(Index: Integer): string;
    function GetFullInfo(Index: Integer): TExternalExeInfo;
    function GetName(Index: Integer): string;
    function GetSymbolTypes(Index: Integer): TSymbolTypes;
    function GetVersion(Index: Integer): Integer;

  protected
    function  AddName(const AName: string): Integer;
    procedure SetAttribute(AIndex: Integer; const AAttr, AValue: string); virtual;
  public
    procedure Add(Name, Exe: string; Opts: String = '');
    procedure Add(Info: TExternalExeInfo);
    procedure LoadFromFile(const AFileName: string);
    function Count: Integer;
    property Name[Index: Integer]: string read GetName;
    property Version[Index: Integer]: Integer read GetVersion;
    property ExeName[Index: Integer]: string read GetExeName;
    property SymbolTypes[Index: Integer]: TSymbolTypes read GetSymbolTypes;
    property CpuBitTypes[Index: Integer]: TCpuBitTypes read GetCpuBitTypes;
    property ExtraOpts[Index: Integer]: string read GetExtraOpts;
    property FullInfo[Index: Integer]: TExternalExeInfo read GetFullInfo;
  end;

function LoadConfig(FileName: String): TBaseList;

implementation

function StrToSymbolTypes(s: string): TSymbolTypes;
var
  s2: string;
begin
  Result := [];
  while (s <> '') do begin
    while (s <> '') and (s[1] in [' ', ',', #9, #10, #13]) do delete(s,1, 1);
    s2 := '';
    while (s <> '') and not (s[1] in [' ', ',', #9, #10, #13]) do begin
      s2 := s2 + s[1];
      delete(s,1, 1);
    end;
    if s2 = 'none' then Result := Result + [stNone];
    if s2 = 'gs' then Result := Result + [stStabs];
    if s2 = 'gw' then Result := Result + [stDwarf];
    if s2 = 'gwset' then Result := Result + [stDwarfSet];
    if s2 = 'gw3' then Result := Result + [stDwarf3];
    if s2 = 'gw4' then Result := Result + [stDwarf4];
  end;
end;

function StrToCpuBitTypes(s: string): TCpuBitTypes;
var
  s2: string;
begin
  Result := [];
  while (s <> '') do begin
    while (s <> '') and (s[1] in [' ', ',', #9, #10, #13]) do delete(s,1, 1);
    s2 := '';
    while (s <> '') and not (s[1] in [' ', ',', #9, #10, #13]) do begin
      s2 := s2 + s[1];
      delete(s,1, 1);
    end;
    if s2 = '32' then Result := Result + [cpu32];
    if s2 = '64' then Result := Result + [cpu64];
  end;
end;

{ TBaseList }

function TBaseList.GetExeName(Index: Integer): string;
begin
  Result := FList[Index].ExeName;
end;

function TBaseList.GetCpuBitTypes(Index: Integer): TCpuBitTypes;
begin
  Result := FList[Index].CpuBitTypes;
end;

function TBaseList.GetExtraOpts(Index: Integer): string;
begin
  Result := FList[Index].ExtraOpts;
end;

function TBaseList.GetFullInfo(Index: Integer): TExternalExeInfo;
begin
  Result := FList[Index];
end;

function TBaseList.GetName(Index: Integer): string;
begin
  Result := FList[Index].Name;
end;

function TBaseList.GetSymbolTypes(Index: Integer): TSymbolTypes;
begin
  Result := FList[Index].SymbolTypes;
end;

function TBaseList.GetVersion(Index: Integer): Integer;
begin
  Result := FList[Index].Version;
end;

function TBaseList.AddName(const AName: string): Integer;
begin
  Result := length(FList);
  SetLength(FList, Result + 1);
  FList[Result].Name := AName;
  FList[Result].Version := -1;
  FList[Result].ExeName := '';
  FList[Result].SymbolTypes := [];
  FList[Result].CpuBitTypes := [low(TCpuBitType)..high(TCpuBitType)]; // default: all
  FList[Result].ExtraOpts := '';
end;

procedure TBaseList.SetAttribute(AIndex: Integer; const AAttr, AValue: string);
begin
  case StringCase(AAttr, ['exe', 'symbols', 'opts', 'vers', 'version', 'bittype', 'bits'], True, False) of
    0: begin // exe
        FList[AIndex].ExeName := AValue;
      end;
    1: begin // symbols
        FList[AIndex].SymbolTypes := StrToSymbolTypes(AValue);
      end;
    2: begin //opts
        FList[AIndex].ExtraOpts := AValue;
      end;
    3,4: begin
        FList[AIndex].Version := StrToIntDef(AValue,-1);
      end;
    5,6: begin
        FList[AIndex].CpuBitTypes := StrToCpuBitTypes(AValue);
      end;
  end;
end;

procedure TBaseList.Add(Name, Exe: string; Opts: String);
var
  i: LongInt;
begin
  i := AddName(Name);
  FList[i].ExeName := Exe;
  FList[i].SymbolTypes := [low(TSymbolTypes)..high(TSymbolTypes)];
  FList[i].ExtraOpts := Opts;
end;

procedure TBaseList.Add(Info: TExternalExeInfo);
var
  i: Integer;
begin
  i := AddName('');
  FList[i] := Info;
end;

procedure TBaseList.LoadFromFile(const AFileName: string);
var
  txt: TStringList;
  s: string;
  i, j, k: Integer;
begin
  txt := TStringList.Create;
  txt.LoadFromFile(AFileName);
  j := -1;
  for i := 0 to txt.Count - 1 do begin
    s := txt[i];
    if Trim(s) = '' then continue;
    if copy(s, 1, 1) = '[' then begin
      j  := AddName(GetPart(['['], [']'], s));
      continue;
    end;
    if j < 0 then continue;
    k := pos('=', s);
    SetAttribute(j, copy(s, 1, k-1), copy(s, k + 1, length(s)));
  end;
  txt.Free;
end;

function TBaseList.Count: Integer;
begin
  Result := length(FList);
end;

function LoadConfig(FileName: String): TBaseList;
begin
  Result := TBaseList.Create;
  if FileExists(FileName) then
    Result.LoadFromFile(FileName);
end;

end.