Unify Debug_Init() for all platforms

This commit is contained in:
Azamat H. Hackimov 2024-09-23 02:03:42 +03:00
parent 585a3804c4
commit 21576c86a5
4 changed files with 38 additions and 48 deletions

View File

@ -1,8 +1,10 @@
set(HEADERS
debug.h
debugbreak.h
mono.h)
mono.h
)
set(CPPS
debug.cpp
$<$<PLATFORM_ID:Darwin,Linux,OpenBSD>:
lnxdebug.cpp
lnxmono.cpp
@ -22,8 +24,9 @@ target_include_directories(ddebug PUBLIC
PRIVATE ${PROJECT_BINARY_DIR}/lib # For d3_version.h
)
target_link_libraries(ddebug PRIVATE
mem
logger
$<$<PLATFORM_ID:Windows>:
mem
misc
>
)

31
ddebug/debug.cpp Normal file
View File

@ -0,0 +1,31 @@
/*
* Descent 3
* Copyright (C) 2024 Descent Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "debug.h"
#include "log.h"
bool Debug_break = false;
bool Debug_Init(bool debugger) {
#ifndef RELEASE
Debug_break = debugger;
LOG_DEBUG_IF(Debug_break) << "Debug Break enabled.";
#endif
return true;
}

View File

@ -41,50 +41,26 @@
#include <cstdio>
#include "debug.h"
#include "mono.h"
///////////////////////////////////////////////////////////////////////////////
bool Debug_break = false;
static char *Debug_DumpInfo();
// if we are running under a debugger, then pass true
bool Debug_Init(bool debugger) {
#ifndef RELEASE
Debug_break = debugger;
if (Debug_break)
mprintf(0, "Debug Break enabled.\n");
#endif // ifndef RELEASE
return true;
}
// Does a messagebox with a stack dump
// Messagebox shows topstring, then stack dump, then bottomstring
// Return types are the same as the Windows return values
int Debug_ErrorBox(int type, const char *topstring, const char *title, const char *bottomstring) {
int answer = 0;
char *dumptext = Debug_DumpInfo();
fprintf(stderr, "\r\n%s(%s)\r\n\n%s\r\n\n%s\r\n", title, topstring, dumptext, bottomstring);
fprintf(stderr, "\n%s(%s)\n\n%s\n\n%s\n", title, topstring, "System Error", bottomstring);
debug_break();
return answer;
}
// displays an message box
// displays a message box
// Returns the same values as the Win32 MessageBox() function
int Debug_MessageBox(int type, const char *title, const char *str) {
return Debug_ErrorBox(type, str, "Descent 3 Message", "");
}
///////////////////////////////////////////////////////////////////////////////
char *Debug_DumpInfo() {
static char e[] = "System Error";
return e;
}

View File

@ -199,26 +199,6 @@
///////////////////////////////////////////////////////////////////////////////
bool Debug_break = false;
///////////////////////////////////////////////////////////////////////////////
bool Debug_Init(bool debugger) {
// initialization of debugging consoles.
#ifndef RELEASE
Debug_break = debugger;
if (Debug_break) {
mprintf(0, "Debug Break enabled.\n");
}
#endif // ifndef RELEASE
return true;
}
/* Message Box functions */
// Does a messagebox with a stack dump