From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6335 invoked by alias); 24 Jun 2013 12:56:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 6324 invoked by uid 89); 24 Jun 2013 12:56:19 -0000 X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,SPF_PASS autolearn=ham version=3.3.1 Received: from mail-la0-f43.google.com (HELO mail-la0-f43.google.com) (209.85.215.43) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 24 Jun 2013 12:56:18 +0000 Received: by mail-la0-f43.google.com with SMTP id gw10so10308696lab.16 for ; Mon, 24 Jun 2013 05:56:15 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.168.132 with SMTP id zw4mr7484526lbb.79.1372078575684; Mon, 24 Jun 2013 05:56:15 -0700 (PDT) Received: by 10.112.71.139 with HTTP; Mon, 24 Jun 2013 05:56:15 -0700 (PDT) In-Reply-To: References: <51B20120.8070909@gmail.com> Date: Mon, 24 Jun 2013 13:42:00 -0000 Message-ID: Subject: Re: [patch] Parse quoted string for restore/dump commands. From: Wei-cheng Wang To: Sergio Durigan Junior Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2013-06/txt/msg00649.txt.bz2 Hi Sergio, On Thu, Jun 20, 2013 at 1:11 PM, Sergio Durigan Junior wrote: > On Thursday, June 20 2013, I wrote: > Oh, sorry, I should have been clearer. I was not referring to the > xrealloc inside the for/if, but rather I was saying that you could call > xrealloc *again* after you set "*outp = '\0'", after the loop finishes. > > When the loop finishes you might end up with "filename" being larger > than you need. I've fixed it accordingly at the end of the mail. Thanks for you suggestion. > >> Also, when you commit the patch, please remember to include your info on >> gdb/MAINTAINERS, since you will be able to commit after approval. > > Just to be totally clear: this modification to gdb/MAINTAINERS should be > considered a totally different patch, and should not be > included/committed with this one :-). Actually, I didn't have CVS write access yet. I may need a sponsor. Before that, I need someone help me checking this patch in, if approved :-) -- gdb/ChangeLog | 6 +++++ gdb/cli/cli-dump.c | 54 ++++++++++++++++++++++++++++++++++----- gdb/testsuite/ChangeLog | 4 +++ gdb/testsuite/gdb.base/dump.exp | 34 +++++++++++++++++++++++- 4 files changed, 91 insertions(+), 7 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1efd3f9..b7a87eb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2013-06-24 Wei-cheng Wang + Sergio Durigan Junior + + * cli/cli-dump.c (scan_filename_with_cleanup): Parse quoted or + escaped string when scanning filename. + 2013-06-21 Joel Brobecker * gdb/gnulib/Makefile.in: Update date in copyright header. diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c index 208916c..70fdfee 100644 --- a/gdb/cli/cli-dump.c +++ b/gdb/cli/cli-dump.c @@ -80,14 +80,56 @@ scan_filename_with_cleanup (char **cmd, const char *defname) } else { - /* FIXME: should parse a possibly quoted string. */ - char *end; + char *inp, *outp; + char quote = '\0'; + int escape = 0; + size_t capacity; + + inp = skip_spaces (*cmd); + /* Allocate initial buffer for filename. If there is no space + in quoted string, this should be the exactly size what we + need. */ + capacity = strcspn (inp, " \t") + 1; + filename = xmalloc (capacity); + outp = filename; + + /* Quoting character. */ + if (*inp == '\'' || *inp == '"') + quote = *inp++; + + for (; *inp != '\0'; inp++) + { + /* Stop by whitespace, if not quoted or escaped. */ + if (isspace (*inp) && !escape && quote != '\0') + break; + + if (escape) + { + escape = 0; + *outp++ = *inp; + } + else if (*inp == '\\') + escape = 1; + else if (*inp == quote) + quote = '\0'; + else + *outp++ = *inp; + + /* Expand when needed. */ + if (outp - filename >= capacity) + { + size_t len = outp - filename; - (*cmd) = skip_spaces (*cmd); - end = *cmd + strcspn (*cmd, " \t"); - filename = savestring ((*cmd), end - (*cmd)); + capacity *= 2; + filename = xrealloc (filename, capacity); + outp = filename + len; + } + } + + *outp = '\0'; + filename = xrealloc (filename, outp - filename + 1); make_cleanup (xfree, filename); - (*cmd) = skip_spaces (end); + (*cmd) = skip_spaces (inp); } gdb_assert (filename != NULL); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 9abc780..bdfa065 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2013-06-24 Wei-cheng Wang + + * gdb.base/dump.exp: Test tests for filenames with spaces. + 2013-06-21 Tom Tromey * gdb.trace/actions.exp (check_tracepoint): Don't use a full file diff --git a/gdb/testsuite/gdb.base/dump.exp b/gdb/testsuite/gdb.base/dump.exp index b2d0b3a..ab0481c 100644 --- a/gdb/testsuite/gdb.base/dump.exp +++ b/gdb/testsuite/gdb.base/dump.exp @@ -105,6 +105,18 @@ make_dump_file "dump bin val intarr1b.bin intarray" \ make_dump_file "dump bin val intstr1b.bin intstruct" \ "dump struct as value, binary" +make_dump_file "dump bin val \"intarr1c .bin\" intarray" \ + "dump array as value, binary, quoted whitespace" + +make_dump_file "dump bin val \"intstr1c .bin\" intstruct" \ + "dump struct as value, binary, quoted whitespace" + +make_dump_file "dump bin val intarr1d\\ .bin intarray" \ + "dump array as value, binary, escaped whitespace" + +make_dump_file "dump bin val intstr1d\\ .bin intstruct" \ + "dump struct as value, binary, escaped whitespace" + make_dump_file "dump srec val intarr1.srec intarray" \ "dump array as value, srec" @@ -300,6 +312,26 @@ test_restore_saved_value "intstr1.bin binary $struct_start" \ gdb_test "print zero_all ()" ".*" +test_restore_saved_value "intarr1c\\ .bin binary $array_start" \ + "array as value, binary, quoted whitespace" \ + $array_val "intarray" + +test_restore_saved_value "intstr1c\\ .bin binary $struct_start" \ + "struct as value, binary, quoted whitespace" \ + $struct_val "intstruct" + +gdb_test "print zero_all ()" ".*" + +test_restore_saved_value "\"intarr1d .bin\" binary $array_start" \ + "array as value, binary, escape whitespace" \ + $array_val "intarray" + +test_restore_saved_value "\"intstr1d .bin\" binary $struct_start" \ + "struct as value, binary, escape whitespace" \ + $struct_val "intstruct" + +gdb_test "print zero_all ()" ".*" + test_restore_saved_value "intarr2.bin binary $array_start" \ "array as memory, binary" \ $array_val "intarray" @@ -505,4 +537,4 @@ if ![string compare $is64bitonly "no"] then { # clean up files -remote_exec build "rm -f intarr1.bin intarr1b.bin intarr1.ihex intarr1.srec intarr1.tekhex intarr2.bin intarr2b.bin intarr2.ihex intarr2.srec intarr2.tekhex intstr1.bin intstr1b.bin intstr1.ihex intstr1.srec intstr1.tekhex intstr2.bin intstr2b.bin intstr2.ihex intstr2.srec intstr2.tekhex intarr3.srec" +remote_exec build "rm -f intarr1.bin intarr1b.bin \"intarr1c .bin\" \"intarr1d .bin\" intarr1.ihex intarr1.srec intarr1.tekhex intarr2.bin intarr2b.bin intarr2.ihex intarr2.srec intarr2.tekhex intstr1.bin intstr1b.bin \"intstr1c .bin\" \"intstr1d .bin\" intstr1.ihex intstr1.srec intstr1.tekhex intstr2.bin intstr2b.bin intstr2.ihex intstr2.srec intstr2.tekhex intarr3.srec" --