Jump to content
IGNORED

FastBasic Debugger Extension for VSCode


Recommended Posts

Hi all -

 

I wanted to share that I am working on an extension that brings debugging to @dmsc's excellent FastBasic Cross Compiler via Visual Studio Code (breakpoints, stepping through code, modifying variables).

 

My goals:

1. To make FastBasic as accessible as possible to newer coders by providing a way to quickly get up and running with FastBasic on Windows (Altirra) and Mac (Atari800Macx).

2. Provide an great "code stepping" debugging experience on both Windows and Mac, so you can easily step through code to tackling bugs that are harder to track down via alternate methods (Altirra debugger, print statements, etc).

3. Shows memory location (e.g $A800) of variables for those that want to know where to look at memory in Altirra.

 

Stretch goals:

1. Debug FastBasic running on real hardware over FujiNet

2. Leverage FastBasic's code formatter

3. Provide a code minifier, useful for 10 liner contests

 

How it works

  1. It injects some FastBasic debugging code into the source code right before compiling. This handles the communication with VSCode, sending/updating memory contents, triggering breakpoints.
  2. It then reads the LBL and LST files the FastBasic compiler outputs to find the variable locations and types.
  3. It reads/writes from Host drive H (easy first pass that works in both emulators) for communication.

 

Here is a quick video of me demonstrating its current state. Let me know if you are interested in trying out the extension once I get it to a sharable state.

 

This is my first VSCode extension, so I still need to read up on packaging it, etc. I plan to put the source out on github.

 

 

image.thumb.png.3da38e28c5fadb42f944b34451a48551.png

 

  • Like 10
  • Thanks 1
Link to comment
Share on other sites

18 minutes ago, tschak909 said:

This is a nice surprise! :)

 

-Thom

Yep, it was either spend a few hours debugging an issue with the 5 Card FastBasic game client, or spend a few days to learn how to create a debugging extension in VSCode. :)  Okay, I’ve actually been meaning to do it for some time, and this weekend I had some extra time to make some progress. 

  • Like 1
Link to comment
Share on other sites

Hi!

2 hours ago, The Car said:

Hi all -

 

 

Here is a quick video of me demonstrating its current state. Let me know if you are interested in trying out the extension once I get it to a sharable state.

Wow, this is fantastic!

 

I have some (very preliminary) work on adding debugging capabilities to the Atari IDE, basically after compiling each line, adds one bytecode that tests if the execution needs to stop there. I think your approach is similar?

 

Have Fun!

 

Link to comment
Share on other sites

14 hours ago, dmsc said:

Hi!

Wow, this is fantastic!

 

I have some (very preliminary) work on adding debugging capabilities to the Atari IDE, basically after compiling each line, adds one bytecode that tests if the execution needs to stop there. I think your approach is similar?

 

Have Fun!

 

Thanks! Yes, right now it just prepends a proc call at the start of every non-empty line (regular FastBasic, so it gets compiled into the byte code along with the rest of the source). The proc checks if "step next statement" flag is true or if the passed line number exists in an array of breakpoints. If so, it stops execution and sends the line number it stopped at and variable memory dump to the debugger, waiting until instructed to continue. 

 

So, each valid line will have this at the front:

000010r 1               @FastBasic_LINE_2:    ; LINE 2
000010r 1  rr               .byte    TOK_BYTE
000011r 1  02               .byte    2                     <-- Set line number
000012r 1  rr               .byte    TOK_PUSH
000013r 1  rr               .byte    TOK_CALL
000014r 1  rr rr            .word    fb_lbl____DEBUG_CB    <-- Check if we should stop execution

 

To avoid the array loop to check each breakpoint line, in the future I may try adding an "IF 0 THEN @PROC N"  check on each line. When a line needs a breakpoint set, I update the bytecode TOK_0 to a TOK_1 in memory.   Then you could have many breakpoints and not slow down execution between them.

 

00000Ar 1               @FastBasic_LINE_2:	; LINE 2
00000Ar 1  rr           	.byte	TOK_0  <-- If this is TOK_1, the breakpoint proc will get called
00000Br 1  rr           	.byte	TOK_COMP_0
00000Cr 1  rr           	.byte	TOK_CJUMP
00000Dr 1  rr rr        	.word	jump_lbl_2
00000Fr 1  rr           	.byte	TOK_BYTE
000010r 1  02           	.byte	2                    <-- Set line number (debugger still needs to know this)
000011r 1  rr           	.byte	TOK_PUSH
000012r 1  rr           	.byte	TOK_CALL
000013r 1  rr rr        	.word	fb_lbl____DEBUG_CB   <-- Immediately breaks. no longer needs to check line against array
000015r 1               jump_lbl_2:

 

