aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-01-31 18:05:56 +0100
committerChristian Tismer <tismer@stackless.com>2021-02-01 09:06:21 +0100
commita9dcb53624cdd09ace10687813a3f3badeaa5983 (patch)
tree323eedeb16f572e25387620783dfee0ac9874d46 /tools
parent3507fd23f1f68b509805394713e6e78da986f24a (diff)
PySide: write a renamer script for debugging, improved
Debug output is hard to read if there are many objects with the same type but different address. This script builds simple names instead of addresses which are easy to track. See the info at the beginning of the script. The improved version is more universal since it only requires a "0x..." word followed by some name. There is no other fixed formatting. Task-number: PYSIDE-79 Task-number: PYSIDE-1478 Change-Id: Iae4abd447dc14a67fe7cc212c1de337c70499ac1 Pick-to: 6.0 Pick-to: 5.15 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/debug_renamer.py37
1 files changed, 17 insertions, 20 deletions
diff --git a/tools/debug_renamer.py b/tools/debug_renamer.py
index da5beb127..db3ba5040 100644
--- a/tools/debug_renamer.py
+++ b/tools/debug_renamer.py
@@ -49,21 +49,18 @@ the addresses of objects do not compare well.
Input format:
-------------
-The Python output lines are of this format:
+The Python output lines can be freely formatted.
-mode filename:lineno funcname object_id typename object_refcount
-
-Mode can be "INC", "DEC", "XINC", XDEC", "NEW, "NEWV".
-
-On "NEW" or "NEWV", an object is created and the refcount is always 1.
-On "DEC" or "XDEC", when refcount is 0, the object is deleted.
+Any line which contains "0x.." followed by some name will be changed,
+all others are left alone.
+We name these fields `object_id` and `typename`.
Operation
---------
The script reads from <stdin> until EOF. It produces output where the
-object_id field is removed and some text is combined with object_typename
+`object_id` field is removed and some text is combined with `typename`
to produce a unique object name.
@@ -81,42 +78,42 @@ This is work in flux that might change quite often.
To Do List
----------
-The script should be re-worked to be more flexible, without relying on
-the number of coulumns but with some intelligent guessing.
-
Names of objects which are already deleted should be monitored and
not by chance be re-used.
"""
+import re
import sys
from collections import OrderedDict
-def make_name(type_name, name_pos):
+def make_name(typename, name_pos):
"""
Build a name by using uppercase letters and numbers
"""
if name_pos < 26:
name = chr(ord("A") + name_pos)
- return f"{type_name}_{name}"
- return f"{type_name}_{str(name_pos)}"
+ return f"{typename}_{name}"
+ return f"{typename}_{str(name_pos)}"
-mode_tokens = "NEW NEWV INC DEC XINC XDEC".split()
known_types = {}
+pattern = r"0x\w+\s+\S+" # hex word followed by non-WS
+rex = re.compile(pattern, re.IGNORECASE)
-while 1:
+while True:
line = sys.stdin.readline()
if not line:
break
- fields = line.split()
- if len(fields) != 6 or fields[0] not in mode_tokens:
+ if not (res := rex.search(line)):
print(line.rstrip())
continue
- mode, fname_lno, funcname, object_id, typename, refcount = fields
+ start_pos, end_pos = res.start(), res.end()
+ beg, mid, end = line[:start_pos], line[start_pos : end_pos], line[end_pos:].rstrip()
+ object_id, typename = mid.split()
if typename not in known_types:
known_types[typename] = OrderedDict()
obj_store = known_types[typename]
if object_id not in obj_store:
obj_store[object_id] = make_name(typename, len(obj_store))
- print(f"{mode} {fname_lno} {funcname} {obj_store[object_id]} {refcount}")
+ print(f"{beg}{obj_store[object_id]}{end}")