Skip to content

[LLDB][NFC] Remove unneeded conditional #138321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2025
Merged

Conversation

satyajanga
Copy link
Contributor

@satyajanga satyajanga commented May 2, 2025

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 $ 

@satyajanga satyajanga requested a review from JDevlieghere as a code owner May 2, 2025 18:27
Copy link

github-actions bot commented May 2, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the lldb label May 2, 2025
@llvmbot
Copy link
Member

llvmbot commented May 2, 2025

@llvm/pr-subscribers-lldb

Author: None (satyajanga)

Changes

Minor code change for removing the unneeded conditional.
we already check for platform_sp not null in the next line.

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 $ 

Full diff: https://github.com/llvm/llvm-project/pull/138321.diff

1 Files Affected:

  • (modified) lldb/source/Commands/CommandObjectPlatform.cpp (+65-68)
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index f849a3815278a..4865c48c82b7f 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1231,77 +1231,74 @@ class CommandObjectPlatformProcessList : public CommandObjectParsed {
     }
 
     if (platform_sp) {
-      Status error;
-      if (platform_sp) {
-        Stream &ostrm = result.GetOutputStream();
-
-        lldb::pid_t pid = m_options.match_info.GetProcessInfo().GetProcessID();
-        if (pid != LLDB_INVALID_PROCESS_ID) {
-          ProcessInstanceInfo proc_info;
-          if (platform_sp->GetProcessInfo(pid, proc_info)) {
-            ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
-                                                 m_options.verbose);
-            proc_info.DumpAsTableRow(ostrm, platform_sp->GetUserIDResolver(),
-                                     m_options.show_args, m_options.verbose);
-            result.SetStatus(eReturnStatusSuccessFinishResult);
-          } else {
-            result.AppendErrorWithFormat(
-                "no process found with pid = %" PRIu64 "\n", pid);
-          }
+      Stream &ostrm = result.GetOutputStream();
+
+      lldb::pid_t pid = m_options.match_info.GetProcessInfo().GetProcessID();
+      if (pid != LLDB_INVALID_PROCESS_ID) {
+        ProcessInstanceInfo proc_info;
+        if (platform_sp->GetProcessInfo(pid, proc_info)) {
+          ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
+                                               m_options.verbose);
+          proc_info.DumpAsTableRow(ostrm, platform_sp->GetUserIDResolver(),
+                                   m_options.show_args, m_options.verbose);
+          result.SetStatus(eReturnStatusSuccessFinishResult);
         } else {
-          ProcessInstanceInfoList proc_infos;
-          const uint32_t matches =
-              platform_sp->FindProcesses(m_options.match_info, proc_infos);
-          const char *match_desc = nullptr;
-          const char *match_name =
-              m_options.match_info.GetProcessInfo().GetName();
-          if (match_name && match_name[0]) {
-            switch (m_options.match_info.GetNameMatchType()) {
-            case NameMatch::Ignore:
-              break;
-            case NameMatch::Equals:
-              match_desc = "matched";
-              break;
-            case NameMatch::Contains:
-              match_desc = "contained";
-              break;
-            case NameMatch::StartsWith:
-              match_desc = "started with";
-              break;
-            case NameMatch::EndsWith:
-              match_desc = "ended with";
-              break;
-            case NameMatch::RegularExpression:
-              match_desc = "matched the regular expression";
-              break;
-            }
+          result.AppendErrorWithFormat(
+              "no process found with pid = %" PRIu64 "\n", pid);
+        }
+      } else {
+        ProcessInstanceInfoList proc_infos;
+        const uint32_t matches =
+            platform_sp->FindProcesses(m_options.match_info, proc_infos);
+        const char *match_desc = nullptr;
+        const char *match_name =
+            m_options.match_info.GetProcessInfo().GetName();
+        if (match_name && match_name[0]) {
+          switch (m_options.match_info.GetNameMatchType()) {
+          case NameMatch::Ignore:
+            break;
+          case NameMatch::Equals:
+            match_desc = "matched";
+            break;
+          case NameMatch::Contains:
+            match_desc = "contained";
+            break;
+          case NameMatch::StartsWith:
+            match_desc = "started with";
+            break;
+          case NameMatch::EndsWith:
+            match_desc = "ended with";
+            break;
+          case NameMatch::RegularExpression:
+            match_desc = "matched the regular expression";
+            break;
           }
+        }
 
-          if (matches == 0) {
-            if (match_desc)
-              result.AppendErrorWithFormatv(
-                  "no processes were found that {0} \"{1}\" on the \"{2}\" "
-                  "platform\n",
-                  match_desc, match_name, platform_sp->GetName());
-            else
-              result.AppendErrorWithFormatv(
-                  "no processes were found on the \"{0}\" platform\n",
-                  platform_sp->GetName());
-          } else {
-            result.AppendMessageWithFormatv(
-                "{0} matching process{1} found on \"{2}\"", matches,
-                matches > 1 ? "es were" : " was", platform_sp->GetName());
-            if (match_desc)
-              result.AppendMessageWithFormat(" whose name %s \"%s\"",
-                                             match_desc, match_name);
-            result.AppendMessageWithFormat("\n");
-            ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
-                                                 m_options.verbose);
-            for (uint32_t i = 0; i < matches; ++i) {
-              proc_infos[i].DumpAsTableRow(
-                  ostrm, platform_sp->GetUserIDResolver(), m_options.show_args,
-                  m_options.verbose);
-            }
+        if (matches == 0) {
+          if (match_desc)
+            result.AppendErrorWithFormatv(
+                "no processes were found that {0} \"{1}\" on the \"{2}\" "
+                "platform\n",
+                match_desc, match_name, platform_sp->GetName());
+          else
+            result.AppendErrorWithFormatv(
+                "no processes were found on the \"{0}\" platform\n",
+                platform_sp->GetName());
+        } else {
+          result.AppendMessageWithFormatv(
+              "{0} matching process{1} found on \"{2}\"", matches,
+              matches > 1 ? "es were" : " was", platform_sp->GetName());
+          if (match_desc)
+            result.AppendMessageWithFormat(" whose name %s \"%s\"", match_desc,
+                                           match_name);
+          result.AppendMessageWithFormat("\n");
+          ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
+                                               m_options.verbose);
+          for (uint32_t i = 0; i < matches; ++i) {
+            proc_infos[i].DumpAsTableRow(
+                ostrm, platform_sp->GetUserIDResolver(), m_options.show_args,
+                m_options.verbose);
           }
         }
       }

@Jlalond Jlalond changed the title Remove unneeded conditional [LLDB][NFC] Remove unneeded conditional May 2, 2025
@Jlalond
Copy link
Contributor

Jlalond commented May 2, 2025

@satyajanga

Please update your summary about where you removed the conditional, and the description. Otherwise LGTM.

Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring whitespace, this is a pretty tiny change that makes sense.

@Jlalond Jlalond merged commit fba68b4 into llvm:main May 3, 2025
12 checks passed
Copy link

github-actions bot commented May 3, 2025

@satyajanga Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants