Skip to content

Commit

Permalink
Properly handle a launch failure after switching the launch operation…
Browse files Browse the repository at this point in the history
… to async
  • Loading branch information
xusheng6 committed Apr 11, 2023
1 parent f732313 commit c288ea1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ extern "C"
TargetStoppedEventType,
ErrorEventType,
GeneralEventType,
LaunchFailureEventType,

StdoutMessageEventType,
BackendMessageEventType,
Expand Down
6 changes: 4 additions & 2 deletions core/adapters/lldbadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ bool LldbAdapter::ExecuteWithArgs(const std::string& path, const std::string& ar
if (!m_target.IsValid())
{
DebuggerEvent event;
event.type = ErrorEventType;
event.type = LaunchFailureEventType;
event.data.errorData.shortError = "LLDB failed to create target.";
event.data.errorData.error =
fmt::format("LLDB Failed to create target with \"{}\"", err.GetCString() ? err.GetCString() : "");
Expand Down Expand Up @@ -231,7 +231,7 @@ bool LldbAdapter::ExecuteWithArgs(const std::string& path, const std::string& ar
auto it = result.find_last_not_of('\n');
result.erase(it + 1);
DebuggerEvent event;
event.type = ErrorEventType;
event.type = LaunchFailureEventType;
event.data.errorData.shortError = fmt::format("LLDB failed to launch target.");
event.data.errorData.error = fmt::format("LLDB Failed to launch target with \"{}\"", result.c_str());
PostDebuggerEvent(event);
Expand Down Expand Up @@ -296,6 +296,8 @@ bool LldbAdapter::Attach(std::uint32_t pid)
return false;
}

// LLDB event listener does not get an event when the attach operation completes, so we must send an event here.
// This is NOT needed for Connect(), since LLDB event listener sends an event in that case.
DebuggerEvent dbgevt;
dbgevt.type = TargetStoppedEventType;
dbgevt.data.targetStoppedData.reason = InitialBreakpoint;
Expand Down
3 changes: 3 additions & 0 deletions core/debuggercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ void DebuggerController::EventHandler(const DebuggerEvent& event)
m_exitCode = event.data.exitData.exitCode;
case QuitDebuggingEventType:
case DetachedEventType:
case LaunchFailureEventType:
{
m_inputFileLoaded = false;
m_initialBreakpointSeen = false;
Expand Down Expand Up @@ -1767,6 +1768,8 @@ DebugStopReason DebuggerController::ExecuteAdapterAndWait(const DebugAdapterOper

if (ok)
sem.Wait();
else
reason = InternalError;

RemoveEventCallback(callback);
if ((operation != DebugAdapterPause) && (operation != DebugAdapterQuit) && (operation != DebugAdapterDetach))
Expand Down
1 change: 1 addition & 0 deletions ui/statusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void DebuggerStatusBarWidget::updateStatusText(const DebuggerEvent& event)
setStatusText("Backend disconnected");
break;
case ErrorEventType:
case LaunchFailureEventType:
setStatusText(QString::fromStdString(event.data.errorData.shortError));
break;
default:
Expand Down
7 changes: 7 additions & 0 deletions ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,13 @@ void DebuggerUI::updateUI(const DebuggerEvent& event)
break;
}

case LaunchFailureEventType:
{
QMessageBox::critical(nullptr, QString::fromStdString(event.data.errorData.shortError),
QString::fromStdString(event.data.errorData.error));
break;
}

case TargetStoppedEventType:
case ActiveThreadChangedEvent:
{
Expand Down

0 comments on commit c288ea1

Please sign in to comment.