From patchwork Wed Apr 16 18:51:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 578 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (peon2454.g.dreamhost.com [208.113.200.127]) by wilcox.dreamhost.com (Postfix) with ESMTP id 25AD336007A for ; Wed, 16 Apr 2014 11:51:34 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id DC25B12C3201; Wed, 16 Apr 2014 11:51:33 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id AB80612BA708 for ; Wed, 16 Apr 2014 11:51:33 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :content-type; q=dns; s=default; b=rqJeAZRfUoYn5mGizJ06BEfrBUG/U E+AglUB6JnIGx7QrsuD6bc8dB0d1NFZ1QFRsyu1ua0rtzYvYNpulvQK0W90C8d8V ioEv3PrOlOvpLTjjbgfQjqkvNHQLYmh95VoLhfDMtJnr6zqjBbYjjlK3gX/LLx3t qdAgkJdWK/Fff0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :content-type; s=default; bh=8LKJYphMgwfj9F/s9qvY6wSGhOM=; b=Jsg Cbyk+n7diYS02sLYIoZvZfy+mbECL8AG3mE8r++3HTfaCwRRCpBYT9jq3IZr2R52 tBtTmVjNHuZlY8mIcgR+odWIMBAn1QMcC7eUb/SzYMD9n/W979W/FP3gY04SakB7 nfXygBkPth1vgpHHfpTDXydhXcp7ZvGiLxWDxC3M= Received: (qmail 31426 invoked by alias); 16 Apr 2014 18:51:32 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 31415 invoked by uid 89); 16 Apr 2014 18:51:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Apr 2014 18:51:30 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3GIpT4Q030156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Apr 2014 14:51:29 -0400 Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s3GIpSi6001982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Wed, 16 Apr 2014 14:51:29 -0400 Message-ID: <534ED130.8020508@redhat.com> Date: Wed, 16 Apr 2014 11:51:28 -0700 From: Keith Seitz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: "gdb-patches@sourceware.org ml" Subject: [RFA testsuite 1/5] Introduce parse_args X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in Hi, The first of these new functions is called parse_args. It was written a loooooooooong time ago by Ian Taylor (then at Cygnus). A part of libugi (used by Insight and Source Navigator(?)), I have been given permission to donate this upstream. It is a very useful utility function which allows you to do getopt-y kinds of things in Tcl. From the documentation: proc myproc {foo args} { parse_args {{bar} {baz "abc"} {qux}} # ... } myproc ABC -bar -baz DEF peanut butter will define the following variables in myproc: foo (=ABC), bar (=1), baz (=DEF), and qux (=0) args will be the list {peanut butter} This will be used by subsequent patches in this series to cleanup mi_create_breakpoint. Keith testsuite/ChangeLog 2014-04-15 Keith Seitz From Ian Lance Taylor : * lib/gdb.exp (parse_args): New procedure. diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 73e935a..7a25edb 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4660,5 +4660,68 @@ proc using_fission { } { return [regexp -- "-gsplit-dwarf" $debug_flags] } +# Search the caller's ARGS list and set variables according to the list of +# valid options described by ARGSET. +# +# The first member of each one- or two-element list in ARGSET defines the +# name of a variable that will be added to the caller's scope. +# +# If only one element is given to describe an option, it the value is +# 0 if the option is not present in (the caller's) ARGS or 1 if +# it is. +# +# If two elements are given, the second element is the default value of +# the variable. This is then overwritten if the option exists in ARGS. +# +# Any parse_args elements in (the caller's) ARGS will be removed, leaving +# any optional components. + +# Example: +# proc myproc {foo args} { +# parse_args {{bar} {baz "abc"} {qux}} +# # ... +# } +# myproc ABC -bar -baz DEF peanut butter +# will define the following variables in myproc: +# foo (=ABC), bar (=1), baz (=DEF), and qux (=0) +# args will be the list {peanut butter} + +proc parse_args { argset } { + upvar args args + + foreach argument $argset { + if {[llength $argument] == 1} { + # No default specified, so we assume that we should set + # the value to 1 if the arg is present and 0 if it's not. + # It is assumed that no value is given with the argument. + set result [lsearch -exact $args "-$argument"] + if {$result != -1} then { + uplevel 1 [list set $argument 1] + set args [lreplace $args $result $result] + } else { + uplevel 1 [list set $argument 0] + } + } elseif {[llength $argument] == 2} { + # There are two items in the argument. The second is a + # default value to use if the item is not present. + # Otherwise, the variable is set to whatever is provided + # after the item in the args. + set arg [lindex $argument 0] + set result [lsearch -exact $args "-[lindex $arg 0]"] + if {$result != -1} then { + uplevel 1 [list set $arg [lindex $args [expr $result+1]]] + set args [lreplace $args $result [expr $result+1]] + } else { + uplevel 1 [list set $arg [lindex $argument 1]] + } + } else { + error "Badly formatted argument \"$argument\" in argument set" + } + } + + # The remaining args should be checked to see that they match the + # number of items expected to be passed into the procedure... +} + # Always load compatibility stuff. load_lib future.exp