From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 0C66E385DC35; Mon, 16 Aug 2021 19:30:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0C66E385DC35 Received: by mail-wr1-x431.google.com with SMTP id r7so25222497wrs.0; Mon, 16 Aug 2021 12:30:58 -0700 (PDT) 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=7sm8uDC6TlWzelyesXJC6CYh78xhJKreIiHYnlQ2nSA=; b=Nd91hWSpGBHUL2iCCR9eV4pJ8b3oxuf9YGA7MBVKOXPTyyHMxBwbxv1/bvzIOWsoNd ozZp0JhZ9vo8mSIOx179TLMIiU3TCW2KDtqXlJHRvXYXU3m7dLoqGxnLFi9WMx4441BF IieA31e3dTTHEa+bTLZC3YZqhstHcFVvsnYIGCZengYTs7bCVFoeB8fFbj4ujIHjVSbo 2f9Wups35zgJFEy+ORHFNMfyeDnilN04/coOw/AsfA0ZPMbpP0BXePGkToJa6WMO2xkX TjRw30M4TJ4IZ0zqw4aq+jE7camTHfF67D51jPRrJsG3TF7FsrXJuR6LqcSoWbhl6jbO 5Ngg== X-Gm-Message-State: AOAM532lmHDqevM7bkmaeM2Gg3F20U1Md+qZTdvMr4SZJ57zKA/PWMBq QacHbaBfvLnaMXTDIgKNNKBBJWkJtZY//p4ESihdyyELj8w= X-Google-Smtp-Source: ABdhPJzxti7NRmErPn03c0NxIs/cNfDNwAt1hb/u9ekMcKYZHm+ItTb4+nfKhSTyq77pLKumtSEMf4evHXuPRVj7ogc= X-Received: by 2002:a5d:6287:: with SMTP id k7mr47854wru.321.1629142257448; Mon, 16 Aug 2021 12:30:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Mon, 16 Aug 2021 20:30:46 +0100 Message-ID: Subject: Re: What should a std::error_code pretty printer show? To: "libstdc++" Cc: gcc-patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Aug 2021 19:31:00 -0000 On Mon, 16 Aug 2021 at 17:51, Jonathan Wakely wrote: > > On Mon, 16 Aug 2021 at 13:11, Jonathan Wakely wrote: > > > > > > > > On Mon, 16 Aug 2021, 12:55 Jonathan Wakely, wrote: > >> > >> I'm adding a GDB printer for std::error_code.What I have now prints > >> the category name as a quoted string, followed by the error value: > >> > >> {"system": 0} > >> {"system": 1234} > >> > >> If the category is std::generic_category() then it also shows the > >> strerror description: > > > > > > I should probably extend this special case for the generic category to also apply to the system category when the OS is POSIX-based. For POSIX systems, the system error numbers are generic errno values. > > > > > >> > >> {"generic": 13 "Permission denied"} > >> > >> But I'd also like it to show the errno macro, but I'm not sure what's > >> the best way to show it. > >> > >> Does this seem OK? > >> > >> {"generic": 13 EACCES "Permission denied"} > >> > >> I think that's a bit too verbose. > >> > >> Would {"generic": EACCES} be better? You can always use ec.value() to > >> get the numeric value, and strerror to get the description if you want > >> those. > > Here's what I plan to commit. It just uses {"generic": EACCES} for > known categories that use errno values, and {"foo": 99} for other > error categories. > > > It also supports std::error_condition (using the same printer and the > same output formats). Actually, the proposal in PR 65230 would mean that we should print { } if the object has its default-constructed state, i.e. {"system": 0} for error_code and {"generic": 0} for error_condition. I'll make that change before pushing anything to master. Other suggestions for improvement (or just agreeing with the direction) are welcome.