[Lldb-commits] [lldb] d40f463 - Handle an unknown binary platform type in debugserver
Jason Molenda via lldb-commits
lldb-commits at lists.llvm.org
Thu Oct 27 13:13:30 PDT 2022
Author: Jason Molenda
Date: 2022-10-27T13:11:20-07:00
New Revision: d40f4636c454cf278b390b6591bf1e8dde8252aa
URL: https://github.com/llvm/llvm-project/commit/d40f4636c454cf278b390b6591bf1e8dde8252aa
DIFF: https://github.com/llvm/llvm-project/commit/d40f4636c454cf278b390b6591bf1e8dde8252aa.diff
LOG: Handle an unknown binary platform type in debugserver
debugserver parses the Mach-O header & load commands of
binaries; if it does this with a binary whose LC_BUILD
platform enum it does not recognize, it will currently crash.
This patch changes MachProcss::GetPlatformString to return
an optional platform string, and updates the callers to
do the right thing when this optional could not be
provided.
Differential Revision: https://reviews.llvm.org/D136719
rdar://100452994
Added:
Modified:
lldb/tools/debugserver/source/DNB.cpp
lldb/tools/debugserver/source/DNB.h
lldb/tools/debugserver/source/MacOSX/MachProcess.h
lldb/tools/debugserver/source/MacOSX/MachProcess.mm
lldb/tools/debugserver/source/RNBRemote.cpp
Removed:
################################################################################
diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp
index 89f573d54bf97..d38c151d9f808 100644
--- a/lldb/tools/debugserver/source/DNB.cpp
+++ b/lldb/tools/debugserver/source/DNB.cpp
@@ -1433,12 +1433,11 @@ nub_bool_t DNBProcessSharedLibrariesUpdated(nub_process_t pid) {
return false;
}
-const char *DNBGetDeploymentInfo(nub_process_t pid, bool is_executable,
- const struct load_command &lc,
- uint64_t load_command_address,
- uint32_t &major_version,
- uint32_t &minor_version,
- uint32_t &patch_version) {
+std::optional<std::string>
+DNBGetDeploymentInfo(nub_process_t pid, bool is_executable,
+ const struct load_command &lc,
+ uint64_t load_command_address, uint32_t &major_version,
+ uint32_t &minor_version, uint32_t &patch_version) {
MachProcessSP procSP;
if (GetProcessSP(pid, procSP)) {
// FIXME: This doesn't return the correct result when xctest (a
diff --git a/lldb/tools/debugserver/source/DNB.h b/lldb/tools/debugserver/source/DNB.h
index b0ab37adad00c..15d11fa794162 100644
--- a/lldb/tools/debugserver/source/DNB.h
+++ b/lldb/tools/debugserver/source/DNB.h
@@ -21,6 +21,7 @@
#include <Availability.h>
#include <mach/machine.h>
#include <mach/thread_info.h>
+#include <optional>
#include <string>
#define DNB_EXPORT __attribute__((visibility("default")))
@@ -134,12 +135,11 @@ nub_bool_t DNBProcessSharedLibrariesUpdated(nub_process_t pid) DNB_EXPORT;
nub_size_t
DNBProcessGetSharedLibraryInfo(nub_process_t pid, nub_bool_t only_changed,
DNBExecutableImageInfo **image_infos) DNB_EXPORT;
-const char *DNBGetDeploymentInfo(nub_process_t pid, bool is_executable,
- const struct load_command &lc,
- uint64_t load_command_address,
- uint32_t &major_version,
- uint32_t &minor_version,
- uint32_t &patch_version);
+std::optional<std::string>
+DNBGetDeploymentInfo(nub_process_t pid, bool is_executable,
+ const struct load_command &lc,
+ uint64_t load_command_address, uint32_t &major_version,
+ uint32_t &minor_version, uint32_t &patch_version);
nub_bool_t DNBProcessSetNameToAddressCallback(nub_process_t pid,
DNBCallbackNameToAddress callback,
void *baton) DNB_EXPORT;
diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.h b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
index 97efb5985ab4a..2ff48879a5bfd 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
@@ -16,6 +16,7 @@
#include <CoreFoundation/CoreFoundation.h>
#include <mach-o/loader.h>
#include <mach/mach.h>
+#include <optional>
#include <pthread.h>
#include <sys/signal.h>
#include <uuid/uuid.h>
@@ -252,7 +253,7 @@ class MachProcess {
DeploymentInfo GetDeploymentInfo(const struct load_command &,
uint64_t load_command_address,
bool is_executable);
- static const char *GetPlatformString(unsigned char platform);
+ static std::optional<std::string> GetPlatformString(unsigned char platform);
bool GetMachOInformationFromMemory(uint32_t platform,
nub_addr_t mach_o_header_addr,
int wordsize,
diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
index c12e07040a604..70a8ecd708456 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -720,7 +720,8 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
return info;
}
-const char *MachProcess::GetPlatformString(unsigned char platform) {
+std::optional<std::string>
+MachProcess::GetPlatformString(unsigned char platform) {
switch (platform) {
case PLATFORM_MACOS:
return "macosx";
@@ -742,8 +743,10 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
return "bridgeos";
case PLATFORM_DRIVERKIT:
return "driverkit";
+ default:
+ DNBLogError("Unknown platform %u found for one binary", platform);
+ return std::nullopt;
}
- return nullptr;
}
static bool mach_header_validity_test(uint32_t magic, uint32_t cputype) {
@@ -867,7 +870,8 @@ static bool mach_header_validity_test(uint32_t magic, uint32_t cputype) {
}
if (DeploymentInfo deployment_info = GetDeploymentInfo(
lc, load_cmds_p, inf.mach_header.filetype == MH_EXECUTE)) {
- const char *lc_platform = GetPlatformString(deployment_info.platform);
+ std::optional<std::string> lc_platform =
+ GetPlatformString(deployment_info.platform);
if (dyld_platform != PLATFORM_MACCATALYST &&
inf.min_version_os_name == "macosx") {
// macCatalyst support.
@@ -882,7 +886,7 @@ static bool mach_header_validity_test(uint32_t magic, uint32_t cputype) {
// processed, ignore this one, which is presumed to be a
// PLATFORM_MACCATALYST one.
} else {
- inf.min_version_os_name = lc_platform;
+ inf.min_version_os_name = lc_platform.value_or("");
inf.min_version_os_version = "";
inf.min_version_os_version +=
std::to_string(deployment_info.major_version);
diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp
index 48de97f1f6a47..5dad4cfb43ffc 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -6258,12 +6258,12 @@ rnb_err_t RNBRemote::HandlePacket_qProcessInfo(const char *p) {
bool is_executable = true;
uint32_t major_version, minor_version, patch_version;
- auto *platform =
+ std::optional<std::string> platform =
DNBGetDeploymentInfo(pid, is_executable, lc, load_command_addr,
major_version, minor_version, patch_version);
if (platform) {
os_handled = true;
- rep << "ostype:" << platform << ";";
+ rep << "ostype:" << *platform << ";";
break;
}
load_command_addr = load_command_addr + lc.cmdsize;
More information about the lldb-commits
mailing list