From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5103 invoked by alias); 23 Nov 2008 21:38:20 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 4929 invoked by uid 306); 23 Nov 2008 21:38:19 -0000 Date: Sun, 23 Nov 2008 21:38:00 -0000 Message-ID: <20081123213818.4906.qmail@sourceware.org> From: tromey@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-tromey-python: * Makefile.in (PY_FILES): Add caller_is.py. X-Git-Refname: refs/heads/archer-tromey-python X-Git-Reftype: branch X-Git-Oldrev: 6252b3bc528df3b39ebcb186b51f298e860d78c1 X-Git-Newrev: 5bbc9e9236e752b546f99749a2ebc758c5fb7fcf X-SW-Source: 2008-q4/txt/msg00154.txt.bz2 List-Id: The branch, archer-tromey-python has been updated via 5bbc9e9236e752b546f99749a2ebc758c5fb7fcf (commit) from 6252b3bc528df3b39ebcb186b51f298e860d78c1 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 5bbc9e9236e752b546f99749a2ebc758c5fb7fcf Author: Tom Tromey Date: Sun Nov 23 14:38:00 2008 -0700 * Makefile.in (PY_FILES): Add caller_is.py. * python/lib/gdb/function/caller_is.py: New file. * python/lib/gdb/command/require.py: Add "require function". ----------------------------------------------------------------------- Summary of changes: gdb/ChangeLog | 6 +++ gdb/Makefile.in | 5 ++- gdb/python/lib/gdb/command/require.py | 2 +- gdb/python/lib/gdb/function/caller_is.py | 58 ++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 gdb/python/lib/gdb/function/caller_is.py First 500 lines of diff: diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 47e01b5..2bab40d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2008-11-23 Tom Tromey + * Makefile.in (PY_FILES): Add caller_is.py. + * python/lib/gdb/function/caller_is.py: New file. + * python/lib/gdb/command/require.py: Add "require function". + +2008-11-23 Tom Tromey + * Makefile.in (PY_DIRS): Update. (PY_FILES): List new files. * python/lib/gdb/FrameIterator.py: New file. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 26e4aaf..6ef02bf 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1917,12 +1917,13 @@ python-value.o: $(srcdir)/python/python-value.c # first. These are maintained by hand because that is simpler than # writing portable sh to make the __init__.py files, and the result is # faster. -PY_DIRS = gdb gdb/command gdb/libstdcxx gdb/libstdcxx/v6 +PY_DIRS = gdb gdb/command gdb/function gdb/libstdcxx gdb/libstdcxx/v6 # All python library files, with the "python/lib" stripped off. # Note that we should only install files in the "gdb" module. PY_FILES = gdb/backtrace.py gdb/command/alias.py \ - gdb/command/backtrace.py gdb/command/require.py gdb/FrameIterator.py \ + gdb/command/backtrace.py gdb/command/require.py \ + gdb/function/caller_is.py gdb/FrameIterator.py \ gdb/__init__.py gdb/libstdcxx/v6/printers.py # Install the Python library. Python library files go under diff --git a/gdb/python/lib/gdb/command/require.py b/gdb/python/lib/gdb/command/require.py index 2112b9a..36b63e5 100644 --- a/gdb/python/lib/gdb/command/require.py +++ b/gdb/python/lib/gdb/command/require.py @@ -54,4 +54,4 @@ class RequireSubcommand (gdb.Command): RequireCommand() RequireSubcommand("command") -# Don't install a "require function" command until we have one. +RequireSubcommand("function") diff --git a/gdb/python/lib/gdb/function/caller_is.py b/gdb/python/lib/gdb/function/caller_is.py new file mode 100644 index 0000000..8afa721 --- /dev/null +++ b/gdb/python/lib/gdb/function/caller_is.py @@ -0,0 +1,58 @@ +# Caller-is functions. + +# Copyright (C) 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import gdb +import re + +class CallerIs (gdb.Function): + """Return True if the calling function's name is equal to a string. +This function takes one or two arguments. +The first argument is the name of a function; if the calling function's +name is equal to this argument, this function returns True. +The optional second argument tells this function how many stack frames +to traverse to find the calling function. The default is 1.""" + + def __init__ (self): + super (CallerIs, self).__init__ ("caller_is") + + def invoke (self, name, nframes = 1): + frame = gdb.get_current_frame () + while nframes > 0: + frame = frame.get_prev () + nframes = nframes - 1 + return frame.get_name () == name.string () + +class CallerMatches (gdb.Function): + """Return True if the calling function's name matches a string. +This function takes one or two arguments. +The first argument is a regular expression; if the calling function's +name is matched by this argument, this function returns True. +The optional second argument tells this function how many stack frames +to traverse to find the calling function. The default is 1.""" + + def __init__ (self): + super (CallerMatches, self).__init__ ("caller_matches") + + def invoke (self, name, nframes = 1): + frame = gdb.get_current_frame () + while nframes > 0: + frame = frame.get_prev () + nframes = nframes - 1 + return re.match (name.string (), frame.get_name ()) is not None + +CallerIs() +CallerMatches() hooks/post-receive -- Repository for Project Archer.