Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:17 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Possible Debugging Tool to Add to MMBasic MM.Info?

Author Message
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1109
Posted: 08:45pm 01 Jan 2024
Copy link to clipboard 
Print this post

Would it be remotely possible to add, say, an MM.Info field that allows a function or subroutine to determine what line it was called from? Or if easier, what line it will return to? Or maybe this is already available?
Visit Vegipete's *Mite Library for cool programs.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 09:29pm 01 Jan 2024
Copy link to clipboard 
Print this post

While waiting for that, a possible work-around:-

Before each call to the offending Sub set a flag that identifies the current location.
The last digit indicating what happened.

eg
Sub.Name.Flag = 420 : Sub.Name : Sub.Name.Flag = 429 'indicate returned ok

elsewhere in the program

Sub.Name.Flag = 430 : Sub.Name : Sub.Name.Flag = 439 'indicate returned ok

When things go wrong read the value of Sub.Name.Flag and it will also show if the crash happened in the Sub or after it returned to the identified location.

Edit
If She sub is big the last digit could also be used to show where in the Sub it got to.
eg at various points in the Sub

Sub.Name.Flag = Inc Sub.Name.Flag
Edited 2024-01-02 07:39 by phil99
 
EDNEDN
Senior Member

Joined: 18/02/2023
Location: United States
Posts: 118
Posted: 09:38pm 01 Jan 2024
Copy link to clipboard 
Print this post

  vegipete said  Would it be remotely possible to add, say, an MM.Info field that allows a function or subroutine to determine what line it was called from? Or if easier, what line it will return to? Or maybe this is already available?


You can use the MMDebug tool to do exactly that.    You can set a break point at the start of the function or subroutine and if you 'Step Out' you will see where it got called from.

Specifically...   To do the following:

1) Load the attached file onto your Pico
2) Load the program you are trying to debug
3) Type 'Run ctrl-D' to start program execution and break at the first line.
4) Scroll down to where ever the function or subroutine is defined.
5) Click on the white line number of the first logic line in the function or subroutine.
6) The program will start executing and when that first line of the function or subroutine is about to be executed, the program will break into the debugger.
7) Click on 'Step-Out' to see where the code got called from.



MMDebug.zip
Edited 2024-01-02 08:00 by EDNEDN
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6792
Posted: 10:45pm 01 Jan 2024
Copy link to clipboard 
Print this post

Ah, the old GOTO and COMEFROM thing. :)

Not a great idea as it has to modify the return stack to take the original value off. That would be hell if subroutines are nested.

A FUNCTION is just that - it isn't a true call to a subroutine so you can't return to a different point as there isn't one.

You can't return to a different point from a SUB any more than you could with a GOSUB. You need to get round it by storing a return point or code in a global then using GOTO, which is nasty.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 479
Posted: 11:07pm 01 Jan 2024
Copy link to clipboard 
Print this post

Mixtel

I think what vegipete is asking for is something like the stack trace, that is very common in any modern language and helps so much debugging hude code, such as the game I'm working on. Sametimes it's a pain to find the issue after a long call stack
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 11:19pm 01 Jan 2024
Copy link to clipboard 
Print this post

The original request could probably be covered with TRACE.
TRACE already exists in MMBasic

Jim
VK7JH
MMedit   MMBasic Help
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1109
Posted: 01:44am 02 Jan 2024
Copy link to clipboard 
Print this post

TRACE would probably work in most cases although in my particular case, I don't necessarily want to stop the program running.

EDNEDN, your MMDebug looks fantastic - I just haven't tried it yet.  It's not immediately obvious which version firmware you used, and if it is VGA.

================
My 'development' setup:

Teraterm and Notepad++ are open on a PC. (PicoMiteVGA user manual too.)

PicoMiteVGA connected to its own VGA monitor, and via USB to PC. Input devices are connected to the PicoMiteVGA too (Wii Classic Pro at the moment.)

I do my heavy editing in Notepad++ and autosave paste it through Teraterm to the Picomite. Simple edits get done directly on the PicoMite and copied back into Notepad++.

This way, I can run the program and look at it at the same time. Usually I don't need to stop the program to find my logic errors. Print statements sent to Teraterm let me watch stuff and compare to the listing.

Hence the 'stack trace'-ish request above. (Thanks Leo for the name.) Then a subroutine could print out where it was called from, so I could check how it got the data it did.
Visit Vegipete's *Mite Library for cool programs.
 
EDNEDN
Senior Member

Joined: 18/02/2023
Location: United States
Posts: 118
Posted: 02:11am 02 Jan 2024
Copy link to clipboard 
Print this post

  vegipete said  
EDNEDN, your MMDebug looks fantastic - I just haven't tried it yet.  It's not immediately obvious which version firmware you used, and if it is VGA.


It is currently based on PicoMite-v5.8rc19 but it can be moved to whatever version is desired.   There are only a couple hooks into the PicoMite code and they are pretty benign.

I don't have a Pico with VGA yet.  I don't have a way to verify the build worked.   But if you want to try the above instructions with a version built to support VGA, you can try the attached file.   (And if you do...   Please let me know if it works!)



MMDebug-VGA.zip
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 02:37am 02 Jan 2024
Copy link to clipboard 
Print this post

Simply put:
trace list 5

at the beginning of the sub/function of interest.

You could wrap it in a debug control
If doDebug then Trace List 5
(any number of lines - 5 is an example.)

Your program will run normally and the last 5 (or what ever) will get spat out the console.
[479][68][69][70][116]


What more do you need?

Jim
VK7JH
MMedit   MMBasic Help
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 02:58am 02 Jan 2024
Copy link to clipboard 
Print this post

  TassyJim said  If doDebug then Trace List 5


Sweet. I've used TRACE LIST often when a program has errored out, but didn't realize that you could use it in a program.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1109
Posted: 06:17am 02 Jan 2024
Copy link to clipboard 
Print this post

  Quote  What more do you need?

Just the knowledge that that is possible. Thank you!

The only problem is it doesn't work on my PicoMiteVGA. The output is only "[200]" repeated as many times as I requested.

Experimenting further, the line number [200] changes if I add a bunch of lines at the start of the program. And the indicated line is:
  Sprite memory s,20+act(i,3),21+act(i,4),0  ' black is transparent

So TRACE LIST n is mostly reporting only that particular line, although I see that it occasionally spits out a possible real line being processed.

Testing further, TRACE LIST n mostly seems to report the line of the first use of the "SPRITE MEMORY" command. This sounds related to the bug Matherp found a while back related to data statements after a sprite command.

edit: PicoMiteVGA MMBasic Version 5.07.08RC21
Edited 2024-01-02 16:18 by vegipete
Visit Vegipete's *Mite Library for cool programs.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024