brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · b308f79 Raw
100 lines · plain
1_T = require('lua_lldb_test').create_test('TestComprehensive')2 3function _T:Test0_CreateTarget()4    self.target = self:create_target()5    assertTrue(self.target:IsValid())6end7 8function _T:Test1_Breakpoint()9    self.main_bp = self.target:BreakpointCreateByName('main', 'a.out')10    self.loop_bp = self.target:BreakpointCreateByLocation('main.c', 28)11    assertTrue(self.main_bp:IsValid() and self.main_bp:GetNumLocations() == 1)12    assertTrue(self.loop_bp:IsValid() and self.loop_bp:GetNumLocations() == 1)13end14 15function _T:Test2_Launch()16    local error = lldb.SBError()17    self.args = { 'arg' }18    self.process = self.target:Launch(19        self.debugger:GetListener(),20        self.args,21        nil,22        nil,23        self.output,24        nil,25        nil,26        0,27        false,28        error29    )30    assertTrue(error:Success())31    assertTrue(self.process:IsValid())32end33 34function _T:Test3_BreakpointFindVariables()35    -- checking "argc" value36    local thread = get_stopped_thread(self.process, lldb.eStopReasonBreakpoint)37    assertNotNil(thread)38    assertTrue(thread:IsValid())39    local frame = thread:GetFrameAtIndex(0)40    assertTrue(frame:IsValid())41    local error = lldb.SBError()42    local var_argc = frame:FindVariable('argc')43    assertTrue(var_argc:IsValid())44    local var_argc_value = var_argc:GetValueAsSigned(error, 0)45    assertTrue(error:Success())46    assertEqual(var_argc_value, 2)47 48    -- checking "inited" value49    local continue = self.process:Continue()50    assertTrue(continue:Success())51    thread = get_stopped_thread(self.process, lldb.eStopReasonBreakpoint)52    assertNotNil(thread)53    assertTrue(thread:IsValid())54    frame = thread:GetFrameAtIndex(0)55    assertTrue(frame:IsValid())56    error = lldb.SBError()57    local var_inited = frame:FindVariable('inited')58    assertTrue(var_inited:IsValid())59    self.var_inited = var_inited60    local var_inited_value = var_inited:GetValueAsUnsigned(error, 0)61    assertTrue(error:Success())62    assertEqual(var_inited_value, 0xDEADBEEF)63end64 65function _T:Test3_RawData()66    local error = lldb.SBError()67    local address = self.var_inited:GetAddress()68    assertTrue(address:IsValid())69    local size = self.var_inited:GetByteSize()70    local raw_data = self.process:ReadMemory(address:GetOffset(), size, error)71    assertTrue(error:Success())72    local data_le = lldb.SBData.CreateDataFromUInt32Array(lldb.eByteOrderLittle, 1, {0xDEADBEEF})73    local data_be = lldb.SBData.CreateDataFromUInt32Array(lldb.eByteOrderBig, 1, {0xDEADBEEF})74    assertTrue(data_le:GetUnsignedInt32(error, 0) == 0xDEADBEEF or data_be:GetUnsignedInt32(error, 0) == 0xDEADBEEF)75    assertTrue(raw_data == "\xEF\xBE\xAD\xDE" or raw_data == "\xDE\xAD\xBE\xEF")76end77 78function _T:Test4_ProcessExit()79    self.loop_bp:SetAutoContinue(true)80    local continue = self.process:Continue()81    assertTrue(continue:Success())82    assertTrue(self.process:GetExitStatus() == 0)83end84 85function _T:Test5_FileOutput()86    local f = io.open(self.output, 'r')87    assertEqual(88        read_file_non_empty_lines(f),89        {90            self.exe,91            table.unpack(self.args),92            'I am a function.',93            'sum = 5050'94        }95    )96    f:close()97end98 99os.exit(_T:run())100