Skip to content

Commit

Permalink
[lldb][NFC] Remove dead code that handles situations where LLDB has n…
Browse files Browse the repository at this point in the history
…o 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

llvm-svn: 369939
  • Loading branch information
Teemperor committed Aug 26, 2019
1 parent 8679ef4 commit cb2380c
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 377 deletions.
4 changes: 2 additions & 2 deletions lldb/include/lldb/Interpreter/CommandObject.h
Expand Up @@ -340,8 +340,8 @@ class CommandObject {
// 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
Expand Down
306 changes: 102 additions & 204 deletions lldb/source/Commands/CommandObjectBreakpoint.cpp

Large diffs are not rendered by default.

30 changes: 8 additions & 22 deletions lldb/source/Commands/CommandObjectBreakpointCommand.cpp
Expand Up @@ -361,16 +361,9 @@ are no syntax errors may indicate that a function was declared but never called.

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) {
Expand All @@ -389,7 +382,7 @@ are no syntax errors may indicate that a function was declared but never called.

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();
Expand All @@ -401,7 +394,7 @@ are no syntax errors may indicate that a function was declared but never called.
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.
Expand Down Expand Up @@ -536,16 +529,9 @@ class CommandObjectBreakpointCommandDelete : public CommandObjectParsed {

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) {
Expand All @@ -563,7 +549,7 @@ class CommandObjectBreakpointCommandDelete : public CommandObjectParsed {

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()) {
Expand All @@ -572,7 +558,7 @@ class CommandObjectBreakpointCommandDelete : public CommandObjectParsed {
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()));
Expand Down
20 changes: 6 additions & 14 deletions lldb/source/Commands/CommandObjectExpression.cpp
Expand Up @@ -316,10 +316,7 @@ void CommandObjectExpression::HandleCompletion(CompletionRequest &request) {
Target *target = exe_ctx.GetTargetPtr();

if (!target)
target = GetDummyTarget();

if (!target)
return;
target = &GetDummyTarget();

unsigned cursor_pos = request.GetRawCursorPos();
llvm::StringRef code = request.GetRawLine();
Expand Down Expand Up @@ -380,9 +377,8 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
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();
Expand Down Expand Up @@ -494,10 +490,6 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
}
}
}
} else {
error_stream->Printf("error: invalid execution context for expression\n");
return false;
}

return true;
}
Expand Down Expand Up @@ -662,11 +654,11 @@ bool CommandObjectExpression::DoExecute(llvm::StringRef command,
}
}

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???)
Expand All @@ -681,12 +673,12 @@ bool CommandObjectExpression::DoExecute(llvm::StringRef command,
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;
}
6 changes: 3 additions & 3 deletions lldb/source/Commands/CommandObjectFrame.cpp
Expand Up @@ -713,11 +713,11 @@ class CommandObjectFrameVariable : public CommandObjectParsed {

// 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;
}

Expand Down
16 changes: 8 additions & 8 deletions lldb/source/Commands/CommandObjectStats.cpp
Expand Up @@ -26,15 +26,15 @@ class CommandObjectStatsEnable : public CommandObjectParsed {

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;
}
Expand All @@ -51,15 +51,15 @@ class CommandObjectStatsDisable : public CommandObjectParsed {

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;
}
Expand All @@ -75,10 +75,10 @@ class CommandObjectStatsDump : public CommandObjectParsed {

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))
Expand Down

0 comments on commit cb2380c

Please sign in to comment.