From patchwork Mon May 21 16:04:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 27359 Received: (qmail 88967 invoked by alias); 21 May 2018 16:04:08 -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 88950 invoked by uid 89); 21 May 2018 16:04:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=regs X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 21 May 2018 16:04:04 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E5BC401EF01; Mon, 21 May 2018 16:04:03 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 863F485778; Mon, 21 May 2018 16:04:02 +0000 (UTC) Subject: Re: [PATCH 05/10] remote: remote_arch_state pointers -> remote_arch_state objects To: Simon Marchi , gdb-patches@sourceware.org References: <20180516141830.16859-1-palves@redhat.com> <20180516141830.16859-6-palves@redhat.com> <2f2b904b-7ceb-ef99-8017-1ea42c241f17@ericsson.com> <8a8783b3-0d5b-c7e7-886c-13c52aaa1ddd@ericsson.com> From: Pedro Alves Message-ID: <1fb4bd88-0e31-736a-451f-8f15ce156cee@redhat.com> Date: Mon, 21 May 2018 17:04:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <8a8783b3-0d5b-c7e7-886c-13c52aaa1ddd@ericsson.com> On 05/18/2018 10:09 PM, Simon Marchi wrote: > Oops, spoke a bit too soon. It fails to build with g++ 5.4.0 (Ubuntu 16.04). > It doesn't like the "this->m_arch_states.emplace (gdbarch, gdbarch)". With > g++ 7.1.0 it builds fine. > > /home/emaisin/src/binutils-gdb/gdb/remote.c:962:61: required from here > /usr/include/c++/5/ext/new_allocator.h:120:4: error: no matching function for call to ‘std::pair::pair(gdbarch*&, gdbarch*&)’ > { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } > ^ Bah. I tried with gcc 4.8 now, and it trips on the same issue. Using a different emplace overload works. From aecfc376df9b718c9f86898db925031151d16774 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 21 May 2018 16:47:03 +0100 Subject: [PATCH] remote: remote_arch_state pointers -> remote_arch_state objects The previous patch made the map store pointers to remote_arch_state instead of objects directly, simply because struct remote_arch_state is still incomplete where struct remote_state is declared. This patch thus moves the remote_arch_state declaration higher up in the file, and makes the map store remote_arch_state objects directly instead of pointers to objects. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * remote.c (struct packet_reg, struct remote_arch_state): Move higher up in the file. (remote_state) : Store remote_arch_state values instead of remote_arch_state pointers. (remote_state::get_remote_arch_state): Adjust. --- gdb/remote.c | 95 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index ba054f5061..1d1819bac1 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -603,6 +603,44 @@ struct readahead_cache ULONGEST miss_count = 0; }; +/* Description of the remote protocol for a given architecture. */ + +struct packet_reg +{ + long offset; /* Offset into G packet. */ + long regnum; /* GDB's internal register number. */ + LONGEST pnum; /* Remote protocol register number. */ + int in_g_packet; /* Always part of G packet. */ + /* long size in bytes; == register_size (target_gdbarch (), regnum); + at present. */ + /* char *name; == gdbarch_register_name (target_gdbarch (), regnum); + at present. */ +}; + +struct remote_arch_state +{ + explicit remote_arch_state (struct gdbarch *gdbarch); + + /* Description of the remote protocol registers. */ + long sizeof_g_packet; + + /* Description of the remote protocol registers indexed by REGNUM + (making an array gdbarch_num_regs in size). */ + std::unique_ptr regs; + + /* This is the size (in chars) of the first response to the ``g'' + packet. It is used as a heuristic when determining the maximum + size of memory-read and memory-write packets. A target will + typically only reserve a buffer large enough to hold the ``g'' + packet. The size does not include packet overhead (headers and + trailers). */ + long actual_register_packet_size; + + /* This is the maximum size (in chars) of a non read/write packet. + It is also used as a cap on the size of read/write packets. */ + long remote_packet_size; +}; + /* Description of the remote protocol state for the currently connected target. This is per-target state, and independent of the selected architecture. */ @@ -749,8 +787,7 @@ private: /* Mapping of remote protocol data for each gdbarch. Usually there is only one entry here, though we may see more with stubs that support multi-process. */ - std::unordered_map> + std::unordered_map m_arch_states; }; @@ -820,44 +857,6 @@ get_remote_state_raw (void) return remote_state; } -/* Description of the remote protocol for a given architecture. */ - -struct packet_reg -{ - long offset; /* Offset into G packet. */ - long regnum; /* GDB's internal register number. */ - LONGEST pnum; /* Remote protocol register number. */ - int in_g_packet; /* Always part of G packet. */ - /* long size in bytes; == register_size (target_gdbarch (), regnum); - at present. */ - /* char *name; == gdbarch_register_name (target_gdbarch (), regnum); - at present. */ -}; - -struct remote_arch_state -{ - explicit remote_arch_state (struct gdbarch *gdbarch); - - /* Description of the remote protocol registers. */ - long sizeof_g_packet; - - /* Description of the remote protocol registers indexed by REGNUM - (making an array gdbarch_num_regs in size). */ - std::unique_ptr regs; - - /* This is the size (in chars) of the first response to the ``g'' - packet. It is used as a heuristic when determining the maximum - size of memory-read and memory-write packets. A target will - typically only reserve a buffer large enough to hold the ``g'' - packet. The size does not include packet overhead (headers and - trailers). */ - long actual_register_packet_size; - - /* This is the maximum size (in chars) of a non read/write packet. - It is also used as a cap on the size of read/write packets. */ - long remote_packet_size; -}; - /* Utility: generate error from an incoming stub packet. */ static void trace_error (char *buf) @@ -958,10 +957,15 @@ remote_get_noisy_reply () struct remote_arch_state * remote_state::get_remote_arch_state (struct gdbarch *gdbarch) { - auto &rsa = this->m_arch_states[gdbarch]; - if (rsa == nullptr) + remote_arch_state *rsa; + + auto it = this->m_arch_states.find (gdbarch); + if (it == this->m_arch_states.end ()) { - rsa.reset (new remote_arch_state (gdbarch)); + auto p = this->m_arch_states.emplace (std::piecewise_construct, + std::forward_as_tuple (gdbarch), + std::forward_as_tuple (gdbarch)); + rsa = &p.first->second; /* Make sure that the packet buffer is plenty big enough for this architecture. */ @@ -971,7 +975,10 @@ remote_state::get_remote_arch_state (struct gdbarch *gdbarch) this->buf = (char *) xrealloc (this->buf, this->buf_size); } } - return rsa.get (); + else + rsa = &it->second; + + return rsa; } /* Fetch the global remote target state. */