forked from yavfast/dbg-spider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJclTD32Ex.pas
3027 lines (2678 loc) · 98.2 KB
/
JclTD32Ex.pas
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{**************************************************************************************************}
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the }
{ License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
{ ANY KIND, either express or implied. See the License for the specific language governing rights }
{ and limitations under the License. }
{ }
{ The Original Code is JclTD32.pas. }
{ }
{ The Initial Developer of the Original Code is Flier Lu (<flier_lu att yahoo dott com dott cn>). }
{ Portions created by Flier Lu are Copyright (C) Flier Lu. All Rights Reserved. }
{ }
{ Contributors: }
{ Flier Lu (flier) }
{ Olivier Sannier (obones) }
{ Petr Vones (pvones) }
{ Heinz Zastrau (heinzz) }
{ Andreas Hausladen (ahuser) }
{ }
{**************************************************************************************************}
{ }
{ Borland TD32 symbolic debugging information support routines and classes. }
{ }
{**************************************************************************************************}
{ }
{ Last modified: $Date:: 2011-09-03 00:07:50 +0200 (sam. 03 sept. 2011) $ }
{ Revision: $Rev:: 3599 $ }
{ Author: $Author:: outchy $ }
{ }
{**************************************************************************************************}
unit JclTD32Ex;
interface
{$I jcl.inc}
{$I windowsonly.inc}
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$IFDEF HAS_UNITSCOPE}
{$IFDEF MSWINDOWS}
Winapi.Windows,
{$ENDIF MSWINDOWS}
System.Classes, System.SysUtils, System.Contnrs,
{$ELSE ~HAS_UNITSCOPE}
{$IFDEF MSWINDOWS}
Windows,
{$ENDIF MSWINDOWS}
Classes, SysUtils, Contnrs,
{$ENDIF ~HAS_UNITSCOPE}
JclBase,
{$IFDEF BORLAND}
JclPeImage,
{$ENDIF BORLAND}
JclFileUtils;
{ TODO -cDOC : Original code: "Flier Lu" <flier_lu att yahoo dott com dott cn> }
// TD32 constants and structures
{*******************************************************************************
[-----------------------------------------------------------------------]
[ Symbol and Type OMF Format Borland Executable Files ]
[-----------------------------------------------------------------------]
Introduction
This section describes the format used to embed debugging information into
the executable file.
Debug Information Format
The format encompasses a block of data which goes at the end of the .EXE
file, i.e., after the header plus load image, overlays, and
Windows/Presentation Manager resource compiler information. The lower
portion of the file is unaffected by the additional data.
The last eight bytes of the file contain a signature and a long file offset
from the end of the file (lfoBase). The signature is FBxx, where xx is the
version number. The long offset indicates the position in the file
(relative to the end of the file) of the base address. For the LX format
executables, the base address is determined by looking at the executable
header.
The signatures have the following meanings:
FB09 The signature for a Borland 32 bit symbol file.
The value
lfaBase=length of the file - lfoBase
gives the base address of the start of the Symbol and Type OMF information
relative to the beginning of the file. All other file offsets in the
Symbol and Type OMF are relative to the lfaBase. At the base address the
signature is repeated, followed by the long displacement to the subsection
directory (lfoDir). All subsections start on a long word boundary and are
designed to maintain natural alignment internally in each subsection and
within the subsection directory.
Subsection Directory
The subsection directory has the format
Directory header
Directory entry 0
Directory entry 1
.
.
.
Directory entry n
There is no requirement for a particular subsection of a particular module to exist.
The following is the layout of the FB09 debug information in the image:
FB09 Header
sstModule [1]
.
.
.
sstModule [n]
sstAlignSym [1]
sstSrcModule [1]
.
.
.
sstAlignSym [n]
sstSrcModule [n]
sstGlobalSym
sstGlobalTypes
sstNames
SubSection Directory
FB09 Trailer
*******************************************************************************}
const
Borland32BitSymbolFileSignatureForDelphi = $39304246; // 'FB09'
Borland32BitSymbolFileSignatureForBCB = $41304246; // 'FB0A'
type
{ Signature structure }
PJclTD32FileSignature = ^TJclTD32FileSignature;
TJclTD32FileSignature = packed record
Signature: DWORD;
Offset: DWORD;
end;
const
{ Subsection Types }
SUBSECTION_TYPE_MODULE = $120;
SUBSECTION_TYPE_TYPES = $121;
SUBSECTION_TYPE_SYMBOLS = $124;
SUBSECTION_TYPE_ALIGN_SYMBOLS = $125;
SUBSECTION_TYPE_SOURCE_MODULE = $127;
SUBSECTION_TYPE_GLOBAL_SYMBOLS = $129;
SUBSECTION_TYPE_GLOBAL_TYPES = $12B;
SUBSECTION_TYPE_NAMES = $130;
type
{ Subsection directory header structure }
{ The directory header structure is followed by the directory entries
which specify the subsection type, module index, file offset, and size.
The subsection directory gives the location (LFO) and size of each subsection,
as well as its type and module number if applicable. }
PDirectoryEntry = ^TDirectoryEntry;
TDirectoryEntry = packed record
SubsectionType: Word; // Subdirectory type
ModuleIndex: Word; // Module index
Offset: DWORD; // Offset from the base offset lfoBase
Size: DWORD; // Number of bytes in subsection
end;
{ The subsection directory is prefixed with a directory header structure
indicating size and number of subsection directory entries that follow. }
PDirectoryHeader = ^TDirectoryHeader;
TDirectoryHeader = packed record
Size: Word; // Length of this structure
DirEntrySize: Word; // Length of each directory entry
DirEntryCount: DWORD; // Number of directory entries
lfoNextDir: DWORD; // Offset from lfoBase of next directory.
Flags: DWORD; // Flags describing directory and subsection tables.
DirEntries: array [0..0] of TDirectoryEntry;
end;
{*******************************************************************************
SUBSECTION_TYPE_MODULE $120
This describes the basic information about an object module including code
segments, module name, and the number of segments for the modules that
follow. Directory entries for sstModules precede all other subsection
directory entries.
*******************************************************************************}
type
PSegmentInfo = ^TSegmentInfo;
TSegmentInfo = packed record
Segment: Word; // Segment that this structure describes
Flags: Word; // Attributes for the logical segment.
// The following attributes are defined:
// $0000 Data segment
// $0001 Code segment
Offset: DWORD; // Offset in segment where the code starts
Size: DWORD; // Count of the number of bytes of code in the segment
end;
PSegmentInfoArray = ^TSegmentInfoArray;
TSegmentInfoArray = array [0..32767] of TSegmentInfo;
PModuleInfo = ^TModuleInfo;
TModuleInfo = packed record
OverlayNumber: Word; // Overlay number
LibraryIndex: Word; // Index into sstLibraries subsection
// if this module was linked from a library
SegmentCount: Word; // Count of the number of code segments
// this module contributes to
DebuggingStyle: Word; // Debugging style for this module.
NameIndex: DWORD; // Name index of module.
TimeStamp: DWORD; // Time stamp from the OBJ file.
Reserved: array [0..2] of DWORD; // Set to 0.
Segments: array [0..0] of TSegmentInfo;
// Detailed information about each segment
// that code is contributed to.
// This is an array of cSeg count segment
// information descriptor structures.
end;
{*******************************************************************************
SUBSECTION_TYPE_SOURCE_MODULE $0127
This table describes the source line number to addressing mapping
information for a module. The table permits the description of a module
containing multiple source files with each source file contributing code to
one or more code segments. The base addresses of the tables described
below are all relative to the beginning of the sstSrcModule table.
Module header
Information for source file 1
Information for segment 1
.
.
.
Information for segment n
.
.
.
Information for source file n
Information for segment 1
.
.
.
Information for segment n
*******************************************************************************}
type
{ The line number to address mapping information is contained in a table with
the following format: }
PLineMappingEntry = ^TLineMappingEntry;
TLineMappingEntry = packed record
SegmentIndex: Word; // Segment index for this table
PairCount: Word; // Count of the number of source line pairs to follow
Offsets: array [0..0] of DWORD;
// An array of 32-bit offsets for the offset
// within the code segment ofthe start of ine contained
// in the parallel array linenumber.
(*
{ This is an array of 16-bit line numbers of the lines in the source file
that cause code to be emitted to the code segment.
This array is parallel to the offset array.
If cPair is not even, then a zero word is emitted to
maintain natural alignment in the sstSrcModule table. }
LineNumbers: array [0..PairCount - 1] of Word;
*)
end;
TOffsetPair = packed record
StartOffset: DWORD;
EndOffset: DWORD;
end;
POffsetPairArray = ^TOffsetPairArray;
TOffsetPairArray = array [0..32767] of TOffsetPair;
{ The file table describes the code segments that receive code from this
source file. Source file entries have the following format: }
PSourceFileEntry = ^TSourceFileEntry;
TSourceFileEntry = packed record
SegmentCount: Word; // Number of segments that receive code from this source file.
NameIndex: DWORD; // Name index of Source file name.
BaseSrcLines: array [0..0] of DWORD;
// An array of offsets for the line/address mapping
// tables for each of the segments that receive code
// from this source file.
(*
{ An array of two 32-bit offsets per segment that
receives code from this module. The first offset
is the offset within the segment of the first byte
of code from this module. The second offset is the
ending address of the code from this module. The
order of these pairs corresponds to the ordering of
the segments in the seg array. Zeros in these
entries means that the information is not known and
the file and line tables described below need to be
examined to determine if an address of interest is
contained within the code from this module. }
SegmentAddress: array [0..SegmentCount - 1] of TOffsetPair;
Name: ShortString; // Count of the number of bytes in source file name
*)
end;
{ The module header structure describes the source file and code segment
organization of the module. Each module header has the following format: }
PSourceModuleInfo = ^TSourceModuleInfo;
TSourceModuleInfo = packed record
FileCount: Word; // The number of source file scontributing code to segments
SegmentCount: Word; // The number of code segments receiving code from this module
BaseSrcFiles: array [0..0] of DWORD;
(*
// This is an array of base offsets from the beginning of the sstSrcModule table
BaseSrcFiles: array [0..FileCount - 1] of DWORD;
{ An array of two 32-bit offsets per segment that
receives code from this module. The first offset
is the offset within the segment of the first byte
of code from this module. The second offset is the
ending address of the code from this module. The
order of these pairs corresponds to the ordering of
the segments in the seg array. Zeros in these
entries means that the information is not known and
the file and line tables described below need to be
examined to determine if an address of interest is
contained within the code from this module. }
SegmentAddress: array [0..SegmentCount - 1] of TOffsetPair;
{ An array of segment indices that receive code from
this module. If the number of segments is not
even, a pad word is inserted to maintain natural
alignment. }
SegmentIndexes: array [0..SegmentCount - 1] of Word;
*)
end;
{*******************************************************************************
SUBSECTION_TYPE_GLOBAL_TYPES $12b
This subsection contains the packed type records for the executable file.
The first long word of the subsection contains the number of types in the
table. This count is followed by a count-sized array of long offsets to the
corresponding type record. As the sstGlobalTypes subsection is written, each
type record is forced to start on a long word boundary. However, the length
of the type string is not adjusted by the pad count. The remainder of the
subsection contains the type records. This table is invalid for NB05
signatures.
Note that for NB07 and NB08 executables, the type string offset is from the
beginning of the subsection table. For NB09 executables, the type string
offset is from the first type record of the sstGlobalTypes subsection. Using
the offset from the first type record simplifies demand loading of the
sstGlobalTypes table.
*******************************************************************************}
type
PGlobalTypeInfo = ^TGlobalTypeInfo;
TGlobalTypeInfo = packed record
Unused: array[0..2] of Byte; // Reserved for future use. Must be emitted as zeroes
Signature: Byte; // Global types table signature
Count: DWORD; // Count or number of types
Offsets: array [0..0] of DWORD; // Offset of each type. See note above
end;
const
{ Symbol type defines }
SYMBOL_TYPE_COMPILE = $0001; // Compile flags symbol
SYMBOL_TYPE_REGISTER = $0002; // Register variable
SYMBOL_TYPE_CONST = $0003; // Constant symbol
SYMBOL_TYPE_UDT = $0004; // User-defined Type
SYMBOL_TYPE_SSEARCH = $0005; // Start search
SYMBOL_TYPE_END = $0006; // End block, procedure, with, or thunk
SYMBOL_TYPE_SKIP = $0007; // Skip - Reserve symbol space
SYMBOL_TYPE_CVRESERVE = $0008; // Reserved for Code View internal use
SYMBOL_TYPE_OBJNAME = $0009; // Specify name of object file
SYMBOL_TYPE_GPROCREF = $0020;
SYMBOL_TYPE_GDATAREF = $0021;
SYMBOL_TYPE_EDATA = $0022;
SYMBOL_TYPE_EPROC = $0023;
SYMBOL_TYPE_USES = $0024;
SYMBOL_TYPE_NAMESPACE = $0025;
SYMBOL_TYPE_USING = $0026;
SYMBOL_TYPE_PCONSTANT = $0027;
SYMBOL_TYPE_BPREL16 = $0100; // BP relative 16:16
SYMBOL_TYPE_LDATA16 = $0101; // Local data 16:16
SYMBOL_TYPE_GDATA16 = $0102; // Global data 16:16
SYMBOL_TYPE_PUB16 = $0103; // Public symbol 16:16
SYMBOL_TYPE_LPROC16 = $0104; // Local procedure start 16:16
SYMBOL_TYPE_GPROC16 = $0105; // Global procedure start 16:16
SYMBOL_TYPE_THUNK16 = $0106; // Thunk start 16:16
SYMBOL_TYPE_BLOCK16 = $0107; // Block start 16:16
SYMBOL_TYPE_WITH16 = $0108; // With start 16:16
SYMBOL_TYPE_LABEL16 = $0109; // Code label 16:16
SYMBOL_TYPE_CEXMODEL16 = $010A; // Change execution model 16:16
SYMBOL_TYPE_VFTPATH16 = $010B; // Virtual function table path descriptor 16:16
SYMBOL_TYPE_BPREL32 = $0200; // BP relative 16:32
SYMBOL_TYPE_LDATA32 = $0201; // Local data 16:32
SYMBOL_TYPE_GDATA32 = $0202; // Global data 16:32
SYMBOL_TYPE_PUB32 = $0203; // Public symbol 16:32
SYMBOL_TYPE_LPROC32 = $0204; // Local procedure start 16:32
SYMBOL_TYPE_GPROC32 = $0205; // Global procedure start 16:32
SYMBOL_TYPE_THUNK32 = $0206; // Thunk start 16:32
SYMBOL_TYPE_BLOCK32 = $0207; // Block start 16:32
SYMBOL_TYPE_WITH32 = $0208; // With start 16:32
SYMBOL_TYPE_LABEL32 = $0209; // Label 16:32
SYMBOL_TYPE_CEXMODEL32 = $020A; // Change execution model 16:32
SYMBOL_TYPE_VFTPATH32 = $020B; // Virtual function table path descriptor 16:32
SYMBOL_TYPE_ENTRY32 = $0210;
SYMBOL_TYPE_OPTVAR32 = $0211;
SYMBOL_TYPE_PROCRET32 = $0212;
SYMBOL_TYPE_SAVREGS32 = $0213;
SYMBOL_TYPE_SLINK32 = $0230;
{*******************************************************************************
Global and Local Procedure Start 16:32
SYMBOL_TYPE_LPROC32 $0204
SYMBOL_TYPE_GPROC32 $0205
The symbol records define local (file static) and global procedure
definition. For C/C++, functions that are declared static to a module are
emitted as Local Procedure symbols. Functions not specifically declared
static are emitted as Global Procedures.
For each SYMBOL_TYPE_GPROC32 emitted, an SYMBOL_TYPE_GPROCREF symbol
must be fabricated and emitted to the SUBSECTION_TYPE_GLOBAL_SYMBOLS section.
*******************************************************************************}
type
TSymbolProcInfo = packed record
pParent: DWORD;
pEnd: DWORD;
pNext: DWORD;
Size: DWORD; // Length in bytes of this procedure
DebugStart: DWORD; // Offset in bytes from the start of the procedure to
// the point where the stack frame has been set up.
DebugEnd: DWORD; // Offset in bytes from the start of the procedure to
// the point where the procedure is ready to return
// and has calculated its return value, if any.
// Frame and register variables an still be viewed.
Offset: DWORD; // Offset portion of the segmented address of
// the start of the procedure in the code segment
Segment: Word; // Segment portion of the segmented address of
// the start of the procedure in the code segment
Reserved1: Word;
TypeIndex: DWORD; // Type of the procedure type record
NameIndex: DWORD; // Name index of procedure
Reserved2: DWORD;
end;
TSymbolObjNameInfo = packed record
Signature: DWORD; // Signature for the CodeView information contained in
// this module
NameIndex: DWORD; // Name index of the object file
end;
TSymbolDataInfo = packed record
Offset: DWORD; // Offset portion of the segmented address of
// the start of the data in the code segment
Segment: Word; // Segment portion of the segmented address of
// the start of the data in the code segment
Reserved1: Word;
TypeIndex: DWORD; // Type index of the symbol
NameIndex: DWORD; // Name index of the symbol
Reserved2: DWORD;
end;
TSymbolWithInfo = packed record
pParent: DWORD;
Size: DWORD; // Length in bytes of this "with"
Offset: DWORD; // Offset portion of the segmented address of
// the start of the "with" in the code segment
Segment: Word; // Segment portion of the segmented address of
// the start of the "with" in the code segment
Reserved1: Word;
TypeIndex: DWORD;
NameIndex: DWORD; // Name index of the "with"
Reserved2: DWORD;
end;
TSymbolLabelInfo = packed record
Offset: DWORD; // Offset portion of the segmented address of
// the start of the label in the code segment
Segment: Word; // Segment portion of the segmented address of
// the start of the label in the code segment
NearFar: Byte; // Address mode of the label:
// 0 near
// 4 far
Reserved: Byte;
NameIndex: DWORD; // Name index of the label
end;
TSymbolConstantInfo = packed record
TypeIndex: DWORD;
Flags: Word;
NameIndex: DWORD;
Reserved: DWORD;
Value: array[0..0] of Byte;
end;
TSymbolUdtInfo = packed record
TypeIndex: DWORD; // Type index of the type
Properties: Word; // isTag:1 True if this is a tag (not a typedef)
// isNest:1 True if the type is a nested type (its name
// will be 'class_name::type_name' in that case)
NameIndex: DWORD; // Name index of the type
Reserved: DWORD;
end;
TSymbolVftPathInfo = packed record
Offset: DWORD; // Offset portion of start of the virtual function table
Segment: Word; // Segment portion of the virtual function table
Reserved: Word;
RootIndex: DWORD; // The type index of the class at the root of the path
PathIndex: DWORD; // Type index of the record describing the base class
// path from the root to the leaf class for the virtual
// function table
end;
TSymbolBPRelInfo = packed record
Offset: Integer;
TypeIndex: DWORD;
NameIndex: DWORD;
Reserved: DWORD;
end;
TSymbolStartInfo = packed record
Offset: DWORD;
Segment: Word;
CodeCount: Word;
DataCount: Word;
FirstData: DWORD;
Reserved: Word;
end;
TSymbolLinkInfo = packed record
Offset: DWORD;
end;
TSymbolUsesInfo = packed record
Names: array[0..0] of DWORD;
end;
TRegisterInfo = packed record
TypeIndex: DWORD;
Registers: Word;
NameIndex: DWORD;
Reserved: DWORD;
end;
PRegisterRange = ^TRegisterRange;
TRegisterRange = packed record
Start: DWORD;
Len: DWORD;
Registers: Word;
end;
TOptVarInfo = packed record
Count: Word;
Ranges: array[0..0] of TRegisterRange;
end;
type
{ Symbol Information Records }
PSymbolInfo = ^TSymbolInfo;
TSymbolInfo = packed record
Size: Word;
SymbolType: Word;
case Word of
SYMBOL_TYPE_LPROC32, SYMBOL_TYPE_GPROC32:
(Proc: TSymbolProcInfo);
SYMBOL_TYPE_OBJNAME:
(ObjName: TSymbolObjNameInfo);
SYMBOL_TYPE_LDATA32, SYMBOL_TYPE_GDATA32, SYMBOL_TYPE_PUB32:
(Data: TSymbolDataInfo);
SYMBOL_TYPE_WITH32:
(With32: TSymbolWithInfo);
SYMBOL_TYPE_LABEL32:
(Label32: TSymbolLabelInfo);
SYMBOL_TYPE_CONST, SYMBOL_TYPE_PCONSTANT:
(Constant: TSymbolConstantInfo);
SYMBOL_TYPE_UDT:
(Udt: TSymbolUdtInfo);
SYMBOL_TYPE_VFTPATH32:
(VftPath: TSymbolVftPathInfo);
SYMBOL_TYPE_REGISTER:
(Registers: TRegisterInfo);
SYMBOL_TYPE_SSEARCH:
(Start: TSymbolStartInfo);
SYMBOL_TYPE_USES:
(Use: TSymbolUsesInfo);
SYMBOL_TYPE_BPREL32:
(BPRel: TSymbolBPRelInfo);
SYMBOL_TYPE_SLINK32:
(Link: TSymbolLinkInfo);
SYMBOL_TYPE_OPTVAR32:
(OptVar: TOptVarInfo);
end;
PSymbolInfos = ^TSymbolInfos;
TSymbolInfos = packed record
Signature: DWORD;
Symbols: array [0..0] of TSymbolInfo;
end;
{$IFDEF SUPPORTS_EXTSYM}
{$EXTERNALSYM Borland32BitSymbolFileSignatureForDelphi}
{$EXTERNALSYM Borland32BitSymbolFileSignatureForBCB}
{$EXTERNALSYM SUBSECTION_TYPE_MODULE}
{$EXTERNALSYM SUBSECTION_TYPE_TYPES}
{$EXTERNALSYM SUBSECTION_TYPE_SYMBOLS}
{$EXTERNALSYM SUBSECTION_TYPE_ALIGN_SYMBOLS}
{$EXTERNALSYM SUBSECTION_TYPE_SOURCE_MODULE}
{$EXTERNALSYM SUBSECTION_TYPE_GLOBAL_SYMBOLS}
{$EXTERNALSYM SUBSECTION_TYPE_GLOBAL_TYPES}
{$EXTERNALSYM SUBSECTION_TYPE_NAMES}
{$EXTERNALSYM SYMBOL_TYPE_COMPILE}
{$EXTERNALSYM SYMBOL_TYPE_REGISTER}
{$EXTERNALSYM SYMBOL_TYPE_CONST}
{$EXTERNALSYM SYMBOL_TYPE_UDT}
{$EXTERNALSYM SYMBOL_TYPE_SSEARCH}
{$EXTERNALSYM SYMBOL_TYPE_END}
{$EXTERNALSYM SYMBOL_TYPE_SKIP}
{$EXTERNALSYM SYMBOL_TYPE_CVRESERVE}
{$EXTERNALSYM SYMBOL_TYPE_OBJNAME}
{$EXTERNALSYM SYMBOL_TYPE_BPREL16}
{$EXTERNALSYM SYMBOL_TYPE_LDATA16}
{$EXTERNALSYM SYMBOL_TYPE_GDATA16}
{$EXTERNALSYM SYMBOL_TYPE_PUB16}
{$EXTERNALSYM SYMBOL_TYPE_LPROC16}
{$EXTERNALSYM SYMBOL_TYPE_GPROC16}
{$EXTERNALSYM SYMBOL_TYPE_THUNK16}
{$EXTERNALSYM SYMBOL_TYPE_BLOCK16}
{$EXTERNALSYM SYMBOL_TYPE_WITH16}
{$EXTERNALSYM SYMBOL_TYPE_LABEL16}
{$EXTERNALSYM SYMBOL_TYPE_CEXMODEL16}
{$EXTERNALSYM SYMBOL_TYPE_VFTPATH16}
{$EXTERNALSYM SYMBOL_TYPE_BPREL32}
{$EXTERNALSYM SYMBOL_TYPE_LDATA32}
{$EXTERNALSYM SYMBOL_TYPE_GDATA32}
{$EXTERNALSYM SYMBOL_TYPE_PUB32}
{$EXTERNALSYM SYMBOL_TYPE_LPROC32}
{$EXTERNALSYM SYMBOL_TYPE_GPROC32}
{$EXTERNALSYM SYMBOL_TYPE_THUNK32}
{$EXTERNALSYM SYMBOL_TYPE_BLOCK32}
{$EXTERNALSYM SYMBOL_TYPE_WITH32}
{$EXTERNALSYM SYMBOL_TYPE_LABEL32}
{$EXTERNALSYM SYMBOL_TYPE_CEXMODEL32}
{$EXTERNALSYM SYMBOL_TYPE_VFTPATH32}
{$ENDIF SUPPORTS_EXTSYM}
// TD32 information related classes
type
TJclTD32SourceModuleInfo = class;
TJclTD32SymbolInfo = class;
TJclTD32ProcSymbolInfo = class;
TJclTD32ModuleInfo = class(TObject)
private
FNameIndex: DWORD;
FSegments: PSegmentInfoArray;
FSegmentCount: Integer;
FSourceModules: TList;
FSymbols: TList;
FProcSymbols: TList;
FUsedModuleNameIndices: TList;
function GetSegment(const Idx: Integer): TSegmentInfo;
function GetSourceModule(const Idx: Integer): TJclTD32SourceModuleInfo;
function GetSourceModuleCount: Integer;
function GetSymbol(const Idx: Integer): TJclTD32SymbolInfo;
function GetSymbolCount: Integer;
function GetProcSymbol(const Idx: Integer): TJclTD32ProcSymbolInfo;
function GetProcSymbolCount: Integer;
function GetUsedModuleNameIndex(const Idx: Integer): Integer;
function GetUsedModuleNameIndexCount: Integer;
protected
constructor Create(pModInfo: PModuleInfo);
public
destructor Destroy; override;
function FindProc(Offset: DWORD): TJclTD32ProcSymbolInfo;
property NameIndex: DWORD read FNameIndex;
property SegmentCount: Integer read FSegmentCount; //GetSegmentCount;
property Segment[const Idx: Integer]: TSegmentInfo read GetSegment; default;
property SourceModules[const Idx: Integer]: TJclTD32SourceModuleInfo read GetSourceModule;
property SourceModuleCount: Integer read GetSourceModuleCount;
property Symbols[const Idx: Integer]: TJclTD32SymbolInfo read GetSymbol;
property SymbolCount: Integer read GetSymbolCount;
property ProcSymbols[const Idx: Integer]: TJclTD32ProcSymbolInfo read GetProcSymbol;
property ProcSymbolCount: Integer read GetProcSymbolCount;
property UsedModuleNameIndices[const Idx: Integer]: Integer read GetUsedModuleNameIndex;
property UsedModuleNameIndexCount: Integer read GetUsedModuleNameIndexCount;
end;
TJclTD32LineInfo = class(TObject)
private
FLineNo: DWORD;
FOffset: DWORD;
FSegment: Word;
public
constructor Create(const ALineNo, AOffset: DWORD; const ASegment: Word);
property LineNo: DWORD read FLineNo;
property Offset: DWORD read FOffset;
property Segment: Word read FSegment;
end;
TJclTD32SourceModuleInfo = class(TObject)
private
FLines: TObjectList;
FSegments: POffsetPairArray;
FSegmentCount: Integer;
FNameIndex: DWORD;
function GetLine(const Idx: Integer): TJclTD32LineInfo;
function GetLineCount: Integer;
function GetSegment(const Idx: Integer): TOffsetPair;
protected
constructor Create(pSrcFile: PSourceFileEntry; const Base: DWORD);
public
destructor Destroy; override;
function FindLine(const AAddr: DWORD; var ALine: TJclTD32LineInfo): LongBool;
property NameIndex: DWORD read FNameIndex;
property LineCount: Integer read GetLineCount;
property Line[const Idx: Integer]: TJclTD32LineInfo read GetLine; default;
property SegmentCount: Integer read FSegmentCount; //GetSegmentCount;
property Segment[const Idx: Integer]: TOffsetPair read GetSegment;
end;
TJclTD32SymbolInfo = class(TObject)
private
FID: DWORD;
FParentID: DWORD;
FParent: TJclTD32SymbolInfo;
FSymbolType: Word;
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); virtual;
property ID: DWORD read FID;
property ParentID: DWORD read FParentID;
property Parent: TJclTD32SymbolInfo read FParent;
property SymbolType: Word read FSymbolType;
end;
TJclTD32NamedSymbol = class(TJclTD32SymbolInfo)
private
FNameIndex: DWORD;
FTypeIndex: DWORD;
public
property NameIndex: DWORD read FNameIndex;
property TypeIndex: DWORD read FTypeIndex;
end;
TJclTD32Scope = class(TJclTD32NamedSymbol)
private
FSegment: Word;
FOffset: DWORD;
FSize: DWORD;
public
property Segment: Word read FSegment;
property Offset: DWORD read FOffset;
property Size: DWORD read FSize;
end;
TJclTD32ProcSymbolInfo = class(TJclTD32Scope)
private
FDebugStart: DWORD;
FDebugEnd: DWORD;
FSymbols: TList;
function GetSymbol(const Idx: Integer): TJclTD32SymbolInfo;
function GetSymbolCount: Integer;
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); override;
destructor Destroy; override;
property DebugStart: DWORD read FDebugStart;
property DebugEnd: DWORD read FDebugEnd;
property Symbols[const Idx: Integer]: TJclTD32SymbolInfo read GetSymbol;
property SymbolCount: Integer read GetSymbolCount;
end;
TJclTD32LocalProcSymbolInfo = class(TJclTD32ProcSymbolInfo);
TJclTD32GlobalProcSymbolInfo = class(TJclTD32ProcSymbolInfo);
TJclTD32WithSymbolInfo = class(TJclTD32Scope)
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); override;
end;
TJclTD32BPRel32SymbolInfo = class(TJclTD32NamedSymbol)
private
FOffset: Integer;
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); override;
property Offset: Integer read FOffset;
end;
TJclTD32RegisterSymbolInfo = class(TJclTD32NamedSymbol)
private
FRegisters: Word;
FRanges: array of PRegisterRange;
function GetRange(const Index: Integer): PRegisterRange;
function GetRangeCount: Integer;
protected
procedure AnalizeRanges(pSymInfo: PSymbolInfo);
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); override;
property Registers: Word read FRegisters;
property Range[const Index: Integer]: PRegisterRange read GetRange;
property RangeCount: Integer read GetRangeCount;
end;
{ not used by Delphi }
TJclTD32ObjNameSymbolInfo = class(TJclTD32SymbolInfo)
private
FSignature: DWORD;
FNameIndex: DWORD;
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); override;
property NameIndex: DWORD read FNameIndex;
property Signature: DWORD read FSignature;
end;
TJclTD32DataSymbolInfo = class(TJclTD32NamedSymbol)
private
FSegment: Word;
FOffset: DWORD;
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); override;
property Segment: Word read FSegment;
property Offset: DWORD read FOffset;
end;
TJclTD32LDataSymbolInfo = class(TJclTD32DataSymbolInfo);
TJclTD32GDataSymbolInfo = class(TJclTD32DataSymbolInfo);
TJclTD32UdtSymbolInfo = class(TJclTD32NamedSymbol)
private
FProperties: Word;
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); override;
property Properties: Word read FProperties;
end;
TJclTD32StartSymbolInfo = class(TJclTD32SymbolInfo)
private
FSegment: Word;
FOffset: DWORD;
FCodeCount: Word;
FDataCount: Word;
FFirstData: DWORD;
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); override;
property Segment: Word read FSegment;
property Offset: DWORD read FOffset;
property CodeCount: Word read FCodeCount;
property DataCount: Word read FDataCount;
property FirstData: DWORD read FFirstData;
end;
TJclTD32EndSymbolInfo = class(TJclTD32SymbolInfo);
TJclTD32LinkSymbolInfo = class(TJclTD32SymbolInfo)
private
FOffset: DWORD;
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); override;
property Offset: DWORD read FOffset;
end;
TJclTD32ConstantSymbolInfo = class(TJclTD32NamedSymbol)
FFlags: Word;
FSize: Word;
FValue: Pointer;
public
constructor Create(pSymInfo: PSymbolInfo; const aID: DWORD); override;
destructor Destroy; override;
property Flags: Word read FFlags;
property Size: Word read FSize;
property Value: Pointer read FValue;
end;
const
{ Leaf indices for type records that can be referenced from symbols }
LF_MODIFIER = $1;
LF_POINTER = $2;
LF_ARRAY = $3;
LF_CLASS = $4;
LF_STRUCTURE = $5;
LF_UNION = $6;
LF_ENUM = $7;
LF_PROCEDURE = $8;
LF_MFUNCTION = $9;
LF_VTSHAPE = $A;
LF_COBOL0 = $B;
LF_COBOL1 = $C;
LF_BARRAY = $D;
LF_LABEL = $E;
LF_NULL = $F;
LF_NOTTRAN = $10;
LF_DIMARRAY = $11;
LF_VFTPATH = $12;
LF_PRECOMP = $13;
LF_ENDPRECOMP = $14;
LF_OEM = $15;
{ Delphi leafs }
LF_SET = $30;
LF_SUBRANGE = $31;
LF_PARRAY = $32;
LF_PSTRING = $33;
LF_CLOSURE = $34;
LF_PROPERTY = $35;
LF_LSTRING = $36;
LF_VARIANT = $37;
LF_CLASSREF = $38;
LF_WSTRING = $39;
{ Leaf indices for type records that can be referenced from other type records }
LF_SKIP = $200;
LF_ARGLIST = $201;
LF_DEFARG = $202;
LF_LIST = $203;
LF_FIELDLIST = $204;
LF_DERIVED = $205;
LF_BITFIELD = $206;
LF_METHODLIST = $207;
LF_DIMCONU = $208;
LF_DIMCONLU = $209;
LF_DIMVARU = $20A;
LF_DIMVARLU = $20B;
LF_REFSYM = $20C;
{ Leaf indices for fields of complex lists }
LF_BCLASS = $400;
LF_VBCLASS = $401;
LF_IVBCLASS = $402;
LF_ENUMERATE = $403;
LF_FRIENDFCN = $404;
LF_INDEX = $405;
LF_MEMBER = $406;
LF_STMEMBER = $407;
LF_METHOD = $408;
LF_NESTTYPE = $409;
LF_VFUNCTAB = $40A;
LF_FRIENDCLS = $40B;
LF_ONEMETHOD = $40C;
LF_VFUNCOFF = $40D;
{ Leaf indices for numeric fields of symbols and type records }
LF_CHAR = $8000;
LF_SHORT = $8001;
LF_USHORT = $8002;
LF_LONG = $8003;
LF_ULONG = $8004;