-
Notifications
You must be signed in to change notification settings - Fork 130
/
edbg_stab.bas
1053 lines (819 loc) · 22.2 KB
/
edbg_stab.bas
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
'' debug emitter (stabs format) for GNU assembler (GAS)
''
'' chng: nov/2004 written [v1ctor]
#include once "fb.bi"
#include once "fbint.bi"
#include once "lex.bi"
#include once "ir.bi"
#include once "emit.bi"
#include once "emitdbg.bi"
#include once "stabs.bi"
type EDBGCTX
typecnt as uinteger
label as FBSYMBOL ptr
lnum as integer
pos as integer
isnewline as integer
firstline as integer '' first non-decl line
lastline as integer '' last /
filename as zstring * FB_MAXPATHLEN+1
incfile as zstring ptr
end type
declare sub hDeclUDT _
( _
byval sym as FBSYMBOL ptr, _
byval dimtbelements as integer _
)
declare sub hDeclENUM _
( _
byval sym as FBSYMBOL ptr _
)
declare function hDeclPointer _
( _
byref dtype as integer _
) as string
declare function hGetDataType _
( _
byval sym as FBSYMBOL ptr, _
byval arraydimensions as integer = 0 _
) as string
'' globals
dim shared ctx as EDBGCTX
'' same order as FB_DATATYPE
'' Mapping dtype => stabs type tag (t*) as declared in the strings in the stabsTb()
dim shared remapTB(0 to FB_DATATYPES-1) as integer = _
{ _
7, _ '' void
16, _ '' boolean
2, _ '' byte
3, _ '' ubyte
4, _ '' char
5, _ '' short
6, _ '' ushort
6, _ '' wchar
1, _ '' int
8, _ '' uint
1, _ '' enum
1, _ '' long
8, _ '' ulong
9, _ '' longint
10, _ '' ulongint
11, _ '' single
12, _ '' double
13, _ '' string
14, _ '' fix-len string
17 _ '' va_list
}
dim shared stabsTb(0 to ...) as const zstring ptr = _
{ _
@"integer:t1=-1", _
@"void:t7=-11", _
@"byte:t2=-6", _
@"ubyte:t3=-5", _
@"char:t4=-2", _
@"short:t5=-3", _
@"ushort:t6=-7", _
@"uinteger:t8=-8", _
@"longint:t9=-31", _
@"ulongint:t10=-32", _
@"single:t11=-12", _
@"double:t12=-13", _
@"string:t13=s12data:15,0,32;len:1,32,32;size:1,64,32;;", _
@"fixstr:t14=-2", _
@"pchar:t15=*4;", _ '' used for the data ptr in the string:t13 declaration only
@"boolean:t16=@s8;-16", _
@"va_list:t17=-11" _
}
sub edbgInit( )
'' Remap wchar to target-specific type
remapTB(FB_DATATYPE_WCHAR) = remapTB(env.target.wchar)
'' The above tables assume 32bit, but that's ok because -gen gas
'' currently only supports 32bit x86 anyways, and this stabs emitter
'' is only used with -gen gas.
assert( fbIs64bit( ) = FALSE )
end sub
'':::::
private sub hEmitSTABS _
( _
byval _type as integer, _
byval _string as const zstring ptr, _
byval _other as integer = 0, _
byval _desc as integer = 0, _
byval _value as const zstring ptr = @"0" _
) static
dim as string ostr
ostr = ".stabs " + QUOTE
ostr += *hEscape( _string )
ostr += QUOTE + ","
ostr += str( _type )
ostr += ","
ostr += str( _other )
ostr += ","
ostr += str( _desc )
ostr += ","
ostr += *_value
emitWriteStr( ostr, TRUE )
end sub
'':::::
private function hMakeSTABN _
( _
byval _type as integer, _
byval _other as integer = 0, _
byval _desc as integer = 0, _
byval _value as const zstring ptr _
) as zstring ptr static
static as string ostr
ostr = ".stabn "
ostr += str( _type )
ostr += ","
ostr += str( _other )
ostr += ","
ostr += str( _desc )
ostr += ","
ostr += *_value
function = strptr( ostr )
end function
'':::::
private sub hEmitSTABN _
( _
byval _type as integer, _
byval _other as integer = 0, _
byval _desc as integer = 0, _
byval _value as const zstring ptr = @"0" _
) static
emitWriteStr( hMakeSTABN( _type, _other, _desc, _value ), TRUE )
end sub
'':::::
private sub hEmitSTABD _
( _
byval _type as integer, _
byval _other as integer = 0, _
byval _desc as integer = 0 _
) static
dim as string ostr
ostr = ".stabd "
ostr += str( _type )
ostr += ","
ostr += str( _other )
ostr += ","
ostr += str( _desc )
emitWriteStr( ostr, TRUE )
end sub
'':::::
private sub hSTABLABEL _
( _
byval label as zstring ptr _
) static
dim ostr as string
ostr = *label
ostr += ":"
emitWriteStr( ostr )
end sub
sub edbgEmitHeader( byval filename as zstring ptr )
dim as string lname
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
ctx.typecnt = 1
ctx.label = NULL
ctx.incfile = NULL
'' ctx.filename is never used
ctx.filename = *filename
'' emit source file name
lname = *symbUniqueLabel( )
emitWriteStr( ".file " + QUOTE + *hEscape( filename ) + QUOTE, TRUE )
'' directory
if( pathIsAbsolute( filename ) = FALSE ) then
hEmitSTABS( STAB_TYPE_SO, hCurDir( ) + FB_HOST_PATHDIV, 0, 0, lname )
end if
'' file name
hEmitSTABS( STAB_TYPE_SO, filename, 0, 0, lname )
''
emitSetSection( IR_SECTION_CODE, 0 )
hSTABLABEL( lname )
'' (known) type definitions
for i as integer = lbound( stabsTb ) to ubound( stabsTb )
hEmitSTABS( STAB_TYPE_LSYM, stabsTb(i), 0, 0, "0" )
ctx.typecnt += 1
next
emitWriteStr( "" )
end sub
'':::::
sub edbgEmitFooter( ) static
dim as string lname
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
emitSetSection( IR_SECTION_CODE, 0 )
'' no checkings after this
lname = *symbUniqueLabel( )
hEmitSTABS( STAB_TYPE_SO, "", 0, 0, lname )
hSTABLABEL( lname )
end sub
'':::::
sub edbgLineBegin _
( _
byval proc as FBSYMBOL ptr, _
byval lnum as integer, _
byval pos_ as integer, _
ByVal filename As zstring ptr _
)
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
if( ctx.lnum > 0 ) then
ctx.pos = pos_ - ctx.pos
if( ctx.pos > 0 ) then
edbgEmitLine( proc, ctx.lnum, ctx.label )
ctx.isnewline = TRUE
end if
end if
edbgInclude( filename )
ctx.pos = pos_
ctx.lnum = lnum
if( ctx.isnewline ) then
ctx.label = symbAddLabel( NULL )
hSTABLABEL( symbGetMangledName( ctx.label ) )
ctx.isnewline = FALSE
end if
end sub
'':::::
sub edbgLineEnd _
( _
byval proc as FBSYMBOL ptr, _
byval lnum as integer, _
byval pos_ as integer _
)
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
if( ctx.lnum > 0 ) then
ctx.pos = pos_ - ctx.pos
if( ctx.pos > 0 ) then
edbgEmitLine( proc, ctx.lnum, ctx.label )
ctx.isnewline = TRUE
end if
ctx.lnum = 0
end if
end sub
'':::::
sub edbgEmitLine _
( _
byval proc as FBSYMBOL ptr, _
byval lnum as integer, _
byval label as FBSYMBOL ptr _
) static
dim as zstring ptr s
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
if( ctx.firstline = -1 ) then
ctx.firstline = lnum
end if
ctx.lastline = lnum
'' emit current line
s = hMakeSTABN( STAB_TYPE_SLINE, _
0, _
lnum, _
*symbGetMangledName( label ) + "-" + *symbGetMangledName( proc ) )
emitWriteStr( s )
end sub
'':::::
sub edbgEmitLineFlush _
( _
byval proc as FBSYMBOL ptr, _
byval lnum as integer, _
byval label as FBSYMBOL ptr _
) static
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
hEmitSTABN( STAB_TYPE_SLINE, _
0, _
lnum, _
*symbGetMangledName( label ) + "-" + *symbGetMangledName( proc ) )
end sub
'':::::
sub edbgScopeBegin _
( _
byval s as FBSYMBOL ptr _
) static
'' called by ir->ast
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
s->scp.dbg.iniline = lexLineNum( )
s->scp.dbg.inilabel = symbAddLabel( NULL )
end sub
'':::::
sub edbgScopeEnd _
( _
byval s as FBSYMBOL ptr _
) static
'' called by ir->ast
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
s->scp.dbg.endline = lexLineNum( )
s->scp.dbg.endlabel = symbAddLabel( NULL )
end sub
'':::::
sub edbgEmitScopeINI _
( _
byval s as FBSYMBOL ptr _
) static
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
hSTABLABEL( symbGetMangledName( s->scp.dbg.inilabel ) )
end sub
'':::::
sub edbgEmitScopeEND _
( _
byval s as FBSYMBOL ptr _
) static
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
hSTABLABEL( symbGetMangledName( s->scp.dbg.endlabel ) )
end sub
'':::::
sub edbgProcBegin _
( _
byval proc as FBSYMBOL ptr _
) static
'' called by ir->ast
proc->proc.ext->dbg.iniline = lexLineNum( )
end sub
'':::::
sub edbgProcEnd _
( _
byval proc as FBSYMBOL ptr _
) static
'' called by ir->ast
proc->proc.ext->dbg.endline = lexLineNum( )
end sub
'':::::
sub edbgProcEmitBegin _
( _
byval proc as FBSYMBOL ptr _
) static
'' called by emit->ir
ctx.firstline = -1
ctx.lastline = -1
end sub
private sub hDeclArgs(byval proc as FBSYMBOL ptr)
dim as FBSYMBOL ptr s = symbGetProcSymbTbHead( proc )
while (s)
if (symbIsVar(s)) then
'' Parameter?
if (symbIsParamVar(s)) then
edbgEmitProcArg(s)
end if
end if
s = s->next
wend
end sub
'':::::
sub edbgEmitProcHeader _
( _
byval proc as FBSYMBOL ptr _
) static
dim as string desc, procname
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
'' For procs defined in include files we must emit corresponding
'' include file blocks, so they appear as being declared in the include
'' file rather than the toplevel .bas file name.
edbgInclude( symbGetProcIncFile( proc ) )
'' main?
if( symbGetIsMainProc( proc ) ) then
'' main proc (the entry point)
hEmitSTABS( STAB_TYPE_MAIN, _
fbGetEntryPoint( ), _
0, _
1, _
*symbGetMangledName( proc ) )
'' set the entry line
hEmitSTABD( STAB_TYPE_SLINE, 0, 1 )
'' also correct the end and start lines
proc->proc.ext->dbg.iniline = 1
proc->proc.ext->dbg.endline = lexLineNum( )
desc = fbGetEntryPoint( )
else
desc = *symbGetDBGName( proc )
end if
''
procname = *symbGetMangledName( proc )
if( symbIsPublic( proc ) ) then
desc += ":F"
else
desc += ":f"
end if
desc += hGetDataType( proc )
hEmitSTABS( STAB_TYPE_FUN, desc, 0, proc->proc.ext->dbg.iniline, procname )
hDeclArgs( proc )
''
ctx.isnewline = TRUE
ctx.lnum = 0
ctx.pos = 0
ctx.label = NULL
end sub
'':::::
private sub hDeclLocalVars _
( _
byval proc as FBSYMBOL ptr, _
byval blk as FBSYMBOL ptr, _
byval inilabel as FBSYMBOL ptr, _
byval endlabel as FBSYMBOL ptr _
)
dim as FBSYMBOL ptr shead, s
static as integer scopecnt
'' proc?
if( symbIsProc( blk ) ) then
shead = symbGetProcSymbTbHead( blk )
'' scope block..
else
shead = symbGetScopeSymbTbHead( blk )
end if
'' for each symbol..
scopecnt = 0
s = shead
do while( s <> NULL )
select case symbGetClass( s )
'' variable?
case FB_SYMBCLASS_VAR
'' Don't emit debug info for parameter variables (the
'' parameters will be emitted instead), temporaries,
'' function result variables, or fake dynamic array
'' variables (the descriptors will be emitted instead).
if( (symbGetAttrib( s ) and _
(FB_SYMBATTRIB_PARAMVARBYDESC or _
FB_SYMBATTRIB_PARAMVARBYVAL or _
FB_SYMBATTRIB_PARAMVARBYREF or _
FB_SYMBATTRIB_TEMP or _
FB_SYMBATTRIB_FUNCRESULT or _
FB_SYMBATTRIB_DYNAMIC)) = 0 ) then
'' And nothing marked IMPLICIT either (e.g. symbAddImplicitVar(),
'' some implicitly generated vars are not TEMPs)
if( symbGetIsImplicit( s ) = FALSE ) then
edbgEmitLocalVar( s, symbIsStatic( s ) )
end if
end if
'' scope? must be emitted later, due the GDB quirks
case FB_SYMBCLASS_SCOPE
scopecnt += 1
end select
s = s->next
loop
'' emit block (change the scope)
hEmitSTABN( STAB_TYPE_LBRAC, _
0, _
0, _
*symbGetMangledName( inilabel ) + "-" + *symbGetMangledName( proc ) )
if( scopecnt > 0 ) then
'' for each scope..
s = shead
do while( s <> NULL )
if( symbIsScope( s ) ) then
hDeclLocalVars( proc, s, s->scp.dbg.inilabel, s->scp.dbg.endlabel )
end if
s = s->next
loop
end if
hEmitSTABN( STAB_TYPE_RBRAC, _
0, _
0, _
*symbGetMangledName( endlabel ) + "-" + *symbGetMangledName( proc ) )
end sub
'':::::
sub edbgEmitProcFooter _
( _
byval proc as FBSYMBOL ptr, _
byval initlabel as FBSYMBOL ptr, _
byval exitlabel as FBSYMBOL ptr _
) static
dim as string procname, lname
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
''
procname = *symbGetMangledName( proc )
''
hDeclLocalVars( proc, proc, initlabel, exitlabel )
lname = *symbUniqueLabel( )
hSTABLABEL( lname )
'' emit end proc (FUN with a null string)
hEmitSTABS( STAB_TYPE_FUN, "", 0, 0, lname + "-" + procname )
''
ctx.isnewline = TRUE
ctx.lnum = 0
ctx.pos = 0
ctx.label = NULL
end sub
'':::::
private function hDeclPointer _
( _
byref dtype as integer _
) as string static
dim as string desc
desc = ""
do while( typeIsPtr( dtype ) )
dtype = typeDeref( dtype )
desc += str( ctx.typecnt ) + "=*"
ctx.typecnt += 1
loop
function = desc
end function
private function hGetDataType _
( _
byval sym as FBSYMBOL ptr, _
byval requesteddimtbelements as integer _
) as string
dim as integer dtype = any, dimtbelements = any
dim as FBSYMBOL ptr subtype = any
dim as string desc
if( sym = NULL ) then
return str( remapTB(FB_DATATYPE_VOID) )
end if
''
'' HACK: When emitting array descriptor types, we don't always emit the
'' whole FBARRAYDIM dimTB, but only the actually used dimensions.
''
'' This makes a difference (only) for arrays declared with unknown
'' dimension count (array()), where the descriptor will have room for
'' FB_MAXARRAYDIMS dimensions but not necessarily all of that are
'' actually used.
''
'' However, we still emit the descriptor's full length in bytes - it's
'' just that the memory at the end won't be visible as fields when
'' inspecting with the debugger, just like padding bytes. Basically the
'' whole unused part of the dimTB will be treated as padding, which is
'' what it basically is, anyways.
''
dimtbelements = 0
'' Shouldn't be a dynamic array - only the descriptor is emitted
assert( symbIsDynamic( sym ) = FALSE )
if( symbIsParamVarBydesc( sym ) ) then
'' Bydesc parameter, need to emit as the real descriptor type
'' (it's really a pointer/ref, but that's already handled by edbgEmitProcArg())
dtype = FB_DATATYPE_STRUCT
subtype = sym->var_.array.desctype
dimtbelements = symbGetArrayDimensions( sym )
else
dtype = symbGetType( sym )
subtype = symbGetSubtype( sym )
'' TODO: handle byref functions?
if( symbIsVar( sym ) or symbIsField( sym ) ) then
'' Looks like reference vars need to be emitted as pointers;
'' at least that's how g++ -gstabs seems to do it, and the gdb docs
'' don't mention any way to encode references in STABS.
'' Byref parameters on the other hand have a special "v" prefix,
'' this is handled in edbgEmitProcArg().
if( symbIsRef( sym ) ) then
assert( symbIsParamVar( sym ) = FALSE )
dtype = typeAddrOf( dtype )
end if
'' Fixed-size array?
if( symbGetArrayDimensions( sym ) > 0 ) then
desc += str( ctx.typecnt ) + "="
ctx.typecnt += 1
'' Normally we want to emit all fixed-size arrays with
'' their proper dimensions & bounds - the only exception
'' is the one-dimensional dimTB in array descriptor
'' types (also see the above HACK).
if( requesteddimtbelements > 0 ) then
assert( symbGetArrayDimensions( sym ) = 1 )
desc += "ar1;"
desc += "0;"
desc += str( requesteddimtbelements - 1 ) + ";"
else
for i as integer = 0 to symbGetArrayDimensions( sym ) - 1
desc += "ar1;"
desc += str( symbArrayLbound( sym, i ) ) + ";"
desc += str( symbArrayUbound( sym, i ) ) + ";"
next
end if
end if
if( symbIsDescriptor( sym ) ) then
dimtbelements = symbGetArrayDimensions( sym->var_.desc.array )
end if
end if
end if
'' If array dimensions still unknown, assume 1
if( dimtbelements < 0 ) then
dimtbelements = 1
end if
'' pointer?
if( typeIsPtr( dtype ) ) then
desc += hDeclPointer( dtype )
end if
'' the const qualifier isn't taken into account
dtype = typeUnsetIsConst( dtype )
select case as const dtype
'' UDT?
case FB_DATATYPE_STRUCT
if( subtype->udt.dbg.typenum = INVALID ) then
hDeclUDT( subtype, dimtbelements )
end if
desc += str( subtype->udt.dbg.typenum )
'' ENUM?
case FB_DATATYPE_ENUM
if( subtype->enum_.dbg.typenum = INVALID ) then
hDeclENUM( subtype )
end if
desc += str( subtype->enum_.dbg.typenum )
'' function pointer?
case FB_DATATYPE_FUNCTION
desc += str( ctx.typecnt ) + "=f"
ctx.typecnt += 1
desc += hGetDataType( subtype )
'' forward reference?
case FB_DATATYPE_FWDREF
desc += str( remapTB(FB_DATATYPE_VOID) )
'' ordinary type..
case else
desc += str( remapTB(dtype) )
end select
function = desc
end function
private sub hDeclUDT _
( _
byval sym as FBSYMBOL ptr, _
byval dimtbelements as integer _
)
dim as FBSYMBOL ptr fld = any
dim as string desc
assert( symbIsStruct( sym ) )
sym->udt.dbg.typenum = ctx.typecnt
ctx.typecnt += 1
desc = *symbGetDBGName( sym )
desc += ":Tt" + str( sym->udt.dbg.typenum ) + "=s" + str( symbGetSizeOf( sym ) )
fld = symbUdtGetFirstField( sym )
while( fld )
'' Skip fake dynamic array fields, only the descriptor is emitted
if( symbIsDynamic( fld ) = FALSE ) then
'' Pass dimtbelements on to hGetDataType() so that the
'' dimTB of array descriptors will be emitted smaller than
'' it actually is. (the dimTB is the only array field in
'' a descriptor type, and dimtbelements will only be set
'' if declaring a descriptor type, so we can just pass it
'' always, to keep it simple)
desc += *symbGetName( fld ) + ":" + hGetDataType( fld, dimtbelements )
desc += "," + str( symbGetFieldBitOffset( fld ) )
desc += "," + str( symbGetFieldBitLength( fld ) )
desc += ";"
end if
fld = symbUdtGetNextField( fld )
wend
desc += ";"
hEmitSTABS( STAB_TYPE_LSYM, desc, 0, 0, "0" )
end sub
'':::::
private sub hDeclENUM _
( _
byval sym as FBSYMBOL ptr _
)
dim as FBSYMBOL ptr e
dim as string desc
sym->enum_.dbg.typenum = ctx.typecnt
ctx.typecnt += 1
desc = *symbGetDBGName( sym )
desc += ":T" + str( sym->enum_.dbg.typenum ) + "=e"
e = symbGetENUMFirstElm( sym )
do while( e <> NULL )
desc += *symbGetName( e ) + ":" + str( symbGetConstInt( e ) ) + ","
e = symbGetENUMNextElm( e )
loop
desc += ";"
hEmitSTABS( STAB_TYPE_LSYM, desc, 0, 0, "0" )
end sub
'' Add debug info for public/shared globals, but not local statics
sub edbgEmitGlobalVar _
( _
byval sym as FBSYMBOL ptr, _
byval section as integer _
)
dim as integer t = any, attrib = any
dim as string desc
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
'' Ignore static locals here (they are handled like other locals during
'' edbgEmitProcFooter() -> hDeclLocalVars())
if( symbIsLocal( sym ) ) then
exit sub
end if
'' This function should only be called for "allocatable" globals
assert( symbIsShared( sym ) or symbIsCommon( sym ) )
'' PUBLIC (allocated EXTERNs) on a variable implies SHARED
assert( iif( symbIsPublic( sym ), symbIsShared( sym ), TRUE ) )
'' (unallocated EXTERNs aren't emitted in the current module)
assert( symbIsExtern( sym ) = FALSE )
'' (no fake dynamic array symbols - the descriptor is emitted instead)
assert( symbIsDynamic( sym ) = FALSE )
'' (no debug info should be emitted for temporaries - but
'' FB_SYMBATTRIB_TEMP isn't used with globals anyways, only locals)
assert( symbIsTemp( sym ) = FALSE )
'' depends on section
select case section
case IR_SECTION_CONST
t = STAB_TYPE_FUN
case IR_SECTION_BSS
t = STAB_TYPE_LCSYM
case else
assert( section = IR_SECTION_DATA )
t = STAB_TYPE_STSYM
end select
desc = *symbGetDBGName( sym )
'' allocation type (static, global, etc)
if( symbIsPublic( sym ) or symbIsCommon( sym ) ) then
desc += ":G"
elseif( symbIsStatic( sym ) ) then
desc += ":S"
else
desc += ":"
end if
'' data type
desc += hGetDataType( sym )
hEmitSTABS( t, desc, 0, 0, *symbGetMangledName( sym ) )
end sub
sub edbgEmitLocalVar _
( _
byval sym as FBSYMBOL ptr, _
byval isstatic as integer _
)
dim as integer t = any
dim as string desc, value
if( env.clopt.debuginfo = FALSE ) then
exit sub
end if
desc = *symbGetName( sym )
'' (no fake dynamic array symbols - the descriptor is emitted instead)
assert( symbIsDynamic( sym ) = FALSE )
if( isstatic ) then
'' never referenced?
if( symbGetIsAccessed( sym ) = FALSE ) then
'' locals can't be public, don't check
exit sub
end if
if( symbGetTypeIniTree( sym ) ) then
t = STAB_TYPE_STSYM
else
t = STAB_TYPE_LCSYM
end if
desc += ":V"
value = *symbGetMangledName( sym )
else
t = STAB_TYPE_LSYM
desc += ":"
value = str( symbGetOfs( sym ) )
end if
'' data type
desc += hGetDataType( sym )
hEmitSTABS( t, desc, 0, 0, value )
end sub
'' should rename to param?
sub edbgEmitProcArg( byval sym as FBSYMBOL ptr )