Summary: Disabling this assert prevents lldb-server from crashing, which prevents it from finding the user and group names of a given process list. Before this change, the process list didn't contain names: ``` PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE ARGUMENTS ====== ====== ========== ========== ========== ========== ============================== ============================ 27585 982 10098 10098 10098 10098 com.LogiaGroup.LogiaDeck 27623 982 10098 10098 10098 10098 com.digitalturbine.ignite.suspend.DataUsageRecorderService 28024 982 10199 10199 10199 10199 com.google.vr.vrcore 28061 983 10353 10353 10353 10353 com.instagram.android:videoplayer 28121 982 10045 10045 10045 10045 com.sec.spp.push 28325 982 10247 10247 10247 10247 com.facebook.orca 28714 982 10367 10367 10367 10367 com.samsung.android.dialer 29867 3208 2000 2000 2000 2000 aarch64-unknown-linux-android /system/bin/sh-c /data/local/tmp/lldb-server platform --listen *:5557 --server --log-file /data/local/tmp/logs --log-channels gdb-remote all --log-channels lldb all ``` After this change, the list looks much better ``` PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE ARGUMENTS ====== ====== ========== ========== ========== ========== ============================== ============================ 24459 1 wifi 1010 wifi 1010 aarch64-unknown-linux-android /vendor/bin/hw/wpa_supplicant-O/data/vendor/wifi/wpa/sockets -puse_p2p_group_interface=1 -g@android:wpa_wlan0 25098 982 u0_a42 10042 u0_a42 10042 com.samsung.android.messaging 25442 982 u0_a65 10065 u0_a65 10065 com.samsung.android.mobileservice 25974 982 u0_a9 10009 u0_a9 10009 com.samsung.android.contacts 26377 982 radio 1001 radio 1001 com.samsung.android.incallui 26390 983 u0_a26 10026 u0_a26 10026 com.samsung.android.game.gametools 26876 983 u0_a306 10306 u0_a306 10306 com.tencent.mm:push ``` Reviewers: clayborg,aadsm,xiaobai,labath Subscribers: llvm-svn: 373760
150 lines
4.5 KiB
C++
150 lines
4.5 KiB
C++
//===-- HostInfoPosix.cpp ---------------------------------------*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/Host/posix/HostInfoPosix.h"
|
|
#include "lldb/Utility/Log.h"
|
|
#include "lldb/Utility/UserIDResolver.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
#include "llvm/ADT/Twine.h"
|
|
#include "llvm/Support/Path.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <grp.h>
|
|
#include <limits.h>
|
|
#include <mutex>
|
|
#include <pwd.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
|
|
using namespace lldb_private;
|
|
|
|
size_t HostInfoPosix::GetPageSize() { return ::getpagesize(); }
|
|
|
|
bool HostInfoPosix::GetHostname(std::string &s) {
|
|
char hostname[PATH_MAX];
|
|
hostname[sizeof(hostname) - 1] = '\0';
|
|
if (::gethostname(hostname, sizeof(hostname) - 1) == 0) {
|
|
s.assign(hostname);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
#ifdef __ANDROID__
|
|
#include <android/api-level.h>
|
|
#endif
|
|
#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
|
|
#define USE_GETPWUID
|
|
#endif
|
|
|
|
namespace {
|
|
class PosixUserIDResolver : public UserIDResolver {
|
|
protected:
|
|
llvm::Optional<std::string> DoGetUserName(id_t uid) override;
|
|
llvm::Optional<std::string> DoGetGroupName(id_t gid) override;
|
|
};
|
|
} // namespace
|
|
|
|
struct PasswdEntry {
|
|
std::string username;
|
|
std::string shell;
|
|
};
|
|
|
|
static llvm::Optional<PasswdEntry> GetPassword(id_t uid) {
|
|
#ifdef USE_GETPWUID
|
|
// getpwuid_r is missing from android-9
|
|
// The caller should provide some thread safety by making sure no one calls
|
|
// this function concurrently, because using getpwuid is ultimately not
|
|
// thread-safe as we don't know who else might be calling it.
|
|
if (auto *user_info_ptr = ::getpwuid(uid))
|
|
return PasswdEntry{user_info_ptr->pw_name, user_info_ptr->pw_shell};
|
|
#else
|
|
struct passwd user_info;
|
|
struct passwd *user_info_ptr = &user_info;
|
|
char user_buffer[PATH_MAX];
|
|
size_t user_buffer_size = sizeof(user_buffer);
|
|
if (::getpwuid_r(uid, &user_info, user_buffer, user_buffer_size,
|
|
&user_info_ptr) == 0 &&
|
|
user_info_ptr) {
|
|
return PasswdEntry{user_info_ptr->pw_name, user_info_ptr->pw_shell};
|
|
}
|
|
#endif
|
|
return llvm::None;
|
|
}
|
|
|
|
llvm::Optional<std::string> PosixUserIDResolver::DoGetUserName(id_t uid) {
|
|
if (llvm::Optional<PasswdEntry> password = GetPassword(uid))
|
|
return password->username;
|
|
return llvm::None;
|
|
}
|
|
|
|
llvm::Optional<std::string> PosixUserIDResolver::DoGetGroupName(id_t gid) {
|
|
#ifndef __ANDROID__
|
|
char group_buffer[PATH_MAX];
|
|
size_t group_buffer_size = sizeof(group_buffer);
|
|
struct group group_info;
|
|
struct group *group_info_ptr = &group_info;
|
|
// Try the threadsafe version first
|
|
if (::getgrgid_r(gid, &group_info, group_buffer, group_buffer_size,
|
|
&group_info_ptr) == 0) {
|
|
if (group_info_ptr)
|
|
return std::string(group_info_ptr->gr_name);
|
|
} else {
|
|
// The threadsafe version isn't currently working for me on darwin, but the
|
|
// non-threadsafe version is, so I am calling it below.
|
|
group_info_ptr = ::getgrgid(gid);
|
|
if (group_info_ptr)
|
|
return std::string(group_info_ptr->gr_name);
|
|
}
|
|
#endif
|
|
return llvm::None;
|
|
}
|
|
|
|
static llvm::ManagedStatic<PosixUserIDResolver> g_user_id_resolver;
|
|
|
|
UserIDResolver &HostInfoPosix::GetUserIDResolver() {
|
|
return *g_user_id_resolver;
|
|
}
|
|
|
|
uint32_t HostInfoPosix::GetUserID() { return getuid(); }
|
|
|
|
uint32_t HostInfoPosix::GetGroupID() { return getgid(); }
|
|
|
|
uint32_t HostInfoPosix::GetEffectiveUserID() { return geteuid(); }
|
|
|
|
uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }
|
|
|
|
FileSpec HostInfoPosix::GetDefaultShell() {
|
|
if (const char *v = ::getenv("SHELL"))
|
|
return FileSpec(v);
|
|
if (llvm::Optional<PasswdEntry> password = GetPassword(::geteuid()))
|
|
return FileSpec(password->shell);
|
|
return FileSpec("/bin/sh");
|
|
}
|
|
|
|
bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
|
|
return ComputePathRelativeToLibrary(file_spec, "/bin");
|
|
}
|
|
|
|
bool HostInfoPosix::ComputeHeaderDirectory(FileSpec &file_spec) {
|
|
FileSpec temp_file("/opt/local/include/lldb");
|
|
file_spec.GetDirectory().SetCString(temp_file.GetPath().c_str());
|
|
return true;
|
|
}
|
|
|
|
bool HostInfoPosix::GetEnvironmentVar(const std::string &var_name,
|
|
std::string &var) {
|
|
if (const char *pvar = ::getenv(var_name.c_str())) {
|
|
var = std::string(pvar);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|