From 3062ac65cb403a1cbce0d2b5bae5fdaa052dd1b9 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 25 Oct 2016 12:32:36 -0500 Subject: [PATCH] Handle multiple python probes at the same location. * python/HelperSDT/__init__.py (Dispatcher.pytrace_dispatch): Handle multiple breakpoints at the same breakpoint location. (Dispatcher.do_b): Make sure the line number field is numeric. Clear the line number field if we've got a return break. * tapset-python.cxx (python_builder::build): Add newlines to debug prints. --- python/HelperSDT/__init__.py | 50 ++++++++++++++++++++++++------------ tapset-python.cxx | 6 ++--- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/python/HelperSDT/__init__.py b/python/HelperSDT/__init__.py index 93b7559a5..8e4c7b562 100644 --- a/python/HelperSDT/__init__.py +++ b/python/HelperSDT/__init__.py @@ -25,7 +25,7 @@ import _HelperSDT class _Breakpoint: def __init__(self, index, filename, funcname, lineno=None, - returnp=None): + returnp=False): # We've got to have a filename and funcname with an optional # lineno or returnp. if not filename: @@ -150,25 +150,31 @@ class Dispatcher(cmd.Cmd): def pytrace_dispatch(self, frame, event, arg): if event == 'call': - if self._bplist.break_here(frame, event): - sys.stdout.write("CALL: %s %s\n" - % (frame.f_code.co_filename, - frame.f_code.co_name)) - _HelperSDT.trace_callback(0, frame, arg) + bplist = self._bplist.break_here(frame, event) + if bplist: + for bp in bplist: + sys.stdout.write("CALL: %s %s\n" + % (frame.f_code.co_filename, + frame.f_code.co_name)) + _HelperSDT.trace_callback(0, frame, arg) return self.pytrace_dispatch elif event == 'line': - if self._bplist.break_here(frame, event): - sys.stdout.write("LINE: %s %s %d\n" - % (frame.f_code.co_filename, - frame.f_code.co_name, frame.f_lineno)) - _HelperSDT.trace_callback(0, frame, arg) + bplist = self._bplist.break_here(frame, event) + if bplist: + for bp in bplist: + sys.stdout.write("LINE: %s %s %d\n" + % (frame.f_code.co_filename, + frame.f_code.co_name, frame.f_lineno)) + _HelperSDT.trace_callback(2, frame, arg) return self.pytrace_dispatch elif event == 'return': - if self._bplist.break_here(frame, event): - sys.stdout.write("RETURN: %s %s %d" - % (frame.f_code.co_filename, - frame.f_code.co_name, frame.f_lineno)) - _HelperSDT.trace_callback(0, frame, arg) + bplist = self._bplist.break_here(frame, event) + if bplist: + for bp in bplist: + sys.stdout.write("RETURN: %s %s %d\n" + % (frame.f_code.co_filename, + frame.f_code.co_name, frame.f_lineno)) + _HelperSDT.trace_callback(3, frame, arg) return self.pytrace_dispatch return self.pytrace_dispatch @@ -219,7 +225,12 @@ class Dispatcher(cmd.Cmd): len(parts)) return filename = parts[0] - lineno = parts[1] + try: + lineno = int(parts[1]) + except: + sys.stderr.write("Invalid breakpoint format: %s\n" % arg) + sys.stderr.write("Invalid line number value (%s)\n" % parts[1]) + return # Decode flags. returnp = False @@ -228,6 +239,11 @@ class Dispatcher(cmd.Cmd): # from line number breaks by the lack of a line number. lineno = None if flags & 0x1: + sys.stderr.write("found returnp\n") + # The breakpoint class distinguishes function return + # breaks from line number breaks by the lack of a line + # number. + lineno = None returnp = True # Actually add the breakpoint. diff --git a/tapset-python.cxx b/tapset-python.cxx index 181726235..19c76a778 100644 --- a/tapset-python.cxx +++ b/tapset-python.cxx @@ -375,7 +375,7 @@ python_builder::build(systemtap_session & sess, probe * base, << ".provider(\"HelperSDT\").mark(\"PyTrace_RETURN\") {" << endl; // FIXME: Placeholder... - code << " printf(\"PyTrace_RETURN\")" << endl; + code << " printf(\"PyTrace_RETURN\\n\")" << endl; code << "}" << endl; python2_return_probe = parse_synthetic_probe (sess, code, tok); if (!python2_return_probe) @@ -393,7 +393,7 @@ python_builder::build(systemtap_session & sess, probe * base, << ".provider(\"HelperSDT\").mark(\"PyTrace_CALL\") {" << endl; // FIXME: Placeholder... - code << " printf(\"PyTrace_CALL\")" << endl; + code << " printf(\"PyTrace_CALL\\n\")" << endl; code << "}" << endl; python2_call_probe = parse_synthetic_probe (sess, code, tok); if (!python2_call_probe) @@ -411,7 +411,7 @@ python_builder::build(systemtap_session & sess, probe * base, << ".provider(\"HelperSDT\").mark(\"PyTrace_LINE\") {" << endl; // FIXME: Placeholder... - code << " printf(\"PyTrace_LINE\")" << endl; + code << " printf(\"PyTrace_LINE\\n\")" << endl; code << "}" << endl; python2_line_probe = parse_synthetic_probe (sess, code, tok); if (!python2_line_probe) -- 2.43.5