[Lldb-commits] [lldb] 5d3926a - [lldb] Clean up ProcessGDBRemote::DidLaunchOrAttach

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 13 01:32:28 PST 2020


Author: Pavel Labath
Date: 2020-02-13T10:32:15+01:00
New Revision: 5d3926a5a287618fea772c5be689f6c9fc2f6fc3

URL: https://github.com/llvm/llvm-project/commit/5d3926a5a287618fea772c5be689f6c9fc2f6fc3
DIFF: https://github.com/llvm/llvm-project/commit/5d3926a5a287618fea772c5be689f6c9fc2f6fc3.diff

LOG: [lldb] Clean up ProcessGDBRemote::DidLaunchOrAttach

- reduce indentation by removing the defensive
  GetID()!=INVALID_PROCESS_ID check -- this function is only called when
  an attach or launch succeeds
- replace LLDB_LOGF with LLDB_LOG

Added: 
    

Modified: 
    lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 3dfe21df500e..329656065822 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1026,123 +1026,87 @@ Status ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) {
 
 void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
-  LLDB_LOGF(log, "ProcessGDBRemote::%s()", __FUNCTION__);
-  if (GetID() != LLDB_INVALID_PROCESS_ID) {
-    BuildDynamicRegisterInfo(false);
+  BuildDynamicRegisterInfo(false);
 
-    // See if the GDB server supports the qHostInfo information
+  // See if the GDB server supports qHostInfo or qProcessInfo packets. Prefer
+  // qProcessInfo as it will be more specific to our process.
 
-    // See if the GDB server supports the qProcessInfo packet, if so prefer
-    // that over the Host information as it will be more specific to our
-    // process.
+  const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture();
+  if (remote_process_arch.IsValid()) {
+    process_arch = remote_process_arch;
+    LLDB_LOG(log, "gdb-remote had process architecture, using {0} {1}",
+             process_arch.GetArchitectureName(),
+             process_arch.GetTriple().getTriple());
+  } else {
+    process_arch = m_gdb_comm.GetHostArchitecture();
+    LLDB_LOG(log,
+             "gdb-remote did not have process architecture, using gdb-remote "
+             "host architecture {0} {1}",
+             process_arch.GetArchitectureName(),
+             process_arch.GetTriple().getTriple());
+  }
 
-    const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture();
-    if (remote_process_arch.IsValid()) {
-      process_arch = remote_process_arch;
-      LLDB_LOGF(log,
-                "ProcessGDBRemote::%s gdb-remote had process architecture, "
-                "using %s %s",
-                __FUNCTION__,
-                process_arch.GetArchitectureName()
-                    ? process_arch.GetArchitectureName()
-                    : "<null>",
-                process_arch.GetTriple().getTriple().c_str()
-                    ? process_arch.GetTriple().getTriple().c_str()
-                    : "<null>");
-    } else {
-      process_arch = m_gdb_comm.GetHostArchitecture();
-      LLDB_LOGF(log,
-                "ProcessGDBRemote::%s gdb-remote did not have process "
-                "architecture, using gdb-remote host architecture %s %s",
-                __FUNCTION__,
-                process_arch.GetArchitectureName()
-                    ? process_arch.GetArchitectureName()
-                    : "<null>",
-                process_arch.GetTriple().getTriple().c_str()
-                    ? process_arch.GetTriple().getTriple().c_str()
-                    : "<null>");
-    }
+  if (process_arch.IsValid()) {
+    const ArchSpec &target_arch = GetTarget().GetArchitecture();
+    if (target_arch.IsValid()) {
+      LLDB_LOG(log, "analyzing target arch, currently {0} {1}",
+               target_arch.GetArchitectureName(),
+               target_arch.GetTriple().getTriple());
+
+      // If the remote host is ARM and we have apple as the vendor, then
+      // ARM executables and shared libraries can have mixed ARM
+      // architectures.
+      // You can have an armv6 executable, and if the host is armv7, then the
+      // system will load the best possible architecture for all shared
+      // libraries it has, so we really need to take the remote host
+      // architecture as our defacto architecture in this case.
+
+      if ((process_arch.GetMachine() == llvm::Triple::arm ||
+           process_arch.GetMachine() == llvm::Triple::thumb) &&
+          process_arch.GetTriple().getVendor() == llvm::Triple::Apple) {
+        GetTarget().SetArchitecture(process_arch);
+        LLDB_LOG(log,
+                 "remote process is ARM/Apple, "
+                 "setting target arch to {0} {1}",
+                 process_arch.GetArchitectureName(),
+                 process_arch.GetTriple().getTriple());
+      } else {
+        // Fill in what is missing in the triple
+        const llvm::Triple &remote_triple = process_arch.GetTriple();
+        llvm::Triple new_target_triple = target_arch.GetTriple();
+        if (new_target_triple.getVendorName().size() == 0) {
+          new_target_triple.setVendor(remote_triple.getVendor());
 
-    if (process_arch.IsValid()) {
-      const ArchSpec &target_arch = GetTarget().GetArchitecture();
-      if (target_arch.IsValid()) {
-        LLDB_LOGF(log,
-                  "ProcessGDBRemote::%s analyzing target arch, currently %s %s",
-                  __FUNCTION__,
-                  target_arch.GetArchitectureName()
-                      ? target_arch.GetArchitectureName()
-                      : "<null>",
-                  target_arch.GetTriple().getTriple().c_str()
-                      ? target_arch.GetTriple().getTriple().c_str()
-                      : "<null>");
-
-        // If the remote host is ARM and we have apple as the vendor, then
-        // ARM executables and shared libraries can have mixed ARM
-        // architectures.
-        // You can have an armv6 executable, and if the host is armv7, then the
-        // system will load the best possible architecture for all shared
-        // libraries it has, so we really need to take the remote host
-        // architecture as our defacto architecture in this case.
-
-        if ((process_arch.GetMachine() == llvm::Triple::arm ||
-             process_arch.GetMachine() == llvm::Triple::thumb) &&
-            process_arch.GetTriple().getVendor() == llvm::Triple::Apple) {
-          GetTarget().SetArchitecture(process_arch);
-          LLDB_LOGF(log,
-                    "ProcessGDBRemote::%s remote process is ARM/Apple, "
-                    "setting target arch to %s %s",
-                    __FUNCTION__,
-                    process_arch.GetArchitectureName()
-                        ? process_arch.GetArchitectureName()
-                        : "<null>",
-                    process_arch.GetTriple().getTriple().c_str()
-                        ? process_arch.GetTriple().getTriple().c_str()
-                        : "<null>");
-        } else {
-          // Fill in what is missing in the triple
-          const llvm::Triple &remote_triple = process_arch.GetTriple();
-          llvm::Triple new_target_triple = target_arch.GetTriple();
-          if (new_target_triple.getVendorName().size() == 0) {
-            new_target_triple.setVendor(remote_triple.getVendor());
-
-            if (new_target_triple.getOSName().size() == 0) {
-              new_target_triple.setOS(remote_triple.getOS());
-
-              if (new_target_triple.getEnvironmentName().size() == 0)
-                new_target_triple.setEnvironment(
-                    remote_triple.getEnvironment());
-            }
+          if (new_target_triple.getOSName().size() == 0) {
+            new_target_triple.setOS(remote_triple.getOS());
 
-            ArchSpec new_target_arch = target_arch;
-            new_target_arch.SetTriple(new_target_triple);
-            GetTarget().SetArchitecture(new_target_arch);
+            if (new_target_triple.getEnvironmentName().size() == 0)
+              new_target_triple.setEnvironment(remote_triple.getEnvironment());
           }
-        }
 
-        LLDB_LOGF(log,
-                  "ProcessGDBRemote::%s final target arch after "
-                  "adjustments for remote architecture: %s %s",
-                  __FUNCTION__,
-                  target_arch.GetArchitectureName()
-                      ? target_arch.GetArchitectureName()
-                      : "<null>",
-                  target_arch.GetTriple().getTriple().c_str()
-                      ? target_arch.GetTriple().getTriple().c_str()
-                      : "<null>");
-      } else {
-        // The target doesn't have a valid architecture yet, set it from the
-        // architecture we got from the remote GDB server
-        GetTarget().SetArchitecture(process_arch);
+          ArchSpec new_target_arch = target_arch;
+          new_target_arch.SetTriple(new_target_triple);
+          GetTarget().SetArchitecture(new_target_arch);
+        }
       }
-    }
 
-    // Find out which StructuredDataPlugins are supported by the debug monitor.
-    // These plugins transmit data over async $J packets.
-    auto supported_packets_array =
-        m_gdb_comm.GetSupportedStructuredDataPlugins();
-    if (supported_packets_array)
-      MapSupportedStructuredDataPlugins(*supported_packets_array);
+      LLDB_LOG(log,
+               "final target arch after adjustments for remote architecture: "
+               "{0} {1}",
+               target_arch.GetArchitectureName(),
+               target_arch.GetTriple().getTriple());
+    } else {
+      // The target doesn't have a valid architecture yet, set it from the
+      // architecture we got from the remote GDB server
+      GetTarget().SetArchitecture(process_arch);
+    }
   }
+
+  // Find out which StructuredDataPlugins are supported by the debug monitor.
+  // These plugins transmit data over async $J packets.
+  if (StructuredData::Array *supported_packets =
+          m_gdb_comm.GetSupportedStructuredDataPlugins())
+    MapSupportedStructuredDataPlugins(*supported_packets);
 }
 
 void ProcessGDBRemote::DidLaunch() {


        


More information about the lldb-commits mailing list