From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19669 invoked by alias); 19 Jul 2011 05:34:07 -0000 Received: (qmail 19514 invoked by uid 22791); 19 Jul 2011 05:34:06 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-ey0-f174.google.com (HELO mail-ey0-f174.google.com) (209.85.215.174) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Jul 2011 05:33:44 +0000 Received: by eyx24 with SMTP id 24so2565951eyx.5 for ; Mon, 18 Jul 2011 22:33:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.213.13.136 with SMTP id c8mr2543757eba.17.1311053622867; Mon, 18 Jul 2011 22:33:42 -0700 (PDT) Received: by 10.213.22.195 with HTTP; Mon, 18 Jul 2011 22:33:42 -0700 (PDT) In-Reply-To: References: <834o2my2uj.fsf@gnu.org> Date: Tue, 19 Jul 2011 08:50:00 -0000 Message-ID: Subject: Re: [PATCH] gdb output pipelining to shell From: Abhijit Halder To: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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 X-SW-Source: 2011-07/txt/msg00450.txt.bz2 Further concern. The last submitted patch does not work in following scenar= io: (gdb) p argc | {int} &argc | {vim -} I think now I should take a pause and refrain myself of doing patch submission in this thread for some time! Regards, Abhijit Halder On Tue, Jul 19, 2011 at 12:31 AM, Abhijit Halder wrote: > Since I was overwriting the braces by space character, this could > essentially change a valid gdb command having braces after pipe. > Here is the example: > (gdb) p argc | {int} &argc > > I have modified the patch to defer the any overwrite (and essentially > the modification) of actual input string for very last moment when the > a sub-string of a given input in gdb prompt is qualified to be in a > valid format of shell command. > > I am re-submitting the patch for review and comments with the > necessary corrections in place. Please do comment on the changes. > > =A0top.c =A0 =A0 | =A0 77 +++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++- > =A0ui-file.c | =A0 15 ++++++++++++ > =A0ui-file.h | =A0 =A03 ++ > =A03 files changed, 94 insertions(+), 1 deletion(-) > > Regards, > Abhijit Halder > > > On Mon, Jul 18, 2011 at 11:31 PM, Abhijit Halder > wrote: >> Please don't consider this patch. This has a conflict with following >> syntax of of >> (gdb) p var | {type} address >> >> On Sat, Jul 16, 2011 at 11:35 PM, Abhijit Halder >> wrote: >>> A small correction. Re-submitting the patch. The earlier patch was not >>> able to handle below situation: >>> (gdb) p '|' | { less } >>> >>> On Sat, Jul 16, 2011 at 3:38 PM, Abhijit Halder >>> wrote: >>>> On Sat, Jul 16, 2011 at 3:17 PM, Eli Zaretskii wrote: >>>>>> Date: Sat, 16 Jul 2011 14:12:35 +0530 >>>>>> From: Abhijit Halder >>>>>> >>>>>> I have implemented a feature which will allow one to pass the output >>>>>> of any gdb command to the shell for further processing. >>>>> >>>>> Thanks. >>>>> >>>>> If this is accepted, we will need a corresponding addition to the >>>>> manual. >>>>> >>>>>> + =A0 =A0 =A0for (cpos =3D spos; (cpos =3D memchr (cpos, '"', (sh_cm= d-cpos))) !=3D NULL; cpos++) >>>>>> + =A0 =A0 =A0 =A0quote_cnt++; >>>>>> + =A0 =A0 =A0spos =3D (sh_cmd + 1); >>>>>> + =A0 =A0 =A0if ((quote_cnt % 2) =3D=3D 0 || (sh_cmd =3D strchr (spo= s, '|')) =3D=3D NULL) >>>>>> + =A0 =A0 =A0 =A0break; >>>>> >>>>> I'm not sure I understand this (comments would be helpful). =A0Are you >>>>> assuming that quote characters `"' in shell commands cannot be >>>>> escaped, e.g. with a backslash? =A0And what about quoting with a sing= le >>>>> quote character ("'")? >>>>> >>>> Any pipe ('|' character), not within double quote will be considered >>>> as either a bitwise-OR operator or a pipe between gdb and shell. >>>> String after pipe (not within double quote) will be considered as >>>> shell command if (and only if) it is encapsulated within opening and >>>> closing braces ('{' and '}') . The shell command can surely contain >>>> double quote, even braces. There is no validation done for shell >>>> command. >>>> >>>>>> + =A0 =A0if (*cpos !=3D '{') >>>>>> + =A0 =A0 =A0return NULL; >>>>>> + >>>>>> + =A0 =A0*cpos =3D ' '; >>>>>> + >>>>>> + =A0 =A0cpos =3D epos; >>>>>> + =A0 =A0while (isspace(*cpos)) >>>>>> + =A0 =A0 =A0cpos--; >>>>>> + >>>>>> + =A0 =A0if (*cpos !=3D '}') >>>>>> + =A0 =A0 =A0return NULL; >>>>> >>>>> What is this magic about {...} that you are removing? =A0Again, comme= nts >>>>> could help. >>>>> >>>> Here I am removing the braces from the shell command. An example will >>>> help in understanding this: >>>> (gdb) thread apply all bt | { grep "foo" } >>>> This will be a valid command. { grep "foo" } will be considered as >>>> shell command and we need to erase the braces part of it to make it a >>>> valid shell command. >>>>>> + >>>>>> + =A0 =A0*cpos =3D ' '; >>>>>> + =A0 =A0} >>>>>> + >>>>>> + =A0if (sh_cmd) >>>>>> + =A0 =A0*sh_cmd++ =3D '\0'; >>>>>> + >>>>>> + =A0return sh_cmd; >>>>> >>>>> This butchers the string passed to execute_command. =A0Are you sure a= ll >>>>> the callers of execute_command can safely deal with that? =A0What if = the >>>>> string is a constant string, for example? >>>>> >>>> The new code path will be executed only when one will enter a command >>>> containing pipeline between gdb and shell. In that case the string >>>> passed to execute_command must not be a constant string (since it is >>>> user input from gdb prompt). Hence we are safe. >>>> >>> >> >