ca65's "line" output in debug file

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
GradualGames
Posts: 1106
Joined: Sun Nov 09, 2008 9:18 pm
Location: Pennsylvania, USA
Contact:

ca65's "line" output in debug file

Post by GradualGames »

Does anyone fully understand the data output in ca65's (might actually be the linker that outputs the full file, actually), exhaustive debug file? I was successfully able to write a python script to translate this file into source-level debugging information for FCEUX, however, I encountered an odd situation which I haven't yet been able to explain.

Code: Select all

                    #Actual line of code.
                    line_number = line["line"] - 1
                    if 0 <= line_number < len(source_file_lines[file_name]):
                        line_of_code = source_file_lines[file_name][line_number].rstrip().replace("#", "")
In order to get the nl comments in FCEUX to show up as expected above the first instruction associated with the line of code, I had to add this - 1 calculation before grabbing the line of code from the source file. What concerns me is that some of these "line" objects report 0 as the line number, so this doesn't seem correct (i.e., it's not a case of counting from 0 in one case versus counting from 1 in another, I have arrays of source code lines that start from 0 and the debug output also appears to start from 0 for these "line" objects). Yet, most of the time I'm getting correct and expected output in the FCEUX debugger. (i.e., I see my line of code, followed by all the instructions assembled for that line of code, exactly as expected).

Just wondering if anyone out there understands the debug output in more detail and can help me explain why I had to put that - 1 there.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: ca65's "line" output in debug file

Post by thefox »

Why not use the dbginfo library (https://github.com/cc65/cc65/tree/master/src/dbginfo)? I really don't understand why many people seem to insist on parsing the format manually.

Whatever you do, the library might help you figure out what you're doing wrong.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
GradualGames
Posts: 1106
Joined: Sun Nov 09, 2008 9:18 pm
Location: Pennsylvania, USA
Contact:

Re: ca65's "line" output in debug file

Post by GradualGames »

Haha, interesting. I didn't even know this existed. That'd be my guess why people parse it themselves. Plus its fun to write little tools in python :D So is this dbginfo library meant to be compiled and used with a standard C compiler outside of cc65 and then just run a debug file through it or...?
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: ca65's "line" output in debug file

Post by thefox »

Yes. dbginfo.c / dbginfo.h make up the library. dbgsh.c is a sample program that uses the library.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Post Reply