But that is future, it's quick enough as-is now. :)

 

Having some debugging capabilities in the Atari IDE would also be a great, for people used to Atari BASIC where you can break, inspect variables, then continue.

 

 

  • Like 1
Link to comment
Share on other sites

  • 5 weeks later...

Something strange going on here...

 

 

Ctrl+F5 produces this which looks OK:

image.thumb.png.61cede636e3fc2a34fa459793c5d36a9.png

 

F5 produces this which is a mess:

image.thumb.png.9de374051d2307d311be2a0c4fc81f9f.png

 

I think adding the GET at the end of the program for debug causes this.

 

EDIT: If I change the FB program, then both the F5 and Ctrl-F5 produce the same output (bottom one).

 

Link to comment
Share on other sites

  • 10 months later...

This is pretty awesome, just set it up.  I'm trying to debug a program I ported from Atari BASIC and am hoping this can help.  Anyone know how to get non-ASCII to be honored in VS code?
I have blocks like this (shown in vim):

 

        ? #6,"xnt g`ud qd`bgdc sgd";
        ? #6,"   dmc ne ^Wdantmc   ";
        ? #6,"   ax ^U^P^R^P ^Q`rsdm   ";
        ? #6,"^Sdkhbhs`shnmr sn xnt";
        ? #6,"^Utrs nmd k`rs rbqddm";
        ? #6,"sn g`ud ` khsskd etm";
        ? #6,"¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢";
        ? #6,"¢Z[\]^_Z[\]^_Z[\]^_¢";
        ? #6,"¢<83><83><83><83><83><83><83><83><83><83><83><83><83><83><83><83><83><83>¢";
        ? #6,"¢_^]\[Z_^]\[Z_^]\[Z¢";
        ? #6,"¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢";

In VS Code

  ? #6,"���������������������";
        ? #6,"ZZZZ  ��������    �";
        ? #6,"�[[[[  �������� ,, ��";
        ? #6,"\\\\  �������� ,, �";
        ? #6,"�]]]�  �        ,  ��";

 

So, when it gets compiled from within VS code things don't look correct.  I usually compile FastBASIC on Linux, and this code is just in a text file.  I'm loading the same text file into VS code.

Edited by telengard
Link to comment
Share on other sites

Hi!

10 hours ago, telengard said:

This is pretty awesome, just set it up.  I'm trying to debug a program I ported from Atari BASIC and am hoping this can help.  Anyone know how to get non-ASCII to be honored in VS code?
I have blocks like this (shown in vim):

 

        ? #6,"xnt g`ud qd`bgdc sgd";
        ? #6,"   dmc ne ^Wdantmc   ";
        ? #6,"   ax ^U^P^R^P ^Q`rsdm   ";
        ? #6,"^Sdkhbhs`shnmr sn xnt";
        ? #6,"^Utrs nmd k`rs rbqddm";
        ? #6,"sn g`ud ` khsskd etm";
        ? #6,"¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢";
        ? #6,"¢Z[\]^_Z[\]^_Z[\]^_¢";
        ? #6,"¢<83><83><83><83><83><83><83><83><83><83><83><83><83><83><83><83><83><83>¢";
        ? #6,"¢_^]\[Z_^]\[Z_^]\[Z¢";
        ? #6,"¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢";

In VS Code

  ? #6,"���������������������";
        ? #6,"ZZZZ  ��������    �";
        ? #6,"�[[[[  �������� ,, ��";
        ? #6,"\\\\  �������� ,, �";
        ? #6,"�]]]�  �        ,  ��";

 

So, when it gets compiled from within VS code things don't look correct.  I usually compile FastBASIC on Linux, and this code is just in a text file.  I'm loading the same text file into VS code.

 

You can use the  -l option to the command line compiler to convert your program to a fully ASCII form:

 

fastbasic -l myprog.bas

 

This will convert all control characters to hexadecimal syntax, indent and reformat your code.

 

Newer versions (on github) also can specify the output file name, and if you want an extended or minimized listing.

 

Have Fun!

 

  • Like 1
Link to comment
Share on other sites

On 4/25/2024 at 11:32 PM, dmsc said:

Hi!

 

You can use the  -l option to the command line compiler to convert your program to a fully ASCII form:

 

fastbasic -l myprog.bas

 

This will convert all control characters to hexadecimal syntax, indent and reformat your code.

 

Newer versions (on github) also can specify the output file name, and if you want an extended or minimized listing.

 

Have Fun!

 

that worked great, thank you!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...