export moo_backtrace()

added textual description for semaphore's io type
This commit is contained in:
hyunghwan.chung 2018-05-17 15:33:36 +00:00
parent 70f17d8896
commit faef93e7d7
3 changed files with 28 additions and 11 deletions

View File

@ -474,7 +474,7 @@ void moo_setsynerr (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, con
* STACK FRAME BACKTRACE
* -------------------------------------------------------------------------- */
#if defined(MOO_ENABLE_LIBUNWIND)
static void backtrace_stack_frames (moo_t* moo)
void moo_backtrace (moo_t* moo)
{
unw_cursor_t cursor;
unw_context_t context;
@ -503,7 +503,7 @@ static void backtrace_stack_frames (moo_t* moo)
}
}
#elif defined(HAVE_BACKTRACE)
static void backtrace_stack_frames (moo_t* moo)
void moo_backtrace (moo_t* moo)
{
void* btarray[128];
moo_oow_t btsize;
@ -524,7 +524,7 @@ static void backtrace_stack_frames (moo_t* moo)
}
}
#else
static void backtrace_stack_frames (moo_t* moo)
void moo_backtrace (moo_t* moo)
{
/* do nothing. not supported */
}
@ -537,8 +537,11 @@ static void backtrace_stack_frames (moo_t* moo)
void moo_assertfailed (moo_t* moo, const moo_bch_t* expr, const moo_bch_t* file, moo_oow_t line)
{
#if defined(MOO_BUILD_RELEASE)
/* do nothing */
#else
moo_logbfmt (moo, MOO_LOG_UNTYPED | MOO_LOG_FATAL, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line);
backtrace_stack_frames (moo);
moo_backtrace (moo);
#if defined(_WIN32)
ExitProcess (249);
@ -565,4 +568,6 @@ void moo_assertfailed (moo_t* moo, const moo_bch_t* expr, const moo_bch_t* file,
kill (getpid(), SIGABRT);
_exit (1);
#endif
#endif
}

View File

@ -32,6 +32,12 @@
#define PROC_STATE_SUSPENDED 0
#define PROC_STATE_TERMINATED -1
static const char* io_type_str[] =
{
"input",
"output"
};
static MOO_INLINE const char* proc_state_to_string (int state)
{
static const moo_bch_t* str[] =
@ -1223,7 +1229,7 @@ static int add_sem_to_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, moo_ooi
{
if (moo->sem_io_tuple[index].sem[io_type])
{
moo_seterrbfmt (moo, MOO_EINVAL, "handle %zd linked with an IO semaphore of type %d", io_handle, (int)io_type);
moo_seterrbfmt (moo, MOO_EINVAL, "handle %zd already linked with an IO semaphore for %hs", io_handle, io_type_str[io_type]);
return -1;
}
@ -1237,11 +1243,11 @@ static int add_sem_to_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, moo_ooi
if (n <= -1)
{
MOO_LOG3 (moo, MOO_LOG_WARN, "Failed to add an IO semaphore at index %zd of type %d on handle %zd\n", index, (int)io_type, io_handle);
MOO_LOG3 (moo, MOO_LOG_WARN, "Failed to add an IO semaphore at index %zd for %hs on handle %zd\n", index, io_type_str[io_type], io_handle);
return -1;
}
MOO_LOG3 (moo, MOO_LOG_DEBUG, "Added an IO semaphore at index %zd of type %d on handle %zd\n", index, (int)io_type, io_handle);
MOO_LOG3 (moo, MOO_LOG_DEBUG, "Added an IO semaphore at index %zd for %hs on handle %zd\n", index, io_type_str[io_type], io_handle);
sem->subtype = MOO_SMOOI_TO_OOP(MOO_SEMAPHORE_SUBTYPE_IO);
sem->u.io.index = MOO_SMOOI_TO_OOP(index);
@ -1304,7 +1310,7 @@ static int delete_sem_from_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, in
moo_poptmp (moo);
if (x <= -1)
{
MOO_LOG3 (moo, MOO_LOG_WARN, "Failed to delete an IO semaphored handle %zd at index %zd of type %d\n", io_handle, index, (int)io_type);
MOO_LOG3 (moo, MOO_LOG_WARN, "Failed to delete an IO semaphored handle %zd at index %zd for %hs\n", io_handle, index, io_type_str[io_type]);
if (!force) return -1;
/* NOTE:
@ -1317,7 +1323,7 @@ static int delete_sem_from_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, in
}
else
{
MOO_LOG3 (moo, MOO_LOG_DEBUG, "Deleted an IO semaphored handle %zd at index %zd of type %d\n", io_handle, index, (int)io_type);
MOO_LOG3 (moo, MOO_LOG_DEBUG, "Deleted an IO semaphored handle %zd at index %zd for %hs\n", io_handle, index, io_type_str[io_type]);
}
sem->subtype = moo->_nil;
@ -1420,7 +1426,9 @@ static void signal_io_semaphore (moo_t* moo, moo_ooi_t io_handle, moo_ooi_t mask
}
else
{
MOO_LOG1 (moo, MOO_LOG_WARN, "Warning - semaphore signaling requested on an unmapped handle %zd\n", io_handle);
/* you may come across this warning message if the multiplexer returned
* an IO event */
MOO_LOG2 (moo, MOO_LOG_WARN, "Warning - semaphore signaling requested on an unmapped handle %zd with mask %#zx\n", io_handle, mask);
}
}
@ -2710,7 +2718,7 @@ static moo_pfrc_t __system_add_io_semaphore (moo_t* moo, moo_ooi_t nargs, moo_se
if (add_sem_to_sem_io_tuple(moo, sem, MOO_OOP_TO_SMOOI(fd), io_type) <= -1)
{
const moo_ooch_t* oldmsg = moo_backuperrmsg(moo);
moo_seterrbfmt (moo, moo->errnum, "cannot add the handle %zd to the multiplexer - %js", MOO_OOP_TO_SMOOI(fd), oldmsg);
moo_seterrbfmt (moo, moo->errnum, "unable to add the handle %zd to the multiplexer for %hs - %js", MOO_OOP_TO_SMOOI(fd), io_type_str[io_type], oldmsg);
return MOO_PF_FAILURE;
}

View File

@ -2242,6 +2242,10 @@ MOO_EXPORT int moo_decode (
const moo_oocs_t* classfqn
);
MOO_EXPORT void moo_backtrace (
moo_t* moo
);
MOO_EXPORT void moo_assertfailed (
moo_t* moo,
const moo_bch_t* expr,