From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4284 invoked by alias); 6 Aug 2004 06:26:41 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 4275 invoked from network); 6 Aug 2004 06:26:39 -0000 Received: from unknown (HELO smtp10.atl.mindspring.net) (207.69.200.246) by sourceware.org with SMTP; 6 Aug 2004 06:26:39 -0000 Received: from user-119a90a.biz.mindspring.com ([66.149.36.10] helo=berman.michael-chastain.com) by smtp10.atl.mindspring.net with esmtp (Exim 3.33 #1) id 1BsyBX-0003MH-00; Fri, 06 Aug 2004 02:26:35 -0400 Received: from mindspring.com (localhost [127.0.0.1]) by berman.michael-chastain.com (Postfix) with SMTP id 426FC4B102; Fri, 6 Aug 2004 02:27:03 -0400 (EDT) Date: Fri, 06 Aug 2004 06:26:00 -0000 From: Michael Chastain To: drow@false.org Subject: Re: gdb.mi/*.exp and absolute line numbers Cc: gdb@sources.redhat.com Message-ID: <411324B4.nail8NE41VN2U@mindspring.com> References: <4111FC04.nailD7G1U3QKS@mindspring.com> <20040805132205.GA10757@nevyn.them.org> In-Reply-To: <20040805132205.GA10757@nevyn.them.org> User-Agent: nail 10.8 6/28/04 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2004-08/txt/msg00094.txt.bz2 Daniel Jacobowitz wrote: > Please do! If you need help with the TCL, I can help also. The result > will probably be faster, and definitely clutter the logs less. Here's some work in progress. Can you eyeball it for me? It works on a few different configurations in my test bed. The old code had side effects on gdb, like setting gdb's idea of the current file and line number. Fortunately none of the 94 callers takes advantage of these side effects. I'm interested in: . source code format -- i'm making it up as i go along. if it looks weird, grab a chunk of code and reformat it with your favorite style. . i wrapped all the filesystem calls with "catch { ... } message". did i do this right? . defaults for the file name and file directories -- i had to be compatible with the old code, but it is baroque. any ideas? Michael C # gdb_get_line_number TEXT [FILE] # # Search the source file FILE, and return the line number of the # first line containing TEXT. If no match is found, return -1. # # TEXT is a string literal, not a regular expression. # # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is # specified, and does not start with "/", then it is assumed to be in # "$srcdir/$subdir". This is awkward, and can be fixed in the future, # by changing the callers and the interface at the same time. # In particular: gdb.base/break.exp, gdb.base/condbreak.exp, # gdb.base/ena-dis-br.exp. # # Use this function to keep your test scripts independent of the # exact line numbering of the source file. Don't write: # # send_gdb "break 20" # # This means that if anyone ever edits your test's source file, # your test could break. Instead, put a comment like this on the # source file line you want to break at: # # /* breakpoint spot: frotz.exp: test name */ # # and then write, in your test script (which we assume is named # frotz.exp): # # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n" # # (Yes, Tcl knows how to handle the nested quotes and brackets. # Try this: # $ tclsh # % puts "foo [lindex "bar baz" 1]" # foo baz # % # Tcl is quite clever, for a little stringy language.) # # === # # The previous implementation of this procedure used the gdb search command. # This version is different: # # . It works with MI, and it also works when gdb is not running. # # . It operates on the build machine, not the host machine. # # . For now, this implementation fakes a current directory of # $srcdir/$subdir to be compatible with the old implementation. # This will go away eventually and some callers will need to # be changed. # # . The TEXT argument is literal text and matches literally, # not a regular expression as it was before. # # . State changes in gdb, such as changing the current file # and setting $_, no longer happen. # # After a bit of time we can forget about the differences from the # old implementation. # # --chastain 2004-08-05 proc gdb_get_line_number { text { file "" } } { global srcdir global subdir global srcfile if { "$file" == "" } then { set file "$srcfile" } if { ! [regexp "^/" "$file"] } then { set file "$srcdir/$subdir/$file" } if { [ catch { set fd [open "$file"] } message ] } then { perror "$message" return -1 } set found -1 for { set line 1 } { 1 } { incr line } { if { [ catch { set nchar [gets "$fd" body] } message ] } then { perror "$message" return -1 } if { $nchar < 0 } then { break } if { [string first "$text" "$body"] >= 0 } then { set found $line break } } if { [ catch { close "$fd" } message ] } then { perror "$message" return -1 } return $found }