Skip to content

🍒/rebranch/bd3976fed470+8d36a82d0a3d+11f45f36dcf5 #5133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lldb/include/lldb/Core/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
eBroadcastBitProgress = (1 << 0),
eBroadcastBitWarning = (1 << 1),
eBroadcastBitError = (1 << 2),
eBroadcastSymbolChange = (1 << 3),
};

static ConstString GetStaticBroadcasterClass();
Expand Down Expand Up @@ -438,6 +439,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
llvm::Optional<lldb::user_id_t> debugger_id = llvm::None,
std::once_flag *once = nullptr);

static void ReportSymbolChange(const ModuleSpec &module_spec);

protected:
friend class CommandInterpreter;
friend class SwiftREPL;
Expand Down
23 changes: 23 additions & 0 deletions lldb/include/lldb/Core/DebuggerEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "lldb/Core/ModuleSpec.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Event.h"

Expand Down Expand Up @@ -82,6 +83,28 @@ class DiagnosticEventData : public EventData {
const DiagnosticEventData &operator=(const DiagnosticEventData &) = delete;
};

class SymbolChangeEventData : public EventData {
public:
SymbolChangeEventData(lldb::DebuggerWP debugger_wp, ModuleSpec module_spec)
: m_debugger_wp(debugger_wp), m_module_spec(std::move(module_spec)) {}

static ConstString GetFlavorString();
ConstString GetFlavor() const override;

static const SymbolChangeEventData *
GetEventDataFromEvent(const Event *event_ptr);

void DoOnRemoval(Event *event_ptr) override;

private:
lldb::DebuggerWP m_debugger_wp;
ModuleSpec m_module_spec;

SymbolChangeEventData(const SymbolChangeEventData &) = delete;
const SymbolChangeEventData &
operator=(const SymbolChangeEventData &) = delete;
};

} // namespace lldb_private

#endif // LLDB_CORE_DEBUGGER_EVENTS_H
3 changes: 3 additions & 0 deletions lldb/include/lldb/Core/ModuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ModuleListProperties : public Properties {
bool SetClangModulesCachePath(const FileSpec &path);
bool GetEnableExternalLookup() const;
bool SetEnableExternalLookup(bool new_value);
bool GetEnableBackgroundLookup() const;
bool GetEnableLLDBIndexCache() const;
bool SetEnableLLDBIndexCache(bool new_value);
uint64_t GetLLDBIndexCacheMaxByteSize();
Expand Down Expand Up @@ -466,6 +467,8 @@ class ModuleList {
static void FindSharedModules(const ModuleSpec &module_spec,
ModuleList &matching_module_list);

static lldb::ModuleSP FindSharedModule(const UUID &uuid);

static size_t RemoveOrphanSharedModules(bool mandatory);

static bool RemoveSharedModuleIfOrphaned(const Module *module_ptr);
Expand Down
11 changes: 10 additions & 1 deletion lldb/include/lldb/Symbol/LocateSymbolFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "lldb/Core/FileSpecList.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-forward.h"

namespace lldb_private {

Expand Down Expand Up @@ -52,7 +53,15 @@ class Symbols {
//
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
Status &error,
bool force_lookup = true);
bool force_lookup = true,
bool copy_executable = true);

/// Locate the symbol file for the given UUID on a background thread. This
/// function returns immediately. Under the hood it uses the debugger's
/// thread pool to call DownloadObjectAndSymbolFile. If a symbol file is
/// found, this will notify all target which contain the module with the
/// given UUID.
static void DownloadSymbolFileAsync(const UUID &uuid);
};

} // namespace lldb_private
Expand Down
29 changes: 15 additions & 14 deletions lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class TargetProperties : public Properties {
bool GetEnableNotifyAboutFixIts() const;

FileSpec GetSaveJITObjectsDir() const;

bool GetEnableSyntheticValue() const;

uint32_t GetMaxZeroPaddingInFloatFormat() const;
Expand Down Expand Up @@ -305,7 +305,7 @@ class TargetProperties : public Properties {
void DisableASLRValueChangedCallback();
void InheritTCCValueChangedCallback();
void DisableSTDIOValueChangedCallback();

// Settings checker for target.jit-save-objects-dir:
void CheckJITObjectsDir();

Expand Down Expand Up @@ -543,7 +543,8 @@ class Target : public std::enable_shared_from_this<Target>,
eBroadcastBitModulesLoaded = (1 << 1),
eBroadcastBitModulesUnloaded = (1 << 2),
eBroadcastBitWatchpointChanged = (1 << 3),
eBroadcastBitSymbolsLoaded = (1 << 4)
eBroadcastBitSymbolsLoaded = (1 << 4),
eBroadcastBitSymbolsChanged = (1 << 5),
};

// These two functions fill out the Broadcaster interface:
Expand Down Expand Up @@ -1045,7 +1046,7 @@ class Target : public std::enable_shared_from_this<Target>,
ModuleIsExcludedForUnconstrainedSearches(const lldb::ModuleSP &module_sp);

const ArchSpec &GetArchitecture() const { return m_arch.GetSpec(); }

/// Returns the name of the target's ABI plugin.
llvm::StringRef GetABIName() const;

Expand Down Expand Up @@ -1535,30 +1536,30 @@ class Target : public std::enable_shared_from_this<Target>,
LazyBool pass = eLazyBoolCalculate;
LazyBool notify = eLazyBoolCalculate;
LazyBool stop = eLazyBoolCalculate;
DummySignalValues(LazyBool pass, LazyBool notify, LazyBool stop) :
pass(pass), notify(notify), stop(stop) {}
DummySignalValues(LazyBool pass, LazyBool notify, LazyBool stop)
: pass(pass), notify(notify), stop(stop) {}
DummySignalValues() = default;
};
using DummySignalElement = llvm::StringMapEntry<DummySignalValues>;
static bool UpdateSignalFromDummy(lldb::UnixSignalsSP signals_sp,
const DummySignalElement &element);
static bool ResetSignalFromDummy(lldb::UnixSignalsSP signals_sp,
const DummySignalElement &element);
static bool UpdateSignalFromDummy(lldb::UnixSignalsSP signals_sp,
const DummySignalElement &element);
static bool ResetSignalFromDummy(lldb::UnixSignalsSP signals_sp,
const DummySignalElement &element);

