Skip to content

Commit fba68b4

Browse files
authored
[LLDB][NFC] Remove unneeded conditional (llvm#138321)
we already check for `platform_sp` not null in one line below. existing code ``` if (platform_sp) { Status error; if (platform_sp) { ... ... } } ``` `platform_sp` null check is redundant and error variable is unused. ### TEST PLAN manual test ``` satyajanga@devvm21837:toolchain $ ./bin/lldb LLDB logging initialized. Logs stored in: /tmp (lldb) platform select host Platform: host Triple: x86_64-*-linux-gnu OS Version: 6.9.0 (6.9.0-0_fbk5_hardened_1_gf368ae920c1a) Hostname: 127.0.0.1 WorkingDir: /home/satyajanga/llvm-sand/build/Debug/fbcode-x86_64/toolchain Kernel: #1 SMP Tue Feb 11 07:24:41 PST 2025 Kernel: Linux Release: 6.9.0-0_fbk5_hardened_1_gf368ae920c1a Version: #1 SMP Tue Feb 11 07:24:41 PST 2025 (lldb) platform process list 144 matching processes were found on "host" PID PARENT USER TRIPLE NAME ====== ====== ========== ============================== ============================ 130461 874915 satyajanga x86_64-*-linux-gnu sushd 135505 874915 satyajanga x86_64-*-linux-gnu hg.real 817146 874915 satyajanga x86_64-*-linux-gnu vscode-thrift 874915 1 satyajanga 874947 874915 satyajanga ``` and running the existing tests ``` satyajanga@devvm21837:toolchain $ ./bin/llvm-lit -v ~/llvm-sand/external/llvm-project/lldb/test/API/commands/platform/ -- Testing: 9 tests, 9 workers -- PASS: lldb-api :: commands/platform/file/read/TestPlatformFileRead.py (1 of 9) PASS: lldb-api :: commands/platform/file/close/TestPlatformFileClose.py (2 of 9) UNSUPPORTED: lldb-api :: commands/platform/sdk/TestPlatformSDK.py (3 of 9) PASS: lldb-api :: commands/platform/basic/TestPlatformPython.py (4 of 9) PASS: lldb-api :: commands/platform/basic/TestPlatformCommand.py (5 of 9) PASS: lldb-api :: commands/platform/connect/TestPlatformConnect.py (6 of 9) PASS: lldb-api :: commands/platform/process/launch/TestPlatformProcessLaunch.py (7 of 9) PASS: lldb-api :: commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py (8 of 9) PASS: lldb-api :: commands/platform/process/list/TestProcessList.py (9 of 9) Testing Time: 13.48s Total Discovered Tests: 9 Unsupported: 1 (11.11%) Passed : 8 (88.89%) satyajanga@devvm21837:toolchain $ ```
1 parent 2b62a31 commit fba68b4

File tree

1 file changed

+65
-68
lines changed

1 file changed

+65
-68
lines changed

lldb/source/Commands/CommandObjectPlatform.cpp

+65-68
Original file line numberDiff line numberDiff line change
@@ -1231,77 +1231,74 @@ class CommandObjectPlatformProcessList : public CommandObjectParsed {
12311231
}
12321232

12331233
if (platform_sp) {
1234-
Status error;
1235-
if (platform_sp) {
1236-
Stream &ostrm = result.GetOutputStream();
1237-
1238-
lldb::pid_t pid = m_options.match_info.GetProcessInfo().GetProcessID();
1239-
if (pid != LLDB_INVALID_PROCESS_ID) {
1240-
ProcessInstanceInfo proc_info;
1241-
if (platform_sp->GetProcessInfo(pid, proc_info)) {
1242-
ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
1243-
m_options.verbose);
1244-
proc_info.DumpAsTableRow(ostrm, platform_sp->GetUserIDResolver(),
1245-
m_options.show_args, m_options.verbose);
1246-
result.SetStatus(eReturnStatusSuccessFinishResult);
1247-
} else {
1248-
result.AppendErrorWithFormat(
1249-
"no process found with pid = %" PRIu64 "\n", pid);
1250-
}
1234+
Stream &ostrm = result.GetOutputStream();
1235+
1236+
lldb::pid_t pid = m_options.match_info.GetProcessInfo().GetProcessID();
1237+
if (pid != LLDB_INVALID_PROCESS_ID) {
1238+
ProcessInstanceInfo proc_info;
1239+
if (platform_sp->GetProcessInfo(pid, proc_info)) {
1240+
ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
1241+
m_options.verbose);
1242+
proc_info.DumpAsTableRow(ostrm, platform_sp->GetUserIDResolver(),
1243+
m_options.show_args, m_options.verbose);
1244+
result.SetStatus(eReturnStatusSuccessFinishResult);
12511245
} else {
1252-
ProcessInstanceInfoList proc_infos;
1253-
const uint32_t matches =
1254-
platform_sp->FindProcesses(m_options.match_info, proc_infos);
1255-
const char *match_desc = nullptr;
1256-
const char *match_name =
1257-
m_options.match_info.GetProcessInfo().GetName();
1258-
if (match_name && match_name[0]) {
1259-
switch (m_options.match_info.GetNameMatchType()) {
1260-
case NameMatch::Ignore:
1261-
break;
1262-
case NameMatch::Equals:
1263-
match_desc = "matched";
1264-
break;
1265-
case NameMatch::Contains:
1266-
match_desc = "contained";
1267-
break;
1268-
case NameMatch::StartsWith:
1269-
match_desc = "started with";
1270-
break;
1271-
case NameMatch::EndsWith:
1272-
match_desc = "ended with";
1273-
break;
1274-
case NameMatch::RegularExpression:
1275-
match_desc = "matched the regular expression";
1276-
break;
1277-
}
1246+
result.AppendErrorWithFormat(
1247+
"no process found with pid = %" PRIu64 "\n", pid);
1248+
}
1249+
} else {
1250+
ProcessInstanceInfoList proc_infos;
1251+
const uint32_t matches =
1252+
platform_sp->FindProcesses(m_options.match_info, proc_infos);
1253+
const char *match_desc = nullptr;
1254+
const char *match_name =
1255+
m_options.match_info.GetProcessInfo().GetName();
1256+
if (match_name && match_name[0]) {
1257+
switch (m_options.match_info.GetNameMatchType()) {
1258+
case NameMatch::Ignore:
1259+
break;
1260+
case NameMatch::Equals:
1261+
match_desc = "matched";
1262+
break;
1263+
case NameMatch::Contains:
1264+
match_desc = "contained";
1265+
break;
1266+
case NameMatch::StartsWith:
1267+
match_desc = "started with";
1268+
break;
1269+
case NameMatch::EndsWith:
1270+
match_desc = "ended with";
1271+
break;
1272+
case NameMatch::RegularExpression:
1273+
match_desc = "matched the regular expression";
1274+
break;
12781275
}
1276+
}
12791277

1280-
if (matches == 0) {
1281-
if (match_desc)
1282-
result.AppendErrorWithFormatv(
1283-
"no processes were found that {0} \"{1}\" on the \"{2}\" "
1284-
"platform\n",
1285-
match_desc, match_name, platform_sp->GetName());
1286-
else
1287-
result.AppendErrorWithFormatv(
1288-
"no processes were found on the \"{0}\" platform\n",
1289-
platform_sp->GetName());
1290-
} else {
1291-
result.AppendMessageWithFormatv(
1292-
"{0} matching process{1} found on \"{2}\"", matches,
1293-
matches > 1 ? "es were" : " was", platform_sp->GetName());
1294-
if (match_desc)
1295-
result.AppendMessageWithFormat(" whose name %s \"%s\"",
1296-
match_desc, match_name);
1297-
result.AppendMessageWithFormat("\n");
1298-
ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
1299-
m_options.verbose);
1300-
for (uint32_t i = 0; i < matches; ++i) {
1301-
proc_infos[i].DumpAsTableRow(
1302-
ostrm, platform_sp->GetUserIDResolver(), m_options.show_args,
1303-
m_options.verbose);
1304-
}
1278+
if (matches == 0) {
1279+
if (match_desc)
1280+
result.AppendErrorWithFormatv(
1281+
"no processes were found that {0} \"{1}\" on the \"{2}\" "
1282+
"platform\n",
1283+
match_desc, match_name, platform_sp->GetName());
1284+
else
1285+
result.AppendErrorWithFormatv(
1286+
"no processes were found on the \"{0}\" platform\n",
1287+
platform_sp->GetName());
1288+
} else {
1289+
result.AppendMessageWithFormatv(
1290+
"{0} matching process{1} found on \"{2}\"", matches,
1291+
matches > 1 ? "es were" : " was", platform_sp->GetName());
1292+
if (match_desc)
1293+
result.AppendMessageWithFormat(" whose name %s \"%s\"", match_desc,
1294+
match_name);
1295+
result.AppendMessageWithFormat("\n");
1296+
ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
1297+
m_options.verbose);
1298+
for (uint32_t i = 0; i < matches; ++i) {
1299+
proc_infos[i].DumpAsTableRow(
1300+
ostrm, platform_sp->GetUserIDResolver(), m_options.show_args,
1301+
m_options.verbose);
13051302
}
13061303
}
13071304
}

0 commit comments

Comments
 (0)