When debugging a source code with include files only lines inside procedures are correctly associated with their file....
I searched in the compiler to find a way to change this behaviour. I did it with very few modifications (#20 lines added or changed).
Nota 1 If every include file name is already stored somewhere it would possible to reduce a bit the memory consumption.
Nota 2 the fix works only for the gas version although the information is now also available in ir-hlc and ir-hllvm but not really used.
As I'm not comfortable with GitHub, I hope someone, St_W or coderjeff or dkl, could integrate these mods, it would be nice.
Code: Select all
==============================================================================================================================
== AST.BI ====================================================================================================================
==============================================================================================================================
Type AST_LINE_DATA ''creating a new type containing line number and included file name SARG
linenum As Long
filename As ZString Ptr
End Type
type AST_NODE_DBG
ex as AST_LINE_DATA ''replacing integer by the new type SARG
op as Integer
end Type
.........
''adding filename SARG
declare function astNewDBG _
( _
byval op as integer, _
byval ex as integer = 0, _
ByVal filename As ZString Ptr =0 _
) as ASTNODE Ptr
........
==============================================================================================================================
== AST-NODE-MISC.BAS =========================================================================================================
==============================================================================================================================
function astNewDBG _
( _
byval op as integer, _
byval ex as Integer, _
ByVal incfile As ZString Ptr _
) as ASTNODE ptr
dim as ASTNODE ptr n = any
if( env.clopt.debuginfo = FALSE ) then
return NULL
end if
n = astNewNode( AST_NODECLASS_DBG, FB_DATATYPE_INVALID )
n->dbg.op = op
n->dbg.ex.linenum = ex ''filling linenum and filename SARG
n->dbg.ex.filename = ZstrAllocate( len( *incfile ) )''creating space to store filename SARG
*n->dbg.ex.filename = *incfile ''filling filename SARG
function = n
end function
function astLoadDBG( byval n as ASTNODE ptr ) as IRVREG ptr
if( ast.doemit ) Then
irEmitDBG( n->dbg.op, astGetProc( )->sym,Cast(Integer,@n->dbg.ex)) ''casting as integer SARG
end if
function = NULL
end Function
=============================================================================================================================
== PARSE-TOP-LEVEL.BAS =======================================================================================================
==============================================================================================================================
Sub cProgram()
dim as integer startlevel = pp.level
'' For each line...
do
'' line begin
astAdd( astNewDBG( AST_OP_DBG_LINEINI, lexLineNum( ),env.inf.incfile ) ) ''adding env.inf.incfile SARG
'' Label?
cLabel( )
..........
==============================================================================================================================
== EDBG_STAB.BAS =============================================================================================================
==============================================================================================================================
Sub edbgLineBegin _
( _
byval proc as FBSYMBOL ptr, _
byval lnum As integer, _
byval pos_ as integer _
)
Dim As AST_LINE_DATA Ptr ldataptr=Cast(AST_LINE_DATA Ptr, lnum) ''casting SARG
if( env.clopt.debuginfo = FALSE ) then
exit sub
end If
if( *ldataptr->filename <> *ctx.incfile) Then edbgInclude(ldataptr->filename) ''check new line ? SARG
zstrfree(ctx.incfile) ''no more needed so release memory SARG
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
ctx.pos = pos_
ctx.lnum = ldataptr->linenum
if( ctx.isnewline ) then
ctx.label = symbAddLabel( NULL )
hLABEL( symbGetMangledName( ctx.label ) )
ctx.isnewline = FALSE
end if
end Sub
==============================================================================================================================
== ir-hlc.bas ===================================================================================================================
==============================================================================================================================
#include once "ast.bi" ''to get AST_LINE_DATA define SARG
.........
private sub _emitDBG _
( _
byval op as integer, _
byval proc as FBSYMBOL ptr, _
byval ex as integer _
)
Dim As AST_LINE_DATA Ptr ldataptr=Cast(AST_LINE_DATA Ptr, ex) ''casting SARG
if( op = AST_OP_DBG_LINEINI ) Then
ctx.linenum = ldataptr->linenum ''retrieve line number SARG
zstrfree(ldataptr->filename) ''no need so release memory SARG
end if
end sub
==============================================================================================================================
== ir-hllvm.bas ==============================================================================================================
==============================================================================================================================
#include once "ast.bi" ''to get AST_LINE_DATA define SARG
..........
private sub _emitDBG _
( _
byval op as integer, _
byval proc as FBSYMBOL ptr, _
byval ex as integer _
)
Dim As AST_LINE_DATA Ptr ldataptr=Cast(AST_LINE_DATA Ptr, ex) ''casting SARG
if( op = AST_OP_DBG_LINEINI ) Then
ctx.linenum = ldataptr->linenum ''retrieve line number SARG
zstrfree(ldataptr->filename) ''no need so release memory SARG
hWriteLine( "#line " & ctx.linenum & " """ & hReplace( env.inf.name, "\", $"\\" ) & """" )
end if
end sub
------------------------------------
-------- For testing
------------------------------------
Code: Select all
==============================================================================================================================
== testone.bi ================================================================================================================
==============================================================================================================================
print "begin one"
#Include Once "testtwo.bi"
Dim As Integer testone=10
sub testinone
print "inside testinone"
end sub
==============================================================================================================================
== testtwo.bi ================================================================================================================
==============================================================================================================================
print "begin two"
sub testintwo
print "inside testintwo"
end sub
Dim As Integer testtwo=52
==============================================================================================================================
== testtwo.bi ================================================================================================================
==============================================================================================================================
print "begin main"
#Include Once "testone.bi"
sub test
print "inside test"
end sub
print "inside main"
-------------------------------------
--- resulting asm file
-------------------------------------
Not easy to follow as the lines coming from include files are not included in the asm code........Just a test to remove if needed.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Code: Select all
.file "tests.bas"
.stabs "D:\\compiler\\",100,0,0,.Lt_0002
.stabs "tests.bas",100,0,0,.Lt_0002
.section .text
.Lt_0002:
.stabs "integer:t1=-1",128,0,0,0
.stabs "void:t7=-11",128,0,0,0
.stabs "byte:t2=-6",128,0,0,0
.stabs "ubyte:t3=-5",128,0,0,0
.stabs "char:t4=-2",128,0,0,0
.stabs "short:t5=-3",128,0,0,0
.stabs "ushort:t6=-7",128,0,0,0
.stabs "uinteger:t8=-8",128,0,0,0
.stabs "longint:t9=-31",128,0,0,0
.stabs "ulongint:t10=-32",128,0,0,0
.stabs "single:t11=-12",128,0,0,0
.stabs "double:t12=-13",128,0,0,0
.stabs "string:t13=s12data:15,0,32;len:1,32,32;size:1,64,32;;",128,0,0,0
.stabs "fixstr:t14=-2",128,0,0,0
.stabs "pchar:t15=*4;",128,0,0,0
.stabs "boolean:t16=@s8;-16",128,0,0,0
.stabs "tests.bas",130,0,0,0
.intel_syntax noprefix
.stabs "D:\\COMPILER\\TESTTWO.BI",130,0,0,0
.stabs "D:\\COMPILER\\TESTTWO.BI",132,0,0,.Lt_000B
.Lt_000B:
.stabs "TESTINTWO:F7",36,0,2,_TESTINTWO@0
.balign 16
.globl _TESTINTWO@0
_TESTINTWO@0:
push ebp
mov ebp, esp
.stabn 68,0,2,_TESTINTWO@0-_TESTINTWO@0
.Lt_0008:
.Lt_000C:
push 1
push 16
push offset _Lt_000A
call _fb_StrAllocTempDescZEx@8
push eax
push 0
call _fb_PrintString@12
.stabn 68,0,3,.Lt_000C-_TESTINTWO@0
.Lt_000D:
.Lt_0009:
mov esp, ebp
pop ebp
ret
.stabn 68,0,4,.Lt_0009-_TESTINTWO@0
.stabn 192,0,0,.Lt_0008-_TESTINTWO@0
.stabn 224,0,0,.Lt_0009-_TESTINTWO@0
.Lt_000E:
.stabs "",36,0,0,.Lt_000E-_TESTINTWO@0
.stabs "",162,0,0,0
.stabs "D:\\COMPILER\\TESTONE.BI",130,0,0,0
.stabs "D:\\COMPILER\\TESTONE.BI",132,0,0,.Lt_0012
.Lt_0012:
.stabs "TESTINONE:F7",36,0,5,_TESTINONE@0
.balign 16
.globl _TESTINONE@0
_TESTINONE@0:
push ebp
mov ebp, esp
.stabn 68,0,5,_TESTINONE@0-_TESTINONE@0
.Lt_000F:
.Lt_0013:
push 1
push 16
push offset _Lt_0011
call _fb_StrAllocTempDescZEx@8
push eax
push 0
call _fb_PrintString@12
.stabn 68,0,6,.Lt_0013-_TESTINONE@0
.Lt_0014:
.Lt_0010:
mov esp, ebp
pop ebp
ret
.stabn 68,0,7,.Lt_0010-_TESTINONE@0
.stabn 192,0,0,.Lt_000F-_TESTINONE@0
.stabn 224,0,0,.Lt_0010-_TESTINONE@0
.Lt_0015:
.stabs "",36,0,0,.Lt_0015-_TESTINONE@0
.stabs "",162,0,0,0
.stabs "TESTS.BAS",130,0,0,0
.stabs "TESTS.BAS",132,0,0,.Lt_0019
.Lt_0019:
.stabs "TEST:F7",36,0,4,_TEST@0
.balign 16
.globl _TEST@0
_TEST@0:
push ebp
mov ebp, esp
.stabn 68,0,4,_TEST@0-_TEST@0
.Lt_0016:
.Lt_001A:
## print "inside test"
push 1
push 11
push offset _Lt_0018
call _fb_StrAllocTempDescZEx@8
push eax
push 0
call _fb_PrintString@12
.stabn 68,0,5,.Lt_001A-_TEST@0
.Lt_001B:
.Lt_0017:
mov esp, ebp
pop ebp
ret
.stabn 68,0,6,.Lt_0017-_TEST@0
.stabn 192,0,0,.Lt_0016-_TEST@0
.stabn 224,0,0,.Lt_0017-_TEST@0
.Lt_001C:
.stabs "",36,0,0,.Lt_001C-_TEST@0
.stabs "main",42,0,1,_main
.stabd 68,0,1
.stabs "main:F1",36,0,1,_main
.stabs "__FB_ARGC__:p1",160,0,0,8
.stabs "__FB_ARGV__:p17=*18=*4",160,0,0,12
.balign 16
.globl _main
_main:
push ebp
mov ebp, esp
and esp, 0xFFFFFFF0
sub esp, 20
.stabn 68,0,1,_main-_main
mov dword ptr [ebp-4], 0
call ___main
push 0
push dword ptr [ebp+12]
push dword ptr [ebp+8]
call _fb_Init@12
.Lt_0003:
.Lt_001E:
##
##print "begin main"
push 1
push 10
push offset _Lt_0005
call _fb_StrAllocTempDescZEx@8
push eax
push 0
call _fb_PrintString@12
.stabs "",162,0,0,0
.stabs "D:\\COMPILER\\TESTONE.BI",130,0,0,0
.stabs "D:\\COMPILER\\TESTONE.BI",132,0,0,.Lt_001F
.Lt_001F:
.stabn 68,0,2,.Lt_001E-_main
.Lt_0020:
push 1
push 9
push offset _Lt_0006
call _fb_StrAllocTempDescZEx@8
push eax
push 0
call _fb_PrintString@12
.stabs "",162,0,0,0
.stabs "D:\\COMPILER\\TESTTWO.BI",130,0,0,0
.stabs "D:\\COMPILER\\TESTTWO.BI",132,0,0,.Lt_0021
.Lt_0021:
.stabn 68,0,2,.Lt_0020-_main
.Lt_0022:
push 1
push 9
push offset _Lt_0007
call _fb_StrAllocTempDescZEx@8
push eax
push 0
call _fb_PrintString@12
.stabn 68,0,1,.Lt_0022-_main
.Lt_0023:
mov dword ptr [ebp-8], 52
.stabn 68,0,6,.Lt_0023-_main
.stabs "",162,0,0,0
.stabs "D:\\COMPILER\\TESTONE.BI",130,0,0,0
.stabs "D:\\COMPILER\\TESTONE.BI",132,0,0,.Lt_0024
.Lt_0024:
.Lt_0025:
mov dword ptr [ebp-12], 10
.stabn 68,0,4,.Lt_0025-_main
.Lt_0026:
###Include Once "testone.bi"
.stabs "",162,0,0,0
.stabs "TESTS.BAS",130,0,0,0
.stabs "TESTS.BAS",132,0,0,.Lt_0027
.Lt_0027:
##
##end sub
##print "inside main"
push 1
push 11
push offset _Lt_001D
call _fb_StrAllocTempDescZEx@8
push eax
push 0
call _fb_PrintString@12
.stabn 68,0,7,.Lt_0026-_main
.Lt_0004:
push 0
call _fb_End@4
mov eax, dword ptr [ebp-4]
mov esp, ebp
pop ebp
ret
.stabn 68,0,7,.Lt_0004-_main
.stabs "TESTTWO:1",128,0,0,-8
.stabs "TESTONE:1",128,0,0,-12
.stabn 192,0,0,.Lt_0003-_main
.stabn 224,0,0,.Lt_0004-_main
.Lt_0028:
.stabs "",36,0,0,.Lt_0028-_main
.stabs "",162,0,0,0
.stabs "tests.bas",132,0,0,.Lt_0029
.Lt_0029:
.section .data
.balign 4
_Lt_0005: .ascii "begin main\0"
.balign 4
_Lt_0006: .ascii "begin one\0"
.balign 4
_Lt_0007: .ascii "begin two\0"
.balign 4
_Lt_000A: .ascii "inside testintwo\0"
.balign 4
_Lt_0011: .ascii "inside testinone\0"
.balign 4
_Lt_0018: .ascii "inside test\0"
.balign 4
_Lt_001D: .ascii "inside main\0"
.section .text
.stabs "",100,0,0,.Lt_002A
.Lt_002A: