2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2009 PCSX2 Dev Team
|
2009-10-04 09:00:07 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-04-27 02:04:31 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 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.
|
2009-04-28 05:56:22 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-04-27 02:04:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PrecompiledHeader.h"
|
|
|
|
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
#include <wx/app.h>
|
2009-12-14 12:18:55 +00:00
|
|
|
#include "Threading.h"
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
wxString GetEnglish( const char* msg )
|
|
|
|
{
|
2009-10-29 13:51:49 +00:00
|
|
|
return fromUTF8(msg);
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetTranslation( const char* msg )
|
|
|
|
{
|
2009-10-29 13:51:49 +00:00
|
|
|
return wxGetTranslation( fromUTF8(msg) );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 02:58:22 +00:00
|
|
|
// ------------------------------------------------------------------------
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
// Force DevAssert to *not* inline for devel builds (allows using breakpoints to trap assertions,
|
|
|
|
// and force it to inline for release builds (optimizes it out completely since IsDevBuild is a
|
|
|
|
// const false).
|
2009-09-12 02:58:22 +00:00
|
|
|
//
|
|
|
|
#ifdef PCSX2_DEVBUILD
|
|
|
|
# define DEVASSERT_INLINE __noinline
|
|
|
|
#else
|
|
|
|
# define DEVASSERT_INLINE __forceinline
|
|
|
|
#endif
|
|
|
|
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
// Using a threadlocal assertion guard. Separate threads can assert at the same time.
|
|
|
|
// That's ok. What we don't want is the *same* thread recurse-asserting.
|
|
|
|
static __threadlocal int s_assert_guard = 0;
|
2009-09-23 09:53:21 +00:00
|
|
|
|
2009-12-14 12:18:55 +00:00
|
|
|
pxDoAssertFnType* pxDoAssert = pxAssertImpl_LogIt;
|
|
|
|
|
|
|
|
// make life easier for people using VC++ IDE by using this format, which allows double-click
|
|
|
|
// response times from the Output window...
|
|
|
|
wxString DiagnosticOrigin::ToString( const wxChar* msg ) const
|
|
|
|
{
|
|
|
|
wxString message;
|
|
|
|
message.reserve( 2048 );
|
|
|
|
|
|
|
|
message.Printf( L"%s(%d) : assertion failed:\n", srcfile, line );
|
|
|
|
|
|
|
|
if( function != NULL )
|
|
|
|
message += L" Function: " + fromUTF8(function) + L"\n";
|
|
|
|
|
|
|
|
message += L" Thread: " + Threading::pxGetCurrentThreadName() + L"\n";
|
|
|
|
|
|
|
|
if( condition != NULL )
|
|
|
|
message += L" Condition: " + wxString(condition) + L"\n";
|
|
|
|
|
|
|
|
if( msg != NULL )
|
|
|
|
message += L" Message: " + wxString(msg) + L"\n";
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool pxAssertImpl_LogIt( const DiagnosticOrigin& origin, const wxChar *msg )
|
|
|
|
{
|
|
|
|
wxLogError( origin.ToString( msg ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEVASSERT_INLINE void pxOnAssert( const DiagnosticOrigin& origin, const wxChar* msg )
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
{
|
|
|
|
RecursionGuard guard( s_assert_guard );
|
2009-12-14 12:18:55 +00:00
|
|
|
if( guard.IsReentrant() ) { return wxTrap(); }
|
2009-10-04 09:00:07 +00:00
|
|
|
|
2009-12-14 12:18:55 +00:00
|
|
|
// wxWidgets doesn't come with debug builds on some Linux distros, and other distros make
|
|
|
|
// it difficult to use the debug build (compilation failures). To handle these I've had to
|
|
|
|
// bypass the internal wxWidgets assertion handler entirely, since it may not exist even if
|
|
|
|
// PCSX2 itself is compiled in debug mode (assertions enabled).
|
|
|
|
|
|
|
|
bool trapit;
|
|
|
|
|
|
|
|
if( pxDoAssert == NULL )
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
{
|
|
|
|
// Note: Format uses MSVC's syntax for output window hotlinking.
|
2009-12-14 12:18:55 +00:00
|
|
|
trapit = pxAssertImpl_LogIt( origin, msg );
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-14 12:18:55 +00:00
|
|
|
trapit = pxDoAssert( origin, msg );
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
}
|
2009-12-14 12:18:55 +00:00
|
|
|
|
|
|
|
if( trapit ) { wxTrap(); }
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
}
|
2009-09-23 09:53:21 +00:00
|
|
|
|
2009-12-14 12:18:55 +00:00
|
|
|
__forceinline void pxOnAssert( const DiagnosticOrigin& origin, const char* msg)
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
{
|
2009-12-14 12:18:55 +00:00
|
|
|
pxOnAssert( origin, fromUTF8(msg) );
|
2009-09-12 02:58:22 +00:00
|
|
|
}
|
|
|
|
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
|
2009-09-20 20:54:45 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Exception Namespace Implementations (Format message handlers for general exceptions)
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Exception::BaseException::~BaseException() throw() {}
|
2009-04-27 02:04:31 +00:00
|
|
|
|
2009-09-20 20:54:45 +00:00
|
|
|
void Exception::BaseException::InitBaseEx( const wxString& msg_eng, const wxString& msg_xlt )
|
|
|
|
{
|
|
|
|
m_message_diag = msg_eng;
|
2009-10-18 12:30:00 +00:00
|
|
|
m_message_user = msg_xlt.IsEmpty() ? msg_eng : msg_xlt;
|
2009-09-01 00:43:28 +00:00
|
|
|
|
2009-09-20 20:54:45 +00:00
|
|
|
// Linux/GCC exception handling is still suspect (this is likely to do with GCC more
|
|
|
|
// than linux), and fails to propagate exceptions up the stack from EErec code. This
|
|
|
|
// could likely be because of the EErec using EBP. So to ensure the user at least
|
|
|
|
// gets a log of the error, we output to console here in the constructor.
|
2009-07-20 00:39:38 +00:00
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
#ifdef __LINUX__
|
2009-09-20 20:54:45 +00:00
|
|
|
//wxLogError( msg_eng.c_str() );
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
Console.Error( msg_eng );
|
2009-04-27 02:04:31 +00:00
|
|
|
#endif
|
2009-09-20 20:54:45 +00:00
|
|
|
}
|
2009-04-28 05:56:22 +00:00
|
|
|
|
2009-09-20 20:54:45 +00:00
|
|
|
// given message is assumed to be a translation key, and will be stored in translated
|
|
|
|
// and untranslated forms.
|
|
|
|
void Exception::BaseException::InitBaseEx( const char* msg_eng )
|
|
|
|
{
|
|
|
|
m_message_diag = GetEnglish( msg_eng );
|
|
|
|
m_message_user = GetTranslation( msg_eng );
|
2009-09-01 00:43:28 +00:00
|
|
|
|
2009-07-20 00:39:38 +00:00
|
|
|
#ifdef __LINUX__
|
2009-09-20 20:54:45 +00:00
|
|
|
//wxLogError( m_message_diag.c_str() );
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
Console.Error( msg_eng );
|
2009-07-20 00:39:38 +00:00
|
|
|
#endif
|
2009-09-20 20:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString Exception::BaseException::FormatDiagnosticMessage() const
|
|
|
|
{
|
|
|
|
return m_message_diag + L"\n\n" + m_stacktrace;
|
|
|
|
}
|
|
|
|
|
2009-10-07 19:20:11 +00:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
wxString Exception::CancelEvent::FormatDiagnosticMessage() const
|
|
|
|
{
|
|
|
|
// FIXME: This should probably just log a single line from the stacktrace.. ?
|
|
|
|
return L"Action canceled: " + m_message_diag;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString Exception::CancelEvent::FormatDisplayMessage() const
|
|
|
|
{
|
|
|
|
return L"Action canceled: " + m_message_diag;
|
|
|
|
}
|
|
|
|
|
2009-09-20 20:54:45 +00:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
wxString Exception::ObjectIsNull::FormatDiagnosticMessage() const
|
|
|
|
{
|
|
|
|
return wxsFormat(
|
2009-10-07 19:20:11 +00:00
|
|
|
L"reference to '%s' failed : handle is null.",
|
2009-09-20 20:54:45 +00:00
|
|
|
m_message_diag.c_str()
|
|
|
|
) + m_stacktrace;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString Exception::ObjectIsNull::FormatDisplayMessage() const
|
|
|
|
{
|
|
|
|
return wxsFormat(
|
2009-10-07 19:20:11 +00:00
|
|
|
L"reference to '%s' failed : handle is null.",
|
2009-09-20 20:54:45 +00:00
|
|
|
m_message_diag.c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
wxString Exception::Stream::FormatDiagnosticMessage() const
|
|
|
|
{
|
|
|
|
return wxsFormat(
|
|
|
|
L"Stream exception: %s\n\tFile/Object: %s",
|
|
|
|
m_message_diag.c_str(), StreamName.c_str()
|
|
|
|
) + m_stacktrace;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString Exception::Stream::FormatDisplayMessage() const
|
|
|
|
{
|
|
|
|
return m_message_user + L"\n\n" +
|
|
|
|
wxsFormat( _("Name: %s"), StreamName.c_str() );
|
|
|
|
}
|
|
|
|
|