From patchwork Thu May 22 15:17:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gutson X-Patchwork-Id: 1077 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id 5EF04360079 for ; Thu, 22 May 2014 08:17:48 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14314964) id BCDE05C3E201; Thu, 22 May 2014 08:17:47 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx22.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx22.g.dreamhost.com (Postfix) with ESMTPS id 2A8CE5949C5B for ; Thu, 22 May 2014 08:17:47 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; q=dns; s=default; b= NgJNeDuZ0TGpXe8I1nns/Kd7uV9gyru1U0/fItEtZNeZ8WrACBu5Sm6RnZSNkx4d IzmES0FPdPMpk41GM+IeWwc+pFKLBu662V4dcKbY/JlVZD2hrydOF1Vr2kWx+X5T 3IKmuq0jYflT0lBi5FVgJxU2cy0lF6wcd/++49rqLb8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; s=default; bh=PIV7U pZA9YO3xZffohf386AIOBg=; b=mLPdvjpVZqebXInwWsUov4zB7UFR/d5tRXn3s KY2yMYXtjVxZHYkdah+dyIOM92nLAz5d8XF2Qwo1I32AtIHuRS3Rnm9DUx+W7In0 7UzW7JuZ6wJIDQy2Iwd3Oe1VDjmlmWLAQ+yvUFqg/RsGfwiv2tnpUNOHqipE/Xja aYUTmQ= Received: (qmail 15837 invoked by alias); 22 May 2014 15:17:40 -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 15778 invoked by uid 89); 22 May 2014 15:17:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: mail-la0-f45.google.com Received: from mail-la0-f45.google.com (HELO mail-la0-f45.google.com) (209.85.215.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 22 May 2014 15:17:37 +0000 Received: by mail-la0-f45.google.com with SMTP id gl10so2766017lab.18 for ; Thu, 22 May 2014 08:17:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=MwXNVBGLXZZexQVIjtwTrnAqo5QNWdBazms4AsZ7jws=; b=k+W142YpcsqKo6f8hIjbtWSxNibddE39ieD8AkUvVS72Q5JJzMiRkNaXJvZIbbQv+v xrrILU6nrguNakhfDfhqYvCsHXaMqnoXGzieB8ujQAtnuml3nqH/TOeE+JpbWHJ5GvlP algnvB3cK+7G+Uln/k2hIYwX++wkImVcWm1bN+MmJRz5tnBzBmZBFAp+LR/eh/Iek7wC XZ8aSTTnqhwvKMzb1earK6ecot3S69G3qyVJuog6tpktYFbqaap4fk84aEx3S8wS9wWr ak/nhv+gKrTtC5gBJ1L8qfMYr/aRawKam7tFpYstPjfHWWjPr7d9wLORIwsqQSTPZh8Q lRhw== X-Gm-Message-State: ALoCoQm3lORfnk37sd/cCAxbaQ6EVFlVILSBAYF3sRVHk0YayJITmjybqWq2WwfJpU/dM7IPPZ4a MIME-Version: 1.0 X-Received: by 10.112.13.35 with SMTP id e3mr36017423lbc.44.1400771853433; Thu, 22 May 2014 08:17:33 -0700 (PDT) Received: by 10.112.9.5 with HTTP; Thu, 22 May 2014 08:17:33 -0700 (PDT) In-Reply-To: <87tx8ks8yv.fsf@fleche.redhat.com> References: <87tx8ks8yv.fsf@fleche.redhat.com> Date: Thu, 22 May 2014 12:17:33 -0300 Message-ID: Subject: Re: [PATCH] Add autocompletion for convenience vars in print and set From: Daniel Gutson To: Tom Tromey Cc: gdb-patches X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in Second version. Comments below: On Tue, May 20, 2014 at 1:36 PM, Tom Tromey wrote: >>>>>> "Daniel" == Daniel Gutson writes: > > Daniel> I could not find any testsuite where to add tests for this; if > Daniel> there are, please let me know. > > See testsuite/gdb.base/completion.exp Thanks, I ran all the tests and passed. I did not add a new test case though since I didn't check how to add a new convenience var and undefine it later from the test framework. (Should I try harder?) > > Daniel> exp : VARIABLE > Daniel> { > Daniel> - write_dollar_variable (pstate, $1); > Daniel> + if (!parse_completion) > Daniel> + write_dollar_variable (pstate, $1); > Daniel> } > > I think this isn't correct. I think it won't work if you try to > complete on a field name where the "LHS" has a convenience variable. > That is something like: > > set $var = (struct x *) malloc (...) > complete print $var.somethin You were right, that was broken. > > Instead I think you need a new production, like "exp : VARIABLE COMPLETE". I found another solution without touching the yacc file: adding a check inside write_dollar_variable > > Daniel> + if (p != NULL && *p == '$') > Daniel> + return complete_internalvar (p + 1); > > I'm not sure this is correct either, but offhand I don't know. > Should it not look at "word"? It actually works ("word" didn't have the $). However, I noticed that 'set' cmd autocomplete doesn't work for members of structures (neither with convenience vars nor regular symbols). I'll address that in the next patch once this gets approved and committed. > > Daniel> + VEC (char_ptr) * ret = current_language->la_make_symbol_completion_list ( > Daniel> + text, word, > Daniel> + TYPE_CODE_UNDEF); > > No space before "ret". > The line breaks look odd, I would break before the "=" and not after the "(". > > thanks, > Tom 2014-05-22 Daniel Gutson gdb/ * parse.c (write_dollar_variable): Do not create an internal var when completing. * completer.c (expression_completer): Call complete_internalvar. * symtab.c (make_symbol_completion_list): Call complete_internalvar. diff --git a/gdb/completer.c b/gdb/completer.c index 94f70a9..6c5cdf8 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -20,6 +20,7 @@ #include "symtab.h" #include "gdbtypes.h" #include "expression.h" +#include "value.h" #include "filenames.h" /* For DOSish file names. */ #include "language.h" #include "gdb_assert.h" @@ -446,8 +447,11 @@ expression_completer (struct cmd_list_element *ignore, p--) ; - /* Not ideal but it is what we used to do before... */ - return location_completer (ignore, p, word); + if (p != NULL && *p == '$') + return complete_internalvar (p + 1); + else + /* Not ideal but it is what we used to do before... */ + return location_completer (ignore, p, word); } /* Here are some useful test cases for completion. FIXME: These diff --git a/gdb/parse.c b/gdb/parse.c index 105d0cd..218be13 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -692,10 +692,12 @@ write_dollar_variable (struct parser_state *ps, struct stoken str) } /* Any other names are assumed to be debugger internal variables. */ - - write_exp_elt_opcode (ps, OP_INTERNALVAR); - write_exp_elt_intern (ps, create_internalvar (copy_name (str) + 1)); - write_exp_elt_opcode (ps, OP_INTERNALVAR); + if (!parse_completion) + { + write_exp_elt_opcode (ps, OP_INTERNALVAR); + write_exp_elt_intern (ps, create_internalvar (copy_name (str) + 1)); + write_exp_elt_opcode (ps, OP_INTERNALVAR); + } return; handle_last: write_exp_elt_opcode (ps, OP_LAST); diff --git a/gdb/symtab.c b/gdb/symtab.c index 15ac3d1..52eb64c 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4542,14 +4542,21 @@ default_make_symbol_completion_list (const char *text, const char *word, } /* Return a vector of all symbols (regardless of class) which begin by - matching TEXT. If the answer is no symbols, then the return value - is NULL. */ + matching TEXT. If the answer is no symbols, then check whether the + text is an internal var ($foo), if so, return what complete_internalvar + returns; otherwise the return value is NULL. */ VEC (char_ptr) * make_symbol_completion_list (const char *text, const char *word) { - return current_language->la_make_symbol_completion_list (text, word, - TYPE_CODE_UNDEF); + VEC (char_ptr) *ret + = current_language->la_make_symbol_completion_list (text, word, + TYPE_CODE_UNDEF); + + if (ret == NULL && *text == '$') + ret = complete_internalvar (text + 1); + + return ret; } /* Like make_symbol_completion_list, but only return STRUCT_DOMAIN