-
Notifications
You must be signed in to change notification settings - Fork 2
/
1460-StabsParser.patch
6622 lines (6619 loc) · 457 KB
/
1460-StabsParser.patch
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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: astrelsky <ajs222@njit.edu>
Date: Mon, 20 Jan 2020 21:00:34 -0500
Subject: [PATCH] 1460: StabsParser
Removed unnecessary final modifiers
---
Ghidra/Features/Base/certification.manifest | 47 +
.../stabs/AbstractStabsSymbolDescriptor.java | 73 +
.../stabs/StabsClassSymbolDescriptor.java | 326 ++++
.../stabs/StabsCompositeSymbolDescriptor.java | 68 +
.../stabs/StabsConstantSymbolDescriptor.java | 154 ++
.../stabs/StabsExceptionSymbolDescriptor.java | 54 +
.../app/util/bin/format/stabs/StabsFile.java | 203 +++
.../stabs/StabsFunctionSymbolDescriptor.java | 194 +++
.../stabs/StabsParameterSymbolDescriptor.java | 77 +
.../bin/format/stabs/StabsParseException.java | 15 +
.../util/bin/format/stabs/StabsParser.java | 258 ++++
.../format/stabs/StabsSymbolDescriptor.java | 43 +
.../stabs/StabsSymbolDescriptorType.java | 116 ++
.../app/util/bin/format/stabs/StabsToken.java | 77 +
.../util/bin/format/stabs/StabsTokenizer.java | 82 +
.../stabs/StabsTypeDefSymbolDescriptor.java | 110 ++
.../format/stabs/StabsTypeDescriptorType.java | 35 +
.../bin/format/stabs/StabsTypeNumber.java | 102 ++
.../app/util/bin/format/stabs/StabsUtils.java | 177 +++
.../stabs/StabsVariableSymbolDescriptor.java | 101 ++
.../stabs/cpp/StabsBaseClassDescriptor.java | 124 ++
.../cpp/StabsMemberSymbolDescriptor.java | 161 ++
.../cpp/StabsMethodSymbolDescriptor.java | 312 ++++
.../AbstractStabsFunctionTypeDescriptor.java | 92 ++
.../types/AbstractStabsTypeDescriptor.java | 49 +
...tractStabsTypeReferenceTypeDescriptor.java | 59 +
.../stabs/types/StabsArrayTypeDescriptor.java | 98 ++
.../types/StabsBuiltinTypeDescriptor.java | 256 ++++
.../types/StabsCompositeTypeDescriptor.java | 165 ++
.../StabsCrossReferenceTypeDescriptor.java | 77 +
.../types/StabsFunctionTypeDescriptor.java | 106 ++
.../types/StabsMethodTypeDescriptor.java | 74 +
.../types/StabsParameterTypeDescriptor.java | 67 +
.../stabs/types/StabsRangeTypeDescriptor.java | 103 ++
.../types/StabsReferenceTypeDescriptor.java | 82 +
.../stabs/types/StabsTypeDescriptor.java | 38 +
.../types/StabsTypeDescriptorFactory.java | 119 ++
.../StabsTypeModifierTypeDescriptor.java | 78 +
.../StabsTypeReferenceTypeDescriptor.java | 47 +
.../bin/format/stabs/AbstractStabsTest.java | 78 +
.../format/stabs/StabsCompositeTokenTest.java | 88 ++
.../util/bin/format/stabs/StabsFullCTest.java | 23 +
.../bin/format/stabs/StabsFullCppTest.java | 23 +
.../format/stabs/StabsFunctionTokenTest.java | 56 +
.../format/stabs/StabsTypeDefTokenTest.java | 33 +
.../types/StabArrayTypeDescriptorTest.java | 37 +
.../util/bin/format/stabs/full_c_stabs.txt | 119 ++
.../util/bin/format/stabs/full_cpp_stabs.txt | 1336 +++++++++++++++++
48 files changed, 6212 insertions(+)
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/AbstractStabsSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsClassSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsCompositeSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsConstantSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsExceptionSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsFile.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsFunctionSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsParameterSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsParseException.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsParser.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsSymbolDescriptorType.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsToken.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsTokenizer.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsTypeDefSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsTypeDescriptorType.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsTypeNumber.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsUtils.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsVariableSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/cpp/StabsBaseClassDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/cpp/StabsMemberSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/cpp/StabsMethodSymbolDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/AbstractStabsFunctionTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/AbstractStabsTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/AbstractStabsTypeReferenceTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsArrayTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsBuiltinTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsCompositeTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsCrossReferenceTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsFunctionTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsMethodTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsParameterTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsRangeTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsReferenceTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsTypeDescriptorFactory.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsTypeModifierTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/types/StabsTypeReferenceTypeDescriptor.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/stabs/AbstractStabsTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/stabs/StabsCompositeTokenTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/stabs/StabsFullCTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/stabs/StabsFullCppTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/stabs/StabsFunctionTokenTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/stabs/StabsTypeDefTokenTest.java
create mode 100644 Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/stabs/types/StabArrayTypeDescriptorTest.java
create mode 100644 Ghidra/Features/Base/src/test/resources/ghidra/app/util/bin/format/stabs/full_c_stabs.txt
create mode 100644 Ghidra/Features/Base/src/test/resources/ghidra/app/util/bin/format/stabs/full_cpp_stabs.txt
diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifest
index df3477fc50..fb07662ff9 100644
--- a/Ghidra/Features/Base/certification.manifest
+++ b/Ghidra/Features/Base/certification.manifest
@@ -642,6 +642,44 @@ src/main/java/ghidra/app/util/bin/format/ne/package.html||GHIDRA||||END|
src/main/java/ghidra/app/util/bin/format/package.html||GHIDRA||||END|
src/main/java/ghidra/app/util/bin/format/pe/package.html||GHIDRA||||END|
src/main/java/ghidra/app/util/bin/format/pe/resource/package.html||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/AbstractStabsSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsClassSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsCompositeSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsConstantSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsExceptionSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsFile.java||GHIDRA||||END||
+src/main/java/ghidra/app/util/bin/format/stabs/StabsFunctionSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsParameterSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsParseException.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsParser.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsSymbolDescriptorType.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsToken.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsTokenizer.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsTypeDefSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsTypeDescriptorType.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsTypeNumber.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsUtils.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/StabsVariableSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/cpp/StabsBaseClassDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/cpp/StabsMemberSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/cpp/StabsMethodSymbolDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/AbstractStabsFunctionTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/AbstractStabsTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/AbstractStabsTypeReferenceTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsArrayTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsBuiltinTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsCompositeTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsCrossReferenceTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsFunctionTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsMethodTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsParameterTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsRangeTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsReferenceTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsTypeDescriptorFactory.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsTypeModifierTypeDescriptor.java||GHIDRA||||END|
+src/main/java/ghidra/app/util/bin/format/stabs/types/StabsTypeReferenceTypeDescriptor.java||GHIDRA||||END|
src/main/java/ghidra/app/util/bin/package.html||GHIDRA||||END|
src/main/java/ghidra/app/util/exporter/package.html||GHIDRA||||END|
src/main/java/ghidra/app/util/importer/package.html||GHIDRA||||END|
@@ -933,4 +971,13 @@ src/test.slow/resources/filterTestDirList.txt||GHIDRA||||END|
src/test.slow/resources/ghidra/app/plugin/core/datamgr/TestDataType.txt||GHIDRA||||END|
src/test.slow/resources/ghidra/app/script/GhidraScriptAsk.properties||GHIDRA||||END|
src/test/resources/defaultTools/TestCodeBrowser.tool||GHIDRA||||END|
+src/test/java/ghidra/app/util/bin/format/stabs/AbstractStabsTest.java||GHIDRA||||END|
+src/test/java/ghidra/app/util/bin/format/stabs/StabsCompositeTokenTest.java||GHIDRA||||END|
+src/test/java/ghidra/app/util/bin/format/stabs/StabsFullCTest.java||GHIDRA||||END|
+src/test/java/ghidra/app/util/bin/format/stabs/StabsFullCppTest.java||GHIDRA||||END|
+src/test/java/ghidra/app/util/bin/format/stabs/StabsFunctionTokenTest.java||GHIDRA||||END|
+src/test/java/ghidra/app/util/bin/format/stabs/StabsTypeDefTokenTest.java||GHIDRA||||END|
+src/test/java/ghidra/app/util/bin/format/stabs/types/StabArrayTypeDescriptorTest.java||GHIDRA||||END|
+src/test/resources/ghidra/app/util/bin/format/stabs/full_c_stabs.txt||GHIDRA||||END|
+src/test/resources/ghidra/app/util/bin/format/stabs/full_cpp_stabs.txt||GHIDRA||||END|
src/test/resources/ghidra/app/util/opinion/test.ord||GHIDRA||||END|
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/AbstractStabsSymbolDescriptor.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/AbstractStabsSymbolDescriptor.java
new file mode 100644
index 0000000000..0aa7840378
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/AbstractStabsSymbolDescriptor.java
@@ -0,0 +1,73 @@
+package ghidra.app.util.bin.format.stabs;
+
+import ghidra.app.util.bin.format.stabs.types.StabsTypeDescriptor;
+import ghidra.program.model.data.CategoryPath;
+import ghidra.program.model.data.DataTypeManager;
+
+/**
+ * Abstract Base Class for StabSymbolDescriptor Implementations
+ */
+public abstract class AbstractStabsSymbolDescriptor implements StabsSymbolDescriptor {
+
+ protected final String stab;
+ protected final String name;
+ protected final char descriptor;
+ protected final StabsFile file;
+ protected final DataTypeManager dtm;
+ protected final CategoryPath path;
+ private int anonCount = 0;
+
+ AbstractStabsSymbolDescriptor(String stab, StabsFile file) {
+ this.name = StabsParser.getNameFromStab(stab);
+ this.stab = stab;
+ this.file = file;
+ this.dtm = file.getProgram().getDataTypeManager();
+ this.path = file.getCategoryPath();
+ this.descriptor = stab.charAt(name.length()+1);
+ }
+
+ protected String getTypeSubStab() {
+ int index = stab.indexOf('=');
+ if (index != -1) {
+ return stab.substring(index+1);
+ }
+ index = stab.indexOf('(');
+ if (index != -1) {
+ return stab.substring(index);
+ }
+ return stab.substring(name.length()+2);
+ }
+
+ protected StabsParseException getError() {
+ return new StabsParseException(getName(), stab);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getStab() {
+ return stab;
+ }
+
+ @Override
+ public final StabsFile getFile() {
+ return file;
+ }
+
+ @Override
+ public StabsTypeDescriptor getTypeInformation() {
+ //default case for having no type information
+ return null;
+ }
+
+ /**
+ * Gets the next available number for an anonymous inner type
+ * @return the next available number
+ */
+ public int getNextAnonCount() {
+ return anonCount++;
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsClassSymbolDescriptor.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsClassSymbolDescriptor.java
new file mode 100644
index 0000000000..2234b5dbd8
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsClassSymbolDescriptor.java
@@ -0,0 +1,326 @@
+package ghidra.app.util.bin.format.stabs;
+
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import ghidra.app.util.NamespaceUtils;
+import ghidra.app.util.SymbolPath;
+import ghidra.app.util.bin.format.stabs.cpp.*;
+import ghidra.app.util.bin.format.stabs.types.StabsTypeDescriptor;
+import ghidra.app.util.bin.format.stabs.types.StabsTypeDescriptorFactory;
+import ghidra.app.util.demangler.DemangledFunction;
+import ghidra.app.util.demangler.DemangledObject;
+import ghidra.program.model.data.DataType;
+import ghidra.program.model.data.InvalidDataTypeException;
+import ghidra.program.model.data.Structure;
+import ghidra.program.model.listing.GhidraClass;
+import ghidra.program.model.listing.Program;
+import ghidra.program.model.listing.VariableUtilities;
+import ghidra.program.model.symbol.Namespace;
+import ghidra.program.model.symbol.SourceType;
+import ghidra.util.Msg;
+import ghidra.util.exception.InvalidInputException;
+
+/**
+ * C++ Class Type (Structure, Union) implementation of the StabSymbolDescriptor
+ */
+public final class StabsClassSymbolDescriptor extends AbstractStabsSymbolDescriptor
+ implements StabsTypeDescriptor{
+
+ private static final String SUPER_CLASS = "super_%s";
+ private static final String CONSTRUCTOR_NAME = "__ct_base";
+ private static final Pattern COMPOSITE_START = Pattern.compile("(?<==)([su]\\d+)");
+ private static final Pattern FIRST_BASE_PATTERN =
+ Pattern.compile(String.format("~%%(%s.*?);", StabsTypeNumber.TYPE_NUMBER_PATTERN));
+
+ private final Program program;
+ private final GhidraClass gc;
+ private final List<StabsBaseClassDescriptor> bases;
+ private final List<StabsMemberSymbolDescriptor> members;
+ private final List<StabsMethodSymbolDescriptor> methods;
+ private final StabsTypeDescriptor firstBase;
+
+ /**
+ * Constructs a new StabsClassSymbolDescriptor
+ * @param stab the portion of the stab containing this descriptor
+ * @param file the file containing this descriptor
+ * @throws StabsParseException if the descriptor or one it relies on is invalid
+ */
+ StabsClassSymbolDescriptor(String stab, StabsFile file) throws StabsParseException {
+ super(stab, file);
+ StabsTypeNumber typeNum = new StabsTypeNumber(stab);
+ file.addType(this, typeNum);
+ this.program = file.getProgram();
+ this.gc = doGetGhidraClass();
+ this.bases = StabsBaseClassDescriptor.getBases(this, getCompositeStart());
+ this.members = StabsMemberSymbolDescriptor.getMembers(this, getMembersStart());
+ this.methods = StabsMethodSymbolDescriptor.getMethods(this);
+ this.firstBase = doGetFirstBase();
+ fixupGhidraClass();
+ doAddBases();
+ doAddMembers();
+ }
+
+ @Override
+ public DataType getDataType() {
+ // don't change the category path as it causes problems
+ return VariableUtilities.findOrCreateClassStruct(gc, dtm);
+ }
+
+ @Override
+ public StabsSymbolDescriptorType getSymbolDescriptorType() {
+ return StabsSymbolDescriptorType.CLASS;
+ }
+
+ @Override
+ public StabsSymbolDescriptor getSymbolDescriptor() {
+ return this;
+ }
+
+ @Override
+ public StabsTypeDescriptorType getType() {
+ return StabsTypeDescriptorType.COMPOSITE;
+ }
+
+ @Override
+ public int getLength() {
+ throw new UnsupportedOperationException("A class cannot hava an inline definition");
+ }
+
+ private StabsTypeDescriptor doGetFirstBase() throws StabsParseException {
+ Matcher matcher = FIRST_BASE_PATTERN.matcher(stab);
+ if (matcher.find()) {
+ return StabsTypeDescriptorFactory.getTypeDescriptor(this, matcher.group(1));
+ }
+ return null;
+ }
+
+ private void fixupGhidraClass() {
+ if (stab.contains(CONSTRUCTOR_NAME) || gc.getName().indexOf('<') != -1) {
+ // no fixing required
+ return;
+ }
+ DemangledObject o = null;
+ for (StabsMemberSymbolDescriptor member : members) {
+ o = member.getDemangledObject();
+ if (o != null) {
+ break;
+ }
+ }
+ if (o != null) {
+ DataType dt = getDataType();
+ try {
+ dt.setName(o.getNamespace().getName());
+ gc.getSymbol().setName(o.getNamespace().getName(), SourceType.IMPORTED);
+ } catch (Exception e) {
+ // don't care
+ Msg.error(this, e);
+ }
+ } /*else {
+ likely didn't require fixing
+ }*/
+ }
+
+ private String getCompositeStart() {
+ Matcher matcher = COMPOSITE_START.matcher(stab);
+ if (matcher.find()) {
+ return stab.substring(matcher.end(1));
+ }
+ return "";
+ }
+
+ private String getMembersStart() {
+ if (bases.isEmpty()) {
+ return getCompositeStart();
+ }
+ int index = StabsBaseClassDescriptor.getBaseStartIndex(stab)+getBasesLength();
+ return stab.substring(index);
+ }
+
+ private int getBasesLength() {
+ return bases.stream()
+ .mapToInt(StabsBaseClassDescriptor::getLength)
+ .sum();
+ }
+
+ private DemangledFunction getCtor() throws StabsParseException {
+ int index = stab.indexOf(CONSTRUCTOR_NAME);
+ if (index != -1) {
+ return StabsMethodSymbolDescriptor.getDemangledFunction(this);
+ }
+ DemangledFunction result =
+ StabsMethodSymbolDescriptor.getDemangledFunction(this);
+ if (result != null) {
+ return result;
+ }
+ throw getError();
+ }
+
+ private String toNamespace(DemangledFunction fun) {
+ return fun.getNamespace().getNamespaceString();
+ }
+
+ private GhidraClass getNextAvailableGc() throws StabsParseException {
+ SymbolPath sPath = new SymbolPath(name);
+ Namespace existingNs = null;
+ int i = 0;
+ do {
+ if (i == 0) {
+ i++;
+ } else {
+ sPath = new SymbolPath(String.format("%s_%d", name, ++i));
+ }
+ existingNs = NamespaceUtils.getNonFunctionNamespace(program, sPath);
+ } while (existingNs != null);
+ try {
+ existingNs = NamespaceUtils.createNamespaceHierarchy(
+ sPath.toString(), null, program, SourceType.IMPORTED);
+ if (!(existingNs instanceof GhidraClass)) {
+ existingNs = NamespaceUtils.convertNamespaceToClass(existingNs);
+ }
+ return (GhidraClass) existingNs;
+ } catch (InvalidInputException e) {
+ // if the input is invalid then so is the stab
+ throw new StabsParseException(name, stab);
+ }
+ }
+
+ private GhidraClass doGetGhidraClass() throws StabsParseException {
+ String nsPath;
+ try {
+ DemangledFunction fun = getCtor();
+ if (fun == null || fun.getNamespace() == null) {
+ return getNextAvailableGc();
+ }
+ nsPath = toNamespace(fun);
+ } catch (StabsParseException e) {
+ // We have no namespace information and no template information. Makeup a namespace.
+ return getNextAvailableGc();
+ }
+ try {
+ Namespace ns = NamespaceUtils.createNamespaceHierarchy(
+ nsPath, null, program, SourceType.IMPORTED);
+ if (!(ns instanceof GhidraClass)) {
+ ns = NamespaceUtils.convertNamespaceToClass(ns);
+ }
+ return (GhidraClass) ns;
+ } catch (InvalidInputException e) {
+ // if the input is invalid then so is the stab
+ throw new StabsParseException(name, stab);
+ }
+ }
+
+ private void doAddBases() {
+ // c++ unions cannot inherit. Safe to cast to Structure
+ Structure struct = (Structure) getDataType();
+ for (StabsBaseClassDescriptor base : bases) {
+ if (!base.isVirtual()) {
+ // TODO add virtual bases once supported
+ int offset = base.getOffset();
+ DataType typeDt = base.getDataType();
+ int length = typeDt.getLength();
+ String name = String.format(SUPER_CLASS, typeDt.getName());
+ String modifier = base.getModifier().getDeclaration();
+ struct.insertAtOffset(offset, typeDt, length,name, modifier);
+ }
+ }
+ }
+
+ private void doAddMembers() throws StabsParseException {
+ try {
+ StabsUtils.addCompositeMembers(getDataType(), members);
+ } catch (InvalidDataTypeException e) {
+ throw new StabsParseException(name, stab, e);
+ }
+ }
+
+ static boolean isClass(String stab) {
+ if (StabsMethodSymbolDescriptor.containsMethods(stab)) {
+ return true;
+ }
+ Pattern pattern = Pattern.compile(
+ String.format(".*?:Tt(%s)=s\\d+\\!", StabsTypeNumber.TYPE_NUMBER_PATTERN));
+ if (pattern.matcher(stab).lookingAt()) {
+ return true;
+ }
+ pattern = Pattern.compile(
+ String.format(":/[0129](%s)", StabsTypeNumber.TYPE_NUMBER_PATTERN));
+ if (pattern.matcher(stab).find()) {
+ return true;
+ }
+ return stab.indexOf('#') != -1 || stab.contains(CONSTRUCTOR_NAME);
+ }
+
+ /**
+ * Gets the GhidraClass for this class descriptor
+ * @return the ghidra class
+ */
+ public GhidraClass getGhidraClass() {
+ return gc;
+ }
+
+ /**
+ * @return the methods
+ */
+ public List<StabsMethodSymbolDescriptor> getMethods() {
+ return methods;
+ }
+
+ /**
+ * @return the firstBase
+ */
+ public StabsTypeDescriptor getFirstBase() {
+ return firstBase;
+ }
+
+ /** Potential Visibility Modifiers */
+ public static enum Visibility {
+ PUBLIC,
+ PROTECTED,
+ PRIVATE,
+ NONE;
+
+ /**
+ * Gets the visibility from the start of the stab
+ * @param stab the portion of the stab where the modifier starts
+ * @return the visibility
+ */
+ public static Visibility getVisibility(CharSequence stab) {
+ if (stab != null) {
+ int index = stab.charAt(0) == '/' ? 1 : 0;
+ return getVisibility(stab.charAt(index));
+ }
+ return NONE;
+ }
+
+ /**
+ * Gets the visibility from the start of the stab
+ * @param c the visibility character
+ * @return the visibility
+ */
+ public static Visibility getVisibility(char c) {
+ switch (c) {
+ case '0':
+ return PRIVATE;
+ case '1':
+ return PROTECTED;
+ case '2':
+ return PUBLIC;
+ default:
+ return NONE;
+ }
+ }
+
+ /**
+ * Gets the declaration of this visibility modifier
+ * @return the visibility declaration or an empty string if none
+ */
+ public String getDeclaration() {
+ if (this == NONE) {
+ return "";
+ }
+ return name().toLowerCase();
+ }
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsCompositeSymbolDescriptor.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsCompositeSymbolDescriptor.java
new file mode 100644
index 0000000000..2450d80436
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsCompositeSymbolDescriptor.java
@@ -0,0 +1,68 @@
+package ghidra.app.util.bin.format.stabs;
+
+import ghidra.app.util.bin.format.stabs.types.StabsCompositeTypeDescriptor;
+import ghidra.app.util.bin.format.stabs.types.StabsTypeDescriptor;
+import ghidra.program.model.data.DataType;
+import ghidra.program.model.data.StructureDataType;
+import ghidra.program.model.data.UnionDataType;
+
+import static ghidra.program.model.data.DataTypeConflictHandler.REPLACE_HANDLER;
+
+/**
+ * Composite Type (Structure, Union, Enum) implementation of the StabSymbolDescriptor
+ */
+public class StabsCompositeSymbolDescriptor extends AbstractStabsSymbolDescriptor {
+
+ private final DataType dt;
+ private final StabsCompositeTypeDescriptor type;
+
+ /**
+ * Constructs a new StabsCompositeSymbolDescriptor
+ * @param stab the portion of the stab containing this descriptor
+ * @param file the file containing this descriptor
+ * @throws StabsParseException if the descriptor or one it relies on is invalid
+ */
+ StabsCompositeSymbolDescriptor(String stab, StabsFile file) throws StabsParseException {
+ super(stab, file);
+ this.dt = initDataType();
+ this.type = StabsCompositeTypeDescriptor.getNamedDescriptor(this, getTypeSubStab());
+ }
+
+ @Override
+ public StabsTypeDescriptor getTypeInformation() {
+ return type;
+ }
+
+ @Override
+ public DataType getDataType() {
+ return dt;
+ }
+
+ @Override
+ public StabsSymbolDescriptorType getSymbolDescriptorType() {
+ return StabsSymbolDescriptorType.COMPOSITE;
+ }
+
+ private DataType initDataType() throws StabsParseException {
+ String typeString = getTypeSubStab();
+ DataType initDt = doGetDataType(typeString);
+ if (initDt != null) {
+ return dtm.resolve(initDt, REPLACE_HANDLER);
+ }
+ throw new StabsParseException(name, stab);
+ }
+
+ private DataType doGetDataType(String typeString) throws StabsParseException {
+ switch (typeString.charAt(0)) {
+ case 'e':
+ return StabsCompositeTypeDescriptor.parseEnum(typeString, name, path, dtm);
+ case 's':
+ return new StructureDataType(path, name, 0, dtm);
+ case 'u':
+ return new UnionDataType(path, name, dtm);
+ default:
+ throw getError();
+ }
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsConstantSymbolDescriptor.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsConstantSymbolDescriptor.java
new file mode 100644
index 0000000000..7ca88d862a
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsConstantSymbolDescriptor.java
@@ -0,0 +1,154 @@
+package ghidra.app.util.bin.format.stabs;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import ghidra.app.util.bin.format.stabs.types.StabsTypeDescriptor;
+import ghidra.program.model.data.*;
+import ghidra.util.Msg;
+
+/**
+ * Constant implementation of the StabSymbolDescriptor
+ */
+public class StabsConstantSymbolDescriptor extends AbstractStabsSymbolDescriptor {
+
+ /** Potential constant types */
+ public enum ConstantType {
+ VALUE,
+ TYPE,
+ STRING,
+ NONE
+ }
+
+ /** Potential constant value types */
+ public enum ValueType {
+ /** true or false */
+ BOOL,
+ /** character value */
+ CHARACTER,
+ /** byte, short, int, long, etc. */
+ INTEGER,
+ /** float, double */
+ REAL,
+ /** not a value type constant */
+ NONE
+ }
+
+ private static final Pattern PATTERN = Pattern.compile("c=([bcirseS])(.*)");
+
+ private final ConstantType type;
+ private final ValueType vType;
+
+ /**
+ * Constructs a new StabsConstantSymbolDescriptor
+ * @param stab the portion of the stab containing this descriptor
+ * @param file the file containing this descriptor
+ * @throws StabsParseException if the descriptor or one it relies on is invalid
+ */
+ StabsConstantSymbolDescriptor(String stab, StabsFile file) {
+ super(stab, file);
+ this.type = doGetConstantType();
+ this.vType = doGetValueType();
+ }
+
+ @Override
+ public DataType getDataType() {
+ switch (type) {
+ case STRING:
+ return StringDataType.dataType;
+ case VALUE:
+ switch (vType) {
+ case BOOL:
+ return BooleanDataType.dataType;
+ case CHARACTER:
+ return CharDataType.dataType;
+ case INTEGER:
+ // implicit int. for others e is used
+ return IntegerDataType.dataType;
+ case REAL:
+ return FloatDataType.dataType;
+ case NONE:
+ default:
+ break;
+ }
+ break;
+ case TYPE:
+ return getTypeDataType();
+ default:
+ break;
+ }
+ return DataType.VOID;
+ }
+
+ @Override
+ public StabsSymbolDescriptorType getSymbolDescriptorType() {
+ return StabsSymbolDescriptorType.CONSTANT;
+ }
+
+ private char getTypeCharacter() {
+ Matcher matcher = PATTERN.matcher(stab);
+ if (matcher.find()) {
+ return matcher.group(1).charAt(0);
+ }
+ return '\0';
+ }
+
+ private ConstantType doGetConstantType() {
+ switch (getTypeCharacter()) {
+ case 'b':
+ case 'c':
+ case 'i':
+ case 'r':
+ return ConstantType.VALUE;
+ case 's':
+ return ConstantType.STRING;
+ case 'e':
+ case 'S':
+ return ConstantType.TYPE;
+ default:
+ break;
+ }
+ Msg.warn(this, "Unknown constant type in stab string:\n" + getStab());
+ return ConstantType.NONE;
+ }
+
+ private DataType getTypeDataType() {
+ StabsTypeNumber num = new StabsTypeNumber(stab);
+ StabsTypeDescriptor type = file.getType(num);
+ return type != null ? type.getDataType() : DataType.VOID;
+ }
+
+ /**
+ * Gets the type of constant this descriptor represents
+ * @return the constant type
+ */
+ public ConstantType getConstantType() {
+ return type;
+ }
+
+ /**
+ * Gets the value type this constant value type descriptor represents
+ * @return the value type
+ */
+ public ValueType getValueType() {
+ return vType;
+ }
+
+ private ValueType doGetValueType() {
+ if (type.equals(ConstantType.VALUE)) {
+ switch (getTypeCharacter()) {
+ case 'b':
+ return ValueType.BOOL;
+ case 'c':
+ return ValueType.CHARACTER;
+ case 'i':
+ return ValueType.INTEGER;
+ case 'r':
+ return ValueType.REAL;
+ default:
+ break;
+ }
+ }
+ return ValueType.NONE;
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsExceptionSymbolDescriptor.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsExceptionSymbolDescriptor.java
new file mode 100644
index 0000000000..6b0d211fc8
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsExceptionSymbolDescriptor.java
@@ -0,0 +1,54 @@
+package ghidra.app.util.bin.format.stabs;
+
+import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
+import ghidra.app.plugin.core.analysis.DefaultDataTypeManagerService;
+import ghidra.app.services.DataTypeManagerService;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.data.DataType;
+import ghidra.util.data.DataTypeParser;
+
+/**
+ * Exception implementation of the StabSymbolDescriptor
+ */
+public class StabsExceptionSymbolDescriptor extends AbstractStabsSymbolDescriptor {
+
+ private final DataTypeParser parser;
+ private final DataTypeManagerService service;
+
+ /**
+ * Constructs a new StabsExceptionSymbolDescriptor
+ * @param stab the portion of the stab containing this descriptor
+ * @param file the file containing this descriptor
+ * @throws StabsParseException if the descriptor or one it relies on is invalid
+ */
+ StabsExceptionSymbolDescriptor(String stab, StabsFile file) {
+ super(stab, file);
+ PluginTool tool =
+ AutoAnalysisManager.getAnalysisManager(file.getProgram()).getAnalysisTool();
+ if (tool != null) {
+ this.service = tool.getService(DataTypeManagerService.class);
+ } else {
+ // if tool == null then we're in headless mode
+ this.service = new DefaultDataTypeManagerService();
+ }
+ this.parser = new DataTypeParser(service, DataTypeParser.AllowedDataTypes.ALL);
+ }
+
+ @Override
+ public DataType getDataType() {
+ try {
+ // return the exceptions datatype if known
+ DataType dt = parser.parse(name);
+ return dt;
+ }
+ catch (Exception e) {
+ // if we don't have it then return null
+ }
+ return null;
+ }
+
+ @Override
+ public StabsSymbolDescriptorType getSymbolDescriptorType() {
+ return StabsSymbolDescriptorType.EXCEPTION;
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsFile.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsFile.java
new file mode 100644
index 0000000000..c2a27be403
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/stabs/StabsFile.java
@@ -0,0 +1,203 @@
+package ghidra.app.util.bin.format.stabs;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import ghidra.app.util.bin.format.stabs.types.StabsTypeDescriptor;
+import ghidra.program.model.data.CategoryPath;
+import ghidra.program.model.data.DataType;
+import ghidra.program.model.listing.Program;
+import ghidra.util.datastruct.RedBlackEntry;
+import ghidra.util.datastruct.RedBlackTree;
+
+/**
+ * A Container representing a file which holds all StabDescriptors
+ * which may have been declared in the file.
+ */
+public class StabsFile {
+
+ private static final Pattern INCLUDE_PATTERN =
+ Pattern.compile("(?<=(?:(?:include/)|(?:sys\\-include/)))(.*)");
+ private static final String BUILTIN_NAME = "__builtin__";
+ private static final int BUILTIN_FILE_NUMBER = 0;
+ private static final CategoryPath STABS_ROOT = new CategoryPath(CategoryPath.ROOT, "stabs");
+
+ private final long fileNumber;
+ private final String fileName;
+ private final String fullPath;
+ private final StabsParser parser;
+ private final CategoryPath path;
+ private final RedBlackTree<Long, StabsTypeDescriptor> types = new RedBlackTree<>();
+ private final Set<StabsFunctionSymbolDescriptor> functions = new HashSet<>();
+ private final Set<StabsClassSymbolDescriptor> classes = new HashSet<>();
+
+ StabsFile(StabsParser parser) {
+ this.fileName = BUILTIN_NAME;
+ this.fullPath = fileName;
+ this.parser = parser;
+ this.path = CategoryPath.ROOT;
+ this.fileNumber = 0;
+ }
+
+ StabsFile(String fileName, StabsParser parser, int fileNumber) {
+ this.fullPath = fileName;
+ Path path = Paths.get(fileName);
+ path.normalize();
+ String strPath = path.toString().replaceAll("\\\\", "/").replaceAll("../", "");
+ Matcher matcher = INCLUDE_PATTERN.matcher(fileName);
+ matcher.reset(strPath);
+ if (matcher.find()) {
+ strPath = matcher.group(1);
+ }
+ this.fileName = strPath;
+ this.parser = parser;
+ this.fileNumber = fileNumber;
+ this.path = new CategoryPath(STABS_ROOT, strPath);
+ }
+
+ // this shouldn't be public. Not sure how to protect this though.
+ public void addType(StabsTypeDescriptor type, StabsTypeNumber typeNumber) {
+ if (isThisFile(typeNumber)) {
+ if (!typeNumber.hasFileNumber()) {
+ StabsFile file = parser.getFile(BUILTIN_FILE_NUMBER);
+ file.types.put(typeNumber.typeNumber, type);
+ }
+ // add to ourselves too so we know where it was defined
+ types.put(typeNumber.typeNumber, type);
+ } else {
+ StabsFile file = parser.getFile(typeNumber.fileNumber);
+ file.types.put(typeNumber.typeNumber, type);
+ }
+ }
+
+ private boolean isThisFile(StabsTypeNumber typeNumber) {
+ return typeNumber.fileNumber == fileNumber || !typeNumber.hasFileNumber();
+ }
+
+ /**
+ * Returns true if this file or an included file defines the type
+ * @param typeNumber the type number of the type to check for
+ * @return true if the type has been defined
+ */
+ public boolean containsType(StabsTypeNumber typeNumber) {
+ if (isThisFile(typeNumber)) {
+ return types.containsKey(typeNumber.typeNumber);
+ }
+ StabsFile otherFile = parser.getFile(typeNumber.fileNumber);
+ return otherFile.containsType(typeNumber);
+ }
+
+ /**
+ * Gets the type descriptor for the provided type number
+ * @param typeNumber the types type number
+ * @return the type descriptor
+ */
+ public StabsTypeDescriptor getType(StabsTypeNumber typeNumber) {
+ if (isThisFile(typeNumber)) {
+ if (!typeNumber.hasFileNumber()) {
+ StabsFile file = parser.getFile(BUILTIN_FILE_NUMBER);
+ return file.types.getOrCreateEntry(typeNumber.typeNumber).getValue();
+ }
+ return types.getOrCreateEntry(typeNumber.typeNumber).getValue();
+ }
+ return parser.getType(typeNumber);
+ }
+
+ /**
+ * Gets the program
+ * @return the program
+ */
+ public Program getProgram() {
+ return parser.getProgram();
+ }
+
+ /**
+ * Gets the CategoryPath