Skip to content

Commit f697fba

Browse files
authored
Merge pull request #96 from jayrm/fbc-debug
fbc-debug: Add debug info for included files
2 parents c0fdfeb + 8ad8a11 commit f697fba

File tree

14 files changed

+75
-40
lines changed

14 files changed

+75
-40
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Version 1.06.0
7272
- #642, #886: CASTs involving CONST qualifiers solved out too early allowing invalid statements to be compiled
7373
- #801: *@(expr) solved to (expr) did not cleanly remove null ptr checks allowing invalid datatype assignment with -exx. *PTRCHK(@expr) solves to (expr).
7474
- #880: Overload binary operators now support covariant arguments, overloaded procedure resolution changed especially with respect to CONST and non-CONST parameters
75+
- Fix for debugging lines in include files but not in procedures. Filename debugging information added for module level statements in included files.
7576

7677

7778
Version 1.05.0

src/compiler/ast-node-misc.bas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ end function
152152
function astNewDBG _
153153
( _
154154
byval op as integer, _
155-
byval ex as integer _
155+
byval ex as integer, _
156+
byval filename As ZString Ptr _
156157
) as ASTNODE ptr
157158

158159
dim as ASTNODE ptr n = any
@@ -165,13 +166,14 @@ function astNewDBG _
165166

166167
n->dbg.op = op
167168
n->dbg.ex = ex
169+
n->dbg.filename = filename
168170

169171
function = n
170172
end function
171173

172174
function astLoadDBG( byval n as ASTNODE ptr ) as IRVREG ptr
173175
if( ast.doemit ) then
174-
irEmitDBG( n->dbg.op, astGetProc( )->sym, n->dbg.ex )
176+
irEmitDBG( n->dbg.op, astGetProc( )->sym, n->dbg.ex, n->dbg.filename )
175177
end if
176178

177179
function = NULL

src/compiler/ast.bi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ type AST_NODE_JMPTB
172172
end type
173173

174174
type AST_NODE_DBG
175-
ex as integer
176-
op as integer
175+
ex as integer
176+
filename as zstring ptr
177+
op as integer
177178
end type
178179

179180
type AST_NODE_MEM
@@ -793,8 +794,9 @@ declare function astNewASM( byval asmtokhead as ASTASMTOK ptr ) as ASTNODE ptr
793794

794795
declare function astNewDBG _
795796
( _
796-
byval op as integer, _
797-
byval ex as integer = 0 _
797+
byval op as integer, _
798+
byval ex as integer = 0, _
799+
byval filename as zstring ptr = 0 _
798800
) as ASTNODE ptr
799801

800802
declare function astNewMEM _

src/compiler/edbg_stab.bas

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,13 @@ sub edbgLineBegin _
266266
( _
267267
byval proc as FBSYMBOL ptr, _
268268
byval lnum as integer, _
269-
byval pos_ as integer _
269+
byval pos_ as integer, _
270+
ByVal filename As zstring ptr _
270271
)
271272

272273
if( env.clopt.debuginfo = FALSE ) then
273274
exit sub
274-
end if
275+
end if
275276

276277
if( ctx.lnum > 0 ) then
277278
ctx.pos = pos_ - ctx.pos
@@ -281,6 +282,8 @@ sub edbgLineBegin _
281282
end if
282283
end if
283284

285+
edbgInclude( filename )
286+
284287
ctx.pos = pos_
285288
ctx.lnum = lnum
286289
if( ctx.isnewline ) then
@@ -530,7 +533,7 @@ sub edbgEmitProcHeader _
530533

531534
''
532535
ctx.isnewline = TRUE
533-
ctx.lnum = 0
536+
ctx.lnum = 0
534537
ctx.pos = 0
535538
ctx.label = NULL
536539

@@ -645,7 +648,7 @@ sub edbgEmitProcFooter _
645648

646649
''
647650
ctx.isnewline = TRUE
648-
ctx.lnum = 0
651+
ctx.lnum = 0
649652
ctx.pos = 0
650653
ctx.label = NULL
651654

src/compiler/emit.bas

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ sub emitFlush( )
204204
case EMIT_NODECLASS_DBG
205205
cast( EMIT_DBGCB, emit.opFnTb[n->dbg.op] )( n->dbg.sym, _
206206
n->dbg.lnum, _
207-
n->dbg.pos )
207+
n->dbg.pos, _
208+
n->dbg.filename )
208209

209210
end select
210211

@@ -456,7 +457,8 @@ private function hNewDBG _
456457
byval op as integer, _
457458
byval sym as FBSYMBOL ptr, _
458459
byval lnum as integer = 0, _
459-
byval pos_ as integer = 0 _
460+
byval pos_ as integer = 0, _
461+
byval filename As zstring ptr = 0 _
460462
) as EMIT_NODE ptr static
461463

462464
dim as EMIT_NODE ptr n
@@ -466,6 +468,7 @@ private function hNewDBG _
466468
n->dbg.op = op
467469
n->dbg.sym = sym
468470
n->dbg.lnum = lnum
471+
n->dbg.filename = filename
469472
n->dbg.pos = pos_
470473

471474
function = n
@@ -1632,10 +1635,11 @@ end function
16321635
function emitDBGLineBegin _
16331636
( _
16341637
byval proc as FBSYMBOL ptr, _
1635-
byval lnum as integer _
1638+
byval lnum as integer, _
1639+
byval filename As zstring ptr _
16361640
) as EMIT_NODE ptr
16371641

1638-
function = hNewDBG( EMIT_OP_LINEINI, proc, lnum, emit.pos )
1642+
function = hNewDBG( EMIT_OP_LINEINI, proc, lnum, emit.pos, filename )
16391643

16401644
end function
16411645

src/compiler/emit.bi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ type EMIT_DBGNODE
199199
op as integer
200200
sym as FBSYMBOL ptr
201201
lnum as integer
202+
filename as zstring ptr
202203
pos as integer
203204
end type
204205

@@ -261,7 +262,8 @@ type EMIT_MEMCB as sub( byval dvreg as IRVREG ptr, _
261262

262263
type EMIT_DBGCB as sub( byval sym as FBSYMBOL ptr, _
263264
byval lnum as integer, _
264-
byval pos as integer )
265+
byval pos as Integer, _
266+
ByVal filename As ZString Ptr =0 )
265267

266268
'' if changed, update the _vtbl symbols at emit_*.bas::*_ctor
267269
type EMIT_VTBL
@@ -790,7 +792,8 @@ declare function emitSTKCLEAR _
790792
declare function emitDBGLineBegin _
791793
( _
792794
byval proc as FBSYMBOL ptr, _
793-
byval ex as integer _
795+
byval ex as Integer, _
796+
ByVal filename As ZString Ptr _
794797
) as EMIT_NODE ptr
795798

796799
declare function emitDBGLineEnd _

src/compiler/emit_x86.bas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6049,10 +6049,11 @@ private sub _emitLINEINI _
60496049
( _
60506050
byval proc as FBSYMBOL ptr, _
60516051
byval lnum as integer, _
6052-
byval pos_ as integer _
6052+
byval pos_ as integer, _
6053+
byval filename As zstring ptr _
60536054
)
60546055

6055-
edbgLineBegin( proc, lnum, pos_ )
6056+
edbgLineBegin( proc, lnum, pos_, filename )
60566057

60576058
end sub
60586059

src/compiler/emitdbg.bi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ declare sub edbgLineBegin _
99
( _
1010
byval proc as FBSYMBOL ptr, _
1111
byval lnum as integer, _
12-
byval pos as integer _
12+
byval pos as integer, _
13+
byval filename as zstring ptr _
1314
)
1415

1516
declare sub edbgLineEnd _

src/compiler/ir-hlc.bas

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ declare sub _emitDBG _
223223
( _
224224
byval op as integer, _
225225
byval proc as FBSYMBOL ptr, _
226-
byval ex as integer _
226+
byval lnum as integer, _
227+
ByVal filename As zstring ptr = 0 _
227228
)
228229

229230
declare sub exprFreeNode( byval n as EXPRNODE ptr )
@@ -3158,11 +3159,15 @@ private sub _emitDBG _
31583159
( _
31593160
byval op as integer, _
31603161
byval proc as FBSYMBOL ptr, _
3161-
byval ex as integer _
3162+
byval lnum as integer, _
3163+
ByVal filename As zstring ptr _
31623164
)
31633165

31643166
if( op = AST_OP_DBG_LINEINI ) then
3165-
ctx.linenum = ex
3167+
ctx.linenum = lnum
3168+
if( filename <> NULL ) then
3169+
hUpdateCurrentFileName( filename )
3170+
end if
31663171
end if
31673172

31683173
end sub

src/compiler/ir-llvm.bas

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ declare sub _emitDBG _
185185
( _
186186
byval op as integer, _
187187
byval proc as FBSYMBOL ptr, _
188-
byval ex as integer _
188+
byval lnum as integer, _
189+
ByVal filename As zstring ptr = 0 _
189190
)
190191
declare function hVregToStr( byval vreg as IRVREG ptr ) as string
191192
declare sub hEmitConvert( byval v1 as IRVREG ptr, byval v2 as IRVREG ptr )
@@ -2080,13 +2081,18 @@ private sub _emitDBG _
20802081
( _
20812082
byval op as integer, _
20822083
byval proc as FBSYMBOL ptr, _
2083-
byval ex as integer _
2084+
byval lnum as integer, _
2085+
ByVal filename As zstring ptr _
20842086
)
20852087

2086-
if( op = AST_OP_DBG_LINEINI ) then
2087-
hWriteLine( "#line " & ex & " """ & hReplace( env.inf.name, "\", $"\\" ) & """" )
2088-
ctx.linenum = ex
2089-
end if
2088+
if( op = AST_OP_DBG_LINEINI ) Then
2089+
if( filename <> NULL ) then
2090+
hWriteLine( "#line " & lnum & " """ & hReplace( filename, "\", $"\\" ) & """" )
2091+
else
2092+
hWriteLine( "#line " & lnum & " """ & hReplace( env.inf.name, "\", $"\\" ) & """" )
2093+
end if
2094+
ctx.linenum = lnum
2095+
end If
20902096

20912097
end sub
20922098

0 commit comments

Comments
 (0)