DavidSpickett created this revision.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

No one was passing nullptr for these.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148228

Files:
  lldb/include/lldb/Core/DumpRegisterValue.h
  lldb/source/Commands/CommandObjectRegister.cpp
  lldb/source/Core/DumpRegisterValue.cpp
  lldb/source/Core/EmulateInstruction.cpp
  lldb/source/Core/FormatEntity.cpp
  
lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
  lldb/source/Target/ThreadPlanCallFunction.cpp
  lldb/source/Target/ThreadPlanTracer.cpp

Index: lldb/source/Target/ThreadPlanTracer.cpp
===================================================================
--- lldb/source/Target/ThreadPlanTracer.cpp
+++ lldb/source/Target/ThreadPlanTracer.cpp
@@ -223,7 +223,7 @@
           reg_value != m_register_values[reg_num]) {
         if (reg_value.GetType() != RegisterValue::eTypeInvalid) {
           stream->PutCString("\n\t");
-          DumpRegisterValue(reg_value, stream, reg_info, true, false,
+          DumpRegisterValue(reg_value, *stream, *reg_info, true, false,
                             eFormatDefault);
         }
       }
Index: lldb/source/Target/ThreadPlanCallFunction.cpp
===================================================================
--- lldb/source/Target/ThreadPlanCallFunction.cpp
+++ lldb/source/Target/ThreadPlanCallFunction.cpp
@@ -163,7 +163,7 @@
          reg_idx < num_registers; ++reg_idx) {
       const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
       if (reg_ctx->ReadRegister(reg_info, reg_value)) {
-        DumpRegisterValue(reg_value, &strm, reg_info, true, false,
+        DumpRegisterValue(reg_value, strm, *reg_info, true, false,
                           eFormatDefault);
         strm.EOL();
       }
Index: lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
===================================================================
--- lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
+++ lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
@@ -500,7 +500,7 @@
     strm.Printf("UnwindAssemblyInstEmulation::ReadRegister  (name = \"%s\") => "
                 "synthetic_value = %i, value = ",
                 reg_info->name, synthetic);
-    DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault);
+    DumpRegisterValue(reg_value, strm, *reg_info, false, false, eFormatDefault);
     log->PutString(strm.GetString());
   }
   return true;
@@ -526,7 +526,7 @@
     strm.Printf(
         "UnwindAssemblyInstEmulation::WriteRegister (name = \"%s\", value = ",
         reg_info->name);
-    DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault);
+    DumpRegisterValue(reg_value, strm, *reg_info, false, false, eFormatDefault);
     strm.PutCString(", context = ");
     context.Dump(strm, instruction);
     log->PutString(strm.GetString());
Index: lldb/source/Core/FormatEntity.cpp
===================================================================
--- lldb/source/Core/FormatEntity.cpp
+++ lldb/source/Core/FormatEntity.cpp
@@ -605,7 +605,7 @@
         if (reg_info) {
           RegisterValue reg_value;
           if (reg_ctx->ReadRegister(reg_info, reg_value)) {
-            DumpRegisterValue(reg_value, &s, reg_info, false, false, format);
+            DumpRegisterValue(reg_value, s, *reg_info, false, false, format);
             return true;
           }
         }
@@ -985,7 +985,7 @@
       if (reg_info) {
         RegisterValue reg_value;
         if (reg_ctx->ReadRegister(reg_info, reg_value)) {
-          DumpRegisterValue(reg_value, &s, reg_info, false, false, format);
+          DumpRegisterValue(reg_value, s, *reg_info, false, false, format);
           return true;
         }
       }
Index: lldb/source/Core/EmulateInstruction.cpp
===================================================================
--- lldb/source/Core/EmulateInstruction.cpp
+++ lldb/source/Core/EmulateInstruction.cpp
@@ -363,7 +363,7 @@
                                               const RegisterValue &reg_value) {
   StreamFile strm(stdout, false);
   strm.Printf("    Write to Register (name = %s, value = ", reg_info->name);
-  DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault);
+  DumpRegisterValue(reg_value, strm, *reg_info, false, false, eFormatDefault);
   strm.PutCString(", context = ");
   context.Dump(strm, instruction);
   strm.EOL();
Index: lldb/source/Core/DumpRegisterValue.cpp
===================================================================
--- lldb/source/Core/DumpRegisterValue.cpp
+++ lldb/source/Core/DumpRegisterValue.cpp
@@ -58,8 +58,8 @@
   vobj_sp->Dump(strm, dump_options);
 }
 
