Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nX0fc-0005VQ-NM for pgsql-docs@arkaria.postgresql.org; Wed, 23 Mar 2022 13:05:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nX0fb-0004f5-IU for pgsql-docs@arkaria.postgresql.org; Wed, 23 Mar 2022 13:04:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nX0fa-0004ee-K7 for pgsql-docs@lists.postgresql.org; Wed, 23 Mar 2022 13:04:59 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nX0fW-0001c6-OA for pgsql-docs@lists.postgresql.org; Wed, 23 Mar 2022 13:04:57 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 498E632009F8; Wed, 23 Mar 2022 09:04:52 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 23 Mar 2022 09:04:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=EMbxmqupAXyWSQdv/60F5mz1PNFEIFNcAAe/MZnX4 Cs=; b=cv4VDftAG9+pIXhs7Lvd684l812M6zoH8cGEXm/ithRCu3E5/lJemRmK3 xL1ihrAjZyNH7J3a4KqDZYEQ2uHRqsYb+5bjD/ISFQZlZLm0hPT+k+ZN8ypSMJi9 nns6nPcUP9y0o9FQods7E6ETsOJYOqU7NZAf0JAioypcbzYFkaNbLX5IYQiZAoLL ikLW13swlJhb+GAMxzUM0nVjNxsB265fbCuAwKQuFEM9ZX5DkW395PshM5HfV26E i6BhhCQR7O8MoB/QDopPfBT+PCM0s4o6RZUu7C8kXwHOsUZdL/zUHvF6RnDEO4tD p1hLv4UEOjUNVaazNFFUu182kO3wQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudegjedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheprfgvthgv rhcugfhishgvnhhtrhgruhhtuceophgvthgvrhdrvghishgvnhhtrhgruhhtsegvnhhtvg hrphhrihhsvggusgdrtghomheqnecuggftrfgrthhtvghrnheplefgteefiedtleelgeeg jeevhfeuteefvddtjeehveeuieefgedvhfeuleduteeunecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepphgvthgvrhdrvghishgvnhhtrhgruhht segvnhhtvghrphhrihhsvggusgdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 23 Mar 2022 09:04:49 -0400 (EDT) Message-ID: <3eafd5c6-f69f-2592-34a1-63cbd39d323b@enterprisedb.com> Date: Wed, 23 Mar 2022 14:04:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: maximum number of backtrace frames logged by backtrace_functions Content-Language: en-US To: Fujii Masao , Tom Lane Cc: pgsql-docs@lists.postgresql.org References: <0f0ed9f3-3892-e8a3-51c9-ed268dff6bdd@oss.nttdata.com> <4e16a3e9-e717-05e1-d905-6c21beba80f8@enterprisedb.com> <252159.1643899696@sss.pgh.pa.us> <33675df8-60e1-7da6-8995-3743668fd682@oss.nttdata.com> <9b3e1b97-4d2f-25af-fa52-1b2c31511444@enterprisedb.com> <7fce4874-1433-42e2-6649-e2c57ce50d4e@oss.nttdata.com> <5c089e04-1f73-f9f1-b60d-d71d6c33e3f2@enterprisedb.com> <070467b6-1ead-8921-89a1-5ec39d1f2103@oss.nttdata.com> From: Peter Eisentraut In-Reply-To: <070467b6-1ead-8921-89a1-5ec39d1f2103@oss.nttdata.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 18.02.22 17:05, Fujii Masao wrote: >>> Or even backtrace should be logged by write_stderr() so that it's >>> written to eventlog if necessary? I just wonder why >>> backtrace_symbols_fd() is used only in ExceptionalCondition(). >> >> Probably because it was simpler.  It would also make sense to convert >> the whole thing to use write_stderr() consistently. > +1 > Attached is the updated version of the patch that uses write_stderr() to > log the backtrace in assertion failure case. > > +        if (nframes >= lengthof(buf)) > +            appendStringInfo(&errtrace, "\n(backtrace limited to %zu > frames)", > +                             lengthof(buf)); I think this should actually print nframes, because that's the actual number of frames returned. > I found this doesn't work on FreeBSD, at least FreeBSD 13 that cfbot > uses on Cirrus CI. When the backtrace is larger than 100, on FreeBSD, > backtrace() seems to write the *99* (not 100) most recent function calls > to the buffer. That is, the variable "nframes" is 99 while lengthof(buf) > indicates 100. So the above message about backtrace limit will never be > logged on FreeBSD. OTOH, on Linux and MacOS, backtrace() writes the 100 > most recent function calls. I'm not sure if such a behavior on FreeBSD > is expected or a bug. Well, the API is that you ask for up to N frames, and it gives you X frames back. There is no requirement that X is as close to N as possible. But that also means that there is no portable API for finding out how many X it could give you if you had enough room (other than by looping and doubling the buffer dynamically etc.). Maybe we can catch this particular case if we made the condition if (nframes >= lengthof(buf) - 1) That might give slightly misleading information if you have exactly 99 or 100 frames, but overall it might still be better.