Fix thread detection

This commit is contained in:
Jan Michael Auer
2020-01-22 11:22:10 +01:00
parent cdb787c26d
commit 0f3bcbec3d

View File

@ -93,7 +93,7 @@ _frame_re = re.compile(
\s \s
# arguments, ignored # arguments, ignored
\([^)]*\) \([^)]*\)
\s* \s*
(?: (?:
# package name, without debug info # package name, without debug info
@ -112,7 +112,7 @@ _frame_re = re.compile(
_image_re = re.compile( _image_re = re.compile(
r"""(?x) r"""(?x)
# address of image # address of image
(?P<image_addr> (?P<image_addr>
0[xX][a-fA-F0-9]+ 0[xX][a-fA-F0-9]+
@ -138,7 +138,7 @@ _image_re = re.compile(
#Code File #Code File
(\s|\s\.\s\-\s)? (\s|\s\.\s\-\s)?
(\.\s)? (\.\s)?
(-\s)* (-\s)*
\.? \.?
(?P<code_file> (?P<code_file>
@ -149,8 +149,8 @@ _image_re = re.compile(
_register_re = re.compile( _register_re = re.compile(
r"""(?xi) r"""(?xi)
# name of the register # name of the register
(?P<register_name>[0-9a-z]+) (?P<register_name>[0-9a-z]+)
\s* \s*
@ -174,7 +174,7 @@ def get_frame(temp):
if temp.group("instruction_addr") is not None: if temp.group("instruction_addr") is not None:
frame.instruction_addr = temp.group("instruction_addr") frame.instruction_addr = temp.group("instruction_addr")
if temp.group("function") is not None: if temp.group("function") not in (None, "??"):
frame.function = temp.group("function") frame.function = temp.group("function")
if temp.group("lineno") is not None: if temp.group("lineno") is not None:
@ -240,14 +240,17 @@ def get_all_threads(process):
# splits gdb output to get each Thread # splits gdb output to get each Thread
try: try:
gdb_output = output.split("Thread") gdb_output = output.split("\n\nThread ")
except: except:
error("gdb output error") error("gdb output error")
crashed_thread_id = re.search( crashed_thread_id = re.search(
r"(?xi)\[Current\s thread\s is\s [0-9a-z]*\s\([a-z]*\s? (?P<thread_id>[a-z0-9]+) \)]", r"(?i)current thread is (?P<thread_id>\d+)",
gdb_output[0], gdb_output[0],
) )
if crashed_thread_id:
crashed_thread_id = crashed_thread_id.group("thread_id")
# Get the exit Signal from the gdb-output # Get the exit Signal from the gdb-output
try: try:
exit_signal = re.search( exit_signal = re.search(
@ -263,10 +266,13 @@ def get_all_threads(process):
stacktrace = Stacktrace() stacktrace = Stacktrace()
# gets the Thread ID # gets the Thread ID
thread_id = re.search( thread_id = re.match(r"(?i)(?P<thread_id>\d+) \(thread 0x[0-9a-f]+ \((?P<thread_name>.*)\)\)", thread_backtrace)
r"(?xi) [0-9a-z]*\s\([a-z]*\s? (?P<thread_id>[a-fA-F0-9]+)", if thread_id is None:
thread_backtrace, continue
) else:
thread_name = thread_id.group("thread_name")
print("name: %s" % thread_name)
thread_id = thread_id.group("thread_id")
# gets each frame from the Thread # gets each frame from the Thread
for match in re.finditer(_frame_re, thread_backtrace): for match in re.finditer(_frame_re, thread_backtrace):
@ -276,14 +282,11 @@ def get_all_threads(process):
stacktrace.reverse_list() stacktrace.reverse_list()
if thread_id.group("thread_id") == crashed_thread_id.group("thread_id"): crashed = thread_id == crashed_thread_id
crashed = True
else:
crashed = False
# appends a Thread to the thread_list # appends a Thread to the thread_list
thread_list.append( thread_list.append(
Thread(thread_id.group("thread_id"), None, crashed, stacktrace.to_json()) Thread(thread_id, thread_name, crashed, stacktrace.to_json())
) )
counter_threads += 1 counter_threads += 1
@ -385,7 +388,7 @@ def main(
image = get_image(match) image = get_image(match)
if image is not None: if image is not None:
image_list.append(image) image_list.append(image)
# Get timestamp # Get timestamp
stat = os.stat(path_to_core) stat = os.stat(path_to_core)
try: try: