[Lldb-commits] [lldb] [AIX] 1. Avoid namespace collision on other platforms (PR #104679)
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/104679 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. This PR is for discussion as asked in #101657 The complete changes for porting are present in this draft PR: https://github.com/llvm/llvm-project/pull/102601 The changes on this PR are intended to avoid namespace collision for certain typedefs between lldb and other platforms: 1. tid_t --> lldb::tid_t 2. offset_t --> lldb::offset_t >From e72ceaada170354aa322b4c6a1787152ac72c65b Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Sat, 17 Aug 2024 12:16:09 -0500 Subject: [PATCH] Using lldb's internal typedefs to avoid namespace collision 1. tid_t --> lldb::tid_t 2. offset_t --> lldb::ofset_t --- lldb/source/API/SBBreakpoint.cpp | 6 +++--- lldb/source/API/SBBreakpointLocation.cpp | 6 +++--- lldb/source/API/SBBreakpointName.cpp | 4 ++-- lldb/source/Expression/DWARFExpression.cpp | 10 +- lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp | 2 +- .../Darwin-Kernel/DynamicLoaderDarwinKernel.cpp| 4 ++-- .../MacOSX-DYLD/DynamicLoaderDarwin.cpp| 2 +- .../InstrumentationRuntimeMainThreadChecker.cpp| 2 +- .../TSan/InstrumentationRuntimeTSan.cpp| 14 +++--- .../UBSan/InstrumentationRuntimeUBSan.cpp | 2 +- .../MemoryHistory/asan/MemoryHistoryASan.cpp | 2 +- .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 6 +++--- .../Python/OperatingSystemPython.cpp | 2 +- .../Plugins/Process/Utility/ThreadMemory.cpp | 2 +- .../Process/gdb-remote/ProcessGDBRemote.cpp| 2 +- .../Plugins/Process/mach-core/ProcessMachCore.cpp | 8 lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp | 2 +- .../MacOSX/AppleGetThreadItemInfoHandler.cpp | 2 +- lldb/source/Symbol/DWARFCallFrameInfo.cpp | 4 ++-- 19 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index 3d908047f9455b..728fe04d14d927 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -342,7 +342,7 @@ uint32_t SBBreakpoint::GetIgnoreCount() const { return count; } -void SBBreakpoint::SetThreadID(tid_t tid) { +void SBBreakpoint::SetThreadID(lldb::tid_t tid) { LLDB_INSTRUMENT_VA(this, tid); BreakpointSP bkpt_sp = GetSP(); @@ -353,10 +353,10 @@ void SBBreakpoint::SetThreadID(tid_t tid) { } } -tid_t SBBreakpoint::GetThreadID() { +lldb::tid_t SBBreakpoint::GetThreadID() { LLDB_INSTRUMENT_VA(this); - tid_t tid = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; BreakpointSP bkpt_sp = GetSP(); if (bkpt_sp) { std::lock_guard guard( diff --git a/lldb/source/API/SBBreakpointLocation.cpp b/lldb/source/API/SBBreakpointLocation.cpp index 75b66364d4f1ae..fad9a4076a54fb 100644 --- a/lldb/source/API/SBBreakpointLocation.cpp +++ b/lldb/source/API/SBBreakpointLocation.cpp @@ -302,7 +302,7 @@ bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) { return has_commands; } -void SBBreakpointLocation::SetThreadID(tid_t thread_id) { +void SBBreakpointLocation::SetThreadID(lldb::tid_t thread_id) { LLDB_INSTRUMENT_VA(this, thread_id); BreakpointLocationSP loc_sp = GetSP(); @@ -313,10 +313,10 @@ void SBBreakpointLocation::SetThreadID(tid_t thread_id) { } } -tid_t SBBreakpointLocation::GetThreadID() { +lldb::tid_t SBBreakpointLocation::GetThreadID() { LLDB_INSTRUMENT_VA(this); - tid_t tid = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; BreakpointLocationSP loc_sp = GetSP(); if (loc_sp) { std::lock_guard guard( diff --git a/lldb/source/API/SBBreakpointName.cpp b/lldb/source/API/SBBreakpointName.cpp index 7f63aaf6fa7d5e..5c7c0a8f6504b0 100644 --- a/lldb/source/API/SBBreakpointName.cpp +++ b/lldb/source/API/SBBreakpointName.cpp @@ -347,7 +347,7 @@ bool SBBreakpointName::GetAutoContinue() { return bp_name->GetOptions().IsAutoContinue(); } -void SBBreakpointName::SetThreadID(tid_t tid) { +void SBBreakpointName::SetThreadID(lldb::tid_t tid) { LLDB_INSTRUMENT_VA(this, tid); BreakpointName *bp_name = GetBreakpointName(); @@ -361,7 +361,7 @@ void SBBreakpointName::SetThreadID(tid_t tid) { UpdateName(*bp_name); } -tid_t SBBreakpointName::GetThreadID() { +lldb::tid_t SBBreakpointName::GetThreadID() { LLDB_INSTRUMENT_VA(this); BreakpointName *bp_name = GetBreakpointName(); diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index 444e44b3928919..c1feec990f989d 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -130,7 +130,7 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *r
[Lldb-commits] [lldb] [AIX] 1. Avoid namespace collision on other platforms (PR #104679)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/104679 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [AIX] 1. Avoid namespace collision on other platforms (PR #104679)
https://github.com/DhruvSrivastavaX closed https://github.com/llvm/llvm-project/pull/104679 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [AIX] 1. Avoid namespace collision on other platforms (PR #104679)
https://github.com/DhruvSrivastavaX reopened https://github.com/llvm/llvm-project/pull/104679 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] 1. Avoid namespace collision on other platforms (PR #104679)
DhruvSrivastavaX wrote: Ok Great, @DavidSpickett I was hoping for some feedback to get more clarity about llvm PRs. 1. Yes, the definition of tid_t and offset_t can differ in certain scenarios in AIX when compared to lldb, so trying to avoid such conflicts. 2. We have used ibm-clang which is an AIX compatible version of clang, Here is the link: https://www.ibm.com/docs/en/openxl-c-and-cpp-aix/17.1.1?topic=cc-highly-configurable-compiler 3. clang-format: Ok, thanks for that. I will use clang-format to avoid such formatting errors in the future. 4. [sub-project][area] : Yes, thanks I had some doubt about that. Thanks for clarifying. Also, I am numbering these porting commits to keep additional tracking. https://github.com/llvm/llvm-project/pull/104679 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] 1. Avoid namespace collision on other platforms (PR #104679)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/104679 >From e72ceaada170354aa322b4c6a1787152ac72c65b Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Sat, 17 Aug 2024 12:16:09 -0500 Subject: [PATCH 1/2] Using lldb's internal typedefs to avoid namespace collision 1. tid_t --> lldb::tid_t 2. offset_t --> lldb::ofset_t --- lldb/source/API/SBBreakpoint.cpp | 6 +++--- lldb/source/API/SBBreakpointLocation.cpp | 6 +++--- lldb/source/API/SBBreakpointName.cpp | 4 ++-- lldb/source/Expression/DWARFExpression.cpp | 10 +- lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp | 2 +- .../Darwin-Kernel/DynamicLoaderDarwinKernel.cpp| 4 ++-- .../MacOSX-DYLD/DynamicLoaderDarwin.cpp| 2 +- .../InstrumentationRuntimeMainThreadChecker.cpp| 2 +- .../TSan/InstrumentationRuntimeTSan.cpp| 14 +++--- .../UBSan/InstrumentationRuntimeUBSan.cpp | 2 +- .../MemoryHistory/asan/MemoryHistoryASan.cpp | 2 +- .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 6 +++--- .../Python/OperatingSystemPython.cpp | 2 +- .../Plugins/Process/Utility/ThreadMemory.cpp | 2 +- .../Process/gdb-remote/ProcessGDBRemote.cpp| 2 +- .../Plugins/Process/mach-core/ProcessMachCore.cpp | 8 lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp | 2 +- .../MacOSX/AppleGetThreadItemInfoHandler.cpp | 2 +- lldb/source/Symbol/DWARFCallFrameInfo.cpp | 4 ++-- 19 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index 3d908047f9455b..728fe04d14d927 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -342,7 +342,7 @@ uint32_t SBBreakpoint::GetIgnoreCount() const { return count; } -void SBBreakpoint::SetThreadID(tid_t tid) { +void SBBreakpoint::SetThreadID(lldb::tid_t tid) { LLDB_INSTRUMENT_VA(this, tid); BreakpointSP bkpt_sp = GetSP(); @@ -353,10 +353,10 @@ void SBBreakpoint::SetThreadID(tid_t tid) { } } -tid_t SBBreakpoint::GetThreadID() { +lldb::tid_t SBBreakpoint::GetThreadID() { LLDB_INSTRUMENT_VA(this); - tid_t tid = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; BreakpointSP bkpt_sp = GetSP(); if (bkpt_sp) { std::lock_guard guard( diff --git a/lldb/source/API/SBBreakpointLocation.cpp b/lldb/source/API/SBBreakpointLocation.cpp index 75b66364d4f1ae..fad9a4076a54fb 100644 --- a/lldb/source/API/SBBreakpointLocation.cpp +++ b/lldb/source/API/SBBreakpointLocation.cpp @@ -302,7 +302,7 @@ bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) { return has_commands; } -void SBBreakpointLocation::SetThreadID(tid_t thread_id) { +void SBBreakpointLocation::SetThreadID(lldb::tid_t thread_id) { LLDB_INSTRUMENT_VA(this, thread_id); BreakpointLocationSP loc_sp = GetSP(); @@ -313,10 +313,10 @@ void SBBreakpointLocation::SetThreadID(tid_t thread_id) { } } -tid_t SBBreakpointLocation::GetThreadID() { +lldb::tid_t SBBreakpointLocation::GetThreadID() { LLDB_INSTRUMENT_VA(this); - tid_t tid = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; BreakpointLocationSP loc_sp = GetSP(); if (loc_sp) { std::lock_guard guard( diff --git a/lldb/source/API/SBBreakpointName.cpp b/lldb/source/API/SBBreakpointName.cpp index 7f63aaf6fa7d5e..5c7c0a8f6504b0 100644 --- a/lldb/source/API/SBBreakpointName.cpp +++ b/lldb/source/API/SBBreakpointName.cpp @@ -347,7 +347,7 @@ bool SBBreakpointName::GetAutoContinue() { return bp_name->GetOptions().IsAutoContinue(); } -void SBBreakpointName::SetThreadID(tid_t tid) { +void SBBreakpointName::SetThreadID(lldb::tid_t tid) { LLDB_INSTRUMENT_VA(this, tid); BreakpointName *bp_name = GetBreakpointName(); @@ -361,7 +361,7 @@ void SBBreakpointName::SetThreadID(tid_t tid) { UpdateName(*bp_name); } -tid_t SBBreakpointName::GetThreadID() { +lldb::tid_t SBBreakpointName::GetThreadID() { LLDB_INSTRUMENT_VA(this); BreakpointName *bp_name = GetBreakpointName(); diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index 444e44b3928919..c1feec990f989d 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -130,7 +130,7 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx, /// Return the length in bytes of the set of operands for \p op. No guarantees /// are made on the state of \p data after this call. -static offset_t GetOpcodeDataSize(const DataExtractor &data, +static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op, const DWARFUnit *dwarf_cu) { lldb::offset_t offset = data_offset; @@ -358,7 +358,7 @@ lldb::add
[Lldb-commits] [lldb] [lldb][AIX] 1. Avoid namespace collision on other platforms (PR #104679)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/104679 >From e72ceaada170354aa322b4c6a1787152ac72c65b Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Sat, 17 Aug 2024 12:16:09 -0500 Subject: [PATCH] Using lldb's internal typedefs to avoid namespace collision 1. tid_t --> lldb::tid_t 2. offset_t --> lldb::ofset_t --- lldb/source/API/SBBreakpoint.cpp | 6 +++--- lldb/source/API/SBBreakpointLocation.cpp | 6 +++--- lldb/source/API/SBBreakpointName.cpp | 4 ++-- lldb/source/Expression/DWARFExpression.cpp | 10 +- lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp | 2 +- .../Darwin-Kernel/DynamicLoaderDarwinKernel.cpp| 4 ++-- .../MacOSX-DYLD/DynamicLoaderDarwin.cpp| 2 +- .../InstrumentationRuntimeMainThreadChecker.cpp| 2 +- .../TSan/InstrumentationRuntimeTSan.cpp| 14 +++--- .../UBSan/InstrumentationRuntimeUBSan.cpp | 2 +- .../MemoryHistory/asan/MemoryHistoryASan.cpp | 2 +- .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 6 +++--- .../Python/OperatingSystemPython.cpp | 2 +- .../Plugins/Process/Utility/ThreadMemory.cpp | 2 +- .../Process/gdb-remote/ProcessGDBRemote.cpp| 2 +- .../Plugins/Process/mach-core/ProcessMachCore.cpp | 8 lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp | 2 +- .../MacOSX/AppleGetThreadItemInfoHandler.cpp | 2 +- lldb/source/Symbol/DWARFCallFrameInfo.cpp | 4 ++-- 19 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index 3d908047f9455b..728fe04d14d927 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -342,7 +342,7 @@ uint32_t SBBreakpoint::GetIgnoreCount() const { return count; } -void SBBreakpoint::SetThreadID(tid_t tid) { +void SBBreakpoint::SetThreadID(lldb::tid_t tid) { LLDB_INSTRUMENT_VA(this, tid); BreakpointSP bkpt_sp = GetSP(); @@ -353,10 +353,10 @@ void SBBreakpoint::SetThreadID(tid_t tid) { } } -tid_t SBBreakpoint::GetThreadID() { +lldb::tid_t SBBreakpoint::GetThreadID() { LLDB_INSTRUMENT_VA(this); - tid_t tid = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; BreakpointSP bkpt_sp = GetSP(); if (bkpt_sp) { std::lock_guard guard( diff --git a/lldb/source/API/SBBreakpointLocation.cpp b/lldb/source/API/SBBreakpointLocation.cpp index 75b66364d4f1ae..fad9a4076a54fb 100644 --- a/lldb/source/API/SBBreakpointLocation.cpp +++ b/lldb/source/API/SBBreakpointLocation.cpp @@ -302,7 +302,7 @@ bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) { return has_commands; } -void SBBreakpointLocation::SetThreadID(tid_t thread_id) { +void SBBreakpointLocation::SetThreadID(lldb::tid_t thread_id) { LLDB_INSTRUMENT_VA(this, thread_id); BreakpointLocationSP loc_sp = GetSP(); @@ -313,10 +313,10 @@ void SBBreakpointLocation::SetThreadID(tid_t thread_id) { } } -tid_t SBBreakpointLocation::GetThreadID() { +lldb::tid_t SBBreakpointLocation::GetThreadID() { LLDB_INSTRUMENT_VA(this); - tid_t tid = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; BreakpointLocationSP loc_sp = GetSP(); if (loc_sp) { std::lock_guard guard( diff --git a/lldb/source/API/SBBreakpointName.cpp b/lldb/source/API/SBBreakpointName.cpp index 7f63aaf6fa7d5e..5c7c0a8f6504b0 100644 --- a/lldb/source/API/SBBreakpointName.cpp +++ b/lldb/source/API/SBBreakpointName.cpp @@ -347,7 +347,7 @@ bool SBBreakpointName::GetAutoContinue() { return bp_name->GetOptions().IsAutoContinue(); } -void SBBreakpointName::SetThreadID(tid_t tid) { +void SBBreakpointName::SetThreadID(lldb::tid_t tid) { LLDB_INSTRUMENT_VA(this, tid); BreakpointName *bp_name = GetBreakpointName(); @@ -361,7 +361,7 @@ void SBBreakpointName::SetThreadID(tid_t tid) { UpdateName(*bp_name); } -tid_t SBBreakpointName::GetThreadID() { +lldb::tid_t SBBreakpointName::GetThreadID() { LLDB_INSTRUMENT_VA(this); BreakpointName *bp_name = GetBreakpointName(); diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index 444e44b3928919..c1feec990f989d 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -130,7 +130,7 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx, /// Return the length in bytes of the set of operands for \p op. No guarantees /// are made on the state of \p data after this call. -static offset_t GetOpcodeDataSize(const DataExtractor &data, +static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op, const DWARFUnit *dwarf_cu) { lldb::offset_t offset = data_offset; @@ -358,7 +358,7 @@ lldb::addr_t D
[Lldb-commits] [lldb] [lldb][AIX] 1. Avoid namespace collision on other platforms (PR #104679)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/104679 >From e72ceaada170354aa322b4c6a1787152ac72c65b Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Sat, 17 Aug 2024 12:16:09 -0500 Subject: [PATCH 1/2] Using lldb's internal typedefs to avoid namespace collision 1. tid_t --> lldb::tid_t 2. offset_t --> lldb::ofset_t --- lldb/source/API/SBBreakpoint.cpp | 6 +++--- lldb/source/API/SBBreakpointLocation.cpp | 6 +++--- lldb/source/API/SBBreakpointName.cpp | 4 ++-- lldb/source/Expression/DWARFExpression.cpp | 10 +- lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp | 2 +- .../Darwin-Kernel/DynamicLoaderDarwinKernel.cpp| 4 ++-- .../MacOSX-DYLD/DynamicLoaderDarwin.cpp| 2 +- .../InstrumentationRuntimeMainThreadChecker.cpp| 2 +- .../TSan/InstrumentationRuntimeTSan.cpp| 14 +++--- .../UBSan/InstrumentationRuntimeUBSan.cpp | 2 +- .../MemoryHistory/asan/MemoryHistoryASan.cpp | 2 +- .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 6 +++--- .../Python/OperatingSystemPython.cpp | 2 +- .../Plugins/Process/Utility/ThreadMemory.cpp | 2 +- .../Process/gdb-remote/ProcessGDBRemote.cpp| 2 +- .../Plugins/Process/mach-core/ProcessMachCore.cpp | 8 lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp | 2 +- .../MacOSX/AppleGetThreadItemInfoHandler.cpp | 2 +- lldb/source/Symbol/DWARFCallFrameInfo.cpp | 4 ++-- 19 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index 3d908047f9455b..728fe04d14d927 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -342,7 +342,7 @@ uint32_t SBBreakpoint::GetIgnoreCount() const { return count; } -void SBBreakpoint::SetThreadID(tid_t tid) { +void SBBreakpoint::SetThreadID(lldb::tid_t tid) { LLDB_INSTRUMENT_VA(this, tid); BreakpointSP bkpt_sp = GetSP(); @@ -353,10 +353,10 @@ void SBBreakpoint::SetThreadID(tid_t tid) { } } -tid_t SBBreakpoint::GetThreadID() { +lldb::tid_t SBBreakpoint::GetThreadID() { LLDB_INSTRUMENT_VA(this); - tid_t tid = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; BreakpointSP bkpt_sp = GetSP(); if (bkpt_sp) { std::lock_guard guard( diff --git a/lldb/source/API/SBBreakpointLocation.cpp b/lldb/source/API/SBBreakpointLocation.cpp index 75b66364d4f1ae..fad9a4076a54fb 100644 --- a/lldb/source/API/SBBreakpointLocation.cpp +++ b/lldb/source/API/SBBreakpointLocation.cpp @@ -302,7 +302,7 @@ bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) { return has_commands; } -void SBBreakpointLocation::SetThreadID(tid_t thread_id) { +void SBBreakpointLocation::SetThreadID(lldb::tid_t thread_id) { LLDB_INSTRUMENT_VA(this, thread_id); BreakpointLocationSP loc_sp = GetSP(); @@ -313,10 +313,10 @@ void SBBreakpointLocation::SetThreadID(tid_t thread_id) { } } -tid_t SBBreakpointLocation::GetThreadID() { +lldb::tid_t SBBreakpointLocation::GetThreadID() { LLDB_INSTRUMENT_VA(this); - tid_t tid = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; BreakpointLocationSP loc_sp = GetSP(); if (loc_sp) { std::lock_guard guard( diff --git a/lldb/source/API/SBBreakpointName.cpp b/lldb/source/API/SBBreakpointName.cpp index 7f63aaf6fa7d5e..5c7c0a8f6504b0 100644 --- a/lldb/source/API/SBBreakpointName.cpp +++ b/lldb/source/API/SBBreakpointName.cpp @@ -347,7 +347,7 @@ bool SBBreakpointName::GetAutoContinue() { return bp_name->GetOptions().IsAutoContinue(); } -void SBBreakpointName::SetThreadID(tid_t tid) { +void SBBreakpointName::SetThreadID(lldb::tid_t tid) { LLDB_INSTRUMENT_VA(this, tid); BreakpointName *bp_name = GetBreakpointName(); @@ -361,7 +361,7 @@ void SBBreakpointName::SetThreadID(tid_t tid) { UpdateName(*bp_name); } -tid_t SBBreakpointName::GetThreadID() { +lldb::tid_t SBBreakpointName::GetThreadID() { LLDB_INSTRUMENT_VA(this); BreakpointName *bp_name = GetBreakpointName(); diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index 444e44b3928919..c1feec990f989d 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -130,7 +130,7 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx, /// Return the length in bytes of the set of operands for \p op. No guarantees /// are made on the state of \p data after this call. -static offset_t GetOpcodeDataSize(const DataExtractor &data, +static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op, const DWARFUnit *dwarf_cu) { lldb::offset_t offset = data_offset; @@ -358,7 +358,7 @@ lldb::add
[Lldb-commits] [lldb] [lldb][AIX] 1. Avoid namespace collision on other platforms (PR #104679)
DhruvSrivastavaX wrote: Great!! Yes, I have turned off private email addresses now. Just a general question. Is it a one time thing or it is advisable to keep it off in future as well? https://github.com/llvm/llvm-project/pull/104679 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] 1. Avoid namespace collision on other platforms (PR #104679)
DhruvSrivastavaX wrote: Hey David, The code format test passed but, I see some new failures (mostly in lldb-api and some in lldb-shell), which were not there in the previous run. Could it be because my branch is not up to date? How can I avoid such failures for future PRs? https://github.com/llvm/llvm-project/pull/104679 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] 1. Avoid namespace collision on other platforms (PR #104679)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/104679 >From e72ceaada170354aa322b4c6a1787152ac72c65b Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Sat, 17 Aug 2024 12:16:09 -0500 Subject: [PATCH 1/2] Using lldb's internal typedefs to avoid namespace collision 1. tid_t --> lldb::tid_t 2. offset_t --> lldb::ofset_t --- lldb/source/API/SBBreakpoint.cpp | 6 +++--- lldb/source/API/SBBreakpointLocation.cpp | 6 +++--- lldb/source/API/SBBreakpointName.cpp | 4 ++-- lldb/source/Expression/DWARFExpression.cpp | 10 +- lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp | 2 +- .../Darwin-Kernel/DynamicLoaderDarwinKernel.cpp| 4 ++-- .../MacOSX-DYLD/DynamicLoaderDarwin.cpp| 2 +- .../InstrumentationRuntimeMainThreadChecker.cpp| 2 +- .../TSan/InstrumentationRuntimeTSan.cpp| 14 +++--- .../UBSan/InstrumentationRuntimeUBSan.cpp | 2 +- .../MemoryHistory/asan/MemoryHistoryASan.cpp | 2 +- .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 6 +++--- .../Python/OperatingSystemPython.cpp | 2 +- .../Plugins/Process/Utility/ThreadMemory.cpp | 2 +- .../Process/gdb-remote/ProcessGDBRemote.cpp| 2 +- .../Plugins/Process/mach-core/ProcessMachCore.cpp | 8 lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp | 2 +- .../MacOSX/AppleGetThreadItemInfoHandler.cpp | 2 +- lldb/source/Symbol/DWARFCallFrameInfo.cpp | 4 ++-- 19 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index 3d908047f9455b..728fe04d14d927 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -342,7 +342,7 @@ uint32_t SBBreakpoint::GetIgnoreCount() const { return count; } -void SBBreakpoint::SetThreadID(tid_t tid) { +void SBBreakpoint::SetThreadID(lldb::tid_t tid) { LLDB_INSTRUMENT_VA(this, tid); BreakpointSP bkpt_sp = GetSP(); @@ -353,10 +353,10 @@ void SBBreakpoint::SetThreadID(tid_t tid) { } } -tid_t SBBreakpoint::GetThreadID() { +lldb::tid_t SBBreakpoint::GetThreadID() { LLDB_INSTRUMENT_VA(this); - tid_t tid = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; BreakpointSP bkpt_sp = GetSP(); if (bkpt_sp) { std::lock_guard guard( diff --git a/lldb/source/API/SBBreakpointLocation.cpp b/lldb/source/API/SBBreakpointLocation.cpp index 75b66364d4f1ae..fad9a4076a54fb 100644 --- a/lldb/source/API/SBBreakpointLocation.cpp +++ b/lldb/source/API/SBBreakpointLocation.cpp @@ -302,7 +302,7 @@ bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) { return has_commands; } -void SBBreakpointLocation::SetThreadID(tid_t thread_id) { +void SBBreakpointLocation::SetThreadID(lldb::tid_t thread_id) { LLDB_INSTRUMENT_VA(this, thread_id); BreakpointLocationSP loc_sp = GetSP(); @@ -313,10 +313,10 @@ void SBBreakpointLocation::SetThreadID(tid_t thread_id) { } } -tid_t SBBreakpointLocation::GetThreadID() { +lldb::tid_t SBBreakpointLocation::GetThreadID() { LLDB_INSTRUMENT_VA(this); - tid_t tid = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; BreakpointLocationSP loc_sp = GetSP(); if (loc_sp) { std::lock_guard guard( diff --git a/lldb/source/API/SBBreakpointName.cpp b/lldb/source/API/SBBreakpointName.cpp index 7f63aaf6fa7d5e..5c7c0a8f6504b0 100644 --- a/lldb/source/API/SBBreakpointName.cpp +++ b/lldb/source/API/SBBreakpointName.cpp @@ -347,7 +347,7 @@ bool SBBreakpointName::GetAutoContinue() { return bp_name->GetOptions().IsAutoContinue(); } -void SBBreakpointName::SetThreadID(tid_t tid) { +void SBBreakpointName::SetThreadID(lldb::tid_t tid) { LLDB_INSTRUMENT_VA(this, tid); BreakpointName *bp_name = GetBreakpointName(); @@ -361,7 +361,7 @@ void SBBreakpointName::SetThreadID(tid_t tid) { UpdateName(*bp_name); } -tid_t SBBreakpointName::GetThreadID() { +lldb::tid_t SBBreakpointName::GetThreadID() { LLDB_INSTRUMENT_VA(this); BreakpointName *bp_name = GetBreakpointName(); diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index 444e44b3928919..c1feec990f989d 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -130,7 +130,7 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx, /// Return the length in bytes of the set of operands for \p op. No guarantees /// are made on the state of \p data after this call. -static offset_t GetOpcodeDataSize(const DataExtractor &data, +static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op, const DWARFUnit *dwarf_cu) { lldb::offset_t offset = data_offset; @@ -358,7 +358,7 @@ lldb::add
[Lldb-commits] [lldb] [lldb][AIX] 1. Avoid namespace collision on other platforms (PR #104679)
DhruvSrivastavaX wrote: Ok thats a relief to hear. > Not sure if you mean in the GitHub CI or locally Yes I was referring to the Github CI right now. Great, The first PR is happily merged. Thanks alot for all of the help and inputs!! We can now get started with the rest of the PRs since I got some clarity now. https://github.com/llvm/llvm-project/pull/104679 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][aix] 2. Updating XCOFF, PPC entry in LLDB ArchSpec (PR #105507)
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/105507 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. #101657 The complete changes for porting are present in this draft PR: https://github.com/llvm/llvm-project/pull/102601 The changes in this PR are intended to update the Architecture entry for LLDB with XCOFF,PPC. 1. Added a new `ArchDefinitionEntry g_xcoff_arch_entries[]` 2. Added a new case for XCOFF in `ArchSpec::SetArchitecture(..)` 3. Updated ArchDefinition *g_arch_definitions[] >From 53e2a7bffaad8a6813fdc5422805d332fdee86fa Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Wed, 21 Aug 2024 06:37:30 -0500 Subject: [PATCH 1/2] Updating XCOFF architecture lookup in LLDB --- lldb/source/Utility/ArchSpec.cpp | 20 +++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp index 07ef435ef451d2..38b403408e38fd 100644 --- a/lldb/source/Utility/ArchSpec.cpp +++ b/lldb/source/Utility/ArchSpec.cpp @@ -14,6 +14,7 @@ #include "lldb/lldb-defines.h" #include "llvm/ADT/STLExtras.h" #include "llvm/BinaryFormat/COFF.h" +#include "llvm/BinaryFormat/XCOFF.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/Compiler.h" @@ -459,10 +460,24 @@ static const ArchDefinition g_coff_arch_def = { "pe-coff", }; + +static const ArchDefinitionEntry g_xcoff_arch_entries[] = { +{ArchSpec::eCore_ppc_generic, llvm::XCOFF::TCPU_COM, LLDB_INVALID_CPUTYPE, 0xu, 0xu}, +{ArchSpec::eCore_ppc64_generic, llvm::XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE, 0xu, 0xu} +}; + +static const ArchDefinition g_xcoff_arch_def = { +eArchTypeXCOFF, +std::size(g_xcoff_arch_entries), +g_xcoff_arch_entries, +"xcoff", +}; + + //===--===// // Table of all ArchDefinitions static const ArchDefinition *g_arch_definitions[] = { -&g_macho_arch_def, &g_elf_arch_def, &g_coff_arch_def}; +&g_macho_arch_def, &g_elf_arch_def, &g_coff_arch_def, &g_xcoff_arch_def}; //===--===// // Static helper functions. @@ -903,6 +918,9 @@ bool ArchSpec::SetArchitecture(ArchitectureType arch_type, uint32_t cpu, } else if (arch_type == eArchTypeCOFF && os == llvm::Triple::Win32) { m_triple.setVendor(llvm::Triple::PC); m_triple.setOS(llvm::Triple::Win32); +} else if (arch_type == eArchTypeXCOFF && os == llvm::Triple::AIX) { +m_triple.setVendor(llvm::Triple::IBM); +m_triple.setOS(llvm::Triple::AIX); } else { m_triple.setVendor(llvm::Triple::UnknownVendor); m_triple.setOS(llvm::Triple::UnknownOS); >From f9b94258b175fe24b3f7612d785155566ed5d270 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Wed, 21 Aug 2024 06:46:36 -0500 Subject: [PATCH 2/2] clang-format modifications --- lldb/source/Utility/ArchSpec.cpp | 15 +++ 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp index 38b403408e38fd..4fd1a800023ce3 100644 --- a/lldb/source/Utility/ArchSpec.cpp +++ b/lldb/source/Utility/ArchSpec.cpp @@ -14,9 +14,9 @@ #include "lldb/lldb-defines.h" #include "llvm/ADT/STLExtras.h" #include "llvm/BinaryFormat/COFF.h" -#include "llvm/BinaryFormat/XCOFF.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/BinaryFormat/MachO.h" +#include "llvm/BinaryFormat/XCOFF.h" #include "llvm/Support/Compiler.h" #include "llvm/TargetParser/ARMTargetParser.h" @@ -460,11 +460,11 @@ static const ArchDefinition g_coff_arch_def = { "pe-coff", }; - static const ArchDefinitionEntry g_xcoff_arch_entries[] = { -{ArchSpec::eCore_ppc_generic, llvm::XCOFF::TCPU_COM, LLDB_INVALID_CPUTYPE, 0xu, 0xu}, -{ArchSpec::eCore_ppc64_generic, llvm::XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE, 0xu, 0xu} -}; +{ArchSpec::eCore_ppc_generic, llvm::XCOFF::TCPU_COM, LLDB_INVALID_CPUTYPE, + 0xu, 0xu}, +{ArchSpec::eCore_ppc64_generic, llvm::XCOFF::TCPU_PPC64, + LLDB_INVALID_CPUTYPE, 0xu, 0xu}}; static const ArchDefinition g_xcoff_arch_def = { eArchTypeXCOFF, @@ -473,7 +473,6 @@ static const ArchDefinition g_xcoff_arch_def = { "xcoff", }; - //===--===// // Table of all ArchDefinitions static const ArchDefinition *g_arch_definitions[] = { @@ -919,8 +918,8 @@ bool ArchSpec::SetArchitecture(ArchitectureType arch_type, uint32_t cpu, m_triple.setVendor(llvm::Triple::PC); m_triple.setOS(llvm::Triple::Win32); } else if (arch_type == eArc
[Lldb-commits] [lldb] [lldb][aix] 2. Updating XCOFF, PPC entry in LLDB ArchSpec (PR #105507)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/105507 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][aix] 2. Updating XCOFF, PPC entry in LLDB ArchSpec (PR #105507)
https://github.com/DhruvSrivastavaX closed https://github.com/llvm/llvm-project/pull/105507 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][aix] 2. Updating XCOFF, PPC entry in LLDB ArchSpec (PR #105523)
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/105523 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. #101657 The complete changes for porting are present in this draft PR: #102601 The changes in this PR are intended to update the Architecture entry for LLDB with XCOFF,PPC. 1. Added new ArchitectureType `eArchTypeXCOFF` 2. Added a new `ArchDefinitionEntry g_xcoff_arch_entries[]` 3. Added a new case for `XCOFF in ArchSpec::SetArchitecture(..)` 4. Updated `ArchDefinition *g_arch_definitions[]` >From 53e2a7bffaad8a6813fdc5422805d332fdee86fa Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Wed, 21 Aug 2024 06:37:30 -0500 Subject: [PATCH 1/3] Updating XCOFF architecture lookup in LLDB --- lldb/source/Utility/ArchSpec.cpp | 20 +++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp index 07ef435ef451d2..38b403408e38fd 100644 --- a/lldb/source/Utility/ArchSpec.cpp +++ b/lldb/source/Utility/ArchSpec.cpp @@ -14,6 +14,7 @@ #include "lldb/lldb-defines.h" #include "llvm/ADT/STLExtras.h" #include "llvm/BinaryFormat/COFF.h" +#include "llvm/BinaryFormat/XCOFF.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/Compiler.h" @@ -459,10 +460,24 @@ static const ArchDefinition g_coff_arch_def = { "pe-coff", }; + +static const ArchDefinitionEntry g_xcoff_arch_entries[] = { +{ArchSpec::eCore_ppc_generic, llvm::XCOFF::TCPU_COM, LLDB_INVALID_CPUTYPE, 0xu, 0xu}, +{ArchSpec::eCore_ppc64_generic, llvm::XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE, 0xu, 0xu} +}; + +static const ArchDefinition g_xcoff_arch_def = { +eArchTypeXCOFF, +std::size(g_xcoff_arch_entries), +g_xcoff_arch_entries, +"xcoff", +}; + + //===--===// // Table of all ArchDefinitions static const ArchDefinition *g_arch_definitions[] = { -&g_macho_arch_def, &g_elf_arch_def, &g_coff_arch_def}; +&g_macho_arch_def, &g_elf_arch_def, &g_coff_arch_def, &g_xcoff_arch_def}; //===--===// // Static helper functions. @@ -903,6 +918,9 @@ bool ArchSpec::SetArchitecture(ArchitectureType arch_type, uint32_t cpu, } else if (arch_type == eArchTypeCOFF && os == llvm::Triple::Win32) { m_triple.setVendor(llvm::Triple::PC); m_triple.setOS(llvm::Triple::Win32); +} else if (arch_type == eArchTypeXCOFF && os == llvm::Triple::AIX) { +m_triple.setVendor(llvm::Triple::IBM); +m_triple.setOS(llvm::Triple::AIX); } else { m_triple.setVendor(llvm::Triple::UnknownVendor); m_triple.setOS(llvm::Triple::UnknownOS); >From f9b94258b175fe24b3f7612d785155566ed5d270 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Wed, 21 Aug 2024 06:46:36 -0500 Subject: [PATCH 2/3] clang-format modifications --- lldb/source/Utility/ArchSpec.cpp | 15 +++ 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp index 38b403408e38fd..4fd1a800023ce3 100644 --- a/lldb/source/Utility/ArchSpec.cpp +++ b/lldb/source/Utility/ArchSpec.cpp @@ -14,9 +14,9 @@ #include "lldb/lldb-defines.h" #include "llvm/ADT/STLExtras.h" #include "llvm/BinaryFormat/COFF.h" -#include "llvm/BinaryFormat/XCOFF.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/BinaryFormat/MachO.h" +#include "llvm/BinaryFormat/XCOFF.h" #include "llvm/Support/Compiler.h" #include "llvm/TargetParser/ARMTargetParser.h" @@ -460,11 +460,11 @@ static const ArchDefinition g_coff_arch_def = { "pe-coff", }; - static const ArchDefinitionEntry g_xcoff_arch_entries[] = { -{ArchSpec::eCore_ppc_generic, llvm::XCOFF::TCPU_COM, LLDB_INVALID_CPUTYPE, 0xu, 0xu}, -{ArchSpec::eCore_ppc64_generic, llvm::XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE, 0xu, 0xu} -}; +{ArchSpec::eCore_ppc_generic, llvm::XCOFF::TCPU_COM, LLDB_INVALID_CPUTYPE, + 0xu, 0xu}, +{ArchSpec::eCore_ppc64_generic, llvm::XCOFF::TCPU_PPC64, + LLDB_INVALID_CPUTYPE, 0xu, 0xu}}; static const ArchDefinition g_xcoff_arch_def = { eArchTypeXCOFF, @@ -473,7 +473,6 @@ static const ArchDefinition g_xcoff_arch_def = { "xcoff", }; - //===--===// // Table of all ArchDefinitions static const ArchDefinition *g_arch_definitions[] = { @@ -919,8 +918,8 @@ bool ArchSpec::SetArchitecture(ArchitectureType arch_type, uint32_t cpu, m_triple.setVendor(llvm::Triple::PC); m_triple.setOS(llvm::Triple::Win32); } else if (arch_typ
[Lldb-commits] [lldb] [lldb][aix] Updating XCOFF, PPC entry in LLDB ArchSpec (PR #105523)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/105523 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][aix] Updating XCOFF, PPC entry in LLDB ArchSpec (PR #105523)
DhruvSrivastavaX wrote: Ok Alex, Thanks for approving. https://github.com/llvm/llvm-project/pull/105523 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/106910 >From bf64f6ebf0e1b92c9a29b07adc4f5502e629c7cd Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Sun, 1 Sep 2024 09:26:34 -0500 Subject: [PATCH 1/2] Taking Linux Host Info base for AIX --- lldb/CMakeLists.txt | 6 +++ lldb/include/lldb/Host/HostGetOpt.h | 2 +- lldb/include/lldb/Host/HostInfo.h | 3 ++ lldb/include/lldb/Host/aix/AbstractSocket.h | 25 + lldb/include/lldb/Host/aix/Host.h | 22 lldb/include/lldb/Host/aix/HostInfoAIX.h| 43 +++ lldb/include/lldb/Host/aix/Ptrace.h | 60 + lldb/include/lldb/Host/aix/Support.h| 29 ++ lldb/include/lldb/Host/aix/Uio.h| 23 lldb/include/lldb/Host/common/GetOptInc.h | 4 +- 10 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 lldb/include/lldb/Host/aix/AbstractSocket.h create mode 100644 lldb/include/lldb/Host/aix/Host.h create mode 100644 lldb/include/lldb/Host/aix/HostInfoAIX.h create mode 100644 lldb/include/lldb/Host/aix/Ptrace.h create mode 100644 lldb/include/lldb/Host/aix/Support.h create mode 100644 lldb/include/lldb/Host/aix/Uio.h diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt index 59cdc4593463c1..f78b7619695c21 100644 --- a/lldb/CMakeLists.txt +++ b/lldb/CMakeLists.txt @@ -38,6 +38,12 @@ endif() include(LLDBConfig) include(AddLLDB) +# This has been added to keep the AIX build isolated for now. +# It will need to be modified later. +if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + add_definitions("-D__AIX__") +endif() + # Define the LLDB_CONFIGURATION_xxx matching the build type. if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) add_definitions(-DLLDB_CONFIGURATION_DEBUG) diff --git a/lldb/include/lldb/Host/HostGetOpt.h b/lldb/include/lldb/Host/HostGetOpt.h index 52cfdf4dbb89c2..f450e561d6afb1 100644 --- a/lldb/include/lldb/Host/HostGetOpt.h +++ b/lldb/include/lldb/Host/HostGetOpt.h @@ -9,7 +9,7 @@ #ifndef LLDB_HOST_HOSTGETOPT_H #define LLDB_HOST_HOSTGETOPT_H -#if !defined(_MSC_VER) && !defined(__NetBSD__) +#if !defined(_MSC_VER) && !defined(__NetBSD__) && !defined(__AIX__) #include #include diff --git a/lldb/include/lldb/Host/HostInfo.h b/lldb/include/lldb/Host/HostInfo.h index b7010d69d88e7f..156df8cf6901df 100644 --- a/lldb/include/lldb/Host/HostInfo.h +++ b/lldb/include/lldb/Host/HostInfo.h @@ -55,6 +55,9 @@ #elif defined(__APPLE__) #include "lldb/Host/macosx/HostInfoMacOSX.h" #define HOST_INFO_TYPE HostInfoMacOSX +#elif defined(__AIX__) +#include "lldb/Host/aix/HostInfoAIX.h" +#define HOST_INFO_TYPE HostInfoAIX #else #include "lldb/Host/posix/HostInfoPosix.h" #define HOST_INFO_TYPE HostInfoPosix diff --git a/lldb/include/lldb/Host/aix/AbstractSocket.h b/lldb/include/lldb/Host/aix/AbstractSocket.h new file mode 100644 index 00..78a567a6b90953 --- /dev/null +++ b/lldb/include/lldb/Host/aix/AbstractSocket.h @@ -0,0 +1,25 @@ +//===-- AbstractSocket.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 liblldb_AbstractSocket_h_ +#define liblldb_AbstractSocket_h_ + +#include "lldb/Host/posix/DomainSocket.h" + +namespace lldb_private { +class AbstractSocket : public DomainSocket { +public: + AbstractSocket(bool child_processes_inherit); + +protected: + size_t GetNameOffset() const override; + void DeleteSocketFile(llvm::StringRef name) override; +}; +} + +#endif // ifndef liblldb_AbstractSocket_h_ diff --git a/lldb/include/lldb/Host/aix/Host.h b/lldb/include/lldb/Host/aix/Host.h new file mode 100644 index 00..ef1e74cd1d501b --- /dev/null +++ b/lldb/include/lldb/Host/aix/Host.h @@ -0,0 +1,22 @@ +//===-- Host.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_HOST_LINUX_HOST_H +#define LLDB_HOST_LINUX_HOST_H + +#include "lldb/lldb-types.h" +#include + +namespace lldb_private { + +// Get PID (i.e. the primary thread ID) corresponding to the specified TID. +std::optional getPIDForTID(lldb::pid_t tid); + +} // namespace lldb_private + +#endif // #ifndef LLDB_HOST_LINUX_HOST_H diff --git a/lldb/include/lldb/Host/aix/HostInfoAIX.h b/lldb/include/lldb/Host/aix/HostInfoAIX.h new file mode 100644 index 00..2964f3f1dc9893 --- /dev/null +++ b/lldb/include/lldb/Host/aix/HostInfoAIX.h @
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/106910 This PR is in reference to porting LLDB on AIX. Link to discussions on llvm discourse and github: https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640 #101657 The complete changes for porting are present in this draft PR: #102601 Taking Base code for Host Info header files from Linux, and setting up header files for AIX Host Info. 1. Added definition `-D__AIX__` 2. Setup header files for AIX Host Info as boilerplate. >From bf64f6ebf0e1b92c9a29b07adc4f5502e629c7cd Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Sun, 1 Sep 2024 09:26:34 -0500 Subject: [PATCH] Taking Linux Host Info base for AIX --- lldb/CMakeLists.txt | 6 +++ lldb/include/lldb/Host/HostGetOpt.h | 2 +- lldb/include/lldb/Host/HostInfo.h | 3 ++ lldb/include/lldb/Host/aix/AbstractSocket.h | 25 + lldb/include/lldb/Host/aix/Host.h | 22 lldb/include/lldb/Host/aix/HostInfoAIX.h| 43 +++ lldb/include/lldb/Host/aix/Ptrace.h | 60 + lldb/include/lldb/Host/aix/Support.h| 29 ++ lldb/include/lldb/Host/aix/Uio.h| 23 lldb/include/lldb/Host/common/GetOptInc.h | 4 +- 10 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 lldb/include/lldb/Host/aix/AbstractSocket.h create mode 100644 lldb/include/lldb/Host/aix/Host.h create mode 100644 lldb/include/lldb/Host/aix/HostInfoAIX.h create mode 100644 lldb/include/lldb/Host/aix/Ptrace.h create mode 100644 lldb/include/lldb/Host/aix/Support.h create mode 100644 lldb/include/lldb/Host/aix/Uio.h diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt index 59cdc4593463c1..f78b7619695c21 100644 --- a/lldb/CMakeLists.txt +++ b/lldb/CMakeLists.txt @@ -38,6 +38,12 @@ endif() include(LLDBConfig) include(AddLLDB) +# This has been added to keep the AIX build isolated for now. +# It will need to be modified later. +if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + add_definitions("-D__AIX__") +endif() + # Define the LLDB_CONFIGURATION_xxx matching the build type. if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) add_definitions(-DLLDB_CONFIGURATION_DEBUG) diff --git a/lldb/include/lldb/Host/HostGetOpt.h b/lldb/include/lldb/Host/HostGetOpt.h index 52cfdf4dbb89c2..f450e561d6afb1 100644 --- a/lldb/include/lldb/Host/HostGetOpt.h +++ b/lldb/include/lldb/Host/HostGetOpt.h @@ -9,7 +9,7 @@ #ifndef LLDB_HOST_HOSTGETOPT_H #define LLDB_HOST_HOSTGETOPT_H -#if !defined(_MSC_VER) && !defined(__NetBSD__) +#if !defined(_MSC_VER) && !defined(__NetBSD__) && !defined(__AIX__) #include #include diff --git a/lldb/include/lldb/Host/HostInfo.h b/lldb/include/lldb/Host/HostInfo.h index b7010d69d88e7f..156df8cf6901df 100644 --- a/lldb/include/lldb/Host/HostInfo.h +++ b/lldb/include/lldb/Host/HostInfo.h @@ -55,6 +55,9 @@ #elif defined(__APPLE__) #include "lldb/Host/macosx/HostInfoMacOSX.h" #define HOST_INFO_TYPE HostInfoMacOSX +#elif defined(__AIX__) +#include "lldb/Host/aix/HostInfoAIX.h" +#define HOST_INFO_TYPE HostInfoAIX #else #include "lldb/Host/posix/HostInfoPosix.h" #define HOST_INFO_TYPE HostInfoPosix diff --git a/lldb/include/lldb/Host/aix/AbstractSocket.h b/lldb/include/lldb/Host/aix/AbstractSocket.h new file mode 100644 index 00..78a567a6b90953 --- /dev/null +++ b/lldb/include/lldb/Host/aix/AbstractSocket.h @@ -0,0 +1,25 @@ +//===-- AbstractSocket.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 liblldb_AbstractSocket_h_ +#define liblldb_AbstractSocket_h_ + +#include "lldb/Host/posix/DomainSocket.h" + +namespace lldb_private { +class AbstractSocket : public DomainSocket { +public: + AbstractSocket(bool child_processes_inherit); + +protected: + size_t GetNameOffset() const override; + void DeleteSocketFile(llvm::StringRef name) override; +}; +} + +#endif // ifndef liblldb_AbstractSocket_h_ diff --git a/lldb/include/lldb/Host/aix/Host.h b/lldb/include/lldb/Host/aix/Host.h new file mode 100644 index 00..ef1e74cd1d501b --- /dev/null +++ b/lldb/include/lldb/Host/aix/Host.h @@ -0,0 +1,22 @@ +//===-- Host.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_HOST_LINUX_HOST_H +#define LLDB_HOST_LINUX_HOST_H + +#include "lldb/lldb-types.h" +#include + +namespace lldb_pri
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
DhruvSrivastavaX wrote: > So, how different is AIX from linux? Should we be treating it as a flavour of > linux. E.g., have HostInfoAIX derive from HostInfoLinux instead of copying it > ? AIX is UNIX based but its very different from Linux, so it cannot be treated as a flavour of Linux. For this PR, I have just added a boiler plate code from Linux, but the immediate next PR will be having AIX specific tweaks, as per community suggestions. Here is the whole code in a draft PR: #102601 https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
@@ -38,6 +38,12 @@ endif() include(LLDBConfig) include(AddLLDB) +# This has been added to keep the AIX build isolated for now. +# It will need to be modified later. +if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + add_definitions("-D__AIX__") DhruvSrivastavaX wrote: It would be really helpful, if we can decide on a better alternative. https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
@@ -38,6 +38,12 @@ endif() include(LLDBConfig) include(AddLLDB) +# This has been added to keep the AIX build isolated for now. +# It will need to be modified later. +if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + add_definitions("-D__AIX__") DhruvSrivastavaX wrote: At this point we are not aware of any predefined ones for AIX though. It would be great if the community can suggest something in this regard. We will also try to find some alternative accordingly. https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
DhruvSrivastavaX wrote: Thank you for your feedback; I understand the concern about potential code duplication. Indeed, components like `PlatformAIX, HostInfoAIX, and NativeProcess/Thread` do share significant similarities with their Linux counterparts. However, several other components, such as `ObjectFileXCOFF, the Big Archive container, and AIX-DYLD, `require more substantial changes due to platform-specific aspects like the AIX base object file formats, hardware architecture (PPC64), and other inherent differences. We've also had to exclude certain functionalities that aren't feasible on AIX at this stage. The main intentionn for our current approach is to isolate platform dependencies, thereby avoiding conditional directives like `#if AIX #else` within the common codebase. Even in the draft PR, our long-term goal is to minimize such conditionals wherever possible. That said, we've made every effort to keep the code as generic as possible, and we’re open to any further suggestions on how to improve this. It will help in refining the changes. https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
@@ -38,6 +38,12 @@ endif() include(LLDBConfig) include(AddLLDB) +# This has been added to keep the AIX build isolated for now. +# It will need to be modified later. +if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + add_definitions("-D__AIX__") DhruvSrivastavaX wrote: Ok Thats helpful 😄 I will give it go, trying to integrate it with the overall changes. Meanwhile, shall I remove `__AIX__` from this PR to keep that discussion separate? https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
DhruvSrivastavaX wrote: Ok sure. For readability and clarity, for the files having comparatively bigger changes, I can drop it as multiple commits in the same PR, so that the changes can be seen as cleanly as possible: 1. Commit 1 - copy paste the original 2. Commit 2 - Make AIX dependant changes And for each of these bigger files, we can have respective PRs as per your suggestion. And for the rest of the common files, another draft PR should be ok for the readability pov. It can be used as reference for the changes that will be dropped in future. One question though? For the comparatively smaller changes across multiple files, is it okay to club the in one PR if they are related? https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Taking Linux Host Info header's base for AIX (PR #106910)
DhruvSrivastavaX wrote: One more thing. For platform differentiating files/paths like HostInfoAIX future files like PlatformAIX, How do you suggest we add them? To keep the code path more streamlined, shall we keep their code under Linux with #if _AIX, Or shall we use some form of inheritance to keep AIX as its own platform? https://github.com/llvm/llvm-project/pull/106910 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/108000 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. #101657 The complete changes for porting are present in this draft PR: #102601 Added Ptrace extensions for AIX. - Commit 1: Taken Linux version for reference. - Commit 2: Modified the extensions for AIX. Review Request: @DavidSpickett >From 426874ab276182858b75e9bbf8704dab1742757c Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Tue, 10 Sep 2024 04:38:32 -0500 Subject: [PATCH 1/2] Ptrace code base for AIX --- lldb/include/lldb/Host/aix/Ptrace.h | 60 + 1 file changed, 60 insertions(+) create mode 100644 lldb/include/lldb/Host/aix/Ptrace.h diff --git a/lldb/include/lldb/Host/aix/Ptrace.h b/lldb/include/lldb/Host/aix/Ptrace.h new file mode 100644 index 00..aabd3fd4fc5573 --- /dev/null +++ b/lldb/include/lldb/Host/aix/Ptrace.h @@ -0,0 +1,60 @@ +//===-- Ptrace.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 +// +//===--===// + +// This file defines ptrace functions & structures + +#ifndef liblldb_Host_linux_Ptrace_h_ +#define liblldb_Host_linux_Ptrace_h_ + +#include + +#ifndef __GLIBC__ +typedef int __ptrace_request; +#endif + +#define DEBUG_PTRACE_MAXBYTES 20 + +// Support ptrace extensions even when compiled without required kernel support +#ifndef PTRACE_GETREGS +#define PTRACE_GETREGS 12 +#endif +#ifndef PTRACE_SETREGS +#define PTRACE_SETREGS 13 +#endif +#ifndef PTRACE_GETFPREGS +#define PTRACE_GETFPREGS 14 +#endif +#ifndef PTRACE_SETFPREGS +#define PTRACE_SETFPREGS 15 +#endif +#ifndef PTRACE_GETREGSET +#define PTRACE_GETREGSET 0x4204 +#endif +#ifndef PTRACE_SETREGSET +#define PTRACE_SETREGSET 0x4205 +#endif +#ifndef PTRACE_GET_THREAD_AREA +#define PTRACE_GET_THREAD_AREA 25 +#endif +#ifndef PTRACE_ARCH_PRCTL +#define PTRACE_ARCH_PRCTL 30 +#endif +#ifndef ARCH_GET_FS +#define ARCH_SET_GS 0x1001 +#define ARCH_SET_FS 0x1002 +#define ARCH_GET_FS 0x1003 +#define ARCH_GET_GS 0x1004 +#endif +#ifndef PTRACE_PEEKMTETAGS +#define PTRACE_PEEKMTETAGS 33 +#endif +#ifndef PTRACE_POKEMTETAGS +#define PTRACE_POKEMTETAGS 34 +#endif + +#endif // liblldb_Host_linux_Ptrace_h_ >From 61bdaf75ddbd5940af5f23363311ffcacb0540d7 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Tue, 10 Sep 2024 05:43:37 -0500 Subject: [PATCH 2/2] Modified specific to AIX --- lldb/include/lldb/Host/aix/Ptrace.h | 38 + 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/lldb/include/lldb/Host/aix/Ptrace.h b/lldb/include/lldb/Host/aix/Ptrace.h index aabd3fd4fc5573..5d5ae82c9dab7d 100644 --- a/lldb/include/lldb/Host/aix/Ptrace.h +++ b/lldb/include/lldb/Host/aix/Ptrace.h @@ -8,29 +8,25 @@ // This file defines ptrace functions & structures -#ifndef liblldb_Host_linux_Ptrace_h_ -#define liblldb_Host_linux_Ptrace_h_ +#ifndef liblldb_Host_aix_Ptrace_h_ +#define liblldb_Host_aix_Ptrace_h_ #include -#ifndef __GLIBC__ -typedef int __ptrace_request; -#endif - #define DEBUG_PTRACE_MAXBYTES 20 // Support ptrace extensions even when compiled without required kernel support #ifndef PTRACE_GETREGS -#define PTRACE_GETREGS 12 +#define PTRACE_GETREGS (PT_COMMAND_MAX + 1) #endif #ifndef PTRACE_SETREGS -#define PTRACE_SETREGS 13 +#define PTRACE_SETREGS (PT_COMMAND_MAX + 2) #endif #ifndef PTRACE_GETFPREGS -#define PTRACE_GETFPREGS 14 +#define PTRACE_GETFPREGS (PT_COMMAND_MAX + 3) #endif #ifndef PTRACE_SETFPREGS -#define PTRACE_SETFPREGS 15 +#define PTRACE_SETFPREGS (PT_COMMAND_MAX + 4) #endif #ifndef PTRACE_GETREGSET #define PTRACE_GETREGSET 0x4204 @@ -38,23 +34,11 @@ typedef int __ptrace_request; #ifndef PTRACE_SETREGSET #define PTRACE_SETREGSET 0x4205 #endif -#ifndef PTRACE_GET_THREAD_AREA -#define PTRACE_GET_THREAD_AREA 25 -#endif -#ifndef PTRACE_ARCH_PRCTL -#define PTRACE_ARCH_PRCTL 30 -#endif -#ifndef ARCH_GET_FS -#define ARCH_SET_GS 0x1001 -#define ARCH_SET_FS 0x1002 -#define ARCH_GET_FS 0x1003 -#define ARCH_GET_GS 0x1004 -#endif -#ifndef PTRACE_PEEKMTETAGS -#define PTRACE_PEEKMTETAGS 33 +#ifndef PTRACE_GETVRREGS +#define PTRACE_GETVRREGS (PT_COMMAND_MAX + 5) #endif -#ifndef PTRACE_POKEMTETAGS -#define PTRACE_POKEMTETAGS 34 +#ifndef PTRACE_GETVSRREGS +#define PTRACE_GETVSRREGS (PT_COMMAND_MAX + 6) #endif -#endif // liblldb_Host_linux_Ptrace_h_ +#endif // liblldb_Host_aix_Ptrace_h_ ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
DhruvSrivastavaX wrote: Glad to hear that! Sure that should be okay. I can proceed with the files which directly rely on this one for the next PRs, so that we can plan accordingly. https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
@@ -0,0 +1,44 @@ +//===-- Ptrace.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 +// +//===--===// + +// This file defines ptrace functions & structures + +#ifndef liblldb_Host_aix_Ptrace_h_ DhruvSrivastavaX wrote: Okay, Done! https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
@@ -0,0 +1,44 @@ +//===-- Ptrace.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 +// +//===--===// + +// This file defines ptrace functions & structures + +#ifndef liblldb_Host_aix_Ptrace_h_ +#define liblldb_Host_aix_Ptrace_h_ + +#include + +#define DEBUG_PTRACE_MAXBYTES 20 DhruvSrivastavaX wrote: To be specific, it is being used in the `NativeProcessLinux.cpp`. For our context, it is used similarly for `NativeProcessAIX.cpp`, utilised by `DisplayBytes(..)<--PtraceDisplayBytes(..)`. We can move it to the same file if you suggest so and in the same way as David suggested. https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
@@ -0,0 +1,44 @@ +//===-- Ptrace.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 +// +//===--===// + +// This file defines ptrace functions & structures + +#ifndef liblldb_Host_aix_Ptrace_h_ +#define liblldb_Host_aix_Ptrace_h_ + +#include + +#define DEBUG_PTRACE_MAXBYTES 20 + +// Support ptrace extensions even when compiled without required kernel support +#ifndef PTRACE_GETREGS +#define PTRACE_GETREGS (PT_COMMAND_MAX + 1) DhruvSrivastavaX wrote: > This PT_COMMAND_MAX is provided by some AIX include file, correct? > > If that's correct then using it like this is fine because PTrace.h is only > included in code built natively. > > Do you have public documentation for these ptrace numbers? Perhaps there is a > man page like https://man7.org/linux/man-pages/man2/ptrace.2.html? It would > be good to include a link to that in the PR description. Although it is defined in AIX's system header `sys/ptrace.h` , its not been mentioned in AIX public documentation. For other defines, here is the link though: https://www.ibm.com/docs/en/aix/7.2?topic=p-ptrace-ptracex-ptrace64-subroutine > ersions. If you're only going to support building lldb on AIX version >=X > (where `X` may even be the most recent version of the OS) then you only need > to provide the symbols that aren't available on every supported version. If > all the supported versions of AIX define these symbols, then you don't need > to define anything here (and maybe you don't even need this file). We are actually using these defines do some emulation in the NativeProcess files, hence the need for them. Please take a look here: https://github.com/llvm/llvm-project/pull/102601/files#diff-932a7c13bbba2ce92d14f75c525489f726af9e95f955df24b3f840727e9f757a https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
@@ -0,0 +1,44 @@ +//===-- Ptrace.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 +// +//===--===// + +// This file defines ptrace functions & structures + +#ifndef liblldb_Host_aix_Ptrace_h_ +#define liblldb_Host_aix_Ptrace_h_ + +#include + +#define DEBUG_PTRACE_MAXBYTES 20 + +// Support ptrace extensions even when compiled without required kernel support +#ifndef PTRACE_GETREGS +#define PTRACE_GETREGS (PT_COMMAND_MAX + 1) DhruvSrivastavaX wrote: Just pasting a small snippet from that here: line: 1755 ``` if (req == PTRACE_GETREGS) { GetRegister(pid, GPR0, &(((GPR *)data)->r0)); GetRegister(pid, GPR1, &(((GPR *)data)->r1)); GetRegister(pid, GPR2, &(((GPR *)data)->r2)); GetRegister(pid, GPR3, &(((GPR *)data)->r3)); GetRegister(pid, GPR4, &(((GPR *)data)->r4)); GetRegister(pid, GPR5, &(((GPR *)data)->r5)); GetRegister(pid, GPR6, &(((GPR *)data)->r6)); GetRegister(pid, GPR7, &(((GPR *)data)->r7)); GetRegister(pid, GPR8, &(((GPR *)data)->r8)); GetRegister(pid, GPR9, &(((GPR *)data)->r9)); GetRegister(pid, GPR10, &(((GPR *)data)->r10)); ``` https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
@@ -0,0 +1,44 @@ +//===-- Ptrace.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 +// +//===--===// + +// This file defines ptrace functions & structures + +#ifndef liblldb_Host_aix_Ptrace_h_ +#define liblldb_Host_aix_Ptrace_h_ + +#include + +#define DEBUG_PTRACE_MAXBYTES 20 DhruvSrivastavaX wrote: For now, I can define it with the given value in that file locally and use it, and going forward we can update/get it removed if that is a better alternative. https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/108000 >From 426874ab276182858b75e9bbf8704dab1742757c Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Tue, 10 Sep 2024 04:38:32 -0500 Subject: [PATCH 1/3] Ptrace code base for AIX --- lldb/include/lldb/Host/aix/Ptrace.h | 60 + 1 file changed, 60 insertions(+) create mode 100644 lldb/include/lldb/Host/aix/Ptrace.h diff --git a/lldb/include/lldb/Host/aix/Ptrace.h b/lldb/include/lldb/Host/aix/Ptrace.h new file mode 100644 index 00..aabd3fd4fc5573 --- /dev/null +++ b/lldb/include/lldb/Host/aix/Ptrace.h @@ -0,0 +1,60 @@ +//===-- Ptrace.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 +// +//===--===// + +// This file defines ptrace functions & structures + +#ifndef liblldb_Host_linux_Ptrace_h_ +#define liblldb_Host_linux_Ptrace_h_ + +#include + +#ifndef __GLIBC__ +typedef int __ptrace_request; +#endif + +#define DEBUG_PTRACE_MAXBYTES 20 + +// Support ptrace extensions even when compiled without required kernel support +#ifndef PTRACE_GETREGS +#define PTRACE_GETREGS 12 +#endif +#ifndef PTRACE_SETREGS +#define PTRACE_SETREGS 13 +#endif +#ifndef PTRACE_GETFPREGS +#define PTRACE_GETFPREGS 14 +#endif +#ifndef PTRACE_SETFPREGS +#define PTRACE_SETFPREGS 15 +#endif +#ifndef PTRACE_GETREGSET +#define PTRACE_GETREGSET 0x4204 +#endif +#ifndef PTRACE_SETREGSET +#define PTRACE_SETREGSET 0x4205 +#endif +#ifndef PTRACE_GET_THREAD_AREA +#define PTRACE_GET_THREAD_AREA 25 +#endif +#ifndef PTRACE_ARCH_PRCTL +#define PTRACE_ARCH_PRCTL 30 +#endif +#ifndef ARCH_GET_FS +#define ARCH_SET_GS 0x1001 +#define ARCH_SET_FS 0x1002 +#define ARCH_GET_FS 0x1003 +#define ARCH_GET_GS 0x1004 +#endif +#ifndef PTRACE_PEEKMTETAGS +#define PTRACE_PEEKMTETAGS 33 +#endif +#ifndef PTRACE_POKEMTETAGS +#define PTRACE_POKEMTETAGS 34 +#endif + +#endif // liblldb_Host_linux_Ptrace_h_ >From 61bdaf75ddbd5940af5f23363311ffcacb0540d7 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Tue, 10 Sep 2024 05:43:37 -0500 Subject: [PATCH 2/3] Modified specific to AIX --- lldb/include/lldb/Host/aix/Ptrace.h | 38 + 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/lldb/include/lldb/Host/aix/Ptrace.h b/lldb/include/lldb/Host/aix/Ptrace.h index aabd3fd4fc5573..5d5ae82c9dab7d 100644 --- a/lldb/include/lldb/Host/aix/Ptrace.h +++ b/lldb/include/lldb/Host/aix/Ptrace.h @@ -8,29 +8,25 @@ // This file defines ptrace functions & structures -#ifndef liblldb_Host_linux_Ptrace_h_ -#define liblldb_Host_linux_Ptrace_h_ +#ifndef liblldb_Host_aix_Ptrace_h_ +#define liblldb_Host_aix_Ptrace_h_ #include -#ifndef __GLIBC__ -typedef int __ptrace_request; -#endif - #define DEBUG_PTRACE_MAXBYTES 20 // Support ptrace extensions even when compiled without required kernel support #ifndef PTRACE_GETREGS -#define PTRACE_GETREGS 12 +#define PTRACE_GETREGS (PT_COMMAND_MAX + 1) #endif #ifndef PTRACE_SETREGS -#define PTRACE_SETREGS 13 +#define PTRACE_SETREGS (PT_COMMAND_MAX + 2) #endif #ifndef PTRACE_GETFPREGS -#define PTRACE_GETFPREGS 14 +#define PTRACE_GETFPREGS (PT_COMMAND_MAX + 3) #endif #ifndef PTRACE_SETFPREGS -#define PTRACE_SETFPREGS 15 +#define PTRACE_SETFPREGS (PT_COMMAND_MAX + 4) #endif #ifndef PTRACE_GETREGSET #define PTRACE_GETREGSET 0x4204 @@ -38,23 +34,11 @@ typedef int __ptrace_request; #ifndef PTRACE_SETREGSET #define PTRACE_SETREGSET 0x4205 #endif -#ifndef PTRACE_GET_THREAD_AREA -#define PTRACE_GET_THREAD_AREA 25 -#endif -#ifndef PTRACE_ARCH_PRCTL -#define PTRACE_ARCH_PRCTL 30 -#endif -#ifndef ARCH_GET_FS -#define ARCH_SET_GS 0x1001 -#define ARCH_SET_FS 0x1002 -#define ARCH_GET_FS 0x1003 -#define ARCH_GET_GS 0x1004 -#endif -#ifndef PTRACE_PEEKMTETAGS -#define PTRACE_PEEKMTETAGS 33 +#ifndef PTRACE_GETVRREGS +#define PTRACE_GETVRREGS (PT_COMMAND_MAX + 5) #endif -#ifndef PTRACE_POKEMTETAGS -#define PTRACE_POKEMTETAGS 34 +#ifndef PTRACE_GETVSRREGS +#define PTRACE_GETVSRREGS (PT_COMMAND_MAX + 6) #endif -#endif // liblldb_Host_linux_Ptrace_h_ +#endif // liblldb_Host_aix_Ptrace_h_ >From 1134b6fb81cedd75e447f42f788bb6d96351cdf3 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Tue, 10 Sep 2024 08:32:41 -0500 Subject: [PATCH 3/3] Addressed comments --- lldb/include/lldb/Host/aix/Ptrace.h | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lldb/include/lldb/Host/aix/Ptrace.h b/lldb/include/lldb/Host/aix/Ptrace.h index 5d5ae82c9dab7d..06678d1e1a2484 100644 --- a/lldb/include/lldb/Host/aix/Ptrace.h +++ b/lldb/include/lldb/Host/aix/Ptrace.h @@ -8,13 +8,11 @@ // This file defines ptrace functions & structures -#ifndef liblldb_Host_aix_Ptrace_h_ -#defi
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
@@ -0,0 +1,44 @@ +//===-- Ptrace.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 +// +//===--===// + +// This file defines ptrace functions & structures + +#ifndef liblldb_Host_aix_Ptrace_h_ +#define liblldb_Host_aix_Ptrace_h_ + +#include + +#define DEBUG_PTRACE_MAXBYTES 20 + +// Support ptrace extensions even when compiled without required kernel support +#ifndef PTRACE_GETREGS +#define PTRACE_GETREGS (PT_COMMAND_MAX + 1) DhruvSrivastavaX wrote: Okay, sure. I will try that implementation as well. https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
DhruvSrivastavaX wrote: > Given [#108000 > (comment)](https://github.com/llvm/llvm-project/pull/108000#discussion_r1752296507), > my feeling is that this file just should not (need not) exist. For now, I'd > suggest moving the header into NativeProcessAIX (that's the only place which > uses it, right?), and then we can figure out what to do with it when we get > to that. So based on this, shall I move this file in the same path as NativeProcessAIX path for now? https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
DhruvSrivastavaX wrote: > You can do that as a temporary fix so that we can move on to dealing with > other Host functionality. In the longer run I'll still most likely want to > get rid of those constants by doing something like I described in that > comment. Yes, agreed. If we do not need be keep the code strictly similar to Linux, that approach can be better. https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
DhruvSrivastavaX wrote: Okay sure. Thats not a problem Pavel, better to have it in smaller understandable pieces, so that it can be organised and reviewed properly. There are a couple of incoming code with such huge changes, it will be good to adhere to this systematic approach. So, I will go ahead and modify this PR to drop a smaller piece of ObjectFileXCOFF.h and ObjectFileXCOFF.cpp instead, which can be reviewed easily (some base skeleton and declaration of parent virtual functions etc). Once that gets pulled in, I will build my next few PRs on that in order to complete these new additions. Will also try to add relevant test cases. Thanks! https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/111814 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. #101657 The complete changes for porting are present in this draft PR: #102601 Added XCOFF Object File Header for AIX. Commit 1: Taken Linux version for reference. Commit 2: Modified the class and header for AIX. Details about XCOFF file format on AIX: [XCOFF](https://www.ibm.com/docs/en/aix/7.3?topic=formats-xcoff-object-file-format) Review Request: @DavidSpickett >From 08c9d5ae66ca857d165dc878ebd1b2e0de364a24 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Thu, 10 Oct 2024 02:24:42 -0500 Subject: [PATCH 1/3] Taking base file structure from ELF as reference --- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 440 ++ 1 file changed, 440 insertions(+) create mode 100644 lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h new file mode 100644 index 00..aba3a5bfcbf5b6 --- /dev/null +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h @@ -0,0 +1,440 @@ +//===-- ObjectFileELF.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_OBJECTFILE_ELF_OBJECTFILEELF_H +#define LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H + +#include + +#include +#include + +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/UUID.h" +#include "lldb/lldb-private.h" + +#include "ELFHeader.h" + +struct ELFNote { + elf::elf_word n_namesz = 0; + elf::elf_word n_descsz = 0; + elf::elf_word n_type = 0; + + std::string n_name; + + ELFNote() = default; + + /// Parse an ELFNote entry from the given DataExtractor starting at position + /// \p offset. + /// + /// \param[in] data + ///The DataExtractor to read from. + /// + /// \param[in,out] offset + ///Pointer to an offset in the data. On return the offset will be + ///advanced by the number of bytes read. + /// + /// \return + ///True if the ELFRel entry was successfully read and false otherwise. + bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset); + + size_t GetByteSize() const { +return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4); + } +}; + +/// \class ObjectFileELF +/// Generic ELF object file reader. +/// +/// This class provides a generic ELF (32/64 bit) reader plugin implementing +/// the ObjectFile protocol. +class ObjectFileELF : public lldb_private::ObjectFile { +public: + // Static Functions + static void Initialize(); + + static void Terminate(); + + static llvm::StringRef GetPluginNameStatic() { return "elf"; } + + static llvm::StringRef GetPluginDescriptionStatic() { +return "ELF object file reader."; + } + + static lldb_private::ObjectFile * + CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, + lldb::offset_t data_offset, const lldb_private::FileSpec *file, + lldb::offset_t file_offset, lldb::offset_t length); + + static lldb_private::ObjectFile *CreateMemoryInstance( + const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, + const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); + + static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, +lldb::DataBufferSP &data_sp, +lldb::offset_t data_offset, +lldb::offset_t file_offset, +lldb::offset_t length, +lldb_private::ModuleSpecList &specs); + + static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, + lldb::addr_t length); + + // PluginInterface protocol + llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } + + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { +return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + + // ObjectFile Protocol. + bool ParseHeader() override; + + bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, + bool value_is_offset) override; + + lldb::ByteOrder GetByteOrder() const override; + + bool IsExecutable() const override; + + uint32
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
DhruvSrivastavaX wrote: Hi Community Members, Apologies for being away for a while as I was occupied with some other activities. Here's some update at what all we are working on based on the past discussions: 1. Removed the CMAKE flag __AIX__ and replaced it with the LLVM environment's _AIX flag [**Done**] 2. We are working on merging some of the common files (like HostInfoAIX.cpp etc) derived from Linux while avoiding any major impact. 3. Working on creating a draft PR as suggested by @DavidSpickett , to highlight all the #if (_AIX) kind of code in the draft PR, to see the overall impact. 4. Implementing additional functionalities which are currently missing on AIX. 5. Rearranging some of the code in the draft PR based on the previous discussions. Going forward @Lakshmi-Surekha will also be assisting me in some of the upstreaming activities. Thanks & Regards https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
DhruvSrivastavaX wrote: > A couple of quick notes: > > * are you sure that ObjectFileELF is the best thing to start with here? Based > on the name, I would expect that ObjectFilePECOFF would be a better baseline. > Or maybe the object file format is different enough from all of the existing > ones that this kind of comparison is not useful? > * without also seeing the cpp file, it hard to judge how similar it is to the > other plugin > * instead of redeclaring all the header types, would it be possible to use > some structures from llvm? (I know that ObjectFileELF does not do that, but > that's because it is very old. ObjectFilePECOFF -- a much newer class -- does > just that) > * a lot of the object file code should be testable on its own. If you include > the necessary plugin glue in this PR, then you should be able to write tests > similar to those in `lldb/test/Shell/ObjectFile`. For example, if you could > start with a test similar to `test/Shell/ObjectFile/ELF/basic-info.yaml` and > then include enough of code in the PR to make that pass. Hi @labath , 1. Actually there might be slight similarities with ObjectFilePECOFF, but the overall format structure is very different to be compared to any one of the existing formats, so I have just taken the ObjectFileELF.h as a base to follow the general class/file arrangement. 2. As per our last discussion, I have planned to drop each of the major files separately, so I can push the .cpp file as another commit, and both of these can be used for comparison. 3. From a surface level I can see that ObjectFilePECOFF has also created its own new structures based on its file format, essentially we have done something similar for XCOFF. Although, let me check the existing llvm structures for XCOFF thoroughly and get back to you on this. 4. So, as per your suggestion, what path flow should we take? Based on previous discussions, as of now I am planning a commit for .h file, another commit for .cpp file and a final commit for the test cases. Is that okay? https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/111814 >From 08c9d5ae66ca857d165dc878ebd1b2e0de364a24 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Thu, 10 Oct 2024 02:24:42 -0500 Subject: [PATCH 1/4] Taking base file structure from ELF as reference --- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 440 ++ 1 file changed, 440 insertions(+) create mode 100644 lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h new file mode 100644 index 00..aba3a5bfcbf5b6 --- /dev/null +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h @@ -0,0 +1,440 @@ +//===-- ObjectFileELF.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_OBJECTFILE_ELF_OBJECTFILEELF_H +#define LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H + +#include + +#include +#include + +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/UUID.h" +#include "lldb/lldb-private.h" + +#include "ELFHeader.h" + +struct ELFNote { + elf::elf_word n_namesz = 0; + elf::elf_word n_descsz = 0; + elf::elf_word n_type = 0; + + std::string n_name; + + ELFNote() = default; + + /// Parse an ELFNote entry from the given DataExtractor starting at position + /// \p offset. + /// + /// \param[in] data + ///The DataExtractor to read from. + /// + /// \param[in,out] offset + ///Pointer to an offset in the data. On return the offset will be + ///advanced by the number of bytes read. + /// + /// \return + ///True if the ELFRel entry was successfully read and false otherwise. + bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset); + + size_t GetByteSize() const { +return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4); + } +}; + +/// \class ObjectFileELF +/// Generic ELF object file reader. +/// +/// This class provides a generic ELF (32/64 bit) reader plugin implementing +/// the ObjectFile protocol. +class ObjectFileELF : public lldb_private::ObjectFile { +public: + // Static Functions + static void Initialize(); + + static void Terminate(); + + static llvm::StringRef GetPluginNameStatic() { return "elf"; } + + static llvm::StringRef GetPluginDescriptionStatic() { +return "ELF object file reader."; + } + + static lldb_private::ObjectFile * + CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, + lldb::offset_t data_offset, const lldb_private::FileSpec *file, + lldb::offset_t file_offset, lldb::offset_t length); + + static lldb_private::ObjectFile *CreateMemoryInstance( + const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, + const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); + + static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, +lldb::DataBufferSP &data_sp, +lldb::offset_t data_offset, +lldb::offset_t file_offset, +lldb::offset_t length, +lldb_private::ModuleSpecList &specs); + + static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, + lldb::addr_t length); + + // PluginInterface protocol + llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } + + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { +return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + + // ObjectFile Protocol. + bool ParseHeader() override; + + bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, + bool value_is_offset) override; + + lldb::ByteOrder GetByteOrder() const override; + + bool IsExecutable() const override; + + uint32_t GetAddressByteSize() const override; + + lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override; + + void ParseSymtab(lldb_private::Symtab &symtab) override; + + bool IsStripped() override; + + void CreateSections(lldb_private::SectionList &unified_section_list) override; + + void Dump(lldb_private::Stream *s) override; + + lldb_private::ArchSpec GetArchitecture() override; + + lldb_private::UUID GetUUID() override; + + /// Return the contents of the .gnu_debuglink section, if the object file +
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/111814 >From 08c9d5ae66ca857d165dc878ebd1b2e0de364a24 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Thu, 10 Oct 2024 02:24:42 -0500 Subject: [PATCH 1/5] Taking base file structure from ELF as reference --- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 440 ++ 1 file changed, 440 insertions(+) create mode 100644 lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h new file mode 100644 index 00..aba3a5bfcbf5b6 --- /dev/null +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h @@ -0,0 +1,440 @@ +//===-- ObjectFileELF.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_OBJECTFILE_ELF_OBJECTFILEELF_H +#define LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H + +#include + +#include +#include + +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/UUID.h" +#include "lldb/lldb-private.h" + +#include "ELFHeader.h" + +struct ELFNote { + elf::elf_word n_namesz = 0; + elf::elf_word n_descsz = 0; + elf::elf_word n_type = 0; + + std::string n_name; + + ELFNote() = default; + + /// Parse an ELFNote entry from the given DataExtractor starting at position + /// \p offset. + /// + /// \param[in] data + ///The DataExtractor to read from. + /// + /// \param[in,out] offset + ///Pointer to an offset in the data. On return the offset will be + ///advanced by the number of bytes read. + /// + /// \return + ///True if the ELFRel entry was successfully read and false otherwise. + bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset); + + size_t GetByteSize() const { +return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4); + } +}; + +/// \class ObjectFileELF +/// Generic ELF object file reader. +/// +/// This class provides a generic ELF (32/64 bit) reader plugin implementing +/// the ObjectFile protocol. +class ObjectFileELF : public lldb_private::ObjectFile { +public: + // Static Functions + static void Initialize(); + + static void Terminate(); + + static llvm::StringRef GetPluginNameStatic() { return "elf"; } + + static llvm::StringRef GetPluginDescriptionStatic() { +return "ELF object file reader."; + } + + static lldb_private::ObjectFile * + CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, + lldb::offset_t data_offset, const lldb_private::FileSpec *file, + lldb::offset_t file_offset, lldb::offset_t length); + + static lldb_private::ObjectFile *CreateMemoryInstance( + const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, + const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); + + static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, +lldb::DataBufferSP &data_sp, +lldb::offset_t data_offset, +lldb::offset_t file_offset, +lldb::offset_t length, +lldb_private::ModuleSpecList &specs); + + static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, + lldb::addr_t length); + + // PluginInterface protocol + llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } + + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { +return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + + // ObjectFile Protocol. + bool ParseHeader() override; + + bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, + bool value_is_offset) override; + + lldb::ByteOrder GetByteOrder() const override; + + bool IsExecutable() const override; + + uint32_t GetAddressByteSize() const override; + + lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override; + + void ParseSymtab(lldb_private::Symtab &symtab) override; + + bool IsStripped() override; + + void CreateSections(lldb_private::SectionList &unified_section_list) override; + + void Dump(lldb_private::Stream *s) override; + + lldb_private::ArchSpec GetArchitecture() override; + + lldb_private::UUID GetUUID() override; + + /// Return the contents of the .gnu_debuglink section, if the object file +
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
DhruvSrivastavaX wrote: Hi @labath , I have dropped some base structure and yaml test cases for the ObjectFileXCOFF support. Please provide your comments. https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
DhruvSrivastavaX wrote: Ok right. Yes, and it is working fine on AIX. Let me get a little more familiar with lldb-test's working and I will try to figure out what's wrong. Thanks! https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
DhruvSrivastavaX wrote: Ok right. Yes, and it is working fine on AIX. Let me get a little more familiar with lldb-test's working and I will try to figure out what's wrong. Thanks! https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/111814 >From 08c9d5ae66ca857d165dc878ebd1b2e0de364a24 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Thu, 10 Oct 2024 02:24:42 -0500 Subject: [PATCH 1/7] Taking base file structure from ELF as reference --- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 440 ++ 1 file changed, 440 insertions(+) create mode 100644 lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h new file mode 100644 index 00..aba3a5bfcbf5b6 --- /dev/null +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h @@ -0,0 +1,440 @@ +//===-- ObjectFileELF.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_OBJECTFILE_ELF_OBJECTFILEELF_H +#define LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H + +#include + +#include +#include + +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/UUID.h" +#include "lldb/lldb-private.h" + +#include "ELFHeader.h" + +struct ELFNote { + elf::elf_word n_namesz = 0; + elf::elf_word n_descsz = 0; + elf::elf_word n_type = 0; + + std::string n_name; + + ELFNote() = default; + + /// Parse an ELFNote entry from the given DataExtractor starting at position + /// \p offset. + /// + /// \param[in] data + ///The DataExtractor to read from. + /// + /// \param[in,out] offset + ///Pointer to an offset in the data. On return the offset will be + ///advanced by the number of bytes read. + /// + /// \return + ///True if the ELFRel entry was successfully read and false otherwise. + bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset); + + size_t GetByteSize() const { +return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4); + } +}; + +/// \class ObjectFileELF +/// Generic ELF object file reader. +/// +/// This class provides a generic ELF (32/64 bit) reader plugin implementing +/// the ObjectFile protocol. +class ObjectFileELF : public lldb_private::ObjectFile { +public: + // Static Functions + static void Initialize(); + + static void Terminate(); + + static llvm::StringRef GetPluginNameStatic() { return "elf"; } + + static llvm::StringRef GetPluginDescriptionStatic() { +return "ELF object file reader."; + } + + static lldb_private::ObjectFile * + CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, + lldb::offset_t data_offset, const lldb_private::FileSpec *file, + lldb::offset_t file_offset, lldb::offset_t length); + + static lldb_private::ObjectFile *CreateMemoryInstance( + const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, + const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); + + static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, +lldb::DataBufferSP &data_sp, +lldb::offset_t data_offset, +lldb::offset_t file_offset, +lldb::offset_t length, +lldb_private::ModuleSpecList &specs); + + static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, + lldb::addr_t length); + + // PluginInterface protocol + llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } + + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { +return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + + // ObjectFile Protocol. + bool ParseHeader() override; + + bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, + bool value_is_offset) override; + + lldb::ByteOrder GetByteOrder() const override; + + bool IsExecutable() const override; + + uint32_t GetAddressByteSize() const override; + + lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override; + + void ParseSymtab(lldb_private::Symtab &symtab) override; + + bool IsStripped() override; + + void CreateSections(lldb_private::SectionList &unified_section_list) override; + + void Dump(lldb_private::Stream *s) override; + + lldb_private::ArchSpec GetArchitecture() override; + + lldb_private::UUID GetUUID() override; + + /// Return the contents of the .gnu_debuglink section, if the object file +
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
DhruvSrivastavaX wrote: Ok Sure, Got it. Will Proceed accordingly then. Thanks! https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/111814 >From 08c9d5ae66ca857d165dc878ebd1b2e0de364a24 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Thu, 10 Oct 2024 02:24:42 -0500 Subject: [PATCH 1/9] Taking base file structure from ELF as reference --- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 440 ++ 1 file changed, 440 insertions(+) create mode 100644 lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h new file mode 100644 index 00..aba3a5bfcbf5b6 --- /dev/null +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h @@ -0,0 +1,440 @@ +//===-- ObjectFileELF.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_OBJECTFILE_ELF_OBJECTFILEELF_H +#define LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H + +#include + +#include +#include + +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/UUID.h" +#include "lldb/lldb-private.h" + +#include "ELFHeader.h" + +struct ELFNote { + elf::elf_word n_namesz = 0; + elf::elf_word n_descsz = 0; + elf::elf_word n_type = 0; + + std::string n_name; + + ELFNote() = default; + + /// Parse an ELFNote entry from the given DataExtractor starting at position + /// \p offset. + /// + /// \param[in] data + ///The DataExtractor to read from. + /// + /// \param[in,out] offset + ///Pointer to an offset in the data. On return the offset will be + ///advanced by the number of bytes read. + /// + /// \return + ///True if the ELFRel entry was successfully read and false otherwise. + bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset); + + size_t GetByteSize() const { +return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4); + } +}; + +/// \class ObjectFileELF +/// Generic ELF object file reader. +/// +/// This class provides a generic ELF (32/64 bit) reader plugin implementing +/// the ObjectFile protocol. +class ObjectFileELF : public lldb_private::ObjectFile { +public: + // Static Functions + static void Initialize(); + + static void Terminate(); + + static llvm::StringRef GetPluginNameStatic() { return "elf"; } + + static llvm::StringRef GetPluginDescriptionStatic() { +return "ELF object file reader."; + } + + static lldb_private::ObjectFile * + CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, + lldb::offset_t data_offset, const lldb_private::FileSpec *file, + lldb::offset_t file_offset, lldb::offset_t length); + + static lldb_private::ObjectFile *CreateMemoryInstance( + const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, + const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); + + static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, +lldb::DataBufferSP &data_sp, +lldb::offset_t data_offset, +lldb::offset_t file_offset, +lldb::offset_t length, +lldb_private::ModuleSpecList &specs); + + static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, + lldb::addr_t length); + + // PluginInterface protocol + llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } + + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { +return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + + // ObjectFile Protocol. + bool ParseHeader() override; + + bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, + bool value_is_offset) override; + + lldb::ByteOrder GetByteOrder() const override; + + bool IsExecutable() const override; + + uint32_t GetAddressByteSize() const override; + + lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override; + + void ParseSymtab(lldb_private::Symtab &symtab) override; + + bool IsStripped() override; + + void CreateSections(lldb_private::SectionList &unified_section_list) override; + + void Dump(lldb_private::Stream *s) override; + + lldb_private::ArchSpec GetArchitecture() override; + + lldb_private::UUID GetUUID() override; + + /// Return the contents of the .gnu_debuglink section, if the object file +
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
DhruvSrivastavaX wrote: > Are XCOFF files always big endian? If so, then all you need is to add a > `DataExtractor::SetByteOrder()`. If not (and you want to support both > endiannesses), then it would be better to add both cases to > `XCOFFHeaderSizeFromMagic`. Yes, AIX XCOFF does not support little endian, so I went ahead with the SetByteOrder Fix. https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
@@ -0,0 +1,193 @@ +//===-- ObjectFileXCOFF.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 "ObjectFileXCOFF.h" + +#include +#include +#include +#include + +#include "lldb/Core/Module.h" +#include "lldb/Core/ModuleSpec.h" +#include "lldb/Core/PluginManager.h" +#include "lldb/Core/Progress.h" +#include "lldb/Core/Section.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Symbol/SymbolContext.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/FileSpecList.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/RangeMap.h" +#include "lldb/Utility/Status.h" +#include "lldb/Utility/Stream.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/XCOFF.h" +#include "llvm/Object/XCOFFObjectFile.h" +#include "llvm/Support/MemoryBuffer.h" + +using namespace llvm; +using namespace lldb; +using namespace lldb_private; + +LLDB_PLUGIN_DEFINE(ObjectFileXCOFF) + +// FIXME: target 64bit at this moment. + +// Static methods. +void ObjectFileXCOFF::Initialize() { + PluginManager::RegisterPlugin(GetPluginNameStatic(), +GetPluginDescriptionStatic(), CreateInstance, +CreateMemoryInstance, GetModuleSpecifications); +} + +void ObjectFileXCOFF::Terminate() { + PluginManager::UnregisterPlugin(CreateInstance); +} + +ObjectFile *ObjectFileXCOFF::CreateInstance(const lldb::ModuleSP &module_sp, +DataBufferSP data_sp, +lldb::offset_t data_offset, +const lldb_private::FileSpec *file, +lldb::offset_t file_offset, +lldb::offset_t length) { + if (!data_sp) { +data_sp = MapFileData(*file, length, file_offset); +if (!data_sp) + return nullptr; +data_offset = 0; + } + if (!ObjectFileXCOFF::MagicBytesMatch(data_sp, data_offset, length)) +return nullptr; + // Update the data to contain the entire file if it doesn't already + if (data_sp->GetByteSize() < length) { +data_sp = MapFileData(*file, length, file_offset); +if (!data_sp) + return nullptr; +data_offset = 0; + } + auto objfile_up = std::make_unique( + module_sp, data_sp, data_offset, file, file_offset, length); + if (!objfile_up) +return nullptr; + + return objfile_up.release(); +} + +ObjectFile *ObjectFileXCOFF::CreateMemoryInstance( +const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp, +const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) { + return nullptr; +} + +size_t ObjectFileXCOFF::GetModuleSpecifications( +const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp, +lldb::offset_t data_offset, lldb::offset_t file_offset, +lldb::offset_t length, lldb_private::ModuleSpecList &specs) { + const size_t initial_count = specs.GetSize(); + + if (ObjectFileXCOFF::MagicBytesMatch(data_sp, 0, data_sp->GetByteSize())) { +ArchSpec arch_spec = +ArchSpec(eArchTypeXCOFF, XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE); +ModuleSpec spec(file, arch_spec); +spec.GetArchitecture().SetArchitecture(eArchTypeXCOFF, XCOFF::TCPU_PPC64, + LLDB_INVALID_CPUTYPE, + llvm::Triple::AIX); +specs.Append(spec); + } + return specs.GetSize() - initial_count; +} + +static uint32_t XCOFFHeaderSizeFromMagic(uint32_t magic) { + switch (magic) { +/* TODO: 32bit not supported yet +case XCOFF::XCOFF32: + return sizeof(struct llvm::object::XCOFFFileHeader32); +*/ + + case XCOFF::XCOFF64: +return sizeof(struct llvm::object::XCOFFFileHeader64); +break; + + default: +break; + } + return 0; +} + +bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp, + lldb::addr_t data_offset, + lldb::addr_t data_length) { + lldb_private::DataExtractor data; + data.SetData(data_sp, data_offset, data_length); + lldb::offset_t offset = 0; + uint16_t magic = data.GetU16(&offset); + if (magic == 0xF701) +magic = 0x01F7; /* Since AIX is big endian, and the host checking platform + might be little endian. */ DhruvSrivastavaX wrote: Great. Done, Thanks! https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https:
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/108000 >From 426874ab276182858b75e9bbf8704dab1742757c Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Tue, 10 Sep 2024 04:38:32 -0500 Subject: [PATCH 1/4] Ptrace code base for AIX --- lldb/include/lldb/Host/aix/Ptrace.h | 60 + 1 file changed, 60 insertions(+) create mode 100644 lldb/include/lldb/Host/aix/Ptrace.h diff --git a/lldb/include/lldb/Host/aix/Ptrace.h b/lldb/include/lldb/Host/aix/Ptrace.h new file mode 100644 index 00..aabd3fd4fc5573 --- /dev/null +++ b/lldb/include/lldb/Host/aix/Ptrace.h @@ -0,0 +1,60 @@ +//===-- Ptrace.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 +// +//===--===// + +// This file defines ptrace functions & structures + +#ifndef liblldb_Host_linux_Ptrace_h_ +#define liblldb_Host_linux_Ptrace_h_ + +#include + +#ifndef __GLIBC__ +typedef int __ptrace_request; +#endif + +#define DEBUG_PTRACE_MAXBYTES 20 + +// Support ptrace extensions even when compiled without required kernel support +#ifndef PTRACE_GETREGS +#define PTRACE_GETREGS 12 +#endif +#ifndef PTRACE_SETREGS +#define PTRACE_SETREGS 13 +#endif +#ifndef PTRACE_GETFPREGS +#define PTRACE_GETFPREGS 14 +#endif +#ifndef PTRACE_SETFPREGS +#define PTRACE_SETFPREGS 15 +#endif +#ifndef PTRACE_GETREGSET +#define PTRACE_GETREGSET 0x4204 +#endif +#ifndef PTRACE_SETREGSET +#define PTRACE_SETREGSET 0x4205 +#endif +#ifndef PTRACE_GET_THREAD_AREA +#define PTRACE_GET_THREAD_AREA 25 +#endif +#ifndef PTRACE_ARCH_PRCTL +#define PTRACE_ARCH_PRCTL 30 +#endif +#ifndef ARCH_GET_FS +#define ARCH_SET_GS 0x1001 +#define ARCH_SET_FS 0x1002 +#define ARCH_GET_FS 0x1003 +#define ARCH_GET_GS 0x1004 +#endif +#ifndef PTRACE_PEEKMTETAGS +#define PTRACE_PEEKMTETAGS 33 +#endif +#ifndef PTRACE_POKEMTETAGS +#define PTRACE_POKEMTETAGS 34 +#endif + +#endif // liblldb_Host_linux_Ptrace_h_ >From 61bdaf75ddbd5940af5f23363311ffcacb0540d7 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Tue, 10 Sep 2024 05:43:37 -0500 Subject: [PATCH 2/4] Modified specific to AIX --- lldb/include/lldb/Host/aix/Ptrace.h | 38 + 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/lldb/include/lldb/Host/aix/Ptrace.h b/lldb/include/lldb/Host/aix/Ptrace.h index aabd3fd4fc5573..5d5ae82c9dab7d 100644 --- a/lldb/include/lldb/Host/aix/Ptrace.h +++ b/lldb/include/lldb/Host/aix/Ptrace.h @@ -8,29 +8,25 @@ // This file defines ptrace functions & structures -#ifndef liblldb_Host_linux_Ptrace_h_ -#define liblldb_Host_linux_Ptrace_h_ +#ifndef liblldb_Host_aix_Ptrace_h_ +#define liblldb_Host_aix_Ptrace_h_ #include -#ifndef __GLIBC__ -typedef int __ptrace_request; -#endif - #define DEBUG_PTRACE_MAXBYTES 20 // Support ptrace extensions even when compiled without required kernel support #ifndef PTRACE_GETREGS -#define PTRACE_GETREGS 12 +#define PTRACE_GETREGS (PT_COMMAND_MAX + 1) #endif #ifndef PTRACE_SETREGS -#define PTRACE_SETREGS 13 +#define PTRACE_SETREGS (PT_COMMAND_MAX + 2) #endif #ifndef PTRACE_GETFPREGS -#define PTRACE_GETFPREGS 14 +#define PTRACE_GETFPREGS (PT_COMMAND_MAX + 3) #endif #ifndef PTRACE_SETFPREGS -#define PTRACE_SETFPREGS 15 +#define PTRACE_SETFPREGS (PT_COMMAND_MAX + 4) #endif #ifndef PTRACE_GETREGSET #define PTRACE_GETREGSET 0x4204 @@ -38,23 +34,11 @@ typedef int __ptrace_request; #ifndef PTRACE_SETREGSET #define PTRACE_SETREGSET 0x4205 #endif -#ifndef PTRACE_GET_THREAD_AREA -#define PTRACE_GET_THREAD_AREA 25 -#endif -#ifndef PTRACE_ARCH_PRCTL -#define PTRACE_ARCH_PRCTL 30 -#endif -#ifndef ARCH_GET_FS -#define ARCH_SET_GS 0x1001 -#define ARCH_SET_FS 0x1002 -#define ARCH_GET_FS 0x1003 -#define ARCH_GET_GS 0x1004 -#endif -#ifndef PTRACE_PEEKMTETAGS -#define PTRACE_PEEKMTETAGS 33 +#ifndef PTRACE_GETVRREGS +#define PTRACE_GETVRREGS (PT_COMMAND_MAX + 5) #endif -#ifndef PTRACE_POKEMTETAGS -#define PTRACE_POKEMTETAGS 34 +#ifndef PTRACE_GETVSRREGS +#define PTRACE_GETVSRREGS (PT_COMMAND_MAX + 6) #endif -#endif // liblldb_Host_linux_Ptrace_h_ +#endif // liblldb_Host_aix_Ptrace_h_ >From 1134b6fb81cedd75e447f42f788bb6d96351cdf3 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Tue, 10 Sep 2024 08:32:41 -0500 Subject: [PATCH 3/4] Addressed comments --- lldb/include/lldb/Host/aix/Ptrace.h | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lldb/include/lldb/Host/aix/Ptrace.h b/lldb/include/lldb/Host/aix/Ptrace.h index 5d5ae82c9dab7d..06678d1e1a2484 100644 --- a/lldb/include/lldb/Host/aix/Ptrace.h +++ b/lldb/include/lldb/Host/aix/Ptrace.h @@ -8,13 +8,11 @@ // This file defines ptrace functions & structures -#ifndef liblldb_Host_aix_Ptrace_h_ -#defi
[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)
DhruvSrivastavaX wrote: Hi @labath To keep the changes for Process Plugin going forward, I have changed the file path as discussed. Will proceed to push the AIX Process Plugin related files next. Please review once more and see if we can proceed with the merge? Once the NativeProcessAIX and other files come into play, I will optimize as per further suggestions from you. https://github.com/llvm/llvm-project/pull/108000 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
DhruvSrivastavaX wrote: > Looks good. Thanks. Do you need someone to push the merge button? Ok, great. Yes, please merge it, I don't have the permission to do that yet. https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added new plugin AIX-DYLD (Dynamic Loader) Base Support (PR #115714)
DhruvSrivastavaX wrote: Hi @labath , I agree that we can put a hold on this one for now. But on that note, we want to start integrating multiple plugins Parallely, but Systematically, to make the upstreaming pick up some pace and also be in order. Keeping that in mind, I think right now, the best candidates will be: xcoff plugin, process plugin, and host plugin. Hope thats alright? Please do suggest if you have something more in mind. https://github.com/llvm/llvm-project/pull/115714 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
@@ -0,0 +1,243 @@ +//===-- ObjectFileXCOFF.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 "ObjectFileXCOFF.h" + +#include +#include +#include +#include + +#include "lldb/Core/Module.h" +#include "lldb/Core/ModuleSpec.h" +#include "lldb/Core/PluginManager.h" +#include "lldb/Core/Progress.h" +#include "lldb/Core/Section.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Host/LZMA.h" +#include "lldb/Symbol/DWARFCallFrameInfo.h" +#include "lldb/Symbol/SymbolContext.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/SectionLoadList.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/FileSpecList.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/RangeMap.h" +#include "lldb/Utility/Status.h" +#include "lldb/Utility/Stream.h" +#include "lldb/Utility/Timer.h" +#include "llvm/ADT/IntervalMap.h" +#include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/XCOFF.h" +#include "llvm/Object/Decompressor.h" +#include "llvm/Object/XCOFFObjectFile.h" +#include "llvm/Support/CRC.h" +#include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/MemoryBuffer.h" + +using namespace llvm; +using namespace lldb; +using namespace lldb_private; + +LLDB_PLUGIN_DEFINE(ObjectFileXCOFF) + +// FIXME: target 64bit at this moment. + +// Static methods. +void ObjectFileXCOFF::Initialize() { + PluginManager::RegisterPlugin(GetPluginNameStatic(), +GetPluginDescriptionStatic(), CreateInstance, +CreateMemoryInstance, GetModuleSpecifications); +} + +void ObjectFileXCOFF::Terminate() { + PluginManager::UnregisterPlugin(CreateInstance); +} + +bool UGLY_FLAG_FOR_AIX __attribute__((weak)) = false; + +ObjectFile *ObjectFileXCOFF::CreateInstance(const lldb::ModuleSP &module_sp, +DataBufferSP data_sp, +lldb::offset_t data_offset, +const lldb_private::FileSpec *file, +lldb::offset_t file_offset, +lldb::offset_t length) { + if (!data_sp) { +data_sp = MapFileData(*file, length, file_offset); +if (!data_sp) + return nullptr; +data_offset = 0; + } + + if (!ObjectFileXCOFF::MagicBytesMatch(data_sp, data_offset, length)) +return nullptr; + + // Update the data to contain the entire file if it doesn't already + if (data_sp->GetByteSize() < length) { +data_sp = MapFileData(*file, length, file_offset); +if (!data_sp) + return nullptr; +data_offset = 0; + } + auto objfile_up = std::make_unique( + module_sp, data_sp, data_offset, file, file_offset, length); + if (!objfile_up) +return nullptr; + + UGLY_FLAG_FOR_AIX = true; + return objfile_up.release(); +} + +ObjectFile *ObjectFileXCOFF::CreateMemoryInstance( +const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp, +const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) { + return nullptr; +} + +size_t ObjectFileXCOFF::GetModuleSpecifications( +const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp, +lldb::offset_t data_offset, lldb::offset_t file_offset, +lldb::offset_t length, lldb_private::ModuleSpecList &specs) { + const size_t initial_count = specs.GetSize(); + + if (ObjectFileXCOFF::MagicBytesMatch(data_sp, 0, data_sp->GetByteSize())) { +ArchSpec arch_spec = +ArchSpec(eArchTypeXCOFF, XCOFF::TCPU_PPC64, LLDB_INVALID_CPUTYPE); +ModuleSpec spec(file, arch_spec); +spec.GetArchitecture().SetArchitecture(eArchTypeXCOFF, XCOFF::TCPU_PPC64, + LLDB_INVALID_CPUTYPE, + llvm::Triple::AIX); +specs.Append(spec); + } + return specs.GetSize() - initial_count; +} + +static uint32_t XCOFFHeaderSizeFromMagic(uint32_t magic) { + switch (magic) { +/* TODO: 32bit not supported yet +case XCOFF::XCOFF32: + return sizeof(struct llvm::object::XCOFFFileHeader32); +*/ + + case XCOFF::XCOFF64: +return sizeof(struct llvm::object::XCOFFFileHeader64); +break; + + default: +break; + } + return 0; +} + +bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp, + lldb::addr_t data_offset, + lldb::addr_t data_length) { + lldb_private::DataExtractor data; + data.SetData(data_sp, data_offset, da
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/111814 >From 08c9d5ae66ca857d165dc878ebd1b2e0de364a24 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Thu, 10 Oct 2024 02:24:42 -0500 Subject: [PATCH 1/6] Taking base file structure from ELF as reference --- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 440 ++ 1 file changed, 440 insertions(+) create mode 100644 lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h new file mode 100644 index 00..aba3a5bfcbf5b6 --- /dev/null +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h @@ -0,0 +1,440 @@ +//===-- ObjectFileELF.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_OBJECTFILE_ELF_OBJECTFILEELF_H +#define LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H + +#include + +#include +#include + +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/UUID.h" +#include "lldb/lldb-private.h" + +#include "ELFHeader.h" + +struct ELFNote { + elf::elf_word n_namesz = 0; + elf::elf_word n_descsz = 0; + elf::elf_word n_type = 0; + + std::string n_name; + + ELFNote() = default; + + /// Parse an ELFNote entry from the given DataExtractor starting at position + /// \p offset. + /// + /// \param[in] data + ///The DataExtractor to read from. + /// + /// \param[in,out] offset + ///Pointer to an offset in the data. On return the offset will be + ///advanced by the number of bytes read. + /// + /// \return + ///True if the ELFRel entry was successfully read and false otherwise. + bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset); + + size_t GetByteSize() const { +return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4); + } +}; + +/// \class ObjectFileELF +/// Generic ELF object file reader. +/// +/// This class provides a generic ELF (32/64 bit) reader plugin implementing +/// the ObjectFile protocol. +class ObjectFileELF : public lldb_private::ObjectFile { +public: + // Static Functions + static void Initialize(); + + static void Terminate(); + + static llvm::StringRef GetPluginNameStatic() { return "elf"; } + + static llvm::StringRef GetPluginDescriptionStatic() { +return "ELF object file reader."; + } + + static lldb_private::ObjectFile * + CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, + lldb::offset_t data_offset, const lldb_private::FileSpec *file, + lldb::offset_t file_offset, lldb::offset_t length); + + static lldb_private::ObjectFile *CreateMemoryInstance( + const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, + const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); + + static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, +lldb::DataBufferSP &data_sp, +lldb::offset_t data_offset, +lldb::offset_t file_offset, +lldb::offset_t length, +lldb_private::ModuleSpecList &specs); + + static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, + lldb::addr_t length); + + // PluginInterface protocol + llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } + + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { +return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + + // ObjectFile Protocol. + bool ParseHeader() override; + + bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, + bool value_is_offset) override; + + lldb::ByteOrder GetByteOrder() const override; + + bool IsExecutable() const override; + + uint32_t GetAddressByteSize() const override; + + lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override; + + void ParseSymtab(lldb_private::Symtab &symtab) override; + + bool IsStripped() override; + + void CreateSections(lldb_private::SectionList &unified_section_list) override; + + void Dump(lldb_private::Stream *s) override; + + lldb_private::ArchSpec GetArchitecture() override; + + lldb_private::UUID GetUUID() override; + + /// Return the contents of the .gnu_debuglink section, if the object file +
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
@@ -0,0 +1,243 @@ +//===-- ObjectFileXCOFF.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 "ObjectFileXCOFF.h" + +#include +#include +#include +#include + +#include "lldb/Core/Module.h" DhruvSrivastavaX wrote: Filtered some of the headers. Thanks! https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
@@ -0,0 +1,243 @@ +//===-- ObjectFileXCOFF.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 "ObjectFileXCOFF.h" + +#include +#include +#include +#include + +#include "lldb/Core/Module.h" +#include "lldb/Core/ModuleSpec.h" +#include "lldb/Core/PluginManager.h" +#include "lldb/Core/Progress.h" +#include "lldb/Core/Section.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Host/LZMA.h" +#include "lldb/Symbol/DWARFCallFrameInfo.h" +#include "lldb/Symbol/SymbolContext.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/SectionLoadList.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/FileSpecList.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/RangeMap.h" +#include "lldb/Utility/Status.h" +#include "lldb/Utility/Stream.h" +#include "lldb/Utility/Timer.h" +#include "llvm/ADT/IntervalMap.h" +#include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/XCOFF.h" +#include "llvm/Object/Decompressor.h" +#include "llvm/Object/XCOFFObjectFile.h" +#include "llvm/Support/CRC.h" +#include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/MemoryBuffer.h" + +using namespace llvm; +using namespace lldb; +using namespace lldb_private; + +LLDB_PLUGIN_DEFINE(ObjectFileXCOFF) + +// FIXME: target 64bit at this moment. + +// Static methods. +void ObjectFileXCOFF::Initialize() { + PluginManager::RegisterPlugin(GetPluginNameStatic(), +GetPluginDescriptionStatic(), CreateInstance, +CreateMemoryInstance, GetModuleSpecifications); +} + +void ObjectFileXCOFF::Terminate() { + PluginManager::UnregisterPlugin(CreateInstance); +} + +bool UGLY_FLAG_FOR_AIX __attribute__((weak)) = false; DhruvSrivastavaX wrote: Yes, sure. It is actually used in other files as a flag. But we can check on it later. https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
DhruvSrivastavaX wrote: > This is exactly what I had in mind -- thank you. > > The patch looks mostly good, apart from the inline comments. My main question > is about the "dependant modules" parsing code. AFAICT, its not actually > functional (and not tested). Is yaml2objs xcoff backend sufficiently > developed to create a test for the dependant module functionality? Given that > we rely on llvm for parsing that, we don't have to test it extensively, but > it would be nice to have at least one test. We could either do that in this > patch, or rip out the dependant module functionality, and add it back in > another patch -- up to you. Great. Thanks for your inputs too. Yes, I think we can add dependant modules related changes later. I have removed them for now. About the yaml xcoff testing, For a basic test case as this one, it works great! I also tried using obj2yaml and on a compiled executable for a basic .c test case, and then reversing it with yaml2obj and that works fine too. But for the dependant module functionality, I might need to check some more, we can check on that in the later PRs. On another note, I have a doubt or maybe I am missing something: I am able to run lldb-test successfully on my aix system setup for this new basic xcoff file (where I have the entire aix changes along with a reduced xcoff same as in this PR). But lldb-test does not recognize the object file generated by yaml2obj on a linux ppc64 system (where I have only the merged changes and the xcoff changes only present in this PR). Is it not supposed to work that way or am I missing something? Any suggestions about what can I try would be great! https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Header Parsing for XCOFF Object File in AIX (PR #116338)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/116338 >From 0c63800bdcbadcfceed4c9a81305eda7d5a15960 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Fri, 15 Nov 2024 02:16:31 -0600 Subject: [PATCH 1/5] Added XCOFF Header Parsing --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 126 +- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 58 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 3be900f9a4bc9f..c06ece4347822d 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -81,9 +81,44 @@ ObjectFile *ObjectFileXCOFF::CreateInstance(const lldb::ModuleSP &module_sp, if (!objfile_up) return nullptr; + // Cache xcoff binary. + if (!objfile_up->CreateBinary()) +return nullptr; + + if (!objfile_up->ParseHeader()) +return nullptr; + return objfile_up.release(); } +bool ObjectFileXCOFF::CreateBinary() { + if (m_binary) +return true; + + Log *log = GetLog(LLDBLog::Object); + + auto binary = llvm::object::XCOFFObjectFile::createObjectFile( + llvm::MemoryBufferRef(toStringRef(m_data.GetData()), +m_file.GetFilename().GetStringRef()), + file_magic::xcoff_object_64); + if (!binary) { +LLDB_LOG_ERROR(log, binary.takeError(), + "Failed to create binary for file ({1}): {0}", m_file); +return false; + } + + // Make sure we only handle XCOFF format. + m_binary = + llvm::unique_dyn_cast(std::move(*binary)); + if (!m_binary) +return false; + + LLDB_LOG(log, "this = {0}, module = {1} ({2}), file = {3}, binary = {4}", + this, GetModule().get(), GetModule()->GetSpecificationDescription(), + m_file.GetPath(), m_binary.get()); + return true; +} + ObjectFile *ObjectFileXCOFF::CreateMemoryInstance( const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) { @@ -136,13 +171,92 @@ bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp, return XCOFFHeaderSizeFromMagic(magic) != 0; } -bool ObjectFileXCOFF::ParseHeader() { return false; } +bool ObjectFileXCOFF::ParseHeader() { + ModuleSP module_sp(GetModule()); + if (module_sp) { +std::lock_guard guard(module_sp->GetMutex()); +lldb::offset_t offset = 0; + +if (ParseXCOFFHeader(m_data, &offset, m_xcoff_header)) { + m_data.SetAddressByteSize(GetAddressByteSize()); + if (m_xcoff_header.auxhdrsize > 0) +ParseXCOFFOptionalHeader(m_data, &offset); +} +return true; + } + + return false; +} + +bool ObjectFileXCOFF::ParseXCOFFHeader(lldb_private::DataExtractor &data, + lldb::offset_t *offset_ptr, + xcoff_header_t &xcoff_header) { + // FIXME: data.ValidOffsetForDataOfSize + xcoff_header.magic = data.GetU16(offset_ptr); + xcoff_header.nsects = data.GetU16(offset_ptr); + xcoff_header.modtime = data.GetU32(offset_ptr); + xcoff_header.symoff = data.GetU64(offset_ptr); + xcoff_header.auxhdrsize = data.GetU16(offset_ptr); + xcoff_header.flags = data.GetU16(offset_ptr); + xcoff_header.nsyms = data.GetU32(offset_ptr); + return true; +} + +bool ObjectFileXCOFF::ParseXCOFFOptionalHeader( +lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr) { + lldb::offset_t init_offset = *offset_ptr; + // FIXME: data.ValidOffsetForDataOfSize + m_xcoff_aux_header.AuxMagic = data.GetU16(offset_ptr); + m_xcoff_aux_header.Version = data.GetU16(offset_ptr); + m_xcoff_aux_header.ReservedForDebugger = data.GetU32(offset_ptr); + m_xcoff_aux_header.TextStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.DataStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.TOCAnchorAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.SecNumOfEntryPoint = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfTOC = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfLoader = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfBSS = data.GetU16(offset_ptr); + m_xcoff_aux_header.MaxAlignOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.MaxAlignOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.ModuleType = data.GetU16(offset_ptr); + m_xcoff_aux_header.CpuFlag = data.GetU8(offset_ptr); + m_xcoff_aux_header.CpuType = data.GetU8(offset_ptr); + m_xcoff_aux_header.TextPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.DataPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.StackPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.FlagAndTDataAlignment = data.GetU8(offset_ptr); + m_xcoff_aux_header.TextSize = data.GetU64(offset_p
[Lldb-commits] [lldb] [lldb][AIX] Header Parsing for XCOFF Object File in AIX (PR #116338)
DhruvSrivastavaX wrote: It is updated now. Please provide your review and merge if everything is good. @labath https://github.com/llvm/llvm-project/pull/116338 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/117906 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/117906 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 This is how we have currently added the support for HostInfo for AIX. It is taken directly from its Linux counterpart. Please let me know your suggestions about how can we plan to merge this and I will plan accordingly, and drop it as required. Can we keep it as a separate entity for AIX or we can combine it with something else? If you, how would like me to proceed in a way that is best for the code base as a whole. Review Request: @labath @DavidSpickett >From d05de47c87362b54760f65c294c30c80b2d5bc9b Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Wed, 27 Nov 2024 10:10:32 -0600 Subject: [PATCH] HostInfoAIX --- lldb/include/lldb/Host/aix/HostInfoAIX.h | 43 + lldb/source/Host/CMakeLists.txt | 5 + lldb/source/Host/aix/HostInfoAIX.cpp | 213 +++ 3 files changed, 261 insertions(+) create mode 100644 lldb/include/lldb/Host/aix/HostInfoAIX.h create mode 100644 lldb/source/Host/aix/HostInfoAIX.cpp diff --git a/lldb/include/lldb/Host/aix/HostInfoAIX.h b/lldb/include/lldb/Host/aix/HostInfoAIX.h new file mode 100644 index 00..c797b36f3dcc8d --- /dev/null +++ b/lldb/include/lldb/Host/aix/HostInfoAIX.h @@ -0,0 +1,43 @@ +//===-- HostInfoAIX.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_HOST_AIX_HOSTINFOAIX_H_ +#define LLDB_HOST_AIX_HOSTINFOAIX_H_ + +#include "lldb/Host/posix/HostInfoPosix.h" +#include "lldb/Utility/FileSpec.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/VersionTuple.h" + +#include +#include + +namespace lldb_private { + +class HostInfoAIX : public HostInfoPosix { + friend class HostInfoBase; + +public: + static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr); + static void Terminate(); + + static llvm::VersionTuple GetOSVersion(); + static std::optional GetOSBuildString(); + static llvm::StringRef GetDistributionId(); + static FileSpec GetProgramFileSpec(); + +protected: + static bool ComputeSupportExeDirectory(FileSpec &file_spec); + static bool ComputeSystemPluginsDirectory(FileSpec &file_spec); + static bool ComputeUserPluginsDirectory(FileSpec &file_spec); + static void ComputeHostArchitectureSupport(ArchSpec &arch_32, + ArchSpec &arch_64); +}; +} // namespace lldb_private + +#endif // LLDB_HOST_AIX_HOSTINFOAIX_H_ diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index c2e091ee8555b7..e0cd8569bf9575 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -133,6 +133,11 @@ else() openbsd/Host.cpp openbsd/HostInfoOpenBSD.cpp ) + + elseif (CMAKE_SYSTEM_NAME MATCHES "AIX") +add_host_subdirectory(aix + aix/HostInfoAIX.cpp + ) endif() endif() diff --git a/lldb/source/Host/aix/HostInfoAIX.cpp b/lldb/source/Host/aix/HostInfoAIX.cpp new file mode 100644 index 00..e43ab3afd94657 --- /dev/null +++ b/lldb/source/Host/aix/HostInfoAIX.cpp @@ -0,0 +1,213 @@ +//===-- HostInfoAIX.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 "lldb/Host/aix/HostInfoAIX.h" +#include "lldb/Host/Config.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" + +#include "llvm/Support/Threading.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace lldb_private; + +namespace { +struct HostInfoAIXFields { + llvm::once_flag m_distribution_once_flag; + std::string m_distribution_id; + llvm::once_flag m_os_version_once_flag; + llvm::VersionTuple m_os_version; +}; +} // namespace + +static HostInfoAIXFields *g_fields = nullptr; + +void HostInfoAIX::Initialize(SharedLibraryDirectoryHelper *helper) { + HostInfoPosix::Initialize(helper); + + g_fields = new HostInfoAIXFields(); +} + +void HostInfoAIX::Terminate() { + assert(g_fields && "Missing call to Initialize?"); + delete g_fields; + g_fields = nullptr; + Host
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/117906 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Header Parsing for XCOFF Object File in AIX (PR #116338)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/116338 >From 0c63800bdcbadcfceed4c9a81305eda7d5a15960 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Fri, 15 Nov 2024 02:16:31 -0600 Subject: [PATCH 1/4] Added XCOFF Header Parsing --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 126 +- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 58 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 3be900f9a4bc9f..c06ece4347822d 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -81,9 +81,44 @@ ObjectFile *ObjectFileXCOFF::CreateInstance(const lldb::ModuleSP &module_sp, if (!objfile_up) return nullptr; + // Cache xcoff binary. + if (!objfile_up->CreateBinary()) +return nullptr; + + if (!objfile_up->ParseHeader()) +return nullptr; + return objfile_up.release(); } +bool ObjectFileXCOFF::CreateBinary() { + if (m_binary) +return true; + + Log *log = GetLog(LLDBLog::Object); + + auto binary = llvm::object::XCOFFObjectFile::createObjectFile( + llvm::MemoryBufferRef(toStringRef(m_data.GetData()), +m_file.GetFilename().GetStringRef()), + file_magic::xcoff_object_64); + if (!binary) { +LLDB_LOG_ERROR(log, binary.takeError(), + "Failed to create binary for file ({1}): {0}", m_file); +return false; + } + + // Make sure we only handle XCOFF format. + m_binary = + llvm::unique_dyn_cast(std::move(*binary)); + if (!m_binary) +return false; + + LLDB_LOG(log, "this = {0}, module = {1} ({2}), file = {3}, binary = {4}", + this, GetModule().get(), GetModule()->GetSpecificationDescription(), + m_file.GetPath(), m_binary.get()); + return true; +} + ObjectFile *ObjectFileXCOFF::CreateMemoryInstance( const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) { @@ -136,13 +171,92 @@ bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp, return XCOFFHeaderSizeFromMagic(magic) != 0; } -bool ObjectFileXCOFF::ParseHeader() { return false; } +bool ObjectFileXCOFF::ParseHeader() { + ModuleSP module_sp(GetModule()); + if (module_sp) { +std::lock_guard guard(module_sp->GetMutex()); +lldb::offset_t offset = 0; + +if (ParseXCOFFHeader(m_data, &offset, m_xcoff_header)) { + m_data.SetAddressByteSize(GetAddressByteSize()); + if (m_xcoff_header.auxhdrsize > 0) +ParseXCOFFOptionalHeader(m_data, &offset); +} +return true; + } + + return false; +} + +bool ObjectFileXCOFF::ParseXCOFFHeader(lldb_private::DataExtractor &data, + lldb::offset_t *offset_ptr, + xcoff_header_t &xcoff_header) { + // FIXME: data.ValidOffsetForDataOfSize + xcoff_header.magic = data.GetU16(offset_ptr); + xcoff_header.nsects = data.GetU16(offset_ptr); + xcoff_header.modtime = data.GetU32(offset_ptr); + xcoff_header.symoff = data.GetU64(offset_ptr); + xcoff_header.auxhdrsize = data.GetU16(offset_ptr); + xcoff_header.flags = data.GetU16(offset_ptr); + xcoff_header.nsyms = data.GetU32(offset_ptr); + return true; +} + +bool ObjectFileXCOFF::ParseXCOFFOptionalHeader( +lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr) { + lldb::offset_t init_offset = *offset_ptr; + // FIXME: data.ValidOffsetForDataOfSize + m_xcoff_aux_header.AuxMagic = data.GetU16(offset_ptr); + m_xcoff_aux_header.Version = data.GetU16(offset_ptr); + m_xcoff_aux_header.ReservedForDebugger = data.GetU32(offset_ptr); + m_xcoff_aux_header.TextStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.DataStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.TOCAnchorAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.SecNumOfEntryPoint = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfTOC = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfLoader = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfBSS = data.GetU16(offset_ptr); + m_xcoff_aux_header.MaxAlignOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.MaxAlignOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.ModuleType = data.GetU16(offset_ptr); + m_xcoff_aux_header.CpuFlag = data.GetU8(offset_ptr); + m_xcoff_aux_header.CpuType = data.GetU8(offset_ptr); + m_xcoff_aux_header.TextPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.DataPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.StackPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.FlagAndTDataAlignment = data.GetU8(offset_ptr); + m_xcoff_aux_header.TextSize = data.GetU64(offset_p
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
@@ -0,0 +1,43 @@ +//===-- HostInfoAIX.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_HOST_AIX_HOSTINFOAIX_H_ +#define LLDB_HOST_AIX_HOSTINFOAIX_H_ + +#include "lldb/Host/posix/HostInfoPosix.h" +#include "lldb/Utility/FileSpec.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/VersionTuple.h" + +#include +#include DhruvSrivastavaX wrote: Ok sure https://github.com/llvm/llvm-project/pull/117906 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
@@ -0,0 +1,213 @@ +//===-- HostInfoAIX.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 "lldb/Host/aix/HostInfoAIX.h" +#include "lldb/Host/Config.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" + +#include "llvm/Support/Threading.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace lldb_private; + +namespace { +struct HostInfoAIXFields { + llvm::once_flag m_distribution_once_flag; + std::string m_distribution_id; + llvm::once_flag m_os_version_once_flag; + llvm::VersionTuple m_os_version; +}; +} // namespace + +static HostInfoAIXFields *g_fields = nullptr; + +void HostInfoAIX::Initialize(SharedLibraryDirectoryHelper *helper) { + HostInfoPosix::Initialize(helper); + + g_fields = new HostInfoAIXFields(); +} + +void HostInfoAIX::Terminate() { + assert(g_fields && "Missing call to Initialize?"); + delete g_fields; + g_fields = nullptr; + HostInfoBase::Terminate(); +} + +llvm::VersionTuple HostInfoAIX::GetOSVersion() { + assert(g_fields && "Missing call to Initialize?"); + llvm::call_once(g_fields->m_os_version_once_flag, []() { +struct utsname un; +if (uname(&un) != 0) + return; + +llvm::StringRef release = un.release; +// The kernel release string can include a lot of stuff (e.g. +// 4.9.0-6-amd64). We're only interested in the numbered prefix. +release = release.substr(0, release.find_first_not_of("0123456789.")); +g_fields->m_os_version.tryParse(release); + }); + + return g_fields->m_os_version; +} + +std::optional HostInfoAIX::GetOSBuildString() { + struct utsname un; + ::memset(&un, 0, sizeof(utsname)); + + if (uname(&un) < 0) +return std::nullopt; + + return std::string(un.release); +} + +llvm::StringRef HostInfoAIX::GetDistributionId() { DhruvSrivastavaX wrote: Since this file is a linux copy so we didnt selectively remove anything. We can take care of that while merging into posix. https://github.com/llvm/llvm-project/pull/117906 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
@@ -0,0 +1,213 @@ +//===-- HostInfoAIX.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 "lldb/Host/aix/HostInfoAIX.h" +#include "lldb/Host/Config.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" + +#include "llvm/Support/Threading.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace lldb_private; + +namespace { +struct HostInfoAIXFields { + llvm::once_flag m_distribution_once_flag; + std::string m_distribution_id; + llvm::once_flag m_os_version_once_flag; + llvm::VersionTuple m_os_version; +}; +} // namespace + +static HostInfoAIXFields *g_fields = nullptr; + +void HostInfoAIX::Initialize(SharedLibraryDirectoryHelper *helper) { + HostInfoPosix::Initialize(helper); + + g_fields = new HostInfoAIXFields(); +} + +void HostInfoAIX::Terminate() { + assert(g_fields && "Missing call to Initialize?"); + delete g_fields; + g_fields = nullptr; + HostInfoBase::Terminate(); +} + +llvm::VersionTuple HostInfoAIX::GetOSVersion() { + assert(g_fields && "Missing call to Initialize?"); + llvm::call_once(g_fields->m_os_version_once_flag, []() { +struct utsname un; +if (uname(&un) != 0) + return; + +llvm::StringRef release = un.release; +// The kernel release string can include a lot of stuff (e.g. +// 4.9.0-6-amd64). We're only interested in the numbered prefix. +release = release.substr(0, release.find_first_not_of("0123456789.")); +g_fields->m_os_version.tryParse(release); + }); + + return g_fields->m_os_version; +} + +std::optional HostInfoAIX::GetOSBuildString() { + struct utsname un; + ::memset(&un, 0, sizeof(utsname)); + + if (uname(&un) < 0) +return std::nullopt; + + return std::string(un.release); +} DhruvSrivastavaX wrote: Yes, I can work on that. I'll update a template for review soon. https://github.com/llvm/llvm-project/pull/117906 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [llvm] Fix for Process attach (PR #116587)
https://github.com/DhruvSrivastavaX closed https://github.com/llvm/llvm-project/pull/116587 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/111814 >From 08c9d5ae66ca857d165dc878ebd1b2e0de364a24 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Thu, 10 Oct 2024 02:24:42 -0500 Subject: [PATCH 1/8] Taking base file structure from ELF as reference --- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 440 ++ 1 file changed, 440 insertions(+) create mode 100644 lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h new file mode 100644 index 00..aba3a5bfcbf5b6 --- /dev/null +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h @@ -0,0 +1,440 @@ +//===-- ObjectFileELF.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_OBJECTFILE_ELF_OBJECTFILEELF_H +#define LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H + +#include + +#include +#include + +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/UUID.h" +#include "lldb/lldb-private.h" + +#include "ELFHeader.h" + +struct ELFNote { + elf::elf_word n_namesz = 0; + elf::elf_word n_descsz = 0; + elf::elf_word n_type = 0; + + std::string n_name; + + ELFNote() = default; + + /// Parse an ELFNote entry from the given DataExtractor starting at position + /// \p offset. + /// + /// \param[in] data + ///The DataExtractor to read from. + /// + /// \param[in,out] offset + ///Pointer to an offset in the data. On return the offset will be + ///advanced by the number of bytes read. + /// + /// \return + ///True if the ELFRel entry was successfully read and false otherwise. + bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset); + + size_t GetByteSize() const { +return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4); + } +}; + +/// \class ObjectFileELF +/// Generic ELF object file reader. +/// +/// This class provides a generic ELF (32/64 bit) reader plugin implementing +/// the ObjectFile protocol. +class ObjectFileELF : public lldb_private::ObjectFile { +public: + // Static Functions + static void Initialize(); + + static void Terminate(); + + static llvm::StringRef GetPluginNameStatic() { return "elf"; } + + static llvm::StringRef GetPluginDescriptionStatic() { +return "ELF object file reader."; + } + + static lldb_private::ObjectFile * + CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, + lldb::offset_t data_offset, const lldb_private::FileSpec *file, + lldb::offset_t file_offset, lldb::offset_t length); + + static lldb_private::ObjectFile *CreateMemoryInstance( + const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, + const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); + + static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, +lldb::DataBufferSP &data_sp, +lldb::offset_t data_offset, +lldb::offset_t file_offset, +lldb::offset_t length, +lldb_private::ModuleSpecList &specs); + + static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, + lldb::addr_t length); + + // PluginInterface protocol + llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } + + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { +return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + + // ObjectFile Protocol. + bool ParseHeader() override; + + bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, + bool value_is_offset) override; + + lldb::ByteOrder GetByteOrder() const override; + + bool IsExecutable() const override; + + uint32_t GetAddressByteSize() const override; + + lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override; + + void ParseSymtab(lldb_private::Symtab &symtab) override; + + bool IsStripped() override; + + void CreateSections(lldb_private::SectionList &unified_section_list) override; + + void Dump(lldb_private::Stream *s) override; + + lldb_private::ArchSpec GetArchitecture() override; + + lldb_private::UUID GetUUID() override; + + /// Return the contents of the .gnu_debuglink section, if the object file +
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header for AIX (PR #111814)
DhruvSrivastavaX wrote: Hi @labath, So the error was due to the endianness difference between Linux and AIX. The previous failure with the new test case has gone now. I have dropped a fix so that AIX binary is recognised on little endian platforms as well, but if there is any better way to add this check, please do let me know. Thanks! https://github.com/llvm/llvm-project/pull/111814 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Header Parsing for XCOFF Object File in AIX (PR #116338)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/116338 >From 0c63800bdcbadcfceed4c9a81305eda7d5a15960 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Fri, 15 Nov 2024 02:16:31 -0600 Subject: [PATCH 1/2] Added XCOFF Header Parsing --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 126 +- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 58 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 3be900f9a4bc9f..c06ece4347822d 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -81,9 +81,44 @@ ObjectFile *ObjectFileXCOFF::CreateInstance(const lldb::ModuleSP &module_sp, if (!objfile_up) return nullptr; + // Cache xcoff binary. + if (!objfile_up->CreateBinary()) +return nullptr; + + if (!objfile_up->ParseHeader()) +return nullptr; + return objfile_up.release(); } +bool ObjectFileXCOFF::CreateBinary() { + if (m_binary) +return true; + + Log *log = GetLog(LLDBLog::Object); + + auto binary = llvm::object::XCOFFObjectFile::createObjectFile( + llvm::MemoryBufferRef(toStringRef(m_data.GetData()), +m_file.GetFilename().GetStringRef()), + file_magic::xcoff_object_64); + if (!binary) { +LLDB_LOG_ERROR(log, binary.takeError(), + "Failed to create binary for file ({1}): {0}", m_file); +return false; + } + + // Make sure we only handle XCOFF format. + m_binary = + llvm::unique_dyn_cast(std::move(*binary)); + if (!m_binary) +return false; + + LLDB_LOG(log, "this = {0}, module = {1} ({2}), file = {3}, binary = {4}", + this, GetModule().get(), GetModule()->GetSpecificationDescription(), + m_file.GetPath(), m_binary.get()); + return true; +} + ObjectFile *ObjectFileXCOFF::CreateMemoryInstance( const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) { @@ -136,13 +171,92 @@ bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp, return XCOFFHeaderSizeFromMagic(magic) != 0; } -bool ObjectFileXCOFF::ParseHeader() { return false; } +bool ObjectFileXCOFF::ParseHeader() { + ModuleSP module_sp(GetModule()); + if (module_sp) { +std::lock_guard guard(module_sp->GetMutex()); +lldb::offset_t offset = 0; + +if (ParseXCOFFHeader(m_data, &offset, m_xcoff_header)) { + m_data.SetAddressByteSize(GetAddressByteSize()); + if (m_xcoff_header.auxhdrsize > 0) +ParseXCOFFOptionalHeader(m_data, &offset); +} +return true; + } + + return false; +} + +bool ObjectFileXCOFF::ParseXCOFFHeader(lldb_private::DataExtractor &data, + lldb::offset_t *offset_ptr, + xcoff_header_t &xcoff_header) { + // FIXME: data.ValidOffsetForDataOfSize + xcoff_header.magic = data.GetU16(offset_ptr); + xcoff_header.nsects = data.GetU16(offset_ptr); + xcoff_header.modtime = data.GetU32(offset_ptr); + xcoff_header.symoff = data.GetU64(offset_ptr); + xcoff_header.auxhdrsize = data.GetU16(offset_ptr); + xcoff_header.flags = data.GetU16(offset_ptr); + xcoff_header.nsyms = data.GetU32(offset_ptr); + return true; +} + +bool ObjectFileXCOFF::ParseXCOFFOptionalHeader( +lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr) { + lldb::offset_t init_offset = *offset_ptr; + // FIXME: data.ValidOffsetForDataOfSize + m_xcoff_aux_header.AuxMagic = data.GetU16(offset_ptr); + m_xcoff_aux_header.Version = data.GetU16(offset_ptr); + m_xcoff_aux_header.ReservedForDebugger = data.GetU32(offset_ptr); + m_xcoff_aux_header.TextStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.DataStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.TOCAnchorAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.SecNumOfEntryPoint = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfTOC = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfLoader = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfBSS = data.GetU16(offset_ptr); + m_xcoff_aux_header.MaxAlignOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.MaxAlignOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.ModuleType = data.GetU16(offset_ptr); + m_xcoff_aux_header.CpuFlag = data.GetU8(offset_ptr); + m_xcoff_aux_header.CpuType = data.GetU8(offset_ptr); + m_xcoff_aux_header.TextPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.DataPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.StackPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.FlagAndTDataAlignment = data.GetU8(offset_ptr); + m_xcoff_aux_header.TextSize = data.GetU64(offset_p
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header Parsing (PR #116337)
https://github.com/DhruvSrivastavaX closed https://github.com/llvm/llvm-project/pull/116337 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Header Parsing for XCOFF Object File in AIX (PR #116338)
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/116338 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 XCOFF Object File Header Parsing for AIX. This PR is an incremental PR to the base: - https://github.com/llvm/llvm-project/pull/111814 Details about XCOFF file format on AIX: [XCOFF](https://www.ibm.com/docs/en/aix/7.3?topic=formats-xcoff-object-file-format) Review Request: @labath @DavidSpickett >From 0c63800bdcbadcfceed4c9a81305eda7d5a15960 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Fri, 15 Nov 2024 02:16:31 -0600 Subject: [PATCH] Added XCOFF Header Parsing --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 126 +- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 58 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 3be900f9a4bc9f..c06ece4347822d 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -81,9 +81,44 @@ ObjectFile *ObjectFileXCOFF::CreateInstance(const lldb::ModuleSP &module_sp, if (!objfile_up) return nullptr; + // Cache xcoff binary. + if (!objfile_up->CreateBinary()) +return nullptr; + + if (!objfile_up->ParseHeader()) +return nullptr; + return objfile_up.release(); } +bool ObjectFileXCOFF::CreateBinary() { + if (m_binary) +return true; + + Log *log = GetLog(LLDBLog::Object); + + auto binary = llvm::object::XCOFFObjectFile::createObjectFile( + llvm::MemoryBufferRef(toStringRef(m_data.GetData()), +m_file.GetFilename().GetStringRef()), + file_magic::xcoff_object_64); + if (!binary) { +LLDB_LOG_ERROR(log, binary.takeError(), + "Failed to create binary for file ({1}): {0}", m_file); +return false; + } + + // Make sure we only handle XCOFF format. + m_binary = + llvm::unique_dyn_cast(std::move(*binary)); + if (!m_binary) +return false; + + LLDB_LOG(log, "this = {0}, module = {1} ({2}), file = {3}, binary = {4}", + this, GetModule().get(), GetModule()->GetSpecificationDescription(), + m_file.GetPath(), m_binary.get()); + return true; +} + ObjectFile *ObjectFileXCOFF::CreateMemoryInstance( const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) { @@ -136,13 +171,92 @@ bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp, return XCOFFHeaderSizeFromMagic(magic) != 0; } -bool ObjectFileXCOFF::ParseHeader() { return false; } +bool ObjectFileXCOFF::ParseHeader() { + ModuleSP module_sp(GetModule()); + if (module_sp) { +std::lock_guard guard(module_sp->GetMutex()); +lldb::offset_t offset = 0; + +if (ParseXCOFFHeader(m_data, &offset, m_xcoff_header)) { + m_data.SetAddressByteSize(GetAddressByteSize()); + if (m_xcoff_header.auxhdrsize > 0) +ParseXCOFFOptionalHeader(m_data, &offset); +} +return true; + } + + return false; +} + +bool ObjectFileXCOFF::ParseXCOFFHeader(lldb_private::DataExtractor &data, + lldb::offset_t *offset_ptr, + xcoff_header_t &xcoff_header) { + // FIXME: data.ValidOffsetForDataOfSize + xcoff_header.magic = data.GetU16(offset_ptr); + xcoff_header.nsects = data.GetU16(offset_ptr); + xcoff_header.modtime = data.GetU32(offset_ptr); + xcoff_header.symoff = data.GetU64(offset_ptr); + xcoff_header.auxhdrsize = data.GetU16(offset_ptr); + xcoff_header.flags = data.GetU16(offset_ptr); + xcoff_header.nsyms = data.GetU32(offset_ptr); + return true; +} + +bool ObjectFileXCOFF::ParseXCOFFOptionalHeader( +lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr) { + lldb::offset_t init_offset = *offset_ptr; + // FIXME: data.ValidOffsetForDataOfSize + m_xcoff_aux_header.AuxMagic = data.GetU16(offset_ptr); + m_xcoff_aux_header.Version = data.GetU16(offset_ptr); + m_xcoff_aux_header.ReservedForDebugger = data.GetU32(offset_ptr); + m_xcoff_aux_header.TextStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.DataStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.TOCAnchorAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.SecNumOfEntryPoint = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfTOC = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfLoader = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfBSS = da
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header Parsing (PR #116337)
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/116337 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 XCOFF Object File Header Parsing for AIX. This PR is an incremental PR to the base: #111814 Details about XCOFF file format on AIX: [XCOFF](https://www.ibm.com/docs/en/aix/7.3?topic=formats-xcoff-object-file-format) Review Request: @labath @DavidSpickett >From 0c63800bdcbadcfceed4c9a81305eda7d5a15960 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Fri, 15 Nov 2024 02:16:31 -0600 Subject: [PATCH] Added XCOFF Header Parsing --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 126 +- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 58 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 3be900f9a4bc9f..c06ece4347822d 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -81,9 +81,44 @@ ObjectFile *ObjectFileXCOFF::CreateInstance(const lldb::ModuleSP &module_sp, if (!objfile_up) return nullptr; + // Cache xcoff binary. + if (!objfile_up->CreateBinary()) +return nullptr; + + if (!objfile_up->ParseHeader()) +return nullptr; + return objfile_up.release(); } +bool ObjectFileXCOFF::CreateBinary() { + if (m_binary) +return true; + + Log *log = GetLog(LLDBLog::Object); + + auto binary = llvm::object::XCOFFObjectFile::createObjectFile( + llvm::MemoryBufferRef(toStringRef(m_data.GetData()), +m_file.GetFilename().GetStringRef()), + file_magic::xcoff_object_64); + if (!binary) { +LLDB_LOG_ERROR(log, binary.takeError(), + "Failed to create binary for file ({1}): {0}", m_file); +return false; + } + + // Make sure we only handle XCOFF format. + m_binary = + llvm::unique_dyn_cast(std::move(*binary)); + if (!m_binary) +return false; + + LLDB_LOG(log, "this = {0}, module = {1} ({2}), file = {3}, binary = {4}", + this, GetModule().get(), GetModule()->GetSpecificationDescription(), + m_file.GetPath(), m_binary.get()); + return true; +} + ObjectFile *ObjectFileXCOFF::CreateMemoryInstance( const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) { @@ -136,13 +171,92 @@ bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp, return XCOFFHeaderSizeFromMagic(magic) != 0; } -bool ObjectFileXCOFF::ParseHeader() { return false; } +bool ObjectFileXCOFF::ParseHeader() { + ModuleSP module_sp(GetModule()); + if (module_sp) { +std::lock_guard guard(module_sp->GetMutex()); +lldb::offset_t offset = 0; + +if (ParseXCOFFHeader(m_data, &offset, m_xcoff_header)) { + m_data.SetAddressByteSize(GetAddressByteSize()); + if (m_xcoff_header.auxhdrsize > 0) +ParseXCOFFOptionalHeader(m_data, &offset); +} +return true; + } + + return false; +} + +bool ObjectFileXCOFF::ParseXCOFFHeader(lldb_private::DataExtractor &data, + lldb::offset_t *offset_ptr, + xcoff_header_t &xcoff_header) { + // FIXME: data.ValidOffsetForDataOfSize + xcoff_header.magic = data.GetU16(offset_ptr); + xcoff_header.nsects = data.GetU16(offset_ptr); + xcoff_header.modtime = data.GetU32(offset_ptr); + xcoff_header.symoff = data.GetU64(offset_ptr); + xcoff_header.auxhdrsize = data.GetU16(offset_ptr); + xcoff_header.flags = data.GetU16(offset_ptr); + xcoff_header.nsyms = data.GetU32(offset_ptr); + return true; +} + +bool ObjectFileXCOFF::ParseXCOFFOptionalHeader( +lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr) { + lldb::offset_t init_offset = *offset_ptr; + // FIXME: data.ValidOffsetForDataOfSize + m_xcoff_aux_header.AuxMagic = data.GetU16(offset_ptr); + m_xcoff_aux_header.Version = data.GetU16(offset_ptr); + m_xcoff_aux_header.ReservedForDebugger = data.GetU32(offset_ptr); + m_xcoff_aux_header.TextStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.DataStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.TOCAnchorAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.SecNumOfEntryPoint = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfTOC = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfLoader = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfBSS = data.GetU16(offset_ptr); + m_xcoff_aux_head
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header Parsing (PR #116337)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/116337 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF Object File Header Parsing (PR #116337)
https://github.com/DhruvSrivastavaX edited https://github.com/llvm/llvm-project/pull/116337 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Header Parsing for XCOFF Object File in AIX (PR #116338)
DhruvSrivastavaX wrote: Hi @labath , not sure why the `Labelling new pull requests` check failed. Also, the build check didnt automatically start for this one. https://github.com/llvm/llvm-project/pull/116338 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Header Parsing for XCOFF Object File in AIX (PR #116338)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/116338 >From 0c63800bdcbadcfceed4c9a81305eda7d5a15960 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Fri, 15 Nov 2024 02:16:31 -0600 Subject: [PATCH 1/3] Added XCOFF Header Parsing --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 126 +- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 58 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 3be900f9a4bc9f..c06ece4347822d 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -81,9 +81,44 @@ ObjectFile *ObjectFileXCOFF::CreateInstance(const lldb::ModuleSP &module_sp, if (!objfile_up) return nullptr; + // Cache xcoff binary. + if (!objfile_up->CreateBinary()) +return nullptr; + + if (!objfile_up->ParseHeader()) +return nullptr; + return objfile_up.release(); } +bool ObjectFileXCOFF::CreateBinary() { + if (m_binary) +return true; + + Log *log = GetLog(LLDBLog::Object); + + auto binary = llvm::object::XCOFFObjectFile::createObjectFile( + llvm::MemoryBufferRef(toStringRef(m_data.GetData()), +m_file.GetFilename().GetStringRef()), + file_magic::xcoff_object_64); + if (!binary) { +LLDB_LOG_ERROR(log, binary.takeError(), + "Failed to create binary for file ({1}): {0}", m_file); +return false; + } + + // Make sure we only handle XCOFF format. + m_binary = + llvm::unique_dyn_cast(std::move(*binary)); + if (!m_binary) +return false; + + LLDB_LOG(log, "this = {0}, module = {1} ({2}), file = {3}, binary = {4}", + this, GetModule().get(), GetModule()->GetSpecificationDescription(), + m_file.GetPath(), m_binary.get()); + return true; +} + ObjectFile *ObjectFileXCOFF::CreateMemoryInstance( const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) { @@ -136,13 +171,92 @@ bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp, return XCOFFHeaderSizeFromMagic(magic) != 0; } -bool ObjectFileXCOFF::ParseHeader() { return false; } +bool ObjectFileXCOFF::ParseHeader() { + ModuleSP module_sp(GetModule()); + if (module_sp) { +std::lock_guard guard(module_sp->GetMutex()); +lldb::offset_t offset = 0; + +if (ParseXCOFFHeader(m_data, &offset, m_xcoff_header)) { + m_data.SetAddressByteSize(GetAddressByteSize()); + if (m_xcoff_header.auxhdrsize > 0) +ParseXCOFFOptionalHeader(m_data, &offset); +} +return true; + } + + return false; +} + +bool ObjectFileXCOFF::ParseXCOFFHeader(lldb_private::DataExtractor &data, + lldb::offset_t *offset_ptr, + xcoff_header_t &xcoff_header) { + // FIXME: data.ValidOffsetForDataOfSize + xcoff_header.magic = data.GetU16(offset_ptr); + xcoff_header.nsects = data.GetU16(offset_ptr); + xcoff_header.modtime = data.GetU32(offset_ptr); + xcoff_header.symoff = data.GetU64(offset_ptr); + xcoff_header.auxhdrsize = data.GetU16(offset_ptr); + xcoff_header.flags = data.GetU16(offset_ptr); + xcoff_header.nsyms = data.GetU32(offset_ptr); + return true; +} + +bool ObjectFileXCOFF::ParseXCOFFOptionalHeader( +lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr) { + lldb::offset_t init_offset = *offset_ptr; + // FIXME: data.ValidOffsetForDataOfSize + m_xcoff_aux_header.AuxMagic = data.GetU16(offset_ptr); + m_xcoff_aux_header.Version = data.GetU16(offset_ptr); + m_xcoff_aux_header.ReservedForDebugger = data.GetU32(offset_ptr); + m_xcoff_aux_header.TextStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.DataStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.TOCAnchorAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.SecNumOfEntryPoint = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfTOC = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfLoader = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfBSS = data.GetU16(offset_ptr); + m_xcoff_aux_header.MaxAlignOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.MaxAlignOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.ModuleType = data.GetU16(offset_ptr); + m_xcoff_aux_header.CpuFlag = data.GetU8(offset_ptr); + m_xcoff_aux_header.CpuType = data.GetU8(offset_ptr); + m_xcoff_aux_header.TextPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.DataPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.StackPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.FlagAndTDataAlignment = data.GetU8(offset_ptr); + m_xcoff_aux_header.TextSize = data.GetU64(offset_p
[Lldb-commits] [lldb] [lldb][AIX] Header Parsing for XCOFF Object File in AIX (PR #116338)
DhruvSrivastavaX wrote: > Do you actually need to parse the headers yourself? The reason for using the > llvm implementation was so that we can avoid that. FWICS, all of this data > should be available through the `(file|auxiliary)Header(32|64)` APIs. Okay, I'll take a look at that. > BTW, this is exactly the kind of granularity I was looking for. Happy to hear that! Will follow the similar practice. > I don't know, but I wouldn't be worried about that. The test failure is more > of a concern. Yeah, I think I missed the test case modification accordingly. Will update! https://github.com/llvm/llvm-project/pull/116338 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/118160 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 base files for NativeProcess Support for AIX. Will be adding further support in consequent incremental PR. Review Request: @labath @DavidSpickett >From 03a290e9c748540b69ca6df7fa9c4481f9cdd3d0 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Sat, 30 Nov 2024 01:14:15 -0600 Subject: [PATCH 1/2] Added base files for NativeProcess for AIX --- .../source/Plugins/Process/AIX/CMakeLists.txt | 14 + .../Plugins/Process/AIX/NativeProcessAIX.cpp | 288 ++ .../Plugins/Process/AIX/NativeProcessAIX.h| 134 lldb/source/Plugins/Process/CMakeLists.txt| 3 + 4 files changed, 439 insertions(+) create mode 100644 lldb/source/Plugins/Process/AIX/CMakeLists.txt create mode 100644 lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp create mode 100644 lldb/source/Plugins/Process/AIX/NativeProcessAIX.h diff --git a/lldb/source/Plugins/Process/AIX/CMakeLists.txt b/lldb/source/Plugins/Process/AIX/CMakeLists.txt new file mode 100644 index 00..4fabbe93022870 --- /dev/null +++ b/lldb/source/Plugins/Process/AIX/CMakeLists.txt @@ -0,0 +1,14 @@ +add_lldb_library(lldbPluginProcessAIX + NativeProcessAIX.cpp + + LINK_LIBS +lldbCore +lldbHost +lldbSymbol +lldbTarget +lldbUtility +lldbPluginProcessPOSIX +lldbPluginProcessUtility + LINK_COMPONENTS +Support + ) diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp new file mode 100644 index 00..6661693b2fc02b --- /dev/null +++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp @@ -0,0 +1,288 @@ +//===-- NativeProcessAIX.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 "NativeProcessAIX.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "NativeThreadAIX.h" +#include "Plugins/Process/POSIX/ProcessPOSIXLog.h" +#include "lldb/Core/ModuleSpec.h" +#include "lldb/Host/Host.h" +#include "lldb/Host/HostProcess.h" +#include "lldb/Host/ProcessLaunchInfo.h" +#include "lldb/Host/PseudoTerminal.h" +#include "lldb/Host/ThreadLauncher.h" +#include "lldb/Host/common/NativeRegisterContext.h" +#include "lldb/Host/aix/Ptrace.h" +#include "lldb/Host/posix/ProcessLauncherPosixFork.h" +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/RegisterValue.h" +#include "lldb/Utility/State.h" +#include "lldb/Utility/Status.h" +#include "lldb/Utility/StringExtractor.h" +#include "llvm/ADT/ScopeExit.h" +#include "llvm/Support/Errno.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Threading.h" +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __aarch64__ +#include +#include +#endif + +// Support hardware breakpoints in case it has not been defined +#ifndef TRAP_HWBKPT +#define TRAP_HWBKPT 4 +#endif + +#ifndef HWCAP2_MTE +#define HWCAP2_MTE (1 << 18) +#endif + +using namespace lldb; +using namespace lldb_private; +using namespace lldb_private::process_aix; +using namespace llvm; + +static constexpr unsigned k_ptrace_word_size = sizeof(void *); +static_assert(sizeof(long) >= k_ptrace_word_size, + "Size of long must be larger than ptrace word size"); + +// Simple helper function to ensure flags are enabled on the given file +// descriptor. +static Status EnsureFDFlags(int fd, int flags) { + Status error; + + int status = fcntl(fd, F_GETFL); + if (status == -1) { +error = Status::FromErrno(); +return error; + } + + if (fcntl(fd, F_SETFL, status | flags) == -1) { +error = Status::FromErrno(); +return error; + } + + return error; +} + +NativeProcessAIX::Manager::Manager(MainLoop &mainloop) +: NativeProcessProtocol::Manager(mainloop) { + Status status; + m_sigchld_handle = mainloop.RegisterSignal( + SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status); + assert(m_sigchld_handle && status.Success()); +} + +// Public Static Methods + +llvm::Expected> +NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info, +Nati
[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/118160 >From 03a290e9c748540b69ca6df7fa9c4481f9cdd3d0 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Sat, 30 Nov 2024 01:14:15 -0600 Subject: [PATCH 1/3] Added base files for NativeProcess for AIX --- .../source/Plugins/Process/AIX/CMakeLists.txt | 14 + .../Plugins/Process/AIX/NativeProcessAIX.cpp | 288 ++ .../Plugins/Process/AIX/NativeProcessAIX.h| 134 lldb/source/Plugins/Process/CMakeLists.txt| 3 + 4 files changed, 439 insertions(+) create mode 100644 lldb/source/Plugins/Process/AIX/CMakeLists.txt create mode 100644 lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp create mode 100644 lldb/source/Plugins/Process/AIX/NativeProcessAIX.h diff --git a/lldb/source/Plugins/Process/AIX/CMakeLists.txt b/lldb/source/Plugins/Process/AIX/CMakeLists.txt new file mode 100644 index 00..4fabbe93022870 --- /dev/null +++ b/lldb/source/Plugins/Process/AIX/CMakeLists.txt @@ -0,0 +1,14 @@ +add_lldb_library(lldbPluginProcessAIX + NativeProcessAIX.cpp + + LINK_LIBS +lldbCore +lldbHost +lldbSymbol +lldbTarget +lldbUtility +lldbPluginProcessPOSIX +lldbPluginProcessUtility + LINK_COMPONENTS +Support + ) diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp new file mode 100644 index 00..6661693b2fc02b --- /dev/null +++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp @@ -0,0 +1,288 @@ +//===-- NativeProcessAIX.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 "NativeProcessAIX.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "NativeThreadAIX.h" +#include "Plugins/Process/POSIX/ProcessPOSIXLog.h" +#include "lldb/Core/ModuleSpec.h" +#include "lldb/Host/Host.h" +#include "lldb/Host/HostProcess.h" +#include "lldb/Host/ProcessLaunchInfo.h" +#include "lldb/Host/PseudoTerminal.h" +#include "lldb/Host/ThreadLauncher.h" +#include "lldb/Host/common/NativeRegisterContext.h" +#include "lldb/Host/aix/Ptrace.h" +#include "lldb/Host/posix/ProcessLauncherPosixFork.h" +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/RegisterValue.h" +#include "lldb/Utility/State.h" +#include "lldb/Utility/Status.h" +#include "lldb/Utility/StringExtractor.h" +#include "llvm/ADT/ScopeExit.h" +#include "llvm/Support/Errno.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Threading.h" +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __aarch64__ +#include +#include +#endif + +// Support hardware breakpoints in case it has not been defined +#ifndef TRAP_HWBKPT +#define TRAP_HWBKPT 4 +#endif + +#ifndef HWCAP2_MTE +#define HWCAP2_MTE (1 << 18) +#endif + +using namespace lldb; +using namespace lldb_private; +using namespace lldb_private::process_aix; +using namespace llvm; + +static constexpr unsigned k_ptrace_word_size = sizeof(void *); +static_assert(sizeof(long) >= k_ptrace_word_size, + "Size of long must be larger than ptrace word size"); + +// Simple helper function to ensure flags are enabled on the given file +// descriptor. +static Status EnsureFDFlags(int fd, int flags) { + Status error; + + int status = fcntl(fd, F_GETFL); + if (status == -1) { +error = Status::FromErrno(); +return error; + } + + if (fcntl(fd, F_SETFL, status | flags) == -1) { +error = Status::FromErrno(); +return error; + } + + return error; +} + +NativeProcessAIX::Manager::Manager(MainLoop &mainloop) +: NativeProcessProtocol::Manager(mainloop) { + Status status; + m_sigchld_handle = mainloop.RegisterSignal( + SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status); + assert(m_sigchld_handle && status.Success()); +} + +// Public Static Methods + +llvm::Expected> +NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info, +NativeDelegate &native_delegate) { + Log *log = GetLog(POSIXLog::Process); + + Status status; + ::pid_t pid = ProcessLauncherPosixFork() +.LaunchProcess(launch_info, status) +.GetProcessId(); + LLDB_LOG(log, "pid = {0:x}", pid); + if (status.Fail()) { +LLDB_LOG(log, "failed to launch process: {0}", status); +return status.ToError(); + } + + // Wait for the child process to trap on its call to execve. + int wstatus = 0; + ::p
[Lldb-commits] [clang] [lldb] [llvm] Extending LLDB to work on AIX (PR #102601)
DhruvSrivastavaX wrote: > BTW, the main loop changes are something that you should be able to upstream > quite easily. It sounds like the main problem is that you don't have a ppoll > syscall, but the last round of changes means that ppoll is not actually > necessary for its operation (the only reason to use it is the increased > precision) Hmm. That is good idea too. I think we can work on that. Thanks!! https://github.com/llvm/llvm-project/pull/102601 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/118160 >From 03a290e9c748540b69ca6df7fa9c4481f9cdd3d0 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Sat, 30 Nov 2024 01:14:15 -0600 Subject: [PATCH 1/4] Added base files for NativeProcess for AIX --- .../source/Plugins/Process/AIX/CMakeLists.txt | 14 + .../Plugins/Process/AIX/NativeProcessAIX.cpp | 288 ++ .../Plugins/Process/AIX/NativeProcessAIX.h| 134 lldb/source/Plugins/Process/CMakeLists.txt| 3 + 4 files changed, 439 insertions(+) create mode 100644 lldb/source/Plugins/Process/AIX/CMakeLists.txt create mode 100644 lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp create mode 100644 lldb/source/Plugins/Process/AIX/NativeProcessAIX.h diff --git a/lldb/source/Plugins/Process/AIX/CMakeLists.txt b/lldb/source/Plugins/Process/AIX/CMakeLists.txt new file mode 100644 index 00..4fabbe93022870 --- /dev/null +++ b/lldb/source/Plugins/Process/AIX/CMakeLists.txt @@ -0,0 +1,14 @@ +add_lldb_library(lldbPluginProcessAIX + NativeProcessAIX.cpp + + LINK_LIBS +lldbCore +lldbHost +lldbSymbol +lldbTarget +lldbUtility +lldbPluginProcessPOSIX +lldbPluginProcessUtility + LINK_COMPONENTS +Support + ) diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp new file mode 100644 index 00..6661693b2fc02b --- /dev/null +++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp @@ -0,0 +1,288 @@ +//===-- NativeProcessAIX.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 "NativeProcessAIX.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "NativeThreadAIX.h" +#include "Plugins/Process/POSIX/ProcessPOSIXLog.h" +#include "lldb/Core/ModuleSpec.h" +#include "lldb/Host/Host.h" +#include "lldb/Host/HostProcess.h" +#include "lldb/Host/ProcessLaunchInfo.h" +#include "lldb/Host/PseudoTerminal.h" +#include "lldb/Host/ThreadLauncher.h" +#include "lldb/Host/common/NativeRegisterContext.h" +#include "lldb/Host/aix/Ptrace.h" +#include "lldb/Host/posix/ProcessLauncherPosixFork.h" +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/RegisterValue.h" +#include "lldb/Utility/State.h" +#include "lldb/Utility/Status.h" +#include "lldb/Utility/StringExtractor.h" +#include "llvm/ADT/ScopeExit.h" +#include "llvm/Support/Errno.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Threading.h" +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __aarch64__ +#include +#include +#endif + +// Support hardware breakpoints in case it has not been defined +#ifndef TRAP_HWBKPT +#define TRAP_HWBKPT 4 +#endif + +#ifndef HWCAP2_MTE +#define HWCAP2_MTE (1 << 18) +#endif + +using namespace lldb; +using namespace lldb_private; +using namespace lldb_private::process_aix; +using namespace llvm; + +static constexpr unsigned k_ptrace_word_size = sizeof(void *); +static_assert(sizeof(long) >= k_ptrace_word_size, + "Size of long must be larger than ptrace word size"); + +// Simple helper function to ensure flags are enabled on the given file +// descriptor. +static Status EnsureFDFlags(int fd, int flags) { + Status error; + + int status = fcntl(fd, F_GETFL); + if (status == -1) { +error = Status::FromErrno(); +return error; + } + + if (fcntl(fd, F_SETFL, status | flags) == -1) { +error = Status::FromErrno(); +return error; + } + + return error; +} + +NativeProcessAIX::Manager::Manager(MainLoop &mainloop) +: NativeProcessProtocol::Manager(mainloop) { + Status status; + m_sigchld_handle = mainloop.RegisterSignal( + SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status); + assert(m_sigchld_handle && status.Success()); +} + +// Public Static Methods + +llvm::Expected> +NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info, +NativeDelegate &native_delegate) { + Log *log = GetLog(POSIXLog::Process); + + Status status; + ::pid_t pid = ProcessLauncherPosixFork() +.LaunchProcess(launch_info, status) +.GetProcessId(); + LLDB_LOG(log, "pid = {0:x}", pid); + if (status.Fail()) { +LLDB_LOG(log, "failed to launch process: {0}", status); +return status.ToError(); + } + + // Wait for the child process to trap on its call to execve. + int wstatus = 0; + ::p
[Lldb-commits] [lldb] [lldb][AIX] Header Parsing for XCOFF Object File in AIX (PR #116338)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/116338 >From 0c63800bdcbadcfceed4c9a81305eda7d5a15960 Mon Sep 17 00:00:00 2001 From: Dhruv-Srivastava Date: Fri, 15 Nov 2024 02:16:31 -0600 Subject: [PATCH 1/6] Added XCOFF Header Parsing --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 126 +- .../ObjectFile/XCOFF/ObjectFileXCOFF.h| 58 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 3be900f9a4bc9f..c06ece4347822d 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -81,9 +81,44 @@ ObjectFile *ObjectFileXCOFF::CreateInstance(const lldb::ModuleSP &module_sp, if (!objfile_up) return nullptr; + // Cache xcoff binary. + if (!objfile_up->CreateBinary()) +return nullptr; + + if (!objfile_up->ParseHeader()) +return nullptr; + return objfile_up.release(); } +bool ObjectFileXCOFF::CreateBinary() { + if (m_binary) +return true; + + Log *log = GetLog(LLDBLog::Object); + + auto binary = llvm::object::XCOFFObjectFile::createObjectFile( + llvm::MemoryBufferRef(toStringRef(m_data.GetData()), +m_file.GetFilename().GetStringRef()), + file_magic::xcoff_object_64); + if (!binary) { +LLDB_LOG_ERROR(log, binary.takeError(), + "Failed to create binary for file ({1}): {0}", m_file); +return false; + } + + // Make sure we only handle XCOFF format. + m_binary = + llvm::unique_dyn_cast(std::move(*binary)); + if (!m_binary) +return false; + + LLDB_LOG(log, "this = {0}, module = {1} ({2}), file = {3}, binary = {4}", + this, GetModule().get(), GetModule()->GetSpecificationDescription(), + m_file.GetPath(), m_binary.get()); + return true; +} + ObjectFile *ObjectFileXCOFF::CreateMemoryInstance( const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) { @@ -136,13 +171,92 @@ bool ObjectFileXCOFF::MagicBytesMatch(DataBufferSP &data_sp, return XCOFFHeaderSizeFromMagic(magic) != 0; } -bool ObjectFileXCOFF::ParseHeader() { return false; } +bool ObjectFileXCOFF::ParseHeader() { + ModuleSP module_sp(GetModule()); + if (module_sp) { +std::lock_guard guard(module_sp->GetMutex()); +lldb::offset_t offset = 0; + +if (ParseXCOFFHeader(m_data, &offset, m_xcoff_header)) { + m_data.SetAddressByteSize(GetAddressByteSize()); + if (m_xcoff_header.auxhdrsize > 0) +ParseXCOFFOptionalHeader(m_data, &offset); +} +return true; + } + + return false; +} + +bool ObjectFileXCOFF::ParseXCOFFHeader(lldb_private::DataExtractor &data, + lldb::offset_t *offset_ptr, + xcoff_header_t &xcoff_header) { + // FIXME: data.ValidOffsetForDataOfSize + xcoff_header.magic = data.GetU16(offset_ptr); + xcoff_header.nsects = data.GetU16(offset_ptr); + xcoff_header.modtime = data.GetU32(offset_ptr); + xcoff_header.symoff = data.GetU64(offset_ptr); + xcoff_header.auxhdrsize = data.GetU16(offset_ptr); + xcoff_header.flags = data.GetU16(offset_ptr); + xcoff_header.nsyms = data.GetU32(offset_ptr); + return true; +} + +bool ObjectFileXCOFF::ParseXCOFFOptionalHeader( +lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr) { + lldb::offset_t init_offset = *offset_ptr; + // FIXME: data.ValidOffsetForDataOfSize + m_xcoff_aux_header.AuxMagic = data.GetU16(offset_ptr); + m_xcoff_aux_header.Version = data.GetU16(offset_ptr); + m_xcoff_aux_header.ReservedForDebugger = data.GetU32(offset_ptr); + m_xcoff_aux_header.TextStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.DataStartAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.TOCAnchorAddr = data.GetU64(offset_ptr); + m_xcoff_aux_header.SecNumOfEntryPoint = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfTOC = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfLoader = data.GetU16(offset_ptr); + m_xcoff_aux_header.SecNumOfBSS = data.GetU16(offset_ptr); + m_xcoff_aux_header.MaxAlignOfText = data.GetU16(offset_ptr); + m_xcoff_aux_header.MaxAlignOfData = data.GetU16(offset_ptr); + m_xcoff_aux_header.ModuleType = data.GetU16(offset_ptr); + m_xcoff_aux_header.CpuFlag = data.GetU8(offset_ptr); + m_xcoff_aux_header.CpuType = data.GetU8(offset_ptr); + m_xcoff_aux_header.TextPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.DataPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.StackPageSize = data.GetU8(offset_ptr); + m_xcoff_aux_header.FlagAndTDataAlignment = data.GetU8(offset_ptr); + m_xcoff_aux_header.TextSize = data.GetU64(offset_p
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
@@ -0,0 +1,213 @@ +//===-- HostInfoAIX.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 "lldb/Host/aix/HostInfoAIX.h" +#include "lldb/Host/Config.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" + +#include "llvm/Support/Threading.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace lldb_private; + +namespace { +struct HostInfoAIXFields { + llvm::once_flag m_distribution_once_flag; + std::string m_distribution_id; + llvm::once_flag m_os_version_once_flag; + llvm::VersionTuple m_os_version; +}; +} // namespace + +static HostInfoAIXFields *g_fields = nullptr; + +void HostInfoAIX::Initialize(SharedLibraryDirectoryHelper *helper) { + HostInfoPosix::Initialize(helper); + + g_fields = new HostInfoAIXFields(); +} + +void HostInfoAIX::Terminate() { + assert(g_fields && "Missing call to Initialize?"); + delete g_fields; + g_fields = nullptr; + HostInfoBase::Terminate(); +} + +llvm::VersionTuple HostInfoAIX::GetOSVersion() { + assert(g_fields && "Missing call to Initialize?"); + llvm::call_once(g_fields->m_os_version_once_flag, []() { +struct utsname un; +if (uname(&un) != 0) + return; + +llvm::StringRef release = un.release; +// The kernel release string can include a lot of stuff (e.g. +// 4.9.0-6-amd64). We're only interested in the numbered prefix. +release = release.substr(0, release.find_first_not_of("0123456789.")); +g_fields->m_os_version.tryParse(release); + }); + + return g_fields->m_os_version; +} + +std::optional HostInfoAIX::GetOSBuildString() { + struct utsname un; + ::memset(&un, 0, sizeof(utsname)); + + if (uname(&un) < 0) +return std::nullopt; + + return std::string(un.release); +} + +llvm::StringRef HostInfoAIX::GetDistributionId() { DhruvSrivastavaX wrote: I understand your concern, and I would truly appreciate your guidance as I work to fill the gaps in my understanding of the flow during these incremental merges. My goal is the same as yours: to keep the code as efficient and maintainable as possible while making the process smoother over time, and please be assured that I will keep all your concerns and suggestions into account! https://github.com/llvm/llvm-project/pull/117906 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
@@ -0,0 +1,213 @@ +//===-- HostInfoAIX.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 "lldb/Host/aix/HostInfoAIX.h" +#include "lldb/Host/Config.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" + +#include "llvm/Support/Threading.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace lldb_private; + +namespace { +struct HostInfoAIXFields { + llvm::once_flag m_distribution_once_flag; + std::string m_distribution_id; + llvm::once_flag m_os_version_once_flag; + llvm::VersionTuple m_os_version; +}; +} // namespace + +static HostInfoAIXFields *g_fields = nullptr; + +void HostInfoAIX::Initialize(SharedLibraryDirectoryHelper *helper) { + HostInfoPosix::Initialize(helper); + + g_fields = new HostInfoAIXFields(); +} + +void HostInfoAIX::Terminate() { + assert(g_fields && "Missing call to Initialize?"); + delete g_fields; + g_fields = nullptr; + HostInfoBase::Terminate(); +} + +llvm::VersionTuple HostInfoAIX::GetOSVersion() { + assert(g_fields && "Missing call to Initialize?"); + llvm::call_once(g_fields->m_os_version_once_flag, []() { +struct utsname un; +if (uname(&un) != 0) + return; + +llvm::StringRef release = un.release; +// The kernel release string can include a lot of stuff (e.g. +// 4.9.0-6-amd64). We're only interested in the numbered prefix. +release = release.substr(0, release.find_first_not_of("0123456789.")); +g_fields->m_os_version.tryParse(release); + }); + + return g_fields->m_os_version; +} + +std::optional HostInfoAIX::GetOSBuildString() { + struct utsname un; + ::memset(&un, 0, sizeof(utsname)); + + if (uname(&un) < 0) +return std::nullopt; + + return std::string(un.release); +} + +llvm::StringRef HostInfoAIX::GetDistributionId() { + assert(g_fields && "Missing call to Initialize?"); + // Try to run 'lbs_release -i', and use that response for the distribution + // id. + llvm::call_once(g_fields->m_distribution_once_flag, []() { +Log *log = GetLog(LLDBLog::Host); +LLDB_LOGF(log, "attempting to determine AIX distribution..."); + +// check if the lsb_release command exists at one of the following paths +const char *const exe_paths[] = {"/bin/lsb_release", + "/usr/bin/lsb_release"}; + +for (size_t exe_index = 0; + exe_index < sizeof(exe_paths) / sizeof(exe_paths[0]); ++exe_index) { + const char *const get_distribution_info_exe = exe_paths[exe_index]; + if (access(get_distribution_info_exe, F_OK)) { +// this exe doesn't exist, move on to next exe +LLDB_LOGF(log, "executable doesn't exist: %s", + get_distribution_info_exe); +continue; + } + + // execute the distribution-retrieval command, read output + std::string get_distribution_id_command(get_distribution_info_exe); + get_distribution_id_command += " -i"; + + FILE *file = popen(get_distribution_id_command.c_str(), "r"); + if (!file) { +LLDB_LOGF(log, + "failed to run command: \"%s\", cannot retrieve " + "platform information", + get_distribution_id_command.c_str()); +break; + } + + // retrieve the distribution id string. + char distribution_id[256] = {'\0'}; + if (fgets(distribution_id, sizeof(distribution_id) - 1, file) != + nullptr) { +LLDB_LOGF(log, "distribution id command returned \"%s\"", + distribution_id); + +const char *const distributor_id_key = "Distributor ID:\t"; +if (strstr(distribution_id, distributor_id_key)) { + // strip newlines + std::string id_string(distribution_id + strlen(distributor_id_key)); + llvm::erase(id_string, '\n'); + + // lower case it and convert whitespace to underscores + std::transform( + id_string.begin(), id_string.end(), id_string.begin(), + [](char ch) { return tolower(isspace(ch) ? '_' : ch); }); + + g_fields->m_distribution_id = id_string; + LLDB_LOGF(log, "distribution id set to \"%s\"", +g_fields->m_distribution_id.c_str()); +} else { + LLDB_LOGF(log, "failed to find \"%s\" field in \"%s\"", +distributor_id_key, distribution_id); +} + } else { +LLDB_LOGF(log, + "failed to retrieve distribution id, \"%s\" returned no" + " lines", + get_distribution_id_command.c_str()); + } + + // clean up the file + p