Skip to content

Instantly share code, notes, and snippets.

@kastiglione
Last active June 6, 2018 19:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kastiglione/4a0648392e72e48354c289eaee833915 to your computer and use it in GitHub Desktop.
Save kastiglione/4a0648392e72e48354c289eaee833915 to your computer and use it in GitHub Desktop.
import re
import __builtin__
from itertools import islice
# See https://sourceware.org/gdb/current/onlinedocs/gdb/Convenience-Funs.html
# breakpoint command add -F '_caller_is("theCaller")'
# breakpoint command add -F 'not _caller_is("theCaller")'
def _caller_is(name):
def check(frame, loc, _):
return frame.parent.name == name
return check
__builtin__._caller_is = _caller_is
# breakpoint command add -F '_any_caller_is("someCaller")'
# breakpoint command add -F 'not _any_caller_is("someCaller")'
def _any_caller_is(name):
def check(frame, loc, _):
callers = islice(frame.thread, 1, None)
return any(f.name == name for f in callers)
return check
__builtin__._any_caller_is = _any_caller_is
# breakpoint command add -F '_caller_matches("theCaller")'
# breakpoint command add -F 'not _caller_matches("theCaller")'
def _caller_matches(pattern):
regex = re.compile(pattern, re.I)
def check(frame, loc, _):
return regex.search(frame.parent.name) != None
return check
__builtin__._caller_matches = _caller_matches
# breakpoint command add -F '_any_caller_matches("someCaller")'
# breakpoint command add -F 'not _any_caller_matches("someCaller")'
def _any_caller_matches(pattern):
regex = re.compile(pattern, re.I)
def check(frame, loc, _):
callers = islice(frame.thread, 1, None)
return any(regex.search(f.name) for f in callers)
return check
__builtin__._any_caller_matches = _any_caller_matches
# breakpoint command add -F '_caller_from("thatModule")'
# breakpoint command add -F 'not _caller_from("thatModule")'
def _caller_from(name):
def check(frame, loc, _):
return frame.parent.module.file.basename == name
return check
__builtin__._caller_from = _caller_from
# breakpoint command add -F '_any_caller_from("thatModule")'
# breakpoint command add -F 'not _any_caller_from("thatModule")'
def _any_caller_from(name):
def check(frame, loc, _):
callers = islice(frame.thread, 1, None)
return any(f.module.file.basename == name for f in callers)
return check
__builtin__._any_caller_from = _any_caller_from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment