Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add BackTrace class to setting. Not yet used in exceptions
  • Loading branch information
moritz committed Jul 5, 2011
1 parent 48b9efc commit 8c4e7fd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/core/BackTrace.pm
@@ -0,0 +1,42 @@
my $*VERBOSE_BACKTRACE = False;
class BackTraceLine {
has Str $.file;
has Int $.line;
has Str $.subname;
has $.subtype;

multi method Str(BackTraceLine:D:) {
my $s = $.subname // '<anon>';
my $what = lc $.subtype.perl;
" in $what $s at {$.file}:$.line"
}
}

class BackTrace is List {
method new(Int $offset = 1) {
my $new = self.bless(*);
my $bt = nqp::atkey(pir::getinterp, 'context').backtrace;
for $offset .. $bt.elems - 1 {
next if pir::isnull($bt[$_]<sub>);
my Mu $p6sub =
pir::perl6_code_object_from_parrot_sub__PP($bt[$_]<sub>);
next if !$*VERBOSE_BACKTRACE && !$p6sub.defined;
next if !$*VERBOSE_BACKTRACE && !$p6sub ~~ Routine;
my $line = $bt[$_]<annotations><line>;
my $file = $bt[$_]<annotations><file>;
my $subname = nqp::p6box_s($bt[$_]<sub>);
$subname = '<anon>' if $subname.substr(0, 6) eq '_block';
$new.push: BackTraceLine.new(
:$line,
:$file,
:$subname,
:subtype($p6sub.WHAT),
);
}
$new;
}

multi method Str(BackTrace:D:) {
self.join("\n") ~ "\n"
}
}
1 change: 1 addition & 0 deletions tools/build/Makefile.in
Expand Up @@ -164,6 +164,7 @@ CORE_SOURCES = \
src/core/Complex.pm \
src/core/Exception.pm \
src/core/Failure.pm \
src/core/BackTrace.pm \
src/core/Exceptions.pm \
src/core/EXPORTHOW.pm \
src/core/operators.pm \
Expand Down

0 comments on commit 8c4e7fd

Please sign in to comment.