From patchwork Tue Jul 18 10:42:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 21661 Received: (qmail 54026 invoked by alias); 18 Jul 2017 10:42:56 -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 51876 invoked by uid 89); 18 Jul 2017 10:42:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Jul 2017 10:42:51 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DCBE62FFC29; Tue, 18 Jul 2017 10:42:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DCBE62FFC29 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DCBE62FFC29 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 F1AC9777D0; Tue, 18 Jul 2017 10:42:48 +0000 (UTC) Subject: [pushed] Fix GDB builds that include the simulator (Re: [PATCH 11/40] Introduce class completion_tracker & rewrite completion<->readline interaction) To: Christophe Lyon , gdb-patches@sourceware.org References: <1496406158-12663-1-git-send-email-palves@redhat.com> <1496406158-12663-12-git-send-email-palves@redhat.com> <5968FDFE.80302@redhat.com> <560f7c11-e627-6cc6-7b57-fa300dd6f3c2@redhat.com> <845f435e-d3d5-b327-4e3a-ce9434bd6ffd@redhat.com> From: Pedro Alves Message-ID: <0be037f9-03c3-372c-6dd5-5458a62109d2@redhat.com> Date: Tue, 18 Jul 2017 11:42:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <845f435e-d3d5-b327-4e3a-ce9434bd6ffd@redhat.com> On 07/18/2017 10:04 AM, Pedro Alves wrote: > sim_command_completer needs to be adjusted to the new interface. > I'm building a --target-none-eabi gdb to fix this. Thanks again for reporting. Fixed with the patch below. Pedro Alves From 386535dd91432b784f6a46f8a92c6a599ba30174 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 18 Jul 2017 11:38:17 +0100 Subject: [PATCH] Fix GDB builds that include the simulator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The completer rewrite series missed adjusting target sim to the new completion_tracker interface. src/gdb/remote-sim.c: In function ‘void _initialize_remote_sim()’: src/gdb/remote-sim.c:1350:46: error: invalid conversion from ‘VEC_char_ptr* (*)(cmd_list_element*, const char*, const char*)’ to ‘void (*)(cmd_list_element*, completion_tracker&, const char*, const char*)’ [-fpermissive] set_cmd_completer (c, sim_command_completer); ^ This commit fixes it, and also takes care to be exception safe (the previous code would leak if growing the VEC throws). Tested manually with a --target=arm-none-eabi build. gdb/ChangeLog: 2017-07-18 Pedro Alves * remote-sim.c (sim_command_completer): Adjust to work with a completion_tracker instead of a VEC. --- gdb/ChangeLog | 5 +++++ gdb/remote-sim.c | 48 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 20344f7..66ae527 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2017-07-18 Pedro Alves + + * remote-sim.c (sim_command_completer): Adjust to work with a + completion_tracker instead of a VEC. + 2017-07-17 Pedro Alves * completer.c (complete_source_filenames): New function. diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index 13137ab..508e2c2 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -1220,30 +1220,48 @@ simulator_command (char *args, int from_tty) registers_changed (); } -static VEC (char_ptr) * -sim_command_completer (struct cmd_list_element *ignore, const char *text, - const char *word) +static void +sim_command_completer (struct cmd_list_element *ignore, + completion_tracker &tracker, + const char *text, const char *word) { struct sim_inferior_data *sim_data; - char **tmp; - int i; - VEC (char_ptr) *result = NULL; sim_data = ((struct sim_inferior_data *) inferior_data (current_inferior (), sim_inferior_data_key)); if (sim_data == NULL || sim_data->gdbsim_desc == NULL) - return NULL; + return; - tmp = sim_complete_command (sim_data->gdbsim_desc, text, word); - if (tmp == NULL) - return NULL; + /* sim_complete_command returns a NULL-terminated malloc'ed array of + malloc'ed strings. */ + struct sim_completions_deleter + { + void operator() (char **ptr) const + { + for (size_t i = 0; ptr[i] != NULL; i++) + xfree (ptr[i]); + xfree (ptr); + } + }; + + std::unique_ptr sim_completions + (sim_complete_command (sim_data->gdbsim_desc, text, word)); + if (sim_completions == NULL) + return; - /* Transform the array into a VEC, and then free the array. */ - for (i = 0; tmp[i] != NULL; i++) - VEC_safe_push (char_ptr, result, tmp[i]); - xfree (tmp); + /* Count the elements and add completions from tail to head because + below we'll swap elements out of the array in case add_completion + throws and the deleter deletes until it finds a NULL element. */ + size_t count = 0; + while (sim_completions[count] != NULL) + count++; - return result; + for (size_t i = count; i > 0; i--) + { + gdb::unique_xmalloc_ptr match (sim_completions[i - 1]); + sim_completions[i - 1] = NULL; + tracker.add_completion (std::move (match)); + } } /* Check to see if a thread is still alive. */