Author: Augusto Noronha Date: 2022-10-28T15:04:24-07:00 New Revision: b3b517d572391d9799d1f29bddd66e2bad1acb54
URL: https://github.com/llvm/llvm-project/commit/b3b517d572391d9799d1f29bddd66e2bad1acb54 DIFF: https://github.com/llvm/llvm-project/commit/b3b517d572391d9799d1f29bddd66e2bad1acb54.diff LOG: [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 Added: Modified: lldb/examples/python/crashlog.py Removed: ################################################################################ diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py index eb43e07d27f4..e80ecd91579a 100755 --- a/lldb/examples/python/crashlog.py +++ b/lldb/examples/python/crashlog.py @@ -449,7 +449,7 @@ def parse_json(buffer): head, _, tail = buffer.partition('\n') return json.loads(tail) - with open(path, 'r') as f: + with open(path, 'r', encoding='utf-8') as f: buffer = f.read() try: return parse_json(buffer) @@ -644,7 +644,7 @@ def __init__(self, debugger, path, verbose): } def parse(self): - with open(self.path,'r') as f: + with open(self.path,'r', encoding='utf-8') as f: lines = f.read().splitlines() for line in lines: @@ -865,7 +865,7 @@ def save_crashlog(debugger, command, exe_ctx, result, dict): result.PutCString( "error: invalid arguments, a single output file is the only valid argument") return - out_file = open(args[0], 'w') + out_file = open(args[0], 'w', encoding='utf-8') if not out_file: result.PutCString( "error: failed to open file '%s' for writing...", _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits