diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py --- a/lldb/examples/python/crashlog.py +++ b/lldb/examples/python/crashlog.py @@ -83,6 +83,7 @@ self.registers = dict() self.reason = None self.queue = None + self.crashed = False self.app_specific_backtrace = app_specific_backtrace def dump(self, prefix): @@ -160,6 +161,9 @@ print() for reg in self.registers.keys(): print(" %-8s = %#16.16x" % (reg, self.registers[reg])) + elif self.crashed: + print() + print("No thread state (register information) available") def add_ident(self, ident): if ident not in self.idents: @@ -505,8 +509,10 @@ thread.reason = json_thread['name'] if json_thread.get('triggered', False): self.crashlog.crashed_thread_idx = idx - thread.registers = self.parse_thread_registers( - json_thread['threadState']) + thread.crashed = True + if 'threadState' in json_thread: + thread.registers = self.parse_thread_registers( + json_thread['threadState']) thread.queue = json_thread.get('queue') self.parse_frames(thread, json_thread.get('frames', [])) self.crashlog.threads.append(thread) diff --git a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/Inputs/no_threadState.ips b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/Inputs/no_threadState.ips new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/Inputs/no_threadState.ips @@ -0,0 +1,104 @@ +{"app_name":"json.test.tmp.out","timestamp":"2021-03-08 13:57:06.00 -0800","app_version":"","slice_uuid":"8f528c10-3e80-3dd6-b0be-5d558f64f7ab","build_version":"","platform":1,"share_with_app_devs":1,"is_first_party":1,"etl_key":"3","bug_type":"309","os_version":"macOS 11.3","incident_id":"FA21DF23-3344-4E45-BF27-4B8E63B7012B","name":"json.test.tmp.out"} +{ + "uptime" : 320000, + "procLaunch" : "2021-03-08 13:56:51.7232 -0800", + "procRole" : "Unspecified", + "version" : 2, + "exception" : { + "type" : "EXC_BAD_ACCESS", + "signal" : "SIGSEGV", + "subtype" : "KERN_INVALID_ADDRESS at 0x0000000000000000" + }, + "userID" : 501, + "modelCode" : "iMacPro1,1", + "coalitionID" : 6086, + "osVersion" : { + "train" : "macOS 11.3", + "build" : "", + "releaseType" : "" + }, + "captureTime" : "2021-03-08 13:56:51.8610 -0800", + "incident" : "FA21DF23-3344-4E45-BF27-4B8E63B7012B", + "pid" : 72932, + "cpuType" : "X86-64", + "procName" : "json.test.tmp.out", + "procPath" : "\/Users\/USER\/*\/json.test.tmp.out", + "parentProc" : "fish", + "parentPid" : 67002, + "coalitionName" : "io.alacritty", + "crashReporterKey" : "DCEF35CB-68D5-F524-FF13-060901F52EA8", + "responsiblePid" : 65465, + "responsibleProc" : "alacritty", + "bridgeVersion" : {"build":"18P4544","train":"5.3"}, + "sip" : "enabled", + "isCorpse" : 1, + "termination" : {"flags":0,"code":11,"namespace":"SIGNAL","indicator":"Segmentation fault: 11","byProc":"exc handler","byPid":72932}, + "asi" : {"dyld":["dyld2 mode"]}, + "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":125361,"task_for_pid":9935},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0}, + "faultingThread" : 0, + "threads" : [ + { + "triggered": true, + "id": 6152004, + "name": "Crashing Thread Name", + "queue": "com.apple.main-thread", + "frames": [ + { + "imageOffset": @foo@, + "sourceLine": 3, + "sourceFile": "test.c", + "symbol": "foo", + "imageIndex": 0, + "symbolLocation": 16 + }, + { + "imageOffset": @bar@, + "sourceLine": 6, + "sourceFile": "test.c", + "symbol": "bar", + "imageIndex": 0, + "symbolLocation": 9 + }, + { + "imageOffset": @main@, + "sourceLine": 8, + "sourceFile": "test.c", + "symbol": "main", + "imageIndex": 0, + "symbolLocation": 20 + }, + { + "imageOffset": 89917, + "symbol": "start", + "symbolLocation": 1, + "imageIndex": 1 + } + ] + } +], + "usedImages" : [ + { + "source" : "P", + "arch" : "x86_64", + "base" : 4355608576, + "size" : 16384, + "uuid" : "@UUID@", + "path" : "@EXEC@", + "name" : "@NAME@" + }, + { + "source" : "P", + "arch" : "x86_64", + "base" : 140733734899712, + "size" : 245760, + "uuid" : "c5caf30b-0617-3b07-88c7-6319cd06f30a", + "path" : "\/usr\/lib\/system\/libdyld.dylib", + "name" : "libdyld.dylib" + } +], + "legacyInfo" : { + "threadTriggered" : { + "queue" : "com.apple.main-thread" + } +} +} diff --git a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no_threadState.test b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no_threadState.test new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no_threadState.test @@ -0,0 +1,11 @@ +# RUN: %clang_host -g %S/Inputs/test.c -o %t.out + +# RUN: cp %S/Inputs/no_threadState.ips %t.crash +# RUN: python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}' --json +# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.crash' 2>&1 | FileCheck %s + +# CHECK: Thread[0] Crashing Thread Name EXC_BAD_ACCESS (SIGSEGV) (KERN_INVALID_ADDRESS at 0x0000000000000000) +# CHECK: [ 0] {{.*}}out`foo + 16 at test.c +# CHECK: [ 1] {{.*}}out`bar + 8 at test.c +# CHECK: [ 2] {{.*}}out`main + 19 at test.c +# CHECK: No thread state (register information) available