Skip to content

[lldb] Fix missing overloads in ThreadMemory #132734

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

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ ThreadSP OperatingSystemPython::CreateThreadFromThreadInfo(
if (!thread_sp) {
if (did_create_ptr)
*did_create_ptr = true;
thread_sp = std::make_shared<ThreadMemory>(*m_process, tid, name, queue,
reg_data_addr);
thread_sp = std::make_shared<ThreadMemoryProvidingNameAndQueue>(
*m_process, tid, name, queue, reg_data_addr);
}

if (core_number < core_thread_list.GetSize(false)) {
Expand Down
23 changes: 11 additions & 12 deletions lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@
using namespace lldb;
using namespace lldb_private;

ThreadMemory::ThreadMemory(Process &process, lldb::tid_t tid,
const ValueObjectSP &thread_info_valobj_sp)
: Thread(process, tid), m_backing_thread_sp(),
m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue(),
m_register_data_addr(LLDB_INVALID_ADDRESS) {}

ThreadMemory::ThreadMemory(Process &process, lldb::tid_t tid,
llvm::StringRef name, llvm::StringRef queue,
lldb::addr_t register_data_addr)
: Thread(process, tid), m_backing_thread_sp(), m_thread_info_valobj_sp(),
m_name(std::string(name)), m_queue(std::string(queue)),
m_register_data_addr(register_data_addr) {}
ThreadMemoryProvidingNameAndQueue::ThreadMemoryProvidingNameAndQueue(
Process &process, lldb::tid_t tid,
const ValueObjectSP &thread_info_valobj_sp)
: ThreadMemoryProvidingName(process, tid, LLDB_INVALID_ADDRESS, ""),
m_thread_info_valobj_sp(thread_info_valobj_sp), m_queue() {}

ThreadMemoryProvidingNameAndQueue::ThreadMemoryProvidingNameAndQueue(
Process &process, lldb::tid_t tid, llvm::StringRef name,
llvm::StringRef queue, lldb::addr_t register_data_addr)
: ThreadMemoryProvidingName(process, tid, register_data_addr, name),
m_thread_info_valobj_sp(), m_queue(std::string(queue)) {}

ThreadMemory::~ThreadMemory() { DestroyThread(); }

Expand Down
198 changes: 174 additions & 24 deletions lldb/source/Plugins/Process/Utility/ThreadMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@

#include "lldb/Target/Thread.h"

/// A memory thread with its own ID, optionally backed by a real thread.
/// Most methods of this class dispatch to the real thread if it is not null.
/// Notable exceptions are the methods calculating the StopInfo and
/// RegisterContext of the thread, those may query the OS plugin that created
/// the thread.
class ThreadMemory : public lldb_private::Thread {
public:
ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
const lldb::ValueObjectSP &thread_info_valobj_sp);

ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
llvm::StringRef name, llvm::StringRef queue,
lldb::addr_t register_data_addr);
lldb::addr_t register_data_addr)
: Thread(process, tid), m_register_data_addr(register_data_addr) {}

~ThreadMemory() override;

Expand All @@ -38,23 +40,82 @@ class ThreadMemory : public lldb_private::Thread {
}

const char *GetName() override {
if (!m_name.empty())
return m_name.c_str();
if (m_backing_thread_sp)
return m_backing_thread_sp->GetName();
return nullptr;
}

const char *GetQueueName() override {
if (!m_queue.empty())
return m_queue.c_str();
if (m_backing_thread_sp)
return m_backing_thread_sp->GetQueueName();
return nullptr;
}

void WillResume(lldb::StateType resume_state) override;

void SetQueueName(const char *name) override {
if (m_backing_thread_sp)
m_backing_thread_sp->SetQueueName(name);
}

lldb::queue_id_t GetQueueID() override {
if (m_backing_thread_sp)
return m_backing_thread_sp->GetQueueID();
return LLDB_INVALID_QUEUE_ID;
}

void SetQueueID(lldb::queue_id_t new_val) override {
if (m_backing_thread_sp)
m_backing_thread_sp->SetQueueID(new_val);
}

lldb::QueueKind GetQueueKind() override {
if (m_backing_thread_sp)
return m_backing_thread_sp->GetQueueKind();
return lldb::eQueueKindUnknown;
}

void SetQueueKind(lldb::QueueKind kind) override {
if (m_backing_thread_sp)
m_backing_thread_sp->SetQueueKind(kind);
}

lldb::QueueSP GetQueue() override {
if (m_backing_thread_sp)
return m_backing_thread_sp->GetQueue();
return lldb::QueueSP();
}

lldb::addr_t GetQueueLibdispatchQueueAddress() override {
if (m_backing_thread_sp)
return m_backing_thread_sp->GetQueueLibdispatchQueueAddress();
return LLDB_INVALID_ADDRESS;
}

void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) override {
if (m_backing_thread_sp)
m_backing_thread_sp->SetQueueLibdispatchQueueAddress(dispatch_queue_t);
}

lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() override {
if (m_backing_thread_sp)
return m_backing_thread_sp->GetAssociatedWithLibdispatchQueue();
return lldb_private::eLazyBoolNo;
}

void SetAssociatedWithLibdispatchQueue(
lldb_private::LazyBool associated_with_libdispatch_queue) override {
if (m_backing_thread_sp)
m_backing_thread_sp->SetAssociatedWithLibdispatchQueue(
associated_with_libdispatch_queue);
}

