diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-23 21:36:25 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-23 21:36:25 +0000 |
commit | 9dba64be9536c28e4800e06512b7f29b43ade345 (patch) | |
tree | 7f0f30947225ecb30ab0fdae8059a936537b0dfe /contrib/llvm-project/lldb/source/Core/Disassembler.cpp | |
parent | 85868e8a1daeaae7a0e48effb2ea2310ae3b02c6 (diff) | |
parent | ead246455adf1a215ec2715dad6533073a6beb4e (diff) |
Notes
Diffstat (limited to 'contrib/llvm-project/lldb/source/Core/Disassembler.cpp')
-rw-r--r-- | contrib/llvm-project/lldb/source/Core/Disassembler.cpp | 239 |
1 files changed, 126 insertions, 113 deletions
diff --git a/contrib/llvm-project/lldb/source/Core/Disassembler.cpp b/contrib/llvm-project/lldb/source/Core/Disassembler.cpp index af7cf82d470a..89ae25cbad64 100644 --- a/contrib/llvm-project/lldb/source/Core/Disassembler.cpp +++ b/contrib/llvm-project/lldb/source/Core/Disassembler.cpp @@ -158,52 +158,58 @@ size_t Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch, return success_count; } -bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch, - const char *plugin_name, const char *flavor, - const ExecutionContext &exe_ctx, - ConstString name, Module *module, - uint32_t num_instructions, - bool mixed_source_and_assembly, - uint32_t num_mixed_context_lines, - uint32_t options, Stream &strm) { +bool Disassembler::Disassemble( + Debugger &debugger, const ArchSpec &arch, const char *plugin_name, + const char *flavor, const ExecutionContext &exe_ctx, ConstString name, + Module *module, uint32_t num_instructions, bool mixed_source_and_assembly, + uint32_t num_mixed_context_lines, uint32_t options, Stream &strm) { + // If no name is given there's nothing to disassemble. + if (!name) + return false; + + const bool include_symbols = true; + const bool include_inlines = true; + + // Find functions matching the given name. SymbolContextList sc_list; - if (name) { - const bool include_symbols = true; - const bool include_inlines = true; - if (module) { - module->FindFunctions(name, nullptr, eFunctionNameTypeAuto, - include_symbols, include_inlines, true, sc_list); - } else if (exe_ctx.GetTargetPtr()) { - exe_ctx.GetTargetPtr()->GetImages().FindFunctions( - name, eFunctionNameTypeAuto, include_symbols, include_inlines, false, - sc_list); - } + if (module) { + module->FindFunctions(name, nullptr, eFunctionNameTypeAuto, include_symbols, + include_inlines, sc_list); + } else if (exe_ctx.GetTargetPtr()) { + exe_ctx.GetTargetPtr()->GetImages().FindFunctions( + name, eFunctionNameTypeAuto, include_symbols, include_inlines, sc_list); } - if (sc_list.GetSize()) { - return Disassemble(debugger, arch, plugin_name, flavor, exe_ctx, sc_list, - num_instructions, mixed_source_and_assembly, - num_mixed_context_lines, options, strm); - } - return false; + // If no functions were found there's nothing to disassemble. + if (sc_list.IsEmpty()) + return false; + + return Disassemble(debugger, arch, plugin_name, flavor, exe_ctx, sc_list, + num_instructions, mixed_source_and_assembly, + num_mixed_context_lines, options, strm); } lldb::DisassemblerSP Disassembler::DisassembleRange( const ArchSpec &arch, const char *plugin_name, const char *flavor, const ExecutionContext &exe_ctx, const AddressRange &range, bool prefer_file_cache) { - lldb::DisassemblerSP disasm_sp; - if (range.GetByteSize() > 0 && range.GetBaseAddress().IsValid()) { - disasm_sp = Disassembler::FindPluginForTarget(exe_ctx.GetTargetSP(), arch, - flavor, plugin_name); - - if (disasm_sp) { - size_t bytes_disassembled = disasm_sp->ParseInstructions( - &exe_ctx, range, nullptr, prefer_file_cache); - if (bytes_disassembled == 0) - disasm_sp.reset(); - } - } + if (range.GetByteSize() <= 0) + return {}; + + if (!range.GetBaseAddress().IsValid()) + return {}; + + lldb::DisassemblerSP disasm_sp = Disassembler::FindPluginForTarget( + exe_ctx.GetTargetSP(), arch, flavor, plugin_name); + + if (!disasm_sp) + return {}; + + const size_t bytes_disassembled = + disasm_sp->ParseInstructions(&exe_ctx, range, nullptr, prefer_file_cache); + if (bytes_disassembled == 0) + return {}; + return disasm_sp; } @@ -212,20 +218,20 @@ Disassembler::DisassembleBytes(const ArchSpec &arch, const char *plugin_name, const char *flavor, const Address &start, const void *src, size_t src_len, uint32_t num_instructions, bool data_from_file) { - lldb::DisassemblerSP disasm_sp; + if (!src) + return {}; - if (src) { - disasm_sp = Disassembler::FindPlugin(arch, flavor, plugin_name); + lldb::DisassemblerSP disasm_sp = + Disassembler::FindPlugin(arch, flavor, plugin_name); - if (disasm_sp) { - DataExtractor data(src, src_len, arch.GetByteOrder(), - arch.GetAddressByteSize()); + if (!disasm_sp) + return {}; - (void)disasm_sp->DecodeInstructions(start, data, 0, num_instructions, - false, data_from_file); - } - } + DataExtractor data(src, src_len, arch.GetByteOrder(), + arch.GetAddressByteSize()); + (void)disasm_sp->DecodeInstructions(start, data, 0, num_instructions, false, + data_from_file); return disasm_sp; } @@ -237,27 +243,28 @@ bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch, bool mixed_source_and_assembly, uint32_t num_mixed_context_lines, uint32_t options, Stream &strm) { - if (disasm_range.GetByteSize()) { - lldb::DisassemblerSP disasm_sp(Disassembler::FindPluginForTarget( - exe_ctx.GetTargetSP(), arch, flavor, plugin_name)); - - if (disasm_sp) { - AddressRange range; - ResolveAddress(exe_ctx, disasm_range.GetBaseAddress(), - range.GetBaseAddress()); - range.SetByteSize(disasm_range.GetByteSize()); - const bool prefer_file_cache = false; - size_t bytes_disassembled = disasm_sp->ParseInstructions( - &exe_ctx, range, &strm, prefer_file_cache); - if (bytes_disassembled == 0) - return false; - - return PrintInstructions(disasm_sp.get(), debugger, arch, exe_ctx, - num_instructions, mixed_source_and_assembly, - num_mixed_context_lines, options, strm); - } - } - return false; + if (!disasm_range.GetByteSize()) + return false; + + lldb::DisassemblerSP disasm_sp(Disassembler::FindPluginForTarget( + exe_ctx.GetTargetSP(), arch, flavor, plugin_name)); + + if (!disasm_sp) + return false; + + AddressRange range; + ResolveAddress(exe_ctx, disasm_range.GetBaseAddress(), + range.GetBaseAddress()); + range.SetByteSize(disasm_range.GetByteSize()); + const bool prefer_file_cache = false; + size_t bytes_disassembled = + disasm_sp->ParseInstructions(&exe_ctx, range, &strm, prefer_file_cache); + if (bytes_disassembled == 0) + return false; + + return PrintInstructions(disasm_sp.get(), debugger, arch, exe_ctx, + num_instructions, mixed_source_and_assembly, + num_mixed_context_lines, options, strm); } bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch, @@ -268,42 +275,51 @@ bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch, bool mixed_source_and_assembly, uint32_t num_mixed_context_lines, uint32_t options, Stream &strm) { - if (num_instructions > 0) { - lldb::DisassemblerSP disasm_sp(Disassembler::FindPluginForTarget( - exe_ctx.GetTargetSP(), arch, flavor, plugin_name)); - if (disasm_sp) { - Address addr; - ResolveAddress(exe_ctx, start_address, addr); - const bool prefer_file_cache = false; - size_t bytes_disassembled = disasm_sp->ParseInstructions( - &exe_ctx, addr, num_instructions, prefer_file_cache); - if (bytes_disassembled == 0) - return false; - return PrintInstructions(disasm_sp.get(), debugger, arch, exe_ctx, - num_instructions, mixed_source_and_assembly, - num_mixed_context_lines, options, strm); - } - } - return false; + if (num_instructions == 0) + return false; + + lldb::DisassemblerSP disasm_sp(Disassembler::FindPluginForTarget( + exe_ctx.GetTargetSP(), arch, flavor, plugin_name)); + if (!disasm_sp) + return false; + + Address addr; + ResolveAddress(exe_ctx, start_address, addr); + + const bool prefer_file_cache = false; + size_t bytes_disassembled = disasm_sp->ParseInstructions( + &exe_ctx, addr, num_instructions, prefer_file_cache); + if (bytes_disassembled == 0) + return false; + + return PrintInstructions(disasm_sp.get(), debugger, arch, exe_ctx, + num_instructions, mixed_source_and_assembly, + num_mixed_context_lines, options, strm); } Disassembler::SourceLine Disassembler::GetFunctionDeclLineEntry(const SymbolContext &sc) { + if (!sc.function) + return {}; + + if (!sc.line_entry.IsValid()) + return {}; + + LineEntry prologue_end_line = sc.line_entry; + FileSpec func_decl_file; + uint32_t func_decl_line; + sc.function->GetStartLineSourceInfo(func_decl_file, func_decl_line); + + if (func_decl_file != prologue_end_line.file && + func_decl_file != prologue_end_line.original_file) + return {}; + SourceLine decl_line; - if (sc.function && sc.line_entry.IsValid()) { - LineEntry prologue_end_line = sc.line_entry; - FileSpec func_decl_file; - uint32_t func_decl_line; - sc.function->GetStartLineSourceInfo(func_decl_file, func_decl_line); - if (func_decl_file == prologue_end_line.file || - func_decl_file == prologue_end_line.original_file) { - decl_line.file = func_decl_file; - decl_line.line = func_decl_line; - // TODO do we care about column on these entries? If so, we need to - // plumb that through GetStartLineSourceInfo. - decl_line.column = 0; - } - } + decl_line.file = func_decl_file; + decl_line.line = func_decl_line; + // TODO: Do we care about column on these entries? If so, we need to plumb + // that through GetStartLineSourceInfo. + decl_line.column = 0; return decl_line; } @@ -355,12 +371,9 @@ bool Disassembler::ElideMixedSourceAndDisassemblyLine( const char *function_name = sc.GetFunctionName(Mangled::ePreferDemangledWithoutArguments) .GetCString(); - if (function_name) { - RegularExpression::Match regex_match(1); - if (avoid_regex->Execute(function_name, ®ex_match)) { - // skip this source line - return true; - } + if (function_name && avoid_regex->Execute(function_name)) { + // skip this source line + return true; } } // don't skip this source line @@ -793,10 +806,9 @@ OptionValueSP Instruction::ReadArray(FILE *in_file, Stream *out_stream, std::string value; static RegularExpression g_reg_exp( llvm::StringRef("^[ \t]*([^ \t]+)[ \t]*$")); - RegularExpression::Match regex_match(1); - bool reg_exp_success = g_reg_exp.Execute(line, ®ex_match); - if (reg_exp_success) - regex_match.GetMatchAtIndex(line.c_str(), 1, value); + llvm::SmallVector<llvm::StringRef, 2> matches; + if (g_reg_exp.Execute(line, &matches)) + value = matches[1].str(); else value = line; @@ -856,14 +868,15 @@ OptionValueSP Instruction::ReadDictionary(FILE *in_file, Stream *out_stream) { if (!line.empty()) { static RegularExpression g_reg_exp(llvm::StringRef( "^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*=[ \t]*(.*)[ \t]*$")); - RegularExpression::Match regex_match(2); - bool reg_exp_success = g_reg_exp.Execute(line, ®ex_match); + llvm::SmallVector<llvm::StringRef, 3> matches; + + bool reg_exp_success = g_reg_exp.Execute(line, &matches); std::string key; std::string value; if (reg_exp_success) { - regex_match.GetMatchAtIndex(line.c_str(), 1, key); - regex_match.GetMatchAtIndex(line.c_str(), 2, value); + key = matches[1].str(); + value = matches[2].str(); } else { out_stream->Printf("Instruction::ReadDictionary: Failure executing " "regular expression.\n"); |