mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-10 11:51:52 +00:00
adopted debug to match scummvm version
This commit is contained in:
parent
9e1e232745
commit
3195f7f3d2
137
common/debug.cpp
137
common/debug.cpp
@ -25,22 +25,21 @@
|
||||
|
||||
#include "common/sys.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/str.h"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include "engine/backend/driver.h"
|
||||
|
||||
const char *tag2str(uint32 tag) {
|
||||
static char str[5];
|
||||
Common::String tag2string(uint32 tag) {
|
||||
char str[5];
|
||||
str[0] = (char)(tag >> 24);
|
||||
str[1] = (char)(tag >> 16);
|
||||
str[2] = (char)(tag >> 8);
|
||||
str[3] = (char)tag;
|
||||
str[4] = '\0';
|
||||
return str;
|
||||
return Common::String(str);
|
||||
}
|
||||
|
||||
void hexdump(const byte * data, int len, int bytesPerLine) {
|
||||
void hexdump(const byte *data, int len, int bytesPerLine) {
|
||||
assert(1 <= bytesPerLine && bytesPerLine <= 32);
|
||||
int i;
|
||||
byte c;
|
||||
@ -90,30 +89,126 @@ void hexdump(const byte * data, int len, int bytesPerLine) {
|
||||
printf("|\n");
|
||||
}
|
||||
|
||||
void CDECL warning(const char *fmt, ...) {
|
||||
std::fprintf(stderr, "WARNING: ");
|
||||
static void debugHelper(const char *in_buf, bool caret = true) {
|
||||
char buf[STRINGBUFLEN];
|
||||
|
||||
std::va_list va;
|
||||
strcpy(buf, in_buf);
|
||||
|
||||
va_start(va, fmt);
|
||||
std::vfprintf(stderr, fmt, va);
|
||||
va_end(va);
|
||||
std::fprintf(stderr, "\n");
|
||||
if (caret)
|
||||
printf("%s\n", buf);
|
||||
else
|
||||
printf("%s", buf);
|
||||
|
||||
#if defined(USE_WINDBG)
|
||||
if (caret)
|
||||
strcat(buf, "\n");
|
||||
#if defined(_WIN32_WCE)
|
||||
TCHAR buf_unicode[1024];
|
||||
MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
|
||||
OutputDebugString(buf_unicode);
|
||||
#else
|
||||
OutputDebugString(buf);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void CDECL error(const char *fmt, ...) {
|
||||
std::fprintf(stderr, "ERROR: ");
|
||||
void CDECL debug(const char *s, ...) {
|
||||
char buf[STRINGBUFLEN];
|
||||
va_list va;
|
||||
|
||||
std::va_list va;
|
||||
|
||||
va_start(va, fmt);
|
||||
std::vfprintf(stderr, fmt, va);
|
||||
va_start(va, s);
|
||||
vsnprintf(buf, STRINGBUFLEN, s, va);
|
||||
va_end(va);
|
||||
std::fprintf(stderr, "\n");
|
||||
|
||||
debugHelper(buf);
|
||||
}
|
||||
|
||||
void CDECL debug(int level, const char *s, ...) {
|
||||
char buf[STRINGBUFLEN];
|
||||
va_list va;
|
||||
|
||||
if (level > debugLevel)
|
||||
return;
|
||||
|
||||
va_start(va, s);
|
||||
vsnprintf(buf, STRINGBUFLEN, s, va);
|
||||
va_end(va);
|
||||
|
||||
debugHelper(buf);
|
||||
}
|
||||
|
||||
void NORETURN CDECL error(const char *s, ...) {
|
||||
char buf_input[STRINGBUFLEN];
|
||||
char buf_output[STRINGBUFLEN];
|
||||
va_list va;
|
||||
|
||||
// Generate the full error message
|
||||
va_start(va, s);
|
||||
vsnprintf(buf_input, STRINGBUFLEN, s, va);
|
||||
va_end(va);
|
||||
|
||||
strcpy(buf_output, buf_input);
|
||||
|
||||
// Print the error message to stderr
|
||||
fprintf(stderr, "%s!\n", buf_output);
|
||||
|
||||
#if defined(USE_WINDBG)
|
||||
#if defined(_WIN32_WCE)
|
||||
TCHAR buf_output_unicode[1024];
|
||||
MultiByteToWideChar(CP_ACP, 0, buf_output, strlen(buf_output) + 1, buf_output_unicode, sizeof(buf_output_unicode));
|
||||
OutputDebugString(buf_output_unicode);
|
||||
#ifndef DEBUG
|
||||
drawError(buf_output);
|
||||
#else
|
||||
int cmon_break_into_the_debugger_if_you_please = *(int *)(buf_output + 1); // bus error
|
||||
printf("%d", cmon_break_into_the_debugger_if_you_please); // don't optimize the int out
|
||||
#endif
|
||||
#else
|
||||
OutputDebugString(buf_output);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PALMOS_MODE
|
||||
extern void PalmFatalError(const char *err);
|
||||
PalmFatalError(buf_output);
|
||||
#endif
|
||||
|
||||
#ifdef __SYMBIAN32__
|
||||
Symbian::FatalError(buf_output);
|
||||
#endif
|
||||
|
||||
if (g_driver)
|
||||
g_driver->quit();
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void CDECL warning(const char *fmt, ...) {
|
||||
char buf[STRINGBUFLEN];
|
||||
va_list va;
|
||||
|
||||
va_start(va, fmt);
|
||||
vsnprintf(buf, STRINGBUFLEN, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
#if !defined (__SYMBIAN32__)
|
||||
fprintf(stderr, "WARNING: %s!\n", buf);
|
||||
#endif
|
||||
|
||||
#if defined(USE_WINDBG)
|
||||
strcat(buf, "\n");
|
||||
#if defined(_WIN32_WCE)
|
||||
TCHAR buf_unicode[1024];
|
||||
MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
|
||||
OutputDebugString(buf_unicode);
|
||||
#else
|
||||
OutputDebugString(buf);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *debug_levels[] = {
|
||||
"NONE",
|
||||
"NORMAL",
|
||||
|
@ -25,6 +25,10 @@
|
||||
|
||||
#include "common/sys.h"
|
||||
|
||||
namespace Common {
|
||||
class String;
|
||||
}
|
||||
|
||||
#ifndef COMMON_DEBUG_H
|
||||
#define COMMON_DEBUG_H
|
||||
|
||||
@ -51,8 +55,11 @@ extern bool ZBUFFER_GLOBAL, SHOWFPS_GLOBAL;
|
||||
|
||||
void warning(const char *fmt, ...);
|
||||
void error(const char *fmt, ...);
|
||||
void CDECL debug(int level, const char *s, ...);
|
||||
void CDECL debug(const char *s, ...);
|
||||
|
||||
const char *tag2str(uint32 tag);
|
||||
void hexdump(const byte * data, int len, int bytesPerLine);
|
||||
|
||||
Common::String tag2string(uint32 tag);
|
||||
|
||||
#endif
|
||||
|
@ -306,13 +306,13 @@ bool File::open(const String &filename, AccessMode mode) {
|
||||
_handle = fopenNoCase(filename, "", modeStr);
|
||||
} else if (_filesMap && _filesMap->contains(fname)) {
|
||||
fname = (*_filesMap)[fname];
|
||||
//debug(3, "Opening hashed: %s", fname.c_str());
|
||||
debug(3, "Opening hashed: %s", fname.c_str());
|
||||
_handle = fopen(fname.c_str(), modeStr);
|
||||
} else if (_filesMap && _filesMap->contains(fname + ".")) {
|
||||
// WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
|
||||
// sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
|
||||
fname = (*_filesMap)[fname + "."];
|
||||
//debug(3, "Opening hashed: %s", fname.c_str());
|
||||
debug(3, "Opening hashed: %s", fname.c_str());
|
||||
_handle = fopen(fname.c_str(), modeStr);
|
||||
} else {
|
||||
|
||||
@ -347,10 +347,10 @@ bool File::open(const String &filename, AccessMode mode) {
|
||||
}
|
||||
|
||||
if (_handle == NULL) {
|
||||
/* if (mode == kFileReadMode)
|
||||
if (mode == kFileReadMode)
|
||||
debug(2, "File %s not found", filename.c_str());
|
||||
else
|
||||
debug(2, "File %s not opened", filename.c_str());*/
|
||||
debug(2, "File %s not opened", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -395,10 +395,10 @@ bool File::open(const FilesystemNode &node, AccessMode mode) {
|
||||
_handle = fopen(node.getPath().c_str(), modeStr);
|
||||
|
||||
if (_handle == NULL) {
|
||||
/* if (mode == kFileReadMode)
|
||||
if (mode == kFileReadMode)
|
||||
debug(2, "File %s not found", filename.c_str());
|
||||
else
|
||||
debug(2, "File %s not opened", filename.c_str());*/
|
||||
debug(2, "File %s not opened", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#define COMMON_UTIL_H
|
||||
|
||||
#include "common/sys.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
#ifdef MIN
|
||||
#undef MIN
|
||||
@ -35,9 +36,9 @@
|
||||
#undef MAX
|
||||
#endif
|
||||
|
||||
template<typename T> inline T ABS (T x) { return (x>=0) ? x : -x; }
|
||||
template<typename T> inline T MIN (T a, T b) { return (a<b) ? a : b; }
|
||||
template<typename T> inline T MAX (T a, T b) { return (a>b) ? a : b; }
|
||||
template<typename T> inline T ABS (T x) { return (x >= 0) ? x : -x; }
|
||||
template<typename T> inline T MIN (T a, T b) { return (a < b) ? a : b; }
|
||||
template<typename T> inline T MAX (T a, T b) { return (a > b) ? a : b; }
|
||||
template<typename T> inline T CLIP (T v, T amin, T amax)
|
||||
{ if (v < amin) return amin; else if (v > amax) return amax; else return v; }
|
||||
|
||||
|
@ -25,8 +25,9 @@
|
||||
|
||||
#include "common/sys.h"
|
||||
#include "common/endian.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/util.h"
|
||||
#include "common/timer.h"
|
||||
#include "common/str.h"
|
||||
|
||||
#include "engine/resource.h"
|
||||
|
||||
@ -70,7 +71,7 @@ void ImuseSndMgr::countElements(byte *ptr, int &numRegions, int &numJumps) {
|
||||
size = READ_BE_UINT32(ptr); ptr += size + 4;
|
||||
break;
|
||||
default:
|
||||
error("ImuseSndMgr::countElements() Unknown MAP tag '%s'", tag2str(tag));
|
||||
error("ImuseSndMgr::countElements() Unknown MAP tag '%s'", tag2string(tag).c_str());
|
||||
}
|
||||
} while (tag != MKID_BE('DATA'));
|
||||
}
|
||||
@ -133,7 +134,7 @@ void ImuseSndMgr::parseSoundHeader(byte *ptr, SoundDesc *sound, int &headerSize)
|
||||
ptr += 4;
|
||||
break;
|
||||
default:
|
||||
error("ImuseSndMgr::prepareSound(%s) Unknown MAP tag '%s'", sound->name, tag2str(tag));
|
||||
error("ImuseSndMgr::prepareSound(%s) Unknown MAP tag '%s'", sound->name, tag2string(tag).c_str());
|
||||
}
|
||||
} while (tag != MKID_BE('DATA'));
|
||||
headerSize = ptr - s_ptr;
|
||||
|
Loading…
Reference in New Issue
Block a user