public:
/// Add a signal to the Target's list of stored signals/actions. These
/// values will get copied into any processes launched from
/// this target.
void AddDummySignal(llvm::StringRef name, LazyBool pass, LazyBool print,
void AddDummySignal(llvm::StringRef name, LazyBool pass, LazyBool print,
LazyBool stop);
/// Updates the signals in signals_sp using the stored dummy signals.
/// If warning_stream_sp is not null, if any stored signals are not found in
/// the current process, a warning will be emitted here.
void UpdateSignalsFromDummy(lldb::UnixSignalsSP signals_sp,
void UpdateSignalsFromDummy(lldb::UnixSignalsSP signals_sp,
lldb::StreamSP warning_stream_sp);
/// Clear the dummy signals in signal_names from the target, or all signals
/// if signal_names is empty. Also remove the behaviors they set from the
/// process's signals if it exists.
/// process's signals if it exists.
void ClearDummySignals(Args &signal_names);
/// Print all the signals set in this target.
void PrintDummySignals(Stream &strm, Args &signals);
Expand Down Expand Up @@ -1644,7 +1645,7 @@ class Target : public std::enable_shared_from_this<Target>,
lldb::TraceSP m_trace_sp;
/// Stores the frame recognizers of this target.
lldb::StackFrameRecognizerManagerUP m_frame_recognizer_manager_up;
/// These are used to set the signal state when you don't have a process and
/// These are used to set the signal state when you don't have a process and
/// more usefully in the Dummy target where you can't know exactly what
/// signals you will have.
llvm::StringMap<DummySignalValues> m_dummy_signals;
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Core/CoreProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ let Definition = "modulelist" in {
Global,
DefaultTrue,
Desc<"Control the use of external tools and repositories to locate symbol files. Directories listed in target.debug-file-search-paths and directory of the executable are always checked first for separate debug info files. Then depending on this setting: On macOS, Spotlight would be also used to locate a matching .dSYM bundle based on the UUID of the executable. On NetBSD, directory /usr/libdata/debug would be also searched. On platforms other than NetBSD directory /usr/lib/debug would be also searched.">;
def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
Global,
DefaultFalse,
Desc<"On macOS, enable calling dsymForUUID (or an equivalent script/binary) in the background to locate symbol files that weren't found.">;
def ClangModulesCachePath: Property<"clang-modules-cache-path", "FileSpec">,
Global,
DefaultStringValue<"">,
Expand Down
32 changes: 24 additions & 8 deletions lldb/source/Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "lldb/Core/FormatEntity.h"
#include "lldb/Core/Mangled.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/StreamAsynchronousIO.h"
#include "lldb/Core/StreamFile.h"
Expand Down Expand Up @@ -104,6 +105,7 @@ static std::recursive_mutex *g_debugger_list_mutex_ptr =
nullptr; // NOTE: intentional leak to avoid issues with C++ destructor chain
static DebuggerList *g_debugger_list_ptr =
nullptr; // NOTE: intentional leak to avoid issues with C++ destructor chain
static llvm::ThreadPool *g_thread_pool = nullptr;

static constexpr OptionEnumValueElement g_show_disassembly_enum_values[] = {
{
Expand Down Expand Up @@ -538,13 +540,19 @@ void Debugger::Initialize(LoadPluginCallbackType load_plugin_callback) {
"Debugger::Initialize called more than once!");
g_debugger_list_mutex_ptr = new std::recursive_mutex();
g_debugger_list_ptr = new DebuggerList();
g_thread_pool = new llvm::ThreadPool(llvm::optimal_concurrency());
g_load_plugin_callback = load_plugin_callback;
}

void Debugger::Terminate() {
assert(g_debugger_list_ptr &&
"Debugger::Terminate called without a matching Debugger::Initialize!");

if (g_thread_pool) {
// The destructor will wait for all the threads to complete.
delete g_thread_pool;
}

if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
// Clear our global list of debugger objects
{
Expand Down Expand Up @@ -1445,6 +1453,18 @@ void Debugger::ReportError(std::string message,
debugger_id, once);
}

void Debugger::ReportSymbolChange(const ModuleSpec &module_spec) {
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
for (DebuggerSP debugger_sp : *g_debugger_list_ptr) {
EventSP event_sp = std::make_shared<Event>(
Debugger::eBroadcastSymbolChange,
new SymbolChangeEventData(debugger_sp, module_spec));
debugger_sp->GetBroadcaster().BroadcastEvent(event_sp);
}
}
}

static std::shared_ptr<LogHandler>
CreateLogHandler(LogHandlerKind log_handler_kind, int fd, bool should_close,
size_t buffer_size) {
Expand Down Expand Up @@ -1754,8 +1774,8 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
CommandInterpreter::eBroadcastBitAsynchronousErrorData);

listener_sp->StartListeningForEvents(
&m_broadcaster,
eBroadcastBitProgress | eBroadcastBitWarning | eBroadcastBitError);
&m_broadcaster, eBroadcastBitProgress | eBroadcastBitWarning |
eBroadcastBitError | eBroadcastSymbolChange);

// Let the thread that spawned us know that we have started up and that we
// are now listening to all required events so no events get missed
Expand Down Expand Up @@ -2057,11 +2077,7 @@ Status Debugger::RunREPL(LanguageType language, const char *repl_options) {
}

llvm::ThreadPool &Debugger::GetThreadPool() {
// NOTE: intentional leak to avoid issues with C++ destructor chain
static llvm::ThreadPool *g_thread_pool = nullptr;
static llvm::once_flag g_once_flag;
llvm::call_once(g_once_flag, []() {
g_thread_pool = new llvm::ThreadPool(llvm::optimal_concurrency());
});
assert(g_thread_pool &&
"Debugger::GetThreadPool called before Debugger::Initialize");
return *g_thread_pool;
}
37 changes: 37 additions & 0 deletions lldb/source/Core/DebuggerEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
//===----------------------------------------------------------------------===//

#include "lldb/Core/DebuggerEvents.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
#include "llvm/Support/WithColor.h"

using namespace lldb_private;
using namespace lldb;

template <typename T>
static const T *GetEventDataFromEventImpl(const Event *event_ptr) {
Expand Down Expand Up @@ -79,3 +82,37 @@ const DiagnosticEventData *
DiagnosticEventData::GetEventDataFromEvent(const Event *event_ptr) {
return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr);
}

ConstString SymbolChangeEventData::GetFlavorString() {
static ConstString g_flavor("SymbolChangeEventData");
return g_flavor;
}

ConstString SymbolChangeEventData::GetFlavor() const {
return SymbolChangeEventData::GetFlavorString();
}

const SymbolChangeEventData *
SymbolChangeEventData::GetEventDataFromEvent(const Event *event_ptr) {
return GetEventDataFromEventImpl<SymbolChangeEventData>(event_ptr);
}

void SymbolChangeEventData::DoOnRemoval(Event *event_ptr) {
DebuggerSP debugger_sp(m_debugger_wp.lock());
if (!debugger_sp)
return;

for (TargetSP target_sp : debugger_sp->GetTargetList().Targets()) {
if (ModuleSP module_sp =
target_sp->GetImages().FindModule(m_module_spec.GetUUID())) {
{
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
if (!module_sp->GetSymbolFileFileSpec())
module_sp->SetSymbolFileFileSpec(m_module_spec.GetSymbolFileSpec());
}
ModuleList module_list;
module_list.Append(module_sp);
target_sp->SymbolsDidLoad(module_list);
}
}
}
6 changes: 5 additions & 1 deletion lldb/source/Core/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/LocateSymbolFile.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Symbol/SymbolContext.h"
Expand Down Expand Up @@ -1362,8 +1363,11 @@ void Module::SectionFileAddressesChanged() {
}

UnwindTable &Module::GetUnwindTable() {
if (!m_unwind_table)
if (!m_unwind_table) {
m_unwind_table.emplace(*this);
if (!m_symfile_spec)
Symbols::DownloadSymbolFileAsync(GetUUID());
}
return *m_unwind_table;
}

Expand Down
10 changes: 10 additions & 0 deletions lldb/source/Core/ModuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ bool ModuleListProperties::SetEnableExternalLookup(bool new_value) {
nullptr, ePropertyEnableExternalLookup, new_value);
}

bool ModuleListProperties::GetEnableBackgroundLookup() const {
const uint32_t idx = ePropertyEnableBackgroundLookup;
return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx, g_modulelist_properties[idx].default_uint_value != 0);
}

FileSpec ModuleListProperties::GetClangModulesCachePath() const {
return m_collection_sp
->GetPropertyAtIndexAsOptionValueFileSpec(nullptr, false,
Expand Down Expand Up @@ -925,6 +931,10 @@ void ModuleList::FindSharedModules(const ModuleSpec &module_spec,
GetSharedModuleList().FindModules(module_spec, matching_module_list);
}

lldb::ModuleSP ModuleList::FindSharedModule(const UUID &uuid) {
return GetSharedModuleList().FindModule(uuid);
}

size_t ModuleList::RemoveOrphanSharedModules(bool mandatory) {
return GetSharedModuleList().RemoveOrphans(mandatory);
}
Expand Down
Loading