Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

bleubleu
Posts: 77
Joined: Wed Apr 04, 2018 7:29 pm
Location: Montreal, Canada

Re: Mesen Debugger - Feedback/Feature Requests? (2018 editi

Post by bleubleu » Wed Feb 13, 2019 7:05 pm

I might be running a build from 1+ month ago (whenever the last time you added me a feature!).
I will take a new nightly and give it a try.

-Mat

bleubleu
Posts: 77
Joined: Wed Apr 04, 2018 7:29 pm
Location: Montreal, Canada

Re: Mesen Debugger - Feedback/Feature Requests? (2018 editi

Post by bleubleu » Sun Apr 28, 2019 5:01 am

Hi!

I want to create myself some simple debugging Lua scripts to display the state of my hero, NPCs, etc. Is it possible to access debug info from Lua? This would avoid me having to hard-code addresses of stuff (which changes all the time during development).

Thanks!

-Mat

Sour
Posts: 795
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen Debugger - Feedback/Feature Requests? (2018 editi

Post by Sour » Sun Apr 28, 2019 6:25 am

In the latest dev builds, there's a "emu.getLabelAddress" function that returns an address that can be used with emu.read/write. See: https://github.com/SourMesen/Mesen/blob/master/Docs/content/apireference/MemoryAccess.md#getlabeladdress

And that's another reason why I really need to get around to releasing a new release and updating the documentation website. Not enough hours in a day, and not enough days in a weekend :p

bleubleu
Posts: 77
Joined: Wed Apr 04, 2018 7:29 pm
Location: Montreal, Canada

Re: Mesen Debugger - Feedback/Feature Requests? (2018 editi

Post by bleubleu » Sun Apr 28, 2019 7:12 pm

Haha. Thanks is brilliant! Thanks!

I'll give it a try soon. I think I can make myself a really kickass visual debugger for gameplay with that.

-Mat

Kurrono
Posts: 1
Joined: Wed Aug 23, 2017 8:49 pm

Re: Mesen Debugger - Feedback/Feature Requests? (2018 editi

Post by Kurrono » Thu Oct 24, 2019 5:40 pm

Is there a way to make the debugger the same way as bsnes... So when u write the registers for music to be detected before the music starts like using...

4100 using as breakpoint...to trigger the values in A,X,Y registers? Oh and by the way can u give me an explanation how Mesen audio msu1 routine is?

Bananmos
Posts: 496
Joined: Wed Mar 09, 2005 9:08 am
Contact:

Re: Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Post by Bananmos » Thu Apr 16, 2020 3:40 am

Pardon me if this is necro-bumping an old thread. But a feature I am really missing whilst debugging NES code is the ability to do asserts to check registers / memory values.

Adding them using macros to generate code is certainly an option, but it'll increase code size and potentially make branch labels out-of-range as well. It would be far more preferable to have a macro that only changes how the debugger reacts, rather than changing any code.

Seeing how Mesen's debugger already has the ability to:
1. Read CA65 source assembly / .dbg files and associate disassembly with source code
2. Set conditions for breakpoints

...I am thinking the ability to trigger conditional breakpoints based on comments should be relatively easy to add? :)

Something like this:

Code: Select all

ldx MyIndex   ; MESEN_DEBUG_ASSERT(X < 10) - check that index is in range
                     ; MESEN_DEBUG_ASSERT([MyPointer] >= $8000) - check that pointer references ROM

Sour
Posts: 795
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Post by Sour » Fri Apr 17, 2020 3:52 pm

Bananmos wrote:
Thu Apr 16, 2020 3:40 am
...I am thinking the ability to trigger conditional breakpoints based on comments should be relatively easy to add? :)
And you would be correct!

It's not really all fleshed out, but it only took about 15 lines of code to get something decent working:
mesenassert.png
Basically, it looks for a "assert(...)" comment in the code, and adds a (hidden) breakpoint with the opposite condition (so anything that's a valid mesen expression/condition can be added as an assert)
As is, this only works with CA65 integration, though. I should probably make it work with all comments (not just those imported by CA65), to allow this to work with asm6f, etc., too.

Fiskbit
Posts: 112
Joined: Sat Nov 18, 2017 9:15 pm

Re: Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Post by Fiskbit » Fri Apr 17, 2020 4:38 pm

Very cool feature. When the assert is on the same line as an instruction, does it check state before or after the instruction? When it's on its own line, does it check after the previous instruction and before the next one?

Sour
Posts: 795
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Post by Sour » Fri Apr 17, 2020 5:13 pm

At the moment it just adds a regular execution breakpoint on the first byte of the instruction - this is identical to clicking on the margin to add a breakpoint and then adding a condition to it. So, it checks the state before running the instruction.

This means you could also use this to add "regular" breakpoints in the source code: "assert(false)" or "assert(0)" will always cause a break. This might be more handy than using stuff like BRK since it doesn't affect execution. So code like:

Code: Select all

;assert(0)
STA $2000
or

Code: Select all

STA $2000 ;assert(0)
would always break before the STA instruction runs.

The logic is the same whether the comment is displayed on the side or above, the only difference here is that mesen displays multi-line comments above a line instead of next to it. In terms of CA65 integration, the source files are parsed and comments above a line (or on the right) are both associated to the same line of code.

Bananmos
Posts: 496
Joined: Wed Mar 09, 2005 9:08 am
Contact:

Re: Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Post by Bananmos » Sat Apr 18, 2020 6:18 am

Wow, what a quick response... and a feature implementation as well!

That already sounds like a great help in debugging... but to be complete for the use-case I'm thinking about, I think what's missing is the ability to use defined expressions from CA65 as conditions.

So that for example you can error-check your bounds by doing:

Code: Select all

MYARRAY:
.db $65, $02
MYARRAY_LENGTH = 2   ; (or possibly even: MYARRAY_LENGTH = * - MYARRAY)
[...]
LDY myIndex,x
LDA MYARRAY,y   ; assert(Y < MYARRAY_LENGTH)
I tried using a constant expression defined in CA65 as input to the breakpoint condition in the debugger, but it looks like it won't accept it.

TBH I could easily make my build system replace any _LENGTH variables found in the .dbg file with their assigned constants to get this feature working... but it sure would be neater to avoid that extra step, as it's already got too many layers of scripting :)

Sour
Posts: 795
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Post by Sour » Sat Apr 18, 2020 11:30 am

Bananmos wrote:
Sat Apr 18, 2020 6:18 am
I think what's missing is the ability to use defined expressions from CA65 as conditions.
With a bit of work, it can work for asserts for CA65:
assertconstant.png
It parses the comment, finds matching constants in the .dbg file and generates a breakpoint with the changed value (e.g Speed = 5 in this case)

Though since I want to generalize this to work for comments in general rather than just CA65, in the end the disassembly would show the comment as "assert(x == 5)" (e.g it would change the comment itself), but I think that's an acceptable compromise. This also wouldn't let you use CA65 constants in expressions (e.g breakpoints or the watch) - the C++ core has no knowledge that CA65 integration is even a thing, so adding something like this would require a lot of work.

Bananmos
Posts: 496
Joined: Wed Mar 09, 2005 9:08 am
Contact:

Re: Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Post by Bananmos » Sat Apr 18, 2020 12:46 pm

Sour wrote:
Sat Apr 18, 2020 11:30 am
Bananmos wrote:
Sat Apr 18, 2020 6:18 am
I think what's missing is the ability to use defined expressions from CA65 as conditions.
With a bit of work, it can work for asserts for CA65:
assertconstant.png
It parses the comment, finds matching constants in the .dbg file and generates a breakpoint with the changed value (e.g Speed = 5 in this case)

Though since I want to generalize this to work for comments in general rather than just CA65, in the end the disassembly would show the comment as "assert(x == 5)" (e.g it would change the comment itself), but I think that's an acceptable compromise. This also wouldn't let you use CA65 constants in expressions (e.g breakpoints or the watch) - the C++ core has no knowledge that CA65 integration is even a thing, so adding something like this would require a lot of work.
That does sound like a fair compromise. :)

And much thanks for pursuing this - it'll save me a ton of time debugging!

Will a build supporting it eventually pop up here?

Sour
Posts: 795
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Post by Sour » Sat Apr 18, 2020 3:29 pm

Bananmos wrote:
Sat Apr 18, 2020 12:46 pm
Will a build supporting it eventually pop up here?
The latest build (0.9.9.25) has support for the asserts (for all comments, not just CA65 integration)
Let me know if you find issues - I haven't tested this a whole ton. :p

Bananmos
Posts: 496
Joined: Wed Mar 09, 2005 9:08 am
Contact:

Re: Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Post by Bananmos » Thu Apr 30, 2020 5:39 pm

Sour wrote:
Sat Apr 18, 2020 3:29 pm
Bananmos wrote:
Sat Apr 18, 2020 12:46 pm
Will a build supporting it eventually pop up here?
The latest build (0.9.9.25) has support for the asserts (for all comments, not just CA65 integration)
Let me know if you find issues - I haven't tested this a whole ton. :p
Finally got around to trying it out... and it works fantastically with both registers and symbols I've tried! This is such a game changer for debugging :D

But I do have another unrelated but likewise hopefully-simple-feature-request though... ;)

The code I end up debugging a lot is sprite drawing code - and I would guess I'm not alone here... all the edge-cases for clipping with the requirements for it to be fast can lead to subtle bugs.

Mesen's sprite viewer has been of great help, as it shows the OAM is a more visual format. But the annoying thing is that I can't actually see that visual presentation of the result until I perform a $4014 DMA to get OAM into the PPU memory. And ideally I'd like to be able to have the sprite viewer show the intermediate result as I'm single-stepping my code.

So I gotta ask... would it be easy enough to add a feature to the OAM viewer that can switch it to sourcing its data from a specific page of CPU memory instead of PPU OAM?

Sour
Posts: 795
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen Debugger - Feedback/Feature Requests? (2018 edition)

Post by Sour » Thu Apr 30, 2020 7:30 pm

Was already planning on eventually doing something like this for the CHR viewer (to allow it to display PRG ROM as tiles), makes sense to have something similar for the sprite viewer, too.

So, here you go! (next appveyor build will have it)
SpriteViewer.png

Post Reply