Author: jrieks
Date: Fri Apr 15 05:05:07 2005
New Revision: 7843
Modified:
trunk/classes/continuation.pmc
trunk/classes/null.pmc
trunk/classes/sub.pmc
trunk/include/parrot/debug.h
trunk/include/parrot/sub.h
trunk/lib/Parrot/Pmc2c.pm
trunk/src/debug.c
trunk/src/inter_run.c
trunk/src/sub.c
trunk/t/pmc/fixedpmcarray.t
trunk/t/pmc/sub.t
Log:
- added PDB_backtrace
- moved classes/sub.pmc:sub_name to src/sub.c:Parrot_full_sub_name
- show backtrace after PMCNULL access
- minor test adjustments (Sub's getstring now returns namespace+" :: "+subname)
- typo fixed
Modified: trunk/classes/continuation.pmc
==============================================================================
--- trunk/classes/continuation.pmc (original)
+++ trunk/classes/continuation.pmc Fri Apr 15 05:05:07 2005
@@ -205,8 +205,7 @@
PMC *sub = INTERP->ctx.current_sub;
STRING *unk = CONST_STRING(INTERP, "(unknown");
PIO_eprintf(INTERP, "# Back in sub '%Ss'\n",
- sub && PMC_sub(sub) && PMC_sub(sub)->name ?
- PMC_sub(sub)->name : unk);
+ Parrot_full_sub_name(INTERP, sub));
}
if (cc->address)
copy_regs(INTERP, caller_regs);
@@ -242,7 +241,7 @@
PMC_sub(caller)->seg->base.data;
s = Parrot_sprintf_c(INTERP,
"called from Sub '%Ss' pc %d\n",
- PMC_sub(caller)->name, (int)offs);
+ Parrot_full_sub_name(INTERP, caller), (int)offs);
}
return s;
}
Modified: trunk/classes/null.pmc
==============================================================================
--- trunk/classes/null.pmc (original)
+++ trunk/classes/null.pmc Fri Apr 15 05:05:07 2005
@@ -21,6 +21,12 @@
#include "parrot/parrot.h"
+static void
+show_backtrace(int ret, void *interp)
+{
+ PDB_backtrace( (Interp*)interp );
+}
+
pmclass Null singleton {
/*
Modified: trunk/classes/sub.pmc
==============================================================================
--- trunk/classes/sub.pmc (original)
+++ trunk/classes/sub.pmc Fri Apr 15 05:05:07 2005
@@ -21,29 +21,6 @@
#include "parrot/parrot.h"
#include <assert.h>
-/*
-
-=item C<sub_name>
-
-Print name and location of subroutine, This should finally use the label
-name of the frozen C<Sub> PMC image for now locate the C<Sub> name in
-the globals.
-
-=cut
-
-*/
-
-static STRING*
-sub_name(Interp* interpreter, PMC* sub)
-{
- struct Parrot_sub * s = PMC_sub(sub);
-
- if (s->name) {
- return s->name;
- }
- return NULL;
-}
-
static void
clear_fixup(Interp* interpreter, PMC* self)
{
@@ -79,7 +56,7 @@
/* sub was located via globals */
PIO_eprintf(interpreter, "# Calling sub '%Ss'\n#",
- sub_name(interpreter, sub));
+ Parrot_full_sub_name(interpreter, sub));
print_pbc_location(interpreter);
}
@@ -143,7 +120,7 @@
return;
#if 0
{
- STRING *n = sub_name(INTERP, SELF);
+ STRING *n = Parrot_full_sub_name(INTERP, SELF);
fprintf(stderr, "DESTROY sub %p %s\n", SELF,
n && n->strstart ? (char*)n->strstart : "???");
}
@@ -164,7 +141,7 @@
*/
STRING* get_string () {
- return sub_name(INTERP, SELF);
+ return Parrot_full_sub_name(INTERP, SELF);
}
/*
Modified: trunk/include/parrot/debug.h
==============================================================================
--- trunk/include/parrot/debug.h (original)
+++ trunk/include/parrot/debug.h Fri Apr 15 05:05:07 2005
@@ -280,6 +280,7 @@
void PDB_help(Interp *interpreter, const char *command);
+void PDB_backtrace(Interp *interpreter);
#define c_b 25245
#define c_c 25500
Modified: trunk/include/parrot/sub.h
==============================================================================
--- trunk/include/parrot/sub.h (original)
+++ trunk/include/parrot/sub.h Fri Apr 15 05:05:07 2005
@@ -103,6 +103,7 @@
void invalidate_retc_context(Interp *interpreter, struct Parrot_Context *);
void add_to_retc_cache(Interp *interpreter, PMC *pmc);
void mark_retc_cache(Interp *);
+STRING* Parrot_full_sub_name(Interp* interpreter, PMC* sub);
#endif /* PARROT_SUB_H_GUARD */
Modified: trunk/lib/Parrot/Pmc2c.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c.pm (original)
+++ trunk/lib/Parrot/Pmc2c.pm Fri Apr 15 05:05:07 2005
@@ -1433,6 +1433,7 @@
return <<EOC;
$l
${decl} {
+ Parrot_on_exit(show_backtrace, interpreter);
internal_exception(NULL_REG_ACCESS,
"Null PMC access in $meth()");
$ret
Modified: trunk/src/debug.c
==============================================================================
--- trunk/src/debug.c (original)
+++ trunk/src/debug.c Fri Apr 15 05:05:07 2005
@@ -2927,6 +2927,46 @@
/*
+=item C<void
+PDB_backtrace(Interp *interpreter)>
+
+Prints a backtrace of the interpreter's call chain.
+
+=cut
+
+*/
+
+void
+PDB_backtrace(Interp *interpreter)
+{
+ STRING *str;
+ PMC *sub;
+
+ /* information about the current sub */
+ sub = interpinfo_p(interpreter, CURRENT_SUB);
+ if (!PMC_IS_NULL(sub)) {
+ str = VTABLE_get_string(interpreter, sub);
+ PIO_eprintf(interpreter, "current instr.: '%Ss' pc %d\n",
+ str,
+ interpreter->ctx.current_pc - PMC_sub(sub)->address
+ );
+ }
+
+ sub = interpinfo_p(interpreter, CURRENT_CONT);
+ while (!PMC_IS_NULL(sub) && sub->vtable->base_type ==
enum_class_Continuation) {
+ str = VTABLE_get_string(interpreter, sub);
+ if (!str)
+ break;
+ PIO_eprintf(interpreter, "%Ss",
+ str
+ );
+ /* get the next Continuation */
+ sub = PMC_cont(sub)->ctx.current_cont;
+ }
+}
+
+/*
+
=back
=head1 SEE ALSO
Modified: trunk/src/inter_run.c
==============================================================================
--- trunk/src/inter_run.c (original)
+++ trunk/src/inter_run.c Fri Apr 15 05:05:07 2005
@@ -185,8 +185,8 @@
PMC* obj, STRING* meth, const char *sig, ...)>
Run parrot ops, called from C code, function arguments are passed as
-C<va_args> according to signature the C<sub> argument is an invocable
-C<Sub> PMC.
+C<va_args> according to the signature. The C<sub> argument is an
+invocable C<Sub> PMC.
Signatures are similar to NCI:
Modified: trunk/src/sub.c
==============================================================================
--- trunk/src/sub.c (original)
+++ trunk/src/sub.c Fri Apr 15 05:05:07 2005
@@ -518,6 +518,36 @@
/*
+=item C<Parrot_full_sub_name>
+
+Print name and location of subroutine, This should finally use the label
+name of the frozen C<Sub> PMC image for now locate the C<Sub> name in
+the globals.
+
+=cut
+
+*/
+
+STRING*
+Parrot_full_sub_name(Interp* interpreter, PMC* sub)
+{
+ struct Parrot_sub * s = PMC_sub(sub);
+
+ if (PMC_IS_NULL(s->name_space)) {
+ return s->name;
+ } else {
+ STRING* ns = VTABLE_get_string(interpreter, s->name_space);
+
+ ns = string_concat(interpreter, ns, string_from_cstring(interpreter, "
:: ", 4), 0);
+ if (s->name) {
+ return string_concat(interpreter, ns, s->name, 0);
+ }
+ }
+ return NULL;
+}
+
+/*
+
=back
=head1 SEE ALSO
Modified: trunk/t/pmc/fixedpmcarray.t
==============================================================================
--- trunk/t/pmc/fixedpmcarray.t (original)
+++ trunk/t/pmc/fixedpmcarray.t Fri Apr 15 05:05:07 2005
@@ -388,7 +388,7 @@
0
OUTPUT
-pir_output_is(<<'CODE', <<'OUTPUT', "Getting unitialized elements");
+pir_output_like(<<'CODE', <<'OUTPUT', "Getting unitialized elements");
.sub main @MAIN
.local pmc arr1
@@ -401,5 +401,5 @@
print type_1956
.end
CODE
-Null PMC access in name()
+/^Null PMC access in name()/
OUTPUT
Modified: trunk/t/pmc/sub.t
==============================================================================
--- trunk/t/pmc/sub.t (original)
+++ trunk/t/pmc/sub.t Fri Apr 15 05:05:07 2005
@@ -1260,14 +1260,14 @@
CODE
main foo
Bar bar
-subname: bar
+subname: Bar :: bar
Bar foo
-caller 0 foo
-caller 1 bar
+caller 0 Bar :: foo
+caller 1 Bar :: bar
caller 2 foo
caller 3 main
Bar foo
-caller 0 foo
+caller 0 Bar :: foo
caller 1 main
ok
OUTPUT