Unverified Commit 635b21be authored by Jake Stine's avatar Jake Stine Committed by GitHub
Browse files

Add lua backtrace info to lutro_error/alter/assert (#207)

The backtraces are looking... not so great in some of my tests. Lua has a bad habit sometimes of obscuring function names. There's sometimes some ways to improve that but I'll have to dig more later and figure out exactly what's going on.
parent f3468c5d
......@@ -118,11 +118,12 @@ static void dumpstack( lua_State* L )
int _lutro_assertf_internal(int ignorable, const char *fmt, ...)
{
fflush(NULL);
va_list argptr;
va_start(argptr, fmt);
vfprintf(stderr, fmt, argptr);
va_end(argptr);
fflush(NULL);
// tips: the fmt input should always be in the predefined format of:
// FILE(LINE): assertion `cond` failed.
......@@ -132,6 +133,19 @@ int _lutro_assertf_internal(int ignorable, const char *fmt, ...)
// We can use this knowledge to parse the file and line positions and perform additional clever filtering
// or log prep/routing.
int top = lua_gettop(L);
lua_getglobal(L, "debug");
lua_getfield(L, -1, "traceback");
lua_pushstring(L, "");
lua_pushinteger(L, 2);
lua_call(L, 2, 1);
fflush(NULL);
const char* msg = lua_tostring(L, -1);
while (*msg == '\r' || *msg == '\n') ++msg; // lua pads some newlines at the beginning.. strip 'em
fprintf(stderr, "%s\n", msg);
lua_pop(L, 1);
if (ignorable)
{
// TODO : suspend the core, show up some user dialog via libretro api?
......@@ -169,6 +183,7 @@ int traceback(lua_State *L) {
// and produces a summary report of unique errors)
//tool_errorf("%s\n", lua_tostring(L, -1));
fflush(NULL);
fprintf(stderr, "%s\n", lua_tostring(L, -1));
return 1;
......
......@@ -48,19 +48,19 @@ typedef enum
extern int _lutro_assertf_internal(int ignorable, const char *fmt, ...);
#define _base_hard_error() ((void)( ((_lutro_assertf_internal(AssertUnrecoverable, __FILE__ "(%d):unrecoverable error " "\n", __LINE__ ),1) && (abort(), 0))))
#define _base_hard_errorf(msg, ...) ((void)( ((_lutro_assertf_internal(AssertUnrecoverable, __FILE__ "(%d):unrecoverable error " msg "\n", __LINE__, ## __VA_ARGS__),1) && (abort(), 0))))
#define _base_soft_alert() ((void)( ((_lutro_assertf_internal(AssertIgnorable, __FILE__ "(%d):alert " "\n", __LINE__ ) ) && (abort(), 0))))
#define _base_soft_alertf(msg, ...) ((void)( ((_lutro_assertf_internal(AssertIgnorable, __FILE__ "(%d):alert " msg "\n", __LINE__, ## __VA_ARGS__) ) && (abort(), 0))))
#define _base_soft_error() ((void)( ((_lutro_assertf_internal(AssertErrorOnly, __FILE__ "(%d):error " "\n", __LINE__ ),0) )))
#define _base_soft_errorf(msg, ...) ((void)( ((_lutro_assertf_internal(AssertErrorOnly, __FILE__ "(%d):error " msg "\n", __LINE__, ## __VA_ARGS__),0) )))
#define _base_cond_error(cond) ((void)((cond) || ((_lutro_assertf_internal(AssertErrorOnly, __FILE__ "(%d):assertion `%s` failed. " "\n", __LINE__, #cond ),0) )))
#define _base_cond_errorf(cond, msg, ...) ((void)((cond) || ((_lutro_assertf_internal(AssertErrorOnly, __FILE__ "(%d):assertion `%s` failed. " msg "\n", __LINE__, #cond , ## __VA_ARGS__),0) )))
#define _base_hard_assert(cond) ((void)((cond) || ((_lutro_assertf_internal(AssertUnrecoverable, __FILE__ "(%d):assertion `%s` failed. " "\n", __LINE__, #cond ),1) && (abort(), 0))))
#define _base_hard_assertf(cond, msg, ...) ((void)((cond) || ((_lutro_assertf_internal(AssertUnrecoverable, __FILE__ "(%d):assertion `%s` failed. " msg "\n", __LINE__, #cond , ## __VA_ARGS__),1) && (abort(), 0))))
#define _base_soft_assert(cond) ((void)((cond) || ((_lutro_assertf_internal(AssertIgnorable, __FILE__ "(%d):assertion `%s` failed. " "\n", __LINE__, #cond ) ) && (abort(), 0))))
#define _base_soft_assertf(cond, msg, ...) ((void)((cond) || ((_lutro_assertf_internal(AssertIgnorable, __FILE__ "(%d):assertion `%s` failed. " msg "\n", __LINE__, #cond , ## __VA_ARGS__) ) && (abort(), 0))))
#define _base_hard_error() ((void)( ((_lutro_assertf_internal(AssertUnrecoverable, __FILE__ "(%d): unrecoverable error " "\n", __LINE__ ),1) && (abort(), 0))))
#define _base_hard_errorf(msg, ...) ((void)( ((_lutro_assertf_internal(AssertUnrecoverable, __FILE__ "(%d): unrecoverable error " msg "\n", __LINE__, ## __VA_ARGS__),1) && (abort(), 0))))
#define _base_soft_alert() ((void)( ((_lutro_assertf_internal(AssertIgnorable, __FILE__ "(%d): alert " "\n", __LINE__ ) ) && (abort(), 0))))
#define _base_soft_alertf(msg, ...) ((void)( ((_lutro_assertf_internal(AssertIgnorable, __FILE__ "(%d): alert " msg "\n", __LINE__, ## __VA_ARGS__) ) && (abort(), 0))))
#define _base_soft_error() ((void)( ((_lutro_assertf_internal(AssertErrorOnly, __FILE__ "(%d): error " "\n", __LINE__ ),0) )))
#define _base_soft_errorf(msg, ...) ((void)( ((_lutro_assertf_internal(AssertErrorOnly, __FILE__ "(%d): error " msg "\n", __LINE__, ## __VA_ARGS__),0) )))
#define _base_cond_error(cond) ((void)((cond) || ((_lutro_assertf_internal(AssertErrorOnly, __FILE__ "(%d): assertion `%s` failed. " "\n", __LINE__, #cond ),0) )))
#define _base_cond_errorf(cond, msg, ...) ((void)((cond) || ((_lutro_assertf_internal(AssertErrorOnly, __FILE__ "(%d): assertion `%s` failed. " msg "\n", __LINE__, #cond , ## __VA_ARGS__),0) )))
#define _base_hard_assert(cond) ((void)((cond) || ((_lutro_assertf_internal(AssertUnrecoverable, __FILE__ "(%d): assertion `%s` failed. " "\n", __LINE__, #cond ),1) && (abort(), 0))))
#define _base_hard_assertf(cond, msg, ...) ((void)((cond) || ((_lutro_assertf_internal(AssertUnrecoverable, __FILE__ "(%d): assertion `%s` failed. " msg "\n", __LINE__, #cond , ## __VA_ARGS__),1) && (abort(), 0))))
#define _base_soft_assert(cond) ((void)((cond) || ((_lutro_assertf_internal(AssertIgnorable, __FILE__ "(%d): assertion `%s` failed. " "\n", __LINE__, #cond ) ) && (abort(), 0))))
#define _base_soft_assertf(cond, msg, ...) ((void)((cond) || ((_lutro_assertf_internal(AssertIgnorable, __FILE__ "(%d): assertion `%s` failed. " msg "\n", __LINE__, #cond , ## __VA_ARGS__) ) && (abort(), 0))))
// lutro error reporting. Errors come in two forms:
// - error / alert /fail (no condition is provided in the paramters)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment