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 : Debugging MMBasic
Author | Message | ||||
Fredd Newbie Joined: 26/09/2023 Location: South AfricaPosts: 4 |
I am busy translating a program of about 3000 lines originally written for mikroElektronica Pic Basic to MMBasic. It was neccesary to do this because the Pic Basic maths was not accurate enough. Truncated to 5 decimal palaces. I have used an in circuit debugger with the Pic for many years so now, with the MMBasic interpreter, I am finding it difficult to identify where my program hangs up if there are no error messages. I have resorted to making a guess where the bug may be and then displaying the line numbers with the Print command. Is there a debugger of some sort available for MMBasic. There has to be a better way! Hardware is a RPi Pico connected to a windows 10 PC. MMEdit V5.0.3 |
||||
IanRogers Senior Member Joined: 09/12/2022 Location: United KingdomPosts: 151 |
I had a glitch the other day. I ran a program that bombed out unexpectedly I had no idea, but when I ran EDIT The cursor was on the culprit so it helped me to find the issue. Not saying it'll work for you, but its there. Other than that, setup a serial monitor and print details to an external terminal. I'd give my left arm to be ambidextrous |
||||
flip Senior Member Joined: 18/07/2016 Location: AustraliaPosts: 114 |
Hi Fredd and welcome. There is also TRACE LIST command which shows last 128 or so line numbers Regards Phil |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Welcome to the 'Shed, Fredd. :) If using the built-in editor, if you re-enter it after a crash (F4 is a shortcut) the cursor is at the beginning of the line where the crash happened. Adding PRINT statements will send info to the console. For something like a Micromite that would be the TXD and RXD pins used for programming. An ICD is probably pointless when you are working with an interpreter as there is no way of knowing what you are looking at. Edited 2023-09-27 00:29 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
What flip said: TRACE LIST n is a friend ("n" is the number of line numbers you want to list). You can also print your program variables after a crash which returns you to the ">" prompt, like "? i,j,k,a,b,c. You can see if variables have unexpected values. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 393 |
I debug large programs in several ways: First, I always start the main program with 'open "debug.txt" for output as #1' Then any time I need to look at something debug-wise, I just add the print #1 line to dump whatever is relevant. This is always more to the point than just doing a trace. Second, I write 'debug' subroutines that can print out larger chunks of data to the debug file whenever needed, typically arrays. Third, I always structure my code with lots of subroutines and functions. These are generally short and easy to debug separately. I wish we had a unit test facility like junit but I typically roll my own by writing testbed code for some of the gnarly parts of the program early on. Fourth, I include traps for the "it can't possibly happen' situations where, if the 'impossible' happens, it will cause an invalid array index or even worse, a valid index that writes garbage into a critical array. Fifth, I have lots of 'const' values at the top of the program. Making a named value a constant protects it against unwanted changes and also makes program maintenance easier since if some constant value has to change, it only needs to change in one place. This also makes the program easier to understand if I or somebody else has to read the code months later. I'm sure there are other good techniques, but these are mine. -Bill |
||||
Fredd Newbie Joined: 26/09/2023 Location: South AfricaPosts: 4 |
Hi Everyone Thank you for your very useful replys. I have been away since I posted hence the delay in replying. This is definately the fastest and on the point reply I have had on any forum. Its many years since I used Gwbasic so I had forgotten Trace and List. Also I never had the pleasure of having a file system to save things. (used 80C32 with BASIC52 before the PICs) Many thanks for some new ideas. Regards Vaughn |
||||
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1114 |
Edited 2023-10-06 18:16 by Martin H. 'no comment |
||||
Print this page |