[LLVMdev] Debug Info scope across include files?

John.Slagel john.slagel at gmail.com
Sun Jun 8 06:21:36 PDT 2014


I'm writing an old-school BASIC compiler using LLVM to make Windows
executables (using MingGW linker), everything works great so far, including
the debug info, with one exception.

A BASIC module (.bas file) doesn't have a "main" function, so I create a
fake _main function and use that function as the scope for each intruction's
line number debug information.   This way I can single step with gdb:

=========== file x.bas ========
print "hello 1"
print "hello 2"

============= sample gdb session ===========
D:\dev\BasicParser>gdb x.exe
GNU gdb (GDB) 7.4
<snip>
Reading symbols from D:\dev\BasicParser\x.exe...done.
(gdb) b _main
Breakpoint 1 at 0x401000: file x.bas, line 1.
(gdb) r
Starting program: D:\dev\BasicParser\x.exe
[New Thread 6164.0xc9c]

Breakpoint 1, _main () at x.bas:1
1       print "hello 1"
(gdb) n
hello 1
2       print "hello 2"
(gdb) n
hello 2
[Inferior 1 (process 6164) exited normally]
(gdb) q


The problem I now face is that the flavor of BASIC I support can use include
files using the meta-command REM $include:
As shown in this example:

=========== file a.bas ===============
x$ = "File A"
10 print "In file A"
rem $include: 'b.bi'
30 print "Back to file A"
print "X$=";x$

========= file b.bi ============
15 print "At line 15 in file b"
17 print "At line 17 in file b"
x$ = "File B"

And when I execute a.exe I get:

In file A
At line 15 in file b
At line 17 in file b
Back to file A
X$=File B

So the "fake" main function now spans two files.

My question is, if currently I link each instruction to the function's
scope, what concepts do I need to study to figure out how to make each line
in a function cross into another file?  
My guess is that I'll need to manage a set of scope blocks for each
function, where each block comes from a different file, and link each
instruction to one of these blocks instead of to the function... 

Thanks!!







More information about the llvm-dev mailing list