Odd problem when using the FBdebugger, says code is not executable in a for loop

New to FreeBASIC? Post your questions here.
olympic sleeper
Posts: 41
Joined: Jun 07, 2020 15:47

Odd problem when using the FBdebugger, says code is not executable in a for loop

Postby olympic sleeper » Jul 12, 2020 16:56

Hi,

I have a really evil bug in a section of code and am trying to use the FBdebugger to nail it. I have narrowed the problem down to 1 for-next loop and the code inside this, however when I try to step inside the loop, the debugger states -inaccessible line - not executable.

Thing is, this line is executable and is executed, its the print statement I've maked below. It prints to the console when the code runs, so why can't I step into this loop? Do I need another option at compile other than -g?

Code: Select all

   temp_num_obj=num_objects
   for count=1 to temp_num_obj
      print count
      obj_loc=objects(count)->location                     'for objects in a room the obj_loc will be positive starting at 1
      print objects(count)->long_name,obj_loc                  '<<<<<trying to step to here
      
      if bit(objects(count)->status,5) then                      'if its currently being worn
         objects(_player)->apparel(objects(count)->cloth_type)=count
      end if
      
      if obj_loc>0 then                              'if obj_loc is a room
         obj_link=obj_loc
         db(obj_loc).linked_objects=db(obj_loc).linked_objects+tag(count)
         obj_link=obj_loc
         
         if obj_loc>0 then
            print "object>>> ";count,objects(count)->long_name;" is in ";obj_loc
            add_tag(db(obj_loc).arrangements(0),count)   'rooms do not have a location, but objects within rooms do
         end if
      else                     'for objects in or around others the obj_loc will be negative and relate to the 1st object (1+num_rooms)
            
         obj_loc=abs(obj_loc)      
         obj_link=abs(obj_loc)+num_rooms   'need to add number of rooms as objects are stored from object 1 and not db pos 1 in data
               
         add_tag(objects(obj_loc)->arrangements(objects(count)->position),count)
         
         print obj_loc,">";objects(obj_loc)->obj_name,count;_
         "",objects(count)->long_name,objects(count)->position,">";objects(obj_loc)->arrangements(objects(count)->position);"<"
                  
         objects(obj_loc)->linked_objects=objects(obj_loc)->linked_objects+tag(count)
      end if
next
SARG
Posts: 1118
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Odd problem when using the FBdebugger, says code is not executable in a for loop

Postby SARG » Jul 12, 2020 17:56

Hi o.s.

What version do you use (gas32bit, gcc 32/64bit) ?
In case of gcc things are not always simple but at first look no problem for accessing that line.

For seeing exactly the problem you could you post the entire code.

