diff options
Diffstat (limited to 'source/Expression')
-rw-r--r-- | source/Expression/DWARFExpression.cpp | 800 | ||||
-rw-r--r-- | source/Expression/DiagnosticManager.cpp | 18 | ||||
-rw-r--r-- | source/Expression/ExpressionVariable.cpp | 18 | ||||
-rw-r--r-- | source/Expression/FunctionCaller.cpp | 42 | ||||
-rw-r--r-- | source/Expression/IRExecutionUnit.cpp | 97 | ||||
-rw-r--r-- | source/Expression/IRInterpreter.cpp | 309 | ||||
-rw-r--r-- | source/Expression/IRMemoryMap.cpp | 64 | ||||
-rw-r--r-- | source/Expression/LLVMUserExpression.cpp | 23 | ||||
-rw-r--r-- | source/Expression/Materializer.cpp | 140 | ||||
-rw-r--r-- | source/Expression/REPL.cpp | 87 | ||||
-rw-r--r-- | source/Expression/UserExpression.cpp | 43 | ||||
-rw-r--r-- | source/Expression/UtilityFunction.cpp | 2 |
12 files changed, 751 insertions, 892 deletions
diff --git a/source/Expression/DWARFExpression.cpp b/source/Expression/DWARFExpression.cpp index a9d365325d9e..3789d9147737 100644 --- a/source/Expression/DWARFExpression.cpp +++ b/source/Expression/DWARFExpression.cpp @@ -33,6 +33,7 @@ #include "lldb/Target/RegisterContext.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/StackID.h" +#include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "Plugins/SymbolFile/DWARF/DWARFUnit.h" @@ -59,12 +60,9 @@ DWARFExpression::DWARFExpression() DWARFExpression::DWARFExpression(lldb::ModuleSP module_sp, const DataExtractor &data, - const DWARFUnit *dwarf_cu, - lldb::offset_t data_offset, - lldb::offset_t data_length) - : m_module_wp(), m_data(data, data_offset, data_length), - m_dwarf_cu(dwarf_cu), m_reg_kind(eRegisterKindDWARF), - m_loclist_slide(LLDB_INVALID_ADDRESS) { + const DWARFUnit *dwarf_cu) + : m_module_wp(), m_data(data), m_dwarf_cu(dwarf_cu), + m_reg_kind(eRegisterKindDWARF), m_loclist_slide(LLDB_INVALID_ADDRESS) { if (module_sp) m_module_wp = module_sp; } @@ -90,387 +88,10 @@ void DWARFExpression::DumpLocation(Stream *s, lldb::offset_t offset, lldb::offset_t length, lldb::DescriptionLevel level, ABI *abi) const { - if (!m_data.ValidOffsetForDataOfSize(offset, length)) - return; - const lldb::offset_t start_offset = offset; - const lldb::offset_t end_offset = offset + length; - while (m_data.ValidOffset(offset) && offset < end_offset) { - const lldb::offset_t op_offset = offset; - const uint8_t op = m_data.GetU8(&offset); - - switch (level) { - default: - break; - - case lldb::eDescriptionLevelBrief: - if (op_offset > start_offset) - s->PutChar(' '); - break; - - case lldb::eDescriptionLevelFull: - case lldb::eDescriptionLevelVerbose: - if (op_offset > start_offset) - s->EOL(); - s->Indent(); - if (level == lldb::eDescriptionLevelFull) - break; - // Fall through for verbose and print offset and DW_OP prefix.. - s->Printf("0x%8.8" PRIx64 ": %s", op_offset, - op >= DW_OP_APPLE_uninit ? "DW_OP_APPLE_" : "DW_OP_"); - break; - } - - switch (op) { - case DW_OP_addr: - *s << "DW_OP_addr(" << m_data.GetAddress(&offset) << ") "; - break; // 0x03 1 address - case DW_OP_deref: - *s << "DW_OP_deref"; - break; // 0x06 - case DW_OP_const1u: - s->Printf("DW_OP_const1u(0x%2.2x)", m_data.GetU8(&offset)); - break; // 0x08 1 1-byte constant - case DW_OP_const1s: - s->Printf("DW_OP_const1s(0x%2.2x)", m_data.GetU8(&offset)); - break; // 0x09 1 1-byte constant - case DW_OP_const2u: - s->Printf("DW_OP_const2u(0x%4.4x)", m_data.GetU16(&offset)); - break; // 0x0a 1 2-byte constant - case DW_OP_const2s: - s->Printf("DW_OP_const2s(0x%4.4x)", m_data.GetU16(&offset)); - break; // 0x0b 1 2-byte constant - case DW_OP_const4u: - s->Printf("DW_OP_const4u(0x%8.8x)", m_data.GetU32(&offset)); - break; // 0x0c 1 4-byte constant - case DW_OP_const4s: - s->Printf("DW_OP_const4s(0x%8.8x)", m_data.GetU32(&offset)); - break; // 0x0d 1 4-byte constant - case DW_OP_const8u: - s->Printf("DW_OP_const8u(0x%16.16" PRIx64 ")", m_data.GetU64(&offset)); - break; // 0x0e 1 8-byte constant - case DW_OP_const8s: - s->Printf("DW_OP_const8s(0x%16.16" PRIx64 ")", m_data.GetU64(&offset)); - break; // 0x0f 1 8-byte constant - case DW_OP_constu: - s->Printf("DW_OP_constu(0x%" PRIx64 ")", m_data.GetULEB128(&offset)); - break; // 0x10 1 ULEB128 constant - case DW_OP_consts: - s->Printf("DW_OP_consts(0x%" PRId64 ")", m_data.GetSLEB128(&offset)); - break; // 0x11 1 SLEB128 constant - case DW_OP_dup: - s->PutCString("DW_OP_dup"); - break; // 0x12 - case DW_OP_drop: - s->PutCString("DW_OP_drop"); - break; // 0x13 - case DW_OP_over: - s->PutCString("DW_OP_over"); - break; // 0x14 - case DW_OP_pick: - s->Printf("DW_OP_pick(0x%2.2x)", m_data.GetU8(&offset)); - break; // 0x15 1 1-byte stack index - case DW_OP_swap: - s->PutCString("DW_OP_swap"); - break; // 0x16 - case DW_OP_rot: - s->PutCString("DW_OP_rot"); - break; // 0x17 - case DW_OP_xderef: - s->PutCString("DW_OP_xderef"); - break; // 0x18 - case DW_OP_abs: - s->PutCString("DW_OP_abs"); - break; // 0x19 - case DW_OP_and: - s->PutCString("DW_OP_and"); - break; // 0x1a - case DW_OP_div: - s->PutCString("DW_OP_div"); - break; // 0x1b - case DW_OP_minus: - s->PutCString("DW_OP_minus"); - break; // 0x1c - case DW_OP_mod: - s->PutCString("DW_OP_mod"); - break; // 0x1d - case DW_OP_mul: - s->PutCString("DW_OP_mul"); - break; // 0x1e - case DW_OP_neg: - s->PutCString("DW_OP_neg"); - break; // 0x1f - case DW_OP_not: - s->PutCString("DW_OP_not"); - break; // 0x20 - case DW_OP_or: - s->PutCString("DW_OP_or"); - break; // 0x21 - case DW_OP_plus: - s->PutCString("DW_OP_plus"); - break; // 0x22 - case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend - s->Printf("DW_OP_plus_uconst(0x%" PRIx64 ")", - m_data.GetULEB128(&offset)); - break; - - case DW_OP_shl: - s->PutCString("DW_OP_shl"); - break; // 0x24 - case DW_OP_shr: - s->PutCString("DW_OP_shr"); - break; // 0x25 - case DW_OP_shra: - s->PutCString("DW_OP_shra"); - break; // 0x26 - case DW_OP_xor: - s->PutCString("DW_OP_xor"); - break; // 0x27 - case DW_OP_skip: - s->Printf("DW_OP_skip(0x%4.4x)", m_data.GetU16(&offset)); - break; // 0x2f 1 signed 2-byte constant - case DW_OP_bra: - s->Printf("DW_OP_bra(0x%4.4x)", m_data.GetU16(&offset)); - break; // 0x28 1 signed 2-byte constant - case DW_OP_eq: - s->PutCString("DW_OP_eq"); - break; // 0x29 - case DW_OP_ge: - s->PutCString("DW_OP_ge"); - break; // 0x2a - case DW_OP_gt: - s->PutCString("DW_OP_gt"); - break; // 0x2b - case DW_OP_le: - s->PutCString("DW_OP_le"); - break; // 0x2c - case DW_OP_lt: - s->PutCString("DW_OP_lt"); - break; // 0x2d - case DW_OP_ne: - s->PutCString("DW_OP_ne"); - break; // 0x2e - - case DW_OP_lit0: // 0x30 - case DW_OP_lit1: // 0x31 - case DW_OP_lit2: // 0x32 - case DW_OP_lit3: // 0x33 - case DW_OP_lit4: // 0x34 - case DW_OP_lit5: // 0x35 - case DW_OP_lit6: // 0x36 - case DW_OP_lit7: // 0x37 - case DW_OP_lit8: // 0x38 - case DW_OP_lit9: // 0x39 - case DW_OP_lit10: // 0x3A - case DW_OP_lit11: // 0x3B - case DW_OP_lit12: // 0x3C - case DW_OP_lit13: // 0x3D - case DW_OP_lit14: // 0x3E - case DW_OP_lit15: // 0x3F - case DW_OP_lit16: // 0x40 - case DW_OP_lit17: // 0x41 - case DW_OP_lit18: // 0x42 - case DW_OP_lit19: // 0x43 - case DW_OP_lit20: // 0x44 - case DW_OP_lit21: // 0x45 - case DW_OP_lit22: // 0x46 - case DW_OP_lit23: // 0x47 - case DW_OP_lit24: // 0x48 - case DW_OP_lit25: // 0x49 - case DW_OP_lit26: // 0x4A - case DW_OP_lit27: // 0x4B - case DW_OP_lit28: // 0x4C - case DW_OP_lit29: // 0x4D - case DW_OP_lit30: // 0x4E - case DW_OP_lit31: - s->Printf("DW_OP_lit%i", op - DW_OP_lit0); - break; // 0x4f - - case DW_OP_reg0: // 0x50 - case DW_OP_reg1: // 0x51 - case DW_OP_reg2: // 0x52 - case DW_OP_reg3: // 0x53 - case DW_OP_reg4: // 0x54 - case DW_OP_reg5: // 0x55 - case DW_OP_reg6: // 0x56 - case DW_OP_reg7: // 0x57 - case DW_OP_reg8: // 0x58 - case DW_OP_reg9: // 0x59 - case DW_OP_reg10: // 0x5A - case DW_OP_reg11: // 0x5B - case DW_OP_reg12: // 0x5C - case DW_OP_reg13: // 0x5D - case DW_OP_reg14: // 0x5E - case DW_OP_reg15: // 0x5F - case DW_OP_reg16: // 0x60 - case DW_OP_reg17: // 0x61 - case DW_OP_reg18: // 0x62 - case DW_OP_reg19: // 0x63 - case DW_OP_reg20: // 0x64 - case DW_OP_reg21: // 0x65 - case DW_OP_reg22: // 0x66 - case DW_OP_reg23: // 0x67 - case DW_OP_reg24: // 0x68 - case DW_OP_reg25: // 0x69 - case DW_OP_reg26: // 0x6A - case DW_OP_reg27: // 0x6B - case DW_OP_reg28: // 0x6C - case DW_OP_reg29: // 0x6D - case DW_OP_reg30: // 0x6E - case DW_OP_reg31: // 0x6F - { - uint32_t reg_num = op - DW_OP_reg0; - if (abi) { - RegisterInfo reg_info; - if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) { - if (reg_info.name) { - s->PutCString(reg_info.name); - break; - } else if (reg_info.alt_name) { - s->PutCString(reg_info.alt_name); - break; - } - } - } - s->Printf("DW_OP_reg%u", reg_num); - break; - } break; - - case DW_OP_breg0: - case DW_OP_breg1: - case DW_OP_breg2: - case DW_OP_breg3: - case DW_OP_breg4: - case DW_OP_breg5: - case DW_OP_breg6: - case DW_OP_breg7: - case DW_OP_breg8: - case DW_OP_breg9: - case DW_OP_breg10: - case DW_OP_breg11: - case DW_OP_breg12: - case DW_OP_breg13: - case DW_OP_breg14: - case DW_OP_breg15: - case DW_OP_breg16: - case DW_OP_breg17: - case DW_OP_breg18: - case DW_OP_breg19: - case DW_OP_breg20: - case DW_OP_breg21: - case DW_OP_breg22: - case DW_OP_breg23: - case DW_OP_breg24: - case DW_OP_breg25: - case DW_OP_breg26: - case DW_OP_breg27: - case DW_OP_breg28: - case DW_OP_breg29: - case DW_OP_breg30: - case DW_OP_breg31: { - uint32_t reg_num = op - DW_OP_breg0; - int64_t reg_offset = m_data.GetSLEB128(&offset); - if (abi) { - RegisterInfo reg_info; - if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) { - if (reg_info.name) { - s->Printf("[%s%+" PRIi64 "]", reg_info.name, reg_offset); - break; - } else if (reg_info.alt_name) { - s->Printf("[%s%+" PRIi64 "]", reg_info.alt_name, reg_offset); - break; - } - } - } - s->Printf("DW_OP_breg%i(0x%" PRIx64 ")", reg_num, reg_offset); - } break; - - case DW_OP_regx: // 0x90 1 ULEB128 register - { - uint32_t reg_num = m_data.GetULEB128(&offset); - if (abi) { - RegisterInfo reg_info; - if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) { - if (reg_info.name) { - s->PutCString(reg_info.name); - break; - } else if (reg_info.alt_name) { - s->PutCString(reg_info.alt_name); - break; - } - } - } - s->Printf("DW_OP_regx(%" PRIu32 ")", reg_num); - break; - } break; - case DW_OP_fbreg: // 0x91 1 SLEB128 offset - s->Printf("DW_OP_fbreg(%" PRIi64 ")", m_data.GetSLEB128(&offset)); - break; - case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset - { - uint32_t reg_num = m_data.GetULEB128(&offset); - int64_t reg_offset = m_data.GetSLEB128(&offset); - if (abi) { - RegisterInfo reg_info; - if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) { - if (reg_info.name) { - s->Printf("[%s%+" PRIi64 "]", reg_info.name, reg_offset); - break; - } else if (reg_info.alt_name) { - s->Printf("[%s%+" PRIi64 "]", reg_info.alt_name, reg_offset); - break; - } - } - } - s->Printf("DW_OP_bregx(reg=%" PRIu32 ",offset=%" PRIi64 ")", reg_num, - reg_offset); - } break; - case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed - s->Printf("DW_OP_piece(0x%" PRIx64 ")", m_data.GetULEB128(&offset)); - break; - case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved - s->Printf("DW_OP_deref_size(0x%2.2x)", m_data.GetU8(&offset)); - break; - case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved - s->Printf("DW_OP_xderef_size(0x%2.2x)", m_data.GetU8(&offset)); - break; - case DW_OP_nop: - s->PutCString("DW_OP_nop"); - break; // 0x96 - case DW_OP_push_object_address: - s->PutCString("DW_OP_push_object_address"); - break; // 0x97 DWARF3 - case DW_OP_call2: // 0x98 DWARF3 1 2-byte offset of DIE - s->Printf("DW_OP_call2(0x%4.4x)", m_data.GetU16(&offset)); - break; - case DW_OP_call4: // 0x99 DWARF3 1 4-byte offset of DIE - s->Printf("DW_OP_call4(0x%8.8x)", m_data.GetU32(&offset)); - break; - case DW_OP_call_ref: // 0x9a DWARF3 1 4- or 8-byte offset of DIE - s->Printf("DW_OP_call_ref(0x%8.8" PRIx64 ")", m_data.GetAddress(&offset)); - break; - case DW_OP_form_tls_address: - s->PutCString("DW_OP_form_tls_address"); // 0x9b - break; - case DW_OP_GNU_addr_index: // 0xfb - s->Printf("DW_OP_GNU_addr_index(0x%" PRIx64 ")", - m_data.GetULEB128(&offset)); - break; - case DW_OP_addrx: - s->Printf("DW_OP_addrx(0x%" PRIx64 ")", - m_data.GetULEB128(&offset)); - break; - case DW_OP_GNU_const_index: // 0xfc - s->Printf("DW_OP_GNU_const_index(0x%" PRIx64 ")", - m_data.GetULEB128(&offset)); - break; - case DW_OP_GNU_push_tls_address: - s->PutCString("DW_OP_GNU_push_tls_address"); // 0xe0 - break; - case DW_OP_APPLE_uninit: - s->PutCString("DW_OP_APPLE_uninit"); // 0xF0 - break; - } - } + llvm::DWARFExpression(DataExtractor(m_data, offset, length).GetAsLLVM(), + llvm::dwarf::DWARF_VERSION, m_data.GetAddressByteSize()) + .print(s->AsRawOstream(), abi ? &abi->GetMCRegisterInfo() : nullptr, + nullptr); } void DWARFExpression::SetLocationListSlide(addr_t slide) { @@ -583,6 +204,8 @@ static bool ReadRegisterValueAsScalar(RegisterContext *reg_ctx, return false; } +/// Return the length in bytes of the set of operands for \p op. No guarantees +/// are made on the state of \p data after this call. static offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) { @@ -779,6 +402,12 @@ static offset_t GetOpcodeDataSize(const DataExtractor &data, return offset - data_offset; } + case DW_OP_entry_value: // 0xa3 ULEB128 size + variable-length block + { + uint64_t subexpr_len = data.GetULEB128(&offset); + return (offset - data_offset) + subexpr_len; + } + default: break; } @@ -1007,6 +636,11 @@ bool DWARFExpression::LocationListContainsAddress( if (lo_pc == 0 && hi_pc == 0) break; + if ((m_data.GetAddressByteSize() == 4 && (lo_pc == UINT32_MAX)) || + (m_data.GetAddressByteSize() == 8 && (lo_pc == UINT64_MAX))) { + loclist_base_addr = hi_pc + m_loclist_slide; + continue; + } lo_pc += loclist_base_addr - m_loclist_slide; hi_pc += loclist_base_addr - m_loclist_slide; @@ -1042,6 +676,12 @@ bool DWARFExpression::GetLocation(addr_t base_addr, addr_t pc, if (lo_pc == 0 && hi_pc == 0) break; + if ((m_data.GetAddressByteSize() == 4 && (lo_pc == UINT32_MAX)) || + (m_data.GetAddressByteSize() == 8 && (lo_pc == UINT64_MAX))) { + curr_base_addr = hi_pc + m_loclist_slide; + continue; + } + lo_pc += curr_base_addr - m_loclist_slide; hi_pc += curr_base_addr - m_loclist_slide; @@ -1074,6 +714,216 @@ bool DWARFExpression::DumpLocationForAddress(Stream *s, return false; } +static bool Evaluate_DW_OP_entry_value(std::vector<Value> &stack, + ExecutionContext *exe_ctx, + RegisterContext *reg_ctx, + const DataExtractor &opcodes, + lldb::offset_t &opcode_offset, + Status *error_ptr, Log *log) { + // DW_OP_entry_value(sub-expr) describes the location a variable had upon + // function entry: this variable location is presumed to be optimized out at + // the current PC value. The caller of the function may have call site + // information that describes an alternate location for the variable (e.g. a + // constant literal, or a spilled stack value) in the parent frame. + // + // Example (this is pseudo-code & pseudo-DWARF, but hopefully illustrative): + // + // void child(int &sink, int x) { + // ... + // /* "x" gets optimized out. */ + // + // /* The location of "x" here is: DW_OP_entry_value($reg2). */ + // ++sink; + // } + // + // void parent() { + // int sink; + // + // /* + // * The callsite information emitted here is: + // * + // * DW_TAG_call_site + // * DW_AT_return_pc ... (for "child(sink, 123);") + // * DW_TAG_call_site_parameter (for "sink") + // * DW_AT_location ($reg1) + // * DW_AT_call_value ($SP - 8) + // * DW_TAG_call_site_parameter (for "x") + // * DW_AT_location ($reg2) + // * DW_AT_call_value ($literal 123) + // * + // * DW_TAG_call_site + // * DW_AT_return_pc ... (for "child(sink, 456);") + // * ... + // */ + // child(sink, 123); + // child(sink, 456); + // } + // + // When the program stops at "++sink" within `child`, the debugger determines + // the call site by analyzing the return address. Once the call site is found, + // the debugger determines which parameter is referenced by DW_OP_entry_value + // and evaluates the corresponding location for that parameter in `parent`. + + // 1. Find the function which pushed the current frame onto the stack. + if ((!exe_ctx || !exe_ctx->HasTargetScope()) || !reg_ctx) { + LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no exe/reg context"); + return false; + } + + StackFrame *current_frame = exe_ctx->GetFramePtr(); + Thread *thread = exe_ctx->GetThreadPtr(); + if (!current_frame || !thread) { + LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no current frame/thread"); + return false; + } + + Target &target = exe_ctx->GetTargetRef(); + StackFrameSP parent_frame = nullptr; + addr_t return_pc = LLDB_INVALID_ADDRESS; + uint32_t current_frame_idx = current_frame->GetFrameIndex(); + uint32_t num_frames = thread->GetStackFrameCount(); + for (uint32_t parent_frame_idx = current_frame_idx + 1; + parent_frame_idx < num_frames; ++parent_frame_idx) { + parent_frame = thread->GetStackFrameAtIndex(parent_frame_idx); + // Require a valid sequence of frames. + if (!parent_frame) + break; + + // Record the first valid return address, even if this is an inlined frame, + // in order to look up the associated call edge in the first non-inlined + // parent frame. + if (return_pc == LLDB_INVALID_ADDRESS) { + return_pc = parent_frame->GetFrameCodeAddress().GetLoadAddress(&target); + LLDB_LOG(log, + "Evaluate_DW_OP_entry_value: immediate ancestor with pc = {0:x}", + return_pc); + } + + // If we've found an inlined frame, skip it (these have no call site + // parameters). + if (parent_frame->IsInlined()) + continue; + + // We've found the first non-inlined parent frame. + break; + } + if (!parent_frame || !parent_frame->GetRegisterContext()) { + LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no parent frame with reg ctx"); + return false; + } + + Function *parent_func = + parent_frame->GetSymbolContext(eSymbolContextFunction).function; + if (!parent_func) { + LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no parent function"); + return false; + } + + // 2. Find the call edge in the parent function responsible for creating the + // current activation. + Function *current_func = + current_frame->GetSymbolContext(eSymbolContextFunction).function; + if (!current_func) { + LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no current function"); + return false; + } + + CallEdge *call_edge = nullptr; + ModuleList &modlist = target.GetImages(); + if (!parent_frame->IsArtificial()) { + // If the parent frame is not artificial, the current activation may be + // produced by an ambiguous tail call. In this case, refuse to proceed. + call_edge = parent_func->GetCallEdgeForReturnAddress(return_pc, target); + if (!call_edge) { + LLDB_LOG(log, + "Evaluate_DW_OP_entry_value: no call edge for retn-pc = {0:x} " + "in parent frame {1}", + return_pc, parent_func->GetName()); + return false; + } + Function *callee_func = call_edge->GetCallee(modlist); + if (callee_func != current_func) { + LLDB_LOG(log, "Evaluate_DW_OP_entry_value: ambiguous call sequence, " + "can't find real parent frame"); + return false; + } + } else { + // The StackFrameList solver machinery has deduced that an unambiguous tail + // call sequence that produced the current activation. The first edge in + // the parent that points to the current function must be valid. + for (CallEdge &edge : parent_func->GetTailCallingEdges()) { + if (edge.GetCallee(modlist) == current_func) { + call_edge = &edge; + break; + } + } + } + if (!call_edge) { + LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no unambiguous edge from parent " + "to current function"); + return false; + } + + // 3. Attempt to locate the DW_OP_entry_value expression in the set of + // available call site parameters. If found, evaluate the corresponding + // parameter in the context of the parent frame. + const uint32_t subexpr_len = opcodes.GetULEB128(&opcode_offset); + const void *subexpr_data = opcodes.GetData(&opcode_offset, subexpr_len); + if (!subexpr_data) { + LLDB_LOG(log, "Evaluate_DW_OP_entry_value: subexpr could not be read"); + return false; + } + + const CallSiteParameter *matched_param = nullptr; + for (const CallSiteParameter ¶m : call_edge->GetCallSiteParameters()) { + DataExtractor param_subexpr_extractor; + if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor)) + continue; + lldb::offset_t param_subexpr_offset = 0; + const void *param_subexpr_data = + param_subexpr_extractor.GetData(¶m_subexpr_offset, subexpr_len); + if (!param_subexpr_data || + param_subexpr_extractor.BytesLeft(param_subexpr_offset) != 0) + continue; + + // At this point, the DW_OP_entry_value sub-expression and the callee-side + // expression in the call site parameter are known to have the same length. + // Check whether they are equal. + // + // Note that an equality check is sufficient: the contents of the + // DW_OP_entry_value subexpression are only used to identify the right call + // site parameter in the parent, and do not require any special handling. + if (memcmp(subexpr_data, param_subexpr_data, subexpr_len) == 0) { + matched_param = ¶m; + break; + } + } + if (!matched_param) { + LLDB_LOG(log, + "Evaluate_DW_OP_entry_value: no matching call site param found"); + return false; + } + + // TODO: Add support for DW_OP_push_object_address within a DW_OP_entry_value + // subexpresion whenever llvm does. + Value result; + ExecutionContext parent_exe_ctx = *exe_ctx; + parent_exe_ctx.SetFrameSP(parent_frame); + const DWARFExpression ¶m_expr = matched_param->LocationInCaller; + if (!param_expr.Evaluate(&parent_exe_ctx, + parent_frame->GetRegisterContext().get(), + /*loclist_base_addr=*/LLDB_INVALID_ADDRESS, + /*initial_value_ptr=*/nullptr, + /*object_address_ptr=*/nullptr, result, error_ptr)) { + LLDB_LOG(log, + "Evaluate_DW_OP_entry_value: call site param evaluation failed"); + return false; + } + + stack.push_back(result); + return true; +} + bool DWARFExpression::Evaluate(ExecutionContextScope *exe_scope, lldb::addr_t loclist_base_load_addr, const Value *initial_value_ptr, @@ -1128,6 +978,13 @@ bool DWARFExpression::Evaluate(ExecutionContext *exe_ctx, if (lo_pc == 0 && hi_pc == 0) break; + if ((m_data.GetAddressByteSize() == 4 && + (lo_pc == UINT32_MAX)) || + (m_data.GetAddressByteSize() == 8 && + (lo_pc == UINT64_MAX))) { + curr_loclist_base_load_addr = hi_pc + m_loclist_slide; + continue; + } lo_pc += curr_loclist_base_load_addr - m_loclist_slide; hi_pc += curr_loclist_base_load_addr - m_loclist_slide; @@ -1135,9 +992,9 @@ bool DWARFExpression::Evaluate(ExecutionContext *exe_ctx, if (length > 0 && lo_pc <= pc && pc < hi_pc) { return DWARFExpression::Evaluate( - exe_ctx, reg_ctx, module_sp, m_data, m_dwarf_cu, offset, length, - m_reg_kind, initial_value_ptr, object_address_ptr, result, - error_ptr); + exe_ctx, reg_ctx, module_sp, + DataExtractor(m_data, offset, length), m_dwarf_cu, m_reg_kind, + initial_value_ptr, object_address_ptr, result, error_ptr); } offset += length; } @@ -1148,20 +1005,19 @@ bool DWARFExpression::Evaluate(ExecutionContext *exe_ctx, } // Not a location list, just a single expression. - return DWARFExpression::Evaluate( - exe_ctx, reg_ctx, module_sp, m_data, m_dwarf_cu, 0, m_data.GetByteSize(), - m_reg_kind, initial_value_ptr, object_address_ptr, result, error_ptr); + return DWARFExpression::Evaluate(exe_ctx, reg_ctx, module_sp, m_data, + m_dwarf_cu, m_reg_kind, initial_value_ptr, + object_address_ptr, result, error_ptr); } bool DWARFExpression::Evaluate( ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, - const DWARFUnit *dwarf_cu, const lldb::offset_t opcodes_offset, - const lldb::offset_t opcodes_length, const lldb::RegisterKind reg_kind, + const DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_kind, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, Status *error_ptr) { - if (opcodes_length == 0) { + if (opcodes.GetByteSize() == 0) { if (error_ptr) error_ptr->SetErrorString( "no location, value may have been optimized out"); @@ -1182,8 +1038,7 @@ bool DWARFExpression::Evaluate( if (initial_value_ptr) stack.push_back(*initial_value_ptr); - lldb::offset_t offset = opcodes_offset; - const lldb::offset_t end_offset = opcodes_offset + opcodes_length; + lldb::offset_t offset = 0; Value tmp; uint32_t reg_num; @@ -1191,30 +1046,24 @@ bool DWARFExpression::Evaluate( uint64_t op_piece_offset = 0; Value pieces; // Used for DW_OP_piece - // Make sure all of the data is available in opcodes. - if (!opcodes.ValidOffsetForDataOfSize(opcodes_offset, opcodes_length)) { - if (error_ptr) - error_ptr->SetErrorString( - "invalid offset and/or length for opcodes buffer."); - return false; - } Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); - while (opcodes.ValidOffset(offset) && offset < end_offset) { + while (opcodes.ValidOffset(offset)) { const lldb::offset_t op_offset = offset; const uint8_t op = opcodes.GetU8(&offset); if (log && log->GetVerbose()) { size_t count = stack.size(); - log->Printf("Stack before operation has %" PRIu64 " values:", - (uint64_t)count); + LLDB_LOGF(log, "Stack before operation has %" PRIu64 " values:", + (uint64_t)count); for (size_t i = 0; i < count; ++i) { StreamString new_value; new_value.Printf("[%" PRIu64 "]", (uint64_t)i); stack[i].Dump(&new_value); - log->Printf(" %s", new_value.GetData()); + LLDB_LOGF(log, " %s", new_value.GetData()); } - log->Printf("0x%8.8" PRIx64 ": %s", op_offset, DW_OP_value_to_name(op)); + LLDB_LOGF(log, "0x%8.8" PRIx64 ": %s", op_offset, + DW_OP_value_to_name(op)); } switch (op) { @@ -1945,7 +1794,7 @@ bool DWARFExpression::Evaluate( case DW_OP_skip: { int16_t skip_offset = (int16_t)opcodes.GetU16(&offset); lldb::offset_t new_offset = offset + skip_offset; - if (new_offset >= opcodes_offset && new_offset < end_offset) + if (opcodes.ValidOffset(new_offset)) offset = new_offset; else { if (error_ptr) @@ -1974,7 +1823,7 @@ bool DWARFExpression::Evaluate( Scalar zero(0); if (tmp.ResolveValue(exe_ctx) != zero) { lldb::offset_t new_offset = offset + bra_offset; - if (new_offset >= opcodes_offset && new_offset < end_offset) + if (opcodes.ValidOffset(new_offset)) offset = new_offset; else { if (error_ptr) @@ -2570,6 +2419,83 @@ bool DWARFExpression::Evaluate( stack.back().SetValueType(Value::eValueTypeScalar); break; + // OPCODE: DW_OP_convert + // OPERANDS: 1 + // A ULEB128 that is either a DIE offset of a + // DW_TAG_base_type or 0 for the generic (pointer-sized) type. + // + // DESCRIPTION: Pop the top stack element, convert it to a + // different type, and push the result. + case DW_OP_convert: { + if (stack.size() < 1) { + if (error_ptr) + error_ptr->SetErrorString( + "Expression stack needs at least 1 item for DW_OP_convert."); + return false; + } + const uint64_t die_offset = opcodes.GetULEB128(&offset); + Scalar::Type type = Scalar::e_void; + uint64_t bit_size; + if (die_offset == 0) { + // The generic type has the size of an address on the target + // machine and an unspecified signedness. Scalar has no + // "unspecified signedness", so we use unsigned types. + if (!module_sp) { + if (error_ptr) + error_ptr->SetErrorString("No module"); + return false; + } + bit_size = module_sp->GetArchitecture().GetAddressByteSize() * 8; + if (!bit_size) { + if (error_ptr) + error_ptr->SetErrorString("unspecified architecture"); + return false; + } + type = Scalar::GetBestTypeForBitSize(bit_size, false); + } else { + // Retrieve the type DIE that the value is being converted to. + // FIXME: the constness has annoying ripple effects. + DWARFDIE die = const_cast<DWARFUnit *>(dwarf_cu)->GetDIE(die_offset); + if (!die) { + if (error_ptr) + error_ptr->SetErrorString("Cannot resolve DW_OP_convert type DIE"); + return false; + } + uint64_t encoding = + die.GetAttributeValueAsUnsigned(DW_AT_encoding, DW_ATE_hi_user); + bit_size = die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8; + if (!bit_size) + bit_size = die.GetAttributeValueAsUnsigned(DW_AT_bit_size, 0); + if (!bit_size) { + if (error_ptr) + error_ptr->SetErrorString("Unsupported type size in DW_OP_convert"); + return false; + } + switch (encoding) { + case DW_ATE_signed: + case DW_ATE_signed_char: + type = Scalar::GetBestTypeForBitSize(bit_size, true); + break; + case DW_ATE_unsigned: + case DW_ATE_unsigned_char: + type = Scalar::GetBestTypeForBitSize(bit_size, false); + break; + default: + if (error_ptr) + error_ptr->SetErrorString("Unsupported encoding in DW_OP_convert"); + return false; + } + } + if (type == Scalar::e_void) { + if (error_ptr) + error_ptr->SetErrorString("Unsupported pointer size"); + return false; + } + Scalar &top = stack.back().ResolveValue(exe_ctx); + top.TruncOrExtendTo(type, bit_size); + break; + } + // OPCODE: DW_OP_call_frame_cfa // OPERANDS: None // DESCRIPTION: Specifies a DWARF expression that pushes the value of @@ -2685,10 +2611,19 @@ bool DWARFExpression::Evaluate( stack.push_back(Scalar(value)); } break; - default: - if (log) - log->Printf("Unhandled opcode %s in DWARFExpression.", + case DW_OP_entry_value: { + if (!Evaluate_DW_OP_entry_value(stack, exe_ctx, reg_ctx, opcodes, offset, + error_ptr, log)) { + LLDB_ERRORF(error_ptr, "Could not evaluate %s.", DW_OP_value_to_name(op)); + return false; + } + break; + } + + default: + LLDB_LOGF(log, "Unhandled opcode %s in DWARFExpression.", + DW_OP_value_to_name(op)); break; } } @@ -2706,13 +2641,13 @@ bool DWARFExpression::Evaluate( } else { if (log && log->GetVerbose()) { size_t count = stack.size(); - log->Printf("Stack after operation has %" PRIu64 " values:", - (uint64_t)count); + LLDB_LOGF(log, "Stack after operation has %" PRIu64 " values:", + (uint64_t)count); for (size_t i = 0; i < count; ++i) { StreamString new_value; new_value.Printf("[%" PRIu64 "]", (uint64_t)i); stack[i].Dump(&new_value); - log->Printf(" %s", new_value.GetData()); + LLDB_LOGF(log, " %s", new_value.GetData()); } } result = stack.back(); @@ -2720,29 +2655,6 @@ bool DWARFExpression::Evaluate( return true; // Return true on success } -size_t DWARFExpression::LocationListSize(const DWARFUnit *dwarf_cu, - const DataExtractor &debug_loc_data, - lldb::offset_t offset) { - const lldb::offset_t debug_loc_offset = offset; - while (debug_loc_data.ValidOffset(offset)) { - lldb::addr_t start_addr = LLDB_INVALID_ADDRESS; - lldb::addr_t end_addr = LLDB_INVALID_ADDRESS; - if (!AddressRangeForLocationListEntry(dwarf_cu, debug_loc_data, &offset, - start_addr, end_addr)) - break; - - if (start_addr == 0 && end_addr == 0) - break; - - uint16_t loc_length = debug_loc_data.GetU16(&offset); - offset += loc_length; - } - - if (offset > debug_loc_offset) - return offset - debug_loc_offset; - return 0; -} - bool DWARFExpression::AddressRangeForLocationListEntry( const DWARFUnit *dwarf_cu, const DataExtractor &debug_loc_data, lldb::offset_t *offset_ptr, lldb::addr_t &low_pc, lldb::addr_t &high_pc) { @@ -2823,6 +2735,11 @@ static bool print_dwarf_exp_op(Stream &s, const DataExtractor &data, s.Printf("%" PRIu64 " %" PRIi64, uint, sint); return true; } + if (opcode_class == DRC_TWOOPERANDS && opcode == DW_OP_entry_value) { + uint = data.GetULEB128(offset_ptr); + s.Printf("%" PRIu64 " ", uint); + return true; + } if (opcode_class != DRC_ONEOPERAND) { s.Printf("UNKNOWN OP %u", opcode); return false; @@ -2923,6 +2840,7 @@ static bool print_dwarf_exp_op(Stream &s, const DataExtractor &data, case DW_OP_regx: case DW_OP_GNU_addr_index: case DW_OP_GNU_const_index: + case DW_OP_entry_value: size = 128; break; default: diff --git a/source/Expression/DiagnosticManager.cpp b/source/Expression/DiagnosticManager.cpp index 53d85f8a6d54..48eba3586d30 100644 --- a/source/Expression/DiagnosticManager.cpp +++ b/source/Expression/DiagnosticManager.cpp @@ -47,7 +47,7 @@ static const char *StringForSeverity(DiagnosticSeverity severity) { std::string DiagnosticManager::GetString(char separator) { std::string ret; - for (const Diagnostic *diagnostic : Diagnostics()) { + for (const auto &diagnostic : Diagnostics()) { ret.append(StringForSeverity(diagnostic->GetSeverity())); ret.append(diagnostic->GetMessage()); ret.push_back(separator); @@ -70,19 +70,9 @@ size_t DiagnosticManager::Printf(DiagnosticSeverity severity, return result; } -size_t DiagnosticManager::PutString(DiagnosticSeverity severity, - llvm::StringRef str) { +void DiagnosticManager::PutString(DiagnosticSeverity severity, + llvm::StringRef str) { if (str.empty()) - return 0; + return; AddDiagnostic(str, severity, eDiagnosticOriginLLDB); - return str.size(); -} - -void DiagnosticManager::CopyDiagnostics(DiagnosticManager &otherDiagnostics) { - for (const DiagnosticList::value_type &other_diagnostic: - otherDiagnostics.Diagnostics()) { - AddDiagnostic( - other_diagnostic->GetMessage(), other_diagnostic->GetSeverity(), - other_diagnostic->getKind(), other_diagnostic->GetCompilerID()); - } } diff --git a/source/Expression/ExpressionVariable.cpp b/source/Expression/ExpressionVariable.cpp index 97305dcf5a02..ed8da0ad8675 100644 --- a/source/Expression/ExpressionVariable.cpp +++ b/source/Expression/ExpressionVariable.cpp @@ -45,8 +45,7 @@ void PersistentExpressionState::RegisterExecutionUnit( m_execution_units.insert(execution_unit_sp); - if (log) - log->Printf("Registering JITted Functions:\n"); + LLDB_LOGF(log, "Registering JITted Functions:\n"); for (const IRExecutionUnit::JittedFunction &jitted_function : execution_unit_sp->GetJittedFunctions()) { @@ -55,15 +54,13 @@ void PersistentExpressionState::RegisterExecutionUnit( jitted_function.m_remote_addr != LLDB_INVALID_ADDRESS) { m_symbol_map[jitted_function.m_name.GetCString()] = jitted_function.m_remote_addr; - if (log) - log->Printf(" Function: %s at 0x%" PRIx64 ".", - jitted_function.m_name.GetCString(), - jitted_function.m_remote_addr); + LLDB_LOGF(log, " Function: %s at 0x%" PRIx64 ".", + jitted_function.m_name.GetCString(), + jitted_function.m_remote_addr); } } - if (log) - log->Printf("Registering JIIted Symbols:\n"); + LLDB_LOGF(log, "Registering JIIted Symbols:\n"); for (const IRExecutionUnit::JittedGlobalVariable &global_var : execution_unit_sp->GetJittedGlobalVariables()) { @@ -74,9 +71,8 @@ void PersistentExpressionState::RegisterExecutionUnit( Mangled mangler(global_var.m_name); mangler.GetDemangledName(lldb::eLanguageTypeUnknown); m_symbol_map[global_var.m_name.GetCString()] = global_var.m_remote_addr; - if (log) - log->Printf(" Symbol: %s at 0x%" PRIx64 ".", - global_var.m_name.GetCString(), global_var.m_remote_addr); + LLDB_LOGF(log, " Symbol: %s at 0x%" PRIx64 ".", + global_var.m_name.GetCString(), global_var.m_remote_addr); } } } diff --git a/source/Expression/FunctionCaller.cpp b/source/Expression/FunctionCaller.cpp index 618c1a13212c..203cfff63d80 100644 --- a/source/Expression/FunctionCaller.cpp +++ b/source/Expression/FunctionCaller.cpp @@ -217,9 +217,8 @@ bool FunctionCaller::InsertFunction(ExecutionContext &exe_ctx, return false; Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); - if (log) - log->Printf("Call Address: 0x%" PRIx64 " Struct Address: 0x%" PRIx64 ".\n", - m_jit_start_addr, args_addr_ref); + LLDB_LOGF(log, "Call Address: 0x%" PRIx64 " Struct Address: 0x%" PRIx64 ".\n", + m_jit_start_addr, args_addr_ref); return true; } @@ -231,10 +230,10 @@ lldb::ThreadPlanSP FunctionCaller::GetThreadPlanToCallFunction( Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); - if (log) - log->Printf("-- [FunctionCaller::GetThreadPlanToCallFunction] Creating " - "thread plan to call function \"%s\" --", - m_name.c_str()); + LLDB_LOGF(log, + "-- [FunctionCaller::GetThreadPlanToCallFunction] Creating " + "thread plan to call function \"%s\" --", + m_name.c_str()); // FIXME: Use the errors Stream for better error reporting. Thread *thread = exe_ctx.GetThreadPtr(); @@ -271,10 +270,10 @@ bool FunctionCaller::FetchFunctionResults(ExecutionContext &exe_ctx, Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); - if (log) - log->Printf("-- [FunctionCaller::FetchFunctionResults] Fetching function " - "results for \"%s\"--", - m_name.c_str()); + LLDB_LOGF(log, + "-- [FunctionCaller::FetchFunctionResults] Fetching function " + "results for \"%s\"--", + m_name.c_str()); Process *process = exe_ctx.GetProcessPtr(); @@ -341,10 +340,9 @@ lldb::ExpressionResults FunctionCaller::ExecuteFunction( Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); - if (log) - log->Printf( - "== [FunctionCaller::ExecuteFunction] Executing function \"%s\" ==", - m_name.c_str()); + LLDB_LOGF(log, + "== [FunctionCaller::ExecuteFunction] Executing function \"%s\" ==", + m_name.c_str()); lldb::ThreadPlanSP call_plan_sp = GetThreadPlanToCallFunction( exe_ctx, args_addr, real_options, diagnostic_manager); @@ -362,13 +360,15 @@ lldb::ExpressionResults FunctionCaller::ExecuteFunction( if (log) { if (return_value != lldb::eExpressionCompleted) { - log->Printf("== [FunctionCaller::ExecuteFunction] Execution of \"%s\" " - "completed abnormally ==", - m_name.c_str()); + LLDB_LOGF(log, + "== [FunctionCaller::ExecuteFunction] Execution of \"%s\" " + "completed abnormally ==", + m_name.c_str()); } else { - log->Printf("== [FunctionCaller::ExecuteFunction] Execution of \"%s\" " - "completed normally ==", - m_name.c_str()); + LLDB_LOGF(log, + "== [FunctionCaller::ExecuteFunction] Execution of \"%s\" " + "completed normally ==", + m_name.c_str()); } } diff --git a/source/Expression/IRExecutionUnit.cpp b/source/Expression/IRExecutionUnit.cpp index 25404ad313e1..b10628e10cc5 100644 --- a/source/Expression/IRExecutionUnit.cpp +++ b/source/Expression/IRExecutionUnit.cpp @@ -122,10 +122,10 @@ Status IRExecutionUnit::DisassembleFunction(Stream &stream, return ret; } - if (log) - log->Printf("Found function, has local address 0x%" PRIx64 - " and remote address 0x%" PRIx64, - (uint64_t)func_local_addr, (uint64_t)func_remote_addr); + LLDB_LOGF(log, + "Found function, has local address 0x%" PRIx64 + " and remote address 0x%" PRIx64, + (uint64_t)func_local_addr, (uint64_t)func_remote_addr); std::pair<lldb::addr_t, lldb::addr_t> func_range; @@ -138,9 +138,8 @@ Status IRExecutionUnit::DisassembleFunction(Stream &stream, return ret; } - if (log) - log->Printf("Function's code range is [0x%" PRIx64 "+0x%" PRIx64 "]", - func_range.first, func_range.second); + LLDB_LOGF(log, "Function's code range is [0x%" PRIx64 "+0x%" PRIx64 "]", + func_range.first, func_range.second); Target *target = exe_ctx.GetTargetPtr(); if (!target) { @@ -188,7 +187,7 @@ Status IRExecutionUnit::DisassembleFunction(Stream &stream, target->GetArchitecture().GetAddressByteSize()); if (log) { - log->Printf("Function data has contents:"); + LLDB_LOGF(log, "Function data has contents:"); extractor.PutToLog(log, 0, extractor.GetByteSize(), func_remote_addr, 16, DataExtractor::TypeUInt8); } @@ -255,7 +254,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr, oss.flush(); - log->Printf("Module being sent to JIT: \n%s", s.c_str()); + LLDB_LOGF(log, "Module being sent to JIT: \n%s", s.c_str()); } m_module_up->getContext().setInlineAsmDiagnosticHandler(ReportInlineAsmError, @@ -317,7 +316,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr, }; if (process_sp->GetTarget().GetEnableSaveObjects()) { - m_object_cache_up = llvm::make_unique<ObjectDumper>(); + m_object_cache_up = std::make_unique<ObjectDumper>(); m_execution_engine_up->setObjectCache(m_object_cache_up.get()); } @@ -433,20 +432,20 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr, } if (log) { - log->Printf("Code can be run in the target."); + LLDB_LOGF(log, "Code can be run in the target."); StreamString disassembly_stream; Status err = DisassembleFunction(disassembly_stream, process_sp); if (!err.Success()) { - log->Printf("Couldn't disassemble function : %s", - err.AsCString("unknown error")); + LLDB_LOGF(log, "Couldn't disassemble function : %s", + err.AsCString("unknown error")); } else { - log->Printf("Function disassembly:\n%s", disassembly_stream.GetData()); + LLDB_LOGF(log, "Function disassembly:\n%s", disassembly_stream.GetData()); } - log->Printf("Sections: "); + LLDB_LOGF(log, "Sections: "); for (AllocationRecord &record : m_records) { if (record.m_process_address != LLDB_INVALID_ADDRESS) { record.dump(log); @@ -599,11 +598,10 @@ uint8_t *IRExecutionUnit::MemoryManager::allocateCodeSection( GetSectionTypeFromSectionName(SectionName, AllocationKind::Code), Size, Alignment, SectionID, SectionName.str().c_str())); - if (log) { - log->Printf("IRExecutionUnit::allocateCodeSection(Size=0x%" PRIx64 - ", Alignment=%u, SectionID=%u) = %p", - (uint64_t)Size, Alignment, SectionID, (void *)return_value); - } + LLDB_LOGF(log, + "IRExecutionUnit::allocateCodeSection(Size=0x%" PRIx64 + ", Alignment=%u, SectionID=%u) = %p", + (uint64_t)Size, Alignment, SectionID, (void *)return_value); if (m_parent.m_reported_allocations) { Status err; @@ -631,11 +629,10 @@ uint8_t *IRExecutionUnit::MemoryManager::allocateDataSection( (uintptr_t)return_value, permissions, GetSectionTypeFromSectionName(SectionName, AllocationKind::Data), Size, Alignment, SectionID, SectionName.str().c_str())); - if (log) { - log->Printf("IRExecutionUnit::allocateDataSection(Size=0x%" PRIx64 - ", Alignment=%u, SectionID=%u) = %p", - (uint64_t)Size, Alignment, SectionID, (void *)return_value); - } + LLDB_LOGF(log, + "IRExecutionUnit::allocateDataSection(Size=0x%" PRIx64 + ", Alignment=%u, SectionID=%u) = %p", + (uint64_t)Size, Alignment, SectionID, (void *)return_value); if (m_parent.m_reported_allocations) { Status err; @@ -661,11 +658,7 @@ FindBestAlternateMangledName(ConstString demangled, if (!sym_ctx.module_sp) return ConstString(); - SymbolVendor *sym_vendor = sym_ctx.module_sp->GetSymbolVendor(); - if (!sym_vendor) - return ConstString(); - - lldb_private::SymbolFile *sym_file = sym_vendor->GetSymbolFile(); + lldb_private::SymbolFile *sym_file = sym_ctx.module_sp->GetSymbolFile(); if (!sym_file) return ConstString(); @@ -676,7 +669,7 @@ FindBestAlternateMangledName(ConstString demangled, std::vector<ConstString> param_matches; for (size_t i = 0; i < alternates.size(); i++) { ConstString alternate_mangled_name = alternates[i]; - Mangled mangled(alternate_mangled_name, true); + Mangled mangled(alternate_mangled_name); ConstString demangled = mangled.GetDemangledName(lang_type); CPlusPlusLanguage::MethodName alternate_cpp_name(demangled); @@ -724,7 +717,7 @@ void IRExecutionUnit::CollectCandidateCPlusPlusNames( ConstString name = C_spec.name; if (CPlusPlusLanguage::IsCPPMangledName(name.GetCString())) { - Mangled mangled(name, true); + Mangled mangled(name); ConstString demangled = mangled.GetDemangledName(lldb::eLanguageTypeC_plus_plus); @@ -861,7 +854,6 @@ lldb::addr_t IRExecutionUnit::FindInSymbols( sc.module_sp->FindFunctions(spec.name, nullptr, spec.mask, true, // include_symbols false, // include_inlines - true, // append sc_list); } @@ -877,7 +869,6 @@ lldb::addr_t IRExecutionUnit::FindInSymbols( sc.target_sp->GetImages().FindFunctions(spec.name, spec.mask, true, // include_symbols false, // include_inlines - true, // append sc_list); } @@ -1042,17 +1033,15 @@ IRExecutionUnit::MemoryManager::GetSymbolAddressAndPresence( lldb::addr_t ret = m_parent.FindSymbol(name_cs, missing_weak); if (ret == LLDB_INVALID_ADDRESS) { - if (log) - log->Printf( - "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = <not found>", - Name.c_str()); + LLDB_LOGF(log, + "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = <not found>", + Name.c_str()); m_parent.ReportSymbolLookupError(name_cs); return 0; } else { - if (log) - log->Printf("IRExecutionUnit::getSymbolAddress(Name=\"%s\") = %" PRIx64, - Name.c_str(), ret); + LLDB_LOGF(log, "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = %" PRIx64, + Name.c_str(), ret); return ret; } } @@ -1075,15 +1064,14 @@ IRExecutionUnit::GetRemoteAddressForLocal(lldb::addr_t local_address) { lldb::addr_t ret = record.m_process_address + (local_address - record.m_host_address); - if (log) { - log->Printf( - "IRExecutionUnit::GetRemoteAddressForLocal() found 0x%" PRIx64 - " in [0x%" PRIx64 "..0x%" PRIx64 "], and returned 0x%" PRIx64 - " from [0x%" PRIx64 "..0x%" PRIx64 "].", - local_address, (uint64_t)record.m_host_address, - (uint64_t)record.m_host_address + (uint64_t)record.m_size, ret, - record.m_process_address, record.m_process_address + record.m_size); - } + LLDB_LOGF(log, + "IRExecutionUnit::GetRemoteAddressForLocal() found 0x%" PRIx64 + " in [0x%" PRIx64 "..0x%" PRIx64 "], and returned 0x%" PRIx64 + " from [0x%" PRIx64 "..0x%" PRIx64 "].", + local_address, (uint64_t)record.m_host_address, + (uint64_t)record.m_host_address + (uint64_t)record.m_size, ret, + record.m_process_address, + record.m_process_address + record.m_size); return ret; } @@ -1210,10 +1198,11 @@ void IRExecutionUnit::AllocationRecord::dump(Log *log) { if (!log) return; - log->Printf("[0x%llx+0x%llx]->0x%llx (alignment %d, section ID %d, name %s)", - (unsigned long long)m_host_address, (unsigned long long)m_size, - (unsigned long long)m_process_address, (unsigned)m_alignment, - (unsigned)m_section_id, m_name.c_str()); + LLDB_LOGF(log, + "[0x%llx+0x%llx]->0x%llx (alignment %d, section ID %d, name %s)", + (unsigned long long)m_host_address, (unsigned long long)m_size, + (unsigned long long)m_process_address, (unsigned)m_alignment, + (unsigned)m_section_id, m_name.c_str()); } lldb::ByteOrder IRExecutionUnit::GetByteOrder() const { diff --git a/source/Expression/IRInterpreter.cpp b/source/Expression/IRInterpreter.cpp index 5a9814d15362..856c9a0244fb 100644 --- a/source/Expression/IRInterpreter.cpp +++ b/source/Expression/IRInterpreter.cpp @@ -327,10 +327,11 @@ public: lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); if (log) { - log->Printf("Made an allocation for argument %s", - PrintValue(value).c_str()); - log->Printf(" Data region : %llx", (unsigned long long)address); - log->Printf(" Ref region : %llx", (unsigned long long)data_address); + LLDB_LOGF(log, "Made an allocation for argument %s", + PrintValue(value).c_str()); + LLDB_LOGF(log, " Data region : %llx", (unsigned long long)address); + LLDB_LOGF(log, " Ref region : %llx", + (unsigned long long)data_address); } return true; @@ -494,8 +495,7 @@ bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function, ++fi) { if (fi->begin() != fi->end()) { if (saw_function_with_body) { - if (log) - log->Printf("More than one function in the module has a body"); + LLDB_LOGF(log, "More than one function in the module has a body"); error.SetErrorToGenericError(); error.SetErrorString(too_many_functions_error); return false; @@ -510,8 +510,7 @@ bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function, ++ii) { switch (ii->getOpcode()) { default: { - if (log) - log->Printf("Unsupported instruction: %s", PrintValue(&*ii).c_str()); + LLDB_LOGF(log, "Unsupported instruction: %s", PrintValue(&*ii).c_str()); error.SetErrorToGenericError(); error.SetErrorString(unsupported_opcode_error); return false; @@ -532,9 +531,8 @@ bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function, } if (!CanIgnoreCall(call_inst) && !support_function_calls) { - if (log) - log->Printf("Unsupported instruction: %s", - PrintValue(&*ii).c_str()); + LLDB_LOGF(log, "Unsupported instruction: %s", + PrintValue(&*ii).c_str()); error.SetErrorToGenericError(); error.SetErrorString(unsupported_opcode_error); return false; @@ -553,9 +551,8 @@ bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function, switch (icmp_inst->getPredicate()) { default: { - if (log) - log->Printf("Unsupported ICmp predicate: %s", - PrintValue(&*ii).c_str()); + LLDB_LOGF(log, "Unsupported ICmp predicate: %s", + PrintValue(&*ii).c_str()); error.SetErrorToGenericError(); error.SetErrorString(unsupported_opcode_error); @@ -605,9 +602,8 @@ bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function, default: break; case Type::VectorTyID: { - if (log) - log->Printf("Unsupported operand type: %s", - PrintType(operand_type).c_str()); + LLDB_LOGF(log, "Unsupported operand type: %s", + PrintType(operand_type).c_str()); error.SetErrorString(unsupported_operand_error); return false; } @@ -618,18 +614,16 @@ bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function, // we can just fall back to the JIT rather than // choking. if (operand_type->getPrimitiveSizeInBits() > 64) { - if (log) - log->Printf("Unsupported operand type: %s", - PrintType(operand_type).c_str()); + LLDB_LOGF(log, "Unsupported operand type: %s", + PrintType(operand_type).c_str()); error.SetErrorString(unsupported_operand_error); return false; } if (Constant *constant = llvm::dyn_cast<Constant>(operand)) { if (!CanResolveConstant(constant)) { - if (log) - log->Printf("Unsupported constant: %s", - PrintValue(constant).c_str()); + LLDB_LOGF(log, "Unsupported constant: %s", + PrintValue(constant).c_str()); error.SetErrorString(unsupported_operand_error); return false; } @@ -659,8 +653,8 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, oss.flush(); - log->Printf("Module as passed in to IRInterpreter::Interpret: \n\"%s\"", - s.c_str()); + LLDB_LOGF(log, "Module as passed in to IRInterpreter::Interpret: \n\"%s\"", + s.c_str()); } DataLayout data_layout(&module); @@ -694,8 +688,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, while (frame.m_ii != frame.m_ie && (++num_insts < 4096)) { const Instruction *inst = &*frame.m_ii; - if (log) - log->Printf("Interpreting %s", PrintValue(inst).c_str()); + LLDB_LOGF(log, "Interpreting %s", PrintValue(inst).c_str()); switch (inst->getOpcode()) { default: @@ -717,10 +710,10 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, const BinaryOperator *bin_op = dyn_cast<BinaryOperator>(inst); if (!bin_op) { - if (log) - log->Printf( - "getOpcode() returns %s, but instruction is not a BinaryOperator", - inst->getOpcodeName()); + LLDB_LOGF( + log, + "getOpcode() returns %s, but instruction is not a BinaryOperator", + inst->getOpcodeName()); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -733,16 +726,14 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::Scalar R; if (!frame.EvaluateValue(L, lhs, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(lhs).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(lhs).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; } if (!frame.EvaluateValue(R, rhs, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(rhs).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(rhs).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -806,28 +797,26 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, frame.AssignValue(inst, result, module); if (log) { - log->Printf("Interpreted a %s", inst->getOpcodeName()); - log->Printf(" L : %s", frame.SummarizeValue(lhs).c_str()); - log->Printf(" R : %s", frame.SummarizeValue(rhs).c_str()); - log->Printf(" = : %s", frame.SummarizeValue(inst).c_str()); + LLDB_LOGF(log, "Interpreted a %s", inst->getOpcodeName()); + LLDB_LOGF(log, " L : %s", frame.SummarizeValue(lhs).c_str()); + LLDB_LOGF(log, " R : %s", frame.SummarizeValue(rhs).c_str()); + LLDB_LOGF(log, " = : %s", frame.SummarizeValue(inst).c_str()); } } break; case Instruction::Alloca: { const AllocaInst *alloca_inst = dyn_cast<AllocaInst>(inst); if (!alloca_inst) { - if (log) - log->Printf("getOpcode() returns Alloca, but instruction is not an " - "AllocaInst"); + LLDB_LOGF(log, "getOpcode() returns Alloca, but instruction is not an " + "AllocaInst"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; } if (alloca_inst->isArrayAllocation()) { - if (log) - log->Printf( - "AllocaInsts are not handled if isArrayAllocation() is true"); + LLDB_LOGF(log, + "AllocaInsts are not handled if isArrayAllocation() is true"); error.SetErrorToGenericError(); error.SetErrorString(unsupported_opcode_error); return false; @@ -846,8 +835,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb::addr_t R = frame.Malloc(T); if (R == LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("Couldn't allocate memory for an AllocaInst"); + LLDB_LOGF(log, "Couldn't allocate memory for an AllocaInst"); error.SetErrorToGenericError(); error.SetErrorString(memory_allocation_error); return false; @@ -856,8 +844,8 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb::addr_t P = frame.Malloc(Tptr); if (P == LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("Couldn't allocate the result pointer for an AllocaInst"); + LLDB_LOGF(log, + "Couldn't allocate the result pointer for an AllocaInst"); error.SetErrorToGenericError(); error.SetErrorString(memory_allocation_error); return false; @@ -868,8 +856,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, execution_unit.WritePointerToMemory(P, R, write_error); if (!write_error.Success()) { - if (log) - log->Printf("Couldn't write the result pointer for an AllocaInst"); + LLDB_LOGF(log, "Couldn't write the result pointer for an AllocaInst"); error.SetErrorToGenericError(); error.SetErrorString(memory_write_error); lldb_private::Status free_error; @@ -881,9 +868,9 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, frame.m_values[alloca_inst] = P; if (log) { - log->Printf("Interpreted an AllocaInst"); - log->Printf(" R : 0x%" PRIx64, R); - log->Printf(" P : 0x%" PRIx64, P); + LLDB_LOGF(log, "Interpreted an AllocaInst"); + LLDB_LOGF(log, " R : 0x%" PRIx64, R); + LLDB_LOGF(log, " P : 0x%" PRIx64, P); } } break; case Instruction::BitCast: @@ -891,10 +878,9 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, const CastInst *cast_inst = dyn_cast<CastInst>(inst); if (!cast_inst) { - if (log) - log->Printf( - "getOpcode() returns %s, but instruction is not a BitCastInst", - cast_inst->getOpcodeName()); + LLDB_LOGF( + log, "getOpcode() returns %s, but instruction is not a BitCastInst", + cast_inst->getOpcodeName()); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -905,8 +891,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::Scalar S; if (!frame.EvaluateValue(S, source, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(source).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(source).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -918,10 +903,9 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, const CastInst *cast_inst = dyn_cast<CastInst>(inst); if (!cast_inst) { - if (log) - log->Printf( - "getOpcode() returns %s, but instruction is not a BitCastInst", - cast_inst->getOpcodeName()); + LLDB_LOGF( + log, "getOpcode() returns %s, but instruction is not a BitCastInst", + cast_inst->getOpcodeName()); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -932,8 +916,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::Scalar S; if (!frame.EvaluateValue(S, source, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(source).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(source).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -949,9 +932,8 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, const BranchInst *br_inst = dyn_cast<BranchInst>(inst); if (!br_inst) { - if (log) - log->Printf( - "getOpcode() returns Br, but instruction is not a BranchInst"); + LLDB_LOGF( + log, "getOpcode() returns Br, but instruction is not a BranchInst"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -963,8 +945,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::Scalar C; if (!frame.EvaluateValue(C, condition, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(condition).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(condition).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -976,14 +957,15 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, frame.Jump(br_inst->getSuccessor(1)); if (log) { - log->Printf("Interpreted a BrInst with a condition"); - log->Printf(" cond : %s", frame.SummarizeValue(condition).c_str()); + LLDB_LOGF(log, "Interpreted a BrInst with a condition"); + LLDB_LOGF(log, " cond : %s", + frame.SummarizeValue(condition).c_str()); } } else { frame.Jump(br_inst->getSuccessor(0)); if (log) { - log->Printf("Interpreted a BrInst with no condition"); + LLDB_LOGF(log, "Interpreted a BrInst with no condition"); } } } @@ -992,17 +974,16 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, const PHINode *phi_inst = dyn_cast<PHINode>(inst); if (!phi_inst) { - if (log) - log->Printf( - "getOpcode() returns PHI, but instruction is not a PHINode"); + LLDB_LOGF(log, + "getOpcode() returns PHI, but instruction is not a PHINode"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; } if (!frame.m_prev_bb) { - if (log) - log->Printf("Encountered PHI node without having jumped from another " - "basic block"); + LLDB_LOGF(log, + "Encountered PHI node without having jumped from another " + "basic block"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -1011,8 +992,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, Value *value = phi_inst->getIncomingValueForBlock(frame.m_prev_bb); lldb_private::Scalar result; if (!frame.EvaluateValue(result, value, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(value).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(value).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -1020,18 +1000,17 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, frame.AssignValue(inst, result, module); if (log) { - log->Printf("Interpreted a %s", inst->getOpcodeName()); - log->Printf(" Incoming value : %s", - frame.SummarizeValue(value).c_str()); + LLDB_LOGF(log, "Interpreted a %s", inst->getOpcodeName()); + LLDB_LOGF(log, " Incoming value : %s", + frame.SummarizeValue(value).c_str()); } } break; case Instruction::GetElementPtr: { const GetElementPtrInst *gep_inst = dyn_cast<GetElementPtrInst>(inst); if (!gep_inst) { - if (log) - log->Printf("getOpcode() returns GetElementPtr, but instruction is " - "not a GetElementPtrInst"); + LLDB_LOGF(log, "getOpcode() returns GetElementPtr, but instruction is " + "not a GetElementPtrInst"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -1043,9 +1022,8 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::Scalar P; if (!frame.EvaluateValue(P, pointer_operand, module)) { - if (log) - log->Printf("Couldn't evaluate %s", - PrintValue(pointer_operand).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", + PrintValue(pointer_operand).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -1067,17 +1045,14 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::Scalar I; if (!frame.EvaluateValue(I, *ii, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(*ii).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(*ii).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; } - if (log) - log->Printf("Evaluated constant index %s as %llu", - PrintValue(*ii).c_str(), - I.ULongLong(LLDB_INVALID_ADDRESS)); + LLDB_LOGF(log, "Evaluated constant index %s as %llu", + PrintValue(*ii).c_str(), I.ULongLong(LLDB_INVALID_ADDRESS)); constant_index = cast<ConstantInt>(ConstantInt::get( (*ii)->getType(), I.ULongLong(LLDB_INVALID_ADDRESS))); @@ -1094,19 +1069,19 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, frame.AssignValue(inst, Poffset, module); if (log) { - log->Printf("Interpreted a GetElementPtrInst"); - log->Printf(" P : %s", - frame.SummarizeValue(pointer_operand).c_str()); - log->Printf(" Poffset : %s", frame.SummarizeValue(inst).c_str()); + LLDB_LOGF(log, "Interpreted a GetElementPtrInst"); + LLDB_LOGF(log, " P : %s", + frame.SummarizeValue(pointer_operand).c_str()); + LLDB_LOGF(log, " Poffset : %s", frame.SummarizeValue(inst).c_str()); } } break; case Instruction::ICmp: { const ICmpInst *icmp_inst = dyn_cast<ICmpInst>(inst); if (!icmp_inst) { - if (log) - log->Printf( - "getOpcode() returns ICmp, but instruction is not an ICmpInst"); + LLDB_LOGF( + log, + "getOpcode() returns ICmp, but instruction is not an ICmpInst"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -1121,16 +1096,14 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::Scalar R; if (!frame.EvaluateValue(L, lhs, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(lhs).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(lhs).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; } if (!frame.EvaluateValue(R, rhs, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(rhs).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(rhs).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -1192,19 +1165,19 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, frame.AssignValue(inst, result, module); if (log) { - log->Printf("Interpreted an ICmpInst"); - log->Printf(" L : %s", frame.SummarizeValue(lhs).c_str()); - log->Printf(" R : %s", frame.SummarizeValue(rhs).c_str()); - log->Printf(" = : %s", frame.SummarizeValue(inst).c_str()); + LLDB_LOGF(log, "Interpreted an ICmpInst"); + LLDB_LOGF(log, " L : %s", frame.SummarizeValue(lhs).c_str()); + LLDB_LOGF(log, " R : %s", frame.SummarizeValue(rhs).c_str()); + LLDB_LOGF(log, " = : %s", frame.SummarizeValue(inst).c_str()); } } break; case Instruction::IntToPtr: { const IntToPtrInst *int_to_ptr_inst = dyn_cast<IntToPtrInst>(inst); if (!int_to_ptr_inst) { - if (log) - log->Printf("getOpcode() returns IntToPtr, but instruction is not an " - "IntToPtrInst"); + LLDB_LOGF(log, + "getOpcode() returns IntToPtr, but instruction is not an " + "IntToPtrInst"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -1215,8 +1188,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::Scalar I; if (!frame.EvaluateValue(I, src_operand, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(src_operand).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(src_operand).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -1225,18 +1197,18 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, frame.AssignValue(inst, I, module); if (log) { - log->Printf("Interpreted an IntToPtr"); - log->Printf(" Src : %s", frame.SummarizeValue(src_operand).c_str()); - log->Printf(" = : %s", frame.SummarizeValue(inst).c_str()); + LLDB_LOGF(log, "Interpreted an IntToPtr"); + LLDB_LOGF(log, " Src : %s", frame.SummarizeValue(src_operand).c_str()); + LLDB_LOGF(log, " = : %s", frame.SummarizeValue(inst).c_str()); } } break; case Instruction::PtrToInt: { const PtrToIntInst *ptr_to_int_inst = dyn_cast<PtrToIntInst>(inst); if (!ptr_to_int_inst) { - if (log) - log->Printf("getOpcode() returns PtrToInt, but instruction is not an " - "PtrToIntInst"); + LLDB_LOGF(log, + "getOpcode() returns PtrToInt, but instruction is not an " + "PtrToIntInst"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -1247,8 +1219,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::Scalar I; if (!frame.EvaluateValue(I, src_operand, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(src_operand).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(src_operand).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -1257,18 +1228,18 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, frame.AssignValue(inst, I, module); if (log) { - log->Printf("Interpreted a PtrToInt"); - log->Printf(" Src : %s", frame.SummarizeValue(src_operand).c_str()); - log->Printf(" = : %s", frame.SummarizeValue(inst).c_str()); + LLDB_LOGF(log, "Interpreted a PtrToInt"); + LLDB_LOGF(log, " Src : %s", frame.SummarizeValue(src_operand).c_str()); + LLDB_LOGF(log, " = : %s", frame.SummarizeValue(inst).c_str()); } } break; case Instruction::Trunc: { const TruncInst *trunc_inst = dyn_cast<TruncInst>(inst); if (!trunc_inst) { - if (log) - log->Printf( - "getOpcode() returns Trunc, but instruction is not a TruncInst"); + LLDB_LOGF( + log, + "getOpcode() returns Trunc, but instruction is not a TruncInst"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -1279,8 +1250,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::Scalar I; if (!frame.EvaluateValue(I, src_operand, module)) { - if (log) - log->Printf("Couldn't evaluate %s", PrintValue(src_operand).c_str()); + LLDB_LOGF(log, "Couldn't evaluate %s", PrintValue(src_operand).c_str()); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -1289,18 +1259,17 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, frame.AssignValue(inst, I, module); if (log) { - log->Printf("Interpreted a Trunc"); - log->Printf(" Src : %s", frame.SummarizeValue(src_operand).c_str()); - log->Printf(" = : %s", frame.SummarizeValue(inst).c_str()); + LLDB_LOGF(log, "Interpreted a Trunc"); + LLDB_LOGF(log, " Src : %s", frame.SummarizeValue(src_operand).c_str()); + LLDB_LOGF(log, " = : %s", frame.SummarizeValue(inst).c_str()); } } break; case Instruction::Load: { const LoadInst *load_inst = dyn_cast<LoadInst>(inst); if (!load_inst) { - if (log) - log->Printf( - "getOpcode() returns Load, but instruction is not a LoadInst"); + LLDB_LOGF( + log, "getOpcode() returns Load, but instruction is not a LoadInst"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -1317,8 +1286,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, Type *pointer_ty = pointer_operand->getType(); PointerType *pointer_ptr_ty = dyn_cast<PointerType>(pointer_ty); if (!pointer_ptr_ty) { - if (log) - log->Printf("getPointerOperand()->getType() is not a PointerType"); + LLDB_LOGF(log, "getPointerOperand()->getType() is not a PointerType"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -1329,16 +1297,14 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb::addr_t P = frame.ResolveValue(pointer_operand, module); if (D == LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("LoadInst's value doesn't resolve to anything"); + LLDB_LOGF(log, "LoadInst's value doesn't resolve to anything"); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; } if (P == LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("LoadInst's pointer doesn't resolve to anything"); + LLDB_LOGF(log, "LoadInst's pointer doesn't resolve to anything"); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -1349,8 +1315,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, execution_unit.ReadPointerFromMemory(&R, P, read_error); if (!read_error.Success()) { - if (log) - log->Printf("Couldn't read the address to be loaded for a LoadInst"); + LLDB_LOGF(log, "Couldn't read the address to be loaded for a LoadInst"); error.SetErrorToGenericError(); error.SetErrorString(memory_read_error); return false; @@ -1363,8 +1328,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, execution_unit.ReadMemory(buffer.GetBytes(), R, buffer.GetByteSize(), read_error); if (!read_error.Success()) { - if (log) - log->Printf("Couldn't read from a region on behalf of a LoadInst"); + LLDB_LOGF(log, "Couldn't read from a region on behalf of a LoadInst"); error.SetErrorToGenericError(); error.SetErrorString(memory_read_error); return false; @@ -1374,18 +1338,17 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, execution_unit.WriteMemory(D, buffer.GetBytes(), buffer.GetByteSize(), write_error); if (!write_error.Success()) { - if (log) - log->Printf("Couldn't write to a region on behalf of a LoadInst"); + LLDB_LOGF(log, "Couldn't write to a region on behalf of a LoadInst"); error.SetErrorToGenericError(); error.SetErrorString(memory_read_error); return false; } if (log) { - log->Printf("Interpreted a LoadInst"); - log->Printf(" P : 0x%" PRIx64, P); - log->Printf(" R : 0x%" PRIx64, R); - log->Printf(" D : 0x%" PRIx64, D); + LLDB_LOGF(log, "Interpreted a LoadInst"); + LLDB_LOGF(log, " P : 0x%" PRIx64, P); + LLDB_LOGF(log, " R : 0x%" PRIx64, R); + LLDB_LOGF(log, " D : 0x%" PRIx64, D); } } break; case Instruction::Ret: { @@ -1395,9 +1358,9 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, const StoreInst *store_inst = dyn_cast<StoreInst>(inst); if (!store_inst) { - if (log) - log->Printf( - "getOpcode() returns Store, but instruction is not a StoreInst"); + LLDB_LOGF( + log, + "getOpcode() returns Store, but instruction is not a StoreInst"); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; @@ -1422,16 +1385,14 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb::addr_t P = frame.ResolveValue(pointer_operand, module); if (D == LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("StoreInst's value doesn't resolve to anything"); + LLDB_LOGF(log, "StoreInst's value doesn't resolve to anything"); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; } if (P == LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("StoreInst's pointer doesn't resolve to anything"); + LLDB_LOGF(log, "StoreInst's pointer doesn't resolve to anything"); error.SetErrorToGenericError(); error.SetErrorString(bad_value_error); return false; @@ -1442,8 +1403,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, execution_unit.ReadPointerFromMemory(&R, P, read_error); if (!read_error.Success()) { - if (log) - log->Printf("Couldn't read the address to be loaded for a LoadInst"); + LLDB_LOGF(log, "Couldn't read the address to be loaded for a LoadInst"); error.SetErrorToGenericError(); error.SetErrorString(memory_read_error); return false; @@ -1456,8 +1416,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, execution_unit.ReadMemory(buffer.GetBytes(), D, buffer.GetByteSize(), read_error); if (!read_error.Success()) { - if (log) - log->Printf("Couldn't read from a region on behalf of a StoreInst"); + LLDB_LOGF(log, "Couldn't read from a region on behalf of a StoreInst"); error.SetErrorToGenericError(); error.SetErrorString(memory_read_error); return false; @@ -1467,28 +1426,26 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, execution_unit.WriteMemory(R, buffer.GetBytes(), buffer.GetByteSize(), write_error); if (!write_error.Success()) { - if (log) - log->Printf("Couldn't write to a region on behalf of a StoreInst"); + LLDB_LOGF(log, "Couldn't write to a region on behalf of a StoreInst"); error.SetErrorToGenericError(); error.SetErrorString(memory_write_error); return false; } if (log) { - log->Printf("Interpreted a StoreInst"); - log->Printf(" D : 0x%" PRIx64, D); - log->Printf(" P : 0x%" PRIx64, P); - log->Printf(" R : 0x%" PRIx64, R); + LLDB_LOGF(log, "Interpreted a StoreInst"); + LLDB_LOGF(log, " D : 0x%" PRIx64, D); + LLDB_LOGF(log, " P : 0x%" PRIx64, P); + LLDB_LOGF(log, " R : 0x%" PRIx64, R); } } break; case Instruction::Call: { const CallInst *call_inst = dyn_cast<CallInst>(inst); if (!call_inst) { - if (log) - log->Printf( - "getOpcode() returns %s, but instruction is not a CallInst", - inst->getOpcodeName()); + LLDB_LOGF(log, + "getOpcode() returns %s, but instruction is not a CallInst", + inst->getOpcodeName()); error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; diff --git a/source/Expression/IRMemoryMap.cpp b/source/Expression/IRMemoryMap.cpp index 70e62ac12b0e..5fdf452bf94e 100644 --- a/source/Expression/IRMemoryMap.cpp +++ b/source/Expression/IRMemoryMap.cpp @@ -327,12 +327,12 @@ lldb::addr_t IRMemoryMap::Malloc(size_t size, uint8_t alignment, break; case eAllocationPolicyMirror: process_sp = m_process_wp.lock(); - if (log) - log->Printf("IRMemoryMap::%s process_sp=0x%" PRIx64 - ", process_sp->CanJIT()=%s, process_sp->IsAlive()=%s", - __FUNCTION__, (lldb::addr_t)process_sp.get(), - process_sp && process_sp->CanJIT() ? "true" : "false", - process_sp && process_sp->IsAlive() ? "true" : "false"); + LLDB_LOGF(log, + "IRMemoryMap::%s process_sp=0x%" PRIx64 + ", process_sp->CanJIT()=%s, process_sp->IsAlive()=%s", + __FUNCTION__, (lldb::addr_t)process_sp.get(), + process_sp && process_sp->CanJIT() ? "true" : "false", + process_sp && process_sp->IsAlive() ? "true" : "false"); if (process_sp && process_sp->CanJIT() && process_sp->IsAlive()) { if (!zero_memory) allocation_address = @@ -344,10 +344,10 @@ lldb::addr_t IRMemoryMap::Malloc(size_t size, uint8_t alignment, if (!error.Success()) return LLDB_INVALID_ADDRESS; } else { - if (log) - log->Printf("IRMemoryMap::%s switching to eAllocationPolicyHostOnly " - "due to failed condition (see previous expr log message)", - __FUNCTION__); + LLDB_LOGF(log, + "IRMemoryMap::%s switching to eAllocationPolicyHostOnly " + "due to failed condition (see previous expr log message)", + __FUNCTION__); policy = eAllocationPolicyHostOnly; allocation_address = FindSpace(allocation_size); if (allocation_address == LLDB_INVALID_ADDRESS) { @@ -417,10 +417,11 @@ lldb::addr_t IRMemoryMap::Malloc(size_t size, uint8_t alignment, break; } - log->Printf("IRMemoryMap::Malloc (%" PRIu64 ", 0x%" PRIx64 ", 0x%" PRIx64 - ", %s) -> 0x%" PRIx64, - (uint64_t)allocation_size, (uint64_t)alignment, - (uint64_t)permissions, policy_string, aligned_address); + LLDB_LOGF(log, + "IRMemoryMap::Malloc (%" PRIu64 ", 0x%" PRIx64 ", 0x%" PRIx64 + ", %s) -> 0x%" PRIx64, + (uint64_t)allocation_size, (uint64_t)alignment, + (uint64_t)permissions, policy_string, aligned_address); } return aligned_address; @@ -477,10 +478,11 @@ void IRMemoryMap::Free(lldb::addr_t process_address, Status &error) { if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { - log->Printf("IRMemoryMap::Free (0x%" PRIx64 ") freed [0x%" PRIx64 - "..0x%" PRIx64 ")", - (uint64_t)process_address, iter->second.m_process_start, - iter->second.m_process_start + iter->second.m_size); + LLDB_LOGF(log, + "IRMemoryMap::Free (0x%" PRIx64 ") freed [0x%" PRIx64 + "..0x%" PRIx64 ")", + (uint64_t)process_address, iter->second.m_process_start, + iter->second.m_process_start + iter->second.m_size); } m_allocations.erase(iter); @@ -574,12 +576,13 @@ void IRMemoryMap::WriteMemory(lldb::addr_t process_address, if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { - log->Printf("IRMemoryMap::WriteMemory (0x%" PRIx64 ", 0x%" PRIx64 - ", 0x%" PRId64 ") went to [0x%" PRIx64 "..0x%" PRIx64 ")", - (uint64_t)process_address, (uint64_t)bytes, (uint64_t)size, - (uint64_t)allocation.m_process_start, - (uint64_t)allocation.m_process_start + - (uint64_t)allocation.m_size); + LLDB_LOGF(log, + "IRMemoryMap::WriteMemory (0x%" PRIx64 ", 0x%" PRIx64 + ", 0x%" PRId64 ") went to [0x%" PRIx64 "..0x%" PRIx64 ")", + (uint64_t)process_address, (uint64_t)bytes, (uint64_t)size, + (uint64_t)allocation.m_process_start, + (uint64_t)allocation.m_process_start + + (uint64_t)allocation.m_size); } } @@ -704,12 +707,13 @@ void IRMemoryMap::ReadMemory(uint8_t *bytes, lldb::addr_t process_address, if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { - log->Printf("IRMemoryMap::ReadMemory (0x%" PRIx64 ", 0x%" PRIx64 - ", 0x%" PRId64 ") came from [0x%" PRIx64 "..0x%" PRIx64 ")", - (uint64_t)process_address, (uint64_t)bytes, (uint64_t)size, - (uint64_t)allocation.m_process_start, - (uint64_t)allocation.m_process_start + - (uint64_t)allocation.m_size); + LLDB_LOGF(log, + "IRMemoryMap::ReadMemory (0x%" PRIx64 ", 0x%" PRIx64 + ", 0x%" PRId64 ") came from [0x%" PRIx64 "..0x%" PRIx64 ")", + (uint64_t)process_address, (uint64_t)bytes, (uint64_t)size, + (uint64_t)allocation.m_process_start, + (uint64_t)allocation.m_process_start + + (uint64_t)allocation.m_size); } } diff --git a/source/Expression/LLVMUserExpression.cpp b/source/Expression/LLVMUserExpression.cpp index 5a1b750318c9..99e0c11df420 100644 --- a/source/Expression/LLVMUserExpression.cpp +++ b/source/Expression/LLVMUserExpression.cpp @@ -12,13 +12,12 @@ #include "lldb/Core/StreamFile.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Expression/DiagnosticManager.h" +#include "lldb/Expression/ExpressionVariable.h" #include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Expression/IRInterpreter.h" #include "lldb/Expression/Materializer.h" #include "lldb/Host/HostInfo.h" #include "lldb/Symbol/Block.h" -#include "lldb/Symbol/ClangASTContext.h" -#include "lldb/Symbol/ClangExternalASTSourceCommon.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/SymbolVendor.h" @@ -48,9 +47,7 @@ LLVMUserExpression::LLVMUserExpression(ExecutionContextScope &exe_scope, m_stack_frame_bottom(LLDB_INVALID_ADDRESS), m_stack_frame_top(LLDB_INVALID_ADDRESS), m_allow_cxx(false), m_allow_objc(false), m_transformed_text(), m_execution_unit_sp(), - m_materializer_up(), m_jit_module_wp(), m_enforce_valid_object(true), - m_in_cplusplus_method(false), m_in_objectivec_method(false), - m_in_static_method(false), m_needs_object_ptr(false), m_target(nullptr), + m_materializer_up(), m_jit_module_wp(), m_can_interpret(false), m_materialized_address(LLDB_INVALID_ADDRESS) {} LLVMUserExpression::~LLVMUserExpression() { @@ -161,9 +158,9 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager, function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize(); function_stack_top = function_stack_pointer; - if (log) - log->Printf( - "-- [UserExpression::Execute] Execution of expression begins --"); + LLDB_LOGF( + log, + "-- [UserExpression::Execute] Execution of expression begins --"); if (exe_ctx.GetProcessPtr()) exe_ctx.GetProcessPtr()->SetRunningUserExpression(true); @@ -175,9 +172,8 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager, if (exe_ctx.GetProcessPtr()) exe_ctx.GetProcessPtr()->SetRunningUserExpression(false); - if (log) - log->Printf("-- [UserExpression::Execute] Execution of expression " - "completed --"); + LLDB_LOGF(log, "-- [UserExpression::Execute] Execution of expression " + "completed --"); if (execution_result == lldb::eExpressionInterrupted || execution_result == lldb::eExpressionHitBreakpoint) { @@ -251,9 +247,8 @@ bool LLVMUserExpression::FinalizeJITExecution( lldb::addr_t function_stack_top) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); - if (log) - log->Printf("-- [UserExpression::FinalizeJITExecution] Dematerializing " - "after execution --"); + LLDB_LOGF(log, "-- [UserExpression::FinalizeJITExecution] Dematerializing " + "after execution --"); if (!m_dematerializer_sp) { diagnostic_manager.Printf(eDiagnosticSeverityError, diff --git a/source/Expression/Materializer.cpp b/source/Expression/Materializer.cpp index 0f871fcbefbc..cd332484debb 100644 --- a/source/Expression/Materializer.cpp +++ b/source/Expression/Materializer.cpp @@ -11,7 +11,6 @@ #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Core/ValueObjectVariable.h" #include "lldb/Expression/ExpressionVariable.h" -#include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/Type.h" #include "lldb/Symbol/Variable.h" @@ -46,20 +45,6 @@ uint32_t Materializer::AddStructMember(Entity &entity) { return ret; } -void Materializer::Entity::SetSizeAndAlignmentFromType(CompilerType &type) { - if (llvm::Optional<uint64_t> size = type.GetByteSize(nullptr)) - m_size = *size; - - uint32_t bit_alignment = type.GetTypeBitAlign(); - - if (bit_alignment % 8) { - bit_alignment += 8; - bit_alignment &= ~((uint32_t)0x111u); - } - - m_alignment = bit_alignment / 8; -} - class EntityPersistentVariable : public Materializer::Entity { public: EntityPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp, @@ -94,9 +79,8 @@ public: return; } - if (log) - log->Printf("Allocated %s (0x%" PRIx64 ") successfully", - m_persistent_variable_sp->GetName().GetCString(), mem); + LLDB_LOGF(log, "Allocated %s (0x%" PRIx64 ") successfully", + m_persistent_variable_sp->GetName().GetCString(), mem); // Put the location of the spare memory into the live data of the // ValueObject. @@ -158,11 +142,12 @@ public: const lldb::addr_t load_addr = process_address + m_offset; if (log) { - log->Printf("EntityPersistentVariable::Materialize [address = 0x%" PRIx64 - ", m_name = %s, m_flags = 0x%hx]", - (uint64_t)load_addr, - m_persistent_variable_sp->GetName().AsCString(), - m_persistent_variable_sp->m_flags); + LLDB_LOGF(log, + "EntityPersistentVariable::Materialize [address = 0x%" PRIx64 + ", m_name = %s, m_flags = 0x%hx]", + (uint64_t)load_addr, + m_persistent_variable_sp->GetName().AsCString(), + m_persistent_variable_sp->m_flags); } if (m_persistent_variable_sp->m_flags & @@ -209,12 +194,12 @@ public: const lldb::addr_t load_addr = process_address + m_offset; if (log) { - log->Printf( - "EntityPersistentVariable::Dematerialize [address = 0x%" PRIx64 - ", m_name = %s, m_flags = 0x%hx]", - (uint64_t)process_address + m_offset, - m_persistent_variable_sp->GetName().AsCString(), - m_persistent_variable_sp->m_flags); + LLDB_LOGF(log, + "EntityPersistentVariable::Dematerialize [address = 0x%" PRIx64 + ", m_name = %s, m_flags = 0x%hx]", + (uint64_t)process_address + m_offset, + m_persistent_variable_sp->GetName().AsCString(), + m_persistent_variable_sp->m_flags); } if (m_delegate) { @@ -291,11 +276,10 @@ public: ExpressionVariable::EVNeedsFreezeDry || m_persistent_variable_sp->m_flags & ExpressionVariable::EVKeepInTarget) { - if (log) - log->Printf( - "Dematerializing %s from 0x%" PRIx64 " (size = %llu)", - m_persistent_variable_sp->GetName().GetCString(), (uint64_t)mem, - (unsigned long long)m_persistent_variable_sp->GetByteSize()); + LLDB_LOGF(log, "Dematerializing %s from 0x%" PRIx64 " (size = %llu)", + m_persistent_variable_sp->GetName().GetCString(), + (uint64_t)mem, + (unsigned long long)m_persistent_variable_sp->GetByteSize()); // Read the contents of the spare memory area @@ -441,9 +425,10 @@ public: const lldb::addr_t load_addr = process_address + m_offset; if (log) { - log->Printf("EntityVariable::Materialize [address = 0x%" PRIx64 - ", m_variable_sp = %s]", - (uint64_t)load_addr, m_variable_sp->GetName().AsCString()); + LLDB_LOGF(log, + "EntityVariable::Materialize [address = 0x%" PRIx64 + ", m_variable_sp = %s]", + (uint64_t)load_addr, m_variable_sp->GetName().AsCString()); } ExecutionContextScope *scope = frame_sp.get(); @@ -545,12 +530,15 @@ public: return; } - size_t bit_align = - m_variable_sp->GetType()->GetLayoutCompilerType().GetTypeBitAlign(); - size_t byte_align = (bit_align + 7) / 8; + llvm::Optional<size_t> opt_bit_align = + m_variable_sp->GetType()->GetLayoutCompilerType().GetTypeBitAlign(scope); + if (!opt_bit_align) { + err.SetErrorStringWithFormat("can't get the type alignment for %s", + m_variable_sp->GetName().AsCString()); + return; + } - if (!byte_align) - byte_align = 1; + size_t byte_align = (*opt_bit_align + 7) / 8; Status alloc_error; const bool zero_memory = false; @@ -606,9 +594,10 @@ public: const lldb::addr_t load_addr = process_address + m_offset; if (log) { - log->Printf("EntityVariable::Dematerialize [address = 0x%" PRIx64 - ", m_variable_sp = %s]", - (uint64_t)load_addr, m_variable_sp->GetName().AsCString()); + LLDB_LOGF(log, + "EntityVariable::Dematerialize [address = 0x%" PRIx64 + ", m_variable_sp = %s]", + (uint64_t)load_addr, m_variable_sp->GetName().AsCString()); } if (m_temporary_allocation != LLDB_INVALID_ADDRESS) { @@ -802,11 +791,14 @@ public: err.SetErrorString("can't get size of type"); return; } - size_t bit_align = m_type.GetTypeBitAlign(); - size_t byte_align = (bit_align + 7) / 8; - if (!byte_align) - byte_align = 1; + llvm::Optional<size_t> opt_bit_align = m_type.GetTypeBitAlign(exe_scope); + if (!opt_bit_align) { + err.SetErrorStringWithFormat("can't get the type alignment"); + return; + } + + size_t byte_align = (*opt_bit_align + 7) / 8; Status alloc_error; const bool zero_memory = true; @@ -869,20 +861,18 @@ public: return; } - Status type_system_error; - TypeSystem *type_system = target_sp->GetScratchTypeSystemForLanguage( - &type_system_error, m_type.GetMinimumLanguage()); + auto type_system_or_err = + target_sp->GetScratchTypeSystemForLanguage(m_type.GetMinimumLanguage()); - if (!type_system) { + if (auto error = type_system_or_err.takeError()) { err.SetErrorStringWithFormat("Couldn't dematerialize a result variable: " "couldn't get the corresponding type " "system: %s", - type_system_error.AsCString()); + llvm::toString(std::move(error)).c_str()); return; } - PersistentExpressionState *persistent_state = - type_system->GetPersistentExpressionState(); + type_system_or_err->GetPersistentExpressionState(); if (!persistent_state) { err.SetErrorString("Couldn't dematerialize a result variable: " @@ -1064,9 +1054,10 @@ public: const lldb::addr_t load_addr = process_address + m_offset; if (log) { - log->Printf("EntitySymbol::Materialize [address = 0x%" PRIx64 - ", m_symbol = %s]", - (uint64_t)load_addr, m_symbol.GetName().AsCString()); + LLDB_LOGF(log, + "EntitySymbol::Materialize [address = 0x%" PRIx64 + ", m_symbol = %s]", + (uint64_t)load_addr, m_symbol.GetName().AsCString()); } const Address sym_address = m_symbol.GetAddress(); @@ -1110,9 +1101,10 @@ public: const lldb::addr_t load_addr = process_address + m_offset; if (log) { - log->Printf("EntitySymbol::Dematerialize [address = 0x%" PRIx64 - ", m_symbol = %s]", - (uint64_t)load_addr, m_symbol.GetName().AsCString()); + LLDB_LOGF(log, + "EntitySymbol::Dematerialize [address = 0x%" PRIx64 + ", m_symbol = %s]", + (uint64_t)load_addr, m_symbol.GetName().AsCString()); } // no work needs to be done @@ -1179,9 +1171,10 @@ public: const lldb::addr_t load_addr = process_address + m_offset; if (log) { - log->Printf("EntityRegister::Materialize [address = 0x%" PRIx64 - ", m_register_info = %s]", - (uint64_t)load_addr, m_register_info.name); + LLDB_LOGF(log, + "EntityRegister::Materialize [address = 0x%" PRIx64 + ", m_register_info = %s]", + (uint64_t)load_addr, m_register_info.name); } RegisterValue reg_value; @@ -1241,9 +1234,10 @@ public: const lldb::addr_t load_addr = process_address + m_offset; if (log) { - log->Printf("EntityRegister::Dematerialize [address = 0x%" PRIx64 - ", m_register_info = %s]", - (uint64_t)load_addr, m_register_info.name); + LLDB_LOGF(log, + "EntityRegister::Dematerialize [address = 0x%" PRIx64 + ", m_register_info = %s]", + (uint64_t)load_addr, m_register_info.name); } Status extract_error; @@ -1380,7 +1374,8 @@ Materializer::Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, if (Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { - log->Printf( + LLDB_LOGF( + log, "Materializer::Materialize (frame_sp = %p, process_address = 0x%" PRIx64 ") materialized:", static_cast<void *>(frame_sp.get()), process_address); @@ -1415,9 +1410,10 @@ void Materializer::Dematerializer::Dematerialize(Status &error, } else { if (Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { - log->Printf("Materializer::Dematerialize (frame_sp = %p, process_address " - "= 0x%" PRIx64 ") about to dematerialize:", - static_cast<void *>(frame_sp.get()), m_process_address); + LLDB_LOGF(log, + "Materializer::Dematerialize (frame_sp = %p, process_address " + "= 0x%" PRIx64 ") about to dematerialize:", + static_cast<void *>(frame_sp.get()), m_process_address); for (EntityUP &entity_up : m_materializer->m_entities) entity_up->DumpToLog(*m_map, m_process_address, log); } diff --git a/source/Expression/REPL.cpp b/source/Expression/REPL.cpp index f4ed887729d8..4f81ee3e56dd 100644 --- a/source/Expression/REPL.cpp +++ b/source/Expression/REPL.cpp @@ -96,7 +96,7 @@ void REPL::IOHandlerActivated(IOHandler &io_handler, bool interactive) { lldb::ProcessSP process_sp = m_target.GetProcessSP(); if (process_sp && process_sp->IsAlive()) return; - lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFile()); + lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFileSP()); error_sp->Printf("REPL requires a running target process.\n"); io_handler.SetIsDone(true); } @@ -180,8 +180,8 @@ int REPL::IOHandlerFixIndentation(IOHandler &io_handler, } void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) { - lldb::StreamFileSP output_sp(io_handler.GetOutputStreamFile()); - lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFile()); + lldb::StreamFileSP output_sp(io_handler.GetOutputStreamFileSP()); + lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFileSP()); bool extra_line = false; bool did_quit = false; @@ -206,7 +206,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) { // Meta command // Strip the ':' code.erase(0, 1); - if (Args::StripSpaces(code)) { + if (!llvm::StringRef(code).trim().empty()) { // "lldb" was followed by arguments, so just execute the command dump // the results @@ -398,17 +398,22 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) { // Update our code on disk if (!m_repl_source_path.empty()) { - lldb_private::File file; - FileSystem::Instance().Open(file, FileSpec(m_repl_source_path), - File::eOpenOptionWrite | - File::eOpenOptionTruncate | - File::eOpenOptionCanCreate, - lldb::eFilePermissionsFileDefault); - std::string code(m_code.CopyList()); - code.append(1, '\n'); - size_t bytes_written = code.size(); - file.Write(code.c_str(), bytes_written); - file.Close(); + auto file = FileSystem::Instance().Open( + FileSpec(m_repl_source_path), + File::eOpenOptionWrite | File::eOpenOptionTruncate | + File::eOpenOptionCanCreate, + lldb::eFilePermissionsFileDefault); + if (file) { + std::string code(m_code.CopyList()); + code.append(1, '\n'); + size_t bytes_written = code.size(); + file.get()->Write(code.c_str(), bytes_written); + file.get()->Close(); + } else { + std::string message = llvm::toString(file.takeError()); + error_sp->Printf("error: couldn't open %s: %s\n", + m_repl_source_path.c_str(), message.c_str()); + } // Now set the default file and line to the REPL source file m_target.GetSourceManager().SetDefaultFileAndLine( @@ -418,7 +423,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) { .SetBaseLineNumber(m_code.GetSize() + 1); } if (extra_line) { - fprintf(output_sp->GetFile().GetStream(), "\n"); + output_sp->Printf("\n"); } } } @@ -433,31 +438,30 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) { } } -int REPL::IOHandlerComplete(IOHandler &io_handler, const char *current_line, - const char *cursor, const char *last_char, - int skip_first_n_matches, int max_matches, - StringList &matches, StringList &descriptions) { - matches.Clear(); - - llvm::StringRef line(current_line, cursor - current_line); - +void REPL::IOHandlerComplete(IOHandler &io_handler, + CompletionRequest &request) { // Complete an LLDB command if the first character is a colon... - if (!line.empty() && line[0] == ':') { + if (request.GetRawLine().startswith(":")) { Debugger &debugger = m_target.GetDebugger(); // auto complete LLDB commands - const char *lldb_current_line = line.substr(1).data(); - return debugger.GetCommandInterpreter().HandleCompletion( - lldb_current_line, cursor, last_char, skip_first_n_matches, max_matches, - matches, descriptions); + llvm::StringRef new_line = request.GetRawLine().drop_front(); + CompletionResult sub_result; + CompletionRequest sub_request(new_line, request.GetRawCursorPos() - 1, + sub_result); + debugger.GetCommandInterpreter().HandleCompletion(sub_request); + StringList matches, descriptions; + sub_result.GetMatches(matches); + sub_result.GetDescriptions(descriptions); + request.AddCompletions(matches, descriptions); + return; } // Strip spaces from the line and see if we had only spaces - line = line.ltrim(); - if (line.empty()) { + if (request.GetRawLine().trim().empty()) { // Only spaces on this line, so just indent - matches.AppendString(m_indent_str); - return 1; + request.AddCompletion(m_indent_str); + return; } std::string current_code; @@ -479,12 +483,17 @@ int REPL::IOHandlerComplete(IOHandler &io_handler, const char *current_line, } } - if (cursor > current_line) { - current_code.append("\n"); - current_code.append(current_line, cursor - current_line); - } - - return CompleteCode(current_code, matches); + current_code.append("\n"); + current_code += request.GetRawLine(); + + StringList matches; + int result = CompleteCode(current_code, matches); + if (result == -2) { + assert(matches.GetSize() == 1); + request.AddCompletion(matches.GetStringAtIndex(0), "", + CompletionMode::RewriteLine); + } else + request.AddCompletions(matches); } bool QuitCommandOverrideCallback(void *baton, const char **argv) { diff --git a/source/Expression/UserExpression.cpp b/source/Expression/UserExpression.cpp index a72e2a07599e..e2d1d2f2b3d2 100644 --- a/source/Expression/UserExpression.cpp +++ b/source/Expression/UserExpression.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include "lldb/Host/Config.h" + #include <stdio.h> #if HAVE_SYS_TYPES_H #include <sys/types.h> @@ -165,9 +167,8 @@ lldb::ExpressionResults UserExpression::Evaluate( Target *target = exe_ctx.GetTargetPtr(); if (!target) { - if (log) - log->Printf("== [UserExpression::Evaluate] Passed a NULL target, can't " - "run expressions."); + LLDB_LOGF(log, "== [UserExpression::Evaluate] Passed a NULL target, can't " + "run expressions."); error.SetErrorString("expression passed a null target"); return lldb::eExpressionSetupError; } @@ -176,9 +177,9 @@ lldb::ExpressionResults UserExpression::Evaluate( if (process == nullptr || process->GetState() != lldb::eStateStopped) { if (execution_policy == eExecutionPolicyAlways) { - if (log) - log->Printf("== [UserExpression::Evaluate] Expression may not run, but " - "is not constant =="); + LLDB_LOGF(log, + "== [UserExpression::Evaluate] Expression may not run, but " + "is not constant =="); error.SetErrorString("expression needed to run but couldn't"); @@ -224,14 +225,14 @@ lldb::ExpressionResults UserExpression::Evaluate( error)); if (error.Fail()) { if (log) - log->Printf("== [UserExpression::Evaluate] Getting expression: %s ==", - error.AsCString()); + LLDB_LOGF(log, "== [UserExpression::Evaluate] Getting expression: %s ==", + error.AsCString()); return lldb::eExpressionSetupError; } if (log) - log->Printf("== [UserExpression::Evaluate] Parsing expression %s ==", - expr.str().c_str()); + LLDB_LOGF(log, "== [UserExpression::Evaluate] Parsing expression %s ==", + expr.str().c_str()); const bool keep_expression_in_memory = true; const bool generate_debug_info = options.GetGenerateDebugInfo(); @@ -310,8 +311,9 @@ lldb::ExpressionResults UserExpression::Evaluate( if (execution_policy == eExecutionPolicyNever && !user_expression_sp->CanInterpret()) { if (log) - log->Printf("== [UserExpression::Evaluate] Expression may not run, but " - "is not constant =="); + LLDB_LOGF(log, + "== [UserExpression::Evaluate] Expression may not run, but " + "is not constant =="); if (!diagnostic_manager.Diagnostics().size()) error.SetExpressionError(lldb::eExpressionSetupError, @@ -332,7 +334,7 @@ lldb::ExpressionResults UserExpression::Evaluate( diagnostic_manager.Clear(); if (log) - log->Printf("== [UserExpression::Evaluate] Executing expression =="); + LLDB_LOGF(log, "== [UserExpression::Evaluate] Executing expression =="); execution_results = user_expression_sp->Execute(diagnostic_manager, exe_ctx, options, @@ -340,8 +342,8 @@ lldb::ExpressionResults UserExpression::Evaluate( if (execution_results != lldb::eExpressionCompleted) { if (log) - log->Printf("== [UserExpression::Evaluate] Execution completed " - "abnormally =="); + LLDB_LOGF(log, "== [UserExpression::Evaluate] Execution completed " + "abnormally =="); if (!diagnostic_manager.Diagnostics().size()) error.SetExpressionError( @@ -354,13 +356,14 @@ lldb::ExpressionResults UserExpression::Evaluate( result_valobj_sp = expr_result->GetValueObject(); if (log) - log->Printf("== [UserExpression::Evaluate] Execution completed " - "normally with result %s ==", - result_valobj_sp->GetValueAsCString()); + LLDB_LOGF(log, + "== [UserExpression::Evaluate] Execution completed " + "normally with result %s ==", + result_valobj_sp->GetValueAsCString()); } else { if (log) - log->Printf("== [UserExpression::Evaluate] Execution completed " - "normally with no result =="); + LLDB_LOGF(log, "== [UserExpression::Evaluate] Execution completed " + "normally with no result =="); error.SetError(UserExpression::kNoResult, lldb::eErrorTypeGeneric); } diff --git a/source/Expression/UtilityFunction.cpp b/source/Expression/UtilityFunction.cpp index eeaeca18da86..aac8b33a6bfa 100644 --- a/source/Expression/UtilityFunction.cpp +++ b/source/Expression/UtilityFunction.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include "lldb/Host/Config.h" + #include <stdio.h> #if HAVE_SYS_TYPES_H #include <sys/types.h> |