102 lines · python
1"""2Test lldb process crash info.3"""4 5import os6 7import lldb8from lldbsuite.test.decorators import *9from lldbsuite.test.lldbtest import *10from lldbsuite.test import lldbutil11from lldbsuite.test import lldbtest12 13 14class PlatformProcessCrashInfoTestCase(TestBase):15 def setUp(self):16 TestBase.setUp(self)17 self.runCmd("settings set auto-confirm true")18 self.source = "main.c"19 self.line = line_number(self.source, "// break here")20 21 def tearDown(self):22 self.runCmd("settings clear auto-confirm")23 TestBase.tearDown(self)24 25 def containsLibmallocError(self, output):26 for error in [27 "pointer being freed was not allocated",28 "not an allocated block",29 ]:30 if error in output:31 return True32 return False33 34 @skipIfAsan # The test process intentionally double-frees.35 @skipUnlessDarwin36 def test_cli(self):37 """Test that `process status --verbose` fetches the extended crash38 information dictionary from the command-line properly."""39 self.build()40 exe = self.getBuildArtifact("a.out")41 self.expect("file " + exe, patterns=["Current executable set to .*a.out"])42 43 self.expect("process launch", patterns=["Process .* launched: .*a.out"])44 45 result = lldb.SBCommandReturnObject()46 self.dbg.GetCommandInterpreter().HandleCommand(47 "process status --verbose", result48 )49 50 self.assertIn("Extended Crash Information", result.GetOutput())51 self.assertIn("Crash-Info Annotations", result.GetOutput())52 self.assertTrue(self.containsLibmallocError(result.GetOutput()))53 54 @skipIfAsan # The test process intentionally hits a memory bug.55 @skipUnlessDarwin56 def test_api(self):57 """Test that lldb can fetch a crashed process' extended crash information58 dictionary from the api properly."""59 self.build()60 target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))61 self.assertTrue(target, VALID_TARGET)62 63 target.LaunchSimple(None, None, os.getcwd())64 65 stream = lldb.SBStream()66 self.assertTrue(stream)67 68 process = target.GetProcess()69 self.assertTrue(process)70 71 crash_info = process.GetExtendedCrashInformation()72 73 error = crash_info.GetAsJSON(stream)74 75 self.assertSuccess(error)76 77 self.assertTrue(crash_info.IsValid())78 79 self.assertTrue(self.containsLibmallocError(stream.GetData()))80 81 # dyld leaves permanent crash_info records when testing on device.82 @skipIfDarwinEmbedded83 def test_on_sane_process(self):84 """Test that lldb doesn't fetch the extended crash information85 dictionary from a 'sane' stopped process."""86 self.build()87 target, _, _, _ = lldbutil.run_to_line_breakpoint(88 self, lldb.SBFileSpec(self.source), self.line89 )90 91 stream = lldb.SBStream()92 self.assertTrue(stream)93 94 process = target.GetProcess()95 self.assertTrue(process)96 97 crash_info = process.GetExtendedCrashInformation()98 99 error = crash_info.GetAsJSON(stream)100 self.assertFalse(error.Success())101 self.assertIn("No structured data.", error.GetCString())102