mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Include code line in runtime debug.
Include the line of code where the error occured into the debug message. Further adjustments to the oeverall implementation.
This commit is contained in:
parent
acea3db378
commit
061110914a
@ -214,6 +214,8 @@ bool Core::Initialize()
|
||||
return false;
|
||||
}
|
||||
|
||||
// See if debugging options should be enabled
|
||||
m_Debugging = conf.GetBoolValue("Squirrel", "Debugging", m_Debugging);
|
||||
// Configure the empty initialization
|
||||
m_EmptyInit = conf.GetBoolValue("Squirrel", "EmptyInit", false);
|
||||
// Configure the verbosity level
|
||||
@ -272,8 +274,6 @@ bool Core::Initialize()
|
||||
DefaultVM::Set(m_VM);
|
||||
// Configure error handling
|
||||
ErrorHandling::Enable(conf.GetBoolValue("Squirrel", "ErrorHandling", true));
|
||||
// See if debugging options should be enabled
|
||||
m_Debugging = conf.GetBoolValue("Squirrel", "Debugging", m_Debugging);
|
||||
|
||||
// Prevent common null objects from using dead virtual machines
|
||||
NullArray() = Array();
|
||||
@ -748,6 +748,20 @@ void Core::SetIncomingName(CSStr name)
|
||||
m_IncomingNameBuffer[len] = '\0';
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
String Core::FetchCodeLine(CSStr src, SQInteger line, bool trim)
|
||||
{
|
||||
// Find the script we're looking for
|
||||
Scripts::iterator script = FindScript(src);
|
||||
// Do we have a valid script and line?
|
||||
if ((script == m_Scripts.end()) || !(script->mInfo) || (script->mLine.size() < line))
|
||||
{
|
||||
return String{}; // No such script!
|
||||
}
|
||||
// Fetch the line of code
|
||||
return script->FetchLine(line, trim);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Core::DoScripts(Scripts::iterator itr, Scripts::iterator end)
|
||||
{
|
||||
@ -886,28 +900,17 @@ void Core::CompilerErrorHandler(HSQUIRRELVM /*vm*/, CSStr desc, CSStr src, SQInt
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Core::CompilerErrorHandlerEx(CSStr desc, CSStr src, SQInteger line, SQInteger column)
|
||||
{
|
||||
// Find the script we're looking for
|
||||
Scripts::iterator script = FindScript(src);
|
||||
// Found anything?
|
||||
if (script == m_Scripts.end())
|
||||
{
|
||||
return false; // No such script!
|
||||
}
|
||||
// Have debug information?
|
||||
else if (!(script->mInfo))
|
||||
{
|
||||
return false; // Nothing to show!
|
||||
}
|
||||
// Is this line outside the range that we have?
|
||||
else if (script->mLine.size() < line)
|
||||
{
|
||||
return false; // No such line!
|
||||
}
|
||||
// Grab the associated line of code
|
||||
String code = script->FetchLine(line, true);
|
||||
// Display the error message with the code included
|
||||
LogFtl("Message: %s\n[\n=>Location: %s\n=>Line: %" PRINT_SZ_FMT "\n=>Column: %" PRINT_INT_FMT "\n=>Code: %s\n]", desc, src, ++line, column, code.c_str());
|
||||
// We displayed the information
|
||||
String code = FetchCodeLine(src, line, true);
|
||||
// Valid line of code?
|
||||
if (!code.empty())
|
||||
{
|
||||
// Display the error message with the code included
|
||||
LogFtl("Message: %s\n[\n=>Location: %s\n=>Line: %" PRINT_SZ_FMT "\n=>Column: %" PRINT_INT_FMT "\n=>Code: %s\n]", desc, src, ++line, column, code.c_str());
|
||||
// We displayed the information
|
||||
return true;
|
||||
}
|
||||
// No code to show. Fall back to normal message
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -958,13 +958,18 @@ public:
|
||||
void SetIncomingName(CSStr name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* retrieve the name for the currently assigned incoming connection..
|
||||
* Retrieve the name for the currently assigned incoming connection.
|
||||
*/
|
||||
CSStr GetIncomingName()
|
||||
{
|
||||
return (!m_IncomingNameBuffer) ? _SC("") : m_IncomingNameBuffer;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieves a line of code from a certain source.
|
||||
*/
|
||||
String FetchCodeLine(CSStr src, SQInteger line, bool trim = true);
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
|
@ -1,5 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Logger.hpp"
|
||||
#include "Core.hpp"
|
||||
#include "Base/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -473,10 +474,28 @@ void Logger::Debug(CCStr fmt, va_list args)
|
||||
// Obtain information about the current stack level
|
||||
if (SQ_SUCCEEDED(sq_stackinfos(vm, 1, &si)))
|
||||
{
|
||||
m_Buffer.WriteF(ret, "\n[\n=>Location: %s\n=>Line: %d\n=>Function: %s\n]"
|
||||
, si.source ? si.source : _SC("unknown")
|
||||
, si.line
|
||||
, si.funcname ? si.funcname : _SC("unknown"));
|
||||
// Whether we should fall back to normal message
|
||||
bool fall_back = true;
|
||||
// Should (can) we include a snippet of code in the traceback?
|
||||
if (Core::Get().IsDebugging() && si.source && (si.line > 0)) {
|
||||
// Grab the associated line of code
|
||||
String code = Core::Get().FetchCodeLine(si.source, si.line-1, true);
|
||||
// Valid line of code?
|
||||
if (!code.empty())
|
||||
{
|
||||
m_Buffer.WriteF(ret, "\n[\n=>Location: %s\n=>Line: %d\n=>Function: %s\n=>Code: %s\n]"
|
||||
, si.source, si.line, si.funcname ? si.funcname : _SC("unknown"), code.c_str());
|
||||
fall_back = false; // No need to fall back to normal message!
|
||||
}
|
||||
}
|
||||
// Should the regular message be shown instead?
|
||||
if (fall_back)
|
||||
{
|
||||
m_Buffer.WriteF(ret, "\n[\n=>Location: %s\n=>Line: %d\n=>Function: %s\n]"
|
||||
, si.source ? si.source : _SC("unknown")
|
||||
, si.line
|
||||
, si.funcname ? si.funcname : _SC("unknown"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user