DavidSpickett created this revision.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
The original logic is retained.
Unlike qHostInfo, qProcessInfo does not check whether
at least one key was parsed correctly. This allowed
me to move a lot of the Get calls next to where the
result is used.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D93226
Files:
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1897,91 +1897,65 @@
bool GDBRemoteCommunicationClient::DecodeProcessInfoResponse(
StringExtractorGDBRemote &response, ProcessInstanceInfo &process_info) {
if (response.IsNormalResponse()) {
- llvm::StringRef name;
- llvm::StringRef value;
- StringExtractor extractor;
-
- uint32_t cpu = LLDB_INVALID_CPUTYPE;
- uint32_t sub = 0;
- std::string vendor;
- std::string os_type;
-
- while (response.GetNameColonValue(name, value)) {
- if (name.equals("pid")) {
- lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
- value.getAsInteger(0, pid);
- process_info.SetProcessID(pid);
- } else if (name.equals("ppid")) {
- lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
- value.getAsInteger(0, pid);
- process_info.SetParentProcessID(pid);
- } else if (name.equals("uid")) {
- uint32_t uid = UINT32_MAX;
- value.getAsInteger(0, uid);
- process_info.SetUserID(uid);
- } else if (name.equals("euid")) {
- uint32_t uid = UINT32_MAX;
- value.getAsInteger(0, uid);
- process_info.SetEffectiveUserID(uid);
- } else if (name.equals("gid")) {
- uint32_t gid = UINT32_MAX;
- value.getAsInteger(0, gid);
- process_info.SetGroupID(gid);
- } else if (name.equals("egid")) {
- uint32_t gid = UINT32_MAX;
- value.getAsInteger(0, gid);
- process_info.SetEffectiveGroupID(gid);
- } else if (name.equals("triple")) {
- StringExtractor extractor(value);
- std::string triple;
- extractor.GetHexByteString(triple);
- process_info.GetArchitecture().SetTriple(triple.c_str());
- } else if (name.equals("name")) {
- StringExtractor extractor(value);
- // The process name from ASCII hex bytes since we can't control the
- // characters in a process name
- std::string name;
- extractor.GetHexByteString(name);
- process_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
- } else if (name.equals("args")) {
- llvm::StringRef encoded_args(value), hex_arg;
-
- bool is_arg0 = true;
- while (!encoded_args.empty()) {
- std::tie(hex_arg, encoded_args) = encoded_args.split('-');
- std::string arg;
- StringExtractor extractor(hex_arg);
- if (extractor.GetHexByteString(arg) * 2 != hex_arg.size()) {
- // In case of wrong encoding, we discard all the arguments
- process_info.GetArguments().Clear();
- process_info.SetArg0("");
- break;
- }
- if (is_arg0)
- process_info.SetArg0(arg);
- else
- process_info.GetArguments().AppendArgument(arg);
- is_arg0 = false;
+ KeyValueExtractorGDBRemote extractor(response);
+
+ process_info.SetProcessID(
+ extractor.GetWithDefault<lldb::pid_t>("pid", LLDB_INVALID_PROCESS_ID));
+ process_info.SetParentProcessID(
+ extractor.GetWithDefault<lldb::pid_t>("ppid", LLDB_INVALID_PROCESS_ID));
+ process_info.SetUserID(
+ extractor.GetWithDefault<uint32_t>("uid", UINT32_MAX));
+ process_info.SetEffectiveUserID(
+ extractor.GetWithDefault<uint32_t>("euid", UINT32_MAX));
+ process_info.SetGroupID(
+ extractor.GetWithDefault<uint32_t>("gid", UINT32_MAX));
+ process_info.SetEffectiveGroupID(
+ extractor.GetWithDefault<uint32_t>("egid", UINT32_MAX));
+
+ if (llvm::Optional<std::string> triple =
+ extractor.GetHexByteString("triple"))
+ process_info.GetArchitecture().SetTriple(triple->c_str());
+
+ // The process name from ASCII hex bytes since we can't control the
+ // characters in a process name
+ if (llvm::Optional<std::string> name = extractor.GetHexByteString("name"))
+ process_info.GetExecutableFile().SetFile(*name, FileSpec::Style::native);
+
+ if (llvm::Optional<std::string> args = extractor.Get<std::string>("args")) {
+ llvm::StringRef encoded_args(*args), hex_arg;
+
+ bool is_arg0 = true;
+ while (encoded_args.size()) {
+ std::tie(hex_arg, encoded_args) = encoded_args.split('-');
+ std::string arg;
+ StringExtractor extractor(hex_arg);
+ if (extractor.GetHexByteString(arg) * 2 != hex_arg.size()) {
+ // In case of wrong encoding, we discard all the arguments
+ process_info.GetArguments().Clear();
+ process_info.SetArg0("");
+ break;
}
- } else if (name.equals("cputype")) {
- value.getAsInteger(0, cpu);
- } else if (name.equals("cpusubtype")) {
- value.getAsInteger(0, sub);
- } else if (name.equals("vendor")) {
- vendor = std::string(value);
- } else if (name.equals("ostype")) {
- os_type = std::string(value);
+ if (is_arg0)
+ process_info.SetArg0(arg);
+ else
+ process_info.GetArguments().AppendArgument(arg);
+ is_arg0 = false;
}
}
- if (cpu != LLDB_INVALID_CPUTYPE && !vendor.empty() && !os_type.empty()) {
- if (vendor == "apple") {
- process_info.GetArchitecture().SetArchitecture(eArchTypeMachO, cpu,
+ llvm::Optional<uint32_t> cpu = extractor.Get<uint32_t>("cputype");
+ llvm::Optional<std::string> vendor = extractor.Get<std::string>("vendor");
+ llvm::Optional<std::string> os_type = extractor.Get<std::string>("ostype");
+
+ if (cpu && vendor && vendor->size() && os_type && os_type->size()) {
+ if (*vendor == "apple") {
+ uint32_t sub = extractor.GetWithDefault<uint32_t>("cpusubtype", 0);
+ process_info.GetArchitecture().SetArchitecture(eArchTypeMachO, *cpu,
sub);
process_info.GetArchitecture().GetTriple().setVendorName(
- llvm::StringRef(vendor));
+ llvm::StringRef(*vendor));
process_info.GetArchitecture().GetTriple().setOSName(
- llvm::StringRef(os_type));
+ llvm::StringRef(*os_type));
}
}
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits