Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfmCV-0000tw-MX for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Jun 2019 14:13:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hfmCT-00019E-C3 for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Jun 2019 14:13:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfmCS-000197-S0 for pgsql-hackers@lists.postgresql.org; Tue, 25 Jun 2019 14:13:33 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfmCP-0006IE-BJ for pgsql-hackers@postgresql.org; Tue, 25 Jun 2019 14:13:31 +0000 Received: by mail-qt1-x843.google.com with SMTP id s15so18488772qtk.9 for ; Tue, 25 Jun 2019 07:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=Iiyu7eL9xU1UQd7M1iXoAE6LBN2ytmlgty50C4nIspU=; b=UnEAMYkEVuxS9zkWSUJzlLXwlvVz0im2uZ3iTaHHdKjy+u0//UA5CMB7fFjMIp4R9y q3RE4ThFK1xfBkE5h02Yk0KbB6edsRRJFMvcOjkz8phkwEXcnzMwxGifJrE6eY2v0jEJ eTNSuvRlbYr14ue8Z8PnSHdlm6amrT0Ze+KwXeL/7HXf4Fisvwb8KwoP3Q45emqbsI+C ouULaTG53vrTGxTDY84ZsSH8Q/Dj3U5u5DWNBBK8EGA7aEgjXKdwts0lWHoT4XRu0AMM lbAxETU6/+z9rfQMC0vBvAHw5VndCM/2o2EIqs/y+yJar+09at26z56fwsalE5Hrdahj z7tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Iiyu7eL9xU1UQd7M1iXoAE6LBN2ytmlgty50C4nIspU=; b=dP+58ZwirZOsr8IUOLf/HHMSaUuPDovye4qBOvh4/V6YIm0PDUzzofu13V/+A/vAbA x1ScOrKoi3K7m9D8j5Ayma/k0N1XWDEDDIsizezf6ADFI2F+VNytz17T8G9GrIqVmFy2 CUITCoBxuoglhkrsoVXfAf5VGaDMjYkCfNSf5wUGTo42ImGzKDrm1z8u4t/tIubMF4N2 rOQHlQRol0cSIaHUCWEtLdhaQrXwgQw5QPMug+xt+g90tu8JePLmZymaA7prIszMx0Tv J6pYrx4NZ0OLKzM8AZinBzzi0O6dPyXeCIOgLh5CqpupZj3LES2Wdiq15EK4BnwSekM/ K+SQ== X-Gm-Message-State: APjAAAWgFIBuSOXWL+kmgmHPiISgCl9IRd/SQu4TSKIG5Q58tlaD3ek6 VyPxioZkYBhX4mkDRH/YmxO/1w== X-Google-Smtp-Source: APXvYqx+OtfhAoa2EohZENQSPnrDvDA4Y80wwiHxBgl3KVofVMz1IaBCtNLd0mbOUSNZRcsVKVK/rg== X-Received: by 2002:ac8:2b01:: with SMTP id 1mr65204577qtu.177.1561472008409; Tue, 25 Jun 2019 07:13:28 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([177.154.145.99]) by smtp.gmail.com with ESMTPSA id j61sm6792690qte.47.2019.06.25.07.13.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 25 Jun 2019 07:13:28 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 892F3120870; Tue, 25 Jun 2019 10:13:24 -0400 (-04) Date: Tue, 25 Jun 2019 10:13:24 -0400 From: Alvaro Herrera To: Peter Eisentraut Cc: pgsql-hackers Subject: Re: errbacktrace Message-ID: <20190625141324.GA3260@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5f48cb47-bf1e-05b6-7aae-3bf2cd01586d@2ndquadrant.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Jun-25, Peter Eisentraut wrote: > Here is a extended version of Álvaro's patch that adds an errbacktrace() > function. Great stuff, thanks for working on it. > You can do two things with this: > > - Manually attach it to an ereport() call site that you want to debug. > > - Set a configuration parameter like backtrace_function = 'int8in' to > debug ereport()/elog() calls in a specific function. WFM. I tried specifying int4in -- didn't work. Turns out the errors are inside another function which is what I have to put in backtrace_function: $ PGOPTIONS="-c backtrace_function=pg_strtoint32" psql alvherre=# select int 'foobar'; 2019-06-25 10:03:51.034 -04 [11711] ERROR: invalid input syntax for type integer: "foobar" at character 12 2019-06-25 10:03:51.034 -04 [11711] BACKTRACE: postgres: alvherre alvherre [local] SELECT(pg_strtoint32+0xef) [0x55862737bdaf] postgres: alvherre alvherre [local] SELECT(int4in+0xd) [0x558627336d7d] postgres: alvherre alvherre [local] SELECT(InputFunctionCall+0x7b) [0x55862740b10b] postgres: alvherre alvherre [local] SELECT(OidInputFunctionCall+0x48) [0x55862740b378] postgres: alvherre alvherre [local] SELECT(coerce_type+0x297) [0x5586270b2f67] postgres: alvherre alvherre [local] SELECT(coerce_to_target_type+0x9d) [0x5586270b37ad] postgres: alvherre alvherre [local] SELECT(+0x1ed3d8) [0x5586270b83d8] postgres: alvherre alvherre [local] SELECT(transformExpr+0x18) [0x5586270bbcc8] postgres: alvherre alvherre [local] SELECT(transformTargetEntry+0xb2) [0x5586270c81c2] postgres: alvherre alvherre [local] SELECT(transformTargetList+0x58) [0x5586270c9808] postgres: alvherre alvherre [local] SELECT(transformStmt+0x9d1) [0x55862708caf1] postgres: alvherre alvherre [local] SELECT(parse_analyze+0x57) [0x55862708f177] postgres: alvherre alvherre [local] SELECT(pg_analyze_and_rewrite+0x12) [0x5586272d2f02] postgres: alvherre alvherre [local] SELECT(+0x4085ca) [0x5586272d35ca] postgres: alvherre alvherre [local] SELECT(PostgresMain+0x1a37) [0x5586272d52b7] postgres: alvherre alvherre [local] SELECT(+0xbf635) [0x558626f8a635] postgres: alvherre alvherre [local] SELECT(PostmasterMain+0xf3e) [0x55862724e27e] postgres: alvherre alvherre [local] SELECT(main+0x723) [0x558626f8c603] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x7f99d1931b97] postgres: alvherre alvherre [local] SELECT(_start+0x2a) [0x558626f8c6ca] Didn't think too much about the libunwind format string (or even try to compile it.) Despite possible shortcomings in the produced backtraces, this is a *much* more convenient interface than requesting users to attach gdb, set breakpoint on errfinish, hey why does my SQL not run, "oh you forgot 'cont' in gdb", etc. > There was also mention of settings that would automatically produce > backtraces for PANICs etc. Those could surely be added if there is > enough interest. Let's have the basics first, we can add niceties afterwards. (IMO yes, we should have backtraces in PANICs and assertion failures). -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services