48#include "llvm/ADT/DenseMap.h"
49#include "llvm/ADT/StringRef.h"
50#include "llvm/Support/Compiler.h"
51#include "llvm/TargetParser/Triple.h"
59#define DEFAULT_DISASM_BYTE_SIZE 32
65 const char *flavor,
const char *cpu,
67 const char *plugin_name) {
76 if (create_callback) {
77 if (
auto disasm_sp = create_callback(arch, flavor, cpu, features))
81 for (
auto create_callback :
83 if (
auto disasm_sp = create_callback(arch, flavor, cpu, features))
92 const char *cpu,
const char *features,
const char *plugin_name) {
97 if (arch.
GetTriple().getArch() == llvm::Triple::x86 ||
98 arch.
GetTriple().getArch() == llvm::Triple::x86_64)
106 return FindPlugin(arch, flavor, cpu, features, plugin_name);
121 if (is_resolved && resolved_addr.
IsValid())
122 return resolved_addr;
128 const ArchSpec &arch,
const char *plugin_name,
const char *flavor,
129 const char *cpu,
const char *features,
Target &target,
130 llvm::ArrayRef<AddressRange> disasm_ranges,
bool force_live_memory) {
132 target, arch, flavor, cpu, features, plugin_name);
137 size_t bytes_disassembled = 0;
139 bytes_disassembled += disasm_sp->AppendInstructions(
140 target, range.GetBaseAddress(), {Limit::Bytes, range.GetByteSize()},
141 nullptr, force_live_memory);
143 if (bytes_disassembled == 0)
151 const char *flavor,
const char *cpu,
152 const char *features,
const Address &start,
153 const void *src,
size_t src_len,
154 uint32_t num_instructions,
bool data_from_file) {
167 (void)disasm_sp->DecodeInstructions(start, data, 0, num_instructions,
false,
173 const char *plugin_name,
const char *flavor,
174 const char *cpu,
const char *features,
177 bool mixed_source_and_assembly,
178 uint32_t num_mixed_context_lines,
179 uint32_t options,
Stream &strm) {
184 exe_ctx.
GetTargetRef(), arch, flavor, cpu, features, plugin_name));
188 const bool force_live_memory =
true;
189 size_t bytes_disassembled = disasm_sp->ParseInstructions(
190 exe_ctx.
GetTargetRef(), address, limit, &strm, force_live_memory);
191 if (bytes_disassembled == 0)
194 disasm_sp->PrintInstructions(debugger, arch, exe_ctx,
195 mixed_source_and_assembly,
196 num_mixed_context_lines, options, strm);
209 SupportFileNSP func_decl_file_sp = std::make_shared<SupportFile>();
210 uint32_t func_decl_line;
213 if (!func_decl_file_sp)
215 if (!func_decl_file_sp->Equal(*prologue_end_line.
file_sp,
222 decl_line.
file = func_decl_file_sp->GetSpecOnly();
223 decl_line.
line = func_decl_line;
232 std::map<
FileSpec, std::set<uint32_t>> &source_lines_seen) {
234 auto source_lines_seen_pos = source_lines_seen.find(line.
file);
235 if (source_lines_seen_pos == source_lines_seen.end()) {
236 std::set<uint32_t> lines;
237 lines.insert(line.
line);
238 source_lines_seen.emplace(line.
file, lines);
240 source_lines_seen_pos->second.insert(line.
line);
259 avoid_regex = thread_sp->GetSymbolsToAvoidRegexp();
264 OptionValueSP value_sp = target_sp->GetDebugger().GetPropertyValue(
265 &exe_ctx,
"target.process.thread.step-avoid-regexp",
error);
274 if (avoid_regex && sc.
symbol !=
nullptr) {
275 const char *function_name =
278 if (function_name && avoid_regex->
Execute(function_name)) {
292 const bool is_live) {
293 annotation_entity.
is_live = is_live;
296 annotations.push_back(std::move(annotation_entity));
313 std::vector<VariableAnnotation> structured_annotations =
316 std::vector<std::string> events;
317 events.reserve(structured_annotations.size());
320 const llvm::StringRef location =
323 : llvm::StringRef(annotation.location_description));
326 llvm::formatv(
"{0} = {1}", annotation.variable_name, location).str());
332std::vector<VariableAnnotation>
334 std::vector<VariableAnnotation> annotations;
349 const auto mask = eSymbolContextFunction | eSymbolContextBlock;
350 if (!module_sp->ResolveSymbolContextForAddress(iaddr, mask, sc) ||
363 auto filter = [](
Variable *v) ->
bool {
return v && !v->IsArtificial(); };
364 B->AppendVariables(
true,
376 ABI *abi = abi_sp.get();
378 llvm::DIDumpOptions opts;
379 opts.ShowAddresses =
false;
381 opts.PrintRegisterOnly =
static_cast<bool>(abi_sp);
383 llvm::DenseMap<lldb::user_id_t, VariableAnnotation> current_vars;
385 for (
size_t i = 0, e = var_list.
GetSize(); i != e; ++i) {
387 if (!v || v->IsArtificial())
390 const char *nm = v->GetName().AsCString();
391 llvm::StringRef name = nm ? nm :
"<anon>";
401 auto entry = *entry_or_err;
406 llvm::StringRef loc = llvm::StringRef(loc_ss.
GetString()).trim();
410 std::optional<std::string> decl_file;
411 std::optional<uint32_t> decl_line;
412 std::optional<std::string> type_name;
421 if (
Type *type = v->GetType())
422 if (
const char *type_str = type->GetName().AsCString())
423 type_name = type_str;
425 current_vars.try_emplace(
428 entry.expr->GetRegisterKind(), entry.file_range,
429 decl_file, decl_line, type_name});
435 for (
const auto &KV : current_vars) {
440 else if (it->second.location_description != KV.second.location_description)
448 if (!current_vars.count(KV.first))
458 bool mixed_source_and_assembly,
459 uint32_t num_mixed_context_lines,
460 uint32_t options,
Stream &strm) {
464 const uint32_t max_opcode_byte_size =
469 const Address *pc_addr_ptr =
nullptr;
479 const uint32_t scope =
480 eSymbolContextLineEntry | eSymbolContextFunction | eSymbolContextSymbol;
481 const bool use_inline_block_range =
false;
487 disassembly_format = &format;
490 disassembly_format = &format;
501 std::map<FileSpec, std::set<uint32_t>> source_lines_seen;
502 const Symbol *previous_symbol =
nullptr;
504 size_t address_text_size = 0;
505 for (
size_t i = 0; i < num_instructions_found; ++i) {
511 const SymbolContextItem resolve_mask = eSymbolContextFunction |
512 eSymbolContextSymbol |
513 eSymbolContextLineEntry;
514 uint32_t resolved_mask =
515 module_sp->ResolveSymbolContextForAddress(addr, resolve_mask, sc);
519 &exe_ctx, &addr, strmstr);
521 if (cur_line > address_text_size)
522 address_text_size = cur_line;
532 if (sc.
symbol != previous_symbol) {
553 previous_symbol =
nullptr;
555 for (
size_t i = 0; i < num_instructions_found; ++i) {
560 const bool inst_is_at_pc = pc_addr_ptr && addr == *pc_addr_ptr;
567 uint32_t resolved_mask = module_sp->ResolveSymbolContextForAddress(
568 addr, eSymbolContextEverything, sc);
570 if (mixed_source_and_assembly) {
575 if (previous_symbol != sc.
symbol) {
580 if (previous_symbol !=
nullptr)
583 previous_symbol = sc.
symbol;
587 prologue_end_line)) {
589 std::make_shared<SupportFile>();
590 uint32_t func_decl_line;
593 if (func_decl_file_sp &&
594 (func_decl_file_sp->Equal(
597 func_decl_file_sp->Equal(
603 for (uint32_t lineno = func_decl_line;
604 lineno <= prologue_end_line.
line; lineno++) {
606 this_line.
file = func_decl_file_sp->GetSpecOnly();
607 this_line.
line = lineno;
608 source_lines_to_display.
lines.push_back(this_line);
612 if (source_lines_to_display.
lines.size() > 0)
614 source_lines_to_display.
lines.size() - 1;
619 current_source_line_range);
626 current_source_line_range);
640 if (this_line != previous_line) {
642 std::vector<uint32_t> previous_lines;
644 i < num_mixed_context_lines &&
645 (this_line.
line - num_mixed_context_lines) > 0;
648 this_line.
line - num_mixed_context_lines + i;
649 auto pos = source_lines_seen.find(this_line.
file);
650 if (pos != source_lines_seen.end()) {
651 if (pos->second.count(line) == 1) {
652 previous_lines.clear();
654 previous_lines.push_back(line);
658 for (
size_t i = 0; i < previous_lines.size(); i++) {
660 previous_line.
file = this_line.
file;
661 previous_line.
line = previous_lines[i];
662 auto pos = source_lines_seen.find(previous_line.
file);
663 if (pos != source_lines_seen.end()) {
664 pos->second.insert(previous_line.
line);
666 source_lines_to_display.
lines.push_back(previous_line);
669 source_lines_to_display.
lines.push_back(this_line);
671 source_lines_to_display.
lines.size() - 1;
673 for (uint32_t i = 0; i < num_mixed_context_lines; i++) {
676 next_line.
line = this_line.
line + i + 1;
677 auto pos = source_lines_seen.find(next_line.
file);
678 if (pos != source_lines_seen.end()) {
679 if (pos->second.count(next_line.
line) == 1)
681 pos->second.insert(next_line.
line);
683 source_lines_to_display.
lines.push_back(next_line);
686 previous_line = this_line;
696 if (source_lines_to_display.
lines.size() > 0) {
698 for (
size_t idx = 0; idx < source_lines_to_display.
lines.size();
701 const char *line_highlight =
"";
703 line_highlight =
"->";
705 line_highlight =
"**";
709 line_highlight, &strm);
716 const bool show_control_flow_kind =
721 inst->
Dump(&inst_line, max_opcode_byte_size,
true, show_bytes,
722 show_control_flow_kind, &exe_ctx, &sc, &prev_sc,
nullptr,
726 auto annotations = annot.
Annotate(*inst);
727 if (!annotations.empty()) {
728 const size_t annotation_column = 100;
731 inst_line.
PutCString(llvm::join(annotations,
", "));
746 constexpr const char *plugin_name =
nullptr;
747 constexpr const char *flavor =
nullptr;
748 constexpr const char *cpu =
nullptr;
749 constexpr const char *features =
nullptr;
750 constexpr bool mixed_source_and_assembly =
false;
751 constexpr uint32_t num_mixed_context_lines = 0;
752 constexpr uint32_t options = 0;
760 disasm_sp->PrintInstructions(debugger, arch, frame,
761 mixed_source_and_assembly,
762 num_mixed_context_lines, options, strm);
780 if (limit.
value == 0)
783 return Disassemble(debugger, arch, plugin_name, flavor, cpu, features, frame,
785 num_mixed_context_lines, options, strm);
802 switch (instruction_control_flow_kind) {
822 llvm_unreachable(
"Fully covered switch above!");
826 bool show_address,
bool show_bytes,
827 bool show_control_flow_kind,
832 size_t max_address_text_size) {
833 size_t opcode_column_width = 7;
834 const size_t operand_column_width = 25;
851 if (max_opcode_byte_size > 0)
852 m_opcode.Dump(&ss, max_opcode_byte_size * 3 + 1);
858 if (max_opcode_byte_size > 0)
859 m_opcode.Dump(&ss, max_opcode_byte_size * 3 + 1);
865 if (show_control_flow_kind) {
869 instruction_control_flow_kind));
872 bool show_color =
false;
875 show_color = target_sp->GetDebugger().GetUseColor();
882 if (opcode_name.empty())
883 opcode_name =
"<unknown>";
900 opcode_pos + opcode_column_width + operand_column_width,
' ');
908 std::unique_ptr<EmulateInstruction> insn_emulator_up(
910 if (insn_emulator_up) {
912 return insn_emulator_up->EvaluateInstruction(0);
930 auto option_value_sp = std::make_shared<OptionValueArray>(1u << data_type);
934 if (!fgets(buffer, 1023, in_file)) {
936 "Instruction::ReadArray: Error reading file (fgets).\n");
937 option_value_sp.reset();
938 return option_value_sp;
941 std::string line(buffer);
943 size_t len = line.size();
944 if (line[len - 1] ==
'\n') {
945 line[len - 1] =
'\0';
946 line.resize(len - 1);
949 if ((line.size() == 1) && line[0] ==
']') {
957 llvm::StringRef(
"^[ \t]*([^ \t]+)[ \t]*$"));
958 llvm::SmallVector<llvm::StringRef, 2> matches;
959 if (g_reg_exp.
Execute(line, &matches))
960 value = matches[1].str();
967 data_value_sp = std::make_shared<OptionValueUInt64>(0, 0);
968 data_value_sp->SetValueFromString(value);
972 data_value_sp = std::make_shared<OptionValueString>(value.c_str(),
"");
976 option_value_sp->GetAsArray()->InsertValue(idx, data_value_sp);
981 return option_value_sp;
988 auto option_value_sp = std::make_shared<OptionValueDictionary>();
989 static constexpr llvm::StringLiteral encoding_key(
"data_encoding");
994 if (!fgets(buffer, 1023, in_file)) {
996 "Instruction::ReadDictionary: Error reading file (fgets).\n");
997 option_value_sp.reset();
998 return option_value_sp;
1002 std::string line(buffer);
1004 size_t len = line.size();
1005 if (line[len - 1] ==
'\n') {
1006 line[len - 1] =
'\0';
1007 line.resize(len - 1);
1010 if ((line.size() == 1) && (line[0] ==
'}')) {
1017 if (!line.empty()) {
1019 "^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*=[ \t]*(.*)[ \t]*$"));
1021 llvm::SmallVector<llvm::StringRef, 3> matches;
1023 bool reg_exp_success = g_reg_exp.
Execute(line, &matches);
1026 if (reg_exp_success) {
1027 key = matches[1].str();
1028 value = matches[2].str();
1030 out_stream.
Printf(
"Instruction::ReadDictionary: Failure executing "
1031 "regular expression.\n");
1032 option_value_sp.reset();
1033 return option_value_sp;
1039 assert(value.empty() ==
false);
1040 assert(key.empty() ==
false);
1042 if (value[0] ==
'{') {
1043 assert(value.size() == 1);
1047 option_value_sp.reset();
1048 return option_value_sp;
1050 }
else if (value[0] ==
'[') {
1051 assert(value.size() == 1);
1053 value_sp =
ReadArray(in_file, out_stream, data_type);
1055 option_value_sp.reset();
1056 return option_value_sp;
1061 }
else if ((value[0] ==
'0') && (value[1] ==
'x')) {
1062 value_sp = std::make_shared<OptionValueUInt64>(0, 0);
1063 value_sp->SetValueFromString(value);
1065 size_t len = value.size();
1066 if ((value[0] ==
'"') && (value[len - 1] ==
'"'))
1067 value = value.substr(1, len - 2);
1068 value_sp = std::make_shared<OptionValueString>(value.c_str(),
"");
1071 if (key == encoding_key) {
1075 if (llvm::StringRef(value) ==
"uint32_t")
1078 option_value_sp->GetAsDictionary()->SetValueForKey(key, value_sp,
1083 return option_value_sp;
1088 out_stream.
Printf(
"Instruction::TestEmulation: Missing file_name.");
1094 "Instruction::TestEmulation: Attempt to open test file failed.");
1099 if (!fgets(buffer, 255, test_file)) {
1101 "Instruction::TestEmulation: Error reading first line of test file.\n");
1106 if (strncmp(buffer,
"InstructionEmulationState={", 27) != 0) {
1107 out_stream.
Printf(
"Instructin::TestEmulation: Test file does not contain "
1108 "emulation state dictionary\n");
1117 if (!data_dictionary_sp) {
1119 "Instruction::TestEmulation: Error reading Dictionary Object.\n");
1127 data_dictionary_sp->GetAsDictionary();
1128 static constexpr llvm::StringLiteral description_key(
"assembly_string");
1129 static constexpr llvm::StringLiteral triple_key(
"triple");
1134 out_stream.
Printf(
"Instruction::TestEmulation: Test file does not "
1135 "contain description string.\n");
1139 SetDescription(value_sp->GetValueAs<llvm::StringRef>().value_or(
""));
1144 "Instruction::TestEmulation: Test file does not contain triple.\n");
1150 llvm::Triple(value_sp->GetValueAs<llvm::StringRef>().value_or(
"")));
1152 bool success =
false;
1153 std::unique_ptr<EmulateInstruction> insn_emulator_up(
1155 if (insn_emulator_up)
1157 insn_emulator_up->TestEmulation(out_stream, arch, data_dictionary);
1160 out_stream.
Printf(
"Emulation test succeeded.");
1162 out_stream.
Printf(
"Emulation test failed.");
1168 const ArchSpec &arch, uint32_t evaluate_options,
void *baton,
1173 std::unique_ptr<EmulateInstruction> insn_emulator_up(
1175 if (insn_emulator_up) {
1176 insn_emulator_up->SetBaton(baton);
1177 insn_emulator_up->SetCallbacks(read_mem_callback, write_mem_callback,
1178 read_reg_callback, write_reg_callback);
1180 return insn_emulator_up->EvaluateInstruction(evaluate_options);
1192 std::vector<VariableAnnotation> annotations =
1199 std::make_shared<StructuredData::Dictionary>();
1201 dict_sp->AddStringItem(
"variable_name", ann.variable_name);
1202 dict_sp->AddStringItem(
"location_description", ann.location_description);
1203 if (ann.address_range.has_value()) {
1204 const auto &range = *ann.address_range;
1205 dict_sp->AddItem(
"start_address",
1206 std::make_shared<StructuredData::UnsignedInteger>(
1207 range.GetBaseAddress().GetFileAddress()));
1210 std::make_shared<StructuredData::UnsignedInteger>(
1211 range.GetBaseAddress().GetFileAddress() + range.GetByteSize()));
1215 std::make_shared<StructuredData::UnsignedInteger>(ann.register_kind));
1216 if (ann.decl_file.has_value())
1217 dict_sp->AddStringItem(
"decl_file", *ann.decl_file);
1218 if (ann.decl_line.has_value())
1221 std::make_shared<StructuredData::UnsignedInteger>(*ann.decl_line));
1222 if (ann.type_name.has_value())
1223 dict_sp->AddStringItem(
"type_name", *ann.type_name);
1225 array_sp->AddItem(dict_sp);
1238 uint32_t max_inst_size = 0;
1239 collection::const_iterator pos, end;
1242 uint32_t inst_size = (*pos)->GetOpcode().GetByteSize();
1243 if (max_inst_size < inst_size)
1244 max_inst_size = inst_size;
1246 return max_inst_size;
1250 size_t total_byte_size = 0;
1251 collection::const_iterator pos, end;
1254 total_byte_size += (*pos)->GetOpcode().GetByteSize();
1256 return total_byte_size;
1274 bool show_control_flow_kind,
1277 collection::const_iterator pos, begin, end;
1283 disassembly_format = &format;
1286 disassembly_format = &format;
1290 pos != end; ++pos) {
1293 (*pos)->Dump(s, max_opcode_byte_size, show_address, show_bytes,
1294 show_control_flow_kind, exe_ctx,
nullptr,
nullptr,
1295 disassembly_format, 0);
1307 uint32_t start,
bool ignore_calls,
bool *found_calls)
const {
1313 *found_calls =
false;
1314 for (
size_t i = start; i < num_instructions; i++) {
1318 *found_calls =
true;
1333 for (
size_t i = 0; i < num_instructions; i++) {
1352 bool force_live_memory) {
1360 byte_size *=
m_arch.GetMaximumOpcodeByteSize();
1361 auto data_sp = std::make_shared<DataBufferHeap>(byte_size,
'\0');
1365 const size_t bytes_read =
1366 target.
ReadMemory(start, data_sp->GetBytes(), data_sp->GetByteSize(),
1367 error, force_live_memory, &load_addr);
1370 if (bytes_read == 0) {
1371 if (error_strm_ptr) {
1372 if (
const char *error_cstr =
error.AsCString())
1373 error_strm_ptr->
Printf(
"error: %s\n", error_cstr);
1378 if (bytes_read != data_sp->GetByteSize())
1379 data_sp->SetByteSize(bytes_read);
1381 m_arch.GetAddressByteSize());
1385 true, data_from_file);
1391 if (flavor ==
nullptr)
1399 std::string thumb_arch_name(arch.GetTriple().getArchName().str());
1401 if (thumb_arch_name.size() > 3) {
1402 thumb_arch_name.erase(0, 3);
1403 thumb_arch_name.insert(0,
"thumb");
1405 m_arch.SetTriple(thumb_arch_name.c_str());
1455 switch (opcode_size) {
1457 uint8_t value8 = *((uint8_t *)opcode_data);
1462 uint16_t value16 = *((uint16_t *)opcode_data);
1467 uint32_t value32 = *((uint32_t *)opcode_data);
1472 uint64_t value64 = *((uint64_t *)opcode_data);
1544 return (base(op) && op.m_children.size() == 2 &&
1545 ((left(op.m_children[0]) && right(op.m_children[1])) ||
1546 (left(op.m_children[1]) && right(op.m_children[0]))));
1555 return (base(op) && op.m_children.size() == 1 && child(op.m_children[0]));
1574 reg = op.m_register;
1583 ((op.m_negative && op.m_immediate == (uint64_t)-imm) ||
1584 (!op.m_negative && op.m_immediate == (uint64_t)imm)));
1594 if (op.m_negative) {
1595 imm = -((int64_t)op.m_immediate);
1597 imm = ((int64_t)op.m_immediate);
static llvm::raw_ostream & error(Stream &strm)
static Address ResolveAddress(Target &target, const Address &addr)
static constexpr const llvm::StringLiteral kUndefLocationFormatted
static constexpr const llvm::StringLiteral kUndefLocation
static void AddVariableAnnotationToVector(std::vector< VariableAnnotation > &annotations, VariableAnnotation annotation_entity, const bool is_live)
#define DEFAULT_DISASM_BYTE_SIZE
#define LLDB_SCOPED_TIMERF(...)
static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch)
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
bool ContainsFileAddress(const Address &so_addr) const
Check if a section offset address is contained in this range.
void SetByteSize(lldb::addr_t byte_size)
Set accessor for the byte size of this range.
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
A section + offset based address class.
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
lldb::addr_t GetFileAddress() const
Get the file address.
lldb::addr_t GetOffset() const
Get the section relative offset value.
bool IsValid() const
Check if the object state is valid.
bool IsSectionOffset() const
Check if an address is section offset.
An architecture specification class.
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool IsAlwaysThumbInstructions() const
Detect whether this architecture uses thumb code exclusively.
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
A class that describes a single lexical block.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
std::optional< DWARFExpressionEntry > GetExpressionEntryAtAddress(lldb::addr_t func_load_addr, lldb::addr_t load_addr) const
Returns a DWARFExpressionEntry whose file_range contains the given load‐address.
bool IsValid() const
Return true if the location expression contains data.
A class to manage flag bits.
FormatEntity::Entry GetDisassemblyFormat() const
SourceManager & GetSourceManager()
static bool FormatDisassemblerAddress(const FormatEntity::Entry *format, const SymbolContext *sc, const SymbolContext *prev_sc, const ExecutionContext *exe_ctx, const Address *addr, Stream &s)
A class that describes the declaration location of a lldb object.
uint32_t GetLine() const
Get accessor for the declaration line number.
FileSpec & GetFile()
Get accessor for file specification.
static lldb::DisassemblerSP FindPluginForTarget(const Target &target, const ArchSpec &arch, const char *flavor, const char *cpu, const char *features, const char *plugin_name)
static lldb::DisassemblerSP DisassembleRange(const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, Target &target, llvm::ArrayRef< AddressRange > disasm_ranges, bool force_live_memory=false)
static lldb::DisassemblerSP FindPlugin(const ArchSpec &arch, const char *flavor, const char *cpu, const char *features, const char *plugin_name)
InstructionList m_instruction_list
void PrintInstructions(Debugger &debugger, const ArchSpec &arch, const ExecutionContext &exe_ctx, bool mixed_source_and_assembly, uint32_t num_mixed_context_lines, uint32_t options, Stream &strm)
static bool Disassemble(Debugger &debugger, const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, const ExecutionContext &exe_ctx, const Address &start, Limit limit, bool mixed_source_and_assembly, uint32_t num_mixed_context_lines, uint32_t options, Stream &strm)
@ eOptionVariableAnnotations
@ eOptionMarkPCSourceLine
@ eOptionShowControlFlowKind
size_t AppendInstructions(Target &target, Address address, Limit limit, Stream *error_strm_ptr, bool force_live_memory)
static void AddLineToSourceLineTables(SourceLine &line, std::map< FileSpec, std::set< uint32_t > > &source_lines_seen)
static bool ElideMixedSourceAndDisassemblyLine(const ExecutionContext &exe_ctx, const SymbolContext &sc, SourceLine &line)
Disassembler(const ArchSpec &arch, const char *flavor)
static SourceLine GetFunctionDeclLineEntry(const SymbolContext &sc)
virtual size_t DecodeInstructions(const Address &base_addr, const DataExtractor &data, lldb::offset_t data_offset, size_t num_instructions, bool append, bool data_from_file)=0
InstructionList & GetInstructionList()
static lldb::DisassemblerSP DisassembleBytes(const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, const Address &start, const void *bytes, size_t length, uint32_t max_num_instructions, bool data_from_file)
bool(* WriteRegisterCallback)(EmulateInstruction *instruction, void *baton, const Context &context, const RegisterInfo *reg_info, const RegisterValue ®_value)
size_t(* WriteMemoryCallback)(EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, const void *dst, size_t length)
size_t(* ReadMemoryCallback)(EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, void *dst, size_t length)
bool(* ReadRegisterCallback)(EmulateInstruction *instruction, void *baton, const RegisterInfo *reg_info, RegisterValue ®_value)
static EmulateInstruction * FindPlugin(const ArchSpec &arch, InstructionType supported_inst_type, const char *plugin_name)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
const lldb::ThreadSP & GetThreadSP() const
Get accessor to get the thread shared pointer.
bool HasTargetScope() const
Returns true the ExecutionContext object contains a valid target.
Target & GetTargetRef() const
Returns a reference to the target object.
const ConstString & GetFilename() const
Filename string const get accessor.
static FileSystem & Instance()
FILE * Fopen(const char *path, const char *mode)
Wraps fopen in a platform-independent way.
const Address & GetAddress() const
Return the address of the function (its entry point).
void GetStartLineSourceInfo(SupportFileNSP &source_file_sp, uint32_t &line_no)
Find the file and line number of the source location of the start of the function.
AddressRanges GetAddressRanges()
void Append(lldb::InstructionSP &inst_sp)
uint32_t GetIndexOfInstructionAtAddress(const Address &addr)
lldb::InstructionSP GetInstructionAtIndex(size_t idx) const
uint32_t GetIndexOfInstructionAtLoadAddress(lldb::addr_t load_addr, Target &target)
size_t GetTotalByteSize() const
collection m_instructions
lldb::InstructionSP GetInstructionAtAddress(const Address &addr)
Get the instruction at the given address.
void Dump(Stream *s, bool show_address, bool show_bytes, bool show_control_flow_kind, const ExecutionContext *exe_ctx)
uint32_t GetIndexOfNextBranchInstruction(uint32_t start, bool ignore_calls, bool *found_calls) const
Get the index of the next branch instruction.
uint32_t GetMaxOpcocdeByteSize() const
uint32_t GetData(DataExtractor &data)
Instruction(const Address &address, AddressClass addr_class=AddressClass::eInvalid)
virtual bool HasDelaySlot()
AddressClass m_address_class
static const char * GetNameForInstructionControlFlowKind(lldb::InstructionControlFlowKind instruction_control_flow_kind)
std::string m_markup_mnemonics
virtual bool TestEmulation(Stream &stream, const char *test_file_name)
virtual lldb::InstructionControlFlowKind GetControlFlowKind(const ExecutionContext *exe_ctx)
void CalculateMnemonicOperandsAndCommentIfNeeded(const ExecutionContext *exe_ctx)
StructuredData::ArraySP GetVariableAnnotations()
Get variable annotations for this instruction as structured data.
lldb::OptionValueSP ReadArray(FILE *in_file, Stream &out_stream, OptionValue::Type data_type)
const Address & GetAddress() const
bool DumpEmulation(const ArchSpec &arch)
lldb::OptionValueSP ReadDictionary(FILE *in_file, Stream &out_stream)
virtual void SetDescription(llvm::StringRef)
const Opcode & GetOpcode() const
std::string m_opcode_name
std::string m_markup_opcode_name
AddressClass GetAddressClass()
virtual void Dump(Stream *s, uint32_t max_opcode_byte_size, bool show_address, bool show_bytes, bool show_control_flow_kind, const ExecutionContext *exe_ctx, const SymbolContext *sym_ctx, const SymbolContext *prev_sym_ctx, const FormatEntity::Entry *disassembly_addr_format, size_t max_address_text_size)
Dump the text representation of this Instruction to a Stream.
bool Emulate(const ArchSpec &arch, uint32_t evaluate_options, void *baton, EmulateInstruction::ReadMemoryCallback read_mem_callback, EmulateInstruction::WriteMemoryCallback write_mem_calback, EmulateInstruction::ReadRegisterCallback read_reg_callback, EmulateInstruction::WriteRegisterCallback write_reg_callback)
bool m_calculated_strings
@ ePreferDemangledWithoutArguments
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr) const
lldb::OptionValueSP GetValueForKey(llvm::StringRef key) const
const RegularExpression * GetCurrentValue() const
static llvm::SmallVector< DisassemblerCreateInstance > GetDisassemblerCreateCallbacks()
static DisassemblerCreateInstance GetDisassemblerCreateCallbackForPluginName(llvm::StringRef name)
std::string m_description
void SetOpcode(size_t opcode_size, void *opcode_data)
void SetDescription(llvm::StringRef description) override
bool IsAuthenticated() override
bool IsBarrier() override
bool HasDelaySlot() override
size_t Decode(const Disassembler &disassembler, const DataExtractor &data, lldb::offset_t data_offset) override
~PseudoInstruction() override
bool DoesBranch() override
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
size_t DisplaySourceLinesWithLineNumbers(SupportFileNSP support_file_nsp, uint32_t line, uint32_t column, uint32_t context_before, uint32_t context_after, const char *current_line_cstr, Stream *s, const SymbolContextList *bp_locs=nullptr, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown)
This base class provides an interface to stack frames.
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
virtual const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
lldb::TargetSP CalculateTarget() override
size_t GetSizeOfLastLine() const
llvm::StringRef GetString() const
void FillLastLineToColumn(uint32_t column, char fill_char)
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Array > ArraySP
@ eEqualFileSpecAndChecksumIfSet
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
ConstString GetFunctionName(Mangled::NamePreference preference=Mangled::ePreferDemangled) const
Find a name of the innermost function for the symbol context.
Block * block
The Block for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
void Clear(bool clear_target)
Clear the object's state.
bool GetAddressRange(uint32_t scope, uint32_t range_idx, bool use_inline_block_range, AddressRange &range) const
Get the address range contained within a symbol context.
Symbol * symbol
The Symbol for a given query.
LineEntry line_entry
The LineEntry for a given query.
bool ValueIsAddress() const
Address & GetAddressRef()
lldb::addr_t GetByteSize() const
const char * GetDisassemblyFeatures() const
const char * GetDisassemblyFlavor() const
const char * GetDisassemblyCPU() const
Debugger & GetDebugger() const
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
virtual size_t ReadMemory(const Address &addr, void *dst, size_t dst_len, Status &error, bool force_live_memory=false, lldb::addr_t *load_addr_ptr=nullptr, bool *did_read_live_memory=nullptr)
const ModuleList & GetImages() const
Get accessor for the images for this process.
Tracks live variable annotations across instructions and produces per-instruction "events" like name ...
std::vector< std::string > Annotate(Instruction &inst)
Compute annotation strings for a single instruction and update m_live_vars.
std::vector< VariableAnnotation > AnnotateStructured(Instruction &inst)
Returns structured data for all variables relevant at this instruction.
llvm::DenseMap< lldb::user_id_t, VariableAnnotation > m_live_vars
lldb::VariableSP GetVariableAtIndex(size_t idx) const
#define LLDB_INVALID_ADDRESS
std::function< bool(const Instruction::Operand &)> MatchRegOp(const RegisterInfo &info)
std::function< bool(const Instruction::Operand &)> FetchRegOp(ConstString ®)
std::function< bool(const Instruction::Operand &)> MatchImmOp(int64_t imm)
std::function< bool(const Instruction::Operand &)> FetchImmOp(int64_t &imm)
std::function< bool(const Instruction::Operand &)> MatchOpType(Instruction::Operand::Type type)
std::function< bool(const Instruction::Operand &)> MatchBinaryOp(std::function< bool(const Instruction::Operand &)> base, std::function< bool(const Instruction::Operand &)> left, std::function< bool(const Instruction::Operand &)> right)
std::function< bool(const Instruction::Operand &)> MatchUnaryOp(std::function< bool(const Instruction::Operand &)> base, std::function< bool(const Instruction::Operand &)> child)
A class that represents a running process on the host machine.
NonNullSharedPtr< lldb_private::SupportFile > SupportFileNSP
lldb::DisassemblerSP(* DisassemblerCreateInstance)(const ArchSpec &arch, const char *flavor, const char *cpu, const char *features)
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::Instruction > InstructionSP
std::shared_ptr< lldb_private::Disassembler > DisassemblerSP
InstructionControlFlowKind
Architecture-agnostic categorization of instructions for traversing the control flow of a trace.
@ eInstructionControlFlowKindReturn
The instruction is a near (function) return.
@ eInstructionControlFlowKindFarJump
The instruction is a jump-like far transfer.
@ eInstructionControlFlowKindOther
The instruction is something not listed below, i.e.
@ eInstructionControlFlowKindFarCall
The instruction is a call-like far transfer.
@ eInstructionControlFlowKindFarReturn
The instruction is a return-like far transfer.
@ eInstructionControlFlowKindUnknown
The instruction could not be classified.
@ eInstructionControlFlowKindJump
The instruction is a near unconditional jump.
@ eInstructionControlFlowKindCall
The instruction is a near (function) call.
@ eInstructionControlFlowKindCondJump
The instruction is a near conditional jump.
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::OptionValue > OptionValueSP
enum lldb_private::Disassembler::Limit::@153225075164054222165007100131150321273323317332 kind
size_t current_source_line
std::vector< SourceLine > lines
bool print_source_context_end_eol
enum lldb_private::Instruction::Operand::Type m_type
static Operand BuildImmediate(lldb::addr_t imm, bool neg)
static Operand BuildDereference(const Operand &ref)
std::vector< Operand > m_children
static Operand BuildProduct(const Operand &lhs, const Operand &rhs)
static Operand BuildSum(const Operand &lhs, const Operand &rhs)
static Operand BuildRegister(ConstString &r)
A line table entry class.
uint16_t column
The column number of the source line, or zero if there is no column information.
bool IsValid() const
Check if a line entry object is valid.
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
const FileSpec & GetFile() const
Helper to access the file.
SupportFileNSP file_sp
The source file, possibly mapped by the target.source-map setting.
SupportFileNSP original_file_sp
The original source file, from debug info.
Every register is described in detail including its name, alternate name (optional),...
const char * alt_name
Alternate name of this register, can be NULL.
const char * name
Name of this register, can't be NULL.
Structured data for a single variable annotation.
bool is_live
Whether variable is live at this instruction.
std::string location_description
Location description (e.g., "r15", "undef", "const_0").