Skip to content

Commit 6adcb4b

Browse files
augusto2112medismailben
authored andcommitted
[lldb] Explicitly open file to write with utf-8 encoding in crashlog.py
The python "open" function will use the default encoding for the locale (the result of "locale.getpreferredencoding()"). Explicitly set the locale to utf-8 when opening the crashlog for writing, as there may be non-ascii symbols in there (for example, Swift uses "τ" to indicate generic parameters). rdar://101402755 Differential Revision: https://reviews.llvm.org/D136798
1 parent 186d6d4 commit 6adcb4b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lldb/examples/python/crashlog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def parse_json(buffer):
568568
head, _, tail = buffer.partition("\n")
569569
return json.loads(tail)
570570

571-
with open(path, "r") as f:
571+
with open(path, "r", encoding="utf-8") as f:
572572
buffer = f.read()
573573
try:
574574
return parse_json(buffer)
@@ -910,7 +910,7 @@ def __init__(self, debugger, path, options):
910910
self.symbols = {}
911911

912912
def parse(self):
913-
with open(self.path, "r") as f:
913+
with open(self.path, "r", encoding="utf-8") as f:
914914
lines = f.read().splitlines()
915915

916916
idx = 0
@@ -1257,7 +1257,7 @@ def save_crashlog(debugger, command, exe_ctx, result, dict):
12571257
"error: invalid arguments, a single output file is the only valid argument"
12581258
)
12591259
return
1260-
out_file = open(args[0], "w")
1260+
out_file = open(args[0], "w", encoding="utf-8")
12611261
if not out_file:
12621262
result.PutCString("error: failed to open file '%s' for writing...", args[0])
12631263
return

0 commit comments

Comments
 (0)