Files
clang-p2996/lldb/source/Plugins/Process/scripted/ScriptedThread.h
Med Ismail Bennani 45148bfe8a [lldb/Plugins] Fix ScriptedThread IndexID reporting
When listing all the Scripted Threads of a ScriptedProcess, we can see that all
have the thread index set to 1. This is caused by the lldb_private::Thread
constructor, which sets the m_index_id member using the provided thread id `tid`.

Because the call to the super constructor is done before instantiating
the `ScriptedThreadInterface`, lldb can't fetch the thread id from the
script instance, so it uses `LLDB_INVALID_THREAD_ID` instead.

To mitigate this, this patch takes advantage of the `ScriptedThread::Create`
fallible constructor idiom to defer calling the `ScriptedThread` constructor
(and the `Thread` super constructor with it), until we can fetch a valid
thread id `tid` from the `ScriptedThreadInterface`.

rdar://87432065

Differential Revision: https://reviews.llvm.org/D117076

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-01-24 20:25:54 +01:00

77 lines
2.3 KiB
C++

//===-- ScriptedThread.h ----------------------------------------*- 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
//
//===----------------------------------------------------------------------===//
#ifndef LLDB_SOURCE_PLUGINS_SCRIPTED_THREAD_H
#define LLDB_SOURCE_PLUGINS_SCRIPTED_THREAD_H
#include <string>
#include "ScriptedProcess.h"
#include "Plugins/Process/Utility/RegisterContextMemory.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Target//DynamicRegisterInfo.h"
#include "lldb/Target/Thread.h"
namespace lldb_private {
class ScriptedProcess;
}
namespace lldb_private {
class ScriptedThread : public lldb_private::Thread {
public:
ScriptedThread(ScriptedProcess &process,
lldb::ScriptedThreadInterfaceSP interface_sp, lldb::tid_t tid,
StructuredData::GenericSP script_object_sp = nullptr);
~ScriptedThread() override;
static llvm::Expected<std::shared_ptr<ScriptedThread>>
Create(ScriptedProcess &process,
StructuredData::Generic *script_object = nullptr);
lldb::RegisterContextSP GetRegisterContext() override;
lldb::RegisterContextSP
CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
bool CalculateStopInfo() override;
const char *GetInfo() override { return nullptr; }
const char *GetName() override;
const char *GetQueueName() override;
void WillResume(lldb::StateType resume_state) override;
void RefreshStateAfterStop() override;
void ClearStackFrames() override;
private:
void CheckInterpreterAndScriptObject() const;
lldb::ScriptedThreadInterfaceSP GetInterface() const;
ScriptedThread(const ScriptedThread &) = delete;
const ScriptedThread &operator=(const ScriptedThread &) = delete;
std::shared_ptr<DynamicRegisterInfo> GetDynamicRegisterInfo();
const ScriptedProcess &m_scripted_process;
lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
lldb_private::StructuredData::GenericSP m_script_object_sp = nullptr;
std::shared_ptr<DynamicRegisterInfo> m_register_info_sp = nullptr;
};
} // namespace lldb_private
#endif // LLDB_SOURCE_PLUGINS_SCRIPTED_THREAD_H