writing some debug information tracking functions

This commit is contained in:
hyunghwan.chung 2019-07-08 07:51:53 +00:00
parent fba3c3213c
commit b88900eda2
3 changed files with 165 additions and 11 deletions

View File

@ -75,15 +75,19 @@ moo_compactdbginfo()? -> compact debug information by scaning dbginfo data. find
int moo_initdbginfo (moo_t* moo, moo_oow_t capa) int moo_initdbginfo (moo_t* moo, moo_oow_t capa)
{ {
moo_dbginfo_t* info; moo_dbginfo_t* tmp;
info = (moo_dbginfo_t*)moo_allocmem(moo, MOO_SIZEOF(*info) + capa); if (capa < MOO_SIZEOF(*tmp)) capa = MOO_SIZEOF(*tmp);
if (!info) return -1;
info->_capa = capa; tmp = (moo_dbginfo_t*)moo_callocmem(moo, capa);
info->_len = 0; if (!tmp) return -1;
moo->dbginfo = info; tmp->_capa = capa;
tmp->_len = MOO_SIZEOF(*tmp);
tmp->_last_class = 0;
tmp->_last_file = 0;
moo->dbginfo = tmp;
return 0; return 0;
} }
@ -96,7 +100,110 @@ void moo_finidbginfo (moo_t* moo)
} }
} }
int moo_addmethodtodbginfo (moo_t* moo, const moo_uch_t* class_name, const moo_uch_t* method_name) static MOO_INLINE secure_dbginfo_space (moo_t* moo, moo_oow_t req_bytes)
{ {
if (moo->dbginfo->_capa - moo->dbginfo->_len < req_bytes)
{
moo_dbginfo_t* tmp;
moo_oow_t newcapa;
newcapa = moo->dbginfo->_len + req_bytes;
newcapa = MOO_ALIGN_POW2(newcapa, 65536); /* TODO: make the align value configurable */
tmp = moo_reallocmem(moo, moo->dbginfo, newcapa);
if (!tmp) return -1;
moo->dbginfo = tmp;
moo->dbginfo->_capa = newcapa;
}
return 0; return 0;
} }
int moo_addclasstodbginfo (moo_t* moo, const moo_ooch_t* class_name, moo_oow_t* start_offset)
{
moo_oow_t name_len, name_bytes, name_bytes_aligned, req_bytes;
moo_dbginfo_class_t* di;
if (!moo->dbginfo) return 0; /* debug information is disabled*/
name_len = moo_count_oocstr(class_name);
name_bytes = name_len * MOO_SIZEOF(*class_name);
name_bytes_aligned = MOO_ALIGN_POW2(name_bytes, MOO_SIZEOF_OOW_T);
req_bytes = MOO_SIZEOF(moo_dbginfo_class_t) + name_bytes_aligned;
if (secure_dbginfo_space(moo, req_bytes) <= -1) return -1;
di = (moo_dbginfo_class_t*)&((moo_uint8_t*)moo->dbginfo)[moo->dbginfo->_len];
di->_type = MOO_DBGINFO_MAKE_TYPE(MOO_DBGINFO_TYPE_CODE_CLASS, 0);
di->_len = name_len;
di->_next = moo->dbginfo->_last_class;
MOO_MEMCPY (di + 1, class_name, name_len * MOO_SIZEOF(*class_name));
/* TODO: set '\0' after file names? */
moo->dbginfo->_last_class = moo->dbginfo->_len;
moo->dbginfo->_len += req_bytes;
if (start_offset) *start_offset = moo->dbginfo->_last_class;
return 0;
}
int moo_addfiletodbginfo (moo_t* moo, const moo_ooch_t* file_name, moo_oow_t* start_offset)
{
moo_oow_t name_len, name_bytes, name_bytes_aligned, req_bytes;
moo_dbginfo_file_t* di;
if (!moo->dbginfo) return 0; /* debug information is disabled*/
name_len = moo_count_oocstr(file_name);
name_bytes = name_len * MOO_SIZEOF(*file_name);
name_bytes_aligned = MOO_ALIGN_POW2(name_bytes, MOO_SIZEOF_OOW_T);
req_bytes = MOO_SIZEOF(moo_dbginfo_file_t) + name_bytes_aligned;
if (secure_dbginfo_space(moo, req_bytes) <= -1) return -1;
di = (moo_dbginfo_file_t*)&((moo_uint8_t*)moo->dbginfo)[moo->dbginfo->_len];
di->_type = MOO_DBGINFO_MAKE_TYPE(MOO_DBGINFO_TYPE_CODE_FILE, 0);
di->_len = name_len;
di->_next = moo->dbginfo->_last_file;
MOO_MEMCPY (di + 1, file_name, name_len * MOO_SIZEOF(*file_name));
/* TODO: set '\0' after file names? */
moo->dbginfo->_last_file = moo->dbginfo->_len;
moo->dbginfo->_len += req_bytes;
if (start_offset) *start_offset = moo->dbginfo->_last_file;
return 0;
}
#if 0
int moo_addmethodtodbginfo (moo_t* moo, const moo_ooch_t* class_name, const moo_ooch_t* method_name, const moo_ooch_t* file_name)
{
moo_oow_t name_len, name_bytes, name_bytes_aligned, req_bytes;
moo_dbginfo_file_t* di;
if (!moo->dbginfo) return 0; /* debug information is disabled*/
name_len = moo_count_oocstr(file_name);
name_bytes = name_len * MOO_SIZEOF(*file_name);
name_bytes_aligned = MOO_ALIGN_POW2(name_bytes, MOO_SIZEOF_OOW_T);
req_bytes = MOO_SIZEOF(moo_dbginfo_file_t) + name_bytes_aligned;
if (secure_dbginfo_space(moo, req_bytes) <= -1) return -1;
di = (moo_dbginfo_file_t*)&((moo_uint8_t*)moo->dbginfo)[moo->dbginfo->_len];
di->_type = MOO_DBGINFO_MAKE_TYPE(MOO_DBGINFO_TYPE_CODE_FILE, 0);
di->_len = name_len;
di->_next = moo->dbginfo->_last_file;
MOO_MEMCPY (di + 1, file_name, name_len * MOO_SIZEOF(*file_name));
/* TODO: set '\0' after file names? */
moo->dbginfo->_last_file = moo->dbginfo->_len;
moo->dbginfo->_len += req_bytes;
if (start_offset) *start_offset = moo->dbginfo->_last_file;
return 0;
}
#endif

