Update upload-coredump.py

This commit is contained in:
drindhauser
2020-01-16 11:10:03 +01:00
parent 9669a8c4b2
commit 3b8fbe70ff

View File

@ -64,12 +64,11 @@ class Stacktrace:
class Thread: class Thread:
def __init__(self, id="", name=None, crashed=None, frames=None): def __init__(self, id="", name=None, crashed=None, stacktrace=None):
self.stacktrace = {}
self.id = id self.id = id
self.name = name self.name = name
self.crashed = crashed self.crashed = crashed
self.stacktrace = frames self.stacktrace = stacktrace
def get_stacktrace(self): def get_stacktrace(self):
return self.stacktrace return self.stacktrace
@ -193,13 +192,9 @@ def get_image(temp):
) )
def get_all_threads(path_to_core, path_to_executable, gdb_path): def execute_gdb(gdb_path, path_to_core, path_to_executable):
"""Executes GDB and returns a list with all threads and backtraces""" """creates a subprocess for gdb and returns it"""
thread_list = []
counter_threads = 0
# execute gdb
if gdb_path is None: if gdb_path is None:
process = subprocess.Popen( process = subprocess.Popen(
["gdb", "-c", path_to_core, path_to_executable], ["gdb", "-c", path_to_core, path_to_executable],
@ -216,6 +211,15 @@ def get_all_threads(path_to_core, path_to_executable, gdb_path):
except OSError as err: except OSError as err:
error(err) error(err)
return process
def get_all_threads(process):
"""Returns a list with all threads and backtraces"""
thread_list = []
counter_threads = 0
output, errors = process.communicate(input="thread apply all bt") output, errors = process.communicate(input="thread apply all bt")
if errors: if errors:
error(errors) error(errors)
@ -293,24 +297,14 @@ def main(
if elfutils_path is not None and os.path.exists(elfutils_path) is not True: if elfutils_path is not None and os.path.exists(elfutils_path) is not True:
error("Wrong path for elfutils") error("Wrong path for elfutils")
if not all_threads: # execute gdb
process = execute_gdb(gdb_path, path_to_core, path_to_executable)
if all_threads:
thread_list, type_of_event = get_all_threads(process)
else:
stacktrace = Stacktrace() stacktrace = Stacktrace()
# execute gdb
if gdb_path is None:
process = subprocess.Popen(
["gdb", "-c", path_to_core, path_to_executable],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
)
else:
try:
process = subprocess.Popen(
[gdb_path, "gdb", "-c", path_to_core, path_to_executable],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
)
except OSError as err:
error(format(err))
output, errors = process.communicate(input="bt") output, errors = process.communicate(input="bt")
if errors: if errors:
@ -360,7 +354,7 @@ def main(
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
) )
except OSError as err: except OSError as err:
error(format(err)) error(err)
output, errors = process.communicate() output, errors = process.communicate()
if errors: if errors:
@ -376,10 +370,10 @@ def main(
# build the json for sentry # build the json for sentry
if all_threads: if all_threads:
thread_list, type_of_event = get_all_threads(
path_to_core, path_to_executable, gdb_path for temp in thread_list:
) if temp.crashed:
stacktrace = thread_list[0].get_stacktrace() stacktrace = temp.get_stacktrace()
data = { data = {
"platform": "native", "platform": "native",