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: CanadaPosts: 1109 |
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: AustraliaPosts: 2135 |
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 StatesPosts: 118 |
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 KingdomPosts: 6792 |
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: CanadaPosts: 479 |
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: AustraliaPosts: 6098 |
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: CanadaPosts: 1109 |
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 StatesPosts: 118 |
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: AustraliaPosts: 6098 |
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 StatesPosts: 3150 |
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: CanadaPosts: 1109 |
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 |