View File

@ -949,9 +949,56 @@ struct moo_dbginfo_t
{ {
moo_oow_t _capa; moo_oow_t _capa;
moo_oow_t _len; moo_oow_t _len;
moo_oow_t _last_class; /* offset to the last class element added */
moo_oow_t _last_file; /* offset to the last file element added */
/* actual information is recorded here */ /* actual information is recorded here */
}; };
enum moo_dbginfo_type_t
{
/* bit 8 to bit 15 */
MOO_DBGINFO_TYPE_CODE_CLASS = 0,
MOO_DBGINFO_TYPE_CODE_FILE = 1,
MOO_DBGINFO_TYPE_CODE_METHOD = 2,
/* low 8 bits */
MOO_DBGINFO_TYPE_FLAG_INVALID = (1 << 0)
};
typedef enum moo_dbginfo_type_t moo_dbginfo_type_t;
#define MOO_DBGINFO_MAKE_TYPE(code,flags) (((code) << 8) | (flags))
typedef struct moo_dbginfo_class_t moo_dbginfo_class_t;
struct moo_dbginfo_class_t
{
moo_oow_t _type;
moo_oow_t _len;
moo_oow_t _next; /* offset to a previous class */
/* ... class name here ... */
};
typedef struct moo_dbginfo_file_t moo_dbginfo_file_t;
struct moo_dbginfo_file_t
{
moo_oow_t _type;
moo_oow_t _len;
moo_oow_t _next;
/* ... file path here ... */
};
typedef struct moo_dbginfo_method_t moo_dbginfo_method_t;
struct moo_dbginfo_method_t
{
moo_oow_t _type;
moo_oow_t _name_len;
moo_oow_t _code_len;
moo_oow_t _next;
moo_oow_t _class;
moo_oow_t _file;
/* ... method name here ... */
/* ... code info here ... */
};
/* ========================================================================= /* =========================================================================
* VM LOGGING * VM LOGGING
* ========================================================================= */ * ========================================================================= */

View File

@ -1745,8 +1745,8 @@ static int _add_poll_fd (moo_t* moo, int fd, int event_mask)
moo_oow_t newcapa; moo_oow_t newcapa;
newcapa = MOO_ALIGN_POW2 (xtn->ev.reg.len + 1, 256); newcapa = MOO_ALIGN_POW2 (xtn->ev.reg.len + 1, 256);
tmp = (struct pollfd*)moo_reallocmem (moo, xtn->ev.reg.ptr, newcapa * MOO_SIZEOF(*tmp)); tmp = (struct pollfd*)moo_reallocmem(moo, xtn->ev.reg.ptr, newcapa * MOO_SIZEOF(*tmp));
tmp2 = (struct pollfd*)moo_reallocmem (moo, xtn->ev.buf, newcapa * MOO_SIZEOF(*tmp2)); tmp2 = (struct pollfd*)moo_reallocmem(moo, xtn->ev.buf, newcapa * MOO_SIZEOF(*tmp2));
if (!tmp || !tmp2) if (!tmp || !tmp2)
{ {
MOO_DEBUG2 (moo, "Cannot add file descriptor %d to poll - %hs\n", fd, strerror(errno)); MOO_DEBUG2 (moo, "Cannot add file descriptor %d to poll - %hs\n", fd, strerror(errno));