From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21122 invoked by alias); 20 Jul 2011 12:34:15 -0000 Received: (qmail 21034 invoked by uid 22791); 20 Jul 2011 12:34:13 -0000 X-SWARE-Spam-Status: No, hits=-2.3 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; Wed, 20 Jul 2011 12:33:59 +0000 Received: by eyx24 with SMTP id 24so768857eyx.5 for ; Wed, 20 Jul 2011 05:33:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.213.19.16 with SMTP id y16mr2798976eba.55.1311165237579; Wed, 20 Jul 2011 05:33:57 -0700 (PDT) Received: by 10.213.22.195 with HTTP; Wed, 20 Jul 2011 05:33:57 -0700 (PDT) In-Reply-To: References: <834o2my2uj.fsf@gnu.org> Date: Wed, 20 Jul 2011 13:17: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/msg00517.txt.bz2 Hi, I am pretty new in this community. Just curious to know whether I will get any notification if my patch get accepted or rejected. Thanks, Abhijit Halder > > On Tue, Jul 19, 2011 at 2:20 PM, Abhijit Halder wrote: >> >> I have made a correction to handle possibly all the cases. Hope this >> is my last correction. Please bear with me. >> >> I have changed the syntax of using shell command. Here it is: >> (gdb) gdb command | `{ shell command }` >> >> The shell command to be executed has to be encapsulated in `{}` and >> not only {} as gdb command itself can have braces, no spaces between >> backtick and braces are allowed. Hope this constraint will be >> acceptable from usability point of view. >> >> Regards, >> Abhijit Halder >> >> On Tue, Jul 19, 2011 at 11:03 AM, Abhijit Halder >> wrote: >> > Further concern. The last submitted patch does not work in following s= cenario: >> > (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 wrot= e: >> >>>>>>> Date: Sat, 16 Jul 2011 14:12:35 +0530 >> >>>>>>> From: Abhijit Halder >> >>>>>>> >> >>>>>>> I have implemented a feature which will allow one to pass the ou= tput >> >>>>>>> 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, '"', (s= h_cmd-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 = (spos, '|')) =3D=3D NULL) >> >>>>>>> + =A0 =A0 =A0 =A0break; >> >>>>>> >> >>>>>> I'm not sure I understand this (comments would be helpful). =A0Ar= e you >> >>>>>> assuming that quote characters `"' in shell commands cannot be >> >>>>>> escaped, e.g. with a backslash? =A0And what about quoting with a = single >> >>>>>> quote character ("'")? >> >>>>>> >> >>>>> Any pipe ('|' character), not within double quote will be consider= ed >> >>>>> 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 a= nd >> >>>>> 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, c= omments >> >>>>>> could help. >> >>>>>> >> >>>>> Here I am removing the braces from the shell command. An example w= ill >> >>>>> 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 i= t 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 su= re all >> >>>>>> 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 comm= and >> >>>>> 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. >> >>>>> >> >>>> >> >>> >> >> >> > >