forked from getsentry/coredump-uploader
Add files via upload
This commit is contained in:
@ -6,6 +6,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import click
|
import click
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class Frame:
|
class Frame:
|
||||||
@ -46,16 +47,15 @@ _frame_re = re.compile(
|
|||||||
#address of instruction
|
#address of instruction
|
||||||
(?P<instruction_addr>
|
(?P<instruction_addr>
|
||||||
0[xX][a-fA-F0-9]+
|
0[xX][a-fA-F0-9]+
|
||||||
)*
|
|
||||||
|
|
||||||
#name of function
|
|
||||||
\sin\s
|
|
||||||
(?P<name_of_function>
|
|
||||||
.*
|
|
||||||
)
|
)
|
||||||
|
#name of function
|
||||||
|
(\sin)? \s?
|
||||||
|
(?P<name_of_function>
|
||||||
|
[a-zA-z]+
|
||||||
|
)?
|
||||||
|
|
||||||
#path from the file
|
#path from the file
|
||||||
\s\(\)(\sat\s)?
|
(\s\(\))? (\sat\s)?
|
||||||
(?P<path>
|
(?P<path>
|
||||||
.*\.c
|
.*\.c
|
||||||
)?
|
)?
|
||||||
@ -94,11 +94,13 @@ _image_re = re.compile(
|
|||||||
0[xX][0-9A-F-a-f]+
|
0[xX][0-9A-F-a-f]+
|
||||||
)*
|
)*
|
||||||
|
|
||||||
#Code file
|
#Code File
|
||||||
(\s|\s\.\s\-\s)
|
(\s|\s\.\s\-\s)?
|
||||||
|
(\.\s)?
|
||||||
|
(-\s)*
|
||||||
(?P<code_file>
|
(?P<code_file>
|
||||||
[\/|.\/][\w|\S]+|\S+\.\S+
|
[\/|.\/][\w|\S]+|\S+\.\S+|[a-zA-Z]*
|
||||||
)
|
)?
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -114,41 +116,41 @@ def error(message):
|
|||||||
|
|
||||||
def get_frame(gdb_output):
|
def get_frame(gdb_output):
|
||||||
"""Parses the output from gdb """
|
"""Parses the output from gdb """
|
||||||
|
|
||||||
frame = Frame()
|
frame = Frame()
|
||||||
temp = _frame_re.search(gdb_output)
|
temp = _frame_re.search(gdb_output)
|
||||||
if temp is not None:
|
if temp is None:
|
||||||
frame.instruction_addr = temp.group("instruction_addr")
|
return
|
||||||
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:
|
|
||||||
frame.path = temp.group("path")
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
frame.path = temp.group("path")
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
|
|
||||||
def get_image(image_string):
|
def get_image(image_string):
|
||||||
"""Parses the output from eu-unstrip"""
|
"""Parses the output from eu-unstrip"""
|
||||||
image = Image()
|
|
||||||
image.type = "elf"
|
|
||||||
|
|
||||||
temp = _image_re.search(image_string)
|
temp = _image_re.search(image_string)
|
||||||
if temp is not None:
|
if temp is None:
|
||||||
image.image_addr = temp.group("image_addr")
|
return None
|
||||||
image.image_size = int(temp.group("image_size"), 16)
|
|
||||||
image.code_id = temp.group("code_id")
|
|
||||||
image.debug_id = code_id_to_debug_id(temp.group("code_id"))
|
|
||||||
image.code_file = temp.group("code_file")
|
|
||||||
|
|
||||||
return image
|
return Image(
|
||||||
|
type="elf",
|
||||||
|
image_addr=temp.group("image_addr"),
|
||||||
|
image_size=int(temp.group("image_size"), 16),
|
||||||
|
code_id=temp.group("code_id"),
|
||||||
|
debug_id=code_id_to_debug_id(temp.group("code_id")),
|
||||||
|
code_file=temp.group("code_file"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.argument("path_to_core")
|
@click.argument("path_to_core")
|
||||||
@click.argument("path_to_executable")
|
@click.argument("path_to_executable")
|
||||||
@click.argument("sentry_dsn", nargs=-1, required=False)
|
@click.option("--sentry-dsn", required=False)
|
||||||
def main(path_to_core, path_to_executable, sentry_dsn):
|
def main(path_to_core, path_to_executable, sentry_dsn):
|
||||||
|
|
||||||
# Validate input Path
|
# Validate input Path
|
||||||
@ -166,7 +168,7 @@ def main(path_to_core, path_to_executable, sentry_dsn):
|
|||||||
|
|
||||||
# execute gdb
|
# execute gdb
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
["gdb", "-c", path_to_core, path_to_executable],
|
["gdb", "-c", path_to_core, "-e", path_to_executable],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
@ -182,15 +184,20 @@ def main(path_to_core, path_to_executable, sentry_dsn):
|
|||||||
["eu-unstrip", "-n", "--core", path_to_core, "-e", path_to_executable],
|
["eu-unstrip", "-n", "--core", path_to_core, "-e", path_to_executable],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
|
|
||||||
output = process.communicate()
|
output = process.communicate()
|
||||||
|
|
||||||
eu_unstrip_output = str(output[0]).split("\n")
|
eu_unstrip_output = str(output[0]).split("\n")
|
||||||
|
|
||||||
for x in range(2, len(gdb_output)):
|
for x in range(2, len(gdb_output)):
|
||||||
frame_list.append(get_frame(gdb_output[x]))
|
frame = get_frame(gdb_output[x])
|
||||||
|
if frame is not None:
|
||||||
|
frame_list.append(frame)
|
||||||
|
|
||||||
for x in range(0, len(eu_unstrip_output) - 1):
|
for x in range(0, len(eu_unstrip_output) - 1):
|
||||||
image_list.append(get_image(eu_unstrip_output[x]))
|
image = get_image(eu_unstrip_output[x])
|
||||||
|
if image is not None:
|
||||||
|
image_list.append(image)
|
||||||
|
|
||||||
# build the json for sentry
|
# build the json for sentry
|
||||||
data = {
|
data = {
|
||||||
@ -203,13 +210,7 @@ def main(path_to_core, path_to_executable, sentry_dsn):
|
|||||||
"debug_meta": {"images": [ob.to_json() for ob in image_list]},
|
"debug_meta": {"images": [ob.to_json() for ob in image_list]},
|
||||||
}
|
}
|
||||||
|
|
||||||
if sentry_dsn is None:
|
sentry_sdk.init(sentry_dsn)
|
||||||
sentry_sdk.init(
|
|
||||||
sentry_dsn
|
|
||||||
# "http://a707e782690f46ebb752810d1a08406a@host.docker.internal:8000/4"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
sentry_sdk.init()
|
|
||||||
sentry_sdk.capture_event(data)
|
sentry_sdk.capture_event(data)
|
||||||
print("Core dump sent to sentry")
|
print("Core dump sent to sentry")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user