Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vFDZw-009Hen-Tu for pgsql-hackers@arkaria.postgresql.org; Sat, 01 Nov 2025 15:31:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vFDZt-005mth-M1 for pgsql-hackers@arkaria.postgresql.org; Sat, 01 Nov 2025 15:31:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vFDZs-005mtY-Rs for pgsql-hackers@lists.postgresql.org; Sat, 01 Nov 2025 15:31:40 +0000 Received: from fhigh-b8-smtp.messagingengine.com ([202.12.124.159]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vFDZp-004ucR-15 for pgsql-hackers@postgresql.org; Sat, 01 Nov 2025 15:31:38 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id 751237A00F9; Sat, 1 Nov 2025 11:31:36 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-06.internal (MEProxy); Sat, 01 Nov 2025 11:31:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eulerto.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1762011096; x=1762097496; bh=VqhoGDQ4ip13XqirHbqZfhK++X/eq9rSx744pRk++AY=; b= S8HXsPep2Yuieu6N0XjrXc9Iw+z1t7cVnlGehTAjV089S5qI5xH+ExDM15tw14l1 jR/IFHbDEDENUW8f/qV5Goj+KS7E2+wkWhhftBkwgWal5YwbY6bH5dSbsupCfA3t hbtKDVf/XEQbWBXcoDdDW0RQzCTQJ1zqcPR7cTOpsL3NDvyNvGxabVZyqV6SYjcv iG2lf8PM2Ya9XBm1y/k2Cvx6U+Q10pg4esYFNXAZyMM2kjnB07WjOe7NCHLeserV 3uXBvWCsmApdr+iy08xdtH25Gs7L2rB4bSDt3hK8yWJQNMVrlR8DVfU1tnukrzuU FpGy3JP2eEMfSCRtg0FqrA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1762011096; x= 1762097496; bh=VqhoGDQ4ip13XqirHbqZfhK++X/eq9rSx744pRk++AY=; b=S vdDyVncE9Z6pS8M4L6yCVAewQVLiu5/DYGMbCueNqv+VbBHEbjoDc00xFw9GxN6Z E6Bqjm+L7RFQo8nIuYvsIj6UOv0Ii+6MrpUEnBQDtgmwQoxUtDXprYgPb7GDHExj e15etxemVO7bllsgfg8rqrtMRvtNxpFQMqlFS7KdGSEyPMMBJlp/S/xfuZTcCOLJ cXWolZ+fGsAPHOrE76Hn6D6Yc0mb9SHsdp37KjctEhEJU3JY7oxgt7sNyvwrRJ4s UyG2GGOf7ZGYx5BnKOY1fKDpNUabGk4d3DvRKKCBsT3v6gI32oHxLDPk+PRKG4KY ThAn5CoHTHKOuRUpOAexg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddujedvjeegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvfevkfgjfhfutgfgsehtjeertdertddtnecuhfhrohhmpedfgfhulhgv rhcuvfgrvhgvihhrrgdfuceovghulhgvrhesvghulhgvrhhtohdrtghomheqnecuggftrf grthhtvghrnhepleevgfeileegfffglefgfeefffeghfefvdeftdduvdffieeijeffudel iefhvdevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegvuhhlvghrsegvuhhl vghrthhordgtohhmpdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpohhuthdprh gtphhtthhopehjrghkuhgsrdifrghrthgrkhesvghnthgvrhhprhhishgvuggsrdgtohhm pdhrtghpthhtohepuggsrhihrghnrdhgrhgvvghnsehgmhgrihhlrdgtohhmpdhrtghpth htoheprghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvpdhrtghpthhtohepmhhitghh rggvlhesphgrqhhuihgvrhdrgiihiidprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrh hssehpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i0c21471d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 8CED51820054; Sat, 1 Nov 2025 11:31:35 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 X-ThreadId: AWPeZBJywbRF Date: Sat, 01 Nov 2025 12:31:15 -0300 From: "Euler Taveira" To: "Bryan Green" , "Jakub Wartak" Cc: =?UTF-8?Q?=C3=81lvaro_Herrera?= , "Michael Paquier" , pgsql-hackers Message-Id: In-Reply-To: <31f43d88-9949-48c5-9497-b9a9b7cdee2b@gmail.com> References: <202510300932.isdvgkzqzshk@alvherre.pgsql> <5b4c6ce0-ed17-4abb-9127-859cc95cbdf3@gmail.com> <30aea073-109c-43cc-979c-081b922d055d@gmail.com> <2241662b-da7d-428f-beba-a416ef48e9e9@app.fastmail.com> <31f43d88-9949-48c5-9497-b9a9b7cdee2b@gmail.com> Subject: Re: [PATCH] Add Windows support for backtrace_functions (MSVC only) Content-Type: text/plain Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Nov 1, 2025, at 1:40 AM, Bryan Green wrote: > v5 patch attached, incorporating all of Euler's feedback with a caveat > around unicode. > Thanks for sharing another patch. > The most interesting aspect turned out to be the encoding conversion for > symbol names and file paths. Initially I tried using the generic > SYMBOL_INFO and SymFromAddr functions as Euler suggested, but ran into a > subtle issue: on PostgreSQL's Windows builds, these become SYMBOL_INFOA > and SymFromAddrA (the ANSI versions), which return strings in whatever > Windows ANSI codepage happens to be active (CP1252, etc). This doesn't > necessarily match the database encoding. > Odd. Does the build define UNICODE? (Don't have a Windows machine right now to explore this case.) > The solution was to use the explicit Unicode versions (SYMBOL_INFOW and > SymFromAddrW), which reliably return UTF-16 strings that wchar2char() > can properly convert to the database encoding. This handles both UTF-8 > and non-UTF-8 databases correctly, and wchar2char() gracefully returns > -1 on conversion failure rather than throwing errors during error > handling. Of course this also necessitated using IMAGEHLP_LINEW64 and > SymGetLineFromAddrW64. > Works for me. > This patch also adds a check for zero frames returned by backtrace() on > Unix/Linux platforms, which can occur in certain circumstances such as > ARM builds without unwind tables. > Please create a separate patch. + if (result != (size_t) -1) + { + appendStringInfo(&errtrace, + "\n%s+0x%llx [0x%llx] [%s:%lu]", + symbol_name, + (unsigned long long) displacement, + (unsigned long long) address, + filename, + (unsigned long) line.LineNumber); + } + else + { + /* Filename conversion failed, omit it */ + appendStringInfo(&errtrace, + "\n%s+0x%llx [0x%llx]", + symbol_name, + (unsigned long long) displacement, + (unsigned long long) address); + } + } + else + { + /* No line info available */ + appendStringInfo(&errtrace, + "\n%s+0x%llx [0x%llx]", + symbol_name, + (unsigned long long) displacement, + (unsigned long long) address); + } One last suggestion is to have a single code path for these last two conditions to avoid duplication. Move this if to outside the "if SymGetLineFromAddrW64". Merge the comment to reflect both conditions (file conversion failed and no line info). -- Euler Taveira EDB https://www.enterprisedb.com/