bool ThreadHasQueueInformation() const override {
if (m_backing_thread_sp)
return m_backing_thread_sp->ThreadHasQueueInformation();
return false;
}

void DidResume() override {
if (m_backing_thread_sp)
m_backing_thread_sp->DidResume();
Expand All @@ -68,8 +129,6 @@ class ThreadMemory : public lldb_private::Thread {

void RefreshStateAfterStop() override;

lldb::ValueObjectSP &GetValueObject() { return m_thread_info_valobj_sp; }

void ClearStackFrames() override;

void ClearBackingThread() override {
Expand All @@ -79,34 +138,125 @@ class ThreadMemory : public lldb_private::Thread {
}

bool SetBackingThread(const lldb::ThreadSP &thread_sp) override {
// printf ("Thread 0x%llx is being backed by thread 0x%llx\n", GetID(),
// thread_sp->GetID());
m_backing_thread_sp = thread_sp;
thread_sp->SetBackedThread(*this);
return (bool)thread_sp;
return thread_sp.get();
}

lldb::ThreadSP GetBackingThread() const override {
return m_backing_thread_sp;
}

protected:
bool IsOperatingSystemPluginThread() const override { return true; }

// If this memory thread is actually represented by a thread from the
// lldb_private::Process subclass, then fill in the thread here and
// all APIs will be routed through this thread object. If m_backing_thread_sp
// is empty, then this thread is simply in memory with no representation
// through the process plug-in.
private:
lldb::addr_t m_register_data_addr;
lldb::ThreadSP m_backing_thread_sp;
lldb::ValueObjectSP m_thread_info_valobj_sp;

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a comment mirroring the ProvidingNameAndQueue

/// A ThreadMemory that optionally overrides the thread name.
class ThreadMemoryProvidingName : public ThreadMemory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments here would be nice.

public:
ThreadMemoryProvidingName(lldb_private::Process &process, lldb::tid_t tid,
lldb::addr_t register_data_addr,
llvm::StringRef name)
: ThreadMemory(process, tid, register_data_addr), m_name(name) {}

const char *GetName() override {
if (!m_name.empty())
return m_name.c_str();
return ThreadMemory::GetName();
}

~ThreadMemoryProvidingName() override = default;

private:
std::string m_name;
};

/// A ThreadMemoryProvidingName that optionally overrides queue information.
class ThreadMemoryProvidingNameAndQueue : public ThreadMemoryProvidingName {
public:
ThreadMemoryProvidingNameAndQueue(
lldb_private::Process &process, lldb::tid_t tid,
const lldb::ValueObjectSP &thread_info_valobj_sp);

ThreadMemoryProvidingNameAndQueue(lldb_private::Process &process,
lldb::tid_t tid, llvm::StringRef name,
llvm::StringRef queue,
lldb::addr_t register_data_addr);

~ThreadMemoryProvidingNameAndQueue() override = default;

const char *GetQueueName() override {
if (!m_queue.empty())
return m_queue.c_str();
return ThreadMemory::GetQueueName();
}

/// TODO: this method should take into account the queue override.
void SetQueueName(const char *name) override { Thread::SetQueueName(name); }

/// TODO: this method should take into account the queue override.
lldb::queue_id_t GetQueueID() override { return Thread::GetQueueID(); }

/// TODO: this method should take into account the queue override.
void SetQueueID(lldb::queue_id_t new_val) override {
Thread::SetQueueID(new_val);
}

/// TODO: this method should take into account the queue override.
lldb::QueueKind GetQueueKind() override { return Thread::GetQueueKind(); }

/// TODO: this method should take into account the queue override.
void SetQueueKind(lldb::QueueKind kind) override {
Thread::SetQueueKind(kind);
}

/// TODO: this method should take into account the queue override.
lldb::QueueSP GetQueue() override { return Thread::GetQueue(); }

/// TODO: this method should take into account the queue override.
lldb::addr_t GetQueueLibdispatchQueueAddress() override {
return Thread::GetQueueLibdispatchQueueAddress();
}

/// TODO: this method should take into account the queue override.
void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) override {
Thread::SetQueueLibdispatchQueueAddress(dispatch_queue_t);
}

/// TODO: this method should take into account the queue override.
bool ThreadHasQueueInformation() const override {
return Thread::ThreadHasQueueInformation();
}

/// TODO: this method should take into account the queue override.
lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() override {
return Thread::GetAssociatedWithLibdispatchQueue();
}

/// TODO: this method should take into account the queue override.
void SetAssociatedWithLibdispatchQueue(
lldb_private::LazyBool associated_with_libdispatch_queue) override {
Thread::SetAssociatedWithLibdispatchQueue(
associated_with_libdispatch_queue);
}

lldb::ValueObjectSP &GetValueObject() { return m_thread_info_valobj_sp; }

protected:
lldb::ValueObjectSP m_thread_info_valobj_sp;
std::string m_queue;
lldb::addr_t m_register_data_addr;

private:
ThreadMemory(const ThreadMemory &) = delete;
const ThreadMemory &operator=(const ThreadMemory &) = delete;
ThreadMemoryProvidingNameAndQueue(const ThreadMemoryProvidingNameAndQueue &) =
delete;
const ThreadMemoryProvidingNameAndQueue &
operator=(const ThreadMemoryProvidingNameAndQueue &) = delete;
};

#endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_THREADMEMORY_H