The BreakPoint on first line cannot be hit if Dim variable in .bi file

General FreeBASIC programming questions.
yangdan_hz
Posts: 6
Joined: Feb 19, 2016 2:32

The BreakPoint on first line cannot be hit if Dim variable in .bi file

Postby yangdan_hz » Feb 19, 2016 3:08

Hi All,

I want to debug the program compiled by fbc with gdb in windows. There is a problem that the breakpoint on first line cannot be hit if Dim variables in .bi file.

'Test.bi

Code: Select all

Function MyProcedure As Integer
   Dim i As Integer = 1
   print i
   Return i
End Function

Dim temp As Integer


Test.bas

Code: Select all

IF MyProcedure >0 Then
Print MyProcedure
End IF

IF MyProcedure >0 Then
Print MyProcedure
End IF

when using gdb to debug the program, if the breakpoint is on first line, the line info is "line number 0 is out of range for "Test.bas" " after run. But if the breakpoint is on second line, the line info is correct.


E:\My_SourceCode\Proj_AMI\Test>fbc -g Test.bas -include Test.bi
E:\My_SourceCode\Proj_AMI\Test>gdb Test.exe
(gdb) break 1
Breakpoint 1 at 0x4015bd: E:\My_SourceCode\Proj_AMI\Test\Test.bas:1. (2 locations)
(gdb) run
Starting program: E:\My_SourceCode\Proj_AMI\Test/Test.exe
[New Thread 5164.0x1e3c]

Breakpoint 1, main (__FB_ARGC__=<error reading variable>,
__FB_ARGV__=<error reading variable>) at Test.bas:8
(gdb) info line
Line number 0 is out of range for "Test.bas".
MrSwiss
Posts: 3367
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: The BreakPoint on first line cannot be hit if Dim variable in .bi file

Postby MrSwiss » Feb 19, 2016 9:35

Hi yangdan_hz,

wellcome to the Forum.
A Tip: try "correct" coding first:

Code: Select all

Function MyFunc() As Long    ' instead of Integer, () = no parameters to Function
    Dim As Long tmp = 1
    Function = tmp    ' alternate to Return ...
End Function

' simplified version (of above), one of the two MUST be commented out!
Function MyFunc() As Long    ' without intermediate Variable
    Function = 1    ' alternate to Return ...
End Function

' ----- EOF "Test.bi" -----
Then in MAIN ("Test.bas"):

Code: Select all

If MyFunc() <> 0 Then ...    ' or as below
If MyFunc() Then ...    ' is the same test, e.g. it returns: "TRUE" if result is "NOT 0"


@Admin,
please move this Thread to "Beginners", thanks.
SARG
Posts: 997
Joined: May 27, 2005 7:15
Location: FRANCE

Re: The BreakPoint on first line cannot be hit if Dim variable in .bi file

Postby SARG » Feb 19, 2016 10:42

Hi all,

The issue could come by the fact the initialization of temp variable is not referenced from the right file.
See asm code.

If I remember well it's an old issue for debugging : better to have only procs in bi files.

Code: Select all

   .stabs "test_today.bas",132,0,0,.Lt_0015   <---- following code lines should be in test_today.bas
.Lt_0015:
   .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, 8
   .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_0016:
##
   mov dword ptr [ebp-8], 0      <------------ initialization of variable  temp
.stabn 68,0,7,.Lt_0016-_main         <------------ line 7 should be referenced in test_today.bi not in test_today.bas
###Include "test_today.bi"
.Lt_0017:
##
##'test
##
##IF MyProcedure >0 Then
   call _MYPROCEDURE@0
   test eax, eax
   jle .Lt_000E
.Lt_000F:
.stabn 68,0,5,.Lt_0017-_main    <------ line 5 in test_today.bas
.Lt_0018:
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: The BreakPoint on first line cannot be hit if Dim variable in .bi file

Postby dkl » Feb 19, 2016 16:15

Yea, I remember there being an fbc bug with regards to debug data emitting for procedures or variables in .bi files. I just never figured out where exactly the problem is.
caseih
Posts: 1425
Joined: Feb 26, 2007 5:32

Re: The BreakPoint on first line cannot be hit if Dim variable in .bi file

Postby caseih » Feb 19, 2016 18:20

Guess I'm an old C programmer, but I always wonder why .bi files are abused by FB programmers in this way. I also find it slightly odd how #include is abused in a similar way--why not compile each .bas file separately and then link them? Has no one heard of modules and object files?

I guess I treat .bi files like header files. They contain definitions and declarations which are used by .bas files, and don't contain code. Thus the debugger should have no reason to trace into a .bi file. This is just a convention of course. But it makes a sort of sense, at least to me!
SARG
Posts: 997
Joined: May 27, 2005 7:15
Location: FRANCE

Re: The BreakPoint on first line cannot be hit if Dim variable in .bi file

Postby SARG » Feb 19, 2016 19:01

caseih wrote:I guess I treat .bi files like header files. They contain definitions and declarations which are used by .bas files, and don't contain code. Thus the debugger should have no reason to trace into a .bi file. This is just a convention of course. But it makes a sort of sense, at least to me!

"Dim as integer temp " is a declaration and an asm line of code is produced for initializing......
But "Dim shared as integer temp" no code
caseih
Posts: 1425
Joined: Feb 26, 2007 5:32

Re: The BreakPoint on first line cannot be hit if Dim variable in .bi file

Postby caseih » Feb 19, 2016 19:37

Right. If we follow this convention, except for UDTs, shared and static variable declarations, variables should always be declared local to the current module (the .bas file). I think of the .bi file as the public interface of my module. The public doesn't need to care or know about the specifics of what functions and variables I'm using, except for the ones they will interface with. And the variables they will interface with may be declared in the .bi file (as shared) but actually defined in the .bas file.

I think many FB programmers on this forum aren't aware of how to do multiple modules or object files either. Basically if you compile each .bas file separately, then we can link them together with:

fbc file1.bas file2.bas etc

or

fbc main.bas precompiled1.o precompiled2.o
RockTheSchock
Posts: 226
Joined: Mar 12, 2006 16:25

Re: The BreakPoint on first line cannot be hit if Dim variable in .bi file

Postby RockTheSchock » Feb 19, 2016 19:57

Maybe fbc should show warning/information if executable code is put into .bi file. Just as a hint.
yangdan_hz
Posts: 6
Joined: Feb 19, 2016 2:32

Re: The BreakPoint on first line cannot be hit if Dim variable in .bi file

Postby yangdan_hz » Feb 23, 2016 3:33

caseih wrote:I think many FB programmers on this forum aren't aware of how to do multiple modules or object files either. Basically if you compile each .bas file separately, then we can link them together with:

fbc file1.bas file2.bas etc

or

fbc main.bas precompiled1.o precompiled2.o


I will try to do that. May be it will resolved my problem. Thanks.

Thanks everyone to reply my problem.

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest