nitesh.jain updated this revision to Diff 83012. nitesh.jain added a comment.
Update diff as per suggestion. https://reviews.llvm.org/D27088 Files: include/lldb/API/SBDwarf.h packages/Python/lldbsuite/test/lldbtest.py packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py scripts/lldb.swig
Index: scripts/lldb.swig =================================================================== --- scripts/lldb.swig +++ scripts/lldb.swig @@ -66,6 +66,7 @@ #include "lldb/API/SBCommunication.h" #include "lldb/API/SBCompileUnit.h" #include "lldb/API/SBData.h" +#include "lldb/API/SBDwarf.h" #include "lldb/API/SBDebugger.h" #include "lldb/API/SBDeclaration.h" #include "lldb/API/SBError.h" @@ -133,6 +134,7 @@ %include "lldb/lldb-enumerations.h" %include "lldb/lldb-forward.h" %include "lldb/lldb-types.h" +%include "lldb/API/SBDwarf.h" /* Forward declaration of SB classes. */ %include "lldb/API/SBDefines.h" Index: packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py =================================================================== --- packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py +++ packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py @@ -541,6 +541,10 @@ self.assertIsNotNone(reg_infos) self.assertTrue(len(reg_infos) > 0) + inferior_exe_path = os.path.abspath("a.out") + Target = self.dbg.CreateTarget(inferior_exe_path) + byte_order = Target.GetByteOrder() + # Read value for each register. reg_index = 0 for reg_info in reg_infos: @@ -565,6 +569,9 @@ # Verify the response length. p_response = context.get("p_response") self.assertIsNotNone(p_response) + + if "dynamic_size_dwarf_expr_bytes" in reg_info: + self.updateRegInfoBitsize(reg_info, byte_order) self.assertEqual(len(p_response), 2 * int(reg_info["bitsize"]) / 8) # Increment loop Index: packages/Python/lldbsuite/test/lldbtest.py =================================================================== --- packages/Python/lldbsuite/test/lldbtest.py +++ packages/Python/lldbsuite/test/lldbtest.py @@ -1260,6 +1260,94 @@ return self.lldbArchitecture + def updateRegInfoBitsize(self, reg_info, byte_order): + """ Update the regInfo bit size. """ + + # Evaluate Dwarf Expression + expr_result = self.evaluateDwarfExpression(reg_info["dynamic_size_dwarf_expr_bytes"], + byte_order) + + if expr_result == 0: + reg_info["bitsize"] = 32 + elif expr_result == 1: + reg_info["bitsize"] = 64 + + def evaluateDwarfExpression(self, dwarf_opcode, byte_order): + """Evaluate Dwarf Expression. """ + + dwarf_opcode = [dwarf_opcode[i:i+2] for i in range(0,len(dwarf_opcode),2)] + dwarf_data = [] + for index in range(len(dwarf_opcode)): + + if index < len(dwarf_opcode): + val = int(dwarf_opcode[index], 16) + else: + break + + if val == lldb.DW_OP_regx: + # Read register number + self.assertTrue(len(dwarf_opcode) > (index + 1)) + reg_no = int(dwarf_opcode.pop(index + 1), 16) + + self.reset_test_sequence() + # Read register value + self.test_sequence.add_log_lines( + ["read packet: $p{0:x}#00".format(reg_no), + {"direction": "send", "regex": r"^\$([0-9a-fA-F]+)#", + "capture": {1: "p_response"}}],True) + + Context = self.expect_gdbremote_sequence() + self.assertIsNotNone(Context) + p_response = Context.get("p_response") + self.assertIsNotNone(p_response) + + if byte_order == lldb.eByteOrderLittle: + # In case of little endian + # first decode the HEX ASCII bytes and then reverse it + # to get actual value of SR register + p_response = "".join(reversed([p_response[i:i+2] for i in range(0, + len(p_response),2)])) + # Push register value + dwarf_data.append(int(p_response,16)) + + elif val == lldb.DW_OP_lit1: + # Push literal 1 + dwarf_data.append(1) + + elif val == lldb.DW_OP_lit26: + # Push literal 26 + dwarf_data.append(26) + + elif val == lldb.DW_OP_shl: + # left shift and push the result back + self.assertTrue(len(dwarf_data) > 1) + shift_amount = dwarf_data.pop() + val_to_shift = dwarf_data.pop() + result = val_to_shift << shift_amount + dwarf_data.append(result) + + elif val == lldb.DW_OP_shr: + # Right shift and push the result back + self.assertTrue(len(dwarf_data) > 1) + shift_amount = dwarf_data.pop() + val_to_shift = dwarf_data.pop() + result = val_to_shift >> shift_amount + dwarf_data.append(result) + + elif val == lldb.DW_OP_and: + # And of topmost 2 elements and push the result back + first_ele = dwarf_data.pop() + second_ele = dwarf_data.pop() + result = first_ele & second_ele + dwarf_data.append(result) + + else: + self.assertTrue(False and "Unprocess Dwarf Opcode") + + self.assertTrue(len(dwarf_data) == 1) + expr_result = dwarf_data.pop() + return expr_result + def getCompiler(self): """Returns the compiler in effect the test suite is running with.""" module = builder_module() Index: include/lldb/API/SBDwarf.h =================================================================== --- /dev/null +++ include/lldb/API/SBDwarf.h @@ -0,0 +1,182 @@ +//===-- SBDwarf.h ---------------------------------------------*- C++ -*-===// +//// +//// The LLVM Compiler Infrastructure +//// +//// This file is distributed under the University of Illinois Open Source +//// License. See LICENSE.TXT for details. +//// +////===----------------------------------------------------------------------===// +// + + +#define HANDLE_DW_OP(ID, NAME) DW_OP_##NAME = ID, + +namespace lldb { +enum LocationAtom { + // DWARF Expression operators. + HANDLE_DW_OP(0x03, addr) + HANDLE_DW_OP(0x06, deref) + HANDLE_DW_OP(0x08, const1u) + HANDLE_DW_OP(0x09, const1s) + HANDLE_DW_OP(0x0a, const2u) + HANDLE_DW_OP(0x0b, const2s) + HANDLE_DW_OP(0x0c, const4u) + HANDLE_DW_OP(0x0d, const4s) + HANDLE_DW_OP(0x0e, const8u) + HANDLE_DW_OP(0x0f, const8s) + HANDLE_DW_OP(0x10, constu) + HANDLE_DW_OP(0x11, consts) + HANDLE_DW_OP(0x12, dup) + HANDLE_DW_OP(0x13, drop) + HANDLE_DW_OP(0x14, over) + HANDLE_DW_OP(0x15, pick) + HANDLE_DW_OP(0x16, swap) + HANDLE_DW_OP(0x17, rot) + HANDLE_DW_OP(0x18, xderef) + HANDLE_DW_OP(0x19, abs) + HANDLE_DW_OP(0x1a, and) + HANDLE_DW_OP(0x1b, div) + HANDLE_DW_OP(0x1c, minus) + HANDLE_DW_OP(0x1d, mod) + HANDLE_DW_OP(0x1e, mul) + HANDLE_DW_OP(0x1f, neg) + HANDLE_DW_OP(0x20, not) + HANDLE_DW_OP(0x21, or) + HANDLE_DW_OP(0x22, plus) + HANDLE_DW_OP(0x23, plus_uconst) + HANDLE_DW_OP(0x24, shl) + HANDLE_DW_OP(0x25, shr) + HANDLE_DW_OP(0x26, shra) + HANDLE_DW_OP(0x27, xor) + HANDLE_DW_OP(0x2f, skip) + HANDLE_DW_OP(0x28, bra) + HANDLE_DW_OP(0x29, eq) + HANDLE_DW_OP(0x2a, ge) + HANDLE_DW_OP(0x2b, gt) + HANDLE_DW_OP(0x2c, le) + HANDLE_DW_OP(0x2d, lt) + HANDLE_DW_OP(0x2e, ne) + HANDLE_DW_OP(0x30, lit0) + HANDLE_DW_OP(0x31, lit1) + HANDLE_DW_OP(0x32, lit2) + HANDLE_DW_OP(0x33, lit3) + HANDLE_DW_OP(0x34, lit4) + HANDLE_DW_OP(0x35, lit5) + HANDLE_DW_OP(0x36, lit6) + HANDLE_DW_OP(0x37, lit7) + HANDLE_DW_OP(0x38, lit8) + HANDLE_DW_OP(0x39, lit9) + HANDLE_DW_OP(0x3a, lit10) + HANDLE_DW_OP(0x3b, lit11) + HANDLE_DW_OP(0x3c, lit12) + HANDLE_DW_OP(0x3d, lit13) + HANDLE_DW_OP(0x3e, lit14) + HANDLE_DW_OP(0x3f, lit15) + HANDLE_DW_OP(0x40, lit16) + HANDLE_DW_OP(0x41, lit17) + HANDLE_DW_OP(0x42, lit18) + HANDLE_DW_OP(0x43, lit19) + HANDLE_DW_OP(0x44, lit20) + HANDLE_DW_OP(0x45, lit21) + HANDLE_DW_OP(0x46, lit22) + HANDLE_DW_OP(0x47, lit23) + HANDLE_DW_OP(0x48, lit24) + HANDLE_DW_OP(0x49, lit25) + HANDLE_DW_OP(0x4a, lit26) + HANDLE_DW_OP(0x4b, lit27) + HANDLE_DW_OP(0x4c, lit28) + HANDLE_DW_OP(0x4d, lit29) + HANDLE_DW_OP(0x4e, lit30) + HANDLE_DW_OP(0x4f, lit31) + HANDLE_DW_OP(0x50, reg0) + HANDLE_DW_OP(0x51, reg1) + HANDLE_DW_OP(0x52, reg2) + HANDLE_DW_OP(0x53, reg3) + HANDLE_DW_OP(0x54, reg4) + HANDLE_DW_OP(0x55, reg5) + HANDLE_DW_OP(0x56, reg6) + HANDLE_DW_OP(0x57, reg7) + HANDLE_DW_OP(0x58, reg8) + HANDLE_DW_OP(0x59, reg9) + HANDLE_DW_OP(0x5a, reg10) + HANDLE_DW_OP(0x5b, reg11) + HANDLE_DW_OP(0x5c, reg12) + HANDLE_DW_OP(0x5d, reg13) + HANDLE_DW_OP(0x5e, reg14) + HANDLE_DW_OP(0x5f, reg15) + HANDLE_DW_OP(0x60, reg16) + HANDLE_DW_OP(0x61, reg17) + HANDLE_DW_OP(0x62, reg18) + HANDLE_DW_OP(0x63, reg19) + HANDLE_DW_OP(0x64, reg20) + HANDLE_DW_OP(0x65, reg21) + HANDLE_DW_OP(0x66, reg22) + HANDLE_DW_OP(0x67, reg23) + HANDLE_DW_OP(0x68, reg24) + HANDLE_DW_OP(0x69, reg25) + HANDLE_DW_OP(0x6a, reg26) + HANDLE_DW_OP(0x6b, reg27) + HANDLE_DW_OP(0x6c, reg28) + HANDLE_DW_OP(0x6d, reg29) + HANDLE_DW_OP(0x6e, reg30) + HANDLE_DW_OP(0x6f, reg31) + HANDLE_DW_OP(0x70, breg0) + HANDLE_DW_OP(0x71, breg1) + HANDLE_DW_OP(0x72, breg2) + HANDLE_DW_OP(0x73, breg3) + HANDLE_DW_OP(0x74, breg4) + HANDLE_DW_OP(0x75, breg5) + HANDLE_DW_OP(0x76, breg6) + HANDLE_DW_OP(0x77, breg7) + HANDLE_DW_OP(0x78, breg8) + HANDLE_DW_OP(0x79, breg9) + HANDLE_DW_OP(0x7a, breg10) + HANDLE_DW_OP(0x7b, breg11) + HANDLE_DW_OP(0x7c, breg12) + HANDLE_DW_OP(0x7d, breg13) + HANDLE_DW_OP(0x7e, breg14) + HANDLE_DW_OP(0x7f, breg15) + HANDLE_DW_OP(0x80, breg16) + HANDLE_DW_OP(0x81, breg17) + HANDLE_DW_OP(0x82, breg18) + HANDLE_DW_OP(0x83, breg19) + HANDLE_DW_OP(0x84, breg20) + HANDLE_DW_OP(0x85, breg21) + HANDLE_DW_OP(0x86, breg22) + HANDLE_DW_OP(0x87, breg23) + HANDLE_DW_OP(0x88, breg24) + HANDLE_DW_OP(0x89, breg25) + HANDLE_DW_OP(0x8a, breg26) + HANDLE_DW_OP(0x8b, breg27) + HANDLE_DW_OP(0x8c, breg28) + HANDLE_DW_OP(0x8d, breg29) + HANDLE_DW_OP(0x8e, breg30) + HANDLE_DW_OP(0x8f, breg31) + HANDLE_DW_OP(0x90, regx) + HANDLE_DW_OP(0x91, fbreg) + HANDLE_DW_OP(0x92, bregx) + HANDLE_DW_OP(0x93, piece) + HANDLE_DW_OP(0x94, deref_size) + HANDLE_DW_OP(0x95, xderef_size) + HANDLE_DW_OP(0x96, nop) + HANDLE_DW_OP(0x97, push_object_address) + HANDLE_DW_OP(0x98, call2) + HANDLE_DW_OP(0x99, call4) + HANDLE_DW_OP(0x9a, call_ref) + HANDLE_DW_OP(0x9b, form_tls_address) + HANDLE_DW_OP(0x9c, call_frame_cfa) + HANDLE_DW_OP(0x9d, bit_piece) + HANDLE_DW_OP(0x9e, implicit_value) + HANDLE_DW_OP(0x9f, stack_value) + HANDLE_DW_OP(0xa0, implicit_pointer) + HANDLE_DW_OP(0xa1, addrx) + HANDLE_DW_OP(0xa2, constx) + HANDLE_DW_OP(0xa3, entry_value) + HANDLE_DW_OP(0xa4, const_type) + HANDLE_DW_OP(0xa5, regval_type) + HANDLE_DW_OP(0xa6, deref_type) + HANDLE_DW_OP(0xa7, xderef_type) + HANDLE_DW_OP(0xa8, convert) + HANDLE_DW_OP(0xa9, reinterpret) +}; // enum LocationAtom +} // namespace lldb
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits