From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 675093858C30 for ; Mon, 20 Feb 2023 13:58:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 675093858C30 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id A41C920362; Mon, 20 Feb 2023 13:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1676901508; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=j/nGykAwyRnbKC/7C56OyUZJQ2bI6sEqiGsdtz9Zs/4=; b=dVfZH3YiAbNtyIF4OeUZf3316lZMZ05VdYtzkkO0y9YMC3xXd8/LFJ+BMCohPYjMsqF9/8 RWPvBDrJxI6u1luM0BsjRRFOf4OPUdTTyKMdCWrzpBXPk7359V4Q++Fm8RodKS57Xg/tJ6 EtPVYHKEnWd0AUHG1MWZ4L5Sfk/qd3k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1676901508; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=j/nGykAwyRnbKC/7C56OyUZJQ2bI6sEqiGsdtz9Zs/4=; b=6/E98ZTZS+9wg6bmWd2WPWMQp6/pXou+gtNYS9P18K96CCrWGjnNesNSKE/zzgf3M/QrBH f/sBT5spGctK9CAw== Received: from hawking.suse.de (unknown [10.168.4.11]) by relay2.suse.de (Postfix) with ESMTP id 973DB2C141; Mon, 20 Feb 2023 13:58:28 +0000 (UTC) Received: by hawking.suse.de (Postfix, from userid 17005) id 3C96F442EF5; Mon, 20 Feb 2023 14:58:28 +0100 (CET) From: Andreas Schwab To: Andrew Burgess via Gdb-patches Cc: Andrew Burgess Subject: Re: [PATCH] gdb: don't treat empty enums as flag enums References: <92a46a82cbc43033fc03942674b80979cc91e572.1676901184.git.aburgess@redhat.com> X-Yow: Place me on a BUFFER counter while you BELITTLE several BELLHOPS in the Trianon Room!! Let me one of your SUBSIDIARIES! Date: Mon, 20 Feb 2023 14:58:28 +0100 In-Reply-To: <92a46a82cbc43033fc03942674b80979cc91e572.1676901184.git.aburgess@redhat.com> (Andrew Burgess via Gdb-patches's message of "Mon, 20 Feb 2023 13:53:16 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Feb 20 2023, Andrew Burgess via Gdb-patches wrote: > In C++ it is possible to use an empty enum as a strong typedef. For > example, a user could write: > > enum class my_type : unsigned char {}; > > Now my_type can be used like 'unsigned char' except the compiler will > not allow implicit conversion too and from the native 'unsigned char' > type. > > This is used in the standard library for things like std::byte. > > Currently, when GDB prints a value of type my_type, it looks like > this: > > (gdb) print my_var > $1 = (unknown: 0x4) > > Which isn't great. This gets worse when we consider something like: > > std::vector vec; > > When using a pretty-printer, this could look like this: > > std::vector of length 2, capacity 2 = {(unknown: 0x2), (unknown: 0x4)} > > Clearly not great. This is described in PR gdb/30148. > > The problem here is in dwarf2/read.c, we assume all enums are flag > enums unless we find an enumerator with a non-flag like value. > Clearly an empty enum contains no non-flag values, so we assume the > enum is a flag enum. > > I propose adding an extra check here; that is, an empty enum should > never be a flag enum. > > With this the above cases look more like: > > (gdb) print my_var > $1 = (unknown: 0x4) I guess this should look different from the output above? -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."