diff --git a/lldb/tools/debugserver/source/DNB.h b/lldb/tools/debugserver/source/DNB.h --- a/lldb/tools/debugserver/source/DNB.h +++ b/lldb/tools/debugserver/source/DNB.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #define DNB_EXPORT __attribute__((visibility("default"))) @@ -134,12 +135,11 @@ 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 +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/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp --- a/lldb/tools/debugserver/source/DNB.cpp +++ b/lldb/tools/debugserver/source/DNB.cpp @@ -1433,12 +1433,11 @@ 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 +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/MacOSX/MachProcess.h b/lldb/tools/debugserver/source/MacOSX/MachProcess.h --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.h +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -252,7 +253,7 @@ DeploymentInfo GetDeploymentInfo(const struct load_command &, uint64_t load_command_address, bool is_executable); - static const char *GetPlatformString(unsigned char platform); + static std::optional 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 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm @@ -720,7 +720,8 @@ return info; } -const char *MachProcess::GetPlatformString(unsigned char platform) { +std::optional +MachProcess::GetPlatformString(unsigned char platform) { switch (platform) { case PLATFORM_MACOS: return "macosx"; @@ -742,8 +743,10 @@ 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 @@ } 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 lc_platform = + GetPlatformString(deployment_info.platform); if (dyld_platform != PLATFORM_MACCATALYST && inf.min_version_os_name == "macosx") { // macCatalyst support. @@ -882,7 +886,7 @@ // 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 --- a/lldb/tools/debugserver/source/RNBRemote.cpp +++ b/lldb/tools/debugserver/source/RNBRemote.cpp @@ -6258,12 +6258,12 @@ bool is_executable = true; uint32_t major_version, minor_version, patch_version; - auto *platform = + std::optional 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;