From fba3c3213cb7a826c9e7dbf5e4a81c2d69d8376e Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sun, 7 Jul 2019 15:24:27 +0000 Subject: [PATCH] attempting to store the source location information collected while compiling into the moo_dbginfo_t data structure --- moo/bin/main.c | 9 +++++++++ moo/lib/comp.c | 2 +- moo/lib/debug.c | 34 ++++++++++++++++++++++++++++++++++ moo/lib/moo.c | 2 ++ moo/lib/moo.h | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) diff --git a/moo/bin/main.c b/moo/bin/main.c index b68cc4a..5759c9b 100644 --- a/moo/bin/main.c +++ b/moo/bin/main.c @@ -240,6 +240,15 @@ int main (int argc, char* argv[]) return -1; } + /* TODO: don't initialize debug information if debug info is not requested. + * call moo_loaddbginfo() if loading a compiled image... */ + if (moo_initdbginfo(moo, 102400) <= -1) /* TODO: set initial debug information size from a configurable value */ + { + moo_logbfmt (moo, MOO_LOG_STDERR, "ERROR: cannot initialize debug information - [%d] %js\n", moo_geterrnum(moo), moo_geterrstr(moo)); + moo_close (moo); + return -1; + } + /* #if defined(macintosh) i = 20; diff --git a/moo/lib/comp.c b/moo/lib/comp.c index e70e940..e808bb4 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -6824,7 +6824,7 @@ static int add_compiled_method (moo_t* moo) /* the method has been read in from the main souce stream */ source_file = moo->_nil; } - + preamble_code = MOO_METHOD_PREAMBLE_NONE; preamble_index = 0; preamble_flags = 0; diff --git a/moo/lib/debug.c b/moo/lib/debug.c index 6a056d9..2268b50 100644 --- a/moo/lib/debug.c +++ b/moo/lib/debug.c @@ -66,3 +66,37 @@ void moo_dumpdic (moo_t* moo, moo_oop_dic_t dic, const moo_bch_t* title) } MOO_DEBUG0 (moo, "--------------------------------------------\n"); } + + +/* TODO: moo_loaddbginfofromimage() -> load debug information from compiled image? +moo_storedbginfotoimage()? -> store debug information to compiled image? +moo_compactdbginfo()? -> compact debug information by scaning dbginfo data. find class and method. if not found, drop the portion. +*/ + +int moo_initdbginfo (moo_t* moo, moo_oow_t capa) +{ + moo_dbginfo_t* info; + + info = (moo_dbginfo_t*)moo_allocmem(moo, MOO_SIZEOF(*info) + capa); + if (!info) return -1; + + info->_capa = capa; + info->_len = 0; + + moo->dbginfo = info; + return 0; +} + +void moo_finidbginfo (moo_t* moo) +{ + if (moo->dbginfo) + { + moo_freemem (moo, moo->dbginfo); + moo->dbginfo = MOO_NULL; + } +} + +int moo_addmethodtodbginfo (moo_t* moo, const moo_uch_t* class_name, const moo_uch_t* method_name) +{ + return 0; +} \ No newline at end of file diff --git a/moo/lib/moo.c b/moo/lib/moo.c index a254e55..12bda5a 100644 --- a/moo/lib/moo.c +++ b/moo/lib/moo.c @@ -249,6 +249,8 @@ void moo_fini (moo_t* moo) * the heap may not exist */ if (moo->heap) moo_killheap (moo, moo->heap); + moo_finidbginfo (moo); + for (i = 0; i < MOO_COUNTOF(moo->sbuf); i++) { if (moo->sbuf[i].ptr) diff --git a/moo/lib/moo.h b/moo/lib/moo.h index 1bcddc7..27628d0 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -944,6 +944,14 @@ struct moo_heap_t moo_space_t newspace; }; +typedef struct moo_dbginfo_t moo_dbginfo_t; +struct moo_dbginfo_t +{ + moo_oow_t _capa; + moo_oow_t _len; + /* actual information is recorded here */ +}; + /* ========================================================================= * VM LOGGING * ========================================================================= */ @@ -1423,6 +1431,7 @@ struct moo_t /* ========================= */ moo_heap_t* heap; + moo_dbginfo_t* dbginfo; /* ============================================================= * nil, true, false @@ -2050,6 +2059,14 @@ MOO_EXPORT int moo_invoke ( const moo_oocs_t* mthname ); + +/** + * The moo_abort() function requests to stop on-going execution. + * On-going execution doesn't get terminated immediately when this function + * returns. Termination of execution is honored by the virtual machine. + * If the virtual machine is in a blocking context, termination will only + * occur after it gets out of the blocking context. + */ MOO_EXPORT void moo_abort ( moo_t* moo ); @@ -2061,6 +2078,23 @@ MOO_EXPORT void moo_abort ( # define moo_switchprocess(moo) ((moo)->switch_proc = 1) #endif +/* ========================================================================= + * DEBUG SUPPORT + * ========================================================================= */ + +MOO_EXPORT int moo_initdbginfo ( + moo_t* moo, + moo_oow_t init_capa +); + +/** + * The moo_finidbginfo() function deletes the debug information. + * It is called by moo_close(). Unless you want the debug information to + * be deleted earlier, you need not call this function explicitly. + */ +MOO_EXPORT void moo_finidbginfo ( + moo_t* moo +); /* ========================================================================= * COMMON OBJECT MANAGEMENT FUNCTIONS * ========================================================================= */