Author Topic: in which line am i ?  (Read 8099 times)

0 Members and 1 Guest are viewing this topic.

Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Re: in which line am i ?
« Reply #30 on: May 27, 2021, 02:38:49 pm »
If I understand correctly...

The problem relates to where you were in a program  when you prematurely terminate a running program (because of say an infinite loop).

Things can get "messy" because QB64 is a compiled based environment. In the old days (some 30 years ago) this type of problem was addressed by using an interpreter based BASIC (eg MS PDS 7.1 which was an upgrade to QB45). I do not know of QB45 (never used it) but with PDS 7.1 one could do all development work in the interpretive environment (break a program at predetermined point, on condition, etc and examine variable information). Because of the p-threading nature (I think) of PDS 7.1 it was practically almost as fast as a stand alone .exe which you could also easily create. So the .exe did not really need special condition checking or fancy error code settings in the program, as in the development/debug stage (using the interpretive environment) one would have hopefully sorted out all the possible bugs. QB64 effectively only works by development testing of the compiled exe.

I have previously suggested that QB64 go along the path of interpretive based (like PDS 7.1) and a few other forum members also support this. However there are forum members (including developers it seems) that are opposed to interpretive based version of QB64. So thirty years ago it was "less painful" to develop, debug and test a BASIC program, and when working, one would create the .exe file then.

In many ways, I still prefer using PDS 7.1 over QB64, because of what mentioned above - but obviously because of hardware improvements over the past 30 years, PDS 7.1 is very limited.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: in which line am i ?
« Reply #31 on: May 27, 2021, 02:42:59 pm »
https://www.qb64.org/forum/index.php?topic=458.0 — That’s the closest to all that ole stuff that you’re going to come.

oh?

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: in which line am i ?
« Reply #32 on: May 27, 2021, 02:43:58 pm »
yes Richard, your suggestion is very good! You wouldn't even need an interpreter here! When we run the exe and press ctrl + break, the exit occurs. I’m sure something stores the line. (I think if there is an error, you know). This should just be printed out!

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: in which line am i ?
« Reply #33 on: May 27, 2021, 02:46:23 pm »
if it were in qb 7.1 _MAPTRIANGLE and I would also use it because of the things listed :)

Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Re: in which line am i ?
« Reply #34 on: May 27, 2021, 03:28:40 pm »
Just a bit of a detour...

To attempt to take advantage of all QB64 features and still have superior features from the past (PDS 7.1) - I experimented having a "dual environment" (for want of a better term) for my development work. Basically it involved the following...

Generate the QB64 program as usual (running as first instance of QB64).
Open up a second instance of QB64 ( and say have a red IDE background).
The second instance of QB64 has a program to read your first instance program and does some modifications to a copy of your program such as inserting line labels (which are exactly the line numbers you see in the IDE of the first instance i.e. your program under development). Also can insert all sorts of things like program breakpoints, display eg on the title bar or console window, disk file, etc, etc of variables, relative timings, history, events. Effectively the second instance of QB64 has a "bloated" version of your original program, it will run much slower, simultaneously display/save  all the variables you choose, etc. By automatically inserting (in the second instance) a "universally used subroutine" - you could single step (forward or backward) or branch elsewhere.
Once the "bloated" program (QB64 instance #2) is setup, run this to debug. Because the line labels correspond to your original program (QB64 instance #1), it is easy to find where to edit as necessary the original program.

A big disadvantage of my approach is that if you edit the "bloated" program ie to make it work, your original program will not be updated. The idea of dual instances of QB64 accessing the exact same program/file with automatic updating of the IDE was rejected - was advised to use say NotePad instead of the second instance.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: in which line am i ?
« Reply #35 on: May 27, 2021, 04:06:04 pm »
It sounds like you are suggesting to use vWatch, which is a program made by Fellippe for debugging QB64 programs :)
Shuwatch!

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: in which line am i ?
« Reply #36 on: May 28, 2021, 04:35:24 am »
Well, here's one way to do it:

Enable debug symbols under Options -> Advanced

Compile your program. Here's mine:
Code: [Select]
Print "hello"

While 1
    Print "world"
    For i = 1 To 10
        Print i
    Next i
Wend

Launch the program under gdb and run it:
Code: [Select]
$ gdb untitled
Reading symbols from untitled...done.
(gdb) run

When you think your program is stuck, kill it with ^C and switch to thread 2:
Code: [Select]
^C
Thread 1 "untitled" received signal SIGINT, Interrupt.
0x00007ffff7d3ebf0 in __GI___nanosleep (
    requested_time=0xb56c10 <Sleep(unsigned int)::ts>, remaining=0x0)
    at ../sysdeps/unix/sysv/linux/nanosleep.c:28
28      ../sysdeps/unix/sysv/linux/nanosleep.c: No such file or directory.
(gdb) thread 2

Get a stack trace:
Code: [Select]
(gdb) bt
#0  __GI___printf_fp_l (fp=fp@entry=0x7ffff55c0bc0, loc=<optimized out>,
    info=info@entry=0x7ffff55c0720, args=args@entry=0x7ffff55c0700)
    at printf_fp.c:1246
#1  0x00007ffff788f7c9 in ___printf_fp (fp=fp@entry=0x7ffff55c0bc0,
    info=info@entry=0x7ffff55c0720, args=args@entry=0x7ffff55c0700)
    at printf_fp.c:1267
#2  0x00007ffff788a54b in _IO_vfprintf_internal (s=s@entry=0x7ffff55c0bc0,
    format=format@entry=0x4cde7d "% .6E", ap=ap@entry=0x7ffff55c0cf0)
    at vfprintf.c:1637
#3  0x00007ffff78ac321 in __IO_vsprintf (
    string=0xb48640 <qbs_str_buffer> " 1.000000E+000", format=0x4cde7d "% .6E",
    args=args@entry=0x7ffff55c0cf0) at iovsprintf.c:42
#4  0x00007ffff7892774 in __sprintf (s=<optimized out>, format=<optimized out>)
    at sprintf.c:32
#5  0x0000000000449876 in qbs_str (value=10) at libqb.cpp:6893
#6  0x00000000004095e7 in QBMAIN (unused=0x0) at ../temp/main.txt:47
#7  0x00000000004091fb in QBMAIN_LINUX (unused=0x0) at qbx.cpp:2084
#8  0x00007ffff7d34fa3 in start_thread (arg=<optimized out>)
    at pthread_create.c:486
#9  0x00007ffff79334cf in clone ()
    at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Note QBMAIN is at temp/main.txt line 47, so open internal/temp/main.txt and look at line 47:
Code: [Select]
45 do{
 46 tqbs=qbs_new(0,0);   
 47 qbs_set(tqbs,qbs_add(qbs_str((float)(*__SINGLE_I)),qbs_new_txt(" ")));   
 48 if (new_error) goto skip6;   
 49 makefit(tqbs);   
 50 qbs_print(tqbs,0);   
 51 qbs_print(nothingstring,1);   
 52 skip6:
 53 qbs_free(tqbs);   
 54 qbs_cleanup(qbs_tmp_base,0);   
 55 if(!qbevent)break;evnt(6);}while(r);

Line 55 is a code fragment that is generated after every BASIC line (more or less). The call to evnt(6) indicates that the preceeding code, including line 47, corresponds to line 6 in the BASIC source.
« Last Edit: May 28, 2021, 04:40:20 am by luke »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: in which line am i ?
« Reply #37 on: May 28, 2021, 04:20:26 pm »
thanks Luke, this is an interesting approach! I will study. interesting thing is what else to see with it.