-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[lldb][llvm][AIX] Added support for getProcFile with TID #142586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-lldb Author: Hemang Gadhavi (HemangGadhavi) ChangesThis PR is in reference to porting LLDB on AIX.
Full diff: https://github.com/llvm/llvm-project/pull/142586.diff 5 Files Affected:
diff --git a/lldb/include/lldb/Host/aix/Support.h b/lldb/include/lldb/Host/aix/Support.h
new file mode 100644
index 0000000000000..f02a1904b09fa
--- /dev/null
+++ b/lldb/include/lldb/Host/aix/Support.h
@@ -0,0 +1,23 @@
+//===-- Support.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_SUPPORT_H
+#define LLDB_HOST_AIX_SUPPORT_H
+
+#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include <memory>
+
+namespace lldb_private {
+
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file);
+
+} // namespace lldb_private
+
+#endif // #ifndef LLDB_HOST_AIX_SUPPORT_H
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index 90814b1bed4c8..d19e4edd4cf56 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -142,6 +142,7 @@ else()
add_host_subdirectory(aix
aix/Host.cpp
aix/HostInfoAIX.cpp
+ aix/Support.cpp
)
endif()
endif()
diff --git a/lldb/source/Host/aix/Support.cpp b/lldb/source/Host/aix/Support.cpp
new file mode 100644
index 0000000000000..afd975565ff2f
--- /dev/null
+++ b/lldb/source/Host/aix/Support.cpp
@@ -0,0 +1,24 @@
+//===-- Support.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/Support.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+lldb_private::getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file) {
+ Log *log = GetLog(LLDBLog::Host);
+ std::string File =
+ ("/proc/" + llvm::Twine(pid) + "/lwp/" + llvm::Twine(tid) + "/" + file)
+ .str();
+ auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
+ if (!Ret)
+ LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
+ return Ret;
+}
diff --git a/lldb/unittests/Host/posix/SupportTest.cpp b/lldb/unittests/Host/posix/SupportTest.cpp
index f3976db755943..e4d7ba89fece6 100644
--- a/lldb/unittests/Host/posix/SupportTest.cpp
+++ b/lldb/unittests/Host/posix/SupportTest.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/posix/Support.h"
+#include "lldb/Host/aix/Support.h"
#include "llvm/Support/Threading.h"
#include "gtest/gtest.h"
@@ -19,3 +20,11 @@ TEST(Support, getProcFile_Pid) {
ASSERT_TRUE(*BufferOrError);
}
#endif // #ifndef __APPLE__
+
+#if defined(_AIX) && defined(LLVM_ENABLE_THREADING)
+TEST(Support, getProcFile_Tid) {
+ auto BufferOrError = getProcFile(getpid(), llvm::get_threadid(), "lwpstatus");
+ ASSERT_TRUE(BufferOrError);
+ ASSERT_TRUE(*BufferOrError);
+}
+#endif // #ifdef _AIX && LLVM_ENABLE_THREADING
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 15a5b008604c3..742660d5bea75 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -142,6 +142,8 @@ uint64_t llvm::get_threadid() {
return uint64_t(gettid());
#elif defined(__linux__)
return uint64_t(syscall(__NR_gettid));
+#elif defined(_AIX)
+ return uint64_t(thread_self());
#else
return uint64_t(pthread_self());
#endif
|
@llvm/pr-subscribers-llvm-support Author: Hemang Gadhavi (HemangGadhavi) ChangesThis PR is in reference to porting LLDB on AIX.
Full diff: https://github.com/llvm/llvm-project/pull/142586.diff 5 Files Affected:
diff --git a/lldb/include/lldb/Host/aix/Support.h b/lldb/include/lldb/Host/aix/Support.h
new file mode 100644
index 0000000000000..f02a1904b09fa
--- /dev/null
+++ b/lldb/include/lldb/Host/aix/Support.h
@@ -0,0 +1,23 @@
+//===-- Support.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_SUPPORT_H
+#define LLDB_HOST_AIX_SUPPORT_H
+
+#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include <memory>
+
+namespace lldb_private {
+
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file);
+
+} // namespace lldb_private
+
+#endif // #ifndef LLDB_HOST_AIX_SUPPORT_H
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index 90814b1bed4c8..d19e4edd4cf56 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -142,6 +142,7 @@ else()
add_host_subdirectory(aix
aix/Host.cpp
aix/HostInfoAIX.cpp
+ aix/Support.cpp
)
endif()
endif()
diff --git a/lldb/source/Host/aix/Support.cpp b/lldb/source/Host/aix/Support.cpp
new file mode 100644
index 0000000000000..afd975565ff2f
--- /dev/null
+++ b/lldb/source/Host/aix/Support.cpp
@@ -0,0 +1,24 @@
+//===-- Support.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/Support.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+lldb_private::getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file) {
+ Log *log = GetLog(LLDBLog::Host);
+ std::string File =
+ ("/proc/" + llvm::Twine(pid) + "/lwp/" + llvm::Twine(tid) + "/" + file)
+ .str();
+ auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
+ if (!Ret)
+ LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
+ return Ret;
+}
diff --git a/lldb/unittests/Host/posix/SupportTest.cpp b/lldb/unittests/Host/posix/SupportTest.cpp
index f3976db755943..e4d7ba89fece6 100644
--- a/lldb/unittests/Host/posix/SupportTest.cpp
+++ b/lldb/unittests/Host/posix/SupportTest.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/posix/Support.h"
+#include "lldb/Host/aix/Support.h"
#include "llvm/Support/Threading.h"
#include "gtest/gtest.h"
@@ -19,3 +20,11 @@ TEST(Support, getProcFile_Pid) {
ASSERT_TRUE(*BufferOrError);
}
#endif // #ifndef __APPLE__
+
+#if defined(_AIX) && defined(LLVM_ENABLE_THREADING)
+TEST(Support, getProcFile_Tid) {
+ auto BufferOrError = getProcFile(getpid(), llvm::get_threadid(), "lwpstatus");
+ ASSERT_TRUE(BufferOrError);
+ ASSERT_TRUE(*BufferOrError);
+}
+#endif // #ifdef _AIX && LLVM_ENABLE_THREADING
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 15a5b008604c3..742660d5bea75 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -142,6 +142,8 @@ uint64_t llvm::get_threadid() {
return uint64_t(gettid());
#elif defined(__linux__)
return uint64_t(syscall(__NR_gettid));
+#elif defined(_AIX)
+ return uint64_t(thread_self());
#else
return uint64_t(pthread_self());
#endif
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identical code to Linux apart from /lwp/
in place of /task/
. Wondered if we could share that but as long as it remains identical, we could always do it later if we want.
It would be something like getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file, const llvm::Twine &task_folder)
. Then each would implement the current call by passing in the right name.
By the time we've done that, we probably have the same number of lines again, but with more layers.
So in summary, LGTM :)
Thanks @HemangGadhavi , just add a link to the ibm doc for reference. |
Thanks @DhruvSrivastavaX updated in description. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/169/builds/11975 Here is the relevant piece of the build log for the reference
|
@labath @DavidSpickett |
The failure is unrelated, ignore it. |
Thanks @DavidSpickett |
This PR is in reference to porting LLDB on AIX.
Link to discussions on llvm discourse and github:
The complete changes for porting are present in this draft PR:
Extending LLDB to work on AIX #102601
@labath @DhruvSrivastavaX