Skip to content

Commit 00cef88

Browse files
committed
Customize bt colorization
221e27d03ecf65a066e77e452326e20c49e89df5
1 parent 212b9b6 commit 00cef88

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

build/plugins/lib/test_const/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# coding: utf-8
22
import re
33

4+
TEST_BT_COLORS = {
5+
"function_name": "[[alt1]]",
6+
"function_arg": "[[good]]",
7+
"stack_frame": "[[bad]]",
8+
"thread_prefix": "[[alt3]]",
9+
"thread_id": "[[bad]]",
10+
"file_path": "[[warn]]",
11+
"line_num": "[[alt2]]",
12+
"address": "[[unimp]]",
13+
}
414

515
RESTART_TEST_INDICATOR = '##restart-test##'
616
INFRASTRUCTURE_ERROR_INDICATOR = '##infrastructure-error##'

library/python/cores/__init__.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,45 @@ def get_problem_stack(backtrace):
162162
return "\n".join(stack)
163163

164164

165+
BT_COLORS = {
166+
"function_name": "[[c:cyan]]",
167+
"function_arg": "[[c:green]]",
168+
"stack_frame": "[[c:red]]",
169+
"thread_prefix": "[[c:light-cyan]]",
170+
"thread_id": "[[c:red]]",
171+
"file_path": "[[c:light-grey]]",
172+
"line_num": "[[c:magenta]]",
173+
"address": "[[c:light-grey]]",
174+
}
175+
176+
165177
# XXX
166-
def colorize_backtrace(text):
178+
def colorize_backtrace(text, c=None):
179+
if c is None:
180+
c = BT_COLORS
181+
167182
filters = [
168183
# Function names and the class they belong to
169-
(re.compile(r"^(#[0-9]+ .*?)([a-zA-Z0-9_:\.@]+)(\s?\()", flags=re.MULTILINE), r"\1[[c:cyan]]\2[[rst]]\3"),
184+
(
185+
re.compile(r"^(#[0-9]+ .*?)([a-zA-Z0-9_:\.@]+)(\s?\()", flags=re.MULTILINE),
186+
r"\1" + c['function_name'] + r"\2[[rst]]\3",
187+
),
170188
# Function argument names
171-
(re.compile(r"([a-zA-Z0-9_#]*)(\s?=\s?)"), r"[[c:green]]\1[[rst]]\2"),
189+
(re.compile(r"([a-zA-Z0-9_#]*)(\s?=\s?)"), c["function_arg"] + r"\1[[rst]]\2"),
172190
# Stack frame number
173-
(re.compile(r"^(#[0-9]+)", flags=re.MULTILINE), r"[[c:red]]\1[[rst]]"),
191+
(re.compile(r"^(#[0-9]+)", flags=re.MULTILINE), c["stack_frame"] + r"\1[[rst]]"),
174192
# Thread id colorization
175-
(re.compile(r"^([ \*]) ([0-9]+)", flags=re.MULTILINE), r"[[c:light-cyan]]\1 [[c:red]]\2[[rst]]"),
193+
(
194+
re.compile(r"^([ \*]) ([0-9]+)", flags=re.MULTILINE),
195+
c["thread_prefix"] + r"\1 " + c["thread_id"] + r"\2[[rst]]",
196+
),
176197
# File path and line number
177-
(re.compile(r"(\.*[/A-Za-z0-9\+_\.\-]*):(([0-9]+)(:[0-9]+)?)$", flags=re.MULTILINE), r"[[c:light-grey]]\1[[rst]]:[[c:magenta]]\2[[rst]]"),
198+
(
199+
re.compile(r"(\.*[/A-Za-z0-9\+_\.\-]*):(([0-9]+)(:[0-9]+)?)$", flags=re.MULTILINE),
200+
c["file_path"] + r"\1[[rst]]:" + c["line_num"] + r"\2[[rst]]",
201+
),
178202
# Addresses
179-
(re.compile(r"\b(0x[a-f0-9]{6,})\b"), r"[[c:light-grey]]\1[[rst]]"),
203+
(re.compile(r"\b(0x[a-f0-9]{6,})\b"), c["address"] + r"\1[[rst]]"),
180204
]
181205

182206
text = six.ensure_str(text)

0 commit comments

Comments
 (0)