From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4635 invoked by alias); 19 Jul 2011 08:50:56 -0000 Received: (qmail 4617 invoked by uid 22791); 19 Jul 2011 08:50:53 -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-ew0-f41.google.com (HELO mail-ew0-f41.google.com) (209.85.215.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Jul 2011 08:50:38 +0000 Received: by ewy9 with SMTP id 9so2137496ewy.0 for ; Tue, 19 Jul 2011 01:50:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.213.19.16 with SMTP id y16mr2184874eba.55.1311065436787; Tue, 19 Jul 2011 01:50:36 -0700 (PDT) Received: by 10.213.22.195 with HTTP; Tue, 19 Jul 2011 01:50:36 -0700 (PDT) In-Reply-To: References: <834o2my2uj.fsf@gnu.org> Date: Tue, 19 Jul 2011 10:31:00 -0000 Message-ID: Subject: Re: [PATCH] gdb output pipelining to shell From: Abhijit Halder To: gdb-patches@sourceware.org Content-Type: multipart/mixed; boundary=0015174be08ca3127704a86835db 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/msg00452.txt.bz2 --0015174be08ca3127704a86835db Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-length: 5276 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 scen= ario: > (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_c= md-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 (sp= os, '|')) =3D=3D NULL) >>>>>>> + =A0 =A0 =A0 =A0break; >>>>>> >>>>>> I'm not sure I understand this (comments would be helpful). =A0Are y= ou >>>>>> assuming that quote characters `"' in shell commands cannot be >>>>>> escaped, e.g. with a backslash? =A0And what about quoting with a sin= gle >>>>>> 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, comm= ents >>>>>> 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. >>>>> >>>> >>> >> > --0015174be08ca3127704a86835db Content-Type: text/x-patch; charset=US-ASCII; name="gdb-shell-integration-correction.patch" Content-Disposition: attachment; filename="gdb-shell-integration-correction.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_gqam74fy0 Content-length: 4893 ZGlmZiAtcnVwIHNyYy8vZ2RiL3RvcC5jIGRzdC8vZ2RiL3RvcC5jCi0tLSBz cmMvL2dkYi90b3AuYwkyMDExLTA2LTI4IDAwOjUxOjUwLjAwMDAwMDAwMCAr MDUzMAorKysgZHN0Ly9nZGIvdG9wLmMJMjAxMS0wNy0xOSAxMToxNTozOC45 ODQzODExNjMgKzA1MzAKQEAgLTQ4LDYgKzQ4LDcgQEAKICNpbmNsdWRlICJl dmVudC1sb29wLmgiCiAjaW5jbHVkZSAiZ2RidGhyZWFkLmgiCiAjaW5jbHVk ZSAicHl0aG9uL3B5dGhvbi5oIgorI2luY2x1ZGUgInVpLWZpbGUuaCIKIAog LyogcmVhZGxpbmUgaW5jbHVkZSBmaWxlcy4gICovCiAjaW5jbHVkZSAicmVh ZGxpbmUvcmVhZGxpbmUuaCIKQEAgLTM1OCw2ICszNTksNzEgQEAgcHJlcGFy ZV9leGVjdXRlX2NvbW1hbmQgKHZvaWQpCiAgIHJldHVybiBjbGVhbnVwOwog fQogCitjaGFyICoKK3BhcnNlX2Zvcl9zaGVsbF9jb21tYW5kIChjaGFyICpw KQoreworICBjaGFyICpzaF9jbWQsICpjcG9zLCAqc3BvcywgKmVwb3M7Cisg IGludCBxdW90ZV9jbnQgPSAwOworCisgIGlmICgoc2hfY21kID0gc3RyY2hy IChwLCAnfCcpKSAhPSBOVUxMKQorICAgIHsKKyAgICAgIHNwb3MgPSBwOwor ICAgICAgZXBvcyA9IHAgKyBzdHJsZW4gKHApIC0gMTsKKworICAgICAgZm9y ICg7OykKKyAgICB7CisgICAgICBmb3IgKGNwb3MgPSBzcG9zOyAoY3BvcyA9 IG1lbWNociAoY3BvcywgJyInLCAoc2hfY21kLWNwb3MpKSkgIT0gTlVMTDsg Y3BvcysrKQorICAgICAgICBxdW90ZV9jbnQrKzsKKyAgICAgIHNwb3MgPSAo c2hfY21kICsgMSk7CisgICAgICBpZiAoKHF1b3RlX2NudCAlIDIpID09IDAg fHwgKHNoX2NtZCA9IHN0cmNociAoc3BvcywgJ3wnKSkgPT0gTlVMTCkKKyAg ICAgICAgYnJlYWs7CisgICAgfQorCisgICAgaWYgKHNoX2NtZCA9PSBOVUxM KQorICAgICAgcmV0dXJuIE5VTEw7CisKKyAgICBjcG9zID0gc3BvczsKKyAg ICB3aGlsZSAoaXNzcGFjZSgqY3BvcykpCisgICAgICBjcG9zKys7CisKKyAg ICBpZiAoKmNwb3MgIT0gJ2AnIHx8ICooY3BvcysxKSAhPSAneycpCisgICAg ICByZXR1cm4gcGFyc2VfZm9yX3NoZWxsX2NvbW1hbmQgKGNwb3MpOworCisg ICAgc3BvcyA9IGNwb3M7CisKKyAgICBjcG9zID0gZXBvczsKKyAgICB3aGls ZSAoaXNzcGFjZSgqY3BvcykpCisgICAgICBjcG9zLS07CisKKyAgICBpZiAo KmNwb3MgIT0gJ2AnIHx8ICooY3Bvcy0xKSAhPSAnfScpCisgICAgICByZXR1 cm4gcGFyc2VfZm9yX3NoZWxsX2NvbW1hbmQgKGNwb3MpOworCisgICAgZXBv cyA9IGNwb3M7CisgICAgfQorCisgIGlmIChzaF9jbWQpCisgICAgeworICAg ICAgKnNwb3MgPSAqKHNwb3MrMSkgPSAqZXBvcyA9ICooZXBvcy0xKSA9ICcg JzsKKyAgICAgICpzaF9jbWQrKyA9ICdcMCc7CisgICAgfQorCisgIHJldHVy biBzaF9jbWQ7Cit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