From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4279 invoked by alias); 24 Jan 2016 22:23:06 -0000 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 Received: (qmail 4268 invoked by uid 89); 24 Jan 2016 22:23:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.2 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 spammy=H*MI:sk:1453499, H*f:sk:CADPb22, H*MI:sk:Ww@mail, H*i:sk:CADPb22 X-HELO: mailsec110.isp.belgacom.be Received: from mailsec110.isp.belgacom.be (HELO mailsec110.isp.belgacom.be) (195.238.20.106) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 24 Jan 2016 22:23:03 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CIAgDKTaVW/5dbgG1egzqBP4hXsgcBDYFihg8CgR05FAEBAQEBAQGBCoRCAQEEIzMjEAgDDgoCAiYCAjkeBhMUiAuuCI5NAQEBBwIeGGOFN4RthCWDJ4E6BYdWjyCIN4UfgV6Ha4UwimyDUx4BAUKDajsuhgOBOQEBAQ Received: from 151.91-128-109.adsl-dyn.isp.belgacom.be (HELO soleil) ([109.128.91.151]) by relay.skynet.be with ESMTP/TLS/AES128-GCM-SHA256; 24 Jan 2016 23:23:00 +0100 Message-ID: <1453674323.2097.91.camel@skynet.be> Subject: Re: RFC: block of commands From: Philippe Waroquiers To: Doug Evans Cc: gdb-patches Date: Sun, 24 Jan 2016 22:23:00 -0000 In-Reply-To: References: <001a1143804e6a9e8f0529ce089a@google.com> <1453499357.2097.18.camel@skynet.be> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg00610.txt.bz2 On Sun, 2016-01-24 at 12:03 -0800, Doug Evans wrote: > On Fri, Jan 22, 2016 at 1:49 PM, Philippe Waroquiers > wrote: > > > > > > I think that effectively, the principles you suggest below > > should allow to make a reasonable syntax, and no backward > > incompatibility. > > So basically: > > * trailing } is mandatory > > * inside a block of commands, { } and ; must be escaped > > * a command block is limited to be on a single line > > I guess multiple lines will be ok if each line is terminated > > by a \. > > > > The above principles should also allow to extend if/while/... > > to have 'one line' if/while/... > > > > I also think that 'one line if' will allow to do things such as: > > > > thread apply all if $ebp -$esp > 1000000 { echo big frame in this thread } > > > > (today, trying to use an 'if' in thread apply gives a quite strange > > behaviour : the rest of the 'if' command is read during each execution > > for each thread, which is not very user friendly :). > > > > I will work based on the above idea, and resubmit a draft patch > > but that will for sure have to wait after FOSDEM, which > > will already consume the night and week-end free time :). > > > > Thanks for the comments/help/nice suggestions > > > > > Hi. > Sounds like a plan, but in an effort to make your time > as productive as I can I would suggest first trying to come > up with syntax that the community can accept. Good idea, the plan is easier to write than the code. > > Among the questions we need to answer: > - when/how to escape { } ; > (what I gave was a strawman, I didn't dig deep > into whether there are any gotchas) > - what to do with { } in expressions, > e.g., "if ({1,2,3})[2] == 3 { echo foo }" > - ??? Here are some more details/answers: Basic syntax ------------ Block of commands are single line, trailing } are mandatory. These conditions are needed to allow to extend existing commands (thread apply, if, while) in a (reasonably) backward compatible way. The parsing of command blocks will be deferred to the commands that accepts block of commands (or commands) as parameters. Commands in a block are separated by ;. ; is optional in front of a { or a }, e.g. { echo 1\n { echo 2\n; echo 3\n ; } echo 4\n } Escaping: --------- { } ; must be escaped inside a block of commands in order to lose their 'block of command special character semantic'. A single \ is good enough to escape, no need to have a \ for each nesting level, e.g. thread apply all { echo \{ at nesting 1 { echo \; at nesting 2 } } No need to escape in expressions which are 'at nesting 0', e.g. if ({1,2,3})[2] == 3 { echo foo } The 'if' command parser will search for a trailing } and will parse backward to search the matching opening {, counting nesting levels. So, thanks to backward parsing, {}; do not need to be escaped in expressions. Only problem I see with this are expressions that are terminated with a }. Then the parser might confuse such an expression in an 'end terminated if' with a block of command of a 'single line' if. So, probably we will have to handle escaping the final } of such an expression. However, that will be a backward incompatibility. I guess this incompatibility is unlikely, unless there is a language where } are often terminating an expression ? I do not see how to avoid this (unlikely?) backward incompatibility. When 'if' is used inside a command block, then special characters in the expression must be escaped e.g. thread apply all { if (\{1,2,3\})[2] == 3 { echo three } } Error handling -------------- {/s ... } means to continue executing the block if a command fails; all the output of failing commands are silently ignored. {/c .... } also means to continue executing the block if a command fails, but the error is reported. Extension of existing commands ------------------------------ Commands that have a command as parameter or read other commands will be extended to accept a block of commands (which must be at the end of the line). So: thread apply all { .... } if expression { ... } [else { ... } } while expression { ... } Is there something else to extend ? Maybe single line define such as define helloworld { echo hello; echo world\n } ? Have a way to silence some commands using optional /s marker ------------------------------------------------------------ E.g. thread apply all /s command means that a thread is shown only if command has produced some output Some new commands ----------------- As discussed, new command frame apply all accepting also an optional /s For completeness, I guess we better have: inferior apply all .... (and optional /s marker) The idea is that all the above can be combined e.g. inferior apply all /s { thread apply all /s { frame apply all /s if condition { echo look at this inferior/thread/frame }}} (long single lines like that can be broken in separate lines using \ at the end of the line). Note: I guess that the parser of inferior/thread/frame apply all can be a 'forward parser', and so the first two { will be optional for the above. Otherwise, inferior/thread/frame will also look for a terminating } and do a backward parsing, then in the above example, all { } are needed to allow backward parsing. I would have preferred to avoid the (unlikely I hope) incompatibility of } terminated expressions, but I do not see a reasonable way to do that. Comments/remarks/plan-killer-bugs/... welcome. Philippe