Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad0a88f

Browse files
committed
feat(minidump_parser): include additional fields in logs
1 parent2ed5771 commitad0a88f

File tree

2 files changed

+83
-18
lines changed

2 files changed

+83
-18
lines changed

‎src/ffpuppet/minidump_parser.py‎

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313
fromtempfileimportTemporaryFile,mkdtemp
1414
fromtypingimportIO,Any
1515

16+
EXTRA_FIELDS= (
17+
# android only
18+
"CrashType",
19+
# Reason why the cycle collector crashed.
20+
"CycleCollector",
21+
# usually assertions message
22+
"MozCrashReason",
23+
# Set if the crash was the result of a hang, with a value which describes the
24+
# type of hang (e.g. "ui" or "shutdown").
25+
"Hang",
26+
# Set before a content process crashes because of an IPC channel error, holds
27+
# a description of the error.
28+
"ipc_channel_error",
29+
"ShutdownReason",
30+
)
1631
LOG=getLogger(__name__)
1732
MDSW_URL="https://lib.rs/crates/minidump-stackwalk"
1833
SYMS_URL="https://symbols.mozilla.org/"
@@ -60,13 +75,44 @@ def _cmd(self, src: Path) -> list[str]:
6075
returncmd
6176

6277
@staticmethod
63-
def_fmt_output(data:dict[str,Any],out_fp:IO[bytes],limit:int=150)->None:
78+
def_metadata(dmp:Path,fields:tuple[str, ...])->dict[str,str]:
79+
"""Collect metadata from .extra file.
80+
81+
Args:
82+
dmp: Matching minidump file.
83+
fields: Fields to collect if available.
84+
85+
Returns:
86+
Metadata from .extra file.
87+
"""
88+
extra=dmp.with_suffix(".extra")
89+
metadata:dict[str,str]= {}
90+
ifextra.is_file():
91+
withextra.open("r")asextra_fp:
92+
try:
93+
extra_data=load(extra_fp)
94+
exceptJSONDecodeError:
95+
LOG.warning("Invalid json in: %s",extra)
96+
return {}
97+
forentryinfields:
98+
ifentryinextra_data:
99+
metadata[entry]=str(extra_data[entry])
100+
returnmetadata
101+
102+
@staticmethod
103+
def_fmt_output(
104+
data:dict[str,Any],
105+
out_fp:IO[bytes],
106+
metadata:dict[str,str],
107+
limit:int=150,
108+
)->None:
64109
"""Write summarized contents of a minidump to a file in a format that is
65110
consumable by FuzzManager.
66111
67112
Args:
68-
md_data: Minidump contents.
113+
data: Minidump contents.
69114
out_fp: Formatted content destination.
115+
metadata: Extra file contents.
70116
limit: Maximum number of stack frames to include.
71117
72118
Returns:
@@ -88,6 +134,11 @@ def _fmt_output(data: dict[str, Any], out_fp: IO[bytes], limit: int = 150) -> No
88134
out_fp.write("".join(reg_lines).rstrip().encode())
89135
out_fp.write(b"\n")
90136

137+
# include metadata
138+
forentryinmetadata.items():
139+
out_fp.write("|".join(entry).encode())
140+
out_fp.write(b"\n")
141+
91142
# generate OS information line
92143
line="|".join(
93144
("OS",data["system_info"]["os"],data["system_info"]["os_ver"])
@@ -170,6 +221,10 @@ def create_log(self, src: Path, filename: str, timeout: int = 300) -> Path:
170221
"""
171222
assertfilename
172223
asserttimeout>=0
224+
225+
# collect data from .extra file if it exists
226+
metadata=self._metadata(src,EXTRA_FIELDS)
227+
173228
cmd=self._cmd(src)
174229
dst=self._storage/filename
175230
with (
@@ -182,7 +237,7 @@ def create_log(self, src: Path, filename: str, timeout: int = 300) -> Path:
182237
out_fp.seek(0)
183238
# load json, format data and write log
184239
withdst.open("wb")aslog_fp:
185-
self._fmt_output(load(out_fp),log_fp)
240+
self._fmt_output(load(out_fp),log_fp,metadata)
186241
except (CalledProcessError,JSONDecodeError,TimeoutExpired)asexc:
187242
ifisinstance(exc,CalledProcessError):
188243
msg=f"minidump-stackwalk failed ({exc.returncode})"

‎src/ffpuppet/test_minidump_parser.py‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
# You can obtain one at http://mozilla.org/MPL/2.0/.
4+
# pylint: disable=protected-access
45
"""ffpuppet minidump parser tests"""
56

67
fromcopyimportdeepcopy
@@ -91,7 +92,6 @@ def test_minidump_parser_01(mocker, tmp_path, symbols):
9192
mocker.patch.object(MinidumpParser,"MDSW_BIN","minidump-stackwalk")
9293
withMinidumpParser(symbols=tmp_pathifsymbolselseNone)asparser:
9394
assertparser
94-
# pylint: disable=protected-access
9595
cmd=parser._cmd(tmp_path)
9696
assertcmd
9797
assert"minidump-stackwalk"incmd
@@ -118,7 +118,6 @@ def test_minidump_parser_02(mocker, code, token, timeout):
118118
"""test MinidumpParser.create_log()"""
119119
mocker.patch.object(MinidumpParser,"_cmd",return_value=[executable,"-c",code])
120120
withMinidumpParser()asparser:
121-
# pylint: disable=protected-access
122121
assertparser._storage.is_dir()
123122
output=parser.create_log(Path("foo.dmp"),"minidump_00.txt",timeout=timeout)
124123
assertoutput
@@ -154,8 +153,7 @@ def test_minidump_parser_02(mocker, code, token, timeout):
154153
deftest_minidump_parser_03(tmp_path,data,reg,operating_system,cpu,crash,frame):
155154
"""test MinidumpParser._fmt_output() - un-symbolized"""
156155
with (tmp_path/"out.txt").open("w+b")asofp:
157-
# pylint: disable=protected-access
158-
MinidumpParser._fmt_output(data,ofp,limit=2)
156+
MinidumpParser._fmt_output(data,ofp, {},limit=2)
159157
ofp.seek(0)
160158
formatted=ofp.read().rstrip().decode().split("\n")
161159
assertlen(formatted)==5
@@ -206,19 +204,19 @@ def test_minidump_parser_04(tmp_path):
206204
}
207205

