From patchwork Mon Mar 20 10:49:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 19656 Received: (qmail 46340 invoked by alias); 20 Mar 2017 10:49:17 -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 46281 invoked by uid 89); 20 Mar 2017 10:49:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Yao, 191 X-HELO: mail-wm0-f44.google.com Received: from mail-wm0-f44.google.com (HELO mail-wm0-f44.google.com) (74.125.82.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Mar 2017 10:49:12 +0000 Received: by mail-wm0-f44.google.com with SMTP id u132so59917356wmg.0 for ; Mon, 20 Mar 2017 03:49:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=GAJ3TJMZiQMUWTez5c6A7OSSElD/Dcmxy1g6+f/LvaM=; b=DfKFClupX/BKIMTNz533RF/bFtE1CxnAsSEap56TMq+izJVGaKhL5HVIx3lA6a51DL ObWBf2KFXmXJUBkMgVaRhFliOyrnYlcTKP04Yoz5Tdb1P+O60vxcYmuzYjlsLiYs2U+R AU796KLZcY3oKV3QsSed/RviBr9tgT434V0wSn429d7Fjn/zlOKNXwC0hAi8Kubsnk5z 0LVhJPTRRZfvloQCPILtN//1DrUV8SW3QI3EgVxVCg/vfZ5+kcLssJQ32vG0x6zGnZbm VRLhxfWZSSBv9Lb639tUHfWhXFQy7CsDybUsTI7/cyOvdFIWx7jxrQ0MesrL59Og8w4X eBGw== X-Gm-Message-State: AFeK/H3yR4ZZ+D5vv0GpWAMgKK7U5555jOf7zBQj6SJq6kMNWC6ZG46mBPAnhJoKcE5bzA== X-Received: by 10.28.195.214 with SMTP id t205mr4768451wmf.104.1490006950400; Mon, 20 Mar 2017 03:49:10 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com ([194.214.185.158]) by smtp.gmail.com with ESMTPSA id t63sm12983404wme.16.2017.03.20.03.49.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Mar 2017 03:49:09 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH] Wrap locally used classes in anonymous namespace Date: Mon, 20 Mar 2017 10:49:08 +0000 Message-Id: <1490006948-13255-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes Both aarch64-tdep.c and arm-tdep.c defines a class instruction_reader, which violates ODR, but linker doesn't an emit error. I fix this issue by wrapping them by anonymous namespace, but I think it is better to apply this for all locally used classes. If it is a good idea to put locally used class into anonymous namespace, we should document this rule into GDB coding convention, or even GCC coding convention. Note that anonymous namespace has been used in GCC but GCC coding convention doesn't mention the it. gdb: 2017-03-20 Yao Qi * aarch64-tdep.c: Wrap locally used classes in anonymous namespace. * arm-tdep.c: Likewise. * linespec.c: Likewise. * ui-out.c: Likewise. --- gdb/aarch64-tdep.c | 4 ++++ gdb/arm-tdep.c | 3 +++ gdb/linespec.c | 8 ++++++++ gdb/ui-out.c | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 801c03d..b922174 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -196,6 +196,8 @@ show_aarch64_debug (struct ui_file *file, int from_tty, fprintf_filtered (file, _("AArch64 debugging is %s.\n"), value); } +namespace { + /* Abstract instruction reader. */ class abstract_instruction_reader @@ -217,6 +219,8 @@ class instruction_reader : public abstract_instruction_reader } }; +} // namespace + /* Analyze a prologue, looking for a recognizable stack frame and frame pointer. Scan until we encounter a store that could clobber the stack frame unexpectedly, or an unknown instruction. */ diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 98d8e0e..b168f43 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -12951,6 +12951,7 @@ thumb2_record_decode_insn_handler (insn_decode_record *thumb2_insn_r) return -1; } +namespace { /* Abstract memory reader. */ class abstract_memory_reader @@ -12976,6 +12977,8 @@ class instruction_reader : public abstract_memory_reader } }; +} // namespace + /* Extracts arm/thumb/thumb2 insn depending on the size, and returns 0 on success and positive val on fauilure. */ diff --git a/gdb/linespec.c b/gdb/linespec.c index 72bcd60..a3cb0cb 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -2793,6 +2793,8 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char *arg) return values; } +namespace { + /* A function object that serves as symbol_found_callback_ftype callback for iterate_over_symbols. This is used by lookup_prefix_sym to collect type symbols. */ @@ -2859,6 +2861,8 @@ decode_compound_collector::operator () (symbol *sym) return true; /* Continue iterating. */ } +} // namespace + /* Return any symbols corresponding to CLASS_NAME in FILE_SYMTABS. */ static VEC (symbolp) * @@ -3095,6 +3099,8 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs, +namespace { + /* This function object is a callback for iterate_over_symtabs, used when collecting all matching symtabs. */ @@ -3148,6 +3154,8 @@ symtab_collector::operator () (struct symtab *symtab) return false; } +} // namespace + /* Given a file name, return a VEC of all matching symtabs. If SEARCH_PSPACE is not NULL, the search is restricted to just that program space. */ diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 42cffbe..9c27742 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -30,6 +30,8 @@ #include #include +namespace { + /* A header of a ui_out_table. */ class ui_out_hdr @@ -91,6 +93,8 @@ class ui_out_hdr std::string m_header; }; +} // namespace + /* A level of nesting (either a list or a tuple) in a ui_out output. */ class ui_out_level