develooper Front page | perl.perl5.porters | Postings from September 2023

Re: Native stack traces?

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
September 8, 2023 10:56
Subject:
Re: Native stack traces?
Message ID:
ZPr9wFHGeVBNQN7B@iabyn.com
On Fri, Sep 08, 2023 at 12:24:58PM +0200, Ovid wrote:
> I don't know if a native stack trace implemented in the Perl core would
> solve the problems, but if we were to add "official" stack traces in the
> core, allowing people to pass a callback or frame subclass for filtering, I
> think this would be a benefit.
> 
> If we later want to add a native exception system, native stack traces
> would likely be a prerequisite.

I'm not really sure in this context what you consider to be a "native"
stack trace which isn't already provided by perl?

Carp and Devel::StackTrace are just wrappers of varying heaviness around
perl's built-in call stack introspection facility: caller() and @DB::args.

Here's a minimal perl stack tracer:

    f(qw(here's some args for f));
    sub f { g(qw(args for g)) }
    sub g { h(qw(h's args))   }
    sub h { dump_stack() }

    sub dump_stack {
        my @c;
        my $i = 0;
        package DB;
        while (@c = caller(++$i)) {
            print "$c[3](", join(', ', @DB::args), ")\n";
        }
    }

which outputs:

    main::h(h's, args)
    main::g(args, for, g)
    main::f(here's, some, args, for, f)

Most of the value that Carp adds is around sanely displaying weird
arguments (undef, long strings, typeglobs, tied/overloaded for example).

What else would you want perl to natively provide?


-- 
The Enterprise successfully ferries an alien VIP from one place to another
without serious incident.
    -- Things That Never Happen in "Star Trek" #7

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About