From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 02E2B385B51F for ; Mon, 20 Feb 2023 14:29:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02E2B385B51F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676903376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7yVzMyevOb3CwHubD+8Jpnd1M1fBT3jqvojk+89hfjU=; b=UpnQbfIks3oatmj174/3IdIUq8shztj3ZRA5slpfK7ia5Dzxmsez/yPvcmltLao8+AdKNL 5g7CesQapGVrZZuLPs09yVn9XAPpuUwryApsWKkbk6u4W9z9R+QLH+lHSw2/1p3Q6Xksqu sahVSRlpSinvOsjZuHpSbPSR9GhIyCU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-617-vJgEfSYNN5OOaaagYDQ4xw-1; Mon, 20 Feb 2023 09:29:35 -0500 X-MC-Unique: vJgEfSYNN5OOaaagYDQ4xw-1 Received: by mail-wm1-f72.google.com with SMTP id c15-20020a05600c0a4f00b003ddff4b9a40so685573wmq.9 for ; Mon, 20 Feb 2023 06:29:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7yVzMyevOb3CwHubD+8Jpnd1M1fBT3jqvojk+89hfjU=; b=ZpEli2iYrnGq9qd1k3AgzOj2ZowkTE/gKAl9pOTOZP77QjHO+iGemjTUMf4yB4GuTo w7yYQjInS4ZViFQPPExaVkUNX+2sdgHT3pF2HdBDl7lr0ZTICHWKk2cuJtUiuaIdvnzu WhSSHTCHgWsc8vGfuBUf37ssd6tq9aFvdEooUjU46Y/51xApiIuNz9mo05+21vuJ1cvP b+OmvkYv6cDanDy6SF27AZ3oPfvPBTNVWekaYT6cCB/ZXIEV6z0DXVTiWYgMd/KUHDkF 1cHDSoOK+uXHw+e7ApWAQVVd3bjY59RfBVtL7A4mo24nhT2j7tXICURkuRI5a8+7NFHX JltA== X-Gm-Message-State: AO0yUKV5jX9vznGOkv9PWgfw1ndN46ILM8zSWOgo/nULWAHyaOBYQqyr Dz1XONCThESvnDWSHRZ89ZawolgYcPWEs3YX60TdPPM/XgsOJH4gw36N/dGFRVDbxqj3DhBTg25 YeGURcCMiSic82U7rO/FESNJ42rc= X-Received: by 2002:a05:600c:198e:b0:3df:9858:c037 with SMTP id t14-20020a05600c198e00b003df9858c037mr793328wmq.12.1676903374182; Mon, 20 Feb 2023 06:29:34 -0800 (PST) X-Google-Smtp-Source: AK7set8DJzJhiMycXs0rQY7vtXUrpQ7ZFLIaQAlMgnz3hYKBNeIze5ySwTnGG4LRJflpj5idwlk4IQ== X-Received: by 2002:a05:600c:198e:b0:3df:9858:c037 with SMTP id t14-20020a05600c198e00b003df9858c037mr793317wmq.12.1676903373929; Mon, 20 Feb 2023 06:29:33 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id w18-20020a05600c475200b003e220998b6bsm1991219wmo.17.2023.02.20.06.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 06:29:33 -0800 (PST) From: Andrew Burgess To: Andreas Schwab , Andrew Burgess via Gdb-patches Subject: Re: [PATCH] gdb: don't treat empty enums as flag enums In-Reply-To: References: <92a46a82cbc43033fc03942674b80979cc91e572.1676901184.git.aburgess@redhat.com> Date: Mon, 20 Feb 2023 14:29:32 +0000 Message-ID: <875ybwl8ab.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: Andreas Schwab writes: > 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? Oops. Yeah, I updated the std::vector example below, but this one should be: (gdb) print my_var $1 = 0x4 I've updated the commit message locally. Thanks, Andrew