Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code from rgbds-live patch #1604

Closed
3 tasks
SelvinPL opened this issue Jan 9, 2025 · 5 comments
Closed
3 tasks

Add code from rgbds-live patch #1604

SelvinPL opened this issue Jan 9, 2025 · 5 comments
Labels
meta This isn't related to the tools directly: repo organization, maintainership...

Comments

@SelvinPL
Copy link

SelvinPL commented Jan 9, 2025

Now building rgbds-live requires applying patch ... What if we would add this code CONDITIONALLY (#ifdef DEBUG_SYMBOLS) to the rgbds itself
Task to do:

  • add/modifing the code
  • change "__DEB..." to "~~DEB..." in rgbds-live and do fixing per code review
  • add -DDEBUG_SYMBOLS to test build! this is important - so if someone modify the api used in rgbds-live code test would fail
@Rangi42
Copy link
Contributor

Rangi42 commented Jan 9, 2025

I'd be happy to include rgbds-live support directly in rgbds (they're both gbdev projects, after all), but I don't think this would work out well.

Say that rgbds tag v0.9.0 includes some definition of sym_AddSecret. And then rgbds-live wants to make some change (like fixing that potential name buffer overflow, or changing the "__SEC" prefix, or otherwise changing how line tracking works). Then it would still have to patch rgbds, unless rgbds were to make a new release just for live's sake (which would be very unlikely unless we had other fixes queued up).

@SelvinPL
Copy link
Author

SelvinPL commented Jan 9, 2025

hmmm, good point
but we could add this code and fix those issues say in next release and then adding patch if needed(in rgbds-live)

added value is that patching would have "anchor point in git" so changes in rgbds would not causing need for changes in rgbds.patch

@SelvinPL
Copy link
Author

SelvinPL commented Jan 9, 2025

the code could be:

  • symbol.hpp
#ifdef DEBUG_SYMBOLS
	Symbol *sym_AddDebugSymbol();
#else
	#define sym_AddDebugSymbol()
#endif
  • parser.y
    | label cpu_commands => | label { sym_AddDebugSymbol(); } cpu_commands
    (you cannot add #ifdef in rule in flex/bison file nor use some conditional code generation as it doesn't have preprocesor)
  • symbol.cpp
#ifdef DEBUG_SYMBOLS
Symbol *sym_AddDebugSymbol() {
	static uint64_t debugSymbolCounter = 1;

	std::shared_ptr<FileStackNode> fstk = fstk_GetFileStack();
	while (fstk->type == NODE_REPT) {
		fstk = fstk->parent;
	}

	char valueBuf[64];
	snprintf(
		valueBuf,
		sizeof(valueBuf),
		"~~DEB~%" PRIx64 "~%" PRIx32 "~",
		debugSymbolCounter ++,
		lexer_GetLineNo()
	);

	std::string name = valueBuf;
	name += fstk->name();

	Symbol *sym = &createSymbol(name);
	sym->type = SYM_LABEL;
	sym->data = static_cast<int32_t>(sect_GetSymbolOffset());
	sym->isExported = true;
	sym->section = sect_GetSymbolSection();

	updateSymbolFilename(*sym);
	return sym;
}
#endif

generated code would have

  case 26: // $@2: %empty
#line 506 "src/asm/parser.y"
                { sym_AddDebugSymbol(); }
#line 1209 "src/asm/parser.cpp"
    break;

with #define sym_AddDebugSymbol() should be nicely optimized in non DEBUG_SYMBOLS build

@SelvinPL SelvinPL changed the title Add code from rgbds-live patch Add code from rgbds-live patch aka add debug symbols for CPU every instruction Jan 9, 2025
@SelvinPL SelvinPL changed the title Add code from rgbds-live patch aka add debug symbols for CPU every instruction Add code from rgbds-live patch Jan 9, 2025
@SelvinPL
Copy link
Author

SelvinPL commented Jan 9, 2025

hmmm,we could even push it further and make those symbols a general debugging symbols for every instruction
instead conditional compiling we could add compiler's flag
benefits: emulator could search for such symbols to easy debug even macros

@Rangi42 Rangi42 added the meta This isn't related to the tools directly: repo organization, maintainership... label Jan 9, 2025
@Rangi42
Copy link
Contributor

Rangi42 commented Jan 9, 2025

but we could add this code and fix those issues say in next release and then adding patch if needed(in rgbds-live)

rgbds-live deploys its current master branch to production. So yes, if the secret-sym code ever changed (or if it started needing to change something else in rgbds), it would end up with an rgbds.patch anyway until the next rgbds release (which do not happen very often). Plus it already needs a binjgb patch. So adding the secret-sym code in the rgbds repo would not simplify rgbds-live, it would still need the patching infrastructure (and possibly an rgbds.patch).

Plus, this would spread the "__SEC_"-related code across two very distant places. The label prefix would be created in rgbds, and rgbds-live would have the code to check for it. I'd prefer keeping them closer together.

@Rangi42 Rangi42 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta This isn't related to the tools directly: repo organization, maintainership...
Projects
None yet
Development

No branches or pull requests

2 participants