jasonmolenda updated this revision to Diff 470885. jasonmolenda added a comment.
Update MachProcess::GetPlatformString to return a std::optional platform string, if the platform enumeration is recognized. Update callers to handle the absence of a value appropriately. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D136719/new/ https://reviews.llvm.org/D136719 Files: 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
Index: lldb/tools/debugserver/source/RNBRemote.cpp =================================================================== --- lldb/tools/debugserver/source/RNBRemote.cpp +++ 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<const char *> platform = DNBGetDeploymentInfo(pid, is_executable, lc, load_command_addr, major_version, minor_version, patch_version); - if (platform) { + if (platform.has_value()) { os_handled = true; - rep << "ostype:" << platform << ";"; + rep << "ostype:" << platform.value() << ";"; break; } load_command_addr = load_command_addr + lc.cmdsize; Index: lldb/tools/debugserver/source/MacOSX/MachProcess.mm =================================================================== --- lldb/tools/debugserver/source/MacOSX/MachProcess.mm +++ lldb/tools/debugserver/source/MacOSX/MachProcess.mm @@ -720,30 +720,44 @@ return info; } -const char *MachProcess::GetPlatformString(unsigned char platform) { +std::optional<const char *> +MachProcess::GetPlatformString(unsigned char platform) { + std::optional<const char *> platform_string; switch (platform) { case PLATFORM_MACOS: - return "macosx"; + platform_string = "macosx"; + break; case PLATFORM_MACCATALYST: - return "maccatalyst"; + platform_string = "maccatalyst"; + break; case PLATFORM_IOS: - return "ios"; + platform_string = "ios"; + break; case PLATFORM_IOSSIMULATOR: - return "iossimulator"; + platform_string = "iossimulator"; + break; case PLATFORM_TVOS: - return "tvos"; + platform_string = "tvos"; + break; case PLATFORM_TVOSSIMULATOR: - return "tvossimulator"; + platform_string = "tvossimulator"; + break; case PLATFORM_WATCHOS: - return "watchos"; + platform_string = "watchos"; + break; case PLATFORM_WATCHOSSIMULATOR: - return "watchossimulator"; + platform_string = "watchossimulator"; + break; case PLATFORM_BRIDGEOS: - return "bridgeos"; + platform_string = "bridgeos"; + break; case PLATFORM_DRIVERKIT: - return "driverkit"; + platform_string = "driverkit"; + break; + default: + DNBLogError("Unknown platform %u found for one binary", platform); } - return nullptr; + return platform_string; } static bool mach_header_validity_test(uint32_t magic, uint32_t cputype) { @@ -867,7 +881,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<const char *> lc_platform = + GetPlatformString(deployment_info.platform); if (dyld_platform != PLATFORM_MACCATALYST && inf.min_version_os_name == "macosx") { // macCatalyst support. @@ -882,7 +897,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); Index: lldb/tools/debugserver/source/MacOSX/MachProcess.h =================================================================== --- lldb/tools/debugserver/source/MacOSX/MachProcess.h +++ 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 @@ DeploymentInfo GetDeploymentInfo(const struct load_command &, uint64_t load_command_address, bool is_executable); - static const char *GetPlatformString(unsigned char platform); + static std::optional<const char *> GetPlatformString(unsigned char platform); bool GetMachOInformationFromMemory(uint32_t platform, nub_addr_t mach_o_header_addr, int wordsize, Index: lldb/tools/debugserver/source/DNB.h =================================================================== --- lldb/tools/debugserver/source/DNB.h +++ 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_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<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); nub_bool_t DNBProcessSetNameToAddressCallback(nub_process_t pid, DNBCallbackNameToAddress callback, void *baton) DNB_EXPORT; Index: lldb/tools/debugserver/source/DNB.cpp =================================================================== --- lldb/tools/debugserver/source/DNB.cpp +++ 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<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) { MachProcessSP procSP; if (GetProcessSP(pid, procSP)) { // FIXME: This doesn't return the correct result when xctest (a
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits