openMSX / debugger

31 stars 15 forks source link

Feature/vasm sym support #186

Closed gilbertfrancois closed 1 year ago

gilbertfrancois commented 1 year ago

This pull request adds support for symbol files for the VASM compiler.

Screenshot 2023-07-17 at 13 41 13

Below is a toy example of the source file and the VASM symbol file, parsed successfully as shown in the screenshot above.

ORGADR  equ $c000
CHPUT   equ $00A2
CHGMOD  equ $005f

    ; Place header before the binary.
    org ORGADR - 7
    ; Bin header, 7 bytes
    db $fe
    dw FileStart
    dw FileEnd - 1
    dw Main

    ; org statement after the header
    org ORGADR

FileStart:
Main:
    ld a, 0
    call CHGMOD

    ld hl, helloWorld
    call PrintStr
    call NewLn
    call Finished

PrintStr:
    ld a, (hl)
    cp 0
    ret z
    inc hl
    call CHPUT
    jr PrintStr

NewLn:
    push af
    ld a, 13
    call CHPUT
    ld a, 10
    call CHPUT
    pop af
    ret

Finished:
    ret

helloWorld:
    db "Hello world!", 0

FileEnd:
Sections:
00: "segbff9" (BFF9-C000)
01: "segc000" (C000-C036)

Source: "01_helloworld/helloworld.bin.asm"
                                 1: ORGADR  equ $c000
                                 2: CHPUT   equ $00A2
                                 3: CHGMOD  equ $005f
                                 4:  
                                 5:     ; Place header before the binary.
                                 6:     org ORGADR - 7
                                 7:     ; Bin header, 7 bytes
00:BFF9 FE                       8:     db $fe
00:BFFA 00C0                     9:     dw FileStart
00:BFFC 35C0                    10:     dw FileEnd - 1
00:BFFE 00C0                    11:     dw Main
                                12: 
                                13:     ; org statement after the header
                                14:     org ORGADR
                                15: 
                                16: FileStart:
                                17: Main:
01:C000 3E00                    18:     ld a, 0
01:C002 CD5F00                  19:     call CHGMOD
                                20: 
01:C005 2129C0                  21:     ld hl, helloWorld
01:C008 CD11C0                  22:     call PrintStr
01:C00B CD1BC0                  23:     call NewLn
01:C00E CD28C0                  24:     call Finished
                                25: 
                                26: PrintStr:
01:C011 7E                      27:     ld a, (hl)
01:C012 FE00                    28:     cp 0
01:C014 C8                      29:     ret z
01:C015 23                      30:     inc hl
01:C016 CDA200                  31:     call CHPUT
01:C019 18F6                    32:     jr PrintStr
                                33: 
                                34: NewLn:
01:C01B F5                      35:     push af
01:C01C 3E0D                    36:     ld a, 13
01:C01E CDA200                  37:     call CHPUT
01:C021 3E0A                    38:     ld a, 10
01:C023 CDA200                  39:     call CHPUT
01:C026 F1                      40:     pop af
01:C027 C9                      41:     ret
                                42: 
                                43: Finished:
01:C028 C9                      44:     ret
                                45: 
                                46: helloWorld:
01:C029 48656C6C6F20776F        47:     db "Hello world!", 0
01:C031 726C6421
01:C035 00
                                48: 
                                49: FileEnd:
                                50: 

Symbols by name:
CHGMOD                           E:005F
CHPUT                            E:00A2
FileEnd                          A:C036
FileStart                        A:C000
Finished                         A:C028
helloWorld                       A:C029
Main                             A:C000
NewLn                            A:C01B
ORGADR                           E:C000
PrintStr                         A:C011

Symbols by value:
005F CHGMOD
00A2 CHPUT
C000 Main
C000 FileStart
C000 ORGADR
C011 PrintStr
C01B NewLn
C028 Finished
C029 helloWorld
C036 FileEnd
gilbertfrancois commented 1 year ago

Thank you for the fast merge.

m9710797 commented 1 year ago

Thanks for the patch! Also thanks for the very good explanation and the example symbol file. Very useful! It's a good fit for the current debugger. I've merged your PR (I haven't actually tried your code, but I trust you tested it well).

--

I'm not sure if you're aware (it's public information, but maybe not yet widely known): we're working on a new version of the debugger. One that is integrated in the openMSX executable itself. This makes many things much simpler, and it allows stuff like a real-time updated memory-view or disassembly-view. And for symbols: it allows to use symbols in Tcl expressions.

You can find this new debugger in the 'imgui' branch of the openMSX git repository. It's currently work on progress: it's starting to work well, but it still needs a lot of fine-tuning.

The symbol handling (including parsing symbol files) is handled in this file. It's taking a different approach compared to the current debugger. It's still an experiment, so we're evaluating the pros/cons of this new approach:

So unfortunately this means we can't easily port your patch from the current to the new debugger :(

Can I ask you some more information about the VASM compiler? (I hadn't heard of it before). Is this popular for MSX development? Can you tell more about your workflow?

Everything is fixable of course. We can extend the symbol parser in the new debugger with support for VASM. But I'd first like to learn a bit more.

m9710797 commented 1 year ago

FYI: I added support for multiple symbol file formats, including vasm, in the integrated openMSX debugger. It was on my TODO list for a long time, but I finally got to it.

gilbertfrancois commented 1 year ago

That is absolutely amazing! Thank you so much.