Skip to content
Browse files

don't use interp to guess where the top of a backtrace is, use an exp…

…licit parameter
  • Loading branch information...
1 parent bab687c commit fad065bd432c6a2325fd22bb0013946983f3f9d7 @plobsing plobsing committed
Showing with 18 additions and 18 deletions.
  1. +3 −1 include/parrot/sub.h
  2. +10 −10 src/debug.c
  3. +1 −1 src/pmc/continuation.pmc
  4. +3 −5 src/sub.c
  5. +1 −1 src/warnings.c
View
4 include/parrot/sub.h
@@ -184,7 +184,9 @@ int Parrot_sub_context_get_info(PARROT_INTERP,
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
-STRING* Parrot_sub_Context_infostr(PARROT_INTERP, ARGIN(PMC *ctx))
+STRING* Parrot_sub_Context_infostr(PARROT_INTERP,
+ ARGIN(PMC *ctx),
+ int is_top)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
View
20 src/debug.c
@@ -230,10 +230,9 @@ static int nomoreargs(ARGIN(PDB_t *pdb), ARGIN(const char *cmd))
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
static STRING * PDB_get_continuation_backtrace(PARROT_INTERP,
- ARGMOD(PMC * ctx))
+ ARGIN(PMC *ctx))
__attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(* ctx);
+ __attribute__nonnull__(2);
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
@@ -3639,8 +3638,7 @@ PDB_backtrace(PARROT_INTERP)
/*
-=item C<static STRING * PDB_get_continuation_backtrace(PARROT_INTERP, PMC *
-ctx)>
+=item C<static STRING * PDB_get_continuation_backtrace(PARROT_INTERP, PMC *ctx)>
Returns an string with the backtrace of interpreter's call chain for the given context information.
@@ -3656,14 +3654,15 @@ PDB_get_continuation_backtrace(PARROT_INTERP, ARGIN(PMC *ctx))
ASSERT_ARGS(PDB_get_continuation_backtrace)
PMC *output = Parrot_pmc_new(interp, enum_class_StringBuilder);
int rec_level = 0;
+ int is_top;
int loop_count;
PMC *prev_ctx;
/* backtrace: follow the continuation chain */
- for (prev_ctx = PMCNULL, loop_count = 0;
+ for (prev_ctx = PMCNULL, loop_count = 0, is_top = 1;
ctx && loop_count < RECURSION_LIMIT;
- loop_count++, prev_ctx = ctx, ctx = Parrot_pcc_get_caller_ctx(interp, ctx)) {
- STRING *info_str = Parrot_sub_Context_infostr(interp, ctx);
+ loop_count++, is_top = 0, prev_ctx = ctx, ctx = Parrot_pcc_get_caller_ctx(interp, ctx)) {
+ STRING *info_str = Parrot_sub_Context_infostr(interp, ctx, is_top);
if (!info_str)
break;
@@ -3682,8 +3681,9 @@ PDB_get_continuation_backtrace(PARROT_INTERP, ARGIN(PMC *ctx))
VTABLE_push_string(interp, output, fmt);
rec_level = 0;
}
- else {
- /* print the context description */
+
+ /* print the context description */
+ if (rec_level == 0) {
PMC *sub = Parrot_pcc_get_sub(interp, ctx);
PackFile_ByteCode *seg = PARROT_SUB(sub)->seg;
VTABLE_push_string(interp, output, info_str);
View
2 src/pmc/continuation.pmc
@@ -284,7 +284,7 @@ Experimental: returns caller info as a STRING.
PMC *to_ctx;
GET_ATTR_to_ctx(INTERP, SELF, to_ctx);
- return Parrot_sub_Context_infostr(INTERP, to_ctx);
+ return Parrot_sub_Context_infostr(INTERP, to_ctx, 0);
}
View
8 src/sub.c
@@ -290,7 +290,7 @@ Parrot_sub_get_filename_from_pc(PARROT_INTERP, ARGIN_NULLOK(PMC *subpmc),
/*
-=item C<STRING* Parrot_sub_Context_infostr(PARROT_INTERP, PMC *ctx)>
+=item C<STRING* Parrot_sub_Context_infostr(PARROT_INTERP, PMC *ctx, int is_top)>
Formats context information for display. Takes a context pointer and
returns a pointer to the text. Used in debug.c and warnings.c
@@ -303,14 +303,12 @@ PARROT_EXPORT
PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
STRING*
-Parrot_sub_Context_infostr(PARROT_INTERP, ARGIN(PMC *ctx))
+Parrot_sub_Context_infostr(PARROT_INTERP, ARGIN(PMC *ctx), int is_top)
{
ASSERT_ARGS(Parrot_sub_Context_infostr)
Parrot_Context_info info;
STRING *res = NULL;
- const char * const msg = (CURRENT_CONTEXT(interp) == ctx)
- ? "current instr.:"
- : "called from Sub";
+ const char * const msg = is_top ? "current instr.:" : "called from Sub";
Parrot_block_GC_mark(interp);
if (Parrot_sub_context_get_info(interp, ctx, &info)) {
View
2 src/warnings.c
@@ -52,7 +52,7 @@ print_pbc_location(PARROT_INTERP)
interp->pdb->debugger :
interp;
Parrot_io_eprintf(tracer, "%Ss\n",
- Parrot_sub_Context_infostr(interp, CURRENT_CONTEXT(interp)));
+ Parrot_sub_Context_infostr(interp, CURRENT_CONTEXT(interp), 1));
}
/*

0 comments on commit fad065b

Please sign in to comment.
Something went wrong with that request. Please try again.