From patchwork Fri Jul 27 21:03:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Franco de Carvalho X-Patchwork-Id: 28661 Received: (qmail 117114 invoked by alias); 27 Jul 2018 21:03:48 -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 117039 invoked by uid 89); 27 Jul 2018 21:03:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 27 Jul 2018 21:03:46 +0000 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6RKsOel039174 for ; Fri, 27 Jul 2018 17:03:44 -0400 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2kg9cskddb-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Jul 2018 17:03:44 -0400 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 27 Jul 2018 17:03:43 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 27 Jul 2018 17:03:40 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w6RL3cAv7733750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 27 Jul 2018 21:03:38 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA776AE067; Fri, 27 Jul 2018 17:02:50 -0400 (EDT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5A872AE06D; Fri, 27 Jul 2018 17:02:50 -0400 (EDT) Received: from pedro.localdomain (unknown [9.85.199.57]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 27 Jul 2018 17:02:50 -0400 (EDT) Received: by pedro.localdomain (Postfix, from userid 1000) id C0F483C04BD; Fri, 27 Jul 2018 18:03:35 -0300 (-03) From: Pedro Franco de Carvalho To: gdb-patches@sourceware.org Cc: uweigand@de.ibm.com Subject: [PATCH v2 5/6] Variable size for regs mask in collection list Date: Fri, 27 Jul 2018 18:03:17 -0300 In-Reply-To: <20180727210318.2960-1-pedromfc@linux.ibm.com> References: <20180727210318.2960-1-pedromfc@linux.ibm.com> x-cbid: 18072721-0064-0000-0000-00000330A82A X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009440; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01067028; UDB=6.00548260; IPR=6.00844894; MB=3.00022359; MTD=3.00000008; XFM=3.00000015; UTC=2018-07-27 21:03:41 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18072721-0065-0000-0000-00003A17D707 Message-Id: <20180727210318.2960-6-pedromfc@linux.ibm.com> This patch changes collection_list to allow larger register masks. The mask is changed from an array to a vector and is initialized to hold the maximum possible remote register number. The stringify method is updated to resize temp_buf if needed. gdb/ChangeLog: YYYY-MM-DD Pedro Franco de Carvalho * tracepoint.h (collection_list) : Change type to std::vector. * tracepoint.c (collection_list::collection_list): Remove m_regs_mask initializer from initializer list. Resize m_regs_mask using the largest remote register number. (collection_list::add_remote_register): Remove size check on m_regs_mask. Use at to access element. (collection_list::stringify): Change type of temp_buf to gdb::char_vector. Update uses of temp_buf. Resize if needed to stringify the register mask. Use pack_hex_byte for the register mask. --- gdb/tracepoint.c | 64 +++++++++++++++++++++++++++++++++++++------------------- gdb/tracepoint.h | 5 +++-- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index f06386158a..fffc9cc173 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -818,10 +818,8 @@ collection_list::add_remote_register (unsigned int regno) { if (info_verbose) printf_filtered ("collect register %d\n", regno); - if (regno >= (8 * sizeof (m_regs_mask))) - error (_("Internal: register number %d too large for tracepoint"), - regno); - m_regs_mask[regno / 8] |= 1 << (regno % 8); + + m_regs_mask.at (regno / 8) |= 1 << (regno % 8); } /* Add all the registers from the mask in AEXPR to the mask in the @@ -1122,9 +1120,20 @@ collection_list::add_static_trace_data () } collection_list::collection_list () - : m_regs_mask (), - m_strace_data (false) + : m_strace_data (false) { + int max_remote_regno = 0; + for (int i = 0; i < gdbarch_num_regs (target_gdbarch ()); i++) + { + int remote_regno = (gdbarch_remote_register_number + (target_gdbarch (), i)); + + if (remote_regno >= 0 && remote_regno > max_remote_regno) + max_remote_regno = remote_regno; + } + + m_regs_mask.resize ((max_remote_regno / 8) + 1); + m_memranges.reserve (128); m_aexprs.reserve (128); } @@ -1134,7 +1143,8 @@ collection_list::collection_list () std::vector collection_list::stringify () { - char temp_buf[2048]; + gdb::char_vector temp_buf (2048); + int count; char *end; long i; @@ -1144,35 +1154,45 @@ collection_list::stringify () { if (info_verbose) printf_filtered ("\nCollecting static trace data\n"); - end = temp_buf; + end = temp_buf.data (); *end++ = 'L'; - str_list.emplace_back (temp_buf, end - temp_buf); + str_list.emplace_back (temp_buf.data (), end - temp_buf.data ()); } - for (i = sizeof (m_regs_mask) - 1; i > 0; i--) + for (i = m_regs_mask.size () - 1; i > 0; i--) if (m_regs_mask[i] != 0) /* Skip leading zeroes in regs_mask. */ break; if (m_regs_mask[i] != 0) /* Prepare to send regs_mask to the stub. */ { if (info_verbose) printf_filtered ("\nCollecting registers (mask): 0x"); - end = temp_buf; + + /* One char for 'R', one for the null terminator and two per + mask byte. */ + std::size_t new_size = (i + 1) * 2 + 2; + if (new_size > temp_buf.size ()) + temp_buf.resize (new_size); + + end = temp_buf.data (); *end++ = 'R'; for (; i >= 0; i--) { QUIT; /* Allow user to bail out with ^C. */ if (info_verbose) printf_filtered ("%02X", m_regs_mask[i]); - sprintf (end, "%02X", m_regs_mask[i]); - end += 2; + + end = pack_hex_byte (end, m_regs_mask[i]); } - str_list.emplace_back (temp_buf); + *end = '\0'; + + str_list.emplace_back (temp_buf.data ()); } if (info_verbose) printf_filtered ("\n"); if (!m_memranges.empty () && info_verbose) printf_filtered ("Collecting memranges: \n"); - for (i = 0, count = 0, end = temp_buf; i < m_memranges.size (); i++) + for (i = 0, count = 0, end = temp_buf.data (); + i < m_memranges.size (); i++) { QUIT; /* Allow user to bail out with ^C. */ if (info_verbose) @@ -1186,9 +1206,9 @@ collection_list::stringify () } if (count + 27 > MAX_AGENT_EXPR_LEN) { - str_list.emplace_back (temp_buf, count); + str_list.emplace_back (temp_buf.data (), count); count = 0; - end = temp_buf; + end = temp_buf.data (); } { @@ -1208,7 +1228,7 @@ collection_list::stringify () } count += strlen (end); - end = temp_buf + count; + end = temp_buf.data () + count; } for (i = 0; i < m_aexprs.size (); i++) @@ -1216,9 +1236,9 @@ collection_list::stringify () QUIT; /* Allow user to bail out with ^C. */ if ((count + 10 + 2 * m_aexprs[i]->len) > MAX_AGENT_EXPR_LEN) { - str_list.emplace_back (temp_buf, count); + str_list.emplace_back (temp_buf.data (), count); count = 0; - end = temp_buf; + end = temp_buf.data (); } sprintf (end, "X%08X,", m_aexprs[i]->len); end += 10; /* 'X' + 8 hex digits + ',' */ @@ -1230,9 +1250,9 @@ collection_list::stringify () if (count != 0) { - str_list.emplace_back (temp_buf, count); + str_list.emplace_back (temp_buf.data (), count); count = 0; - end = temp_buf; + end = temp_buf.data (); } return str_list; diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h index 8bdad3567e..c185672cc1 100644 --- a/gdb/tracepoint.h +++ b/gdb/tracepoint.h @@ -292,8 +292,9 @@ public: { return m_computed; } private: - /* room for up to 256 regs */ - unsigned char m_regs_mask[32]; + /* We need the allocator zero-initialize the mask, so we don't use + gdb::byte_vector. */ + std::vector m_regs_mask; std::vector m_memranges;