pike.git/
src/
modules/
_Debug/
debug.cmod
Branch:
Tag:
Non-build tags
All tags
No tags
2015-04-10
2015-04-10 14:20:19 by Martin Nilsson <nilsson@opera.com>
4e5a84f551ae6e257f05ce76860d6d94150ec07a (
62
lines) (+
62
/-
0
)
[
Show
|
Annotate
]
Branch:
8.1
Moved disassemble into _Debug.
323:
#endif /* YYDEBUG */
+
#if defined(PIKE_PORTABLE_BYTECODE)
+
+
/*! @decl void disassemble(function fun)
+
*! @belongs Debug
+
*!
+
*! Disassemble a Pike function to @[Stdio.stderr].
+
*!
+
*! @note
+
*! This function is only available if the Pike runtime
+
*! has been compiled with debug enabled.
+
*/
+
PIKEFUN void disassemble(function fun)
+
{
+
if ((TYPEOF(*fun) != T_FUNCTION) ||
+
(SUBTYPEOF(*fun) == FUNCTION_BUILTIN)) {
+
fprintf(stderr,
+
"Disassembly only supported for functions implemented in Pike.\n");
+
} else if (!fun->u.object->prog) {
+
fprintf(stderr, "Function in destructed object.\n");
+
} else {
+
int f = SUBTYPEOF(*fun);
+
struct reference *ptr = PTR_FROM_INT(fun->u.object->prog, f);
+
struct program *p = PROG_FROM_PTR(fun->u.object->prog, ptr);
+
struct identifier *id = p->identifiers + ptr->identifier_offset;
+
if (id->func.offset >= 0) {
+
struct pike_string *tripples =
+
p->strings[read_program_data(p->program + id->func.offset, -1)];
+
switch(tripples->size_shift) {
+
#define CASE(SHIFT) \
+
case SHIFT: \
+
{ \
+
PIKE_CONCAT(p_wchar, SHIFT) *str = \
+
PIKE_CONCAT(STR, SHIFT)(tripples); \
+
int i=0; \
+
while(i < tripples->len) { \
+
fprintf(stderr, "@@@ %d: %s, %d, %d\n", \
+
i/3, \
+
instrs[*str - F_OFFSET]. \
+
name, \
+
str[1], str[2]); \
+
str += 3; \
+
i += 3; \
+
} \
+
} \
+
break
+
CASE(0);
+
CASE(1);
+
CASE(2);
+
#undef CASE
+
}
+
} else {
+
fprintf(stderr, "Prototype.\n");
+
}
+
}
+
pop_n_elems(args);
+
push_int(0);
+
}
+
+
#endif /* PIKE_PORTABLE_BYTECODE */
+
+
#endif /* PIKE_DEBUG */ PIKE_MODULE_INIT