maziac / DeZog

Visual Studio Code Debugger for Z80/ZX Spectrum.
MIT License
212 stars 35 forks source link

[Feature Request] Watch struct support #37

Closed howprice closed 3 years ago

howprice commented 3 years ago

Would it be possible to enhance the WATCH window to allow structured data to be conveniently visualised? The end result would be like viewing a struct or array of structures when debugging C in Visual Studio.

Currently for watches you can tell DeZog the number of elements to show and if it should show bytes, words or both. The format is:

label,size,types

with

It would be very helpful for debugging if

For example:

        STRUCT Hitbox
x0      BYTE 0  ; min X
x1      BYTE 0  ; max X (inclusive)
y0      BYTE 0  ; min Y
y1      BYTE 0  ; max Y (inclusive)
        ENDS

        STRUCT Invader
active                  BYTE
type                    BYTE
pSpriteAttributes       WORD    ; address of sprite attributes
hitboxScreenSpace       Hitbox
        ENDS

INVADER_COUNT EQU 55
invaders DS INVADER_COUNT*Invader

When assembled with sjasmplus this produces in the .lst file (or .lables file if sjasmplus --lstlab option used)

0x0008   Invader
0x0000   Invader.active
0x0001   Invader.type
0x0002   Invader.pSpriteAttributes
0x0004   Invader.hitboxScreenSpace
0x0004 X Invader.hitboxScreenSpace.x0
0x0005 X Invader.hitboxScreenSpace.x1
0x0006 X Invader.hitboxScreenSpace.y0
0x0007 X Invader.hitboxScreenSpace.y1

As a first pass, if the label 'invaders' watched, the user could specify invaders,55,8b which would display the memory in groupings of 8 bytes.

v WATCH
  v invaders,55,8b
    v 8b: [0,54]
      v [0]
           [0]: 00h
           [1]: 00h
           [2]: 00h
           [3]: 00h
           [4]: 00h
           [5]: 00h
           [6]: 00h
           [7]: 00h
      v [1]
           [0]: 00h
           [1]: 00h
           [2]: 00h
           [3]: 00h
           [4]: 00h
           [5]: 00h
           [6]: 00h
           [7]: 00h
      > [2]
      > [3]
      > [4]
      ....
      > [54]

Better still, if the Watch window could access types from the lst, it would know the size of the Invader struct and the array size, so the user could enter invaders,INVADER_COUNT,Invader

v WATCH
  v invaders,INVADER_COUNT,Invader
    v Invader: [0,54]
      v [0]
           [0]: 00h
           [1]: 00h
           [2]: 00h
           [3]: 00h
           [4]: 00h
           [5]: 00h
           [6]: 00h
           [7]: 00h
      v [1]
           [0]: 00h
           [1]: 00h
           [2]: 00h
           [3]: 00h
           [4]: 00h
           [5]: 00h
           [6]: 00h
           [7]: 00h
      > [2]
      > [3]
      > [4]
      ....
      > [54]

Ideally, the Watch window would parse the list file to allow the individual element struct members to be shown with the name and type:

v WATCH
  v invaders,INVADER_COUNT,Invader
    v Invader: [0,54]
      v [0]
         active: 00h
         type: 00h
        pSpriteAttributes: 0000h
        v hitboxScreenSpace
          x0: 00h
          x1: 00h
          y0: 00h
          y1: 00h
      v [1]
        active: 00h
        type: 00h
        pSpriteAttributes: 0000h
        v hitboxScreenSpace
          x0: 00h
          x1: 00h
          y0: 00h
          y1: 00h
      > [2]
      > [3]
      > [4]
      ....
      > [54]

I appreciate that this might not be possible, but it would make a huge difference to the quality of the debugging experience.

maziac commented 3 years ago

That's a valid request. I have been thinking already how something like this could be done. I think there are some good ideas in your request. I will have a look when I get some time. The problem is that I need to find a solution that will also work with other assemblers, at least to some extend.

howprice commented 3 years ago

Great. I'm afraid I am not familiar with any other assemblers or your codebase (or Typescript) so I can't appreciate the implementation details.

maziac commented 3 years ago

Here is a pre-release with the enhanced WATCH feature. You can test if you like. https://github.com/maziac/DeZog/releases/tag/v2.1.0 (Don't forget to update the CSpect DeZog plugin as well). If you migrate from DeZog 1.5 please read the Migration.md as well.

howprice commented 3 years ago

Hi. Thanks for the pre-release. I have installed the VSIX in Visual Studio Code 1.52.1 (Windows 10) and placed the new DLL next to CSpect exe (V2.13.00), but I do not see the same behaviour as the animations in the Watches section of the documentation when testing with my public repo https://github.com/howprice/specnext-invaders

Only a single element is visible:

image

Please let me know if you need any more information to debug this.

EDIT: In fact the original behaviour seems to be broken

image

maziac commented 3 years ago

Sorry. Here is the fix: https://github.com/maziac/DeZog/releases/tag/v2.1.1

howprice commented 3 years ago

Thanks. I've just had a quick play. It is working for the Invader and InvaderBullet struct, but the Player struct seems to be causing a problem:

image

image

maziac commented 3 years ago

Could you provide the zipped project or a down stripped version.

howprice commented 3 years ago

specnext-invaders.zip

EDIT: NEX and lst/sld in the bin/ folder

maziac commented 3 years ago

This should do it: https://github.com/maziac/DeZog/releases/tag/v2.1.2

Thanks for beta testing :-)

howprice commented 3 years ago

No problem at all. I was seriously considering learning Typescript to implement this. Thanks very much for taking this on.

The latest release seems to handle all of my structs, so I'm very happy thank-you.

Please don't interpret this as feature creep, but should the values be editable in the Watch window or just viewable?

maziac commented 3 years ago

vscode does not allow editing of variables in the WATCH area. Also in other languages.

maziac commented 3 years ago

Just saw this: Thanks for the sponsorship !

howprice commented 3 years ago

vscode does not allow editing of variables in the WATCH area.

I wasn't aware of this! Quite a limitation.