diff --git a/README.md b/README.md index fcb3689..e8f23c0 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,16 @@ Coredump Uploader Requirements: ------- +python + GDB elfutils +sentry-sdk + +click + Usage: -------- diff --git a/tests/coredumplib.py b/tests/coredumplib.py new file mode 120000 index 0000000..f525992 --- /dev/null +++ b/tests/coredumplib.py @@ -0,0 +1 @@ +../upload-coredump.py \ No newline at end of file diff --git a/tests/test_basic.py b/tests/test_basic.py index 1ebd267..b1b1dba 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -24,7 +24,7 @@ def test_code_id_to_debug_id(): instruction_addr="0x000055ee7d69e60a", name_of_function="crashing_function", path="./test.c", - lineno="3", + lineno=3, ), ], [ @@ -33,7 +33,7 @@ def test_code_id_to_debug_id(): instruction_addr="0x000055ee7d69e61c", name_of_function="main", path="./test.c", - lineno="7", + lineno=7, ), ], [ @@ -46,10 +46,19 @@ def test_code_id_to_debug_id(): ), ], [ - "3 0x000055708e742643 in main ()", + "#1 0x0000748f47a34256 in ::event ()", Frame( - instruction_addr="0x000055708e742643", - name_of_function="main", + instruction_addr="0x0000748f47a34256", + name_of_function="event", + path="abs_path", + lineno=None, + ), + ], + [ + "#1 0x0000748f47a34256 in test::function as test::function::event ()", + Frame( + instruction_addr="0x0000748f47a34256", + name_of_function="event", path="abs_path", lineno=None, ), @@ -81,7 +90,7 @@ def test_get_frame(gdb_output, parsed): [ "0x55ee7d69e000+0x201018 b814d9f87debe4b312c06a03fa8d6b44a7b41199@0x55ee7d69e284 ./a.out . a.out", Image( - code_file="./a.out", + code_file="/a.out", code_id="b814d9f87debe4b312c06a03fa8d6b44a7b41199", image_addr="0x55ee7d69e000", image_size=2101272, @@ -112,9 +121,9 @@ def test_frame_to_json(): frame = Frame() assert frame.to_json() == { "instruction_addr": "", - "lineno": "", + "lineno": None, "name_of_function": "", - "path": "", + "path": "abs_path", } diff --git a/upload-coredump.py b/upload-coredump.py index a6578f9..fcf822b 100644 --- a/upload-coredump.py +++ b/upload-coredump.py @@ -10,7 +10,9 @@ import time class Frame: - def __init__(self, instruction_addr="", name_of_function="", path="", lineno=""): + def __init__( + self, instruction_addr="", name_of_function="", path="abs_path", lineno=None, + ): self.instruction_addr = instruction_addr self.name_of_function = name_of_function self.path = path @@ -58,7 +60,7 @@ _frame_re = re.compile( )? #path from the file - (\s\(\))? (\sat\s)? + (\s\(.*\))? (\sat\s)? (?P .*\.c )? @@ -127,12 +129,15 @@ def get_frame(gdb_output): return frame.instruction_addr = temp.group("instruction_addr") + frame.name_of_function = temp.group("name_of_function") - frame.lineno = temp.group("lineno") - if temp.group("path") is None: - frame.path = "abs_path" - else: + + if temp.group("lineno") is not None: + frame.lineno = int(temp.group("lineno")) + + if temp.group("path") is not None: frame.path = temp.group("path") + return frame @@ -167,10 +172,10 @@ def main(path_to_core, path_to_executable, sentry_dsn, gdb_path, elfutils_path): if os.path.isfile(path_to_executable) is not True: error("Wrong path to executable") - if gdb_path is not None and os.path.isfile(gdb_path) is not True: + if gdb_path is not None and os.path.exists(gdb_path) is not True: error("Wrong path for gdb") - if elfutils_path is not None and os.path.isfile(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") image_list = [] @@ -187,11 +192,14 @@ def main(path_to_core, path_to_executable, sentry_dsn, gdb_path, elfutils_path): stdin=subprocess.PIPE, ) else: - process = subprocess.Popen( - [gdb_path, "gdb", "-c", path_to_core, path_to_executable], - stdout=subprocess.PIPE, - stdin=subprocess.PIPE, - ) + 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 = re.search(r"#0.*", str(process.communicate(input="bt"))) try: @@ -206,24 +214,27 @@ def main(path_to_core, path_to_executable, sentry_dsn, gdb_path, elfutils_path): stdout=subprocess.PIPE, ) else: - process = subprocess.Popen( - [ - elfutils_path, - "eu-unstrip", - "-n", - "--core", - path_to_core, - "-e", - path_to_executable, - ], - stdout=subprocess.PIPE, - ) + try: + process = subprocess.Popen( + [ + elfutils_path, + "eu-unstrip", + "-n", + "--core", + path_to_core, + "-e", + path_to_executable, + ], + stdout=subprocess.PIPE, + ) + except OSError as err: + error(format(err)) output = process.communicate() eu_unstrip_output = str(output[0]).split("\n") - for x in range(2, len(gdb_output)): + for x in range(1, len(gdb_output)): frame = get_frame(gdb_output[x]) if frame is not None: frame_list.append(frame) @@ -246,7 +257,7 @@ def main(path_to_core, path_to_executable, sentry_dsn, gdb_path, elfutils_path): sentry_sdk.init(sentry_dsn) sentry_sdk.capture_event(data) - print("Core dump sent to sentry") + print("Core dump sent to sentry!") if __name__ == "__main__":