Browse Source

Customize bt colorization
221e27d03ecf65a066e77e452326e20c49e89df5

iaz1607 6 months ago
parent
commit
00cef8844c
2 changed files with 41 additions and 7 deletions
  1. 10 0
      build/plugins/lib/test_const/__init__.py
  2. 31 7
      library/python/cores/__init__.py

+ 10 - 0
build/plugins/lib/test_const/__init__.py

@@ -1,6 +1,16 @@
 # coding: utf-8
 # coding: utf-8
 import re
 import re
 
 
+TEST_BT_COLORS = {
+    "function_name": "[[alt1]]",
+    "function_arg": "[[good]]",
+    "stack_frame": "[[bad]]",
+    "thread_prefix": "[[alt3]]",
+    "thread_id": "[[bad]]",
+    "file_path": "[[warn]]",
+    "line_num": "[[alt2]]",
+    "address": "[[unimp]]",
+}
 
 
 RESTART_TEST_INDICATOR = '##restart-test##'
 RESTART_TEST_INDICATOR = '##restart-test##'
 INFRASTRUCTURE_ERROR_INDICATOR = '##infrastructure-error##'
 INFRASTRUCTURE_ERROR_INDICATOR = '##infrastructure-error##'

+ 31 - 7
library/python/cores/__init__.py

@@ -162,21 +162,45 @@ def get_problem_stack(backtrace):
     return "\n".join(stack)
     return "\n".join(stack)
 
 
 
 
+BT_COLORS = {
+    "function_name": "[[c:cyan]]",
+    "function_arg": "[[c:green]]",
+    "stack_frame": "[[c:red]]",
+    "thread_prefix": "[[c:light-cyan]]",
+    "thread_id": "[[c:red]]",
+    "file_path": "[[c:light-grey]]",
+    "line_num": "[[c:magenta]]",
+    "address": "[[c:light-grey]]",
+}
+
+
 # XXX
 # XXX
-def colorize_backtrace(text):
+def colorize_backtrace(text, c=None):
+    if c is None:
+        c = BT_COLORS
+
     filters = [
     filters = [
         # Function names and the class they belong to
         # Function names and the class they belong to
-        (re.compile(r"^(#[0-9]+ .*?)([a-zA-Z0-9_:\.@]+)(\s?\()", flags=re.MULTILINE), r"\1[[c:cyan]]\2[[rst]]\3"),
+        (
+            re.compile(r"^(#[0-9]+ .*?)([a-zA-Z0-9_:\.@]+)(\s?\()", flags=re.MULTILINE),
+            r"\1" + c['function_name'] + r"\2[[rst]]\3",
+        ),
         # Function argument names
         # Function argument names
-        (re.compile(r"([a-zA-Z0-9_#]*)(\s?=\s?)"), r"[[c:green]]\1[[rst]]\2"),
+        (re.compile(r"([a-zA-Z0-9_#]*)(\s?=\s?)"), c["function_arg"] + r"\1[[rst]]\2"),
         # Stack frame number
         # Stack frame number
-        (re.compile(r"^(#[0-9]+)", flags=re.MULTILINE), r"[[c:red]]\1[[rst]]"),
+        (re.compile(r"^(#[0-9]+)", flags=re.MULTILINE), c["stack_frame"] + r"\1[[rst]]"),
         # Thread id colorization
         # Thread id colorization
-        (re.compile(r"^([ \*]) ([0-9]+)", flags=re.MULTILINE), r"[[c:light-cyan]]\1 [[c:red]]\2[[rst]]"),
+        (
+            re.compile(r"^([ \*]) ([0-9]+)", flags=re.MULTILINE),
+            c["thread_prefix"] + r"\1 " + c["thread_id"] + r"\2[[rst]]",
+        ),
         # File path and line number
         # File path and line number
-        (re.compile(r"(\.*[/A-Za-z0-9\+_\.\-]*):(([0-9]+)(:[0-9]+)?)$", flags=re.MULTILINE), r"[[c:light-grey]]\1[[rst]]:[[c:magenta]]\2[[rst]]"),
+        (
+            re.compile(r"(\.*[/A-Za-z0-9\+_\.\-]*):(([0-9]+)(:[0-9]+)?)$", flags=re.MULTILINE),
+            c["file_path"] + r"\1[[rst]]:" + c["line_num"] + r"\2[[rst]]",
+        ),
         # Addresses
         # Addresses
-        (re.compile(r"\b(0x[a-f0-9]{6,})\b"), r"[[c:light-grey]]\1[[rst]]"),
+        (re.compile(r"\b(0x[a-f0-9]{6,})\b"), c["address"] + r"\1[[rst]]"),
     ]
     ]
 
 
     text = six.ensure_str(text)
     text = six.ensure_str(text)