[Lldb-commits] [lldb] [lldb][AIX] Added new plugin AIX-DYLD (Dynamic Loader) Base Support (PR #115714)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 11 05:34:37 PST 2024
https://github.com/Lakshmi-Surekha created https://github.com/llvm/llvm-project/pull/115714
This PR is in reference to porting LLDB on AIX.
Link to discussions on llvm discourse and github:
1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
2. https://github.com/llvm/llvm-project/issues/101657
The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601
Added Dynamic Loader base implementation for LLDB support for AIX
Added base functionality. Will enhance the files in incremental PRs
@DavidSpickett @labath @DhruvSrivastavaX
>From 468ad873cd90312cea67900851f8a0cf44a830f6 Mon Sep 17 00:00:00 2001
From: Lakshmi Surekha Kovvuri <lakshmi at aixbase.aus.stglabs.ibm.com>
Date: Mon, 11 Nov 2024 03:02:16 -0600
Subject: [PATCH 1/4] New Plugin DynamicLoader(AIX-DYLD) for Platform AIX
---
lldb/source/Plugins/DynamicLoader/CMakeLists.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/lldb/source/Plugins/DynamicLoader/CMakeLists.txt b/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
index 30607159acdc08..4f3fb693faae18 100644
--- a/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
+++ b/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
@@ -5,4 +5,5 @@ add_subdirectory(POSIX-DYLD)
add_subdirectory(Static)
add_subdirectory(Hexagon-DYLD)
add_subdirectory(Windows-DYLD)
+add_subdirectory(AIX-DYLD)
add_subdirectory(wasm-DYLD)
>From 7add496ea80646cfe2b8aad0ecd595811cc01522 Mon Sep 17 00:00:00 2001
From: Lakshmi Surekha Kovvuri <lakshmi at aixbase.aus.stglabs.ibm.com>
Date: Mon, 11 Nov 2024 03:48:02 -0600
Subject: [PATCH 2/4] New Plugin DynamicLoader(AIX-DYLD) for Platform AIX
---
.../DynamicLoader/AIX-DYLD/CMakeLists.txt | 11 ++
.../AIX-DYLD/DynamicLoaderAIXDYLD.cpp | 153 ++++++++++++++++++
.../AIX-DYLD/DynamicLoaderAIXDYLD.h | 55 +++++++
3 files changed, 219 insertions(+)
create mode 100644 lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt
create mode 100644 lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp
create mode 100644 lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.h
diff --git a/lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt
new file mode 100644
index 00000000000000..02fe0d617955a0
--- /dev/null
+++ b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt
@@ -0,0 +1,11 @@
+add_definitions("-D_ALL_SOURCE")
+
+add_lldb_library(lldbPluginDynamicLoaderAIXDYLD PLUGIN
+ DynamicLoaderAIXDYLD.cpp
+
+ LINK_LIBS
+ lldbCore
+ lldbTarget
+ LINK_COMPONENTS
+ Support
+ )
diff --git a/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp
new file mode 100644
index 00000000000000..070831cc0f54fa
--- /dev/null
+++ b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp
@@ -0,0 +1,153 @@
+//===-- DynamicLoaderAIXDYLD.cpp --------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "DynamicLoaderAIXDYLD.h"
+
+#include "lldb/Core/Module.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Platform.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/ThreadPlanStepInstruction.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#if defined(_AIX)
+#include <sys/ldr.h>
+#endif
+
+/*#include "llvm/ADT/Triple.h"
+*/
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(DynamicLoaderAIXDYLD)
+
+DynamicLoaderAIXDYLD::DynamicLoaderAIXDYLD(Process *process)
+ : DynamicLoader(process) {}
+
+DynamicLoaderAIXDYLD::~DynamicLoaderAIXDYLD() = default;
+
+void DynamicLoaderAIXDYLD::Initialize() {
+ PluginManager::RegisterPlugin(GetPluginNameStatic(),
+ GetPluginDescriptionStatic(), CreateInstance);
+}
+
+void DynamicLoaderAIXDYLD::Terminate() {}
+
+llvm::StringRef DynamicLoaderAIXDYLD::GetPluginDescriptionStatic() {
+ return "Dynamic loader plug-in that watches for shared library "
+ "loads/unloads in AIX processes.";
+}
+
+DynamicLoader *DynamicLoaderAIXDYLD::CreateInstance(Process *process,
+ bool force) {
+ bool should_create = force;
+ if (!should_create) {
+ const llvm::Triple &triple_ref =
+ process->GetTarget().GetArchitecture().GetTriple();
+ if (triple_ref.getOS() == llvm::Triple::AIX)
+ should_create = true;
+ }
+
+ if (should_create)
+ return new DynamicLoaderAIXDYLD(process);
+
+ return nullptr;
+}
+
+void DynamicLoaderAIXDYLD::OnLoadModule(lldb::ModuleSP module_sp,
+ const ModuleSpec module_spec,
+ lldb::addr_t module_addr) {
+
+ // Resolve the module unless we already have one.
+ if (!module_sp) {
+ Status error;
+ module_sp = m_process->GetTarget().GetOrCreateModule(module_spec,
+ true /* notify */, &error);
+ if (error.Fail())
+ return;
+ }
+
+ m_loaded_modules[module_sp] = module_addr;
+ UpdateLoadedSectionsCommon(module_sp, module_addr, false);
+ ModuleList module_list;
+ module_list.Append(module_sp);
+ m_process->GetTarget().ModulesDidLoad(module_list);
+}
+
+void DynamicLoaderAIXDYLD::OnUnloadModule(lldb::addr_t module_addr) {
+ Address resolved_addr;
+ if (!m_process->GetTarget().ResolveLoadAddress(module_addr, resolved_addr))
+ return;
+
+ ModuleSP module_sp = resolved_addr.GetModule();
+ if (module_sp) {
+ m_loaded_modules.erase(module_sp);
+ UnloadSectionsCommon(module_sp);
+ ModuleList module_list;
+ module_list.Append(module_sp);
+ m_process->GetTarget().ModulesDidUnload(module_list, false);
+ }
+}
+
+lldb::addr_t DynamicLoaderAIXDYLD::GetLoadAddress(ModuleSP executable) {
+ // First, see if the load address is already cached.
+ auto it = m_loaded_modules.find(executable);
+ if (it != m_loaded_modules.end() && it->second != LLDB_INVALID_ADDRESS)
+ return it->second;
+
+ lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
+
+ // Second, try to get it through the process plugins. For a remote process,
+ // the remote platform will be responsible for providing it.
+ FileSpec file_spec(executable->GetPlatformFileSpec());
+ bool is_loaded = false;
+ Status status =
+ m_process->GetFileLoadAddress(file_spec, is_loaded, load_addr);
+ // Servers other than lldb server could respond with a bogus address.
+ if (status.Success() && is_loaded && load_addr != LLDB_INVALID_ADDRESS) {
+ m_loaded_modules[executable] = load_addr;
+ return load_addr;
+ }
+
+ //// Hack to try set breakpoint
+ //Breakpoint *dyld_break = m_process->GetTarget().CreateBreakpoint(0x100000638, true, false).get();
+ //dyld_break->SetCallback(DynamicLoaderAIXDYLD::NotifyBreakpointHit, this, true);
+ //dyld_break->SetBreakpointKind("hack-debug");
+
+ return LLDB_INVALID_ADDRESS;
+}
+
+bool DynamicLoaderAIXDYLD::NotifyBreakpointHit(
+ void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id,
+ lldb::user_id_t break_loc_id) {
+}
+
+void DynamicLoaderAIXDYLD::DidLaunch() {
+ Log *log = GetLog(LLDBLog::DynamicLoader);
+ LLDB_LOGF(log, "DynamicLoaderAIXDYLD::%s()", __FUNCTION__);
+
+ ModuleSP executable = GetTargetExecutable();
+ if (!executable.get())
+ return;
+
+ lldb::addr_t load_addr = GetLoadAddress(executable);
+ if (load_addr != LLDB_INVALID_ADDRESS) {
+ // Update the loaded sections so that the breakpoints can be resolved.
+ UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_addr, false);
+
+ ModuleList module_list;
+ module_list.Append(executable);
+ m_process->GetTarget().ModulesDidLoad(module_list);
+ auto error = m_process->LoadModules();
+ LLDB_LOG_ERROR(log, std::move(error), "failed to load modules: {0}");
+ }
+}
diff --git a/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.h b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.h
new file mode 100644
index 00000000000000..ae4b7aca66dcc5
--- /dev/null
+++ b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.h
@@ -0,0 +1,55 @@
+//===-- DynamicLoaderAIXDYLD.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_DYNAMICLOADER_AIX_DYLD_DYNAMICLOADERAIXDYLD_H
+#define LLDB_SOURCE_PLUGINS_DYNAMICLOADER_AIX_DYLD_DYNAMICLOADERAIXDYLD_H
+
+#include "lldb/Target/DynamicLoader.h"
+#include "lldb/lldb-forward.h"
+
+#include <map>
+
+namespace lldb_private {
+
+class DynamicLoaderAIXDYLD : public DynamicLoader {
+public:
+ DynamicLoaderAIXDYLD(Process *process);
+
+ ~DynamicLoaderAIXDYLD() override;
+
+ static void Initialize();
+ static void Terminate();
+ static llvm::StringRef GetPluginNameStatic() { return "windows-dyld"; }
+ static llvm::StringRef GetPluginDescriptionStatic();
+
+ static DynamicLoader *CreateInstance(Process *process, bool force);
+
+ void OnLoadModule(lldb::ModuleSP module_sp, const ModuleSpec module_spec,
+ lldb::addr_t module_addr);
+ void OnUnloadModule(lldb::addr_t module_addr);
+
+ void DidAttach() override;
+ void DidLaunch() override;
+ Status CanLoadImage() override;
+ lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
+ bool stop) override;
+
+ llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
+
+ static bool NotifyBreakpointHit(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
+
+protected:
+ lldb::addr_t GetLoadAddress(lldb::ModuleSP executable);
+
+private:
+ std::map<lldb::ModuleSP, lldb::addr_t> m_loaded_modules;
+};
+
+} // namespace lldb_private
+
+#endif // LLDB_SOURCE_PLUGINS_DYNAMICLOADER_AIX_DYLD_DYNAMICLOADERWAIXDYLD_H
>From 8d96335a18cbc6957524c786184c2101197806f2 Mon Sep 17 00:00:00 2001
From: Lakshmi Surekha Kovvuri <lakshmi at aixbase.aus.stglabs.ibm.com>
Date: Mon, 11 Nov 2024 07:05:29 -0600
Subject: [PATCH 3/4] New Plugin DynamicLoader(AIX-DYLD) for platform AIX
---
.../AIX-DYLD/DynamicLoaderAIXDYLD.cpp | 35 ++++++++-----------
.../AIX-DYLD/DynamicLoaderAIXDYLD.h | 4 +--
2 files changed, 15 insertions(+), 24 deletions(-)
diff --git a/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp
index 070831cc0f54fa..6b48737551bfb4 100644
--- a/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp
@@ -18,12 +18,6 @@
#include "lldb/Target/ThreadPlanStepInstruction.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
-#if defined(_AIX)
-#include <sys/ldr.h>
-#endif
-
-/*#include "llvm/ADT/Triple.h"
-*/
using namespace lldb;
using namespace lldb_private;
@@ -48,7 +42,7 @@ llvm::StringRef DynamicLoaderAIXDYLD::GetPluginDescriptionStatic() {
}
DynamicLoader *DynamicLoaderAIXDYLD::CreateInstance(Process *process,
- bool force) {
+ bool force) {
bool should_create = force;
if (!should_create) {
const llvm::Triple &triple_ref =
@@ -64,14 +58,14 @@ DynamicLoader *DynamicLoaderAIXDYLD::CreateInstance(Process *process,
}
void DynamicLoaderAIXDYLD::OnLoadModule(lldb::ModuleSP module_sp,
- const ModuleSpec module_spec,
- lldb::addr_t module_addr) {
+ const ModuleSpec module_spec,
+ lldb::addr_t module_addr) {
// Resolve the module unless we already have one.
if (!module_sp) {
Status error;
- module_sp = m_process->GetTarget().GetOrCreateModule(module_spec,
- true /* notify */, &error);
+ module_sp = m_process->GetTarget().GetOrCreateModule(
+ module_spec, true /* notify */, &error);
if (error.Fail())
return;
}
@@ -117,19 +111,10 @@ lldb::addr_t DynamicLoaderAIXDYLD::GetLoadAddress(ModuleSP executable) {
m_loaded_modules[executable] = load_addr;
return load_addr;
}
-
- //// Hack to try set breakpoint
- //Breakpoint *dyld_break = m_process->GetTarget().CreateBreakpoint(0x100000638, true, false).get();
- //dyld_break->SetCallback(DynamicLoaderAIXDYLD::NotifyBreakpointHit, this, true);
- //dyld_break->SetBreakpointKind("hack-debug");
-
return LLDB_INVALID_ADDRESS;
}
-bool DynamicLoaderAIXDYLD::NotifyBreakpointHit(
- void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id) {
-}
+void DynamicLoaderAIXDYLD::DidAttach() {}
void DynamicLoaderAIXDYLD::DidLaunch() {
Log *log = GetLog(LLDBLog::DynamicLoader);
@@ -151,3 +136,11 @@ void DynamicLoaderAIXDYLD::DidLaunch() {
LLDB_LOG_ERROR(log, std::move(error), "failed to load modules: {0}");
}
}
+
+Status DynamicLoaderAIXDYLD::CanLoadImage() { return Status(); }
+
+ThreadPlanSP DynamicLoaderAIXDYLD::GetStepThroughTrampolinePlan(Thread &thread,
+ bool stop) {
+ // FIXME
+ return ThreadPlanSP();
+}
diff --git a/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.h b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.h
index ae4b7aca66dcc5..ba690d66997366 100644
--- a/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.h
+++ b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.h
@@ -24,7 +24,7 @@ class DynamicLoaderAIXDYLD : public DynamicLoader {
static void Initialize();
static void Terminate();
- static llvm::StringRef GetPluginNameStatic() { return "windows-dyld"; }
+ static llvm::StringRef GetPluginNameStatic() { return "aix-dyld"; }
static llvm::StringRef GetPluginDescriptionStatic();
static DynamicLoader *CreateInstance(Process *process, bool force);
@@ -41,8 +41,6 @@ class DynamicLoaderAIXDYLD : public DynamicLoader {
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
- static bool NotifyBreakpointHit(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
-
protected:
lldb::addr_t GetLoadAddress(lldb::ModuleSP executable);
>From 8afa6e6f16aeabecd24ad26c4d76454685fc2b00 Mon Sep 17 00:00:00 2001
From: Lakshmi Surekha Kovvuri <lakshmi at aixbase.aus.stglabs.ibm.com>
Date: Mon, 11 Nov 2024 07:24:25 -0600
Subject: [PATCH 4/4] New Plugin DynamicLoader(AIX-DYLD) for Platform AIX
---
lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt | 2 --
1 file changed, 2 deletions(-)
diff --git a/lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt
index 02fe0d617955a0..c3bd424479f17c 100644
--- a/lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt
+++ b/lldb/source/Plugins/DynamicLoader/AIX-DYLD/CMakeLists.txt
@@ -1,5 +1,3 @@
-add_definitions("-D_ALL_SOURCE")
-
add_lldb_library(lldbPluginDynamicLoaderAIXDYLD PLUGIN
DynamicLoaderAIXDYLD.cpp
More information about the lldb-commits
mailing list