added pf_method_get_ip_source_line() and defined CompiledMethod::ipSourceLine
This commit is contained in:
parent
4afe4b459d
commit
d5475d79b6
@ -322,9 +322,10 @@ class(#pointer) CompiledMethod(Object)
|
||||
ntmprs,
|
||||
nargs,
|
||||
//code, <-- only if moo is built with MOO_USE_METHOD_TRAILER disable.
|
||||
source,
|
||||
source_file,
|
||||
source_line.
|
||||
source_text,
|
||||
dbi_file_offset,
|
||||
source_line,
|
||||
dbi_method_offset.
|
||||
|
||||
method preamble
|
||||
{
|
||||
@ -348,6 +349,7 @@ class(#pointer) CompiledMethod(Object)
|
||||
}
|
||||
|
||||
method(#primitive) sourceFile.
|
||||
method(#primitive) ipSourceLine: ip.
|
||||
|
||||
method sourceLine
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ while (ctx notNil)
|
||||
if (ctx class == MethodContext)
|
||||
{
|
||||
System logNl: (" " & ctx method owner name & ">>" & ctx method name &
|
||||
" (" & ctx method sourceFile & " " & ctx method sourceLine asString & ")").
|
||||
" (" & ctx method sourceFile & " " & (ctx method ipSourceLine: (ctx pc)) asString & ")").
|
||||
// TODO: get location of the current pc and include it... (ctx method sourceLine: ctx pc) asString dump.
|
||||
|
||||
}.
|
||||
|
@ -6782,7 +6782,6 @@ static int add_compiled_method (moo_t* moo)
|
||||
#else
|
||||
moo_oop_byte_t code;
|
||||
#endif
|
||||
moo_oop_t source_file;
|
||||
moo_oow_t tmp_count = 0;
|
||||
moo_oow_t i;
|
||||
moo_ooi_t preamble_code, preamble_index, preamble_flags;
|
||||
@ -6815,20 +6814,6 @@ static int add_compiled_method (moo_t* moo)
|
||||
moo_pushvolat (moo, (moo_oop_t*)&code); tmp_count++;
|
||||
#endif
|
||||
|
||||
if (cc->mth.code_start_loc.file)
|
||||
{
|
||||
/* TODO: make file names like symbols at least in this compiler. can also make it readonly.
|
||||
don't want to make it a symbol */
|
||||
source_file = moo_makestring(moo, cc->mth.code_start_loc.file, moo_count_oocstr(cc->mth.code_start_loc.file));
|
||||
if (!source_file) goto oops;
|
||||
moo_pushvolat (moo, (moo_oop_t*)&source_file); tmp_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 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;
|
||||
@ -6990,7 +6975,6 @@ static int add_compiled_method (moo_t* moo)
|
||||
MOO_STORE_OOP (moo, (moo_oop_t*)&mth->code, (moo_oop_t)code);
|
||||
#endif
|
||||
|
||||
MOO_STORE_OOP (moo, &mth->source_file, source_file);
|
||||
if (cc->mth.code_start_loc.line <= MOO_SMOOI_MAX)
|
||||
{
|
||||
mth->source_line = MOO_SMOOI_TO_OOP(cc->mth.code_start_loc.line);
|
||||
@ -7021,7 +7005,7 @@ static int add_compiled_method (moo_t* moo)
|
||||
/* TODO: warning */
|
||||
file_offset = 0;
|
||||
}
|
||||
mth->source_file = MOO_SMOOI_TO_OOP(file_offset);
|
||||
mth->dbi_file_offset = MOO_SMOOI_TO_OOP(file_offset);
|
||||
|
||||
if (moo_addmethodtodbgi(moo, file_offset, cc->dbgi_class_offset, cc->mth.name.ptr, cc->mth.code.locptr, cc->mth.code.len, &method_offset) <= -1)
|
||||
{
|
||||
@ -7030,9 +7014,9 @@ static int add_compiled_method (moo_t* moo)
|
||||
}
|
||||
else if (method_offset > MOO_SMOOI_MAX)
|
||||
{
|
||||
method_offset = 90;
|
||||
method_offset = 0;
|
||||
}
|
||||
/* TODO mth->code_sline = MOO_SMOOI_TO_OOP(method_offset); */
|
||||
mth->dbi_method_offset = MOO_SMOOI_TO_OOP(method_offset);
|
||||
}
|
||||
|
||||
/*TODO: preserve source??? mth->text = cc->mth.text
|
||||
|
@ -235,6 +235,7 @@ int moo_addmethodtodbgi (moo_t* moo, moo_oow_t file_offset, moo_oow_t class_offs
|
||||
di->_next = moo->dbgi->_last_method;
|
||||
di->_file = file_offset;
|
||||
di->_class = class_offset;
|
||||
di->code_loc_start = name_bytes_aligned;
|
||||
di->code_loc_len = code_loc_len;
|
||||
|
||||
moo_copy_oocstr ((moo_ooch_t*)(di + 1), name_len + 1, method_name);
|
||||
|
@ -2227,12 +2227,12 @@ static moo_pfrc_t pf_method_get_source_file (moo_t* moo, moo_mod_t* mod, moo_ooi
|
||||
|
||||
if (moo->dbgi)
|
||||
{
|
||||
if (MOO_OOP_IS_SMOOI(rcv->source_file) && MOO_OOP_TO_SMOOI(rcv->source_file) > 0)
|
||||
if (MOO_OOP_IS_SMOOI(rcv->dbi_file_offset) && MOO_OOP_TO_SMOOI(rcv->dbi_file_offset) > 0)
|
||||
{
|
||||
moo_dbgi_file_t* di;
|
||||
const moo_ooch_t* file_name;
|
||||
|
||||
di = (moo_dbgi_file_t*)&((moo_uint8_t*)moo->dbgi)[MOO_OOP_TO_SMOOI(rcv->source_file)];
|
||||
di = (moo_dbgi_file_t*)&((moo_uint8_t*)moo->dbgi)[MOO_OOP_TO_SMOOI(rcv->dbi_file_offset)];
|
||||
/* TODO: check if di is the file type... otherwise, it's internal corruption */
|
||||
|
||||
file_name = (const moo_ooch_t*)(di + 1);
|
||||
@ -2247,10 +2247,11 @@ static moo_pfrc_t pf_method_get_source_file (moo_t* moo, moo_mod_t* mod, moo_ooi
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_method_get_code_source_line (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
static moo_pfrc_t pf_method_get_ip_source_line (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
/* get source line of the given instruction pointer */
|
||||
moo_oop_method_t rcv;
|
||||
moo_oow_t line = 0;
|
||||
|
||||
rcv = (moo_oop_method_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo, MOO_CLASSOF(moo, rcv) == moo->_method);
|
||||
@ -2265,17 +2266,27 @@ static moo_pfrc_t pf_method_get_code_source_line (moo_t* moo, moo_mod_t* mod, mo
|
||||
|
||||
source_line = MOO_OOP_TO_SMOOI(rcv->source_line);
|
||||
ipv = MOO_OOP_TO_SMOOI(ip);
|
||||
#if 0
|
||||
if (MOO_OOP_IS_SMOOI(rcv->code_sline))
|
||||
|
||||
if (source_line >= 0 && ipv >= 0 && MOO_OOP_IS_SMOOI(rcv->dbi_method_offset))
|
||||
{
|
||||
moo_dbgi_method_t* di;
|
||||
moo_ooi_t dbi_method_offset;
|
||||
moo_oow_t* code_loc_ptr;
|
||||
|
||||
di = (moo_dbgi_method_t*)&((moo_uint8_t*)moo->dbgi)[MOO_OOP_TO_SMOOI(rcv->code_sline)];
|
||||
/* ... TODO .. */
|
||||
dbi_method_offset = MOO_OOP_TO_SMOOI(rcv->dbi_method_offset);
|
||||
di = (moo_dbgi_method_t*)&((moo_uint8_t*)moo->dbgi)[dbi_method_offset];
|
||||
|
||||
code_loc_ptr = (moo_oow_t*)((moo_uint8_t*)(di + 1) + di->code_loc_start);
|
||||
if (ipv < di->code_loc_len && code_loc_ptr[ipv] <= MOO_SMOOI_MAX)
|
||||
{
|
||||
line = code_loc_ptr[ipv] + source_line; /* this won't overflow but can exceed MOO_SMOOI_MAX */
|
||||
if (line > MOO_SMOOI_MAX) line = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* TODO: security check for data corruption? check if the ipv offset and the size calcualted doesn't exceed di->_len... */
|
||||
}
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(line));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
@ -4002,6 +4013,7 @@ static pf_t pftab[] =
|
||||
{ "Character_asError", { pf_character_as_error, 0, 0 } },
|
||||
{ "Character_asInteger", { pf_character_as_smooi, 0, 0 } },
|
||||
|
||||
{ "CompiledMethod_ipSourceLine:", { pf_method_get_ip_source_line, 1, 1 } },
|
||||
{ "CompiledMethod_sourceFile", { pf_method_get_source_file, 0, 0 } },
|
||||
|
||||
{ "Error_asCharacter", { pf_error_as_character, 0, 0 } },
|
||||
|
@ -555,9 +555,9 @@ struct moo_methsig_t
|
||||
};
|
||||
|
||||
#if defined(MOO_USE_METHOD_TRAILER)
|
||||
# define MOO_METHOD_NAMED_INSTVARS 10
|
||||
#else
|
||||
# define MOO_METHOD_NAMED_INSTVARS 11
|
||||
#else
|
||||
# define MOO_METHOD_NAMED_INSTVARS 12
|
||||
#endif
|
||||
typedef struct moo_method_t moo_method_t;
|
||||
typedef struct moo_method_t* moo_oop_method_t;
|
||||
@ -586,9 +586,9 @@ struct moo_method_t
|
||||
#endif
|
||||
|
||||
moo_oop_t source_text; /* source text. String if available. nil if not */
|
||||
moo_oop_t source_file; /* SmallInteger. source file path that contains the definition of this method. offset from moo->dbgi. 0 if unavailable */
|
||||
moo_oop_t source_line; /* SmallInteger. line of the source file where the method definition begins. valid only if source_file is greater than 0 */
|
||||
//moo_oop_t code_line; /* SmallInteger */
|
||||
moo_oop_t dbi_file_offset; /* SmallInteger. source file path that contains the definition of this method. offset from moo->dbgi. 0 if unavailable */
|
||||
moo_oop_t source_line; /* SmallInteger. line of the source file where the method definition begins. valid only if dbi_file_offset is greater than 0 */
|
||||
moo_oop_t dbi_method_offset; /* SmallInteger */
|
||||
|
||||
/* == variable indexed part == */
|
||||
moo_oop_t literal_frame[1]; /* it stores literals */
|
||||
@ -975,7 +975,7 @@ typedef struct moo_dbgi_file_t moo_dbgi_file_t;
|
||||
struct moo_dbgi_file_t
|
||||
{
|
||||
moo_oow_t _type;
|
||||
moo_oow_t _len;
|
||||
moo_oow_t _len; /* length of this record including the header and the file path payload */
|
||||
moo_oow_t _next;
|
||||
/* ... file path here ... */
|
||||
};
|
||||
@ -984,7 +984,7 @@ typedef struct moo_dbgi_class_t moo_dbgi_class_t;
|
||||
struct moo_dbgi_class_t
|
||||
{
|
||||
moo_oow_t _type;
|
||||
moo_oow_t _len;
|
||||
moo_oow_t _len; /* length of this record including the header and the class name payload */
|
||||
moo_oow_t _next; /* offset to a previous class */
|
||||
moo_oow_t _file;
|
||||
moo_oow_t _line;
|
||||
@ -995,13 +995,14 @@ typedef struct moo_dbgi_method_t moo_dbgi_method_t;
|
||||
struct moo_dbgi_method_t
|
||||
{
|
||||
moo_oow_t _type;
|
||||
moo_oow_t _len;
|
||||
moo_oow_t _len; /* length of this record including the header and the payload including method name and code line numbers */
|
||||
moo_oow_t _next;
|
||||
moo_oow_t _file;
|
||||
moo_oow_t _class;
|
||||
moo_oow_t code_loc_start; /* start offset from the payload beginning within this record */
|
||||
moo_oow_t code_loc_len;
|
||||
/* ... method name here ... */
|
||||
/* ... code info here ... */
|
||||
/* ... code line numbers here ... */
|
||||
};
|
||||
|
||||
/* =========================================================================
|
||||
|
@ -2915,6 +2915,9 @@ static MOO_INLINE void abort_all_moos (int unused)
|
||||
/* TODO: make this atomic */
|
||||
}
|
||||
|
||||
static MOO_INLINE void do_nothing (int unused)
|
||||
{
|
||||
}
|
||||
|
||||
/*#define MOO_TICKER_INTERVAL_USECS 10000*/ /* microseconds. 0.01 seconds */
|
||||
#define MOO_TICKER_INTERVAL_USECS 20000 /* microseconds. 0.02 seconds. */
|
||||
@ -3912,13 +3915,17 @@ void moo_uncatch_termreq (void)
|
||||
void moo_catch_termreq (void)
|
||||
{
|
||||
set_signal_handler(SIGTERM, abort_all_moos, 0);
|
||||
set_signal_handler(SIGHUP, abort_all_moos, 0);
|
||||
set_signal_handler(SIGINT, abort_all_moos, 0);
|
||||
set_signal_handler(SIGPIPE, do_nothing, 0);
|
||||
}
|
||||
|
||||
void moo_uncatch_termreq (void)
|
||||
{
|
||||
unset_signal_handler(SIGTERM);
|
||||
unset_signal_handler(SIGHUP);
|
||||
unset_signal_handler(SIGINT);
|
||||
unset_signal_handler(SIGPIPE);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user