49#include "llvm/ADT/DenseMap.h"
50#include "llvm/ADT/StringRef.h"
51#include "llvm/Support/Compiler.h"
52#include "llvm/TargetParser/Triple.h"
60#define DEFAULT_DISASM_BYTE_SIZE 32
66 const char *flavor,
const char *cpu,
68 const char *plugin_name) {
77 if (create_callback) {
78 if (
auto disasm_sp = create_callback(arch, flavor, cpu, features))
82 for (
auto create_callback :
84 if (
auto disasm_sp = create_callback(arch, flavor, cpu, features))
93 const char *cpu,
const char *features,
const char *plugin_name) {
98 if (arch.
GetTriple().getArch() == llvm::Triple::x86 ||
99 arch.
GetTriple().getArch() == llvm::Triple::x86_64)
107 return FindPlugin(arch, flavor, cpu, features, plugin_name);
122 if (is_resolved && resolved_addr.
IsValid())
123 return resolved_addr;
129 const ArchSpec &arch,
const char *plugin_name,
const char *flavor,
130 const char *cpu,
const char *features,
Target &target,
131 llvm::ArrayRef<AddressRange> disasm_ranges,
bool force_live_memory) {
133 target, arch, flavor, cpu, features, plugin_name);
138 size_t bytes_disassembled = 0;
140 bytes_disassembled += disasm_sp->AppendInstructions(
141 target, range.GetBaseAddress(), {Limit::Bytes, range.GetByteSize()},
142 nullptr, force_live_memory);
144 if (bytes_disassembled == 0)
152 const char *flavor,
const char *cpu,
153 const char *features,
const Address &start,
154 const void *src,
size_t src_len,
155 uint32_t num_instructions,
bool data_from_file) {
168 (void)disasm_sp->DecodeInstructions(start, data, 0, num_instructions,
false,
174 const char *plugin_name,
const char *flavor,
175 const char *cpu,
const char *features,
178 bool mixed_source_and_assembly,
179 uint32_t num_mixed_context_lines,
180 uint32_t options,
Stream &strm) {
185 exe_ctx.
GetTargetRef(), arch, flavor, cpu, features, plugin_name));
189 const bool force_live_memory =
true;
190 size_t bytes_disassembled = disasm_sp->ParseInstructions(
191 exe_ctx.
GetTargetRef(), address, limit, &strm, force_live_memory);
192 if (bytes_disassembled == 0)
195 disasm_sp->PrintInstructions(debugger, arch, exe_ctx,
196 mixed_source_and_assembly,
197 num_mixed_context_lines, options, strm);
210 SupportFileNSP func_decl_file_sp = std::make_shared<SupportFile>();
211 uint32_t func_decl_line;
214 if (!func_decl_file_sp)
216 if (!func_decl_file_sp->Equal(*prologue_end_line.
file_sp,
223 decl_line.
file = func_decl_file_sp->GetSpecOnly();
224 decl_line.
line = func_decl_line;
233 std::map<
FileSpec, std::set<uint32_t>> &source_lines_seen) {
235 auto source_lines_seen_pos = source_lines_seen.find(line.
file);
236 if (source_lines_seen_pos == source_lines_seen.end()) {
237 std::set<uint32_t> lines;
238 lines.insert(line.
line);
239 source_lines_seen.emplace(line.
file, lines);
241 source_lines_seen_pos->second.insert(line.
line);
260 avoid_regex = thread_sp->GetSymbolsToAvoidRegexp();
265 OptionValueSP value_sp = target_sp->GetDebugger().GetPropertyValue(
266 &exe_ctx,
"target.process.thread.step-avoid-regexp",
error);
275 if (avoid_regex && sc.
symbol !=
nullptr) {
276 const char *function_name =
279 if (function_name && avoid_regex->
Execute(function_name)) {
293 const bool is_live) {
294 annotation_entity.
is_live = is_live;
297 annotations.push_back(std::move(annotation_entity));
314 std::vector<VariableAnnotation> structured_annotations =
317 std::vector<std::string> events;
318 events.reserve(structured_annotations.size());
321 const llvm::StringRef location =
324 : llvm::StringRef(annotation.location_description));
327 llvm::formatv(
"{0} = {1}", annotation.variable_name, location).str());
333std::vector<VariableAnnotation>
335 std::vector<VariableAnnotation> annotations;
350 const auto mask = eSymbolContextFunction | eSymbolContextBlock;
351 if (!module_sp->ResolveSymbolContextForAddress(iaddr, mask, sc) ||
364 auto filter = [](
Variable *v) ->
bool {
return v && !v->IsArtificial(); };
365 B->AppendVariables(
true,
377 ABI *abi = abi_sp.get();
379 llvm::DIDumpOptions opts;
380 opts.ShowAddresses =
false;
382 opts.PrintRegisterOnly =
static_cast<bool>(abi_sp);
384 llvm::DenseMap<lldb::user_id_t, VariableAnnotation> current_vars;
386 for (
size_t i = 0, e = var_list.
GetSize(); i != e; ++i) {
388 if (!v || v->IsArtificial())
391 const char *nm = v->GetName().AsCString(
nullptr);
392 llvm::StringRef name = nm ? nm :
"<anon>";
402 auto entry = *entry_or_err;
407 llvm::StringRef loc = llvm::StringRef(loc_ss.
GetString()).trim();
411 std::optional<std::string> decl_file;
412 std::optional<uint32_t> decl_line;
413 std::optional<std::string> type_name;
422 if (
Type *type = v->GetType())
423 if (
const char *type_str = type->GetName().AsCString(
nullptr))
424 type_name = type_str;
426 current_vars.try_emplace(
429 entry.expr->GetRegisterKind(), entry.file_range,
430 decl_file, decl_line, type_name});
436 for (
const auto &KV : current_vars) {
441 else if (it->second.location_description != KV.second.location_description)
449 if (!current_vars.count(KV.first))
459 bool mixed_source_and_assembly,
460 uint32_t num_mixed_context_lines,
461 uint32_t options,
Stream &strm) {
465 const uint32_t max_opcode_byte_size =
470 const Address *pc_addr_ptr =
nullptr;
480 const uint32_t scope =
481 eSymbolContextLineEntry | eSymbolContextFunction | eSymbolContextSymbol;
482 const bool use_inline_block_range =
false;
488 disassembly_format = &format;
491 disassembly_format = &format;
502 std::map<FileSpec, std::set<uint32_t>> source_lines_seen;
503 const Symbol *previous_symbol =
nullptr;
505 size_t address_text_size = 0;
506 for (
size_t i = 0; i < num_instructions_found; ++i) {
512 const SymbolContextItem resolve_mask = eSymbolContextFunction |
513 eSymbolContextSymbol |
514 eSymbolContextLineEntry;
515 uint32_t resolved_mask =
516 module_sp->ResolveSymbolContextForAddress(addr, resolve_mask, sc);
520 &exe_ctx, &addr, strmstr);
522 if (cur_line > address_text_size)
523 address_text_size = cur_line;
533 if (sc.
symbol != previous_symbol) {
554 previous_symbol =
nullptr;
556 for (
size_t i = 0; i < num_instructions_found; ++i) {
561 const bool inst_is_at_pc = pc_addr_ptr && addr == *pc_addr_ptr;
568 uint32_t resolved_mask = module_sp->ResolveSymbolContextForAddress(
569 addr, eSymbolContextEverything, sc);
571 if (mixed_source_and_assembly) {
576 if (previous_symbol != sc.
symbol) {
581 if (previous_symbol !=
nullptr)
584 previous_symbol = sc.
symbol;
588 prologue_end_line)) {
590 std::make_shared<SupportFile>();
591 uint32_t func_decl_line;
594 if (func_decl_file_sp &&
595 (func_decl_file_sp->Equal(
598 func_decl_file_sp->Equal(
604 for (uint32_t lineno = func_decl_line;
605 lineno <= prologue_end_line.
line; lineno++) {
607 this_line.
file = func_decl_file_sp->GetSpecOnly();
608 this_line.
line = lineno;
609 source_lines_to_display.
lines.push_back(this_line);
613 if (source_lines_to_display.
lines.size() > 0)
615 source_lines_to_display.
lines.size() - 1;
620 current_source_line_range);
627 current_source_line_range);
641 if (this_line != previous_line) {
643 std::vector<uint32_t> previous_lines;
645 i < num_mixed_context_lines &&
646 (this_line.
line - num_mixed_context_lines) > 0;
649 this_line.
line - num_mixed_context_lines + i;
650 auto pos = source_lines_seen.find(this_line.
file);
651 if (pos != source_lines_seen.end()) {
652 if (pos->second.count(line) == 1) {
653 previous_lines.clear();
655 previous_lines.push_back(line);
659 for (
size_t i = 0; i < previous_lines.size(); i++) {
661 previous_line.
file = this_line.
file;
662 previous_line.
line = previous_lines[i];
663 auto pos = source_lines_seen.find(previous_line.
file);
664 if (pos != source_lines_seen.end()) {
665 pos->second.insert(previous_line.
line);
667 source_lines_to_display.
lines.push_back(previous_line);
670 source_lines_to_display.
lines.push_back(this_line);
672 source_lines_to_display.
lines.size() - 1;
674 for (uint32_t i = 0; i < num_mixed_context_lines; i++) {
677 next_line.
line = this_line.
line + i + 1;
678 auto pos = source_lines_seen.find(next_line.
file);
679 if (pos != source_lines_seen.end()) {
680 if (pos->second.count(next_line.
line) == 1)
682 pos->second.insert(next_line.
line);
684 source_lines_to_display.
lines.push_back(next_line);
687 previous_line = this_line;
697 if (source_lines_to_display.
lines.size() > 0) {
699 for (
size_t idx = 0; idx < source_lines_to_display.
lines.size();
702 const char *line_highlight =
"";
704 line_highlight =
"->";
706 line_highlight =
"**";
710 line_highlight, &strm);
717 const bool show_control_flow_kind =
722 inst->
Dump(&inst_line, max_opcode_byte_size,
true, show_bytes,
723 show_control_flow_kind, &exe_ctx, &sc, &prev_sc,
nullptr,
727 auto annotations = annot.
Annotate(*inst);
728 if (!annotations.empty()) {
729 const size_t annotation_column = 100;
732 inst_line.
PutCString(llvm::join(annotations,
", "));
747 constexpr const char *plugin_name =
nullptr;
748 constexpr const char *flavor =
nullptr;
749 constexpr const char *cpu =
nullptr;
750 constexpr const char *features =
nullptr;
751 constexpr bool mixed_source_and_assembly =
false;
752 constexpr uint32_t num_mixed_context_lines = 0;
753 constexpr uint32_t options = 0;
761 disasm_sp->PrintInstructions(debugger, arch, frame,
762 mixed_source_and_assembly,
763 num_mixed_context_lines, options, strm);
781 if (limit.
value == 0)
784 return Disassemble(debugger, arch, plugin_name, flavor, cpu, features, frame,
786 num_mixed_context_lines, options, strm);
803 switch (instruction_control_flow_kind) {
823 llvm_unreachable(
"Fully covered switch above!");
827 bool show_address,
bool show_bytes,
828 bool show_control_flow_kind,
833 size_t max_address_text_size) {
834 size_t opcode_column_width = 7;
835 const size_t operand_column_width = 25;
852 if (max_opcode_byte_size > 0)
853 m_opcode.Dump(&ss, max_opcode_byte_size * 3 + 1);
859 if (max_opcode_byte_size > 0)
860 m_opcode.Dump(&ss, max_opcode_byte_size * 3 + 1);
866 if (show_control_flow_kind) {
870 instruction_control_flow_kind));
873 bool show_color =
false;
876 show_color = target_sp->GetDebugger().GetUseColor();
883 if (opcode_name.empty())
884 opcode_name =
"<unknown>";
901 opcode_pos + opcode_column_width + operand_column_width,
' ');
909 std::unique_ptr<EmulateInstruction> insn_emulator_up(
911 if (insn_emulator_up) {
913 return insn_emulator_up->EvaluateInstruction(0);
931 auto option_value_sp = std::make_shared<OptionValueArray>(1u << data_type);
935 if (!fgets(buffer, 1023, in_file)) {
937 "Instruction::ReadArray: Error reading file (fgets).\n");
938 option_value_sp.reset();
939 return option_value_sp;
942 std::string line(buffer);
944 size_t len = line.size();
945 if (line[len - 1] ==
'\n') {
946 line[len - 1] =
'\0';
947 line.resize(len - 1);
950 if ((line.size() == 1) && line[0] ==
']') {
958 llvm::StringRef(
"^[ \t]*([^ \t]+)[ \t]*$"));
959 llvm::SmallVector<llvm::StringRef, 2> matches;
960 if (g_reg_exp.
Execute(line, &matches))
961 value = matches[1].str();
968 data_value_sp = std::make_shared<OptionValueUInt64>(0, 0);
969 data_value_sp->SetValueFromString(value);
973 data_value_sp = std::make_shared<OptionValueString>(value.c_str(),
"");
977 option_value_sp->GetAsArray()->InsertValue(idx, data_value_sp);
982 return option_value_sp;
989 auto option_value_sp = std::make_shared<OptionValueDictionary>();
990 static constexpr llvm::StringLiteral encoding_key(
"data_encoding");
995 if (!fgets(buffer, 1023, in_file)) {
997 "Instruction::ReadDictionary: Error reading file (fgets).\n");
998 option_value_sp.reset();
999 return option_value_sp;
1003 std::string line(buffer);
1005 size_t len = line.size();
1006 if (line[len - 1] ==
'\n') {
1007 line[len - 1] =
'\0';
1008 line.resize(len - 1);
1011 if ((line.size() == 1) && (line[0] ==
'}')) {
1018 if (!line.empty()) {
1020 "^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*=[ \t]*(.*)[ \t]*$"));
1022 llvm::SmallVector<llvm::StringRef, 3> matches;
1024 bool reg_exp_success = g_reg_exp.
Execute(line, &matches);
1027 if (reg_exp_success) {
1028 key = matches[1].str();
1029 value = matches[2].str();
1031 out_stream.
Printf(
"Instruction::ReadDictionary: Failure executing "
1032 "regular expression.\n");
1033 option_value_sp.reset();
1034 return option_value_sp;
1040 assert(value.empty() ==
false);
1041 assert(key.empty() ==
false);
1043 if (value[0] ==
'{') {
1044 assert(value.size() == 1);
1048 option_value_sp.reset();
1049 return option_value_sp;
1051 }
else if (value[0] ==
'[') {
1052 assert(value.size() == 1);
1054 value_sp =
ReadArray(in_file, out_stream, data_type);
1056 option_value_sp.reset();
1057 return option_value_sp;
1062 }
else if ((value[0] ==
'0') && (value[1] ==
'x')) {
1063 value_sp = std::make_shared<OptionValueUInt64>(0, 0);
1064 value_sp->SetValueFromString(value);
1066 size_t len = value.size();
1067 if ((value[0] ==
'"') && (value[len - 1] ==
'"'))
1068 value = value.substr(1, len - 2);
1069 value_sp = std::make_shared<OptionValueString>(value.c_str(),
"");
1072 if (key == encoding_key) {
1076 if (llvm::StringRef(value) ==
"uint32_t")
1079 option_value_sp->GetAsDictionary()->SetValueForKey(key, value_sp,
1084 return option_value_sp;
1089 out_stream.
PutCString(
"Instruction::TestEmulation: Missing file_name.");
1095 "Instruction::TestEmulation: Attempt to open test file failed.");
1100 if (!fgets(buffer, 255, test_file)) {
1102 "Instruction::TestEmulation: Error reading first line of test file.\n");
1107 if (strncmp(buffer,
"InstructionEmulationState={", 27) != 0) {
1108 out_stream.
Printf(
"Instructin::TestEmulation: Test file does not contain "
1109 "emulation state dictionary\n");
1118 if (!data_dictionary_sp) {
1120 "Instruction::TestEmulation: Error reading Dictionary Object.\n");
1128 data_dictionary_sp->GetAsDictionary();
1129 static constexpr llvm::StringLiteral description_key(
"assembly_string");
1130 static constexpr llvm::StringLiteral triple_key(
"triple");
1135 out_stream.
Printf(
"Instruction::TestEmulation: Test file does not "
1136 "contain description string.\n");
1140 SetDescription(value_sp->GetValueAs<llvm::StringRef>().value_or(
""));
1145 "Instruction::TestEmulation: Test file does not contain triple.\n");
1151 llvm::Triple(value_sp->GetValueAs<llvm::StringRef>().value_or(
"")));
1153 bool success =
false;
1154 std::unique_ptr<EmulateInstruction> insn_emulator_up(
1156 if (insn_emulator_up)
1158 insn_emulator_up->TestEmulation(out_stream, arch, data_dictionary);
1161 out_stream.
PutCString(
"Emulation test succeeded.");
1163 out_stream.
PutCString(
"Emulation test failed.");
1169 const ArchSpec &arch, uint32_t evaluate_options,
void *baton,
1174 std::unique_ptr<EmulateInstruction> insn_emulator_up(
1176 if (insn_emulator_up) {
1177 insn_emulator_up->SetBaton(baton);
1178 insn_emulator_up->SetCallbacks(read_mem_callback, write_mem_callback,
1179 read_reg_callback, write_reg_callback);
1181 return insn_emulator_up->EvaluateInstruction(evaluate_options);
1193 std::vector<VariableAnnotation> annotations =
1200 std::make_shared<StructuredData::Dictionary>();
1202 dict_sp->AddStringItem(
"variable_name", ann.variable_name);
1203 dict_sp->AddStringItem(
"location_description", ann.location_description);
1204 if (ann.address_range.has_value()) {
1205 const auto &range = *ann.address_range;
1206 dict_sp->AddItem(
"start_address",
1207 std::make_shared<StructuredData::UnsignedInteger>(
1208 range.GetBaseAddress().GetFileAddress()));
1211 std::make_shared<StructuredData::UnsignedInteger>(
1212 range.GetBaseAddress().GetFileAddress() + range.GetByteSize()));
1216 std::make_shared<StructuredData::UnsignedInteger>(ann.register_kind));
1217 if (ann.decl_file.has_value())
1218 dict_sp->AddStringItem(
"decl_file", *ann.decl_file);
1219 if (ann.decl_line.has_value())
1222 std::make_shared<StructuredData::UnsignedInteger>(*ann.decl_line));
1223 if (ann.type_name.has_value())
1224 dict_sp->AddStringItem(
"type_name", *ann.type_name);
1226 array_sp->AddItem(dict_sp);
1239 uint32_t max_inst_size = 0;
1240 collection::const_iterator pos, end;
1243 uint32_t inst_size = (*pos)->GetOpcode().GetByteSize();
1244 if (max_inst_size < inst_size)
1245 max_inst_size = inst_size;
1247 return max_inst_size;
1251 size_t total_byte_size = 0;
1252 collection::const_iterator pos, end;
1255 total_byte_size += (*pos)->GetOpcode().GetByteSize();
1257 return total_byte_size;
1275 bool show_control_flow_kind,
1278 collection::const_iterator pos, begin, end;
1284 disassembly_format = &format;
1287 disassembly_format = &format;
1291 pos != end; ++pos) {
1294 (*pos)->Dump(s, max_opcode_byte_size, show_address, show_bytes,
1295 show_control_flow_kind, exe_ctx,
nullptr,
nullptr,
1296 disassembly_format, 0);
1308 uint32_t start,
bool ignore_calls,
bool *found_calls)
const {
1314 *found_calls =
false;
1315 for (
size_t i = start; i < num_instructions; i++) {
1319 *found_calls =
true;
1334 for (
size_t i = 0; i < num_instructions; i++) {
1353 bool force_live_memory) {
1361 const Address first_insn = arch->SkipFunctionHeader(start);
1373 byte_size *=
m_arch.GetMaximumOpcodeByteSize();
1374 auto data_sp = std::make_shared<DataBufferHeap>(byte_size,
'\0');
1378 const size_t bytes_read =
1379 target.
ReadMemory(start, data_sp->GetBytes(), data_sp->GetByteSize(),
1380 error, force_live_memory, &load_addr);
1383 if (bytes_read == 0) {
1384 if (error_strm_ptr) {
1385 if (
const char *error_cstr =
error.AsCString(
nullptr))
1386 error_strm_ptr->
Printf(
"error: %s\n", error_cstr);
1391 if (bytes_read != data_sp->GetByteSize())
1392 data_sp->SetByteSize(bytes_read);
1394 m_arch.GetAddressByteSize());
1398 true, data_from_file);
1404 if (flavor ==
nullptr)
1412 std::string thumb_arch_name(arch.GetTriple().getArchName().str());
1414 if (thumb_arch_name.size() > 3) {
1415 thumb_arch_name.erase(0, 3);
1416 thumb_arch_name.insert(0,
"thumb");
1418 m_arch.SetTriple(thumb_arch_name.c_str());
1468 switch (opcode_size) {
1470 uint8_t value8 = *((uint8_t *)opcode_data);
1475 uint16_t value16 = *((uint16_t *)opcode_data);
1480 uint32_t value32 = *((uint32_t *)opcode_data);
1485 uint64_t value64 = *((uint64_t *)opcode_data);
1557 return (base(op) && op.m_children.size() == 2 &&
1558 ((left(op.m_children[0]) && right(op.m_children[1])) ||
1559 (left(op.m_children[1]) && right(op.m_children[0]))));
1568 return (base(op) && op.m_children.size() == 1 && child(op.m_children[0]));
1587 reg = op.m_register;
1596 ((op.m_negative && op.m_immediate == (uint64_t)-imm) ||
1597 (!op.m_negative && op.m_immediate == (uint64_t)imm)));
1607 if (op.m_negative) {
1608 imm = -((int64_t)op.m_immediate);
1610 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)
static void skip(TSLexer *lexer)
#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 * 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.
llvm::StringRef 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 source file and line number for 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
Architecture * GetArchitecturePlugin() 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. E.g. FAR JMP.
@ 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").