From patchwork Sun Aug 25 22:35:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 34264 Received: (qmail 50529 invoked by alias); 25 Aug 2019 22:35:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 50187 invoked by uid 89); 25 Aug 2019 22:35:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=protect, ended, prefixed X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 25 Aug 2019 22:35:11 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id x7PMZ1Wj022891 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 25 Aug 2019 18:35:06 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca x7PMZ1Wj022891 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1566772507; bh=HZneVZbVsJMFINq8Z3LDWrwpeXO5S6S46cjxGAOUh2A=; h=Subject:From:To:Cc:References:Date:In-Reply-To:From; b=rOwG5UqiJK6IGUEamF191Hi4WpojWDrll3pjADW/bLQfy4+02HGFnWuL+e7pCzQQL mkVyOD4wsCWbbQX7Ec/+qhq06h1D715HWCNr0OBqPyvPxEIU8Z2TazhOoZwuLMGaq5 cZX1jF87mEf2yrYf65p3hV0b5pUkJATE5Y09keUA= Received: from [10.0.0.193] (unknown [192.222.164.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 724671E65F; Sun, 25 Aug 2019 18:35:01 -0400 (EDT) Subject: Re: [PATCH] Remove some variables in favor of using gdb::optional From: Simon Marchi To: Ruslan Kabatsayev Cc: Pedro Alves , GDB Patches References: <20190804201023.25628-1-simon.marchi@polymtl.ca> <9b1cdf6d-baae-3a5e-c2ea-fcdf124b7a1b@redhat.com> <65a23d93-bf2e-de1a-9052-f6d75832c2a1@polymtl.ca> <697c3e3d-4f75-4fb2-685b-a6fa59c7a2a3@polymtl.ca> <5d2e7548-1303-ba42-6d67-93ab37f6577d@redhat.com> <829ab63c-55b0-07bc-1517-0efe9aeecc95@polymtl.ca> <58b2c8d82f3f42588bc1b75f74e1f453@polymtl.ca> Message-ID: <5aac09a7-ea07-1ffa-70f5-d469a97a2aff@polymtl.ca> Date: Sun, 25 Aug 2019 18:35:01 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <58b2c8d82f3f42588bc1b75f74e1f453@polymtl.ca> X-IsSubscribed: yes On 2019-08-24 7:55 p.m., Simon Marchi wrote: > On 2019-08-24 07:22, Ruslan Kabatsayev wrote: >> Since GDB uses C++11, and we don't really rely on conversion to int >> here, why not use enum class? This would protect from unwanted >> conversions. Additionally, we'll be forced to use a "scoped" name >> instead of "prefixed" one, like symbol_nature::unknown vs >> symbol_nature_unknown, which seems a bit more explicit (will need to >> do something with "static" though, since it's a keyword). > > Good point, I'll try this for the new version. > > Simon This is what I ended up pushing, thanks to both of you for your comments. From beadd3e84ed8e652015f07eb4734a6d3b17e79cb Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sun, 25 Aug 2019 18:09:47 -0400 Subject: [PATCH] dwarf2read: replace gdb::optional with enum gdb::optional is dangerous, because it's easy to do: if (opt_bool) when you actually meant if (*opt_bool) or vice-versa. The first checks if the optional is set, the second checks if the wrapped bool is true. Replace it with an enum that explicitly defines the three possible states. gdb/ChangeLog: * dwarf2read.c (dw2_debug_names_iterator::next): Use enum to represent whether the symbol is static, dynamic, or we don't know. --- gdb/ChangeLog | 6 ++++++ gdb/dwarf2read.c | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cbb83347f1e6..5f64ca6d4a94 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-08-25 Simon Marchi + + * dwarf2read.c (dw2_debug_names_iterator::next): Use enum to + represent whether the symbol is static, dynamic, or we don't + know. + 2019-08-25 Yoshinori Sato * gdb/rx-tdep.c (rx_register_names): New. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index de9755f6ce30..a0b989fd0c2e 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -5843,7 +5843,11 @@ dw2_debug_names_iterator::next () return NULL; } const mapped_debug_names::index_val &indexval = indexval_it->second; - gdb::optional is_static; + enum class symbol_linkage { + unknown, + static_, + extern_, + } symbol_linkage = symbol_linkage::unknown; dwarf2_per_cu_data *per_cu = NULL; for (const mapped_debug_names::index_val::attr &attr : indexval.attr_vec) { @@ -5895,12 +5899,12 @@ dw2_debug_names_iterator::next () case DW_IDX_GNU_internal: if (!m_map.augmentation_is_gdb) break; - is_static = true; + symbol_linkage = symbol_linkage::static_; break; case DW_IDX_GNU_external: if (!m_map.augmentation_is_gdb) break; - is_static = false; + symbol_linkage = symbol_linkage::extern_; break; } } @@ -5910,10 +5914,11 @@ dw2_debug_names_iterator::next () goto again; /* Check static vs global. */ - if (is_static.has_value () && m_block_index.has_value ()) + if (symbol_linkage != symbol_linkage::unknown && m_block_index.has_value ()) { const bool want_static = *m_block_index == STATIC_BLOCK; - if (want_static != *is_static) + const bool symbol_is_static = symbol_linkage == symbol_linkage::static_; + if (want_static != symbol_is_static) goto again; }