Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113821 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4835 invoked from network); 28 Mar 2021 09:04:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Mar 2021 09:04:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B6B471804DD for ; Sun, 28 Mar 2021 02:01:02 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 28 Mar 2021 02:01:02 -0700 (PDT) Received: by mail-lf1-f47.google.com with SMTP id a198so13934386lfd.7 for ; Sun, 28 Mar 2021 02:01:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=E4XYyZTmUi1da/rQODXzHomQriF11vwo+8pSmP5yHLM=; b=bzJX9c8OcTFXMD5AX5B3ugMqWBxG/mUip5fnLBBPGrghm7jiz7iNIYF9Xsg6lPSP9B Bvg8Vm4GDH/YO9N68xivih1nEMYmXrPIHOFi8+/ZT27GMsSEeXHUFNrbyHdvsqvkHmm4 sHtjgVBagC2Z5tafkXa79U/JXxyT7WkJQ8rh5N+NagdDsLMcPDlxDvD3fWIESTonV/9Z 5DnoMVJbX79YC4qfdynEnwGamNSU0QUlE6PBQWONhWYYm3zt70a3O987Oj7iL5RxJHmW JSNNMZYcxGH2KKYb3csgQXvgFto+mExF2YP/51RskVRbNhjfOjRzCWDPZLMTatHGCYNY ZOdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=E4XYyZTmUi1da/rQODXzHomQriF11vwo+8pSmP5yHLM=; b=bvCaO2rgwPr/LsH4QsautLVppyw1Re6Bpd0XCYZMay8qw81PphWI6U/dO3o9xZQTh3 7yqub+ijxxgTZKirtk0708K4JEnFPbtgt0lMnLRROGUEtDOUB+4izE95ngdD9dO20Zg/ o2lgVKsJobkeAZwNptFGayIf4WF24NYVPP1nv0o48Q6hGhcJLJ5oC0zQulj5qP1X7Yce OrhiExCor6whi7oU2vdw5VynmKHxzUm8/7AUHoKnjP5E/ItxrEKMK5yU6s5E3/gdm4bC IdBBoa51jzGGw1084CNSUgA1Hsl4fYgiKy/OVms9hJ00nNLzZqLyFfbsAr8LP0Yzp+pb mUAg== X-Gm-Message-State: AOAM532McB0L0hh+MD4EhEMSeIdb+qfw05r7mDPnlfNoieaxHfmYLG8t 5Z8m+89OO1mImge04cXXPCmeOyBgU0QvBghRcV8= X-Google-Smtp-Source: ABdhPJxhk1C3YImIg0pQS8ocHMhtwYjheuOLw7dViErtkKzOn0YSknra5YL8aovqhmyS5HM5yFk9IZSS9O+5NHxZMRA= X-Received: by 2002:a05:6512:22c9:: with SMTP id g9mr13997036lfu.286.1616922058004; Sun, 28 Mar 2021 02:00:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 28 Mar 2021 11:00:42 +0200 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000e59aff05be950081" Subject: Re: [PHP-DEV] [RFC] debug_backtrace_depth(int $limit=0): int From: nikita.ppv@gmail.com (Nikita Popov) --000000000000e59aff05be950081 Content-Type: text/plain; charset="UTF-8" On Sat, Mar 13, 2021 at 6:30 PM tyson andre wrote: > Hi internals, > > I've created a new RFC https://wiki.php.net/rfc/debug_backtrace_depth to > return the depth of the current stack trace. > > Inspecting the current stack trace depth is occasionally useful for > 1. Manually debugging with temporary debug statements > 2. Checking for potential infinite recursion or investigating reproducible > reports of infinite recursion > 3. Checking if code is likely to hit stack frame limits when run in > environments using extensions such as Xdebug > (https://xdebug.org/docs/all_settings#max_nesting_level , which also > checks for potential infinite recursion) > (note that Xdebug is a debugger - running php under xdebug is > significantly slower than without Xdebug) > > It is currently possible to compute the depth through > `count(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $limit=0))`, > but this is verbose, inefficient, and harder to read compared to returning > the depth directly. > > Thoughts? > > Thanks, > - Tyson There hasn't been much discussion on this one, probably because the functionality and use cases are so specific. I'm not really convinced by your examples. For the purpose of printing debug logs, using an engine-provided depth is non-ideal, because any intermediate helper functions will count towards the depth. Tracking your own depth will result in a more meaningful/predictable output. For tracking down infinite recursion, isn't this what the xdebug recursion limit is for? You'll directly get your recursive stack trace, which should make it obvious where the infinite recursion occurs. Using debug_backtrace_depth() for this purpose means that you actually already need to know where you are infinitely recursing in order to place the guard. If you want to find places where your code would hit the xdebug recursion limit, then why not run it under xdebug and find out, rather than trying to simulate the same behavior manually? That again requires that you actually place relevant guards in the first place, which makes this another chicken and egg problem. Regards, Nikita --000000000000e59aff05be950081--