31#define LLDB_OPTIONS_disassemble
32#include "CommandOptions.inc"
41 uint32_t option_idx, llvm::StringRef option_arg,
45 const int short_option = m_getopt_table[option_idx].val;
47 switch (short_option) {
53 if (option_arg.getAsInteger(0, num_lines_context))
55 "invalid num context lines string: \"%s\"", option_arg.str().c_str());
59 if (option_arg.getAsInteger(0, num_instructions))
61 "invalid num of instructions string: \"%s\"",
62 option_arg.str().c_str());
70 show_control_flow_kind =
true;
77 some_location_specified =
true;
83 some_location_specified =
true;
87 func_name.assign(std::string(option_arg));
88 some_location_specified =
true;
93 some_location_specified =
true;
101 some_location_specified =
true;
105 plugin_name.assign(std::string(option_arg));
111 if (target_sp && (target_sp->GetArchitecture().GetTriple().getArch() ==
113 target_sp->GetArchitecture().GetTriple().getArch() ==
114 llvm::Triple::x86_64)) {
115 flavor_string.assign(std::string(option_arg));
118 "Disassembler flavors are currently only "
119 "supported for x86 and x86_64 targets.");
124 cpu_string = std::string(option_arg);
128 features_string = std::string(option_arg);
136 current_function =
true;
137 some_location_specified =
true;
141 if (execution_context) {
142 const auto &target_sp = execution_context->
GetTargetSP();
143 auto platform_ptr = target_sp ? target_sp->GetPlatform().get() :
nullptr;
152 some_location_specified =
true;
161 llvm_unreachable(
"Unimplemented option");
171 show_control_flow_kind =
false;
172 num_lines_context = 0;
173 num_instructions = 0;
175 current_function =
false;
185 execution_context ? execution_context->
GetTargetPtr() :
nullptr;
194 llvm::Triple::x86_64) {
197 flavor_string.assign(
"default");
200 cpu_string.assign(cpu);
202 features_string.assign(features);
204 flavor_string.assign(
"default");
205 cpu_string.assign(
"default");
206 features_string.assign(
"default");
210 some_location_specified =
false;
216 if (!some_location_specified)
217 current_function =
true;
221llvm::ArrayRef<OptionDefinition>
223 return llvm::ArrayRef(g_disassemble_options);
231 interpreter,
"disassemble",
232 "Disassemble specified instructions in the current target. "
233 "Defaults to the current function for the current thread and "
235 "disassemble [<cmd-options>]", eCommandRequiresTarget) {}
240 llvm::StringRef what) {
243 return llvm::Error::success();
245 msg <<
"Not disassembling " << what <<
" because it is very large ";
248 msg <<
". To disassemble specify an instruction count limit, start/stop "
249 "addresses or use the --force option.";
250 return llvm::createStringError(llvm::inconvertibleErrorCode(),
254llvm::Expected<std::vector<AddressRange>>
256 std::vector<AddressRange> ranges;
257 const auto &get_range = [&](
Address addr) {
258 ModuleSP module_sp(addr.GetModule());
260 bool resolve_tail_call_address =
true;
261 addr.GetModule()->ResolveSymbolContextForAddress(
262 addr, eSymbolContextEverything, sc, resolve_tail_call_address);
267 ranges.push_back(range);
273 Address symbol_containing_address;
276 get_range(symbol_containing_address);
283 get_range(file_address);
288 if (ranges.empty()) {
289 return llvm::createStringError(
290 llvm::inconvertibleErrorCode(),
291 "Could not find function bounds for address 0x%" PRIx64,
296 return std::move(err);
300llvm::Expected<std::vector<AddressRange>>
306 return llvm::createStringError(
307 llvm::inconvertibleErrorCode(),
308 "Cannot disassemble around the current "
309 "function without the process being stopped.\n");
311 return llvm::createStringError(llvm::inconvertibleErrorCode(),
312 "Cannot disassemble around the current "
313 "function without a selected frame: "
314 "no currently running process.\n");
327 if (llvm::Error err =
CheckRangeSize(range,
"the current function"))
328 return std::move(err);
329 return std::vector<AddressRange>{range};
332llvm::Expected<std::vector<AddressRange>>
338 return llvm::createStringError(
339 llvm::inconvertibleErrorCode(),
340 "Cannot disassemble around the current "
341 "function without the process being stopped.\n");
343 return llvm::createStringError(llvm::inconvertibleErrorCode(),
344 "Cannot disassemble around the current "
345 "line without a selected frame: "
346 "no currently running process.\n");
353 return std::vector<AddressRange>{pc_line_entry.
range};
360llvm::Expected<std::vector<AddressRange>>
371 function_options, sc_list);
373 std::vector<AddressRange> ranges;
374 llvm::Error range_errs = llvm::Error::success();
376 const uint32_t scope =
377 eSymbolContextBlock | eSymbolContextFunction | eSymbolContextSymbol;
378 const bool use_inline_block_range =
true;
380 for (uint32_t range_idx = 0;
381 sc.GetAddressRange(scope, range_idx, use_inline_block_range, range);
384 range_errs = joinErrors(std::move(range_errs), std::move(err));
386 ranges.push_back(range);
389 if (ranges.empty()) {
391 return std::move(range_errs);
392 return llvm::createStringError(llvm::inconvertibleErrorCode(),
393 "Unable to find symbol with name '%s'.\n",
401llvm::Expected<std::vector<AddressRange>>
407 return llvm::createStringError(
408 llvm::inconvertibleErrorCode(),
409 "Cannot disassemble around the current "
410 "function without the process being stopped.\n");
412 return llvm::createStringError(llvm::inconvertibleErrorCode(),
413 "Cannot disassemble around the current "
414 "PC without a selected frame: "
415 "no currently running process.\n");
427llvm::Expected<std::vector<AddressRange>>
432 return llvm::createStringError(llvm::inconvertibleErrorCode(),
433 "End address before start address.");
440llvm::Expected<std::vector<AddressRange>>
465 "use the --arch option or set the target architecture to disassemble");
475 m_options.
arch, flavor_string, cpu_string, features_string, plugin_name);
480 "Unable to find Disassembler plug-in named '%s' that supports the "
481 "'%s' architecture.\n",
485 "Unable to find Disassembler plug-in for the '%s' architecture.\n",
488 }
else if (flavor_string !=
nullptr && !disassembler->FlavorValidForArchSpec(
491 "invalid disassembler flavor \"%s\", using default.\n", flavor_string);
495 if (!command.
empty()) {
497 "\"disassemble\" arguments are specified as options.\n");
498 const int terminal_width =
525 llvm::Expected<std::vector<AddressRange>> ranges =
532 bool print_sc_header = ranges->size() > 1;
537 if (limit.
value == 0)
544 cpu_string, features_string,
m_exe_ctx, cur_range.GetBaseAddress(),
552 "Failed to disassemble memory in function at 0x%8.8" PRIx64
".\n",
556 "Failed to disassemble memory at 0x%8.8" PRIx64
".\n",
557 cur_range.GetBaseAddress().GetLoadAddress(&target));
static constexpr unsigned default_disasm_num_ins
static constexpr unsigned default_disasm_byte_size
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address range class.
bool Dump(Stream *s, Target *target, Address::DumpStyle style, Address::DumpStyle fallback_style=Address::DumpStyleInvalid) const
Dump a description of this object to a Stream.
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
A section + offset based address class.
@ DumpStyleFileAddress
Display as the file address (if any).
@ DumpStyleLoadAddress
Display as the load address (if resolved).
bool IsValid() const
Tests if this ArchSpec is valid.
llvm::Triple & GetTriple()
Architecture triple accessor.
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
A command line argument class.
bool show_control_flow_kind
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
uint32_t num_lines_context
void OptionParsingStarting(ExecutionContext *execution_context) override
const char * GetCPUString()
Status OptionParsingFinished(ExecutionContext *execution_context) override
lldb::addr_t symbol_containing_addr
const char * GetFeaturesString()
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
~CommandOptions() override
const char * GetFlavorString()
const char * GetPluginName()
uint32_t num_instructions
llvm::Expected< std::vector< AddressRange > > GetCurrentFunctionRanges()
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectDisassemble() override
llvm::Expected< std::vector< AddressRange > > GetStartEndAddressRanges()
llvm::Error CheckRangeSize(const AddressRange &range, llvm::StringRef what)
CommandObjectDisassemble(CommandInterpreter &interpreter)
llvm::Expected< std::vector< AddressRange > > GetNameRanges(CommandReturnObject &result)
llvm::Expected< std::vector< AddressRange > > GetPCRanges()
llvm::Expected< std::vector< AddressRange > > GetCurrentLineRanges()
Options * GetOptions() override
llvm::Expected< std::vector< AddressRange > > GetContainingAddressRanges()
llvm::Expected< std::vector< AddressRange > > GetRangesForSelectedMode(CommandReturnObject &result)
ExecutionContext m_exe_ctx
CommandInterpreter & GetCommandInterpreter()
void void AppendError(llvm::StringRef in_string)
void AppendWarningWithFormat(const char *format,...) __attribute__((format(printf
Stream & GetErrorStream()
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void void AppendWarning(llvm::StringRef in_string)
Stream & GetOutputStream()
A uniqued constant string class.
const char * GetCString() const
Get the string value as a C string.
uint64_t GetTerminalWidth() const
static lldb::DisassemblerSP FindPlugin(const ArchSpec &arch, const char *flavor, const char *cpu, const char *features, const char *plugin_name)
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)
@ eOptionMarkPCSourceLine
@ eOptionShowControlFlowKind
"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.
Process * GetProcessPtr() const
Returns a pointer to the process object.
const AddressRange & GetAddressRange()
DEPRECATED: Use GetAddressRanges instead.
void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list) const
ModuleIterable Modules() const
void GenerateOptionUsage(Stream &strm, CommandObject &cmd, uint32_t screen_width)
A plug-in interface definition class for debugging a process.
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
This base class provides an interface to stack frames.
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
llvm::StringRef GetString() const
Defines a list of symbol context objects.
SymbolContextIterable SymbolContexts()
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
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
lldb::addr_t GetByteSize() const
Address GetAddress() const
const char * GetDisassemblyFeatures() const
const char * GetDisassemblyFlavor() const
const char * GetDisassemblyCPU() const
SectionLoadList & GetSectionLoadList()
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
const char * toString(AppleArm64ExceptionClass EC)
std::shared_ptr< lldb_private::Disassembler > DisassemblerSP
@ eReturnStatusSuccessFinishResult
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
A line table entry class.
bool IsValid() const
Check if a line entry object is valid.
AddressRange range
The section offset address range for this line entry.
Options used by Module::FindFunctions.
bool include_inlines
Include inlined functions.
bool include_symbols
Include the symbol table.
static lldb::addr_t ToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s, lldb::addr_t fail_value, Status *error_ptr)
Try to parse an address.