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 -D option to specifiy file to receive trace output. #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brouhaha
Copy link

Add -D option to specifiy file to receive trace output, though the default is still stderr. While redirection of stderr could be used without this change, the intent here is to allow stderr to be used for only error conditions. It is possible that some such output should go to both stderr and the trace file, though this commit does not do that.

@EtchedPixels
Copy link
Owner

Makes a lot of sense. Will have a think about how best to handle this.

@brouhaha
Copy link
Author

I didn't expect that you'd necessarily want to accept this PR as-is.

On some projects, I've used something like this:

typdef uint32_t trace_source_t;

#define TRACE_MEM	0x000001
#define TRACE_IO	0x000002
#define TRACE_ROM	0x000004
...
static trace_source_t trace_mask = 0;
static FILE *trace_file = 0; /* stderr may not be statically defined, so
                                initialize to stderr in main() */

static int trace_vprintf(trace_source_t source, const char *format, va_list arg)
{
	if (! source & trace_mask)
		return 0;
	vfprintf(trace_file, format, arg);
}

static int trace_printf(trace_source_t source, const char *format, ...)
{
	va_list ap;
	va_start(ap, format);
	trace_vprintf(source, fmt, ap);
	va_end(ap);
}
...
static uint8_t mem_read0(uint16_t addr)
{
	if (bankenable) {
		unsigned int bank = (addr & 0xC000) >> 14;
		trace_printf(TRACE_MEM, "R %04x[%02X] = %02X\n", addr, (unsigned int) bankreg[bank], (unsigned int) ramrom[(bankreg[bank] << 14) + (addr & 0x3FFF)]);

That has the drawback of requiring a function call even if the trace is masked, which is OK for some things but probably not anything in the core of a simulator. A macro could be used instead, though I'm not a huge fan of macros.

@peterw8102
Copy link

I don't think you really need this. I use

./emulator -flags 2> /tmp/stderr

I use a Mac but it looks like the almost identical syntax works on Windows as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants