github-actions[bot] wrote: <!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning: <details> <summary> You can test this locally with the following command: </summary> ``````````bash git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- lldb/include/lldb/Utility/GPUGDBRemotePackets.h lldb/source/Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.cpp lldb/source/Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.h lldb/source/Plugins/Process/gdb-remote/LLDBServerPlugin.cpp lldb/source/Plugins/Process/gdb-remote/LLDBServerPlugin.h lldb/source/Utility/GPUGDBRemotePackets.cpp lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.h lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.cpp lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.h lldb/tools/lldb-server/Plugins/AMDGPU/RegisterContextAMDGPU.cpp lldb/tools/lldb-server/Plugins/AMDGPU/RegisterContextAMDGPU.h lldb/tools/lldb-server/Plugins/AMDGPU/ThreadAMDGPU.cpp lldb/tools/lldb-server/Plugins/AMDGPU/ThreadAMDGPU.h lldb/tools/lldb-server/Plugins/MockGPU/LLDBServerPluginMockGPU.cpp lldb/tools/lldb-server/Plugins/MockGPU/LLDBServerPluginMockGPU.h lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.cpp lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.h lldb/tools/lldb-server/Plugins/MockGPU/RegisterContextMockGPU.cpp lldb/tools/lldb-server/Plugins/MockGPU/RegisterContextMockGPU.h lldb/tools/lldb-server/Plugins/MockGPU/ThreadMockGPU.cpp lldb/tools/lldb-server/Plugins/MockGPU/ThreadMockGPU.h lldb/include/lldb/Host/common/NativeProcessProtocol.h lldb/include/lldb/Target/DynamicLoader.h lldb/include/lldb/Target/Process.h lldb/include/lldb/Target/StopInfo.h lldb/include/lldb/Target/Target.h lldb/include/lldb/Utility/ArchSpec.h lldb/include/lldb/Utility/GDBRemote.h lldb/include/lldb/Utility/StringExtractorGDBRemote.h lldb/include/lldb/lldb-enumerations.h lldb/source/API/SBModuleSpec.cpp lldb/source/API/SBThread.cpp lldb/source/Core/Module.cpp lldb/source/Host/common/NativeProcessProtocol.cpp lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h lldb/source/Target/Process.cpp lldb/source/Target/StopInfo.cpp lldb/source/Target/Thread.cpp lldb/source/Utility/ArchSpec.cpp lldb/source/Utility/StringExtractorGDBRemote.cpp lldb/tools/lldb-server/lldb-gdbserver.cpp `````````` </details> <details> <summary> View the diff from clang-format here. </summary> ``````````diff diff --git a/lldb/include/lldb/Host/common/NativeProcessProtocol.h b/lldb/include/lldb/Host/common/NativeProcessProtocol.h index 4d7b880ec..a620c620d 100644 --- a/lldb/include/lldb/Host/common/NativeProcessProtocol.h +++ b/lldb/include/lldb/Host/common/NativeProcessProtocol.h @@ -15,9 +15,9 @@ #include "lldb/Host/Host.h" #include "lldb/Host/MainLoop.h" #include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/GPUGDBRemotePackets.h" #include "lldb/Utility/Iterable.h" #include "lldb/Utility/Status.h" -#include "lldb/Utility/GPUGDBRemotePackets.h" #include "lldb/Utility/TraceGDBRemotePackets.h" #include "lldb/Utility/UnimplementedError.h" #include "lldb/lldb-private-forward.h" @@ -258,7 +258,7 @@ public: virtual Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) = 0; - virtual std::optional<GPUDynamicLoaderResponse> + virtual std::optional<GPUDynamicLoaderResponse> GetGPUDynamicLoaderLibraryInfos(const GPUDynamicLoaderArgs &args) { return std::nullopt; } diff --git a/lldb/include/lldb/Target/DynamicLoader.h b/lldb/include/lldb/Target/DynamicLoader.h index 6f18a6747..9e75b5ad3 100644 --- a/lldb/include/lldb/Target/DynamicLoader.h +++ b/lldb/include/lldb/Target/DynamicLoader.h @@ -97,9 +97,7 @@ public: /// debug services that shared libraries are available. /// /// \returns True if handled, false otherwise. - virtual bool HandleStopReasonDynammicLoader() { - return false; - } + virtual bool HandleStopReasonDynammicLoader() { return false; } /// Get whether the process should stop when images change. /// diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index e80182097..ba4440be7 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -2314,7 +2314,7 @@ public: /// Wait for the process to resume. /// /// Given the current ProcessModID that identifies a current state, wait for - /// the process to resume. + /// the process to resume. /// /// \param[in] curr_resume_id /// The resume ID that identifies the resume ID from a stopped state. @@ -2323,7 +2323,7 @@ public: /// The maximum time in seconds to wait for the process to transition to /// the eStateRunning state. If no timeout is supplied, block and wait /// indefinitely. - Status WaitForNextResume(const uint32_t curr_resume_id, + Status WaitForNextResume(const uint32_t curr_resume_id, std::optional<uint32_t> timeout_sec); uint32_t GetIOHandlerID() const { return m_iohandler_sync.GetValue(); } diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index e631734d4..b48e75759 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -1562,12 +1562,11 @@ public: /// Print all the signals set in this target. void PrintDummySignals(Stream &strm, Args &signals); - lldb::TargetSP GetGPUPluginTarget(llvm::StringRef plugin_name) { return m_gpu_plugin_targets.lookup(plugin_name).lock(); } - void SetGPUPluginTarget(llvm::StringRef plugin_name, + void SetGPUPluginTarget(llvm::StringRef plugin_name, lldb::TargetSP target_sp) { m_native_target_gpu_wp = shared_from_this(); m_gpu_plugin_targets[plugin_name] = target_sp; diff --git a/lldb/include/lldb/Utility/GDBRemote.h b/lldb/include/lldb/Utility/GDBRemote.h index 6f979404e..931add100 100644 --- a/lldb/include/lldb/Utility/GDBRemote.h +++ b/lldb/include/lldb/Utility/GDBRemote.h @@ -13,8 +13,8 @@ #include "lldb/Utility/StreamString.h" #include "lldb/lldb-enumerations.h" #include "lldb/lldb-public.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/JSON.h" +#include "llvm/Support/raw_ostream.h" #include <cstddef> #include <cstdint> @@ -61,14 +61,14 @@ public: /// /// \return /// Number of bytes written. - template<class T> int PutAsJSON(const T &obj, bool hex_ascii) { + template <class T> int PutAsJSON(const T &obj, bool hex_ascii) { std::string json_string; llvm::raw_string_ostream os(json_string); os << toJSON(obj); if (hex_ascii) return PutStringAsRawHex8(json_string); else - return PutEscapedBytes(json_string.c_str(), json_string.size()); + return PutEscapedBytes(json_string.c_str(), json_string.size()); } /// Convert an array of objects into JSON and add the JSON text to the packet. /// @@ -76,19 +76,19 @@ public: /// interfere with the GDB remote protocol packet format. /// /// \param[in] array - /// An array of objects to convert to JSON. The object't type must have a + /// An array of objects to convert to JSON. The object't type must have a /// method written that converts the object to a llvm::json::Value: /// /// \code llvm::json::Value toJSON(const T &obj); /// /// \return /// Number of bytes written. - template<class T> int PutAsJSONArray(const std::vector<T> &array) { + template <class T> int PutAsJSONArray(const std::vector<T> &array) { std::string json_string; llvm::raw_string_ostream os(json_string); bool first = true; os << "["; - for (auto &obj: array) { + for (auto &obj : array) { if (first) first = false; else @@ -98,7 +98,6 @@ public: os << "]"; return PutEscapedBytes(json_string.data(), json_string.size()); } - }; /// GDB remote packet as used by the GDB remote communication history. Packets diff --git a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h index b6c03b91a..fc4112d50 100644 --- a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h +++ b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h @@ -220,8 +220,7 @@ public: std::optional<std::pair<lldb::pid_t, lldb::tid_t>> GetPidTid(lldb::pid_t default_pid); - - template<class T> std::optional<T> GetFromJSONText() { + template <class T> std::optional<T> GetFromJSONText() { llvm::Expected<T> info = llvm::json::parse<T>(Peek(), ""); if (info) return *info; @@ -229,7 +228,7 @@ public: return std::nullopt; } - template<class T> std::optional<T> GetFromJSONHexASCII() { + template <class T> std::optional<T> GetFromJSONHexASCII() { std::string json; GetHexByteString(json); llvm::Expected<T> info = llvm::json::parse<T>(json.c_str(), ""); diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp index 548b056fa..fbbcfeac2 100644 --- a/lldb/source/API/SBModuleSpec.cpp +++ b/lldb/source/API/SBModuleSpec.cpp @@ -170,7 +170,7 @@ uint64_t SBModuleSpec::GetObjectSize() { void SBModuleSpec::SetObjectSize(uint64_t object_size) { LLDB_INSTRUMENT_VA(this, object_size); - + m_opaque_up->SetObjectSize(object_size); } diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 73f414574..fccd2ae92 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -236,7 +236,7 @@ uint64_t SBThread::GetStopReasonDataAtIndex(uint32_t idx) { case eStopReasonProcessorTrace: case eStopReasonVForkDone: case eStopReasonHistoryBoundary: - case lldb::eStopReasonDynammicLoader: + case lldb::eStopReasonDynammicLoader: // There is no data for these stop reasons. return 0; diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 4296b0661..6dabfd00e 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -157,11 +157,8 @@ Module::Module(const ModuleSpec &module_spec) ModuleSpecList modules_specs; if (ObjectFile::GetModuleSpecifications( - module_spec.GetFileSpec(), - module_spec.GetObjectOffset(), - module_spec.GetObjectSize(), - modules_specs, - data_sp) == 0) + module_spec.GetFileSpec(), module_spec.GetObjectOffset(), + module_spec.GetObjectSize(), modules_specs, data_sp) == 0) return; // Now make sure that one of the module specifications matches what we just diff --git a/lldb/source/Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.cpp b/lldb/source/Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.cpp index f587f5a2f..469b248ef 100644 --- a/lldb/source/Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.cpp +++ b/lldb/source/Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.cpp @@ -54,7 +54,7 @@ void DynamicLoaderGDBRemoteGPU::DidAttach() { LoadModulesFromGDBServer(true); } /// attaching to a process. void DynamicLoaderGDBRemoteGPU::DidLaunch() { LoadModulesFromGDBServer(true); } -bool DynamicLoaderGDBRemoteGPU::HandleStopReasonDynammicLoader() { +bool DynamicLoaderGDBRemoteGPU::HandleStopReasonDynammicLoader() { return LoadModulesFromGDBServer(false); } @@ -76,17 +76,17 @@ bool DynamicLoaderGDBRemoteGPU::LoadModulesFromGDBServer(bool full) { std::shared_ptr<DataBufferHeap> data_sp; // Read the object file from memory if requested. if (info.native_memory_address && info.native_memory_size) { - LLDB_LOG(log, "Reading \"{0}\" from memory at {1:x}", info.pathname, + LLDB_LOG(log, "Reading \"{0}\" from memory at {1:x}", info.pathname, *info.native_memory_address); data_sp = std::make_shared<DataBufferHeap>(*info.native_memory_size, 0); Status error; // TODO: we are assuming we can read the memory from the GPU process // since the memory is shared with the host process. const size_t bytes_read = m_process->ReadMemory( - *info.native_memory_address, data_sp->GetBytes(), + *info.native_memory_address, data_sp->GetBytes(), data_sp->GetByteSize(), error); if (bytes_read != *info.native_memory_size) { - LLDB_LOG(log, "Failed to read \"{0}\" from memory at {1:x}: {2}", + LLDB_LOG(log, "Failed to read \"{0}\" from memory at {1:x}: {2}", info.pathname, *info.native_memory_address, error); data_sp.reset(); } @@ -102,31 +102,31 @@ bool DynamicLoaderGDBRemoteGPU::LoadModulesFromGDBServer(bool full) { if (info.file_size) module_spec.SetObjectSize(*info.file_size); // Get or create the module from the module spec. - ModuleSP module_sp = target.GetOrCreateModule(module_spec, + ModuleSP module_sp = target.GetOrCreateModule(module_spec, /*notify=*/true); if (module_sp) { - LLDB_LOG(log, "Created module for \"{0}\": {1:x}", - info.pathname, module_sp.get()); + LLDB_LOG(log, "Created module for \"{0}\": {1:x}", info.pathname, + module_sp.get()); bool changed = false; if (info.load_address) { - LLDB_LOG(log, "Setting load address for module \"{0}\" to {1:x}", + LLDB_LOG(log, "Setting load address for module \"{0}\" to {1:x}", info.pathname, *info.load_address); - module_sp->SetLoadAddress(target, *info.load_address, - /*value_is_offset=*/true , changed); - } else if (!info.loaded_sections.empty()) { - + module_sp->SetLoadAddress(target, *info.load_address, + /*value_is_offset=*/true, changed); + } else if (!info.loaded_sections.empty()) { + // Set the load address of the module to the first loaded section. bool warn_multiple = true; for (const GPUSectionInfo § : info.loaded_sections) { if (sect.names.empty()) continue; - // Find the section by name using the names specified. If there is + // Find the section by name using the names specified. If there is // only on name, them find it. If there are multiple names, the top // most section names comes first and then we find child sections // by name within the previous section. SectionSP section_sp; - for (uint32_t i=0; i<sect.names.size(); ++i) { + for (uint32_t i = 0; i < sect.names.size(); ++i) { ConstString name(sect.names[i]); if (section_sp) section_sp = section_sp->GetChildren().FindSectionByName(name); @@ -136,21 +136,20 @@ bool DynamicLoaderGDBRemoteGPU::LoadModulesFromGDBServer(bool full) { break; } if (section_sp) { - LLDB_LOG(log, "Loading module \"{0}\" section \"{1} to {2:x}", + LLDB_LOG(log, "Loading module \"{0}\" section \"{1} to {2:x}", info.pathname, section_sp->GetName(), sect.load_address); - changed = target.SetSectionLoadAddress(section_sp, - sect.load_address, - warn_multiple); + changed = target.SetSectionLoadAddress( + section_sp, sect.load_address, warn_multiple); } else { - LLDB_LOG(log, "Failed to find section \"{0}\"", + LLDB_LOG(log, "Failed to find section \"{0}\"", section_sp->GetName()); } } } if (changed) { - LLDB_LOG(log, "Module \"{0}\" was loaded, notifying target", + LLDB_LOG(log, "Module \"{0}\" was loaded, notifying target", info.pathname); - loaded_module_list.AppendIfNeeded(module_sp); + loaded_module_list.AppendIfNeeded(module_sp); } } } @@ -160,13 +159,12 @@ bool DynamicLoaderGDBRemoteGPU::LoadModulesFromGDBServer(bool full) { ThreadPlanSP DynamicLoaderGDBRemoteGPU::GetStepThroughTrampolinePlan(Thread &thread, - bool stop_others) { + bool stop_others) { return ThreadPlanSP(); } Status DynamicLoaderGDBRemoteGPU::CanLoadImage() { - return Status::FromErrorString( - "can't load images on GPU targets"); + return Status::FromErrorString("can't load images on GPU targets"); } void DynamicLoaderGDBRemoteGPU::Initialize() { diff --git a/lldb/source/Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.h b/lldb/source/Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.h index 0284f98fd..0d92c09d5 100644 --- a/lldb/source/Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.h +++ b/lldb/source/Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.h @@ -23,9 +23,9 @@ /// "jGPUPluginGetDynamicLoaderLibraryInfo" packet. Many GPUs have drivers that /// coordinate the loading and unloading of shared libraries, but they don't use /// the standard method of setting a breakpoint in the target and handle the -/// breakpoint callback in the dynamic loader plug-in. Instead, the drivers +/// breakpoint callback in the dynamic loader plug-in. Instead, the drivers /// have callbacks or notifications that tell the lldb-server GPU plug-in when -/// a shared library is loaded or unloaded. +/// a shared library is loaded or unloaded. class DynamicLoaderGDBRemoteGPU : public lldb_private::DynamicLoader { public: DynamicLoaderGDBRemoteGPU(lldb_private::Process *process); @@ -51,7 +51,7 @@ public: void DidLaunch() override; bool HandleStopReasonDynammicLoader() override; - + lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread, bool stop_others) override; @@ -67,7 +67,7 @@ private: /// \param[in] full /// If true, load all modules. If false, load or unload only new modules. /// - /// \returns True if the GDB server supports the packet named + /// \returns True if the GDB server supports the packet named /// "jGPUPluginGetDynamicLoaderLibraryInfo", false otherwise. bool LoadModulesFromGDBServer(bool full); }; diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index 687f0efa0..d3dc6779c 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -603,7 +603,7 @@ size_t ObjectFileELF::GetModuleSpecifications( // // Validate it is ok to remove GetOsFromOSABI GetOsFromOSABI(header.e_ident[EI_OSABI], ostype); - if (ostype != llvm::Triple::OSType::UnknownOS && + if (ostype != llvm::Triple::OSType::UnknownOS && spec_ostype != llvm::Triple::OSType::UnknownOS) { LLDB_LOGF(log, "ObjectFileELF::%s file '%s' set ELF module OS type " diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index e77637619..95408d574 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -436,10 +436,10 @@ public: std::optional<std::vector<GPUActions>> GetGPUInitializeActions(); - std::optional<GPUPluginBreakpointHitResponse> + std::optional<GPUPluginBreakpointHitResponse> GPUBreakpointHit(const GPUPluginBreakpointHitArgs &args); - std::optional<GPUDynamicLoaderResponse> + std::optional<GPUDynamicLoaderResponse> GetGPUDynamicLoaderLibraryInfos(const GPUDynamicLoaderArgs &args); bool GetThreadExtendedInfoSupported(); @@ -549,7 +549,7 @@ public: bool SupportsGPUDynamicLoader() const { return m_supports_gdb_remote_gpu_dyld == eLazyBoolYes; } - + protected: LazyBool m_supports_not_sending_acks = eLazyBoolCalculate; LazyBool m_supports_thread_suffix = eLazyBoolCalculate; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index f5fea122b..37a545b16 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -263,9 +263,11 @@ void GDBRemoteCommunicationServerLLGS::RegisterPacketHandlers() { StringExtractorGDBRemote::eServerPacketType_jGPUPluginBreakpointHit, &GDBRemoteCommunicationServerLLGS::Handle_jGPUPluginBreakpointHit); RegisterMemberFunctionHandler( - StringExtractorGDBRemote::eServerPacketType_jGPUPluginGetDynamicLoaderLibraryInfo, - &GDBRemoteCommunicationServerLLGS::Handle_jGPUPluginGetDynamicLoaderLibraryInfo); - } + StringExtractorGDBRemote:: + eServerPacketType_jGPUPluginGetDynamicLoaderLibraryInfo, + &GDBRemoteCommunicationServerLLGS:: + Handle_jGPUPluginGetDynamicLoaderLibraryInfo); +} void GDBRemoteCommunicationServerLLGS::SetLaunchInfo( const ProcessLaunchInfo &info) { @@ -1107,16 +1109,16 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped( // Check if any plug-ins have new connections StreamGDBRemote extra_stop_reply_args; for (auto &plugin_up : m_plugins) { - if (std::optional<GPUActions> connection_info = - plugin_up->NativeProcessIsStopping()) { + if (std::optional<GPUActions> connection_info = + plugin_up->NativeProcessIsStopping()) { extra_stop_reply_args.PutCString("gpu-actions:"); extra_stop_reply_args.PutAsJSON(*connection_info, /*hex_ascii=*/true); extra_stop_reply_args.PutChar(';'); - } + } } PacketResult result = SendStopReasonForState( - *process, StateType::eStateStopped, /*force_synchronous=*/false, + *process, StateType::eStateStopped, /*force_synchronous=*/false, extra_stop_reply_args.GetData()); if (result != PacketResult::Success) { LLDB_LOGF(log, @@ -1137,7 +1139,6 @@ void GDBRemoteCommunicationServerLLGS::ProcessStateChanged( __FUNCTION__, process->GetID(), StateAsCString(state)); } - switch (state) { case StateType::eStateRunning: break; @@ -2005,7 +2006,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReasonForState( // Make sure we set the current thread so g and p packets return the data // the gdb will expect. SetCurrentThreadID(tid); - return SendStopReplyPacketForThread(process, tid, force_synchronous, + return SendStopReplyPacketForThread(process, tid, force_synchronous, extra_stop_reply_args); } @@ -3663,7 +3664,7 @@ GDBRemoteCommunicationServerLLGS::Handle_qThreadStopInfo( return SendErrorResponse(0x15); } return SendStopReplyPacketForThread(*m_current_process, tid, - /*force_synchronous=*/true, + /*force_synchronous=*/true, llvm::StringRef()); } @@ -3699,7 +3700,7 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_jGPUPluginInitialize( StringExtractorGDBRemote &) { std::vector<GPUActions> gpu_actions; - for (auto &plugin_up: m_plugins) + for (auto &plugin_up : m_plugins) gpu_actions.push_back(plugin_up->GetInitializeActions()); StreamGDBRemote response; response.PutAsJSONArray(gpu_actions); @@ -3712,18 +3713,18 @@ GDBRemoteCommunicationServerLLGS::Handle_jGPUPluginBreakpointHit( packet.ConsumeFront("jGPUPluginBreakpointHit:"); Expected<GPUPluginBreakpointHitArgs> args = - json::parse<GPUPluginBreakpointHitArgs>(packet.Peek(), + json::parse<GPUPluginBreakpointHitArgs>(packet.Peek(), "GPUPluginBreakpointHitArgs"); if (!args) return SendErrorResponse(args.takeError()); - for (auto &plugin_up: m_plugins) { + for (auto &plugin_up : m_plugins) { if (plugin_up->GetPluginName() == args->plugin_name) { - Expected<GPUPluginBreakpointHitResponse> bp_response = + Expected<GPUPluginBreakpointHitResponse> bp_response = plugin_up->BreakpointWasHit(*args); if (!bp_response) return SendErrorResponse(bp_response.takeError()); - + StreamGDBRemote response; response.PutAsJSON(*bp_response, /*hex_ascii=*/false); return SendPacketNoLock(response.GetString()); @@ -3732,7 +3733,6 @@ GDBRemoteCommunicationServerLLGS::Handle_jGPUPluginBreakpointHit( return SendErrorResponse(Status::FromErrorString("Invalid plugin name.")); } - GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_jGPUPluginGetDynamicLoaderLibraryInfo( StringExtractorGDBRemote &packet) { @@ -3743,10 +3743,9 @@ GDBRemoteCommunicationServerLLGS::Handle_jGPUPluginGetDynamicLoaderLibraryInfo( if (!args) return SendErrorResponse(args.takeError()); - if (!m_current_process) return SendErrorResponse(Status::FromErrorString("invalid process")); - std::optional<GPUDynamicLoaderResponse> libraries_response = + std::optional<GPUDynamicLoaderResponse> libraries_response = m_current_process->GetGPUDynamicLoaderLibraryInfos(*args); if (!libraries_response) return SendErrorResponse(Status::FromErrorString( @@ -4319,12 +4318,8 @@ std::vector<std::string> GDBRemoteCommunicationServerLLGS::HandleFeatures( const llvm::ArrayRef<llvm::StringRef> client_features) { std::vector<std::string> ret = GDBRemoteCommunicationServerCommon::HandleFeatures(client_features); - ret.insert(ret.end(), { - "QThreadSuffixSupported+", - "QListThreadsInStopReply+", - "qXfer:features:read+", - "QNonStop+" - }); + ret.insert(ret.end(), {"QThreadSuffixSupported+", "QListThreadsInStopReply+", + "qXfer:features:read+", "QNonStop+"}); // report server-only features using Extension = NativeProcessProtocol::Extension; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h index 4fe653e23..89c11badb 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -26,7 +26,7 @@ class StringExtractorGDBRemote; namespace lldb_private { namespace lldb_server { - class LLDBServerPlugin; +class LLDBServerPlugin; } namespace process_gdb_remote { @@ -108,9 +108,7 @@ public: Flag flags; }; - NativeProcessProtocol *GetCurrentProcess() { - return m_current_process; - } + NativeProcessProtocol *GetCurrentProcess() { return m_current_process; } protected: MainLoop &m_mainloop; @@ -152,15 +150,15 @@ protected: StreamString PrepareStopReplyPacketForThread(NativeThreadProtocol &thread); - PacketResult SendStopReplyPacketForThread(NativeProcessProtocol &process, - lldb::tid_t tid, - bool force_synchronous, - llvm::StringRef extra_stop_reply_args = {}); + PacketResult + SendStopReplyPacketForThread(NativeProcessProtocol &process, lldb::tid_t tid, + bool force_synchronous, + llvm::StringRef extra_stop_reply_args = {}); - PacketResult SendStopReasonForState(NativeProcessProtocol &process, - lldb::StateType process_state, - bool force_synchronous, - llvm::StringRef extra_stop_reply_args = {}); + PacketResult + SendStopReasonForState(NativeProcessProtocol &process, + lldb::StateType process_state, bool force_synchronous, + llvm::StringRef extra_stop_reply_args = {}); void EnqueueStopReplyPackets(lldb::tid_t thread_to_skip); @@ -291,7 +289,7 @@ protected: PacketResult Handle_T(StringExtractorGDBRemote &packet); PacketResult Handle_jGPUPluginInitialize(StringExtractorGDBRemote &packet); - + PacketResult Handle_jGPUPluginBreakpointHit(StringExtractorGDBRemote &packet); PacketResult Handle_jGPUPluginGetDynamicLoaderLibraryInfo( diff --git a/lldb/source/Plugins/Process/gdb-remote/LLDBServerPlugin.cpp b/lldb/source/Plugins/Process/gdb-remote/LLDBServerPlugin.cpp index 439f6b6af..2fdea22b6 100644 --- a/lldb/source/Plugins/Process/gdb-remote/LLDBServerPlugin.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/LLDBServerPlugin.cpp @@ -14,22 +14,21 @@ using namespace lldb_private; using namespace lldb_server; - -LLDBServerPlugin::LLDBServerPlugin(GDBServer &native_process, MainLoop &main_loop) : - m_native_process(native_process), m_main_loop(main_loop) {} +LLDBServerPlugin::LLDBServerPlugin(GDBServer &native_process, + MainLoop &main_loop) + : m_native_process(native_process), m_main_loop(main_loop) {} LLDBServerPlugin::~LLDBServerPlugin() {} - -lldb::StateType -LLDBServerPlugin::HaltNativeProcessIfNeeded(bool &was_halted, +lldb::StateType +LLDBServerPlugin::HaltNativeProcessIfNeeded(bool &was_halted, uint32_t timeout_sec) { using namespace std::chrono; NativeProcessProtocol *process = m_native_process.GetCurrentProcess(); if (process->IsRunning()) { was_halted = true; process->Halt(); - + auto end_time = steady_clock::now() + seconds(timeout_sec); while (std::chrono::steady_clock::now() < end_time) { std::this_thread::sleep_for(milliseconds(250)); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index b1b3f01a8..d158cba2a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -78,17 +78,16 @@ #include "GDBRemoteRegisterContext.h" #include "GDBRemoteRegisterFallback.h" +#include "Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.h" #include "Plugins/Process/Utility/GDBRemoteSignals.h" #include "Plugins/Process/Utility/InferiorCallPOSIX.h" #include "Plugins/Process/Utility/StopInfoMachException.h" -#include "Plugins/DynamicLoader/GDBRemoteGPU/DynamicLoaderGDBRemoteGPU.h" #include "ProcessGDBRemote.h" #include "ProcessGDBRemoteLog.h" #include "ThreadGDBRemote.h" #include "lldb/Host/Host.h" #include "lldb/Utility/StringExtractorGDBRemote.h" - #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSwitch.h" @@ -815,29 +814,30 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module, return error; } -class GPUBreakpointCallbackBaton : public TypedBaton<GPUPluginBreakpointHitArgs> { - public: - explicit GPUBreakpointCallbackBaton(std::unique_ptr<GPUPluginBreakpointHitArgs> Data) - : TypedBaton(std::move(Data)) {} +class GPUBreakpointCallbackBaton + : public TypedBaton<GPUPluginBreakpointHitArgs> { +public: + explicit GPUBreakpointCallbackBaton( + std::unique_ptr<GPUPluginBreakpointHitArgs> Data) + : TypedBaton(std::move(Data)) {} }; -typedef std::shared_ptr<GPUBreakpointCallbackBaton> GPUBreakpointCallbackBatonSP; +typedef std::shared_ptr<GPUBreakpointCallbackBaton> + GPUBreakpointCallbackBatonSP; bool ProcessGDBRemote::GPUBreakpointHitCallback( - void *baton, - StoppointCallbackContext *context, - lldb::user_id_t break_id, + void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id) { ProcessSP process_sp = context->exe_ctx_ref.GetProcessSP(); ProcessGDBRemote *process = static_cast<ProcessGDBRemote *>(process_sp.get()); return process->GPUBreakpointHit(baton, context, break_id, break_loc_id); } -bool ProcessGDBRemote::GPUBreakpointHit(void *baton, +bool ProcessGDBRemote::GPUBreakpointHit(void *baton, StoppointCallbackContext *context, - lldb::user_id_t break_id, + lldb::user_id_t break_id, lldb::user_id_t break_loc_id) { - GPUPluginBreakpointHitArgs *callback_data = + GPUPluginBreakpointHitArgs *callback_data = static_cast<GPUPluginBreakpointHitArgs *>(baton); // Make a copy of the args so we can fill in any needed symbol values prior // to notifying lldb-server. @@ -846,16 +846,15 @@ bool ProcessGDBRemote::GPUBreakpointHit(void *baton, const size_t num_symbols = args.breakpoint.symbol_names.size(); if (num_symbols > 0) { args.symbol_values.resize(num_symbols); - for (size_t i=0; i<num_symbols; ++i) { + for (size_t i = 0; i < num_symbols; ++i) { const auto &symbol_name = args.breakpoint.symbol_names[i]; SymbolContextList sc_list; - target.GetImages().FindSymbolsWithNameAndType(ConstString(symbol_name), - lldb::eSymbolTypeAny, - sc_list); + target.GetImages().FindSymbolsWithNameAndType( + ConstString(symbol_name), lldb::eSymbolTypeAny, sc_list); SymbolContext sc; args.symbol_values[i].name = symbol_name; size_t num_symbols = sc_list.GetSize(); - for (size_t sc_idx=0; sc_idx<num_symbols; ++sc_idx) { + for (size_t sc_idx = 0; sc_idx < num_symbols; ++sc_idx) { if (sc_list.GetContextAtIndex(sc_idx, sc)) { auto load_addr = sc.symbol->GetAddress().GetLoadAddress(&target); if (load_addr != LLDB_INVALID_ADDRESS) { @@ -873,7 +872,7 @@ bool ProcessGDBRemote::GPUBreakpointHit(void *baton, // the hit count and other stats on the breakpoint. if (response->disable_bp) { BreakpointSP bp_sp = target.GetBreakpointByID(break_id); - if (bp_sp) + if (bp_sp) bp_sp->SetEnabled(false); } if (Status err = HandleGPUActions(response->actions); err.Fail()) { @@ -904,10 +903,10 @@ Status ProcessGDBRemote::HandleGPUActions(const GPUActions &gpu_action) { // using stale information, as the GPU target hasn't finished processing // its internal metadata. It's worth mentioning that there are multiple // threads operating on the GPU target. - if (!(gpu_action.load_libraries || gpu_action.resume_gpu_process || - gpu_action.wait_for_gpu_process_to_resume)) + if (!(gpu_action.load_libraries || gpu_action.resume_gpu_process || + gpu_action.wait_for_gpu_process_to_resume)) return error; - lldb::TargetSP gpu_target_sp = + lldb::TargetSP gpu_target_sp = GetTarget().GetGPUPluginTarget(gpu_action.plugin_name); if (!gpu_target_sp) return error; @@ -935,10 +934,10 @@ Status ProcessGDBRemote::HandleGPUActions(const GPUActions &gpu_action) { } Status ProcessGDBRemote::HandleConnectionRequest(const GPUActions &gpu_action) { - const GPUPluginConnectionInfo &connection_info = - gpu_action.connect_info.value(); + const GPUPluginConnectionInfo &connection_info = + gpu_action.connect_info.value(); Log *log = GetLog(GDBRLog::Plugin); - LLDB_LOG(log, "ProcessGDBRemote::HandleConnectionRequest()"); + LLDB_LOG(log, "ProcessGDBRemote::HandleConnectionRequest()"); auto &debugger = GetTarget().GetDebugger(); TargetSP gpu_target_sp; llvm::StringRef exe_path; @@ -946,13 +945,13 @@ Status ProcessGDBRemote::HandleConnectionRequest(const GPUActions &gpu_action) { OptionGroupPlatform *platform_options = nullptr; if (connection_info.exe_path) - exe_path = *connection_info.exe_path; + exe_path = *connection_info.exe_path; if (connection_info.triple) triple = *connection_info.triple; // Create an empty target for our GPU. Status error(debugger.GetTargetList().CreateTarget( - debugger, exe_path, triple, eLoadDependentsNo, platform_options, - gpu_target_sp)); + debugger, exe_path, triple, eLoadDependentsNo, platform_options, + gpu_target_sp)); if (error.Fail()) return error; if (!gpu_target_sp) @@ -973,17 +972,17 @@ Status ProcessGDBRemote::HandleConnectionRequest(const GPUActions &gpu_action) { if (!process_sp) return Status::FromErrorString("invalid process after connecting"); - GetTarget().SetGPUPluginTarget(gpu_action.plugin_name, + GetTarget().SetGPUPluginTarget(gpu_action.plugin_name, process_sp->GetTarget().shared_from_this()); LLDB_LOG(log, "ProcessGDBRemote::HandleConnectionRequest(): successfully " - "created process!!!"); + "created process!!!"); return Status(); } void ProcessGDBRemote::HandleGPUBreakpoints(const GPUActions &gpu_action) { Target &target = GetTarget(); - for (const auto &bp: gpu_action.breakpoints) { - // Create data that will live with the breakpoint so when we hit the + for (const auto &bp : gpu_action.breakpoints) { + // Create data that will live with the breakpoint so when we hit the // breakpoint and the GPUBreakpointHitCallback is called, we can use this // data. auto args_up = std::make_unique<GPUPluginBreakpointHitArgs>(); @@ -993,20 +992,20 @@ void ProcessGDBRemote::HandleGPUBreakpoints(const GPUActions &gpu_action) { BreakpointSP bp_sp; if (bp.name_info) { if (bp.name_info->shlib && !bp.name_info->shlib->empty()) - bp_modules.Append(FileSpec(*bp.name_info->shlib, - llvm::sys::path::Style::native)); + bp_modules.Append( + FileSpec(*bp.name_info->shlib, llvm::sys::path::Style::native)); bp_sp = target.CreateBreakpoint( - &bp_modules, // Containing modules. - nullptr, // Containing source files. + &bp_modules, // Containing modules. + nullptr, // Containing source files. bp.name_info->function_name.c_str(), // Function name. - eFunctionNameTypeFull, // Function name type. - eLanguageTypeUnknown, // Language type - 0, // Byte offset. - eLazyBoolNo, // Skip prologue. - true, // Internal breakpoint. - false); // Request hardware. + eFunctionNameTypeFull, // Function name type. + eLanguageTypeUnknown, // Language type + 0, // Byte offset. + eLazyBoolNo, // Skip prologue. + true, // Internal breakpoint. + false); // Request hardware. } else if (bp.addr_info) { - bp_sp = target.CreateBreakpoint(bp.addr_info->load_address, + bp_sp = target.CreateBreakpoint(bp.addr_info->load_address, /*internal=*/true, /*request_hardware=*/false); } @@ -1014,10 +1013,10 @@ void ProcessGDBRemote::HandleGPUBreakpoints(const GPUActions &gpu_action) { // Create some JSON we can send back to the lldb-server // that identifies the plug-in and the breakpoint for when // the breakpoint gets hit. - auto baton_sp = + auto baton_sp = std::make_shared<GPUBreakpointCallbackBaton>(std::move(args_up)); bp_sp->SetCallback(GPUBreakpointHitCallback, baton_sp, - /*is_synchronous=*/true); + /*is_synchronous=*/true); } } } @@ -2157,7 +2156,8 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo( auto error = LoadModules(); if (error) { Log *log(GetLog(GDBRLog::Process)); - LLDB_LOG_ERROR(log, std::move(error), "Failed to load modules: {0}"); + LLDB_LOG_ERROR(log, std::move(error), + "Failed to load modules: {0}"); } // TODO: create dyld stop reason, or auto resume depending on value // of setting that specifies if we should stop for shared library @@ -2628,8 +2628,8 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) { } } else if (key.compare("gpu-actions") == 0) { StringExtractorGDBRemote extractor(value); - if (std::optional<GPUActions> gpu_actions = - extractor.GetFromJSONHexASCII<GPUActions>()) { + if (std::optional<GPUActions> gpu_actions = + extractor.GetFromJSONHexASCII<GPUActions>()) { if (Status err = HandleGPUActions(*gpu_actions); err.Fail()) { Debugger::ReportError(llvm::formatv( "HandleGPUActions failed. Error: {0}\nActions:\n{1}\n", @@ -5448,20 +5448,20 @@ llvm::Error ProcessGDBRemote::LoadModules() { /// See if the dynamic loader knows how to load the modules when requested. /// This can get triggered in multiple ways: - /// - If a breakpoint in the native process that was set by any GPUActions - /// gets hit, and the breakpoint hit response from the GPU plug-in via an - /// instance of GPUPluginBreakpointHitResponse has the "load_libraries" + /// - If a breakpoint in the native process that was set by any GPUActions + /// gets hit, and the breakpoint hit response from the GPU plug-in via an + /// instance of GPUPluginBreakpointHitResponse has the "load_libraries" /// bool member variable is set to true. This is the preferred method if /// it is possible for a breakpoint to be set in the native process as it /// allows the native process to be stopped while GPU shared libraries are /// loaded. The breakpoint will auto resume the process after the GPU /// shared libraries are loaded. - /// - Stop reason for a thread in GPU process is set to the + /// - Stop reason for a thread in GPU process is set to the /// eStopReasonDynammicLoader stop reason. This is used when the GPU process /// doesn't require synchronization with the native process. If the GPU - /// can't set a breakpoint in GPU code and the GPU driver gets a + /// can't set a breakpoint in GPU code and the GPU driver gets a /// notification that shared libraries are available. This should be used - /// if we want to stop for shared library loading and LLDB should auto + /// if we want to stop for shared library loading and LLDB should auto /// continue the process. It doesn't do this yet, but it can and will in the /// future if we need this method of shared library load notification. /// - The GPU process stop reply packet contains for a GPU thread has the diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index 543d76325..2d49b8da2 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -441,12 +441,12 @@ private: static bool GPUBreakpointHitCallback(void *baton, StoppointCallbackContext *context, - lldb::user_id_t break_id, + lldb::user_id_t break_id, lldb::user_id_t break_loc_id); - - bool GPUBreakpointHit(void *baton, StoppointCallbackContext *context, + + bool GPUBreakpointHit(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id); - + void HandleGPUBreakpoints(const GPUActions &gpu_action); Status HandleConnectionRequest(const GPUActions &gpu_action); diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 4e06ffccd..d1196efd7 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -2563,18 +2563,18 @@ Status Process::DisableWatchpoint(WatchpointSP wp_sp, bool notify) { return error; } -Status Process::WaitForNextResume(const uint32_t curr_resume_id, - std::optional<uint32_t> opt_timeout_seconds) { +Status Process::WaitForNextResume(const uint32_t curr_resume_id, + std::optional<uint32_t> opt_timeout_seconds) { ListenerSP listener_sp; { - // Don't let the private state change on us while we do some checking by + // Don't let the private state change on us while we do some checking by // locking the private state mutex. The resume ID can't be bumped while we // hold this lock. We also need to start listening for state changed events // prior to letting go of this mutex to ensure there is no race condition. std::lock_guard<std::recursive_mutex> guard(m_private_state.GetMutex()); if (GetResumeID() != curr_resume_id) return Status(); ///< Process already resumed. - + listener_sp = Listener::MakeListener("Process::WaitForNextResume"); listener_sp->StartListeningForEvents(this, eBroadcastBitStateChanged); } @@ -2587,7 +2587,7 @@ Status Process::WaitForNextResume(const uint32_t curr_resume_id, if (!event_sp) return Status::FromErrorString("timeout waiting for process to resume"); - + // Don't let the private state change on us while we do some checking. std::lock_guard<std::recursive_mutex> guard(m_private_state.GetMutex()); if (GetResumeID() != curr_resume_id) diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp index 746baaf2b..51ef30077 100644 --- a/lldb/source/Target/StopInfo.cpp +++ b/lldb/source/Target/StopInfo.cpp @@ -1470,19 +1470,18 @@ protected: }; /// A stop reason for causing shared libraries to load. This will create a stop -/// info that will resume the process by returning the right value for -/// StopInfo::ShouldStopSynchronous(...). This allows a process to stop and -/// report it wants to load/unload shared libraries and auto continue after all +/// info that will resume the process by returning the right value for +/// StopInfo::ShouldStopSynchronous(...). This allows a process to stop and +/// report it wants to load/unload shared libraries and auto continue after all /// libraries have been loaded/unloaded. class StopInfoDyld : public StopInfo { public: - StopInfoDyld(Thread &thread, const char *description) - : StopInfo(thread, 0) { + StopInfoDyld(Thread &thread, const char *description) : StopInfo(thread, 0) { SetDescription(description ? description : "dynamic loader"); } ~StopInfoDyld() override = default; - StopReason GetStopReason() const override { - return lldb::eStopReasonDynammicLoader; + StopReason GetStopReason() const override { + return lldb::eStopReasonDynammicLoader; } bool ShouldStopSynchronous(Event *event_ptr) override { if (ThreadSP thread_sp = GetThread()) { @@ -1556,12 +1555,11 @@ StopInfoSP StopInfo::CreateStopReasonHistoryBoundary(Thread &thread, return StopInfoSP(new StopInfoHistoryBoundary(thread, description)); } -StopInfoSP StopInfo::CreateStopReasonDyld(Thread &thread, +StopInfoSP StopInfo::CreateStopReasonDyld(Thread &thread, const char *description) { return StopInfoSP(new StopInfoDyld(thread, description)); } - StopInfoSP StopInfo::CreateStopReasonWithExec(Thread &thread) { return StopInfoSP(new StopInfoExec(thread)); } diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp index 710f44b5d..2d615ae1d 100644 --- a/lldb/source/Target/Thread.cpp +++ b/lldb/source/Target/Thread.cpp @@ -1758,7 +1758,7 @@ std::string Thread::StopReasonAsString(lldb::StopReason reason) { return "processor trace"; case eStopReasonInterrupt: return "async interrupt"; - case eStopReasonHistoryBoundary: + case eStopReasonHistoryBoundary: return "history boundary"; case eStopReasonDynammicLoader: return "dynamic loader"; diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp index f3de45138..47a341715 100644 --- a/lldb/source/Utility/ArchSpec.cpp +++ b/lldb/source/Utility/ArchSpec.cpp @@ -248,15 +248,15 @@ static const CoreDefinition g_core_definitions[] = { {eByteOrderLittle, 4, 1, 4, llvm::Triple::wasm32, ArchSpec::eCore_wasm32, "wasm32"}, - {eByteOrderLittle, 4, 4, 4, llvm::Triple::r600, - ArchSpec::eCore_amd_gpu_r600,"r600"}, - {eByteOrderLittle, 8, 4, 4, llvm::Triple::amdgcn, - ArchSpec::eCore_amd_gpu_gcn, "amdgcn"}, - {eByteOrderLittle, 4, 4, 4, llvm::Triple::nvptx, - ArchSpec::eCore_nvidia_nvptx,"nvptx"}, - {eByteOrderLittle, 8, 4, 4, llvm::Triple::nvptx64, - ArchSpec::eCore_nvidia_nvptx64, "nvptx64"}, - }; + {eByteOrderLittle, 4, 4, 4, llvm::Triple::r600, + ArchSpec::eCore_amd_gpu_r600, "r600"}, + {eByteOrderLittle, 8, 4, 4, llvm::Triple::amdgcn, + ArchSpec::eCore_amd_gpu_gcn, "amdgcn"}, + {eByteOrderLittle, 4, 4, 4, llvm::Triple::nvptx, + ArchSpec::eCore_nvidia_nvptx, "nvptx"}, + {eByteOrderLittle, 8, 4, 4, llvm::Triple::nvptx64, + ArchSpec::eCore_nvidia_nvptx64, "nvptx64"}, +}; // Ensure that we have an entry in the g_core_definitions for each core. If you // comment out an entry above, you will need to comment out the corresponding @@ -442,9 +442,10 @@ static const ArchDefinitionEntry g_elf_arch_entries[] = { {ArchSpec::eCore_loongarch64, llvm::ELF::EM_LOONGARCH, ArchSpec::eLoongArchSubType_loongarch64, 0xFFFFFFFFu, 0xFFFFFFFFu}, // loongarch64 - // TODO: add data that says what the address byte size is in there + // TODO: add data that says what the address byte size is in there // structures so we can tell r600 from gcn - // {ArchSpec::eCore_amd_gpu_r600, llvm::ELF::EM_AMDGPU, LLDB_INVALID_CPUTYPE, + // {ArchSpec::eCore_amd_gpu_r600, llvm::ELF::EM_AMDGPU, + // LLDB_INVALID_CPUTYPE, // 0xFFFFFFFFu, 0xFFFFFFFFu}, {ArchSpec::eCore_amd_gpu_gcn, llvm::ELF::EM_AMDGPU, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu}, @@ -942,7 +943,7 @@ bool ArchSpec::SetArchitecture(ArchitectureType arch_type, uint32_t cpu, break; case llvm::ELF::ELFOSABI_AMDGPU_HSA: m_triple.setOS(llvm::Triple::OSType::AMDHSA); - break; + break; } } else if (arch_type == eArchTypeCOFF && os == llvm::Triple::Win32) { m_triple.setVendor(llvm::Triple::PC); diff --git a/lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.cpp b/lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.cpp index a5bce9ece..a268df08a 100644 --- a/lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.cpp +++ b/lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.cpp @@ -141,7 +141,7 @@ bool ProcessAMDGPU::GetProcessInfo(ProcessInstanceInfo &proc_info) { return true; } -std::optional<lldb_private::GPUDynamicLoaderLibraryInfo> +std::optional<lldb_private::GPUDynamicLoaderLibraryInfo> ParseLibraryInfo(llvm::StringRef lib_spec) { // This function will parse the shared library string that AMDs GPU driver // sends to the debugger. The format is one of: @@ -150,8 +150,8 @@ ParseLibraryInfo(llvm::StringRef lib_spec) { lldb_private::GPUDynamicLoaderLibraryInfo lib_info; lib_info.load = true; - auto get_offset_and_size = [](llvm::StringRef &values, - std::optional<uint64_t> &offset, + auto get_offset_and_size = [](llvm::StringRef &values, + std::optional<uint64_t> &offset, std::optional<uint64_t> &size) { offset = std::nullopt; size = std::nullopt; @@ -182,7 +182,7 @@ ParseLibraryInfo(llvm::StringRef lib_spec) { if (name.empty()) return std::nullopt; lib_info.pathname = name.str(); - get_offset_and_size(values, lib_info.native_memory_address, + get_offset_and_size(values, lib_info.native_memory_address, lib_info.native_memory_size); // We must have a valid address and size for memory objects. if (!(lib_info.native_memory_address.has_value() && @@ -191,7 +191,7 @@ ParseLibraryInfo(llvm::StringRef lib_spec) { } else { return std::nullopt; } - // TODO: do we need this expanding into a URL or is this for JSON? + // TODO: do we need this expanding into a URL or is this for JSON? lib_info.pathname.clear(); for (char c : path) { if (c == '#') @@ -209,7 +209,6 @@ ParseLibraryInfo(llvm::StringRef lib_spec) { return lib_info; } - std::optional<GPUDynamicLoaderResponse> ProcessAMDGPU::GetGPUDynamicLoaderLibraryInfos( const GPUDynamicLoaderArgs &args) { @@ -235,8 +234,7 @@ ProcessAMDGPU::GetGPUDynamicLoaderLibraryInfos( lib_info->file_size.value()); response.library_infos.push_back(*lib_info); } else { - LLDB_LOGF(log, - "ProcessAMDGPU::%s() failed to parse module path \"%s\"", + LLDB_LOGF(log, "ProcessAMDGPU::%s() failed to parse module path \"%s\"", __FUNCTION__, module.path.c_str()); } } diff --git a/lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.h b/lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.h index 7c6d3956c..440c9c9fd 100644 --- a/lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.h +++ b/lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.h @@ -26,7 +26,8 @@ class ProcessAMDGPU : public NativeProcessProtocol { ProcessInstanceInfo m_process_info; public: - ProcessAMDGPU(lldb::pid_t pid, NativeDelegate &delegate, LLDBServerPluginAMDGPU *plugin); + ProcessAMDGPU(lldb::pid_t pid, NativeDelegate &delegate, + LLDBServerPluginAMDGPU *plugin); Status Resume(const ResumeActionList &resume_actions) override; @@ -82,14 +83,14 @@ public: // Custom accessors void SetLaunchInfo(ProcessLaunchInfo &launch_info); - std::optional<GPUDynamicLoaderResponse> + std::optional<GPUDynamicLoaderResponse> GetGPUDynamicLoaderLibraryInfos(const GPUDynamicLoaderArgs &args) override; bool handleWaveStop(amd_dbgapi_event_id_t eventId); bool handleDebugEvent(amd_dbgapi_event_id_t eventId, - amd_dbgapi_event_kind_t eventKind); - + amd_dbgapi_event_kind_t eventKind); + struct GPUModule { std::string path; uint64_t base_address; @@ -97,14 +98,14 @@ public: uint64_t size; bool is_loaded; }; - std::unordered_map<uintptr_t, GPUModule>& GetGPUModules() { + std::unordered_map<uintptr_t, GPUModule> &GetGPUModules() { return m_gpu_modules; } GPUModule parseCodeObjectUrl(const std::string &url, uint64_t load_address); void AddThread(amd_dbgapi_wave_id_t wave_id); - - LLDBServerPluginAMDGPU* m_debugger = nullptr; + + LLDBServerPluginAMDGPU *m_debugger = nullptr; std::unordered_map<uintptr_t, GPUModule> m_gpu_modules; enum class State { @@ -133,8 +134,8 @@ public: llvm::Expected<std::unique_ptr<NativeProcessProtocol>> Attach(lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) override; - - LLDBServerPluginAMDGPU* m_debugger = nullptr; + + LLDBServerPluginAMDGPU *m_debugger = nullptr; }; } // namespace lldb_server diff --git a/lldb/tools/lldb-server/Plugins/AMDGPU/RegisterContextAMDGPU.cpp b/lldb/tools/lldb-server/Plugins/AMDGPU/RegisterContextAMDGPU.cpp index 670a0eae7..dd7703e99 100644 --- a/lldb/tools/lldb-server/Plugins/AMDGPU/RegisterContextAMDGPU.cpp +++ b/lldb/tools/lldb-server/Plugins/AMDGPU/RegisterContextAMDGPU.cpp @@ -512,7 +512,7 @@ RegisterContextAMDGPU::GetExpeditedRegisters(ExpeditedRegs expType) const { if (g_expedited_regs.empty()) { // We can't expedite all registers because that would cause jThreadsInfo to // fetch registers from all stopped waves eagarly which would be too slow - // and unnecessary. + // and unnecessary. g_expedited_regs.push_back(s_gpu_pc_reg_num); } return g_expedited_regs; diff --git a/lldb/tools/lldb-server/Plugins/AMDGPU/RegisterContextAMDGPU.h b/lldb/tools/lldb-server/Plugins/AMDGPU/RegisterContextAMDGPU.h index 938d6d6bc..3faaf3232 100644 --- a/lldb/tools/lldb-server/Plugins/AMDGPU/RegisterContextAMDGPU.h +++ b/lldb/tools/lldb-server/Plugins/AMDGPU/RegisterContextAMDGPU.h @@ -48,7 +48,7 @@ public: private: bool InitRegisterInfos(); void InitRegisters(); - + Status ReadRegs(); Status ReadReg(const RegisterInfo *reg_info); diff --git a/lldb/tools/lldb-server/Plugins/AMDGPU/ThreadAMDGPU.h b/lldb/tools/lldb-server/Plugins/AMDGPU/ThreadAMDGPU.h index 02991a20b..3fb3775cd 100644 --- a/lldb/tools/lldb-server/Plugins/AMDGPU/ThreadAMDGPU.h +++ b/lldb/tools/lldb-server/Plugins/AMDGPU/ThreadAMDGPU.h @@ -12,8 +12,8 @@ #include "RegisterContextAMDGPU.h" #include "lldb/Host/common/NativeThreadProtocol.h" #include "lldb/lldb-private-forward.h" -#include <string> #include <amd-dbgapi/amd-dbgapi.h> +#include <string> namespace lldb_private { namespace lldb_server { @@ -25,7 +25,8 @@ class ThreadAMDGPU : public NativeThreadProtocol { friend class ProcessAMDGPU; public: - ThreadAMDGPU(ProcessAMDGPU &process, lldb::tid_t tid, std::optional<amd_dbgapi_wave_id_t> wave_id = std::nullopt); + ThreadAMDGPU(ProcessAMDGPU &process, lldb::tid_t tid, + std::optional<amd_dbgapi_wave_id_t> wave_id = std::nullopt); // NativeThreadProtocol Interface std::string GetName() override; @@ -34,14 +35,10 @@ public: bool GetStopReason(ThreadStopInfo &stop_info, std::string &description) override; - - void SetStopReason(lldb::StopReason reason) { - m_stop_info.reason = reason; - } - - RegisterContextAMDGPU &GetRegisterContext() override { - return m_reg_context; - } + + void SetStopReason(lldb::StopReason reason) { m_stop_info.reason = reason; } + + RegisterContextAMDGPU &GetRegisterContext() override { return m_reg_context; } Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) override; @@ -56,9 +53,7 @@ public: const ProcessAMDGPU &GetProcess() const; - std::optional<amd_dbgapi_wave_id_t> GetWaveId() const { - return m_wave_id; - } + std::optional<amd_dbgapi_wave_id_t> GetWaveId() const { return m_wave_id; } private: // Member Variables diff --git a/lldb/tools/lldb-server/Plugins/MockGPU/LLDBServerPluginMockGPU.cpp b/lldb/tools/lldb-server/Plugins/MockGPU/LLDBServerPluginMockGPU.cpp index 8630fa1a6..097c221f9 100644 --- a/lldb/tools/lldb-server/Plugins/MockGPU/LLDBServerPluginMockGPU.cpp +++ b/lldb/tools/lldb-server/Plugins/MockGPU/LLDBServerPluginMockGPU.cpp @@ -7,18 +7,18 @@ //===----------------------------------------------------------------------===// #include "LLDBServerPluginMockGPU.h" +#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h" +#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" #include "ProcessMockGPU.h" #include "lldb/Host/common/TCPSocket.h" -#include "llvm/Support/Error.h" -#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" -#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h" #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h" +#include "llvm/Support/Error.h" #include <sys/socket.h> #include <sys/types.h> #include <sys/uio.h> -#include <unistd.h> #include <thread> +#include <unistd.h> using namespace lldb; using namespace lldb_private; @@ -26,14 +26,16 @@ using namespace lldb_private::lldb_server; using namespace lldb_private::process_gdb_remote; LLDBServerPluginMockGPU::LLDBServerPluginMockGPU( - LLDBServerPlugin::GDBServer &native_process, MainLoop &main_loop) + LLDBServerPlugin::GDBServer &native_process, MainLoop &main_loop) : LLDBServerPlugin(native_process, main_loop) { m_process_manager_up.reset(new ProcessMockGPU::Manager(m_main_loop)); m_gdb_server.reset(new GDBRemoteCommunicationServerLLGS( m_main_loop, *m_process_manager_up, "mock-gpu.server")); Log *log = GetLog(GDBRLog::Plugin); - LLDB_LOGF(log, "LLDBServerPluginMockGPU::LLDBServerPluginMockGPU() faking launch..."); + LLDB_LOGF( + log, + "LLDBServerPluginMockGPU::LLDBServerPluginMockGPU() faking launch..."); ProcessLaunchInfo info; info.GetFlags().Set(eLaunchFlagStopAtEntry | eLaunchFlagDebug | eLaunchFlagDisableASLR); @@ -47,19 +49,19 @@ LLDBServerPluginMockGPU::LLDBServerPluginMockGPU( m_gdb_server->SetLaunchInfo(info); Status error = m_gdb_server->LaunchProcess(); if (error.Fail()) { - LLDB_LOGF(log, "LLDBServerPluginMockGPU::LLDBServerPluginMockGPU() failed to launch: %s", error.AsCString()); + LLDB_LOGF(log, + "LLDBServerPluginMockGPU::LLDBServerPluginMockGPU() failed to " + "launch: %s", + error.AsCString()); } else { - LLDB_LOGF(log, "LLDBServerPluginMockGPU::LLDBServerPluginMockGPU() launched successfully"); + LLDB_LOGF(log, "LLDBServerPluginMockGPU::LLDBServerPluginMockGPU() " + "launched successfully"); } } -LLDBServerPluginMockGPU::~LLDBServerPluginMockGPU() { - CloseFDs(); -} +LLDBServerPluginMockGPU::~LLDBServerPluginMockGPU() { CloseFDs(); } -llvm::StringRef LLDBServerPluginMockGPU::GetPluginName() { - return "mock-gpu"; -} +llvm::StringRef LLDBServerPluginMockGPU::GetPluginName() { return "mock-gpu"; } void LLDBServerPluginMockGPU::CloseFDs() { if (m_fds[0] != -1) { @@ -84,8 +86,7 @@ int LLDBServerPluginMockGPU::GetEventFileDescriptorAtIndex(size_t idx) { return m_fds[0]; } - -bool LLDBServerPluginMockGPU::HandleEventFileDescriptorEvent(int fd) { +bool LLDBServerPluginMockGPU::HandleEventFileDescriptorEvent(int fd) { if (fd == m_fds[0]) { char buf[1]; // Read 1 bytes from the fd @@ -107,8 +108,8 @@ void LLDBServerPluginMockGPU::AcceptAndMainLoopThread( std::lock_guard<std::mutex> guard(m_connect_mutex); m_is_listening = false; if (error.Fail()) { - LLDB_LOGF(log, "%s error returned from Accept(): %s", __PRETTY_FUNCTION__, - error.AsCString()); + LLDB_LOGF(log, "%s error returned from Accept(): %s", __PRETTY_FUNCTION__, + error.AsCString()); return; } m_is_connected = true; @@ -124,14 +125,14 @@ void LLDBServerPluginMockGPU::AcceptAndMainLoopThread( if (m_main_loop_status.Fail()) { LLDB_LOGF(log, "%s main loop exited with an error: %s", __PRETTY_FUNCTION__, m_main_loop_status.AsCString()); - } // Protect access to m_is_connected. std::lock_guard<std::mutex> guard(m_connect_mutex); m_is_connected = false; } -std::optional<GPUPluginConnectionInfo> LLDBServerPluginMockGPU::CreateConnection() { +std::optional<GPUPluginConnectionInfo> +LLDBServerPluginMockGPU::CreateConnection() { std::lock_guard<std::mutex> guard(m_connect_mutex); Log *log = GetLog(GDBRLog::Plugin); LLDB_LOGF(log, "%s called", __PRETTY_FUNCTION__); @@ -145,21 +146,21 @@ std::optional<GPUPluginConnectionInfo> LLDBServerPluginMockGPU::CreateConnection } m_is_listening = true; LLDB_LOGF(log, "%s trying to listen on port 0", __PRETTY_FUNCTION__); - llvm::Expected<std::unique_ptr<TCPSocket>> sock = + llvm::Expected<std::unique_ptr<TCPSocket>> sock = Socket::TcpListen("localhost:0", 5); if (sock) { GPUPluginConnectionInfo connection_info; const uint16_t listen_port = (*sock)->GetLocalPortNumber(); - connection_info.connect_url = llvm::formatv("connect://localhost:{}", - listen_port); + connection_info.connect_url = + llvm::formatv("connect://localhost:{}", listen_port); LLDB_LOGF(log, "%s listening to %u", __PRETTY_FUNCTION__, listen_port); - std::thread t(&LLDBServerPluginMockGPU::AcceptAndMainLoopThread, this, + std::thread t(&LLDBServerPluginMockGPU::AcceptAndMainLoopThread, this, std::move(*sock)); t.detach(); return connection_info; } else { std::string error = llvm::toString(sock.takeError()); - LLDB_LOGF(log, "%s failed to listen to localhost:0: %s", + LLDB_LOGF(log, "%s failed to listen to localhost:0: %s", __PRETTY_FUNCTION__, error.c_str()); } m_is_listening = false; @@ -188,21 +189,24 @@ LLDBServerPluginMockGPU::BreakpointWasHit(GPUPluginBreakpointHitArgs &args) { std::string &bp_identifier = args.breakpoint.identifier; llvm::raw_string_ostream os(json_string); os << toJSON(args); - LLDB_LOGF(log, "LLDBServerPluginMockGPU::BreakpointWasHit(\"%s\"):\nJSON:\n%s", + LLDB_LOGF(log, + "LLDBServerPluginMockGPU::BreakpointWasHit(\"%s\"):\nJSON:\n%s", bp_identifier.c_str(), json_string.c_str()); GPUPluginBreakpointHitResponse response; response.actions.plugin_name = GetPluginName(); if (bp_identifier == "gpu_initialize") { response.disable_bp = true; - LLDB_LOGF(log, "LLDBServerPluginMockGPU::BreakpointWasHit(\"%s\") disabling breakpoint", + LLDB_LOGF(log, + "LLDBServerPluginMockGPU::BreakpointWasHit(\"%s\") disabling " + "breakpoint", bp_identifier.c_str()); response.actions.connect_info = CreateConnection(); // We asked for the symbol "gpu_shlib_load" to be delivered as a symbol // value when the "gpu_initialize" breakpoint was set. So we will use this // to set a breakpoint by address to test setting breakpoints by address. - std::optional<uint64_t> gpu_shlib_load_addr = + std::optional<uint64_t> gpu_shlib_load_addr = args.GetSymbolValue("gpu_shlib_load"); if (gpu_shlib_load_addr) { GPUBreakpointInfo bp; @@ -222,10 +226,10 @@ LLDBServerPluginMockGPU::BreakpointWasHit(GPUPluginBreakpointHitArgs &args) { GPUActions LLDBServerPluginMockGPU::GetInitializeActions() { GPUActions init_actions; init_actions.plugin_name = GetPluginName(); - + GPUBreakpointInfo bp1; bp1.identifier = "gpu_initialize"; - bp1.name_info = {"a.out", "gpu_initialize"}; + bp1.name_info = {"a.out", "gpu_initialize"}; bp1.symbol_names.push_back("gpu_shlib_load"); init_actions.breakpoints.emplace_back(std::move(bp1)); return init_actions; diff --git a/lldb/tools/lldb-server/Plugins/MockGPU/LLDBServerPluginMockGPU.h b/lldb/tools/lldb-server/Plugins/MockGPU/LLDBServerPluginMockGPU.h index 55c5307af..cae90a423 100644 --- a/lldb/tools/lldb-server/Plugins/MockGPU/LLDBServerPluginMockGPU.h +++ b/lldb/tools/lldb-server/Plugins/MockGPU/LLDBServerPluginMockGPU.h @@ -61,7 +61,8 @@ namespace lldb_server { class LLDBServerPluginMockGPU : public LLDBServerPlugin { public: - LLDBServerPluginMockGPU(LLDBServerPlugin::GDBServer &native_process, MainLoop &main_loop); + LLDBServerPluginMockGPU(LLDBServerPlugin::GDBServer &native_process, + MainLoop &main_loop); ~LLDBServerPluginMockGPU() override; llvm::StringRef GetPluginName() override; int GetEventFileDescriptorAtIndex(size_t idx) override; diff --git a/lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.cpp b/lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.cpp index 4518df6db..0e13ac232 100644 --- a/lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.cpp +++ b/lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.cpp @@ -9,13 +9,12 @@ #include "ProcessMockGPU.h" #include "ThreadMockGPU.h" +#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" #include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Utility/ProcessInfo.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/UnimplementedError.h" #include "llvm/Support/Error.h" -#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" - using namespace lldb; using namespace lldb_private; @@ -128,8 +127,9 @@ bool ProcessMockGPU::GetProcessInfo(ProcessInstanceInfo &proc_info) { return true; } -std::optional<GPUDynamicLoaderResponse> -ProcessMockGPU::GetGPUDynamicLoaderLibraryInfos(const GPUDynamicLoaderArgs &args) { +std::optional<GPUDynamicLoaderResponse> +ProcessMockGPU::GetGPUDynamicLoaderLibraryInfos( + const GPUDynamicLoaderArgs &args) { GPUDynamicLoaderResponse response; // First example of a shared library. This is for cases where there is a file // on disk that contains an object file that can be loaded into the process @@ -152,8 +152,8 @@ ProcessMockGPU::GetGPUDynamicLoaderLibraryInfos(const GPUDynamicLoaderArgs &args lib2.file_offset = 0x1000; lib2.file_size = 0x500; response.library_infos.push_back(lib2); - /// Third example of a shared library. This is for cases where there the - /// object file is loaded into the memory of the native process. LLDB will + /// Third example of a shared library. This is for cases where there the + /// object file is loaded into the memory of the native process. LLDB will /// need create an in memory object file using the data in this info. GPUDynamicLoaderLibraryInfo lib3; lib3.pathname = "/usr/lib/lib3.so"; @@ -162,7 +162,7 @@ ProcessMockGPU::GetGPUDynamicLoaderLibraryInfos(const GPUDynamicLoaderArgs &args response.library_infos.push_back(lib3); /// Fourth example of a shared library where we load each of the top level - /// sections of an object file at different addresses. + /// sections of an object file at different addresses. GPUDynamicLoaderLibraryInfo lib4; lib4.pathname = "/usr/lib/lib4.so"; lib4.loaded_sections.push_back({{"PT_LOAD[0]"}, 0x0e0000}); @@ -171,26 +171,25 @@ ProcessMockGPU::GetGPUDynamicLoaderLibraryInfos(const GPUDynamicLoaderArgs &args lib4.loaded_sections.push_back({{"PT_LOAD[3]"}, 0x020000}); response.library_infos.push_back(lib4); - /// Fifth example of a shared library. This is for cases where there the - /// object file is loaded individual sections are loaded at different - /// addresses instead of having a single load address for the entire object - /// file. This allows GPU plug-ins to load sections at different addresses - /// as they are loaded by the GPU driver. Sections can be created for + /// Fifth example of a shared library. This is for cases where there the + /// object file is loaded individual sections are loaded at different + /// addresses instead of having a single load address for the entire object + /// file. This allows GPU plug-ins to load sections at different addresses + /// as they are loaded by the GPU driver. Sections can be created for /// functions in the ObjectFileELF plug-in when parsing the GPU ELF file so - /// that individual functions can be loaded at different addresses as the + /// that individual functions can be loaded at different addresses as the /// driver loads them. GPUDynamicLoaderLibraryInfo lib5; lib5.pathname = "/usr/lib/lib5.so"; - /// Here we are going to assume that the .text section has functions that - /// create sections for each function in the object file. Then each function + /// Here we are going to assume that the .text section has functions that + /// create sections for each function in the object file. Then each function /// can be loaded at a different address as the driver loads them. - lib5.loaded_sections.push_back({{"PT_LOAD[1]", ".text", "foo"}, 0x80000}); - lib5.loaded_sections.push_back({{"PT_LOAD[1]", ".text", "bar"}, 0x80200}); + lib5.loaded_sections.push_back({{"PT_LOAD[1]", ".text", "foo"}, 0x80000}); + lib5.loaded_sections.push_back({{"PT_LOAD[1]", ".text", "bar"}, 0x80200}); response.library_infos.push_back(lib5); return response; } - llvm::Expected<std::unique_ptr<NativeProcessProtocol>> ProcessMockGPU::Manager::Launch( ProcessLaunchInfo &launch_info, @@ -207,7 +206,6 @@ ProcessMockGPU::Manager::Attach( return llvm::createStringError("Unimplemented function"); } - ProcessMockGPU::Extension ProcessMockGPU::Manager::GetSupportedExtensions() const { return Extension::gpu_dyld; diff --git a/lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.h b/lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.h index d1326b83c..cd01f09de 100644 --- a/lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.h +++ b/lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.h @@ -24,23 +24,21 @@ class ProcessMockGPU : public NativeProcessProtocol { ProcessInstanceInfo m_process_info; public: - -class Manager : public NativeProcessProtocol::Manager { + class Manager : public NativeProcessProtocol::Manager { public: - Manager(MainLoop &mainloop) - : NativeProcessProtocol::Manager(mainloop) {} - + Manager(MainLoop &mainloop) : NativeProcessProtocol::Manager(mainloop) {} + llvm::Expected<std::unique_ptr<NativeProcessProtocol>> Launch(ProcessLaunchInfo &launch_info, NativeProcessProtocol::NativeDelegate &native_delegate) override; - + llvm::Expected<std::unique_ptr<NativeProcessProtocol>> Attach(lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) override; - + Extension GetSupportedExtensions() const override; }; - + ProcessMockGPU(lldb::pid_t pid, NativeDelegate &delegate); Status Resume(const ResumeActionList &resume_actions) override; @@ -94,14 +92,13 @@ class Manager : public NativeProcessProtocol::Manager { bool GetProcessInfo(ProcessInstanceInfo &info) override; - std::optional<GPUDynamicLoaderResponse> + std::optional<GPUDynamicLoaderResponse> GetGPUDynamicLoaderLibraryInfos(const GPUDynamicLoaderArgs &args) override; // Custom accessors void SetLaunchInfo(ProcessLaunchInfo &launch_info); }; - } // namespace lldb_server } // namespace lldb_private diff --git a/lldb/tools/lldb-server/Plugins/MockGPU/RegisterContextMockGPU.cpp b/lldb/tools/lldb-server/Plugins/MockGPU/RegisterContextMockGPU.cpp index 18a3ffc35..58c5aaf01 100644 --- a/lldb/tools/lldb-server/Plugins/MockGPU/RegisterContextMockGPU.cpp +++ b/lldb/tools/lldb-server/Plugins/MockGPU/RegisterContextMockGPU.cpp @@ -119,12 +119,12 @@ static const RegisterSet g_reg_sets[] = { #define REG_OFFSET(Reg) offsetof(RegisterContextMockGPU::RegisterContext, Reg) static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { { - "R0", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(R0),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "R0", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(R0), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_R0, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -138,12 +138,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "R1", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(R1),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "R1", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(R1), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_R1, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -157,12 +157,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "R2", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(R2),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "R2", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(R2), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_R2, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -176,12 +176,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "R3", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(R3),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "R3", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(R3), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_R3, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -195,12 +195,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "R4", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(R4),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "R4", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(R4), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_R4, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -214,12 +214,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "R5", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(R5),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "R5", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(R5), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_R5, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -233,12 +233,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "R6", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(R6),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "R6", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(R6), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_R6, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -252,12 +252,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "R7", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(R7),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "R7", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(R7), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_R7, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -271,12 +271,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "SP", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(SP),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "SP", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(SP), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_SP, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -290,12 +290,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "FP", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(FP),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "FP", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(FP), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_FP, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -309,12 +309,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "PC", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(PC),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "PC", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(PC), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_PC, // RegisterInfo::kinds[eRegisterKindEHFrame] @@ -328,12 +328,12 @@ static const RegisterInfo g_reg_infos[LLDBRegNum::kNumRegs] = { nullptr, // RegisterInfo::flags_type }, { - "Flags", // RegisterInfo::name - nullptr, // RegisterInfo::alt_name - 8, // RegisterInfo::byte_size - REG_OFFSET(Flags),// RegisterInfo::byte_offset - eEncodingUint, // RegisterInfo::encoding - eFormatHex, // RegisterInfo::format + "Flags", // RegisterInfo::name + nullptr, // RegisterInfo::alt_name + 8, // RegisterInfo::byte_size + REG_OFFSET(Flags), // RegisterInfo::byte_offset + eEncodingUint, // RegisterInfo::encoding + eFormatHex, // RegisterInfo::format { // RegisterInfo::kinds[] EH_FRAME_Flags, // RegisterInfo::kinds[eRegisterKindEHFrame] diff --git a/lldb/tools/lldb-server/Plugins/MockGPU/RegisterContextMockGPU.h b/lldb/tools/lldb-server/Plugins/MockGPU/RegisterContextMockGPU.h index e80b7fec2..d58b75363 100644 --- a/lldb/tools/lldb-server/Plugins/MockGPU/RegisterContextMockGPU.h +++ b/lldb/tools/lldb-server/Plugins/MockGPU/RegisterContextMockGPU.h @@ -43,40 +43,39 @@ public: std::vector<uint32_t> GetExpeditedRegisters(ExpeditedRegs expType) const override; - // A storage stucture for all registers; - struct RegisterContext { - uint64_t R0; - uint64_t R1; - uint64_t R2; - uint64_t R3; - uint64_t R4; - uint64_t R5; - uint64_t R6; - uint64_t R7; - uint64_t SP; - uint64_t FP; - uint64_t PC; - uint64_t Flags; - uint64_t V0; - uint64_t V1; - uint64_t V2; - uint64_t V3; - uint64_t V4; - uint64_t V5; - uint64_t V6; - uint64_t V7; - }; - + // A storage stucture for all registers; + struct RegisterContext { + uint64_t R0; + uint64_t R1; + uint64_t R2; + uint64_t R3; + uint64_t R4; + uint64_t R5; + uint64_t R6; + uint64_t R7; + uint64_t SP; + uint64_t FP; + uint64_t PC; + uint64_t Flags; + uint64_t V0; + uint64_t V1; + uint64_t V2; + uint64_t V3; + uint64_t V4; + uint64_t V5; + uint64_t V6; + uint64_t V7; + }; + private: void InitRegisters(); void InvalidateAllRegisters(); Status ReadRegs(); - // All mock GPU registers are contained in this buffer. union { /// Allow for indexed access to each register value. - uint64_t data[sizeof(RegisterContext)/sizeof(uint64_t)]; + uint64_t data[sizeof(RegisterContext) / sizeof(uint64_t)]; /// Allow for direct access to the register values by name. RegisterContext regs; } m_regs; diff --git a/lldb/tools/lldb-server/Plugins/MockGPU/ThreadMockGPU.cpp b/lldb/tools/lldb-server/Plugins/MockGPU/ThreadMockGPU.cpp index 31024fc99..b327c247a 100644 --- a/lldb/tools/lldb-server/Plugins/MockGPU/ThreadMockGPU.cpp +++ b/lldb/tools/lldb-server/Plugins/MockGPU/ThreadMockGPU.cpp @@ -13,7 +13,8 @@ using namespace lldb_server; ThreadMockGPU::ThreadMockGPU(ProcessMockGPU &process, lldb::tid_t tid) : NativeThreadProtocol(process, tid), m_reg_context(*this) { - m_stop_info.reason = lldb::eStopReasonTrace; // lldb::eStopReasonDynammicLoader; + m_stop_info.reason = + lldb::eStopReasonTrace; // lldb::eStopReasonDynammicLoader; } // NativeThreadProtocol Interface `````````` </details> https://github.com/llvm/llvm-project/pull/146978 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits