[Lldb-commits] [lldb] r334282 - Fix DynamicRegisterInfo copying/moving issue.

Tatyana Krasnukha via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 8 04:28:15 PDT 2018


Author: tkrasnukha
Date: Fri Jun  8 04:28:15 2018
New Revision: 334282

URL: http://llvm.org/viewvc/llvm-project?rev=334282&view=rev
Log:
Fix DynamicRegisterInfo copying/moving issue.

Summary:
Default copy/move constructors and assignment operators leave wrong m_sets[i].registers pointers.

Made the class movable and non-copyable (it's difficult to imagine when it needs to be copied).

Reviewers: clayborg

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D47728

Modified:
    lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
    lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.h

Modified: lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp?rev=334282&r1=334281&r2=334282&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp Fri Jun  8 04:28:15 2018
@@ -21,21 +21,42 @@
 using namespace lldb;
 using namespace lldb_private;
 
-DynamicRegisterInfo::DynamicRegisterInfo()
-    : m_regs(), m_sets(), m_set_reg_nums(), m_set_names(), m_value_regs_map(),
-      m_invalidate_regs_map(), m_dynamic_reg_size_map(),
-      m_reg_data_byte_size(0), m_finalized(false) {}
-
 DynamicRegisterInfo::DynamicRegisterInfo(
     const lldb_private::StructuredData::Dictionary &dict,
-    const lldb_private::ArchSpec &arch)
-    : m_regs(), m_sets(), m_set_reg_nums(), m_set_names(), m_value_regs_map(),
-      m_invalidate_regs_map(), m_dynamic_reg_size_map(),
-      m_reg_data_byte_size(0), m_finalized(false) {
+    const lldb_private::ArchSpec &arch) {
   SetRegisterInfo(dict, arch);
 }
 
-DynamicRegisterInfo::~DynamicRegisterInfo() {}
+DynamicRegisterInfo::DynamicRegisterInfo(DynamicRegisterInfo &&info) {
+  MoveFrom(std::move(info));
+}
+
+DynamicRegisterInfo &
+DynamicRegisterInfo::operator=(DynamicRegisterInfo &&info) {
+  MoveFrom(std::move(info));
+  return *this;
+}
+
+void DynamicRegisterInfo::MoveFrom(DynamicRegisterInfo &&info) {
+  m_regs = std::move(info.m_regs);
+  m_sets = std::move(info.m_sets);
+  m_set_reg_nums = std::move(info.m_set_reg_nums);
+  m_set_names = std::move(info.m_set_names);
+  m_value_regs_map = std::move(info.m_value_regs_map);
+  m_invalidate_regs_map = std::move(info.m_invalidate_regs_map);
+  m_dynamic_reg_size_map = std::move(info.m_dynamic_reg_size_map);
+
+  m_reg_data_byte_size = info.m_reg_data_byte_size;
+  m_finalized = info.m_finalized;
+
+  if (m_finalized) {
+    const size_t num_sets = m_sets.size();
+    for (size_t set = 0; set < num_sets; ++set)
+      m_sets[set].registers = m_set_reg_nums[set].data();
+  }
+
+  info.Clear();
+}
 
 size_t
 DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
@@ -136,7 +157,7 @@ DynamicRegisterInfo::SetRegisterInfo(con
 
                 ConstString containing_reg_name(reg_name_str);
 
-                RegisterInfo *containing_reg_info =
+                const RegisterInfo *containing_reg_info =
                     GetRegisterInfo(containing_reg_name);
                 if (containing_reg_info) {
                   const uint32_t max_bit = containing_reg_info->byte_size * 8;
@@ -205,7 +226,7 @@ DynamicRegisterInfo::SetRegisterInfo(con
               ConstString composite_reg_name;
               if (composite_reg_list->GetItemAtIndexAsString(
                       composite_idx, composite_reg_name, nullptr)) {
-                RegisterInfo *composite_reg_info =
+                const RegisterInfo *composite_reg_info =
                     GetRegisterInfo(composite_reg_name);
                 if (composite_reg_info) {
                   composite_offset = std::min(composite_offset,
@@ -345,7 +366,7 @@ DynamicRegisterInfo::SetRegisterInfo(con
           uint64_t invalidate_reg_num;
           if (invalidate_reg_list->GetItemAtIndexAsString(
                   idx, invalidate_reg_name)) {
-            RegisterInfo *invalidate_reg_info =
+            const RegisterInfo *invalidate_reg_info =
                 GetRegisterInfo(invalidate_reg_name);
             if (invalidate_reg_info) {
               m_invalidate_regs_map[i].push_back(
@@ -725,8 +746,8 @@ void DynamicRegisterInfo::Dump() const {
   }
 }
 
-lldb_private::RegisterInfo *DynamicRegisterInfo::GetRegisterInfo(
-    const lldb_private::ConstString &reg_name) {
+const lldb_private::RegisterInfo *DynamicRegisterInfo::GetRegisterInfo(
+    const lldb_private::ConstString &reg_name) const {
   for (auto &reg_info : m_regs) {
     // We can use pointer comparison since we used a ConstString to set the
     // "name" member in AddRegister()

Modified: lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.h?rev=334282&r1=334281&r2=334282&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.h Fri Jun  8 04:28:15 2018
@@ -23,12 +23,18 @@
 
 class DynamicRegisterInfo {
 public:
-  DynamicRegisterInfo();
+  DynamicRegisterInfo() = default;
 
   DynamicRegisterInfo(const lldb_private::StructuredData::Dictionary &dict,
                       const lldb_private::ArchSpec &arch);
 
-  virtual ~DynamicRegisterInfo();
+  virtual ~DynamicRegisterInfo() = default;
+
+  DynamicRegisterInfo(DynamicRegisterInfo &) = delete;
+  void operator=(DynamicRegisterInfo &) = delete;
+
+  DynamicRegisterInfo(DynamicRegisterInfo &&info);
+  DynamicRegisterInfo &operator=(DynamicRegisterInfo &&info);
 
   size_t SetRegisterInfo(const lldb_private::StructuredData::Dictionary &dict,
                          const lldb_private::ArchSpec &arch);
@@ -75,8 +81,10 @@ protected:
   typedef std::vector<uint8_t> dwarf_opcode;
   typedef std::map<uint32_t, dwarf_opcode> dynamic_reg_size_map;
 
-  lldb_private::RegisterInfo *
-  GetRegisterInfo(const lldb_private::ConstString &reg_name);
+  const lldb_private::RegisterInfo *
+  GetRegisterInfo(const lldb_private::ConstString &reg_name) const;
+
+  void MoveFrom(DynamicRegisterInfo &&info);
 
   reg_collection m_regs;
   set_collection m_sets;
@@ -85,9 +93,8 @@ protected:
   reg_to_regs_map m_value_regs_map;
   reg_to_regs_map m_invalidate_regs_map;
   dynamic_reg_size_map m_dynamic_reg_size_map;
-  size_t m_reg_data_byte_size; // The number of bytes required to store all
-                               // registers
-  bool m_finalized;
+  size_t m_reg_data_byte_size = 0u; // The number of bytes required to store
+                                    // all registers
+  bool m_finalized = false;
 };
-
 #endif // lldb_DynamicRegisterInfo_h_




More information about the lldb-commits mailing list