-void lldb_private::DumpRegisterValue(const RegisterValue &reg_val, Stream *s,
-                                     const RegisterInfo *reg_info,
+void lldb_private::DumpRegisterValue(const RegisterValue &reg_val, Stream &s,
+                                     const RegisterInfo &reg_info,
                                      bool prefix_with_name,
                                      bool prefix_with_alt_name, Format format,
                                      uint32_t reg_name_right_align_at,
@@ -82,38 +82,38 @@
     format_string.Printf("%%s");
   std::string fmt = std::string(format_string.GetString());
   if (prefix_with_name) {
-    if (reg_info->name) {
-      s->Printf(fmt.c_str(), reg_info->name);
+    if (reg_info.name) {
+      s.Printf(fmt.c_str(), reg_info.name);
       name_printed = true;
-    } else if (reg_info->alt_name) {
-      s->Printf(fmt.c_str(), reg_info->alt_name);
+    } else if (reg_info.alt_name) {
+      s.Printf(fmt.c_str(), reg_info.alt_name);
       prefix_with_alt_name = false;
       name_printed = true;
     }
   }
   if (prefix_with_alt_name) {
     if (name_printed)
-      s->PutChar('/');
-    if (reg_info->alt_name) {
-      s->Printf(fmt.c_str(), reg_info->alt_name);
+      s.PutChar('/');
+    if (reg_info.alt_name) {
+      s.Printf(fmt.c_str(), reg_info.alt_name);
       name_printed = true;
     } else if (!name_printed) {
       // No alternate name but we were asked to display a name, so show the
       // main name
-      s->Printf(fmt.c_str(), reg_info->name);
+      s.Printf(fmt.c_str(), reg_info.name);
       name_printed = true;
     }
   }
   if (name_printed)
-    s->PutCString(" = ");
+    s.PutCString(" = ");
 
   if (format == eFormatDefault)
-    format = reg_info->format;
+    format = reg_info.format;
 
-  DumpDataExtractor(data, s,
+  DumpDataExtractor(data, &s,
                     0,                    // Offset in "data"
                     format,               // Format to use when dumping
-                    reg_info->byte_size,  // item_byte_size
+                    reg_info.byte_size,   // item_byte_size
                     1,                    // item_count
                     UINT32_MAX,           // num_per_line
                     LLDB_INVALID_ADDRESS, // base_addr
@@ -121,21 +121,21 @@
                     0,                    // item_bit_offset
                     exe_scope);
 
-  if (!print_flags || !reg_info->flags_type || !exe_scope || !target_sp ||
-      (reg_info->byte_size != 4 && reg_info->byte_size != 8))
+  if (!print_flags || !reg_info.flags_type || !exe_scope || !target_sp ||
+      (reg_info.byte_size != 4 && reg_info.byte_size != 8))
     return;
 
   CompilerType fields_type = target_sp->GetRegisterType(
-      reg_info->name, *reg_info->flags_type, reg_info->byte_size);
+      reg_info.name, *reg_info.flags_type, reg_info.byte_size);
 
   // Use a new stream so we can remove a trailing newline later.
   StreamString fields_stream;
 
-  if (reg_info->byte_size == 4) {
-    dump_type_value(fields_type, reg_val.GetAsUInt32(), exe_scope, *reg_info,
+  if (reg_info.byte_size == 4) {
+    dump_type_value(fields_type, reg_val.GetAsUInt32(), exe_scope, reg_info,
                     fields_stream);
   } else {
-    dump_type_value(fields_type, reg_val.GetAsUInt64(), exe_scope, *reg_info,
+    dump_type_value(fields_type, reg_val.GetAsUInt64(), exe_scope, reg_info,
                     fields_stream);
   }
 
@@ -149,7 +149,7 @@
   llvm::StringRef fields_str = fields_stream.GetString().drop_back();
 
   // End the line that contains "    foo = 0x12345678".
-  s->EOL();
+  s.EOL();
 
   // Then split the value lines and indent each one.
   bool first = true;
@@ -157,18 +157,18 @@
     std::pair<llvm::StringRef, llvm::StringRef> split = fields_str.split('\n');
     fields_str = split.second;
     // Indent as far as the register name did.
-    s->Printf(fmt.c_str(), "");
+    s.Printf(fmt.c_str(), "");
 
     // Lines after the first won't have " = " so compensate for that.
     if (!first)
-      (*s) << "   ";
+      s << "   ";
     first = false;
 
-    (*s) << split.first;
+    s << split.first;
 
     // On the last line we don't want a newline because the command will add
     // one too.
     if (fields_str.size())
-      s->EOL();
+      s.EOL();
   }
 }
Index: lldb/source/Commands/CommandObjectRegister.cpp
===================================================================
--- lldb/source/Commands/CommandObjectRegister.cpp
+++ lldb/source/Commands/CommandObjectRegister.cpp
@@ -84,42 +84,38 @@
   Options *GetOptions() override { return &m_option_group; }
 
   bool DumpRegister(const ExecutionContext &exe_ctx, Stream &strm,
-                    RegisterContext *reg_ctx, const RegisterInfo *reg_info,
+                    RegisterContext &reg_ctx, const RegisterInfo &reg_info,
                     bool print_flags) {
-    if (reg_info) {
-      RegisterValue reg_value;
-
-      if (reg_ctx->ReadRegister(reg_info, reg_value)) {
-        strm.Indent();
-
-        bool prefix_with_altname = (bool)m_command_options.alternate_name;
-        bool prefix_with_name = !prefix_with_altname;
-        DumpRegisterValue(reg_value, &strm, reg_info, prefix_with_name,
-                          prefix_with_altname, m_format_options.GetFormat(), 8,
-                          exe_ctx.GetBestExecutionContextScope(), print_flags,
-                          exe_ctx.GetTargetSP());
-        if ((reg_info->encoding == eEncodingUint) ||
-            (reg_info->encoding == eEncodingSint)) {
-          Process *process = exe_ctx.GetProcessPtr();
-          if (process && reg_info->byte_size == process->GetAddressByteSize()) {
-            addr_t reg_addr = reg_value.GetAsUInt64(LLDB_INVALID_ADDRESS);
-            if (reg_addr != LLDB_INVALID_ADDRESS) {
-              Address so_reg_addr;
-              if (exe_ctx.GetTargetRef()
-                      .GetSectionLoadList()
-                      .ResolveLoadAddress(reg_addr, so_reg_addr)) {
-                strm.PutCString("  ");
-                so_reg_addr.Dump(&strm, exe_ctx.GetBestExecutionContextScope(),
-                                 Address::DumpStyleResolvedDescription);
-              }
-            }
+    RegisterValue reg_value;
+    if (!reg_ctx.ReadRegister(&reg_info, reg_value))
+      return false;
+
+    strm.Indent();
+
+    bool prefix_with_altname = (bool)m_command_options.alternate_name;
+    bool prefix_with_name = !prefix_with_altname;
+    DumpRegisterValue(reg_value, strm, reg_info, prefix_with_name,
+                      prefix_with_altname, m_format_options.GetFormat(), 8,
+                      exe_ctx.GetBestExecutionContextScope(), print_flags,
+                      exe_ctx.GetTargetSP());
+    if ((reg_info.encoding == eEncodingUint) ||
+        (reg_info.encoding == eEncodingSint)) {
+      Process *process = exe_ctx.GetProcessPtr();
+      if (process && reg_info.byte_size == process->GetAddressByteSize()) {
+        addr_t reg_addr = reg_value.GetAsUInt64(LLDB_INVALID_ADDRESS);
+        if (reg_addr != LLDB_INVALID_ADDRESS) {
+          Address so_reg_addr;
+          if (exe_ctx.GetTargetRef().GetSectionLoadList().ResolveLoadAddress(
+                  reg_addr, so_reg_addr)) {
+            strm.PutCString("  ");
+            so_reg_addr.Dump(&strm, exe_ctx.GetBestExecutionContextScope(),
+                             Address::DumpStyleResolvedDescription);
           }
         }
-        strm.EOL();
-        return true;
       }
     }
-    return false;
+    strm.EOL();
+    return true;
   }
 
   bool DumpRegisterSet(const ExecutionContext &exe_ctx, Stream &strm,
@@ -144,8 +140,8 @@
         if (primitive_only && reg_info && reg_info->value_regs)
           continue;
 
-        if (DumpRegister(exe_ctx, strm, reg_ctx, reg_info,
-                         /*print_flags=*/false))
+        if (reg_info && DumpRegister(exe_ctx, strm, *reg_ctx, *reg_info,
+                                     /*print_flags=*/false))
           ++available_count;
         else
           ++unavailable_count;
@@ -165,7 +161,6 @@
     Stream &strm = result.GetOutputStream();
     RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext();
 
-    const RegisterInfo *reg_info = nullptr;
     if (command.GetArgumentCount() == 0) {
       size_t set_idx;
 
@@ -218,10 +213,9 @@
           auto arg_str = entry.ref();
           arg_str.consume_front("$");
 
-          reg_info = reg_ctx->GetRegisterInfoByName(arg_str);
-
-          if (reg_info) {
-            if (!DumpRegister(m_exe_ctx, strm, reg_ctx, reg_info,
+          if (const RegisterInfo *reg_info =
+                  reg_ctx->GetRegisterInfoByName(arg_str)) {
+            if (!DumpRegister(m_exe_ctx, strm, *reg_ctx, *reg_info,
                               /*print_flags=*/true))
               strm.Printf("%-12s = error: unavailable\n", reg_info->name);
           } else {
Index: lldb/include/lldb/Core/DumpRegisterValue.h
===================================================================
--- lldb/include/lldb/Core/DumpRegisterValue.h
+++ lldb/include/lldb/Core/DumpRegisterValue.h
@@ -24,8 +24,8 @@
 // all.
 // Set print_flags to true to print register fields if they are available.
 // If you do so, target_sp must be non-null for it to work.
-void DumpRegisterValue(const RegisterValue &reg_val, Stream *s,
-                       const RegisterInfo *reg_info, bool prefix_with_name,
+void DumpRegisterValue(const RegisterValue &reg_val, Stream &s,
+                       const RegisterInfo &reg_info, bool prefix_with_name,
                        bool prefix_with_alt_name, lldb::Format format,
                        uint32_t reg_name_right_align_at = 0,
                        ExecutionContextScope *exe_scope = nullptr,
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] ... David Spickett via Phabricator via lldb-commits

Reply via email to