diff options
author | Doug Evans <xdje42@gmail.com> | 2014-09-06 09:15:44 -0700 |
---|---|---|
committer | Doug Evans <xdje42@gmail.com> | 2014-09-06 09:15:44 -0700 |
commit | faa42425cb1f5cd279fc8c91d0b75d37853a128a (patch) | |
tree | 239606104986f50fe38a824610ed3fa46b7cdd7f /gdb/python/lib | |
parent | 0d41ba00c60b5e0b66895cfa56c1db137a9345d8 (diff) | |
download | gdb-faa42425cb1f5cd279fc8c91d0b75d37853a128a.zip gdb-faa42425cb1f5cd279fc8c91d0b75d37853a128a.tar.gz gdb-faa42425cb1f5cd279fc8c91d0b75d37853a128a.tar.bz2 |
PR 15276: Add $_caller_is, $_caller_matches, $_any_caller_is, $_any_caller_matches
gdb/ChangeLog:
PR 15276
* NEWS: Mention $_caller_is, $_caller_matches, $_any_caller_is,
$_any_caller_matches.
* data-directory/Makefile.in (PYTHON_FILE_LIST): Add caller_is.py.
* python/lib/gdb/function/caller_is.py: New file.
gdb/testsuite/ChangeLog:
PR 15276
* gdb.python/py-caller-is.c: New file.
* gdb.python/py-caller-is.exp: New file.
gdb/doc/ChangeLog:
PR 15276
* gdb.texinfo (Convenience Funs): Document $_caller_is,
$_caller_matches, $_any_caller_is, $_any_caller_matches.
Diffstat (limited to 'gdb/python/lib')
-rw-r--r-- | gdb/python/lib/gdb/function/caller_is.py | 160 |
1 files changed, 160 insertions, 0 deletions
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..f5b0a58 --- /dev/null +++ b/gdb/python/lib/gdb/function/caller_is.py @@ -0,0 +1,160 @@ +# Caller-is functions. +# Copyright (C) 2008, 2014 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 <http://www.gnu.org/licenses/>. + +import gdb +import re + +class CallerIs(gdb.Function): + """Check the calling function's name. + +Usage: + $_caller_is(name [, number_of_frames]) + +Arguments: + + name: The name of the function to search for. + + number_of_frames: How many stack frames to traverse back from the currently + selected frame to compare with. If the value is greater than the depth of + the stack from that point then the result is False. + The default is 1. + +Returns: + True if the function's name at the specified frame is equal to name. +""" + + def __init__(self): + super(CallerIs, self).__init__("_caller_is") + + def invoke(self, name, nframes = 1): + if nframes < 0: + raise ValueError("nframes must be >= 0") + frame = gdb.selected_frame() + while nframes > 0: + frame = frame.older() + if frame is None: + return False + nframes = nframes - 1 + return frame.name() == name.string() + +class CallerMatches(gdb.Function): + """Compare the calling function's name with a regexp. + +Usage: + $_caller_matches(regex [, number_of_frames]) + +Arguments: + + regex: The regular expression to compare the function's name with. + + number_of_frames: How many stack frames to traverse back from the currently + selected frame to compare with. If the value is greater than the depth of + the stack from that point then the result is False. + The default is 1. + +Returns: + True if the function's name at the specified frame matches regex. +""" + + def __init__(self): + super(CallerMatches, self).__init__("_caller_matches") + + def invoke(self, name, nframes = 1): + if nframes < 0: + raise ValueError("nframes must be >= 0") + frame = gdb.selected_frame() + while nframes > 0: + frame = frame.older() + if frame is None: + return False + nframes = nframes - 1 + return re.match(name.string(), frame.name()) is not None + +class AnyCallerIs(gdb.Function): + """Check all calling function's names. + +Usage: + $_any_caller_is(name [, number_of_frames]) + +Arguments: + + name: The name of the function to search for. + + number_of_frames: How many stack frames to traverse back from the currently + selected frame to compare with. If the value is greater than the depth of + the stack from that point then the result is False. + The default is 1. + +Returns: + True if any function's name is equal to name. +""" + + def __init__(self): + super(AnyCallerIs, self).__init__("_any_caller_is") + + def invoke(self, name, nframes = 1): + if nframes < 0: + raise ValueError("nframes must be >= 0") + frame = gdb.selected_frame() + while nframes >= 0: + if frame.name() == name.string(): + return True + frame = frame.older() + if frame is None: + return False + nframes = nframes - 1 + return False + +class AnyCallerMatches(gdb.Function): + """Compare all calling function's names with a regexp. + +Usage: + $_any_caller_matches(regex [, number_of_frames]) + +Arguments: + + regex: The regular expression to compare the function's name with. + + number_of_frames: How many stack frames to traverse back from the currently + selected frame to compare with. If the value is greater than the depth of + the stack from that point then the result is False. + The default is 1. + +Returns: + True if any function's name matches regex. +""" + + def __init__(self): + super(AnyCallerMatches, self).__init__("_any_caller_matches") + + def invoke(self, name, nframes = 1): + if nframes < 0: + raise ValueError("nframes must be >= 0") + frame = gdb.selected_frame() + name_re = re.compile(name.string()) + while nframes >= 0: + if name_re.match(frame.name()) is not None: + return True + frame = frame.older() + if frame is None: + return False + nframes = nframes - 1 + return False + +CallerIs() +CallerMatches() +AnyCallerIs() +AnyCallerMatches() |