diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
| commit | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch) | |
| tree | 4adf86a776049cbf7f69a1929c4babcbbef925eb /lldb/source/Target | |
| parent | 7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff) | |
Notes
Diffstat (limited to 'lldb/source/Target')
20 files changed, 223 insertions, 209 deletions
diff --git a/lldb/source/Target/ABI.cpp b/lldb/source/Target/ABI.cpp index 005261e0ddee..58396ba70586 100644 --- a/lldb/source/Target/ABI.cpp +++ b/lldb/source/Target/ABI.cpp @@ -63,24 +63,6 @@ bool ABI::GetRegisterInfoByName(ConstString name, RegisterInfo &info) { return false; } -bool ABI::GetRegisterInfoByKind(RegisterKind reg_kind, uint32_t reg_num, - RegisterInfo &info) { - if (reg_kind < eRegisterKindEHFrame || reg_kind >= kNumRegisterKinds) - return false; - - uint32_t count = 0; - const RegisterInfo *register_info_array = GetRegisterInfoArray(count); - if (register_info_array) { - for (uint32_t i = 0; i < count; ++i) { - if (register_info_array[i].kinds[reg_kind] == reg_num) { - info = register_info_array[i]; - return true; - } - } - } - return false; -} - ValueObjectSP ABI::GetReturnValueObject(Thread &thread, CompilerType &ast_type, bool persistent) const { if (!ast_type.IsValid()) @@ -105,7 +87,7 @@ ValueObjectSP ABI::GetReturnValueObject(Thread &thread, CompilerType &ast_type, ast_type.GetMinimumLanguage()); if (!persistent_expression_state) - return ValueObjectSP(); + return {}; auto prefix = persistent_expression_state->GetPersistentVariablePrefix(); ConstString persistent_variable_name = @@ -229,3 +211,20 @@ std::unique_ptr<llvm::MCRegisterInfo> ABI::MakeMCRegisterInfo(const ArchSpec &ar assert(info_up); return info_up; } + +void ABI::AugmentRegisterInfo(RegisterInfo &info) { + if (info.kinds[eRegisterKindEHFrame] != LLDB_INVALID_REGNUM && + info.kinds[eRegisterKindDWARF] != LLDB_INVALID_REGNUM) + return; + + RegisterInfo abi_info; + if (!GetRegisterInfoByName(ConstString(info.name), abi_info)) + return; + + if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM) + info.kinds[eRegisterKindEHFrame] = abi_info.kinds[eRegisterKindEHFrame]; + if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM) + info.kinds[eRegisterKindDWARF] = abi_info.kinds[eRegisterKindDWARF]; + if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM) + info.kinds[eRegisterKindGeneric] = abi_info.kinds[eRegisterKindGeneric]; +} diff --git a/lldb/source/Target/Language.cpp b/lldb/source/Target/Language.cpp index 43d0be0f737c..10a9ddd56c44 100644 --- a/lldb/source/Target/Language.cpp +++ b/lldb/source/Target/Language.cpp @@ -134,11 +134,6 @@ Language::GetHardcodedSynthetics() { return {}; } -HardcodedFormatters::HardcodedValidatorFinder -Language::GetHardcodedValidators() { - return {}; -} - std::vector<ConstString> Language::GetPossibleFormattersMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic) { diff --git a/lldb/source/Target/LanguageRuntime.cpp b/lldb/source/Target/LanguageRuntime.cpp index 999ac99e93c3..32dd805a00b1 100644 --- a/lldb/source/Target/LanguageRuntime.cpp +++ b/lldb/source/Target/LanguageRuntime.cpp @@ -155,8 +155,10 @@ public: protected: BreakpointResolverSP CopyForBreakpoint(Breakpoint &breakpoint) override { - return BreakpointResolverSP( + BreakpointResolverSP ret_sp( new ExceptionBreakpointResolver(m_language, m_catch_bp, m_throw_bp)); + ret_sp->SetBreakpoint(&breakpoint); + return ret_sp; } bool SetActualResolver() { diff --git a/lldb/source/Target/MemoryRegionInfo.cpp b/lldb/source/Target/MemoryRegionInfo.cpp new file mode 100644 index 000000000000..2c31563786aa --- /dev/null +++ b/lldb/source/Target/MemoryRegionInfo.cpp @@ -0,0 +1,40 @@ +//===-- MemoryRegionInfo.cpp ------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Target/MemoryRegionInfo.h" + +using namespace lldb_private; + +llvm::raw_ostream &lldb_private::operator<<(llvm::raw_ostream &OS, + const MemoryRegionInfo &Info) { + return OS << llvm::formatv("MemoryRegionInfo([{0}, {1}), {2:r}{3:w}{4:x}, " + "{5}, `{6}`, {7}, {8})", + Info.GetRange().GetRangeBase(), + Info.GetRange().GetRangeEnd(), Info.GetReadable(), + Info.GetWritable(), Info.GetExecutable(), + Info.GetMapped(), Info.GetName(), Info.GetFlash(), + Info.GetBlocksize()); +} + +void llvm::format_provider<MemoryRegionInfo::OptionalBool>::format( + const MemoryRegionInfo::OptionalBool &B, raw_ostream &OS, + StringRef Options) { + assert(Options.size() <= 1); + bool Empty = Options.empty(); + switch (B) { + case lldb_private::MemoryRegionInfo::eNo: + OS << (Empty ? "no" : "-"); + return; + case lldb_private::MemoryRegionInfo::eYes: + OS << (Empty ? "yes" : Options); + return; + case lldb_private::MemoryRegionInfo::eDontKnow: + OS << (Empty ? "don't know" : "?"); + return; + } +} diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index c9849a9e5f09..aaf48f35f921 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -406,7 +406,7 @@ void Platform::GetStatus(Stream &strm) { if (arch.IsValid()) { if (!arch.GetTriple().str().empty()) { strm.Printf(" Triple: "); - arch.DumpTriple(strm); + arch.DumpTriple(strm.AsRawOstream()); strm.EOL(); } } diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index ed0b951fbce1..6711dc37eca6 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -137,19 +137,12 @@ ProcessProperties::ProcessProperties(lldb_private::Process *process) Process::GetGlobalProperties().get()); m_collection_sp->SetValueChangedCallback( ePropertyPythonOSPluginPath, - ProcessProperties::OptionValueChangedCallback, this); + [this] { m_process->LoadOperatingSystemPlugin(true); }); } } ProcessProperties::~ProcessProperties() = default; -void ProcessProperties::OptionValueChangedCallback(void *baton, - OptionValue *option_value) { - ProcessProperties *properties = (ProcessProperties *)baton; - if (properties->m_process) - properties->m_process->LoadOperatingSystemPlugin(true); -} - bool ProcessProperties::GetDisableMemoryCache() const { const uint32_t idx = ePropertyDisableMemCache; return m_collection_sp->GetPropertyAtIndexAsBoolean( @@ -1486,8 +1479,7 @@ const lldb::ABISP &Process::GetABI() { return m_abi_sp; } -std::vector<LanguageRuntime *> -Process::GetLanguageRuntimes(bool retry_if_null) { +std::vector<LanguageRuntime *> Process::GetLanguageRuntimes() { std::vector<LanguageRuntime *> language_runtimes; if (m_finalizing) @@ -1500,15 +1492,14 @@ Process::GetLanguageRuntimes(bool retry_if_null) { // yet or the proper condition for loading wasn't yet met (e.g. libc++.so // hadn't been loaded). for (const lldb::LanguageType lang_type : Language::GetSupportedLanguages()) { - if (LanguageRuntime *runtime = GetLanguageRuntime(lang_type, retry_if_null)) + if (LanguageRuntime *runtime = GetLanguageRuntime(lang_type)) language_runtimes.emplace_back(runtime); } return language_runtimes; } -LanguageRuntime *Process::GetLanguageRuntime(lldb::LanguageType language, - bool retry_if_null) { +LanguageRuntime *Process::GetLanguageRuntime(lldb::LanguageType language) { if (m_finalizing) return nullptr; @@ -1517,7 +1508,7 @@ LanguageRuntime *Process::GetLanguageRuntime(lldb::LanguageType language, std::lock_guard<std::recursive_mutex> guard(m_language_runtimes_mutex); LanguageRuntimeCollection::iterator pos; pos = m_language_runtimes.find(language); - if (pos == m_language_runtimes.end() || (retry_if_null && !pos->second)) { + if (pos == m_language_runtimes.end() || !pos->second) { lldb::LanguageRuntimeSP runtime_sp( LanguageRuntime::FindPlugin(this, language)); @@ -5802,7 +5793,8 @@ Process::AdvanceAddressToNextBranchInstruction(Address default_stop_addr, uint32_t branch_index = insn_list->GetIndexOfNextBranchInstruction(insn_offset, target, - false /* ignore_calls*/); + false /* ignore_calls*/, + nullptr); if (branch_index == UINT32_MAX) { return retval; } diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp index 5e5a596e471d..5c6ea7a03933 100644 --- a/lldb/source/Target/StackFrame.cpp +++ b/lldb/source/Target/StackFrame.cpp @@ -573,8 +573,7 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath( if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions)) { // Check if any anonymous unions are there which contain a variable with // the name we need - for (size_t i = 0; i < variable_list->GetSize(); i++) { - VariableSP variable_sp = variable_list->GetVariableAtIndex(i); + for (const VariableSP &variable_sp : *variable_list) { if (!variable_sp) continue; if (!variable_sp->GetName().IsEmpty()) @@ -1529,11 +1528,9 @@ lldb::ValueObjectSP DoGuessValueAt(StackFrame &frame, ConstString reg, : Instruction::Operand::BuildDereference( Instruction::Operand::BuildRegister(reg)); - for (size_t vi = 0, ve = variables.GetSize(); vi != ve; ++vi) { - VariableSP var_sp = variables.GetVariableAtIndex(vi); - if (var_sp->LocationExpression().MatchesOperand(frame, op)) { + for (VariableSP var_sp : variables) { + if (var_sp->LocationExpression().MatchesOperand(frame, op)) return frame.GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); - } } const uint32_t current_inst = diff --git a/lldb/source/Target/StackFrameList.cpp b/lldb/source/Target/StackFrameList.cpp index 6d0c46259c20..87b49849bc99 100644 --- a/lldb/source/Target/StackFrameList.cpp +++ b/lldb/source/Target/StackFrameList.cpp @@ -243,7 +243,8 @@ void StackFrameList::GetOnlyConcreteFramesUpTo(uint32_t end_idx, /// \p return_pc) to \p end. On success this path is stored into \p path, and /// on failure \p path is unchanged. static void FindInterveningFrames(Function &begin, Function &end, - Target &target, addr_t return_pc, + ExecutionContext &exe_ctx, Target &target, + addr_t return_pc, std::vector<Function *> &path, ModuleList &images, Log *log) { LLDB_LOG(log, "Finding frames between {0} and {1}, retn-pc={2:x}", @@ -251,9 +252,9 @@ static void FindInterveningFrames(Function &begin, Function &end, // Find a non-tail calling edge with the correct return PC. if (log) - for (const CallEdge &edge : begin.GetCallEdges()) + for (const auto &edge : begin.GetCallEdges()) LLDB_LOG(log, "FindInterveningFrames: found call with retn-PC = {0:x}", - edge.GetReturnPCAddress(begin, target)); + edge->GetReturnPCAddress(begin, target)); CallEdge *first_edge = begin.GetCallEdgeForReturnAddress(return_pc, target); if (!first_edge) { LLDB_LOG(log, "No call edge outgoing from {0} with retn-PC == {1:x}", @@ -262,7 +263,7 @@ static void FindInterveningFrames(Function &begin, Function &end, } // The first callee may not be resolved, or there may be nothing to fill in. - Function *first_callee = first_edge->GetCallee(images); + Function *first_callee = first_edge->GetCallee(images, exe_ctx); if (!first_callee) { LLDB_LOG(log, "Could not resolve callee"); return; @@ -283,8 +284,10 @@ static void FindInterveningFrames(Function &begin, Function &end, bool ambiguous = false; Function *end; ModuleList &images; + ExecutionContext &context; - DFS(Function *end, ModuleList &images) : end(end), images(images) {} + DFS(Function *end, ModuleList &images, ExecutionContext &context) + : end(end), images(images), context(context) {} void search(Function &first_callee, std::vector<Function *> &path) { dfs(first_callee); @@ -313,8 +316,8 @@ static void FindInterveningFrames(Function &begin, Function &end, // Search the calls made from this callee. active_path.push_back(&callee); - for (CallEdge &edge : callee.GetTailCallingEdges()) { - Function *next_callee = edge.GetCallee(images); + for (const auto &edge : callee.GetTailCallingEdges()) { + Function *next_callee = edge->GetCallee(images, context); if (!next_callee) continue; @@ -326,7 +329,7 @@ static void FindInterveningFrames(Function &begin, Function &end, } }; - DFS(&end, images).search(*first_callee, path); + DFS(&end, images, exe_ctx).search(*first_callee, path); } /// Given that \p next_frame will be appended to the frame list, synthesize @@ -379,8 +382,10 @@ void StackFrameList::SynthesizeTailCallFrames(StackFrame &next_frame) { addr_t return_pc = next_reg_ctx_sp->GetPC(); Target &target = *target_sp.get(); ModuleList &images = next_frame.CalculateTarget()->GetImages(); - FindInterveningFrames(*next_func, *prev_func, target, return_pc, path, images, - log); + ExecutionContext exe_ctx(target_sp, /*get_process=*/true); + exe_ctx.SetFramePtr(&next_frame); + FindInterveningFrames(*next_func, *prev_func, exe_ctx, target, return_pc, + path, images, log); // Push synthetic tail call frames. for (Function *callee : llvm::reverse(path)) { diff --git a/lldb/source/Target/StackFrameRecognizer.cpp b/lldb/source/Target/StackFrameRecognizer.cpp index 567d694bf093..75a6cd215126 100644 --- a/lldb/source/Target/StackFrameRecognizer.cpp +++ b/lldb/source/Target/StackFrameRecognizer.cpp @@ -39,7 +39,7 @@ ScriptedStackFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame) { ValueObjectListSP args = m_interpreter->GetRecognizedArguments(m_python_object_sp, frame); auto args_synthesized = ValueObjectListSP(new ValueObjectList()); - for (const auto o : args->GetObjects()) { + for (const auto &o : args->GetObjects()) { args_synthesized->Append(ValueObjectRecognizerSynthesizedValue::Create( *o, eValueTypeVariableArgument)); } diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 4b9a1b77ad16..83e6f3062666 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -404,8 +404,8 @@ Target::CreateAddressInModuleBreakpoint(lldb::addr_t file_addr, bool internal, bool request_hardware) { SearchFilterSP filter_sp( new SearchFilterForUnconstrainedSearches(shared_from_this())); - BreakpointResolverSP resolver_sp( - new BreakpointResolverAddress(nullptr, file_addr, file_spec)); + BreakpointResolverSP resolver_sp(new BreakpointResolverAddress( + nullptr, file_addr, file_spec ? *file_spec : FileSpec())); return CreateBreakpoint(filter_sp, resolver_sp, internal, request_hardware, false); } @@ -728,11 +728,17 @@ void Target::ConfigureBreakpointName( } void Target::ApplyNameToBreakpoints(BreakpointName &bp_name) { - BreakpointList bkpts_with_name(false); - m_breakpoint_list.FindBreakpointsByName(bp_name.GetName().AsCString(), - bkpts_with_name); + llvm::Expected<std::vector<BreakpointSP>> expected_vector = + m_breakpoint_list.FindBreakpointsByName(bp_name.GetName().AsCString()); + + if (!expected_vector) { + LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS), + "invalid breakpoint name: {}", + llvm::toString(expected_vector.takeError())); + return; + } - for (auto bp_sp : bkpts_with_name.Breakpoints()) + for (auto bp_sp : *expected_vector) bp_name.ConfigureBreakpoint(bp_sp); } @@ -1425,8 +1431,7 @@ void Target::SetExecutableModule(ModuleSP &executable_sp, ModuleList added_modules; executable_objfile->GetDependentModules(dependent_files); for (uint32_t i = 0; i < dependent_files.GetSize(); i++) { - FileSpec dependent_file_spec( - dependent_files.GetFileSpecPointerAtIndex(i)); + FileSpec dependent_file_spec(dependent_files.GetFileSpecAtIndex(i)); FileSpec platform_dependent_file_spec; if (m_platform_sp) m_platform_sp->GetFileWithUUID(dependent_file_spec, nullptr, @@ -2253,20 +2258,6 @@ Target::GetUtilityFunctionForLanguage(const char *text, return utility_fn; } -ClangASTContext *Target::GetScratchClangASTContext(bool create_on_demand) { - if (!m_valid) - return nullptr; - - auto type_system_or_err = - GetScratchTypeSystemForLanguage(eLanguageTypeC, create_on_demand); - if (auto err = type_system_or_err.takeError()) { - LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET), - std::move(err), "Couldn't get scratch ClangASTContext"); - return nullptr; - } - return llvm::dyn_cast<ClangASTContext>(&type_system_or_err.get()); -} - ClangASTImporterSP Target::GetClangASTImporter() { if (m_valid) { if (!m_ast_importer_sp) { @@ -3177,7 +3168,7 @@ void Target::StopHook::SetThreadSpecifier(ThreadSpec *specifier) { void Target::StopHook::GetDescription(Stream *s, lldb::DescriptionLevel level) const { - int indent_level = s->GetIndentLevel(); + unsigned indent_level = s->GetIndentLevel(); s->SetIndentLevel(indent_level + 2); @@ -3470,29 +3461,24 @@ TargetProperties::TargetProperties(Target *target) // Set callbacks to update launch_info whenever "settins set" updated any // of these properties m_collection_sp->SetValueChangedCallback( - ePropertyArg0, TargetProperties::Arg0ValueChangedCallback, this); - m_collection_sp->SetValueChangedCallback( - ePropertyRunArgs, TargetProperties::RunArgsValueChangedCallback, this); + ePropertyArg0, [this] { Arg0ValueChangedCallback(); }); m_collection_sp->SetValueChangedCallback( - ePropertyEnvVars, TargetProperties::EnvVarsValueChangedCallback, this); + ePropertyRunArgs, [this] { RunArgsValueChangedCallback(); }); m_collection_sp->SetValueChangedCallback( - ePropertyInputPath, TargetProperties::InputPathValueChangedCallback, - this); + ePropertyEnvVars, [this] { EnvVarsValueChangedCallback(); }); m_collection_sp->SetValueChangedCallback( - ePropertyOutputPath, TargetProperties::OutputPathValueChangedCallback, - this); + ePropertyInputPath, [this] { InputPathValueChangedCallback(); }); m_collection_sp->SetValueChangedCallback( - ePropertyErrorPath, TargetProperties::ErrorPathValueChangedCallback, - this); + ePropertyOutputPath, [this] { OutputPathValueChangedCallback(); }); m_collection_sp->SetValueChangedCallback( - ePropertyDetachOnError, - TargetProperties::DetachOnErrorValueChangedCallback, this); + ePropertyErrorPath, [this] { ErrorPathValueChangedCallback(); }); + m_collection_sp->SetValueChangedCallback(ePropertyDetachOnError, [this] { + DetachOnErrorValueChangedCallback(); + }); m_collection_sp->SetValueChangedCallback( - ePropertyDisableASLR, TargetProperties::DisableASLRValueChangedCallback, - this); + ePropertyDisableASLR, [this] { DisableASLRValueChangedCallback(); }); m_collection_sp->SetValueChangedCallback( - ePropertyDisableSTDIO, - TargetProperties::DisableSTDIOValueChangedCallback, this); + ePropertyDisableSTDIO, [this] { DisableSTDIOValueChangedCallback(); }); m_experimental_properties_up.reset(new TargetExperimentalProperties()); m_collection_sp->AppendProperty( @@ -3502,16 +3488,16 @@ TargetProperties::TargetProperties(Target *target) true, m_experimental_properties_up->GetValueProperties()); // Update m_launch_info once it was created - Arg0ValueChangedCallback(this, nullptr); - RunArgsValueChangedCallback(this, nullptr); - // EnvVarsValueChangedCallback(this, nullptr); // FIXME: cause segfault in + Arg0ValueChangedCallback(); + RunArgsValueChangedCallback(); + // EnvVarsValueChangedCallback(); // FIXME: cause segfault in // Target::GetPlatform() - InputPathValueChangedCallback(this, nullptr); - OutputPathValueChangedCallback(this, nullptr); - ErrorPathValueChangedCallback(this, nullptr); - DetachOnErrorValueChangedCallback(this, nullptr); - DisableASLRValueChangedCallback(this, nullptr); - DisableSTDIOValueChangedCallback(this, nullptr); + InputPathValueChangedCallback(); + OutputPathValueChangedCallback(); + ErrorPathValueChangedCallback(); + DetachOnErrorValueChangedCallback(); + DisableASLRValueChangedCallback(); + DisableSTDIOValueChangedCallback(); } else { m_collection_sp = std::make_shared<TargetOptionValueProperties>(ConstString("target")); @@ -3554,18 +3540,6 @@ void TargetProperties::SetInjectLocalVariables(ExecutionContext *exe_ctx, true); } -bool TargetProperties::GetUseModernTypeLookup() const { - const Property *exp_property = m_collection_sp->GetPropertyAtIndex( - nullptr, false, ePropertyExperimental); - OptionValueProperties *exp_values = - exp_property->GetValue()->GetAsProperties(); - if (exp_values) - return exp_values->GetPropertyAtIndexAsBoolean( - nullptr, ePropertyUseModernTypeLookup, true); - else - return true; -} - ArchSpec TargetProperties::GetDefaultArchitecture() const { OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch( nullptr, ePropertyDefaultArch); @@ -3996,81 +3970,54 @@ void TargetProperties::SetRequireHardwareBreakpoints(bool b) { m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); } -void TargetProperties::Arg0ValueChangedCallback(void *target_property_ptr, - OptionValue *) { - TargetProperties *this_ = - reinterpret_cast<TargetProperties *>(target_property_ptr); - this_->m_launch_info.SetArg0(this_->GetArg0()); +void TargetProperties::Arg0ValueChangedCallback() { + m_launch_info.SetArg0(GetArg0()); } -void TargetProperties::RunArgsValueChangedCallback(void *target_property_ptr, - OptionValue *) { - TargetProperties *this_ = - reinterpret_cast<TargetProperties *>(target_property_ptr); +void TargetProperties::RunArgsValueChangedCallback() { Args args; - if (this_->GetRunArguments(args)) - this_->m_launch_info.GetArguments() = args; + if (GetRunArguments(args)) + m_launch_info.GetArguments() = args; } -void TargetProperties::EnvVarsValueChangedCallback(void *target_property_ptr, - OptionValue *) { - TargetProperties *this_ = - reinterpret_cast<TargetProperties *>(target_property_ptr); - this_->m_launch_info.GetEnvironment() = this_->GetEnvironment(); +void TargetProperties::EnvVarsValueChangedCallback() { + m_launch_info.GetEnvironment() = GetEnvironment(); } -void TargetProperties::InputPathValueChangedCallback(void *target_property_ptr, - OptionValue *) { - TargetProperties *this_ = - reinterpret_cast<TargetProperties *>(target_property_ptr); - this_->m_launch_info.AppendOpenFileAction( - STDIN_FILENO, this_->GetStandardInputPath(), true, false); +void TargetProperties::InputPathValueChangedCallback() { + m_launch_info.AppendOpenFileAction(STDIN_FILENO, GetStandardInputPath(), true, + false); } -void TargetProperties::OutputPathValueChangedCallback(void *target_property_ptr, - OptionValue *) { - TargetProperties *this_ = - reinterpret_cast<TargetProperties *>(target_property_ptr); - this_->m_launch_info.AppendOpenFileAction( - STDOUT_FILENO, this_->GetStandardOutputPath(), false, true); +void TargetProperties::OutputPathValueChangedCallback() { + m_launch_info.AppendOpenFileAction(STDOUT_FILENO, GetStandardOutputPath(), + false, true); } -void TargetProperties::ErrorPathValueChangedCallback(void *target_property_ptr, - OptionValue *) { - TargetProperties *this_ = - reinterpret_cast<TargetProperties *>(target_property_ptr); - this_->m_launch_info.AppendOpenFileAction( - STDERR_FILENO, this_->GetStandardErrorPath(), false, true); +void TargetProperties::ErrorPathValueChangedCallback() { + m_launch_info.AppendOpenFileAction(STDERR_FILENO, GetStandardErrorPath(), + false, true); } -void TargetProperties::DetachOnErrorValueChangedCallback( - void *target_property_ptr, OptionValue *) { - TargetProperties *this_ = - reinterpret_cast<TargetProperties *>(target_property_ptr); - if (this_->GetDetachOnError()) - this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDetachOnError); +void TargetProperties::DetachOnErrorValueChangedCallback() { + if (GetDetachOnError()) + m_launch_info.GetFlags().Set(lldb::eLaunchFlagDetachOnError); else - this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDetachOnError); + m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDetachOnError); } -void TargetProperties::DisableASLRValueChangedCallback( - void *target_property_ptr, OptionValue *) { - TargetProperties *this_ = - reinterpret_cast<TargetProperties *>(target_property_ptr); - if (this_->GetDisableASLR()) - this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableASLR); +void TargetProperties::DisableASLRValueChangedCallback() { + if (GetDisableASLR()) + m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableASLR); else - this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableASLR); + m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableASLR); } -void TargetProperties::DisableSTDIOValueChangedCallback( - void *target_property_ptr, OptionValue *) { - TargetProperties *this_ = - reinterpret_cast<TargetProperties *>(target_property_ptr); - if (this_->GetDisableSTDIO()) - this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableSTDIO); +void TargetProperties::DisableSTDIOValueChangedCallback() { + if (GetDisableSTDIO()) + m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableSTDIO); else - this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableSTDIO); + m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableSTDIO); } // Target::TargetEventData @@ -4094,7 +4041,7 @@ void Target::TargetEventData::Dump(Stream *s) const { if (i != 0) *s << ", "; m_module_list.GetModuleAtIndex(i)->GetDescription( - s, lldb::eDescriptionLevelBrief); + s->AsRawOstream(), lldb::eDescriptionLevelBrief); } } diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp index 7c7a36e97bbf..1b4db0c2aba5 100644 --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -144,9 +144,9 @@ Status TargetList::CreateTargetInternal( StreamString platform_arch_strm; StreamString module_arch_strm; - platform_arch.DumpTriple(platform_arch_strm); + platform_arch.DumpTriple(platform_arch_strm.AsRawOstream()); matching_module_spec.GetArchitecture().DumpTriple( - module_arch_strm); + module_arch_strm.AsRawOstream()); error.SetErrorStringWithFormat( "the specified architecture '%s' is not compatible with '%s' " "in '%s'", @@ -457,15 +457,12 @@ TargetSP TargetList::FindTargetWithExecutableAndArchitecture( const FileSpec &exe_file_spec, const ArchSpec *exe_arch_ptr) const { std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); TargetSP target_sp; - bool full_match = (bool)exe_file_spec.GetDirectory(); - collection::const_iterator pos, end = m_target_list.end(); for (pos = m_target_list.begin(); pos != end; ++pos) { Module *exe_module = (*pos)->GetExecutableModulePointer(); if (exe_module) { - if (FileSpec::Equal(exe_file_spec, exe_module->GetFileSpec(), - full_match)) { + if (FileSpec::Match(exe_file_spec, exe_module->GetFileSpec())) { if (exe_arch_ptr) { if (!exe_arch_ptr->IsCompatibleMatch(exe_module->GetArchitecture())) continue; diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td index 9079c3cf4276..ff8062aaa2cb 100644 --- a/lldb/source/Target/TargetProperties.td +++ b/lldb/source/Target/TargetProperties.td @@ -4,9 +4,6 @@ let Definition = "experimental" in { def InjectLocalVars : Property<"inject-local-vars", "Boolean">, Global, DefaultTrue, Desc<"If true, inject local variables explicitly into the expression text. This will fix symbol resolution when there are name collisions between ivars and local variables. But it can make expressions run much more slowly.">; - def UseModernTypeLookup : Property<"use-modern-type-lookup", "Boolean">, - Global, DefaultFalse, - Desc<"If true, use Clang's modern type lookup infrastructure.">; } let Definition = "target" in { diff --git a/lldb/source/Target/ThreadPlanRunToAddress.cpp b/lldb/source/Target/ThreadPlanRunToAddress.cpp index 160743a9f3f8..32ea2e675270 100644 --- a/lldb/source/Target/ThreadPlanRunToAddress.cpp +++ b/lldb/source/Target/ThreadPlanRunToAddress.cpp @@ -97,7 +97,7 @@ void ThreadPlanRunToAddress::GetDescription(Stream *s, s->Printf("run to addresses: "); for (size_t i = 0; i < num_addresses; i++) { - s->Address(m_addresses[i], sizeof(addr_t)); + DumpAddress(s->AsRawOstream(), m_addresses[i], sizeof(addr_t)); s->Printf(" "); } } else { @@ -116,7 +116,7 @@ void ThreadPlanRunToAddress::GetDescription(Stream *s, s->Indent(); } - s->Address(m_addresses[i], sizeof(addr_t)); + DumpAddress(s->AsRawOstream(), m_addresses[i], sizeof(addr_t)); s->Printf(" using breakpoint: %d - ", m_break_ids[i]); Breakpoint *breakpoint = m_thread.CalculateTarget()->GetBreakpointByID(m_break_ids[i]).get(); @@ -143,7 +143,7 @@ bool ThreadPlanRunToAddress::ValidatePlan(Stream *error) { all_bps_good = false; if (error) { error->Printf("Could not set breakpoint for address: "); - error->Address(m_addresses[i], sizeof(addr_t)); + DumpAddress(error->AsRawOstream(), m_addresses[i], sizeof(addr_t)); error->Printf("\n"); } } diff --git a/lldb/source/Target/ThreadPlanStepInRange.cpp b/lldb/source/Target/ThreadPlanStepInRange.cpp index 71045cc7a990..ab1f6a21a862 100644 --- a/lldb/source/Target/ThreadPlanStepInRange.cpp +++ b/lldb/source/Target/ThreadPlanStepInRange.cpp @@ -145,8 +145,8 @@ bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) { if (log) { StreamString s; - s.Address( - m_thread.GetRegisterContext()->GetPC(), + DumpAddress( + s.AsRawOstream(), m_thread.GetRegisterContext()->GetPC(), m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize()); LLDB_LOGF(log, "ThreadPlanStepInRange reached %s.", s.GetData()); } @@ -339,7 +339,7 @@ bool ThreadPlanStepInRange::FrameMatchesAvoidCriteria() { if (frame_library) { for (size_t i = 0; i < num_libraries; i++) { const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i)); - if (FileSpec::Equal(file_spec, frame_library, false)) { + if (FileSpec::Match(file_spec, frame_library)) { libraries_say_avoid = true; break; } @@ -392,7 +392,7 @@ bool ThreadPlanStepInRange::DefaultShouldStopHereCallback( should_stop_here = ThreadPlanShouldStopHere::DefaultShouldStopHereCallback( current_plan, flags, operation, status, baton); if (!should_stop_here) - return should_stop_here; + return false; if (should_stop_here && current_plan->GetKind() == eKindStepInRange && operation == eFrameCompareYounger) { diff --git a/lldb/source/Target/ThreadPlanStepInstruction.cpp b/lldb/source/Target/ThreadPlanStepInstruction.cpp index 0c75cb811156..afcc9d608b27 100644 --- a/lldb/source/Target/ThreadPlanStepInstruction.cpp +++ b/lldb/source/Target/ThreadPlanStepInstruction.cpp @@ -65,7 +65,7 @@ void ThreadPlanStepInstruction::GetDescription(Stream *s, PrintFailureIfAny(); } else { s->Printf("Stepping one instruction past "); - s->Address(m_instruction_addr, sizeof(addr_t)); + DumpAddress(s->AsRawOstream(), m_instruction_addr, sizeof(addr_t)); if (!m_start_has_symbol) s->Printf(" which has no symbol"); @@ -182,14 +182,16 @@ bool ThreadPlanStepInstruction::ShouldStop(Event *event_ptr) { s.PutCString("Stepped in to: "); addr_t stop_addr = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC(); - s.Address(stop_addr, m_thread.CalculateTarget() - ->GetArchitecture() - .GetAddressByteSize()); + DumpAddress(s.AsRawOstream(), stop_addr, + m_thread.CalculateTarget() + ->GetArchitecture() + .GetAddressByteSize()); s.PutCString(" stepping out to: "); addr_t return_addr = return_frame->GetRegisterContext()->GetPC(); - s.Address(return_addr, m_thread.CalculateTarget() - ->GetArchitecture() - .GetAddressByteSize()); + DumpAddress(s.AsRawOstream(), return_addr, + m_thread.CalculateTarget() + ->GetArchitecture() + .GetAddressByteSize()); LLDB_LOGF(log, "%s.", s.GetData()); } diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp b/lldb/source/Target/ThreadPlanStepOut.cpp index d7dae446b229..f15a343aaa38 100644 --- a/lldb/source/Target/ThreadPlanStepOut.cpp +++ b/lldb/source/Target/ThreadPlanStepOut.cpp @@ -126,6 +126,25 @@ ThreadPlanStepOut::ThreadPlanStepOut( if (m_return_addr == LLDB_INVALID_ADDRESS) return; + // Perform some additional validation on the return address. + uint32_t permissions = 0; + if (!m_thread.GetProcess()->GetLoadAddressPermissions(m_return_addr, + permissions)) { + m_constructor_errors.Printf("Return address (0x%" PRIx64 + ") permissions not found.", + m_return_addr); + LLDB_LOGF(log, "ThreadPlanStepOut(%p): %s", static_cast<void *>(this), + m_constructor_errors.GetData()); + return; + } else if (!(permissions & ePermissionsExecutable)) { + m_constructor_errors.Printf("Return address (0x%" PRIx64 + ") did not point to executable memory.", + m_return_addr); + LLDB_LOGF(log, "ThreadPlanStepOut(%p): %s", static_cast<void *>(this), + m_constructor_errors.GetData()); + return; + } + Breakpoint *return_bp = m_thread.CalculateTarget() ->CreateBreakpoint(m_return_addr, true, false) .get(); @@ -238,8 +257,13 @@ bool ThreadPlanStepOut::ValidatePlan(Stream *error) { } if (m_return_bp_id == LLDB_INVALID_BREAK_ID) { - if (error) + if (error) { error->PutCString("Could not create return address breakpoint."); + if (m_constructor_errors.GetSize() > 0) { + error->PutCString(" "); + error->PutCString(m_constructor_errors.GetString()); + } + } return false; } diff --git a/lldb/source/Target/ThreadPlanStepOverRange.cpp b/lldb/source/Target/ThreadPlanStepOverRange.cpp index 2de678597c8a..3dc1967e6d4e 100644 --- a/lldb/source/Target/ThreadPlanStepOverRange.cpp +++ b/lldb/source/Target/ThreadPlanStepOverRange.cpp @@ -128,8 +128,8 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) { if (log) { StreamString s; - s.Address( - m_thread.GetRegisterContext()->GetPC(), + DumpAddress( + s.AsRawOstream(), m_thread.GetRegisterContext()->GetPC(), m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize()); LLDB_LOGF(log, "ThreadPlanStepOverRange reached %s.", s.GetData()); } diff --git a/lldb/source/Target/ThreadPlanStepRange.cpp b/lldb/source/Target/ThreadPlanStepRange.cpp index 27513a34eadb..d1c56165da50 100644 --- a/lldb/source/Target/ThreadPlanStepRange.cpp +++ b/lldb/source/Target/ThreadPlanStepRange.cpp @@ -238,8 +238,19 @@ lldb::FrameComparison ThreadPlanStepRange::CompareCurrentFrameToStartFrame() { } bool ThreadPlanStepRange::StopOthers() { - return (m_stop_others == lldb::eOnlyThisThread || - m_stop_others == lldb::eOnlyDuringStepping); + switch (m_stop_others) { + case lldb::eOnlyThisThread: + return true; + case lldb::eOnlyDuringStepping: + // If there is a call in the range of the next branch breakpoint, + // then we should always run all threads, since a call can execute + // arbitrary code which might for instance take a lock that's held + // by another thread. + return !m_found_calls; + case lldb::eAllThreads: + return false; + } + llvm_unreachable("Unhandled run mode!"); } InstructionList *ThreadPlanStepRange::GetInstructionsForAddress( @@ -292,6 +303,7 @@ void ThreadPlanStepRange::ClearNextBranchBreakpoint() { GetTarget().RemoveBreakpointByID(m_next_branch_bp_sp->GetID()); m_next_branch_bp_sp.reset(); m_could_not_resolve_hw_bp = false; + m_found_calls = false; } } @@ -305,6 +317,9 @@ bool ThreadPlanStepRange::SetNextBranchBreakpoint() { if (!m_use_fast_step) return false; + // clear the m_found_calls, we'll rediscover it for this range. + m_found_calls = false; + lldb::addr_t cur_addr = GetThread().GetRegisterContext()->GetPC(); // Find the current address in our address ranges, and fetch the disassembly // if we haven't already: @@ -319,7 +334,8 @@ bool ThreadPlanStepRange::SetNextBranchBreakpoint() { const bool ignore_calls = GetKind() == eKindStepOverRange; uint32_t branch_index = instructions->GetIndexOfNextBranchInstruction(pc_index, target, - ignore_calls); + ignore_calls, + &m_found_calls); Address run_to_address; diff --git a/lldb/source/Target/ThreadPlanStepThrough.cpp b/lldb/source/Target/ThreadPlanStepThrough.cpp index 92b7fce1bc90..8c7b180fce2d 100644 --- a/lldb/source/Target/ThreadPlanStepThrough.cpp +++ b/lldb/source/Target/ThreadPlanStepThrough.cpp @@ -119,11 +119,11 @@ void ThreadPlanStepThrough::GetDescription(Stream *s, s->Printf("Step through"); else { s->PutCString("Stepping through trampoline code from: "); - s->Address(m_start_address, sizeof(addr_t)); + DumpAddress(s->AsRawOstream(), m_start_address, sizeof(addr_t)); if (m_backstop_bkpt_id != LLDB_INVALID_BREAK_ID) { s->Printf(" with backstop breakpoint ID: %d at address: ", m_backstop_bkpt_id); - s->Address(m_backstop_addr, sizeof(addr_t)); + DumpAddress(s->AsRawOstream(), m_backstop_addr, sizeof(addr_t)); } else s->PutCString(" unable to set a backstop breakpoint."); } diff --git a/lldb/source/Target/ThreadPlanTracer.cpp b/lldb/source/Target/ThreadPlanTracer.cpp index 5782fe8e6443..b50c1636b7ff 100644 --- a/lldb/source/Target/ThreadPlanTracer.cpp +++ b/lldb/source/Target/ThreadPlanTracer.cpp @@ -115,10 +115,6 @@ TypeFromUser ThreadPlanAssemblyTracer::GetIntPointerType() { ThreadPlanAssemblyTracer::~ThreadPlanAssemblyTracer() = default; void ThreadPlanAssemblyTracer::TracingStarted() { - RegisterContext *reg_ctx = m_thread.GetRegisterContext().get(); - - if (m_register_values.empty()) - m_register_values.resize(reg_ctx->GetRegisterCount()); } void ThreadPlanAssemblyTracer::TracingEnded() { m_register_values.clear(); } @@ -208,6 +204,11 @@ void ThreadPlanAssemblyTracer::Log() { } } + if (m_register_values.empty()) { + RegisterContext *reg_ctx = m_thread.GetRegisterContext().get(); + m_register_values.resize(reg_ctx->GetRegisterCount()); + } + RegisterValue reg_value; for (uint32_t reg_num = 0, num_registers = reg_ctx->GetRegisterCount(); reg_num < num_registers; ++reg_num) { |
