[Lldb-commits] [lldb] 04592d5 - [lldb] s/ExecutionContext/Target in Disassembler
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 5 05:49:28 PST 2020
Author: Pavel Labath
Date: 2020-03-05T14:46:39+01:00
New Revision: 04592d5b23178cfacfd0817f58fca8a0a24a71c7
URL: https://github.com/llvm/llvm-project/commit/04592d5b23178cfacfd0817f58fca8a0a24a71c7
DIFF: https://github.com/llvm/llvm-project/commit/04592d5b23178cfacfd0817f58fca8a0a24a71c7.diff
LOG: [lldb] s/ExecutionContext/Target in Disassembler
Some functions in this file only use the "target" component of an
execution context. Adjust the argument lists to reflect that.
This avoids some defensive null checks and simplifies most of the
callers.
Added:
Modified:
lldb/include/lldb/Core/Disassembler.h
lldb/source/API/SBFunction.cpp
lldb/source/API/SBSymbol.cpp
lldb/source/Core/Disassembler.cpp
lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
lldb/source/Symbol/Function.cpp
lldb/source/Symbol/Symbol.cpp
lldb/source/Target/Process.cpp
lldb/source/Target/StackFrame.cpp
lldb/source/Target/ThreadPlanStepRange.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/Disassembler.h b/lldb/include/lldb/Core/Disassembler.h
index a4ecfdbdb5ca..5975be096ff7 100644
--- a/lldb/include/lldb/Core/Disassembler.h
+++ b/lldb/include/lldb/Core/Disassembler.h
@@ -379,13 +379,14 @@ class Disassembler : public std::enable_shared_from_this<Disassembler>,
FindPlugin(const ArchSpec &arch, const char *flavor, const char *plugin_name);
// This version will use the value in the Target settings if flavor is NULL;
- static lldb::DisassemblerSP
- FindPluginForTarget(const lldb::TargetSP target_sp, const ArchSpec &arch,
- const char *flavor, const char *plugin_name);
+ static lldb::DisassemblerSP FindPluginForTarget(const Target &target,
+ const ArchSpec &arch,
+ const char *flavor,
+ const char *plugin_name);
static lldb::DisassemblerSP
DisassembleRange(const ArchSpec &arch, const char *plugin_name,
- const char *flavor, const ExecutionContext &exe_ctx,
+ const char *flavor, Target &target,
const AddressRange &disasm_range, bool prefer_file_cache);
static lldb::DisassemblerSP
diff --git a/lldb/source/API/SBFunction.cpp b/lldb/source/API/SBFunction.cpp
index 79bc44a7e207..e49513bd0da5 100644
--- a/lldb/source/API/SBFunction.cpp
+++ b/lldb/source/API/SBFunction.cpp
@@ -126,20 +126,15 @@ SBInstructionList SBFunction::GetInstructions(SBTarget target,
SBInstructionList sb_instructions;
if (m_opaque_ptr) {
- ExecutionContext exe_ctx;
TargetSP target_sp(target.GetSP());
std::unique_lock<std::recursive_mutex> lock;
- if (target_sp) {
- lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
- target_sp->CalculateExecutionContext(exe_ctx);
- exe_ctx.SetProcessSP(target_sp->GetProcessSP());
- }
ModuleSP module_sp(
m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule());
- if (module_sp) {
+ if (target_sp && module_sp) {
+ lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
const bool prefer_file_cache = false;
sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
- module_sp->GetArchitecture(), nullptr, flavor, exe_ctx,
+ module_sp->GetArchitecture(), nullptr, flavor, *target_sp,
m_opaque_ptr->GetAddressRange(), prefer_file_cache));
}
}
diff --git a/lldb/source/API/SBSymbol.cpp b/lldb/source/API/SBSymbol.cpp
index dc81324d0af1..e4f2f3518270 100644
--- a/lldb/source/API/SBSymbol.cpp
+++ b/lldb/source/API/SBSymbol.cpp
@@ -124,22 +124,17 @@ SBInstructionList SBSymbol::GetInstructions(SBTarget target,
SBInstructionList sb_instructions;
if (m_opaque_ptr) {
- ExecutionContext exe_ctx;
TargetSP target_sp(target.GetSP());
std::unique_lock<std::recursive_mutex> lock;
- if (target_sp) {
+ if (target_sp && m_opaque_ptr->ValueIsAddress()) {
lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
-
- target_sp->CalculateExecutionContext(exe_ctx);
- }
- if (m_opaque_ptr->ValueIsAddress()) {
const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
ModuleSP module_sp = symbol_addr.GetModule();
if (module_sp) {
AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
const bool prefer_file_cache = false;
sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
- module_sp->GetArchitecture(), nullptr, flavor_string, exe_ctx,
+ module_sp->GetArchitecture(), nullptr, flavor_string, *target_sp,
symbol_range, prefer_file_cache));
}
}
diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp
index edeb02a54834..df48469bb316 100644
--- a/lldb/source/Core/Disassembler.cpp
+++ b/lldb/source/Core/Disassembler.cpp
@@ -89,61 +89,56 @@ DisassemblerSP Disassembler::FindPlugin(const ArchSpec &arch,
return DisassemblerSP();
}
-DisassemblerSP Disassembler::FindPluginForTarget(const TargetSP target_sp,
+DisassemblerSP Disassembler::FindPluginForTarget(const Target &target,
const ArchSpec &arch,
const char *flavor,
const char *plugin_name) {
- if (target_sp && flavor == nullptr) {
+ if (flavor == nullptr) {
// FIXME - we don't have the mechanism in place to do per-architecture
// settings. But since we know that for now we only support flavors on x86
// & x86_64,
if (arch.GetTriple().getArch() == llvm::Triple::x86 ||
arch.GetTriple().getArch() == llvm::Triple::x86_64)
- flavor = target_sp->GetDisassemblyFlavor();
+ flavor = target.GetDisassemblyFlavor();
}
return FindPlugin(arch, flavor, plugin_name);
}
-static void ResolveAddress(const ExecutionContext &exe_ctx, const Address &addr,
+static void ResolveAddress(Target &target, const Address &addr,
Address &resolved_addr) {
if (!addr.IsSectionOffset()) {
// If we weren't passed in a section offset address range, try and resolve
// it to something
- Target *target = exe_ctx.GetTargetPtr();
- if (target) {
- bool is_resolved =
- target->GetSectionLoadList().IsEmpty() ?
- target->GetImages().ResolveFileAddress(addr.GetOffset(),
- resolved_addr) :
- target->GetSectionLoadList().ResolveLoadAddress(addr.GetOffset(),
- resolved_addr);
-
- // We weren't able to resolve the address, just treat it as a raw address
- if (is_resolved && resolved_addr.IsValid())
- return;
- }
+ bool is_resolved = target.GetSectionLoadList().IsEmpty()
+ ? target.GetImages().ResolveFileAddress(
+ addr.GetOffset(), resolved_addr)
+ : target.GetSectionLoadList().ResolveLoadAddress(
+ addr.GetOffset(), resolved_addr);
+
+ // We weren't able to resolve the address, just treat it as a raw address
+ if (is_resolved && resolved_addr.IsValid())
+ return;
}
resolved_addr = addr;
}
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) {
- if (range.GetByteSize() <= 0 || !exe_ctx.GetTargetPtr())
+ Target &target, const AddressRange &range, bool prefer_file_cache) {
+ if (range.GetByteSize() <= 0)
return {};
if (!range.GetBaseAddress().IsValid())
return {};
- lldb::DisassemblerSP disasm_sp = Disassembler::FindPluginForTarget(
- exe_ctx.GetTargetSP(), arch, flavor, plugin_name);
+ lldb::DisassemblerSP disasm_sp =
+ Disassembler::FindPluginForTarget(target, arch, flavor, plugin_name);
if (!disasm_sp)
return {};
- const size_t bytes_disassembled = disasm_sp->ParseInstructions(
- exe_ctx.GetTargetRef(), range, nullptr, prefer_file_cache);
+ const size_t bytes_disassembled =
+ disasm_sp->ParseInstructions(target, range, nullptr, prefer_file_cache);
if (bytes_disassembled == 0)
return {};
@@ -184,13 +179,13 @@ bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
return false;
lldb::DisassemblerSP disasm_sp(Disassembler::FindPluginForTarget(
- exe_ctx.GetTargetSP(), arch, flavor, plugin_name));
+ exe_ctx.GetTargetRef(), arch, flavor, plugin_name));
if (!disasm_sp)
return false;
AddressRange range;
- ResolveAddress(exe_ctx, disasm_range.GetBaseAddress(),
+ ResolveAddress(exe_ctx.GetTargetRef(), disasm_range.GetBaseAddress(),
range.GetBaseAddress());
range.SetByteSize(disasm_range.GetByteSize());
const bool prefer_file_cache = false;
@@ -217,12 +212,12 @@ bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
return false;
lldb::DisassemblerSP disasm_sp(Disassembler::FindPluginForTarget(
- exe_ctx.GetTargetSP(), arch, flavor, plugin_name));
+ exe_ctx.GetTargetRef(), arch, flavor, plugin_name));
if (!disasm_sp)
return false;
Address addr;
- ResolveAddress(exe_ctx, start_address, addr);
+ ResolveAddress(exe_ctx.GetTargetRef(), start_address, addr);
const bool prefer_file_cache = false;
size_t bytes_disassembled = disasm_sp->ParseInstructions(
diff --git a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
index e4eceb2bd63c..7f9504b9b3a9 100644
--- a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
@@ -192,9 +192,8 @@ DynamicLoaderWindowsDYLD::GetStepThroughTrampolinePlan(Thread &thread,
// Max size of an instruction in x86 is 15 bytes.
AddressRange range(pc, 2 * 15);
- ExecutionContext exe_ctx(m_process->GetTarget());
DisassemblerSP disassembler_sp = Disassembler::DisassembleRange(
- arch, nullptr, nullptr, exe_ctx, range, true);
+ arch, nullptr, nullptr, m_process->GetTarget(), range, true);
if (!disassembler_sp) {
return ThreadPlanSP();
}
@@ -213,6 +212,7 @@ DynamicLoaderWindowsDYLD::GetStepThroughTrampolinePlan(Thread &thread,
auto first_insn = insn_list->GetInstructionAtIndex(0);
auto second_insn = insn_list->GetInstructionAtIndex(1);
+ ExecutionContext exe_ctx(m_process->GetTarget());
if (first_insn == nullptr || second_insn == nullptr ||
strcmp(first_insn->GetMnemonic(&exe_ctx), "jmpl") != 0 ||
strcmp(second_insn->GetMnemonic(&exe_ctx), "nop") != 0) {
diff --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp
index e867a7f80398..e1d5a720bcc3 100644
--- a/lldb/source/Symbol/Function.cpp
+++ b/lldb/source/Symbol/Function.cpp
@@ -420,11 +420,11 @@ lldb::DisassemblerSP Function::GetInstructions(const ExecutionContext &exe_ctx,
const char *flavor,
bool prefer_file_cache) {
ModuleSP module_sp(GetAddressRange().GetBaseAddress().GetModule());
- if (module_sp) {
+ if (module_sp && exe_ctx.HasTargetScope()) {
const bool prefer_file_cache = false;
return Disassembler::DisassembleRange(module_sp->GetArchitecture(), nullptr,
- flavor, exe_ctx, GetAddressRange(),
- prefer_file_cache);
+ flavor, exe_ctx.GetTargetRef(),
+ GetAddressRange(), prefer_file_cache);
}
return lldb::DisassemblerSP();
}
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index c96f14126e6b..8d099e0cc7e1 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -541,11 +541,11 @@ lldb::DisassemblerSP Symbol::GetInstructions(const ExecutionContext &exe_ctx,
const char *flavor,
bool prefer_file_cache) {
ModuleSP module_sp(m_addr_range.GetBaseAddress().GetModule());
- if (module_sp) {
+ if (module_sp && exe_ctx.HasTargetScope()) {
const bool prefer_file_cache = false;
return Disassembler::DisassembleRange(module_sp->GetArchitecture(), nullptr,
- flavor, exe_ctx, m_addr_range,
- prefer_file_cache);
+ flavor, exe_ctx.GetTargetRef(),
+ m_addr_range, prefer_file_cache);
}
return lldb::DisassemblerSP();
}
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 80382007c329..7938d2b9a9b2 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -5778,12 +5778,11 @@ Process::AdvanceAddressToNextBranchInstruction(Address default_stop_addr,
if (!default_stop_addr.IsValid())
return retval;
- ExecutionContext exe_ctx(this);
const char *plugin_name = nullptr;
const char *flavor = nullptr;
const bool prefer_file_cache = true;
disassembler_sp = Disassembler::DisassembleRange(
- target.GetArchitecture(), plugin_name, flavor, exe_ctx, range_bounds,
+ target.GetArchitecture(), plugin_name, flavor, GetTarget(), range_bounds,
prefer_file_cache);
if (disassembler_sp)
insn_list = &disassembler_sp->GetInstructionList();
diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp
index 83c11470edef..f9e55cfb7375 100644
--- a/lldb/source/Target/StackFrame.cpp
+++ b/lldb/source/Target/StackFrame.cpp
@@ -1321,14 +1321,13 @@ lldb::ValueObjectSP StackFrame::GuessValueForAddress(lldb::addr_t addr) {
pc_range.GetBaseAddress() = GetFrameCodeAddress();
pc_range.SetByteSize(target_arch.GetMaximumOpcodeByteSize());
- ExecutionContext exe_ctx(shared_from_this());
-
const char *plugin_name = nullptr;
const char *flavor = nullptr;
const bool prefer_file_cache = false;
- DisassemblerSP disassembler_sp = Disassembler::DisassembleRange(
- target_arch, plugin_name, flavor, exe_ctx, pc_range, prefer_file_cache);
+ DisassemblerSP disassembler_sp =
+ Disassembler::DisassembleRange(target_arch, plugin_name, flavor,
+ *target_sp, pc_range, prefer_file_cache);
if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) {
return ValueObjectSP();
@@ -1702,13 +1701,12 @@ lldb::ValueObjectSP StackFrame::GuessValueForRegisterAndOffset(ConstString reg,
return ValueObjectSP();
}
- ExecutionContext exe_ctx(shared_from_this());
-
const char *plugin_name = nullptr;
const char *flavor = nullptr;
const bool prefer_file_cache = false;
- DisassemblerSP disassembler_sp = Disassembler::DisassembleRange(
- target_arch, plugin_name, flavor, exe_ctx, pc_range, prefer_file_cache);
+ DisassemblerSP disassembler_sp =
+ Disassembler::DisassembleRange(target_arch, plugin_name, flavor,
+ *target_sp, pc_range, prefer_file_cache);
if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) {
return ValueObjectSP();
diff --git a/lldb/source/Target/ThreadPlanStepRange.cpp b/lldb/source/Target/ThreadPlanStepRange.cpp
index 96a095844a8e..5362d504e1a4 100644
--- a/lldb/source/Target/ThreadPlanStepRange.cpp
+++ b/lldb/source/Target/ThreadPlanStepRange.cpp
@@ -264,12 +264,11 @@ InstructionList *ThreadPlanStepRange::GetInstructionsForAddress(
if (!m_instruction_ranges[i]) {
// Disassemble the address range given:
- ExecutionContext exe_ctx(m_thread.GetProcess());
const char *plugin_name = nullptr;
const char *flavor = nullptr;
const bool prefer_file_cache = true;
m_instruction_ranges[i] = Disassembler::DisassembleRange(
- GetTarget().GetArchitecture(), plugin_name, flavor, exe_ctx,
+ GetTarget().GetArchitecture(), plugin_name, flavor, GetTarget(),
m_address_ranges[i], prefer_file_cache);
}
if (!m_instruction_ranges[i])
More information about the lldb-commits
mailing list