208206
with (tmp_path/"out.txt").open("w+b")asofp:
209-
# pylint: disable=protected-access
210-
MinidumpParser._fmt_output(data,ofp,limit=2)
207+
MinidumpParser._fmt_output(data,ofp, {"metadata":"foo"},limit=2)
211208
ofp.seek(0)
212209
formatted=ofp.read().rstrip().decode().split("\n")
213-
assertlen(formatted)==8
210+
assertlen(formatted)==9
214211
assertformatted[0]=="r10 = 0x12345678\tr11 = 0x0badf00d\tr12 = 0x00000000"
215212
assertformatted[1]=="r13 = 0x000000dceebfc2e8"
216-
assertformatted[2]=="OS|Windows NT|10.0.19044"
217-
assertformatted[3]=="CPU|amd64|family 6 model 70 stepping 1|8"
218-
assertformatted[4]=="Crash|EXCEPTION_BREAKPOINT|0x00007ffe4e09af8d|0"
219-
assertformatted[5]=="0|0|xul.dll|function00()|file0.cpp|47|0x1ed"
220-
assertformatted[6]=="0|1|xul.dll|function01()|file1.cpp|210|0x1bb"
221-
assertformatted[7]=="WARNING: Hit stack size output limit!"
213+
assertformatted[2]=="metadata|foo"
214+
assertformatted[3]=="OS|Windows NT|10.0.19044"
215+
assertformatted[4]=="CPU|amd64|family 6 model 70 stepping 1|8"
216+
assertformatted[5]=="Crash|EXCEPTION_BREAKPOINT|0x00007ffe4e09af8d|0"
217+
assertformatted[6]=="0|0|xul.dll|function00()|file0.cpp|47|0x1ed"
218+
assertformatted[7]=="0|1|xul.dll|function01()|file1.cpp|210|0x1bb"
219+
assertformatted[8]=="WARNING: Hit stack size output limit!"
222220

223221

224222
@mark.parametrize(
@@ -294,11 +292,23 @@ def test_minidump_parser_06(tmp_path):
294292
deftest_minidump_parser_missing_crashing_thread(tmp_path):
295293
"""test MinidumpParser._fmt_output() - missing crashing thread"""
296294
with (tmp_path/"out.txt").open("w+b")asofp:
297-
# pylint: disable=protected-access
298-
MinidumpParser._fmt_output(MD_BASE_AMD64_WIN,ofp)
295+
MinidumpParser._fmt_output(MD_BASE_AMD64_WIN,ofp, {})
299296
ofp.seek(0)
300297
formatted=ofp.read().rstrip().decode().split("\n")
301298
assertlen(formatted)==3
302299
assertformatted[0]=="OS|Windows NT|10.0.19044"
303300
assertformatted[1]=="CPU|amd64|family 6 model 70 stepping 1|8"
304301
assertformatted[2]=="Crash|EXCEPTION_BREAKPOINT|0x00007ffe4e09af8d|?"
302+
303+
304+
deftest_minidump_parser_metadata(tmp_path):
305+
"""test MinidumpParser._metadata()"""
306+
# collect metadata from .extra file
307+
(tmp_path/"out.extra").write_text(dumps({"a":"1","b":"2","c":"3"}))
308+
result=MinidumpParser._metadata(tmp_path/"out.dmp", ("a","c"))
309+
assert"a"inresult
310+
assert"b"notinresult
311+
assert"c"inresult
312+
# invalid .extra file
313+
(tmp_path/"out.extra").write_text("!")
314+
assertnotMinidumpParser._metadata(tmp_path/"out.dmp", ("a","c"))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp