Skip to content

[lldb][AIX] Taking Linux Host Info header's base for AIX #106910

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lldb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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__")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be defining a reserved identifier. Also, isn't there an existing macro that we could test use to check if we're on AIX?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be really helpful, if we can decide on a better alternative.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't really answer my question. Are there predefined compiler macros that we could use? I'd be surprised if there weren't any, as every platform I know of has some. FWIW, these are the predefined macros on linux: https://godbolt.org/z/EG9fKaxMv

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is _AIX at least in clang: https://godbolt.org/z/95MzjcsKn

And according to this (totally official, legit) doc (https://www.lnf.infn.it/computing/doc/aixcxx/html/language/ref/rnmcradd.htm) they exist for the AIX system compiler as well. I'm sure you can find the proper page :)

void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,

If for some reason that's not going to work, then we would use something like LLDB_... as we have done for LLDB_ENABLE_LIBXML2 and friends.

(but I'm yet to look at the whole PR so I don't know yet)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. If we need a cmake generated definition, add that in its own PR along with anything that uses it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, with something that uses it. I'm not asking you to look into the future and know all possible uses.

endif()

# Define the LLDB_CONFIGURATION_xxx matching the build type.
if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
add_definitions(-DLLDB_CONFIGURATION_DEBUG)
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Host/HostGetOpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <getopt.h>
#include <unistd.h>
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/Host/HostInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions lldb/include/lldb/Host/aix/AbstractSocket.h
Original file line number Diff line number Diff line change
@@ -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;
};
} // namespace lldb_private

#endif // ifndef liblldb_AbstractSocket_h_
22 changes: 22 additions & 0 deletions lldb/include/lldb/Host/aix/Host.h
Original file line number Diff line number Diff line change
@@ -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 <optional>

namespace lldb_private {

// Get PID (i.e. the primary thread ID) corresponding to the specified TID.
std::optional<lldb::pid_t> getPIDForTID(lldb::pid_t tid);

} // namespace lldb_private

#endif // #ifndef LLDB_HOST_LINUX_HOST_H
43 changes: 43 additions & 0 deletions lldb/include/lldb/Host/aix/HostInfoAIX.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===-- HostInfoLinux.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_HostInfoLinux_h_
#define lldb_Host_linux_HostInfoLinux_h_

#include "lldb/Host/posix/HostInfoPosix.h"
#include "lldb/Utility/FileSpec.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/VersionTuple.h"

#include <optional>
#include <string>

namespace lldb_private {

class HostInfoLinux : public HostInfoPosix {
friend class HostInfoBase;

public:
static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr);
static void Terminate();

static llvm::VersionTuple GetOSVersion();
static std::optional<std::string> 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
60 changes: 60 additions & 0 deletions lldb/include/lldb/Host/aix/Ptrace.h
Original file line number Diff line number Diff line change
@@ -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 <sys/ptrace.h>

#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_
29 changes: 29 additions & 0 deletions lldb/include/lldb/Host/aix/Support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- 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_LINUX_SUPPORT_H
#define LLDB_HOST_LINUX_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);

llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getProcFile(::pid_t pid, const llvm::Twine &file);

llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getProcFile(const llvm::Twine &file);

} // namespace lldb_private

#endif // #ifndef LLDB_HOST_LINUX_SUPPORT_H
23 changes: 23 additions & 0 deletions lldb/include/lldb/Host/aix/Uio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Uio.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_Host_linux_Uio_h_
#define liblldb_Host_linux_Uio_h_

#include "lldb/Host/Config.h"
#include <sys/uio.h>

// We shall provide our own implementation of process_vm_readv if it is not
// present
#if !HAVE_PROCESS_VM_READV
ssize_t process_vm_readv(::pid_t pid, const struct iovec *local_iov,
unsigned long liovcnt, const struct iovec *remote_iov,
unsigned long riovcnt, unsigned long flags);
#endif

#endif // liblldb_Host_linux_Uio_h_
4 changes: 2 additions & 2 deletions lldb/include/lldb/Host/common/GetOptInc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

#include "lldb/lldb-defines.h"

#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__AIX__)
#define REPLACE_GETOPT
#define REPLACE_GETOPT_LONG
#endif
#if defined(_MSC_VER) || defined(__NetBSD__)
#if defined(_MSC_VER) || defined(__NetBSD__) || defined(__AIX__)
#define REPLACE_GETOPT_LONG_ONLY
#endif

Expand Down
Loading