PASM and SPIN debug with Zero Footprint
Cluso99
Posts: 18,069
Zero Footprint - eat your heart out Hippy · (just kidding - great to get groups together for lateral thinking !)
I wouldn't have thought about placing the code in the shadow ram, but for your (Hippy's) code.
See PASM debug with just one long !·· http://forums.parallax.com/showthread.php?p=747204
Also see Debug SPIN and ASM - LMM style· http://forums.parallax.com/showthread.php?p=743062
This is how it works...
The first 3·long of the cog are copied out before loading from hub and replaced with a little bootstrap. When the cog is loaded this bootstrap copies 4 longs into the cog shadow ram at $1F0-1F3 and then jumps to $1F0 to execute.·This executes a micro-LMM kernel in hub ram (4 longs + 1 long for variable space) - this must be located in hub ram at and below $1FF.
Spin code controls the micro-LMM kernel. The spin firstly replaces the first 3 longs in the cog which had held the temporary bootstrap.
Now spin can control and execute any single-stepping, debugging, reading or writing to the cog as desired.
I still believe that the debug code can reside in LMM (rather than a seperate cog running spin). However, that will have to wait for another day.
I use the FullDuplexSerial object modified to FullDuplexSerial2.spin - it has out(txbyte) equivalent to tx(txbyte) and PST. This makes it easier to change to the TV object that Hippy uses.
The spin debug code is only proof of concept and will require further work. Enjoy
@Hippy: Is the copyright message as you want it??? I would rather acknowledge you directly.
Postedit: See the latest post(s) for the latest code release.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Prop Tools under Development or Completed (Index)
http://forums.parallax.com/showthread.php?p=753439
My cruising website http://www.bluemagic.biz
Post Edited (Cluso99) : 1/10/2009 8:58:23 AM GMT
I wouldn't have thought about placing the code in the shadow ram, but for your (Hippy's) code.
See PASM debug with just one long !·· http://forums.parallax.com/showthread.php?p=747204
Also see Debug SPIN and ASM - LMM style· http://forums.parallax.com/showthread.php?p=743062
This is how it works...
The first 3·long of the cog are copied out before loading from hub and replaced with a little bootstrap. When the cog is loaded this bootstrap copies 4 longs into the cog shadow ram at $1F0-1F3 and then jumps to $1F0 to execute.·This executes a micro-LMM kernel in hub ram (4 longs + 1 long for variable space) - this must be located in hub ram at and below $1FF.
Spin code controls the micro-LMM kernel. The spin firstly replaces the first 3 longs in the cog which had held the temporary bootstrap.
Now spin can control and execute any single-stepping, debugging, reading or writing to the cog as desired.
I still believe that the debug code can reside in LMM (rather than a seperate cog running spin). However, that will have to wait for another day.
I use the FullDuplexSerial object modified to FullDuplexSerial2.spin - it has out(txbyte) equivalent to tx(txbyte) and PST. This makes it easier to change to the TV object that Hippy uses.
The spin debug code is only proof of concept and will require further work. Enjoy
@Hippy: Is the copyright message as you want it??? I would rather acknowledge you directly.
Postedit: See the latest post(s) for the latest code release.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Prop Tools under Development or Completed (Index)
http://forums.parallax.com/showthread.php?p=753439
My cruising website http://www.bluemagic.biz
Post Edited (Cluso99) : 1/10/2009 8:58:23 AM GMT
Comments
You did exactly what I'd asked but not what I'd intended - "Copyright : 2008, (undisclosed third party) - original code". The intent was to make you change the AiChip filename prefix ( as you did ) and remove any impression derivatives come from AiChip ( as you have ), but I hadn't intended that to stretch to deleting the original author credit
I'll think about re-wording. Thanks for pointing it out.
@Hippy: How is this copyright message? PM me if you'd·prefer something else.
Postedited - sample of debug output...
Enjoy
Post Edited (Cluso99) : 9/4/2008 12:46:14 AM GMT
Back to my interpreter tomorrow, before the .... hits the fan on Friday !
I have had great fun with this exercise. I have code (untested) which debugs the interpreter (spin) and single-steps the cog using LMM style code in the same cog. It's a little tricky to code but will ultimately save a cog. I think I will lave most of this for another day and oncentrate on what I have.
Did I say, OP_SHR_IWCNR and OP_SHR_IWZNR needed the cond bits set to execute.
I am trying to start the Interpreter only once to run the spin test code. I spent a lot of time before I realised that I had multiple copies running, all debugging with conflicting parameters.
In using the technique to debug the LCC VM I'm finding I'm not really using it to its full potential. I'm breaking on every bytecode fetch and displaying stack so it's easier to push a value to stack where I'm interested in what's happening, jump to the Fetch loop and look to see what is at TOS.
This way of working is down to not having an easy way to interact with the debugger. To be really usable it needs a 'command shell' wrapper so this looks like a great way forward.
I'd suggest one possible improvement ( saves an extra cog ); rather than use FDX, as you're only transmitting when you've hit a breakpoint ( only the micro-LMM debugger is running ), temporarily replace some code in the cog being debugged with a bit-banged transmit serial byte routine and use that for transmit. As you'll only need to receive characters ("S" etc ) once data has been displayed you can temporarily add a receive routine in the same way. With a bit of clever working you should be able to get the receive doing single byte rx buffering while processing the last and be able to tell it to stop and return to the micro-LMM debugger when you need to continue. Don't forget to save and restore the state of C and Z !
I didn't want to change the FDX object as it is fairly simple to put your TV object back in (or probably VGA for that matter). It keep flexibility for others. However, I am sure I can do this inside the cog being debugged by using LMM later. I have written a fair bit of the routine but not the decoding (which you and· have done in spin).
Spin Debugger
You have found the same as me, you need to look at the stacks after an instruction executes. That is my task at the moment so that I can verify the Interpreter. I am going to use the new zero footprint version and add my debuging from my LMM code.
I am a little stumped on launching just 1 version of the Interpreter running the spin test code, without is replacing all versions of the Interpreter. Need to sit back and think a bit more.
Debugger (Spin & PASM)
Command structure... I was thinking something like...
On launch, asking if "S"pin or "A"sm. Then the debugger nows what format to use.
nnnT = Trace nnn instructions/bytecodes (nnn defaults to 1)
nnnS = Skip·· nnn instructions/bytecodes (nnn defaults to 1)· i.e. no display
BxxxxxxxxT = Run until breakpoint with Trace (xxxx hex = cog·address for instructions / hub address for bytecodes)
BxxxxxxxxS = Run until breakpoint with·Skip· ·(xxxx hex = cog address for instructions / hub address for bytecodes)
Dxxx,nnC······ ·= displays cog data at address xxx,······· nn longs (xxx hex, nn decimal)
Dxxxxxxxx,nnH = displays hub data at address xxxxxxxx, nn longs (xxx hex, nn decimal)
Mxxx,yyyyyyyyC······· = modifies cog data at address xxx······· to yyyyyyyy· ·(xxx and yyyyyyyy·hex)
Mxxxxxxxx,yyyyyyyyH = modifies hub data at address xxxxxxxx to yyyyyyyy· ·(xxx and yyyyyyyy·hex)
Any thoughts anybody ??
It uses Zero Footprint in the PASM code. Here are the commands and output sample. I believe it all works, so please report any bugs.
Just place your PASM code at the end of the file and use PST to communicate with the debugger. The debugger waits for PST to send a character (while outputting a message). Then the screen is cleared and the command set is displayed.
Special thanks to Hippy for all his original work, especially the idea to use the cog shadow ram
Now to add spin debugging to debug my Faster Ram Interpreter.
Enjoy
PS If you want to use the TV object for display, just add·a routine·"tv.tx" to the tv object, add the tv pin, and it·should work -·you will need to cater for the keyboard though.
Update:
I've been thinking about the command structure. Any suggestions would be appreciated (no promises).
These are things to I'd like to implement:
Hub memory dump
Cog memory dump
Modify cog memory
Modify hub memory
Jump cog address (changes execution)
Restart cog
Spin debugging (already working, just need to shoehorn it in here, and add some features)
Maybe 'Enter' should repeat the last command.
Maybe the following format XxxxxZ and nnnnZ where X indicates xxxx is a hex address; nnnn is a decimal number; Z is the command which cannot be A..F (hex numbering), X (prefix for hex) ??? Note this conflicts with my current implementation but that's not a problem yet.
Post Edited (Cluso99) : 9/8/2008 2:46:54 PM GMT
Yes, return only repeating last command is nice for command line. Of course you will need a GUI some day.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Since PASM code is self-modifiable, the only way to have multiple breaks is by checking as each instruction is executed which is doable. Stepover doesn' have the same meaning in PASM (especially without source access) but it would be possible to run until a jmp/tj../dj.. is executed (presume not taken).
It doesn't faithfully reproduce the feature Hippy mentioned whereby he modifies the next instruction knowing it will have been fetched before it gets written.
I am not intending to do a GUI. I'll leave that for someone else. Currently you can use any serial program (as long as it doesn't reset the Prop by DTR). It is also simple to modify the code to use TV or VGA output - not sure about the keyboard drivers, but should be fairly easy. One step closer to standalone operation
Break line really means break address for PASM. Not sure a spin debugger would be very usable without line info although one could reverse engineer the bytecode to determine the source line in run-time. BradC had a nice listing showing some spin source lines content.
I forgot the "Until" command which would step until the current address is passed ... good for loops [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
I now have it·tracing the spin interpreter
See What are your cogs doing ? http://forums.parallax.com/showthread.php?p=749977
I did not use it though, I have no love for the serial interface ( ), so I use my simulator. But all these tools may become handy some unexpected day !
Here is the output of the Spin section of the debugger (still being tested and refined). You can turn the Pasm and the Spin on/off seperately, so the trace can be mixed. The RamInterpreter is required.
Convenience is just another reason to have a GUI. All IDE: MSVC++, Eclipse, Visual·*blah* have step buttons... All GUI except Ariba's PASD that is··.· Most IDE GUIs take your frustration one-click-step-away.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
What kind of "style annoyances" do you mean?
One seams to be: No Toolbar with Step buttons. - This can be added very easy! I've not done it, because I always use Shortkeys for single stepping, also in VB, VisualC ....
The 12 longs for the Debugger kernel was never a problem in my Assembly codes, I never filled a cog to its limits.
To debugging a complicate LMM kernel or a Spin kernel, PASD is shurely not the right tool.
If mpark add a listing output, and perhaps some debug support to his 'Homespun Spin compiler" much better debuggers will be possible in the future!
Andy
I originally tried your PASD on the RamInterpreter. I made room for the 12 longs, but that didn't help because I didn't have control for the fact I had multiple cogs running the same code.
In the end I wrote my own, which just used the PST, and used a LMM model to spit out the debugged code (spin bytecode tracing). I did this in 6 longs and could be anywhere in the cog. Then I expanded it to use 8 longs for PASM debugging and Hippy took up the challenge to reduce it. He put it in the shadow ram and ended up using 1 long but it had to be $1EF which caused problems with the Interpreter. I found a way to make it all fit in 4 longs in the shadow ram $1F0-1F3.
I wasn't interested in writing the GUI, so I just used PST. (I did a lot of VB4-6 work in the 90's but really haven't done much in the last 6 years).
If you want, I am sure you could merge your code and mine (and Hippy's) for zero footprint. Mpark is doing a lot of work with his compiler and Hippy with PropList. Hopefully we can make these function together for a combined set of tools.
I have it debugging spin as well (on the fly you can flip in/out of pasm) so you can see what·the bytecode really does. I need this for·debugging my RamInterpreter.
The command structure is still evolving.
PS. Unfortunately, my time comes in bursts, which means I have to·go back to where I left off and remember what I have done/tested and what I have not. I modified the RamInterpreter heavily (without hardware to test) and now it doesn't work I am looking for a needle in a haystack. My debugger is helping with that.
Post Edited (Cluso99) : 9/10/2008 2:28:30 AM GMT
There are 3 files in the example.
ClusoDebuggerDemoSpin3.spin is the top object and requires the code at the beginning to be present and unmodified. This is also where the user's spin·code to be debugged goes.
ClusoDebuggerSpin3.spin is the next object and is a self contained file which is called by the top object to launch and configure the debugger.
ClusoDebugger.spin is the actual debugger which is called and will launch itself in a separate cog. This·object·is used for both pasm and spin debugging.
ClusoDebuggerSpin.spin and subsequently ClusoDebugger.spin launch the FullDuplexSerial object in a separate cog. Only one FDX object is present at a time.
Currently there is an issue with the PAR register values being returned, giving what I think is an incorrect usage of the stack. This requires further investigation.
User debugging will need to be done in conjunction with the spin source code. PropList and PropView provide·extra·information of user source code. When the homespun compiler has a listing available, this will be a great aid also. The debugger does not provide a bytecode translation.
"P" toggles pasm output on and off. This means that you can actually see the Interpreter executing the bytecode interpretation.·"O"·toggles spin output on and off. "T" traces and "S" traces (without display) nnnn instructions. The enter key is equivalent to "T". Upper and lower case·are interchangable, except for c and z which can be used to force condition code changes in pasm. No hub instructions (coginit, locknew, etc have been tested. There is a summary of most keys in the display. (I am not happy with the key assignments, so this may change is later releases)
Enjoy (and please report any bugs)
Update:
See the posts below for updated version v0.275. Note the new version is incompatable with that posted here, so I have removed these attachments.
Included in the posts below is an alternative method to trace spin code using·the RamInterpreter instead of the Rom version.
Post Edited (Cluso99) : 9/23/2008 2:39:02 AM GMT
There are 3 modes of debugging:
-1: PASM
-2: SPIN (uses RamInterpreter) Limited to tracing cog 7; sqrt function is disabled.
-3: SPIN (interrupts existing RomInterpreter) - [noparse][[/noparse]See next post for code v0.275 - See previous post·v0.270S for more information]
Sample output of spin trace (including partial pasm trace of Interpreter)...
I noted while doing a trace of coginit bytecodes, that in preparing for the call, spin code executes from hub ROM $FFFC, then lower FF70-FFF4 code. This code presets the parameters on the stack (pbase, vbase, dbase, pcurr, dcurr). It seems like it is the 'Runner Code' that Chip spoke about - I thought it was a bug.
Post Edited (Cluso99) : 9/23/2008 2:44:37 AM GMT
See my post 9/21/2008 2:49 AM (GMT +10) for more information on this mode of operation.
Uses the·common debug object·used for both PASM & SPIN (see previous post for ClusoDebugger_275.spin)
WARNING: Mode -3 uses a differently configured Debug_Block to modes -1 and -2.
Post Edited (Cluso99) : 9/23/2008 2:50:31 AM GMT
I use the listing output from the Homespun compiler.
Spin debugging will be singlestep or by breakpoints. The debugger can break down the spin debugging into pasm debugging when desired.
I see your debugger as a great plug-in for Praxis Developer Studio (both of you use the same compiler: wonderful).
Do you think it's possible ?
Cheers
When I've finished I will just need to make it a dll.
There is some confusion about how my debuggers work, so here goes - let me know if there is something you do not understand.
Attached is the latest debugger for spin (all files required are included).
ClusoDebuggerDemoSpin_275.spin
This is the Top Level file. It contains YOUR spin code to be traced/debugged - just replace the section "PUB TestSpin" with your code.
Your code is loaded by the CogInit instruction a few lines above.
Your code is in a PUB called "TestSpin", uses a stack called "priStack" and has been defined as $40 in length. If you need more, change it.
Note: Your code MUST run in Cog 7 because the RamInterpreter has been modified to only use Cog 7.
ClusoDebugger_276.spin
This is my debugger (written in spin). It uses FullDuplexSerial.spin to communicate with PST (Parallax Serial Terminal) using the serial downloader on pins 30 & 31 at 115,200 baud. It is the same code as used in my·Pasm debugger.
FullDuplexSerial.spin
Used by the ClusoDebugger described above.
RamInterpreter1_275.spin and RamInterpreter2_275.spin
These are Ram versions of Chip's Interpreter with minor modifications to force the RamInterpreter2 to be loaded if Cog 7, else load the RamInterpreter1. The SQRT function has been disabled in both versions·(for space to perform the RamInterpreter load section). The two versions have a minor difference to force the compiler to think they are different. Otherwise the compiler will optimise (removing one copy).
Operating Instructions
1. Compile and load "ClusoDebuggerDemoSpin_275.spin" (set as Top Object) using PropTool
2. Run PST (check it uses the same port as PropTool and is set to 115,200 baud)
3. You should see the (repeating) message "ClusoDebugger: Press Enter to start."
4. Press "Enter" (or any key) to start
5. You should now see the Instructions displayed on the PST screen.
(I don't recall BxxxS and BxxxT working·- I haven't unpacked my Prop since returning from holidays to test it.)
These commands should be fairly self-explanatory. If you wish to see the Pasm instructions being executed by the RamInterpreter for each spin bytecode, type "P" to toggle the pasm debug on and off. A counter displays the instruction numbers being executed, so you can see how many pasm instructions have been executed for each spin bytecode executed.
Note:
If you compile using the Homespun compiler, you will see the spin bytecodes in the listing. These will equate to the spin instructions executed in the ClusoDebugger.
I have a crude VB program which works with the debugger and the homespun listing to highlight the spin bytecodes as they are executed. If anyone is interested in programming·the VB code, please PM me. I don't mind doing any changes in the debugger required, but currently I don't have the time to do the VB.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Prop Tools under Development or Completed (Index)
http://forums.parallax.com/showthread.php?p=753439
My cruising website http://www.bluemagic.biz
Post Edited (Cluso99) : 1/10/2009 8:51:12 AM GMT
There is some confusion about how my debuggers work, so here goes - let me know if there is something you do not understand.
Attached is the latest debugger for·PASM (all files required are included).
ClusoDebuggerDemoPasm_275.spin
This is the Top Level file. It contains YOUR·Pasm code to be traced/debugged - just replace the DAT section "PasmCode" with your code.
Your code is loaded by the CogNew instruction a few lines above.
ClusoDebugger_276.spin
This is my debugger (written in spin). It uses FullDuplexSerial.spin to communicate with PST (Parallax Serial Terminal) using the serial downloader on pins 30 & 31 at 115,200 baud. It is the same code as used in my Spin debugger.
FullDuplexSerial.spin
Used by the ClusoDebugger described above.
Operating Instructions
1. Compile and load "ClusoDebuggerDemoPasm_275.spin" (set as Top Object) using PropTool
2. Run PST (check it uses the same port as PropTool and is set to 115,200 baud)
3. You should see the (repeating) message "ClusoDebugger: Press Enter to start."
4. Press "Enter" (or any key) to start
5. You should now see the Instructions displayed on the PST screen.
(I don't recall BxxxS and BxxxT working·- I haven't unpacked my Prop since returning from holidays to test it.)
These commands should be fairly self-explanatory.·A counter displays the instruction numbers being executed.
Note:
If you compile using the Homespun compiler, you will see the·instructions in the listing. These will equate to the Pasm instructions executed in the ClusoDebugger.
I have a crude VB program which works with the debugger and the homespun listing to highlight the Pasm instructions as they are executed. If anyone is interested in programming·the VB code, please PM me. I don't mind doing any changes in the debugger required, but currently I don't have the time to do the VB.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Prop Tools under Development or Completed (Index)
http://forums.parallax.com/showthread.php?p=753439
My cruising website http://www.bluemagic.biz
I can see pasm listings which is great. Wasn't there a program that could associate the byte-codes with spin source from BradC (or someone)? Maybe I just dreamed seeing that, but I remember Hippy being impressed.
Ok, got it now using brad's bstc:
From here it would be quite easy to create a spin-step debugger GUI thanks to your and BradC's excellent work.
So break-points are broken?
Thanks a bunch.
BTW was the first hard disk drive bigger than a washing machine? I remember having to carry ~15" disk packs around for CDCs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Post Edited (jazzed) : 1/10/2009 6:39:40 PM GMT
Great work with the steps to produce a listing with BradC's bstc. As I said, I started a VB program to step through the listing with the debugger. It works for both Pasm and Spin (VB6 and VB2008) but I haven't found a nice way of displaying the listing for stepping. In VB6 I used the TextBox and could highlight the line as it stepped. Similarly in VB2008 I used another control (can't remember as this is the only code I have done on VB2008). However, it requires a control (maybe a grid) so that you can click to show a breakpoint (like VB). When the code hits a breakpoint the VB would recognise this and stop the debugger (the debugger would always be in single-step mode and the VB would just be saying proceed to the next instruction).
Homespun's listing was good for the spin code trace. I haven't looked at Brad's listing lately. Would you like to post the listing of ClusoDebuggerDemoSpin_275 ?
OT: The drives of the 70's were typically 19" platters. A 10MB was 6 high, 10 heads and 11 high, 20 heads were 40MB. In 1976 a 10MB drive cost A$16,000. The drives were about the size of a typical washing machine. They required the heads to realigned by engineers at least every 3 months. I used to teach engineers to take a machine (disc drive) to pieces and build it back up.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Prop Tools under Development or Completed (Index)
http://forums.parallax.com/showthread.php?p=753439
My cruising website http://www.bluemagic.biz