SARG (fbdebugger's author)
olympic sleeper
Posts: 41
Joined: Jun 07, 2020 15:47

Re: Odd problem when using the FBdebugger, says code is not executable in a for loop

Postby olympic sleeper » Jul 19, 2020 16:22

Hi Sarg,
I'm using the fbdbg 64 version, on Windows 10. I confess I don't understand this either as other for..next loops are stepped into. I solved the debug issue by changing the code to use a while wend, which stepped in fine. This is the whole routine. Having found the bug the current code is somewhat different. The whole app is now significantly changed, and maybe too large to post(?).

Code: Select all

sub setup_rooms()
dim count as integer
dim temp as string
dim hash as integer
dim obj_id as integer
dim room_count as integer=1
dim obj_count as integer
dim obj_loc as integer
dim obj_link as integer
num_objects=0
num_rooms=0
restore d_objects
   count=1
   do
      read temp
      'print "temp";temp;"<"
      if temp <>"*end*" then
         with db(count)
            .obj_type=temp
            'print ">";.obj_name;"<"
            
            select case .obj_type
         
               case "room"
                  read .obj_name,.long_name
                  read .room_start_words,.init_player_stance,.init_player_position,.description
                  read .directions,.inv_directions
                  print "}";.obj_name,.room_start_words;" ";.init_player_stance;" ";.init_player_position;" ";.description;"{"
                  num_rooms=num_rooms+1
               case "object","scenery"
                  read .obj_name,.long_name
                  read .additional_desc,.location,.weight,.size,.description,.hold_size,.surface_size,.status,.cloth_type
                  print ">";.obj_name,.additional_desc,.location,.weight,.size,.description,.hold_size,.surface_size,.status,.cloth_type
                  obj_count=obj_count+1
                  
                  num_objects=num_objects+1
               case "alts"                  'alts are additional names for the previous object eact one separated by a +
                                       'data line format must be <object>...... new line <alts> !
                  count=count-1:read db(count).alt_names
               case "position"
                  print"-----------------------------------";db(count).long_name
                  
                  count=count-1:read db(count).position
                  print"-----------------------------------";db(count).long_name
            end select
         end with
      end if
print ">>>>>>>>>>>>>>>>>>>>>>>>>>>num objects>";num_objects,"num rooms>";num_rooms
      with db(count)
         
      '   print "}";.obj_name,.room_start_words;" ";.init_player_stance;" ";.init_player_position;" ";.description;"{"
         
      end with
      
      count = count +1
      if count = _max_object_count then
         print "**********Error********** max object count exceeded, increase the max object count define."
         stop
      end if
   loop while temp<>"*end*"   

'now have num_objects so redim the hash_table

   redim hash_search(num_objects) as integer
   redim rooms(num_rooms) as integer
   redim objects(num_objects) as _thing ptr
   obj_count=1:count=1
   while db(count).obj_name<>""
         
      if db(count).obj_type="object" or db(count).obj_type="scenery" then 'only for objects not needed for rooms
      
         with db(count)
                                                         'add the object to its 'container' either room or another object linked_objects list
            objects(obj_count)=@db(count)                           'set the object id obj_count to point to this object, now have a flat array pointers to just objects
            
            
            print "obj_count>";obj_count,"db count>";count,db(count).obj_name,"contents",db(count).linked_objects
            
            print obj_count,">";objects(obj_count)->long_name;"<"
            obj_count=obj_count+1
            
            hash=calc_hash(.obj_name,num_objects)                     'calculate hash value
            
            if hash_search(hash)=0 then                               'if there is nothing in the hash search
               hash_search(hash)=count                                    'store the current object id (count)
            else
               obj_id=hash_search(hash)                              'get the the object id in the hash table
               while db(obj_id).hash_next_object<>0                  'while the next object is not 0
                  'print obj_id,db(obj_id).next_object,
                  obj_id=db(obj_id).hash_next_object                  'get the id of the next object
         
               wend
               'print obj_id,.long_name                                          'object id now contains the id of the object at the end of the list
               .hash_next_object=count
            end if
         end with
      elseif db(count).obj_type="room" then
         rooms(room_count)=count
         room_count=room_count+1
      end if
      count=count+1
   wend
print "*************"

   objects(0)=@db(0)                                       'set up objects pointer for player, object 0 in db location 0

   for count=1 to num_objects
   'print count
      obj_loc=objects(count)->location                        'for objects in a room the obj_loc will be positive starting at 1
      print objects(count)->long_name,obj_loc
      
      if bit(objects(count)->status,5) then                      'if its currently being worn
         objects(_player)->apparel(objects(count)->cloth_type)=count
      end if
      
      
      if obj_loc>0 then         'if obj_loc is a room
         obj_link=obj_loc
         db(obj_loc).linked_objects=db(obj_loc).linked_objects+tag(count)
         obj_link=obj_loc
         'while db(obj_link).next_obj_here<>0
         '   obj_link=db(obj_link).next_obj_here
         'wend
         '   db(obj_link).next_obj_here=count


         if obj_loc>0 then add_tag(db(obj_loc).arrangements(0),count)   'rooms do not have a location, but obejcts within rooms do
         
      else                                                'for objects in or around others the obj_loc will be negative and relate to the 1st object (1+num_rooms)
            
         obj_loc=abs(obj_loc)      
         obj_link=abs(obj_loc)+num_rooms                                    'need to add number of rooms as objects are stored from object 1 and not db pos 1 in data
      '                                                            'may need to take one off this
      '   while db(obj_link).next_obj_here<>0
      '      obj_link=db(obj_link).next_obj_here
      '   wend
      '      db(obj_link).next_obj_here=count
      
               
         add_tag(objects(obj_loc)->arrangements(objects(count)->position),count)
         
         print obj_loc,">";objects(obj_loc)->obj_name,count;"<",objects(count)->long_name,objects(count)->position,">";objects(obj_loc)->arrangements(objects(count)->position);"<"
                  
         objects(obj_loc)->linked_objects=objects(obj_loc)->linked_objects+tag(count)
      end if
   next
   
end sub


It reads data lines in this form

Code: Select all

data "room","South end of beach","south of beach"
data "You are","","at","the south end of a long sandy beach that stretches away to the north"
data "<n>2","<all>You cannot go that way"

data "scenery","sea","sea"
data "What all of it?",1,0,0,"Its wet.",0,0,0,0
data "scenery","sea","sea"
data "What all of it?",2,0,0,"Its a lovely blue with waves lapping onto the shore.",0,0,0,0
data "scenery","beach","beach"
data "What all of it?",2,0,0,"Nice and sandy.",0,0,0,0
data "scenery","sand","sand"
data "",2,0,0,"Essential building material for sandcastles",0,0,0,0
data "scenery","sea","sea"
data "What all of it?",3,0,0,"Its a quite shallow and inviting here.",0,0,0,0
'5
data "scenery","jetty","wooden jetty"
data "But it's fixed!",1,0,0,"Wooden, complete with knot holes.",0,0,0,0
data "scenery","wood","wood"
data "Why do we need to dismantle the jetty?",1,0,0,"Its weather worn and salt splashed.",0,0,0,0
data "scenery","salt","salt"
data "Can't see any use for that.",1,0,0,"Its staining the wood.",0,0,0,0
data "scenery","splash","splash"
data "",1,0,0,"I'm no chemist, but given how close we are I'd say they were caused by the sea.",0,0,0,0
data "alts","splashes+stain+stains"
data "scenery","seawater","seawater"
data "",1,0,0,"Its wet.",0,0,0,0
data "*end*"


Again the current code is somewhat different.
SARG
Posts: 1118
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Odd problem when using the FBdebugger, says code is not executable in a for loop

Postby SARG » Jul 22, 2020 7:36

Hi o.s.

Without the initial code it's hard to say what was the problem. However I'll try to find it (and fix it if possible) by using the code provided in your 2 posts.

My advice : if you get trouble for debugging with 64bit version compile in 32bit (gas not gcc) and then use fbdebugger version 32bit. It's 99% problem free. And if 64bit integers are necessary change their datatype by longint.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 4 guests