mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-09-28 16:54:51 +00:00
Expose unused variables and improve logging
* Adds support for RELEASE_ logging (logging even with NDEBUG builds)
This commit is contained in:
parent
86076697b9
commit
8ded3fa0f1
65
src/common.h
65
src/common.h
@ -72,51 +72,60 @@
|
|||||||
#define MAX(a,b) (((a) >= (b)) ? (a) : (b))
|
#define MAX(a,b) (((a) >= (b)) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
# if defined(__GNUC__)
|
|
||||||
# pragma GCC diagnostic push
|
|
||||||
# pragma GCC diagnostic ignored "-Wunused-variable"
|
|
||||||
# elif defined(__clang__)
|
|
||||||
# pragma clang diagnostic push
|
|
||||||
# pragma clang diagnostic ignored "-Wunused-variable"
|
|
||||||
# endif
|
|
||||||
|
|
||||||
extern bool do_logging;
|
extern bool do_logging;
|
||||||
extern FILE *error_log;
|
extern FILE *error_log;
|
||||||
#define ERRLOG(/* err message format string, args */...) \
|
|
||||||
if (do_logging) { \
|
#define _LOG(...) \
|
||||||
int saverr = errno; errno = 0; \
|
int saverr = errno; \
|
||||||
fprintf(error_log ? error_log : stderr, "%s:%d - ", __FILE__, __LINE__); \
|
errno = 0; \
|
||||||
fprintf(error_log ? error_log : stderr, __VA_ARGS__); \
|
fprintf(error_log, "%s:%d - ", __FILE__, __LINE__); \
|
||||||
if (saverr) { \
|
fprintf(error_log, __VA_ARGS__); \
|
||||||
fprintf(error_log ? error_log : stderr, " (syserr: %s)", strerror(saverr)); \
|
if (saverr) { \
|
||||||
} \
|
fprintf(error_log, " (syserr: %s)", strerror(saverr)); \
|
||||||
fprintf(error_log ? error_log : stderr, "\n"); \
|
} \
|
||||||
|
fprintf(error_log, "\n");
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
|
||||||
|
#define ERRLOG(...) \
|
||||||
|
if (do_logging) { \
|
||||||
|
_LOG(__VA_ARGS__); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ERRQUIT(...) \
|
#define ERRQUIT(...) \
|
||||||
if (do_logging) { \
|
if (do_logging) { \
|
||||||
ERRLOG(__VA_ARGS__); \
|
_LOG(__VA_ARGS__); \
|
||||||
exit(1); \
|
} \
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
#define LOG(...) \
|
||||||
|
if (do_logging) { \
|
||||||
|
errno = 0; \
|
||||||
|
_LOG(__VA_ARGS__); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // NDEBUG
|
#else // NDEBUG
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
# pragma GCC diagnostic pop
|
|
||||||
#elif defined(__clang__)
|
|
||||||
# pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ERRLOG(...) \
|
#define ERRLOG(...) \
|
||||||
do { } while(0);
|
do { } while(0);
|
||||||
|
|
||||||
|
#define ERRQUIT(...) \
|
||||||
|
do { } while(0);
|
||||||
|
|
||||||
|
#define LOG(...) \
|
||||||
|
do { } while(0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LOG(...) \
|
#define RELEASE_ERRLOG(...) \
|
||||||
|
do { \
|
||||||
|
_LOG(__VA_ARGS__); \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
#define RELEASE_LOG(...) \
|
||||||
do { \
|
do { \
|
||||||
errno = 0; \
|
errno = 0; \
|
||||||
ERRLOG(__VA_ARGS__); \
|
_LOG(__VA_ARGS__); \
|
||||||
} while(0);
|
} while(0);
|
||||||
|
|
||||||
#define Free(X) \
|
#define Free(X) \
|
||||||
|
@ -25,6 +25,11 @@ static unsigned char apple_iie_rom[32768]; /* //e */
|
|||||||
bool do_logging = true; // also controlled by NDEBUG
|
bool do_logging = true; // also controlled by NDEBUG
|
||||||
FILE *error_log = NULL;
|
FILE *error_log = NULL;
|
||||||
|
|
||||||
|
__attribute__((constructor))
|
||||||
|
static void _init_common() {
|
||||||
|
error_log = stderr;
|
||||||
|
}
|
||||||
|
|
||||||
GLUE_BANK_READ(read_ram_bank,base_d000_rd)
|
GLUE_BANK_READ(read_ram_bank,base_d000_rd)
|
||||||
GLUE_BANK_MAYBEWRITE(write_ram_bank,base_d000_wrt)
|
GLUE_BANK_MAYBEWRITE(write_ram_bank,base_d000_wrt)
|
||||||
GLUE_BANK_READ(read_ram_lc,base_e000_rd)
|
GLUE_BANK_READ(read_ram_lc,base_e000_rd)
|
||||||
@ -73,9 +78,7 @@ uint8_t *base_cxrom;
|
|||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
void c_debug_illegal_bcd()
|
void c_debug_illegal_bcd()
|
||||||
{
|
{
|
||||||
ERRLOG("Illegal/undefined BCD operation encountered, debug break on c_debug_illegal_bcd to debug...");
|
RELEASE_LOG("Illegal/undefined BCD operation encountered, debug break on c_debug_illegal_bcd to debug...");
|
||||||
char *ptr = (char*)0x0bad;
|
|
||||||
*ptr = 0x1337; // segfault
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user