[Lldb-commits] [lldb] r369939 - [lldb][NFC] Remove dead code that handles situations where LLDB has no dummy target

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 26 11:12:44 PDT 2019


Author: teemperor
Date: Mon Aug 26 11:12:44 2019
New Revision: 369939

URL: http://llvm.org/viewvc/llvm-project?rev=369939&view=rev
Log:
[lldb][NFC] Remove dead code that handles situations where LLDB has no dummy target

Summary:
We always have a dummy target, so any error handling regarding a missing dummy target is dead code now.
Also makes the CommandObject methods that return Target& to express this fact in the API.

This patch just for the CommandObject part of LLDB. I'll migrate the rest of LLDB in a follow-up patch that's WIP.

Reviewers: labath

Reviewed By: labath

Subscribers: abidh, lldb-commits

Tags: #lldb

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

Modified:
    lldb/trunk/include/lldb/Interpreter/CommandObject.h
    lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
    lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp
    lldb/trunk/source/Commands/CommandObjectExpression.cpp
    lldb/trunk/source/Commands/CommandObjectFrame.cpp
    lldb/trunk/source/Commands/CommandObjectStats.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Interpreter/CommandObject.cpp
    lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp

Modified: lldb/trunk/include/lldb/Interpreter/CommandObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObject.h?rev=369939&r1=369938&r2=369939&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObject.h Mon Aug 26 11:12:44 2019
@@ -340,8 +340,8 @@ protected:
   // This is for use in the command interpreter, when you either want the
   // selected target, or if no target is present you want to prime the dummy
   // target with entities that will be copied over to new targets.
-  Target *GetSelectedOrDummyTarget(bool prefer_dummy = false);
-  Target *GetDummyTarget();
+  Target &GetSelectedOrDummyTarget(bool prefer_dummy = false);
+  Target &GetDummyTarget();
 
   // If a command needs to use the "current" thread, use this call. Command
   // objects will have an ExecutionContext to use, and that may or may not have

Modified: lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp?rev=369939&r1=369938&r2=369939&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp Mon Aug 26 11:12:44 2019
@@ -550,14 +550,7 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget(m_dummy_options.m_use_dummy);
-
-    if (target == nullptr) {
-      result.AppendError("Invalid target.  Must set target before setting "
-                         "breakpoints (see 'target create' command).");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
+    Target &target = GetSelectedOrDummyTarget(m_dummy_options.m_use_dummy);
 
     // The following are the various types of breakpoints that could be set:
     //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location)
@@ -619,16 +612,11 @@ protected:
       // Only check for inline functions if
       LazyBool check_inlines = eLazyBoolCalculate;
 
-      bp_sp = target->CreateBreakpoint(&(m_options.m_modules), 
-                                       file,
-                                       m_options.m_line_num,
-                                       m_options.m_column,
-                                       m_options.m_offset_addr,
-                                       check_inlines, 
-                                       m_options.m_skip_prologue,
-                                       internal, 
-                                       m_options.m_hardware,
-                                       m_options.m_move_to_nearest_code);
+      bp_sp = target.CreateBreakpoint(
+          &(m_options.m_modules), file, m_options.m_line_num,
+          m_options.m_column, m_options.m_offset_addr, check_inlines,
+          m_options.m_skip_prologue, internal, m_options.m_hardware,
+          m_options.m_move_to_nearest_code);
     } break;
 
     case eSetTypeAddress: // Breakpoint by address
@@ -640,12 +628,11 @@ protected:
       if (num_modules_specified == 1) {
         const FileSpec *file_spec =
             m_options.m_modules.GetFileSpecPointerAtIndex(0);
-        bp_sp = target->CreateAddressInModuleBreakpoint(m_options.m_load_addr,
-                                                        internal, file_spec,
-                                                        m_options.m_hardware);
+        bp_sp = target.CreateAddressInModuleBreakpoint(
+            m_options.m_load_addr, internal, file_spec, m_options.m_hardware);
       } else if (num_modules_specified == 0) {
-        bp_sp = target->CreateBreakpoint(m_options.m_load_addr, internal,
-                                         m_options.m_hardware);
+        bp_sp = target.CreateBreakpoint(m_options.m_load_addr, internal,
+                                        m_options.m_hardware);
       } else {
         result.AppendError("Only one shared library can be specified for "
                            "address breakpoints.");
@@ -661,15 +648,11 @@ protected:
       if (name_type_mask == 0)
         name_type_mask = eFunctionNameTypeAuto;
 
-      bp_sp = target->CreateBreakpoint(&(m_options.m_modules), 
-                                       &(m_options.m_filenames),
-                                       m_options.m_func_names, 
-                                       name_type_mask, 
-                                       m_options.m_language,
-                                       m_options.m_offset_addr, 
-                                       m_options.m_skip_prologue, 
-                                       internal,
-                                       m_options.m_hardware);
+      bp_sp = target.CreateBreakpoint(
+          &(m_options.m_modules), &(m_options.m_filenames),
+          m_options.m_func_names, name_type_mask, m_options.m_language,
+          m_options.m_offset_addr, m_options.m_skip_prologue, internal,
+          m_options.m_hardware);
     } break;
 
     case eSetTypeFunctionRegexp: // Breakpoint by regular expression function
@@ -684,13 +667,10 @@ protected:
           return false;
         }
 
-        bp_sp = target->CreateFuncRegexBreakpoint(&(m_options.m_modules), 
-                                                  &(m_options.m_filenames), 
-                                                  regexp,
-                                                  m_options.m_language, 
-                                                  m_options.m_skip_prologue, 
-                                                  internal,
-                                                  m_options.m_hardware);
+        bp_sp = target.CreateFuncRegexBreakpoint(
+            &(m_options.m_modules), &(m_options.m_filenames), regexp,
+            m_options.m_language, m_options.m_skip_prologue, internal,
+            m_options.m_hardware);
       }
       break;
     case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
@@ -717,30 +697,22 @@ protected:
         result.SetStatus(eReturnStatusFailed);
         return false;
       }
-      bp_sp = 
-          target->CreateSourceRegexBreakpoint(&(m_options.m_modules), 
-                                              &(m_options.m_filenames),
-                                              m_options
-                                                  .m_source_regex_func_names,
-                                              regexp,
-                                              internal,
-                                              m_options.m_hardware,
-                                              m_options.m_move_to_nearest_code);
+      bp_sp = target.CreateSourceRegexBreakpoint(
+          &(m_options.m_modules), &(m_options.m_filenames),
+          m_options.m_source_regex_func_names, regexp, internal,
+          m_options.m_hardware, m_options.m_move_to_nearest_code);
     } break;
     case eSetTypeException: {
       Status precond_error;
-      bp_sp = target->CreateExceptionBreakpoint(m_options.m_exception_language, 
-                                                m_options.m_catch_bp,
-                                                m_options.m_throw_bp, 
-                                                internal,
-                                                &m_options
-                                                    .m_exception_extra_args, 
-                                                &precond_error);
+      bp_sp = target.CreateExceptionBreakpoint(
+          m_options.m_exception_language, m_options.m_catch_bp,
+          m_options.m_throw_bp, internal, &m_options.m_exception_extra_args,
+          &precond_error);
       if (precond_error.Fail()) {
         result.AppendErrorWithFormat(
             "Error setting extra exception arguments: %s",
             precond_error.AsCString());
-        target->RemoveBreakpointByID(bp_sp->GetID());
+        target.RemoveBreakpointByID(bp_sp->GetID());
         result.SetStatus(eReturnStatusFailed);
         return false;
       }
@@ -748,18 +720,15 @@ protected:
     case eSetTypeScripted: {
 
       Status error;
-      bp_sp = target->CreateScriptedBreakpoint(m_options.m_python_class,
-                                               &(m_options.m_modules), 
-                                               &(m_options.m_filenames),
-                                               false,
-                                               m_options.m_hardware,
-                                               m_options.m_extra_args_sp,
-                                               &error);
+      bp_sp = target.CreateScriptedBreakpoint(
+          m_options.m_python_class, &(m_options.m_modules),
+          &(m_options.m_filenames), false, m_options.m_hardware,
+          m_options.m_extra_args_sp, &error);
       if (error.Fail()) {
         result.AppendErrorWithFormat(
             "Error setting extra exception arguments: %s",
             error.AsCString());
-        target->RemoveBreakpointByID(bp_sp->GetID());
+        target.RemoveBreakpointByID(bp_sp->GetID());
         result.SetStatus(eReturnStatusFailed);
         return false;
       }
@@ -775,11 +744,11 @@ protected:
       if (!m_options.m_breakpoint_names.empty()) {
         Status name_error;
         for (auto name : m_options.m_breakpoint_names) {
-          target->AddNameToBreakpoint(bp_sp, name.c_str(), name_error);
+          target.AddNameToBreakpoint(bp_sp, name.c_str(), name_error);
           if (name_error.Fail()) {
             result.AppendErrorWithFormat("Invalid breakpoint name: %s",
                                          name.c_str());
-            target->RemoveBreakpointByID(bp_sp->GetID());
+            target.RemoveBreakpointByID(bp_sp->GetID());
             result.SetStatus(eReturnStatusFailed);
             return false;
           }
@@ -792,7 +761,7 @@ protected:
       const bool show_locations = false;
       bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial,
                          show_locations);
-      if (target == GetDebugger().GetDummyTarget())
+      if (&target == &GetDummyTarget())
         output_stream.Printf("Breakpoint set in dummy target, will get copied "
                              "into future targets.\n");
       else {
@@ -814,12 +783,12 @@ protected:
   }
 
 private:
-  bool GetDefaultFile(Target *target, FileSpec &file,
+  bool GetDefaultFile(Target &target, FileSpec &file,
                       CommandReturnObject &result) {
     uint32_t default_line;
     // First use the Source Manager's default file. Then use the current stack
     // frame's file.
-    if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) {
+    if (!target.GetSourceManager().GetDefaultFileAndLine(file, default_line)) {
       StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
       if (cur_frame == nullptr) {
         result.AppendError(
@@ -888,20 +857,15 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget(m_dummy_opts.m_use_dummy);
-    if (target == nullptr) {
-      result.AppendError("Invalid target.  No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
+    Target &target = GetSelectedOrDummyTarget(m_dummy_opts.m_use_dummy);
 
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList().GetListMutex(lock);
+    target.GetBreakpointList().GetListMutex(lock);
 
     BreakpointIDList valid_bp_ids;
 
     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-        command, target, result, &valid_bp_ids, 
+        command, &target, result, &valid_bp_ids,
         BreakpointName::Permissions::PermissionKinds::disablePerm);
 
     if (result.Succeeded()) {
@@ -911,7 +875,7 @@ protected:
 
         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
           Breakpoint *bp =
-              target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
+              target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
           if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
             BreakpointLocation *location =
                 bp->FindLocationByID(cur_bp_id.GetLocationID()).get();
@@ -957,17 +921,12 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
-    if (target == nullptr) {
-      result.AppendError("Invalid target.  No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
+    Target &target = GetSelectedOrDummyTarget();
 
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList().GetListMutex(lock);
+    target.GetBreakpointList().GetListMutex(lock);
 
-    const BreakpointList &breakpoints = target->GetBreakpointList();
+    const BreakpointList &breakpoints = target.GetBreakpointList();
 
     size_t num_breakpoints = breakpoints.GetSize();
 
@@ -979,7 +938,7 @@ protected:
 
     if (command.empty()) {
       // No breakpoint selected; enable all currently set breakpoints.
-      target->EnableAllowedBreakpoints();
+      target.EnableAllowedBreakpoints();
       result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64
                                      " breakpoints)\n",
                                      (uint64_t)num_breakpoints);
@@ -988,7 +947,7 @@ protected:
       // Particular breakpoint selected; enable that breakpoint.
       BreakpointIDList valid_bp_ids;
       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-          command, target, result, &valid_bp_ids, 
+          command, &target, result, &valid_bp_ids,
           BreakpointName::Permissions::PermissionKinds::disablePerm);
 
       if (result.Succeeded()) {
@@ -1000,7 +959,7 @@ protected:
 
           if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
             Breakpoint *breakpoint =
-                target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
+                target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
               BreakpointLocation *location =
                   breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
@@ -1070,17 +1029,11 @@ the second re-enables the first location
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
-    if (target == nullptr) {
-      result.AppendError("Invalid target.  No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
-
+    Target &target = GetSelectedOrDummyTarget();
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList().GetListMutex(lock);
+    target.GetBreakpointList().GetListMutex(lock);
 
-    const BreakpointList &breakpoints = target->GetBreakpointList();
+    const BreakpointList &breakpoints = target.GetBreakpointList();
     size_t num_breakpoints = breakpoints.GetSize();
 
     if (num_breakpoints == 0) {
@@ -1091,7 +1044,7 @@ protected:
 
     if (command.empty()) {
       // No breakpoint selected; disable all currently set breakpoints.
-      target->DisableAllowedBreakpoints();
+      target.DisableAllowedBreakpoints();
       result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64
                                      " breakpoints)\n",
                                      (uint64_t)num_breakpoints);
@@ -1101,7 +1054,7 @@ protected:
       BreakpointIDList valid_bp_ids;
 
       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-          command, target, result, &valid_bp_ids, 
+          command, &target, result, &valid_bp_ids,
           BreakpointName::Permissions::PermissionKinds::disablePerm);
 
       if (result.Succeeded()) {
@@ -1113,7 +1066,7 @@ protected:
 
           if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
             Breakpoint *breakpoint =
-                target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
+                target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
               BreakpointLocation *location =
                   breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
@@ -1228,18 +1181,12 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
-
-    if (target == nullptr) {
-      result.AppendError("Invalid target. No current target or breakpoints.");
-      result.SetStatus(eReturnStatusSuccessFinishNoResult);
-      return true;
-    }
+    Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
 
     const BreakpointList &breakpoints =
-        target->GetBreakpointList(m_options.m_internal);
+        target.GetBreakpointList(m_options.m_internal);
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList(m_options.m_internal).GetListMutex(lock);
+    target.GetBreakpointList(m_options.m_internal).GetListMutex(lock);
 
     size_t num_breakpoints = breakpoints.GetSize();
 
@@ -1265,14 +1212,14 @@ protected:
       // Particular breakpoints selected; show info about that breakpoint.
       BreakpointIDList valid_bp_ids;
       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-          command, target, result, &valid_bp_ids, 
+          command, &target, result, &valid_bp_ids,
           BreakpointName::Permissions::PermissionKinds::listPerm);
 
       if (result.Succeeded()) {
         for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) {
           BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
           Breakpoint *breakpoint =
-              target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
+              target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
           AddBreakpointDescription(&output_stream, breakpoint,
                                    m_options.m_level);
         }
@@ -1357,12 +1304,7 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
-    if (target == nullptr) {
-      result.AppendError("Invalid target. No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
+    Target &target = GetSelectedOrDummyTarget();
 
     // The following are the various types of breakpoints that could be
     // cleared:
@@ -1374,9 +1316,9 @@ protected:
       break_type = eClearTypeFileAndLine;
 
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList().GetListMutex(lock);
+    target.GetBreakpointList().GetListMutex(lock);
 
-    BreakpointList &breakpoints = target->GetBreakpointList();
+    BreakpointList &breakpoints = target.GetBreakpointList();
     size_t num_breakpoints = breakpoints.GetSize();
 
     // Early return if there's no breakpoint at all.
@@ -1410,7 +1352,7 @@ protected:
           if (loc_coll.GetSize() == 0) {
             bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
             ss.EOL();
-            target->RemoveBreakpointByID(bp->GetID());
+            target.RemoveBreakpointByID(bp->GetID());
             ++num_cleared;
           }
         }
@@ -1508,18 +1450,12 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
-
-    if (target == nullptr) {
-      result.AppendError("Invalid target. No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
+    Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
 
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList().GetListMutex(lock);
+    target.GetBreakpointList().GetListMutex(lock);
 
-    const BreakpointList &breakpoints = target->GetBreakpointList();
+    const BreakpointList &breakpoints = target.GetBreakpointList();
 
     size_t num_breakpoints = breakpoints.GetSize();
 
@@ -1536,7 +1472,7 @@ protected:
               true)) {
         result.AppendMessage("Operation cancelled...");
       } else {
-        target->RemoveAllowedBreakpoints();
+        target.RemoveAllowedBreakpoints();
         result.AppendMessageWithFormat(
             "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n",
             (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
@@ -1546,7 +1482,7 @@ protected:
       // Particular breakpoint selected; disable that breakpoint.
       BreakpointIDList valid_bp_ids;
       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-          command, target, result, &valid_bp_ids, 
+          command, &target, result, &valid_bp_ids,
           BreakpointName::Permissions::PermissionKinds::deletePerm);
 
       if (result.Succeeded()) {
@@ -1559,7 +1495,7 @@ protected:
           if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
               Breakpoint *breakpoint =
-                  target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
+                  target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
               BreakpointLocation *location =
                   breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
               // It makes no sense to try to delete individual locations, so we
@@ -1569,7 +1505,7 @@ protected:
                 ++disable_count;
               }
             } else {
-              target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID());
+              target.RemoveBreakpointByID(cur_bp_id.GetBreakpointID());
               ++delete_count;
             }
           }
@@ -1762,18 +1698,11 @@ protected:
       result.SetStatus(eReturnStatusFailed);
       return false;
     }
-    
-    Target *target =
-        GetSelectedOrDummyTarget(false);
 
-    if (target == nullptr) {
-      result.AppendError("Invalid target. No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
+    Target &target = GetSelectedOrDummyTarget(false);
 
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList().GetListMutex(lock);
+    target.GetBreakpointList().GetListMutex(lock);
 
     // Make a pass through first to see that all the names are legal.
     for (auto &entry : command.entries()) {
@@ -1792,7 +1721,7 @@ protected:
     if (m_bp_id.m_breakpoint.OptionWasSet())
     {
       lldb::break_id_t bp_id = m_bp_id.m_breakpoint.GetUInt64Value();
-      bp_sp = target->GetBreakpointByID(bp_id);
+      bp_sp = target.GetBreakpointByID(bp_id);
       if (!bp_sp)
       {
         result.AppendErrorWithFormatv("Could not find specified breakpoint {0}",
@@ -1805,18 +1734,17 @@ protected:
     Status error;
     for (auto &entry : command.entries()) {
       ConstString name(entry.c_str());
-      BreakpointName *bp_name = target->FindBreakpointName(name, true, error);
+      BreakpointName *bp_name = target.FindBreakpointName(name, true, error);
       if (!bp_name)
         continue;
       if (m_bp_id.m_help_string.OptionWasSet())
         bp_name->SetHelp(m_bp_id.m_help_string.GetStringValue().str().c_str());
       
       if (bp_sp)
-        target->ConfigureBreakpointName(*bp_name,
-                                       *bp_sp->GetOptions(),
+        target.ConfigureBreakpointName(*bp_name, *bp_sp->GetOptions(),
                                        m_access_options.GetPermissions());
       else
-        target->ConfigureBreakpointName(*bp_name,
+        target.ConfigureBreakpointName(*bp_name,
                                        m_bp_opts.GetBreakpointOptions(),
                                        m_access_options.GetPermissions());
     }
@@ -1861,19 +1789,13 @@ protected:
       return false;
     }
 
-    Target *target =
+    Target &target =
         GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
 
-    if (target == nullptr) {
-      result.AppendError("Invalid target. No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
-
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList().GetListMutex(lock);
+    target.GetBreakpointList().GetListMutex(lock);
 
-    const BreakpointList &breakpoints = target->GetBreakpointList();
+    const BreakpointList &breakpoints = target.GetBreakpointList();
 
     size_t num_breakpoints = breakpoints.GetSize();
     if (num_breakpoints == 0) {
@@ -1885,7 +1807,7 @@ protected:
     // Particular breakpoint selected; disable that breakpoint.
     BreakpointIDList valid_bp_ids;
     CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
-        command, target, result, &valid_bp_ids, 
+        command, &target, result, &valid_bp_ids,
         BreakpointName::Permissions::PermissionKinds::listPerm);
 
     if (result.Succeeded()) {
@@ -1902,7 +1824,7 @@ protected:
         lldb::break_id_t bp_id =
             valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
         BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
-        target->AddNameToBreakpoint(bp_sp, bp_name, error);
+        target.AddNameToBreakpoint(bp_sp, bp_name, error);
       }
     }
 
@@ -1946,19 +1868,13 @@ protected:
       return false;
     }
 
-    Target *target =
+    Target &target =
         GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
 
-    if (target == nullptr) {
-      result.AppendError("Invalid target. No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
-
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList().GetListMutex(lock);
+    target.GetBreakpointList().GetListMutex(lock);
 
-    const BreakpointList &breakpoints = target->GetBreakpointList();
+    const BreakpointList &breakpoints = target.GetBreakpointList();
 
     size_t num_breakpoints = breakpoints.GetSize();
     if (num_breakpoints == 0) {
@@ -1970,7 +1886,7 @@ protected:
     // Particular breakpoint selected; disable that breakpoint.
     BreakpointIDList valid_bp_ids;
     CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
-        command, target, result, &valid_bp_ids, 
+        command, &target, result, &valid_bp_ids,
         BreakpointName::Permissions::PermissionKinds::deletePerm);
 
     if (result.Succeeded()) {
@@ -1985,7 +1901,7 @@ protected:
         lldb::break_id_t bp_id =
             valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
         BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
-        target->RemoveNameFromBreakpoint(bp_sp, bp_name);
+        target.RemoveNameFromBreakpoint(bp_sp, bp_name);
       }
     }
 
@@ -2016,19 +1932,12 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target =
+    Target &target =
         GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
 
-    if (target == nullptr) {
-      result.AppendError("Invalid target. No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
-    
-    
     std::vector<std::string> name_list;
     if (command.empty()) {
-      target->GetBreakpointNames(name_list);
+      target.GetBreakpointNames(name_list);
     } else {
       for (const Args::ArgEntry &arg : command)
       {
@@ -2043,9 +1952,8 @@ protected:
         const char *name = name_str.c_str();
         // First print out the options for the name:
         Status error;
-        BreakpointName *bp_name = target->FindBreakpointName(ConstString(name),
-                                                             false,
-                                                             error);
+        BreakpointName *bp_name =
+            target.FindBreakpointName(ConstString(name), false, error);
         if (bp_name)
         {
           StreamString s;
@@ -2056,9 +1964,9 @@ protected:
           }
         
           std::unique_lock<std::recursive_mutex> lock;
-          target->GetBreakpointList().GetListMutex(lock);
+          target.GetBreakpointList().GetListMutex(lock);
 
-          BreakpointList &breakpoints = target->GetBreakpointList();
+          BreakpointList &breakpoints = target.GetBreakpointList();
           bool any_set = false;
           for (BreakpointSP bp_sp : breakpoints.Breakpoints()) {
             if (bp_sp->MatchesName(name)) {
@@ -2185,21 +2093,16 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
-    if (target == nullptr) {
-      result.AppendError("Invalid target.  No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
+    Target &target = GetSelectedOrDummyTarget();
 
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList().GetListMutex(lock);
+    target.GetBreakpointList().GetListMutex(lock);
 
     FileSpec input_spec(m_options.m_filename);
     FileSystem::Instance().Resolve(input_spec);
     BreakpointIDList new_bps;
-    Status error = target->CreateBreakpointsFromFile(
-        input_spec, m_options.m_names, new_bps);
+    Status error = target.CreateBreakpointsFromFile(input_spec,
+                                                    m_options.m_names, new_bps);
 
     if (!error.Success()) {
       result.AppendError(error.AsCString());
@@ -2217,7 +2120,7 @@ protected:
       result.AppendMessage("New breakpoints:");
       for (size_t i = 0; i < num_breakpoints; ++i) {
         BreakpointID bp_id = new_bps.GetBreakpointIDAtIndex(i);
-        Breakpoint *bp = target->GetBreakpointList()
+        Breakpoint *bp = target.GetBreakpointList()
                              .FindBreakpointByID(bp_id.GetBreakpointID())
                              .get();
         if (bp)
@@ -2301,20 +2204,15 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
-    if (target == nullptr) {
-      result.AppendError("Invalid target.  No existing target or breakpoints.");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
+    Target &target = GetSelectedOrDummyTarget();
 
     std::unique_lock<std::recursive_mutex> lock;
-    target->GetBreakpointList().GetListMutex(lock);
+    target.GetBreakpointList().GetListMutex(lock);
 
     BreakpointIDList valid_bp_ids;
     if (!command.empty()) {
       CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
-          command, target, result, &valid_bp_ids, 
+          command, &target, result, &valid_bp_ids,
           BreakpointName::Permissions::PermissionKinds::listPerm);
 
       if (!result.Succeeded()) {
@@ -2324,8 +2222,8 @@ protected:
     }
     FileSpec file_spec(m_options.m_filename);
     FileSystem::Instance().Resolve(file_spec);
-    Status error = target->SerializeBreakpointsToFile(file_spec, valid_bp_ids,
-                                                      m_options.m_append);
+    Status error = target.SerializeBreakpointsToFile(file_spec, valid_bp_ids,
+                                                     m_options.m_append);
     if (!error.Success()) {
       result.AppendErrorWithFormat("error serializing breakpoints: %s.",
                                    error.AsCString());

Modified: lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp?rev=369939&r1=369938&r2=369939&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp Mon Aug 26 11:12:44 2019
@@ -361,16 +361,9 @@ are no syntax errors may indicate that a
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
+    Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
 
-    if (target == nullptr) {
-      result.AppendError("There is not a current executable; there are no "
-                         "breakpoints to which to add commands");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
-
-    const BreakpointList &breakpoints = target->GetBreakpointList();
+    const BreakpointList &breakpoints = target.GetBreakpointList();
     size_t num_breakpoints = breakpoints.GetSize();
 
     if (num_breakpoints == 0) {
@@ -389,7 +382,7 @@ protected:
 
     BreakpointIDList valid_bp_ids;
     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-        command, target, result, &valid_bp_ids,
+        command, &target, result, &valid_bp_ids,
         BreakpointName::Permissions::PermissionKinds::listPerm);
 
     m_bp_options_vec.clear();
@@ -401,7 +394,7 @@ protected:
         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
           Breakpoint *bp =
-              target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
+              target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
           BreakpointOptions *bp_options = nullptr;
           if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID) {
             // This breakpoint does not have an associated location.
@@ -536,16 +529,9 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
-
-    if (target == nullptr) {
-      result.AppendError("There is not a current executable; there are no "
-                         "breakpoints from which to delete commands");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
+    Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
 
-    const BreakpointList &breakpoints = target->GetBreakpointList();
+    const BreakpointList &breakpoints = target.GetBreakpointList();
     size_t num_breakpoints = breakpoints.GetSize();
 
     if (num_breakpoints == 0) {
@@ -563,7 +549,7 @@ protected:
 
     BreakpointIDList valid_bp_ids;
     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-        command, target, result, &valid_bp_ids,
+        command, &target, result, &valid_bp_ids,
         BreakpointName::Permissions::PermissionKinds::listPerm);
 
     if (result.Succeeded()) {
@@ -572,7 +558,7 @@ protected:
         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
           Breakpoint *bp =
-              target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
+              target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
           if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
             BreakpointLocationSP bp_loc_sp(
                 bp->FindLocationByID(cur_bp_id.GetLocationID()));

Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=369939&r1=369938&r2=369939&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Mon Aug 26 11:12:44 2019
@@ -316,10 +316,7 @@ void CommandObjectExpression::HandleComp
   Target *target = exe_ctx.GetTargetPtr();
 
   if (!target)
-    target = GetDummyTarget();
-
-  if (!target)
-    return;
+    target = &GetDummyTarget();
 
   unsigned cursor_pos = request.GetRawCursorPos();
   llvm::StringRef code = request.GetRawLine();
@@ -380,9 +377,8 @@ bool CommandObjectExpression::EvaluateEx
   Target *target = exe_ctx.GetTargetPtr();
 
   if (!target)
-    target = GetDummyTarget();
+    target = &GetDummyTarget();
 
-  if (target) {
     lldb::ValueObjectSP result_valobj_sp;
     bool keep_in_memory = true;
     StackFrame *frame = exe_ctx.GetFramePtr();
@@ -494,10 +490,6 @@ bool CommandObjectExpression::EvaluateEx
         }
       }
     }
-  } else {
-    error_stream->Printf("error: invalid execution context for expression\n");
-    return false;
-  }
 
   return true;
 }
@@ -662,11 +654,11 @@ bool CommandObjectExpression::DoExecute(
     }
   }
 
-  Target *target = GetSelectedOrDummyTarget();
+  Target &target = GetSelectedOrDummyTarget();
   if (EvaluateExpression(expr, &(result.GetOutputStream()),
                          &(result.GetErrorStream()), &result)) {
 
-    if (!m_fixed_expression.empty() && target->GetEnableNotifyAboutFixIts()) {
+    if (!m_fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) {
       CommandHistory &history = m_interpreter.GetCommandHistory();
       // FIXME: Can we figure out what the user actually typed (e.g. some alias
       // for expr???)
@@ -681,12 +673,12 @@ bool CommandObjectExpression::DoExecute(
       history.AppendString(fixed_command);
     }
     // Increment statistics to record this expression evaluation success.
-    target->IncrementStats(StatisticKind::ExpressionSuccessful);
+    target.IncrementStats(StatisticKind::ExpressionSuccessful);
     return true;
   }
 
   // Increment statistics to record this expression evaluation failure.
-  target->IncrementStats(StatisticKind::ExpressionFailure);
+  target.IncrementStats(StatisticKind::ExpressionFailure);
   result.SetStatus(eReturnStatusFailed);
   return false;
 }

Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=369939&r1=369938&r2=369939&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Mon Aug 26 11:12:44 2019
@@ -713,11 +713,11 @@ protected:
 
     // Increment statistics.
     bool res = result.Succeeded();
-    Target *target = GetSelectedOrDummyTarget();
+    Target &target = GetSelectedOrDummyTarget();
     if (res)
-      target->IncrementStats(StatisticKind::FrameVarSuccess);
+      target.IncrementStats(StatisticKind::FrameVarSuccess);
     else
-      target->IncrementStats(StatisticKind::FrameVarFailure);
+      target.IncrementStats(StatisticKind::FrameVarFailure);
     return res;
   }
 

Modified: lldb/trunk/source/Commands/CommandObjectStats.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectStats.cpp?rev=369939&r1=369938&r2=369939&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectStats.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectStats.cpp Mon Aug 26 11:12:44 2019
@@ -26,15 +26,15 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
+    Target &target = GetSelectedOrDummyTarget();
 
-    if (target->GetCollectingStats()) {
+    if (target.GetCollectingStats()) {
       result.AppendError("statistics already enabled");
       result.SetStatus(eReturnStatusFailed);
       return false;
     }
 
-    target->SetCollectingStats(true);
+    target.SetCollectingStats(true);
     result.SetStatus(eReturnStatusSuccessFinishResult);
     return true;
   }
@@ -51,15 +51,15 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
+    Target &target = GetSelectedOrDummyTarget();
 
-    if (!target->GetCollectingStats()) {
+    if (!target.GetCollectingStats()) {
       result.AppendError("need to enable statistics before disabling them");
       result.SetStatus(eReturnStatusFailed);
       return false;
     }
 
-    target->SetCollectingStats(false);
+    target.SetCollectingStats(false);
     result.SetStatus(eReturnStatusSuccessFinishResult);
     return true;
   }
@@ -75,10 +75,10 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
+    Target &target = GetSelectedOrDummyTarget();
 
     uint32_t i = 0;
-    for (auto &stat : target->GetStatistics()) {
+    for (auto &stat : target.GetStatistics()) {
       result.AppendMessageWithFormat(
           "%s : %u\n",
           lldb_private::GetStatDescription(static_cast<lldb_private::StatisticKind>(i))

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=369939&r1=369938&r2=369939&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Mon Aug 26 11:12:44 2019
@@ -4672,52 +4672,50 @@ protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
     m_stop_hook_sp.reset();
 
-    Target *target = GetSelectedOrDummyTarget();
-    if (target) {
-      Target::StopHookSP new_hook_sp = target->CreateStopHook();
-
-      //  First step, make the specifier.
-      std::unique_ptr<SymbolContextSpecifier> specifier_up;
-      if (m_options.m_sym_ctx_specified) {
-        specifier_up.reset(
-            new SymbolContextSpecifier(GetDebugger().GetSelectedTarget()));
-
-        if (!m_options.m_module_name.empty()) {
-          specifier_up->AddSpecification(
-              m_options.m_module_name.c_str(),
-              SymbolContextSpecifier::eModuleSpecified);
-        }
+    Target &target = GetSelectedOrDummyTarget();
+    Target::StopHookSP new_hook_sp = target.CreateStopHook();
 
-        if (!m_options.m_class_name.empty()) {
-          specifier_up->AddSpecification(
-              m_options.m_class_name.c_str(),
-              SymbolContextSpecifier::eClassOrNamespaceSpecified);
-        }
+    //  First step, make the specifier.
+    std::unique_ptr<SymbolContextSpecifier> specifier_up;
+    if (m_options.m_sym_ctx_specified) {
+      specifier_up.reset(
+          new SymbolContextSpecifier(GetDebugger().GetSelectedTarget()));
+
+      if (!m_options.m_module_name.empty()) {
+        specifier_up->AddSpecification(
+            m_options.m_module_name.c_str(),
+            SymbolContextSpecifier::eModuleSpecified);
+      }
 
-        if (!m_options.m_file_name.empty()) {
-          specifier_up->AddSpecification(
-              m_options.m_file_name.c_str(),
-              SymbolContextSpecifier::eFileSpecified);
-        }
+      if (!m_options.m_class_name.empty()) {
+        specifier_up->AddSpecification(
+            m_options.m_class_name.c_str(),
+            SymbolContextSpecifier::eClassOrNamespaceSpecified);
+      }
 
-        if (m_options.m_line_start != 0) {
-          specifier_up->AddLineSpecification(
-              m_options.m_line_start,
-              SymbolContextSpecifier::eLineStartSpecified);
-        }
+      if (!m_options.m_file_name.empty()) {
+        specifier_up->AddSpecification(m_options.m_file_name.c_str(),
+                                       SymbolContextSpecifier::eFileSpecified);
+      }
 
-        if (m_options.m_line_end != UINT_MAX) {
-          specifier_up->AddLineSpecification(
-              m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
-        }
+      if (m_options.m_line_start != 0) {
+        specifier_up->AddLineSpecification(
+            m_options.m_line_start,
+            SymbolContextSpecifier::eLineStartSpecified);
+      }
 
-        if (!m_options.m_function_name.empty()) {
-          specifier_up->AddSpecification(
-              m_options.m_function_name.c_str(),
-              SymbolContextSpecifier::eFunctionSpecified);
-        }
+      if (m_options.m_line_end != UINT_MAX) {
+        specifier_up->AddLineSpecification(
+            m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
       }
 
+      if (!m_options.m_function_name.empty()) {
+        specifier_up->AddSpecification(
+            m_options.m_function_name.c_str(),
+            SymbolContextSpecifier::eFunctionSpecified);
+      }
+    }
+
       if (specifier_up)
         new_hook_sp->SetSpecifier(specifier_up.release());
 
@@ -4760,10 +4758,6 @@ protected:
                       // into our IOHandlerDelegate functions
       }
       result.SetStatus(eReturnStatusSuccessFinishNoResult);
-    } else {
-      result.AppendError("invalid target\n");
-      result.SetStatus(eReturnStatusFailed);
-    }
 
     return result.Succeeded();
   }
@@ -4788,43 +4782,37 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
-    if (target) {
-      // FIXME: see if we can use the breakpoint id style parser?
-      size_t num_args = command.GetArgumentCount();
-      if (num_args == 0) {
-        if (!m_interpreter.Confirm("Delete all stop hooks?", true)) {
+    Target &target = GetSelectedOrDummyTarget();
+    // FIXME: see if we can use the breakpoint id style parser?
+    size_t num_args = command.GetArgumentCount();
+    if (num_args == 0) {
+      if (!m_interpreter.Confirm("Delete all stop hooks?", true)) {
+        result.SetStatus(eReturnStatusFailed);
+        return false;
+      } else {
+        target.RemoveAllStopHooks();
+      }
+    } else {
+      bool success;
+      for (size_t i = 0; i < num_args; i++) {
+        lldb::user_id_t user_id = StringConvert::ToUInt32(
+            command.GetArgumentAtIndex(i), 0, 0, &success);
+        if (!success) {
+          result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
+                                       command.GetArgumentAtIndex(i));
           result.SetStatus(eReturnStatusFailed);
           return false;
-        } else {
-          target->RemoveAllStopHooks();
         }
-      } else {
-        bool success;
-        for (size_t i = 0; i < num_args; i++) {
-          lldb::user_id_t user_id = StringConvert::ToUInt32(
-              command.GetArgumentAtIndex(i), 0, 0, &success);
-          if (!success) {
-            result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
-                                         command.GetArgumentAtIndex(i));
-            result.SetStatus(eReturnStatusFailed);
-            return false;
-          }
-          success = target->RemoveStopHookByID(user_id);
-          if (!success) {
-            result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
-                                         command.GetArgumentAtIndex(i));
-            result.SetStatus(eReturnStatusFailed);
-            return false;
-          }
+        success = target.RemoveStopHookByID(user_id);
+        if (!success) {
+          result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
+                                       command.GetArgumentAtIndex(i));
+          result.SetStatus(eReturnStatusFailed);
+          return false;
         }
       }
-      result.SetStatus(eReturnStatusSuccessFinishNoResult);
-    } else {
-      result.AppendError("invalid target\n");
-      result.SetStatus(eReturnStatusFailed);
     }
-
+      result.SetStatus(eReturnStatusSuccessFinishNoResult);
     return result.Succeeded();
   }
 };
@@ -4845,38 +4833,33 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
-    if (target) {
-      // FIXME: see if we can use the breakpoint id style parser?
-      size_t num_args = command.GetArgumentCount();
-      bool success;
+    Target &target = GetSelectedOrDummyTarget();
+    // FIXME: see if we can use the breakpoint id style parser?
+    size_t num_args = command.GetArgumentCount();
+    bool success;
 
-      if (num_args == 0) {
-        target->SetAllStopHooksActiveState(m_enable);
-      } else {
-        for (size_t i = 0; i < num_args; i++) {
-          lldb::user_id_t user_id = StringConvert::ToUInt32(
-              command.GetArgumentAtIndex(i), 0, 0, &success);
-          if (!success) {
-            result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
-                                         command.GetArgumentAtIndex(i));
-            result.SetStatus(eReturnStatusFailed);
-            return false;
-          }
-          success = target->SetStopHookActiveStateByID(user_id, m_enable);
-          if (!success) {
-            result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
-                                         command.GetArgumentAtIndex(i));
-            result.SetStatus(eReturnStatusFailed);
-            return false;
-          }
+    if (num_args == 0) {
+      target.SetAllStopHooksActiveState(m_enable);
+    } else {
+      for (size_t i = 0; i < num_args; i++) {
+        lldb::user_id_t user_id = StringConvert::ToUInt32(
+            command.GetArgumentAtIndex(i), 0, 0, &success);
+        if (!success) {
+          result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
+                                       command.GetArgumentAtIndex(i));
+          result.SetStatus(eReturnStatusFailed);
+          return false;
+        }
+        success = target.SetStopHookActiveStateByID(user_id, m_enable);
+        if (!success) {
+          result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
+                                       command.GetArgumentAtIndex(i));
+          result.SetStatus(eReturnStatusFailed);
+          return false;
         }
       }
-      result.SetStatus(eReturnStatusSuccessFinishNoResult);
-    } else {
-      result.AppendError("invalid target\n");
-      result.SetStatus(eReturnStatusFailed);
     }
+      result.SetStatus(eReturnStatusSuccessFinishNoResult);
     return result.Succeeded();
   }
 
@@ -4899,19 +4882,14 @@ public:
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    Target *target = GetSelectedOrDummyTarget();
-    if (!target) {
-      result.AppendError("invalid target\n");
-      result.SetStatus(eReturnStatusFailed);
-      return result.Succeeded();
-    }
+    Target &target = GetSelectedOrDummyTarget();
 
-    size_t num_hooks = target->GetNumStopHooks();
+    size_t num_hooks = target.GetNumStopHooks();
     if (num_hooks == 0) {
       result.GetOutputStream().PutCString("No stop hooks.\n");
     } else {
       for (size_t i = 0; i < num_hooks; i++) {
-        Target::StopHookSP this_hook = target->GetStopHookAtIndex(i);
+        Target::StopHookSP this_hook = target.GetStopHookAtIndex(i);
         if (i > 0)
           result.GetOutputStream().PutCString("\n");
         this_hook->GetDescription(&(result.GetOutputStream()),

Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=369939&r1=369938&r2=369939&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Mon Aug 26 11:12:44 2019
@@ -917,12 +917,12 @@ const char *CommandObject::GetArgumentDe
   return g_arguments_data[arg_type].help_text;
 }
 
-Target *CommandObject::GetDummyTarget() {
-  return m_interpreter.GetDebugger().GetDummyTarget();
+Target &CommandObject::GetDummyTarget() {
+  return *m_interpreter.GetDebugger().GetDummyTarget();
 }
 
-Target *CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) {
-  return m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy);
+Target &CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) {
+  return *m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy);
 }
 
 Thread *CommandObject::GetDefaultThread() {

Modified: lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp?rev=369939&r1=369938&r2=369939&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp (original)
+++ lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp Mon Aug 26 11:12:44 2019
@@ -787,15 +787,10 @@ protected:
 
     // Now check if we have a running process.  If so, we should instruct the
     // process monitor to enable/disable DarwinLog support now.
-    Target *target = GetSelectedOrDummyTarget();
-    if (!target) {
-      // No target, so there is nothing more to do right now.
-      result.SetStatus(eReturnStatusSuccessFinishNoResult);
-      return true;
-    }
+    Target &target = GetSelectedOrDummyTarget();
 
     // Grab the active process.
-    auto process_sp = target->GetProcessSP();
+    auto process_sp = target.GetProcessSP();
     if (!process_sp) {
       // No active process, so there is nothing more to do right now.
       result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -877,9 +872,9 @@ protected:
 
     // Figure out if we've got a process.  If so, we can tell if DarwinLog is
     // available for that process.
-    Target *target = GetSelectedOrDummyTarget();
-    auto process_sp = target ? target->GetProcessSP() : ProcessSP();
-    if (!target || !process_sp) {
+    Target &target = GetSelectedOrDummyTarget();
+    auto process_sp = target.GetProcessSP();
+    if (!process_sp) {
       stream.PutCString("Availability: unknown (requires process)\n");
       stream.PutCString("Enabled: not applicable "
                         "(requires process)\n");




More information about the lldb-commits mailing list