Skip to content

Commit 6d4bccb

Browse files
HemangGadhavirorth
authored andcommitted
[lldb][llvm][AIX] Added support for getProcFile with TID (llvm#142586)
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. llvm#101657 The complete changes for porting are present in this draft PR: llvm#102601 - Added changes to getProcFile() with threadID, including testcase for AIX. - Added support for AIX to get_threadid() from llvm.
1 parent e620f95 commit 6d4bccb

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

lldb/include/lldb/Host/aix/Support.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Support.h -----------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_HOST_AIX_SUPPORT_H
10+
#define LLDB_HOST_AIX_SUPPORT_H
11+
12+
#include "llvm/Support/ErrorOr.h"
13+
#include "llvm/Support/MemoryBuffer.h"
14+
#include <memory>
15+
16+
namespace lldb_private {
17+
18+
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
19+
getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file);
20+
21+
} // namespace lldb_private
22+
23+
#endif // #ifndef LLDB_HOST_AIX_SUPPORT_H

lldb/source/Host/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ else()
142142
add_host_subdirectory(aix
143143
aix/Host.cpp
144144
aix/HostInfoAIX.cpp
145+
aix/Support.cpp
145146
)
146147
endif()
147148
endif()

lldb/source/Host/aix/Support.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===-- Support.cpp -------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "lldb/Host/aix/Support.h"
10+
#include "lldb/Utility/LLDBLog.h"
11+
#include "lldb/Utility/Log.h"
12+
#include "llvm/Support/MemoryBuffer.h"
13+
14+
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
15+
lldb_private::getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file) {
16+
Log *log = GetLog(LLDBLog::Host);
17+
std::string File =
18+
("/proc/" + llvm::Twine(pid) + "/lwp/" + llvm::Twine(tid) + "/" + file)
19+
.str();
20+
auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
21+
if (!Ret)
22+
LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
23+
return Ret;
24+
}

lldb/unittests/Host/posix/SupportTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Host/posix/Support.h"
10+
#include "lldb/Host/aix/Support.h"
1011
#include "llvm/Support/Threading.h"
1112
#include "gtest/gtest.h"
1213

@@ -19,3 +20,11 @@ TEST(Support, getProcFile_Pid) {
1920
ASSERT_TRUE(*BufferOrError);
2021
}
2122
#endif // #ifndef __APPLE__
23+
24+
#if defined(_AIX) && defined(LLVM_ENABLE_THREADING)
25+
TEST(Support, getProcFile_Tid) {
26+
auto BufferOrError = getProcFile(getpid(), llvm::get_threadid(), "lwpstatus");
27+
ASSERT_TRUE(BufferOrError);
28+
ASSERT_TRUE(*BufferOrError);
29+
}
30+
#endif // #ifdef _AIX && LLVM_ENABLE_THREADING

llvm/lib/Support/Unix/Threading.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ uint64_t llvm::get_threadid() {
142142
return uint64_t(gettid());
143143
#elif defined(__linux__)
144144
return uint64_t(syscall(__NR_gettid));
145+
#elif defined(_AIX)
146+
return uint64_t(thread_self());
145147
#else
146148
return uint64_t(pthread_self());
147149
#endif

0 commit comments

Comments
 (0)