Index | Thread | Search

From:
Andrew Hewus Fresh <andrew@afresh1.com>
Subject:
Re: are you running under the perl debugger ?
To:
tech@openbsd.org
Date:
Tue, 23 Jun 2026 14:22:35 -0700

Download raw body.

Thread
On Tue, Jun 23, 2026 at 06:08:01PM +0200, Marc Espie wrote:
> The following snippet:
> 
> can be used to determine if I am running under perl -d.
> 
> I'm wondering if there's something cleaner.

I asked at work and millert@'s neighbor Tom says he uses:

    sub am_running_perldb() {
        no warnings "once";
        return keys(%DB::sub) > 0;
    }



> 
> #! /usr/bin/perl
> 
> use v5.36;
> 
> my $db;
> eval { no strict 'subs'; 
> 	$db = DB->can(DB); };
> 
> if ($db) {
> 	say "debugguer";
> }
> 
> 
> The reason I'm asking is because pkg_add is a giant try {} catch ();
> (okay the actual code is a lexical eval {} with if ($@) test)
> 
> I have a -Ddebug switch that can turn that off, which is very useful when
> debugging -- turns out, the perl debugger is not so great at entering evals.
> 
> 
> I have several questions: am I missing something ?
> 
> If not, I would like to use something like tne above in order to, by default,
> remove the eval {}; if ($@)... block in case the code detects it runs under
> the debugguer.

-- 
andrew

Speed matters.  
Almost as much as some things, and nowhere near as much as others.
                      -- Nick Holland