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.96) (envelope-from ) id 1vubI8-00FL1c-0o for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Feb 2026 19:08:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vubI6-00Ehpd-2r for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Feb 2026 19:08:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vubI6-00EhpV-1u for pgsql-hackers@lists.postgresql.org; Mon, 23 Feb 2026 19:08:22 +0000 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vubI3-00000000ufc-2B5P for pgsql-hackers@postgresql.org; Mon, 23 Feb 2026 19:08:22 +0000 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-7984d31b895so9153357b3.1 for ; Mon, 23 Feb 2026 11:08:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771873698; x=1772478498; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=pTuJZVav0MJ7e547nQgsJYM+j/3ND0sjZcsbQG96PIw=; b=VPD0AqXVt1zspP0wLcO4kIXlisTdG3TFpKNLPGsJNox9JBac8CmuxOsHU3JkRXt629 VRoZX3K92k4bEIspQDV8eiJ18BCbC3k+PjqGXmgw0ACcCXfdrY4eRrVEQDiGNABvRX01 drcYX2/RfEHbcIsSXcHK9AILLimftidKq6NO4i/rZW2WzAS3bYXdXK5JGO4//0CrPZ+X Dn33psRI8VJUozVVXLuWyCpOU8aHRQthtwBNmHw3ZDLoZukC2j0xEwd85flGOCafGxTG mSXI1t1narDPD+GyXGWe0yxBaE2AZ2ibAV10XgArpNprZUVheI8Ckzq94eV3x/e26EzO OjZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771873698; x=1772478498; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pTuJZVav0MJ7e547nQgsJYM+j/3ND0sjZcsbQG96PIw=; b=dE5a/uOAmg+xHy7MBivUNiBuyHOFNFnXUEsZfnOu16TEDE0uhSBUCEvxk4fMu+gn9I f9AxYhisLteZ41JCPX7+jTObjDcii0AWY9JEq/SIVhAdeJKOocU7l3vK1P+11jOSUkF9 jy37YdHAFE6c3IvEV19aTvFErZctAvHoxrvrWzhPe7vY4byYfEphwzlcrZrnlOKO7D8b OjRdaIuCHXyrQ6fYYoZe5PzYH1sz5fOnnsSByrcAeXg6C+QogRRmYNKtWaD7APOQFZLA OnkbS2rO2RLNk7cDYED7BoJzrd4iRNI3Ig/Y8MiKU2sbbwN0Mk5rDEpPCcy4wL1SDm5u cMew== X-Forwarded-Encrypted: i=1; AJvYcCVHSkX3N4Hm2s8exHJ19esWXPNRXnuSeLcNXCHKYyotPrkefnp4IDs3CTUQ+PJLuVebUGvOWR+6HUv2/PcH@postgresql.org X-Gm-Message-State: AOJu0Yw+V8uXVYBGz1Blg3lYVHmRDsAj4i5kQ4Wp1pwePTl7nJOBL5Ea y3bOaFcrOXFY4EnHqv5//pEcuu5a75Nel26Sbti4oUoaZ2bOkKW4mf5abqTsDLY4 X-Gm-Gg: ATEYQzz+rMT9jnxS+/PJ1P5EmkTx9HFiGegXcCj0Nyq0SrSDAhmQHhZ7HKX1hfa6A9O bUSHRSdWu1o0MVeZ9oJMeof1GupBrcupkGHJVp+N5rXJtBeXdDLwsxi1G1K1G/4kyxaInGHEGVU uoIHbHzX+gutQO9cbLekYFzhzmDhod4GFl1GoGRCGrANDiPT5+G9WWT5pMVEEm+390gjimHldyD eNsseeVbYZpZyJMa+OC88NpUpPlH6HUzAwUEXf0jex2PW5W+bF9B0x712R0zBMz4nlojblUUe6S 1cS8vlfPjcRMnYojC7bZua4vv9OyMo82wLh+nRhWZDKMgjaxxI/K353v6/apxAH5MDVsKEAj6yu im09uUHsYf/qirNy6mFe//mAK4ggWvWLgClBwIP2aGnZv5UQVWoRTRwr75pYMSgBx9wwSEwtqkI /UcWkcudX4t2n/Hg0cu5OPKvwUnmHhfCEa4ok/1HCBvJkkPXu3UfqNzwG4MI7BvJz0z2CHojzif 9LCfaTIpDptZMkdchMv/peZdPys5pUTgUTu X-Received: by 2002:a05:690c:e18:b0:796:2fde:5de7 with SMTP id 00721157ae682-79828fc1cafmr83801037b3.34.1771873697896; Mon, 23 Feb 2026 11:08:17 -0800 (PST) Received: from ?IPV6:2600:1700:8952:80:e08a:9894:2f23:ace1? ([2600:1700:8952:80:e08a:9894:2f23:ace1]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7982de0fd63sm34990807b3.46.2026.02.23.11.08.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Feb 2026 11:08:17 -0800 (PST) Message-ID: Date: Mon, 23 Feb 2026 13:07:23 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Add Windows support for backtrace_functions (MSVC only) To: =?UTF-8?Q?=C3=81lvaro_Herrera?= Cc: Euler Taveira , Jakub Wartak , Michael Paquier , pgsql-hackers References: <202602091656.sxosgjxnc42l@alvherre.pgsql> Content-Language: en-US From: Bryan Green In-Reply-To: <202602091656.sxosgjxnc42l@alvherre.pgsql> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/9/2026 11:17 AM, Álvaro Herrera wrote: > On 2025-Nov-01, Bryan Green wrote: > >> Done. Now the code prints symbol+offset+address first, then conditionally >> appends line info if both SymGetLineFromAddrW64 succeeds and the filename >> conversion succeeds. This eliminates the duplication. > > Thanks! > > I was a bit surprised that you were doing elog(WARNING) for some > problematic conditions when trying to write the backtrace. I think that > would work fine, because our elog.c stuff is all supposed to be > reentrant ... yet I think it's going to be odd (assuming it ever > happens). I think we should instead just print the diagnostics message > to the backtrace string, where it will be displayed together with the > main error being processed, in the place where the backtrace would be. > > This applies particularly when SymFromAddrW() fails: instead of printing > the elog(WARNING) in a separate error entry, we would still print the > function address in the correct spot of the backtrace with a small > diagnostics about the symbol not being found. ... I think. > > What do *you* think? > > I also made the backtrace_cleanup() function exist always, but on > non-win32 builds it's unused, so I tagged it as such. > > Github is down at the moment, so I don't know if this actually compiles. > > 0001 is your patch (I may have pgindented it, not sure), 0002 are my > changes. > Hi Álvaro, Thanks for the fixups — I've applied both patches and confirmed everything works correctly on Windows. You are correct to change the elog(WARNING) calls. Embedding the diagnostic directly into the backtrace string is much cleaner, and your approach of printing the address with a parenthetical note ([0x%llx] (symbol lookup failed: error code %lu)) puts the information exactly where it belongs, in context. The backtrace_cleanup() restructuring also makes sense — making it unconditionally defined with pg_attribute_unused() and putting the #ifdef _MSC_VER guard inside the body is cleaner. I confirmed it compiles and links successfully on Windows with MSVC. I ran several tests and the backtrace feature is working as expected. Thanks again to everyone who reviewed this. -- Bryan Green EDB: https://www.enterprisedb.com