diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h --- a/lldb/include/lldb/Interpreter/CommandObject.h +++ b/lldb/include/lldb/Interpreter/CommandObject.h @@ -340,8 +340,8 @@ // 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 diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp --- a/lldb/source/Commands/CommandObjectBreakpoint.cpp +++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp @@ -550,14 +550,7 @@ 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 @@ // 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ } 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 @@ 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 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 @@ 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 @@ 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 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 @@ 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 @@ // 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 @@ 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 @@ 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 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 @@ 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 @@ 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 @@ 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 @@ 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 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 @@ // 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 @@ 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 @@ break_type = eClearTypeFileAndLine; std::unique_lock 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 @@ 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 @@ 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 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 @@ 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 @@ // 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 @@ 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 @@ ++disable_count; } } else { - target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID()); + target.RemoveBreakpointByID(cur_bp_id.GetBreakpointID()); ++delete_count; } } @@ -1762,18 +1698,11 @@ 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 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 @@ 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 @@ 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 @@ 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 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 @@ // 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 @@ 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 @@ 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 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 @@ // 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 @@ 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 @@ 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 name_list; if (command.empty()) { - target->GetBreakpointNames(name_list); + target.GetBreakpointNames(name_list); } else { for (const Args::ArgEntry &arg : command) { @@ -2043,9 +1952,8 @@ 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 @@ } std::unique_lock 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 @@ 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 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 @@ 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 @@ 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 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 @@ } 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()); diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -361,16 +361,9 @@ 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 @@ 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 @@ 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 @@ 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 from which to delete 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) { @@ -563,7 +549,7 @@ 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 @@ 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())); diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -316,10 +316,7 @@ 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 @@ 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 @@ } } } - } else { - error_stream->Printf("error: invalid execution context for expression\n"); - return false; - } return true; } @@ -662,11 +654,11 @@ } } - 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 @@ 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; } diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -713,11 +713,11 @@ // 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; } diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp --- a/lldb/source/Commands/CommandObjectStats.cpp +++ b/lldb/source/Commands/CommandObjectStats.cpp @@ -26,15 +26,15 @@ 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 @@ 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 @@ 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(i)) diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -4672,51 +4672,49 @@ 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 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(); + + // First step, make the specifier. + std::unique_ptr 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_class_name.empty()) { - specifier_up->AddSpecification( - m_options.m_class_name.c_str(), - SymbolContextSpecifier::eClassOrNamespaceSpecified); - } + if (!m_options.m_class_name.empty()) { + specifier_up->AddSpecification( + m_options.m_class_name.c_str(), + SymbolContextSpecifier::eClassOrNamespaceSpecified); + } - if (!m_options.m_file_name.empty()) { - specifier_up->AddSpecification( - m_options.m_file_name.c_str(), - SymbolContextSpecifier::eFileSpecified); - } + if (!m_options.m_file_name.empty()) { + specifier_up->AddSpecification(m_options.m_file_name.c_str(), + SymbolContextSpecifier::eFileSpecified); + } - if (m_options.m_line_start != 0) { - specifier_up->AddLineSpecification( - m_options.m_line_start, - SymbolContextSpecifier::eLineStartSpecified); - } + if (m_options.m_line_start != 0) { + specifier_up->AddLineSpecification( + m_options.m_line_start, + SymbolContextSpecifier::eLineStartSpecified); + } - if (m_options.m_line_end != UINT_MAX) { - specifier_up->AddLineSpecification( - m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified); - } + 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 (!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 @@ // into our IOHandlerDelegate functions } result.SetStatus(eReturnStatusSuccessFinishNoResult); - } else { - result.AppendError("invalid target\n"); - result.SetStatus(eReturnStatusFailed); - } return result.Succeeded(); } @@ -4788,43 +4782,37 @@ 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 @@ 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 @@ 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()), diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -917,12 +917,12 @@ 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() { diff --git a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp --- a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp +++ b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp @@ -787,15 +787,10 @@ // 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 @@ // 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");