From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25274 invoked by alias); 18 Jul 2011 18:02:11 -0000 Received: (qmail 25265 invoked by uid 22791); 18 Jul 2011 18:02:10 -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; Mon, 18 Jul 2011 18:01:56 +0000 Received: by eyx24 with SMTP id 24so2269988eyx.5 for ; Mon, 18 Jul 2011 11:01:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.213.112.141 with SMTP id w13mr2336888ebp.131.1311012115017; Mon, 18 Jul 2011 11:01:55 -0700 (PDT) Received: by 10.213.22.195 with HTTP; Mon, 18 Jul 2011 11:01:54 -0700 (PDT) In-Reply-To: References: <834o2my2uj.fsf@gnu.org> Date: Mon, 18 Jul 2011 18:23: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/msg00428.txt.bz2 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_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). =A0Are 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 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, comments >>> 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 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 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. >> >