public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Michael Chastain <mec.gnu@mindspring.com>
To: drow@false.org
Cc: gdb@sources.redhat.com
Subject: Re: gdb.mi/*.exp and absolute line numbers
Date: Fri, 06 Aug 2004 06:26:00 -0000	[thread overview]
Message-ID: <411324B4.nail8NE41VN2U@mindspring.com> (raw)
In-Reply-To: <20040805132205.GA10757@nevyn.them.org>

Daniel Jacobowitz <drow@false.org> 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
}

  reply	other threads:[~2004-08-06  6:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-05  9:20 Michael Chastain
2004-08-05 13:23 ` Daniel Jacobowitz
2004-08-06  6:26   ` Michael Chastain [this message]
2004-08-05 14:34 ` Jim Blandy
2004-08-05 16:02   ` Michael Chastain
2004-08-06  8:24 ` Eli Zaretskii
2004-08-06  9:41   ` Michael Chastain
2004-08-06 14:46 ` Andrew Cagney
2004-08-06 16:06   ` Michael Chastain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=411324B4.nail8NE41VN2U@mindspring.com \
    --to=mec.gnu@mindspring.com \
    --cc=drow@false.org \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).