From 7f1cad89bc86438673987d031072ee96eda096c9 Mon Sep 17 00:00:00 2001 From: icebp <8842017+icebp@users.noreply.github.com> Date: Thu, 27 Dec 2018 21:30:17 +0200 Subject: [PATCH] add support for unfinished and resumed operations. --- villoc.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/villoc.py b/villoc.py index 88c81a1..22b879b 100755 --- a/villoc.py +++ b/villoc.py @@ -227,7 +227,11 @@ def parse_ltrace(ltrace): match_call = re.compile(r"^([A-z_\.]+->)?([A-z_]+)\((.*)\) += (.*)$") match_err = re.compile(r"^([A-z_\.]+->)?([A-z_]+)\((.*) ") + match_unfinished = re.compile(r"^([A-z_\.]+->)?([A-z_]+)\((.*) ") + match_resumed = re.compile(r"^<\.\.\. (.*) resumed> \) += (.*)$") + # for multithreaded applications + unfinished_calls = {} for line in ltrace: # if the trace file contains PID (for ltrace -f) @@ -237,6 +241,7 @@ def parse_ltrace(ltrace): try: _, func, args, ret = match_call.findall(line)[0] + if not func in operations: continue except Exception: @@ -248,10 +253,32 @@ def parse_ltrace(ltrace): continue ret = None except Exception: - print("ignoring line: %s" % line, file=sys.stderr) - continue + + try: + # maybe this is an unfinished operation + _, func, args = match_unfinished.findall(line)[0] + unfinished_calls[head] = (func, args) + + continue + + except Exception: + try: + # or a resumed operation + if len(unfinished_calls) > 0: + func, ret = match_resumed.findall(line)[0] + + if not unfinished_calls[head][0] == func: + continue + args = unfinished_calls[head][1] + unfinished_calls.pop(head) + + except Exception: + print("ignoring line: %s" % line, file=sys.stderr) + continue print("%s" % (line.strip(),), file=sys.stderr) + if type(args) == list: + args = ''.join(args) args = list(map(sanitize, args.split(", "))) ret = sanitize(ret)