From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12363 invoked by alias); 16 Jul 2011 10:09:19 -0000 Received: (qmail 12352 invoked by uid 22791); 16 Jul 2011 10:09:18 -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 X-Spam-Check-By: sourceware.org Received: from mail-ew0-f41.google.com (HELO mail-ew0-f41.google.com) (209.85.215.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 16 Jul 2011 10:08:59 +0000 Received: by ewy9 with SMTP id 9so1120110ewy.0 for ; Sat, 16 Jul 2011 03:08:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.213.112.141 with SMTP id w13mr1539593ebp.131.1310810937856; Sat, 16 Jul 2011 03:08:57 -0700 (PDT) Received: by 10.213.22.195 with HTTP; Sat, 16 Jul 2011 03:08:57 -0700 (PDT) In-Reply-To: <834o2my2uj.fsf@gnu.org> References: <834o2my2uj.fsf@gnu.org> Date: Sat, 16 Jul 2011 18:06:00 -0000 Message-ID: Subject: Re: [PATCH] gdb output pipelining to shell From: Abhijit Halder To: Eli Zaretskii Cc: 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/msg00413.txt.bz2 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-cp= os))) !=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.