[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:23:27 +01:00
|
|
|
//===-- CommandObjectQuit.cpp ---------------------------------------------===//
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "CommandObjectQuit.h"
|
|
|
|
|
|
2010-06-09 07:57:51 +00:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2015-03-03 23:11:11 +00:00
|
|
|
#include "lldb/Target/Process.h"
|
2018-07-11 17:18:01 +00:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
// CommandObjectQuit
|
|
|
|
|
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectQuit::CommandObjectQuit(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectParsed(interpreter, "quit", "Quit the LLDB debugger.",
|
2018-07-11 17:18:01 +00:00
|
|
|
"quit [exit-code]") {}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2021-07-02 11:27:37 -07:00
|
|
|
CommandObjectQuit::~CommandObjectQuit() = default;
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// returns true if there is at least one alive process is_a_detach will be true
|
|
|
|
|
// if all alive processes will be detached when you quit and false if at least
|
|
|
|
|
// one process will be killed instead
|
2013-01-17 21:36:19 +00:00
|
|
|
bool CommandObjectQuit::ShouldAskForConfirmation(bool &is_a_detach) {
|
2018-12-15 00:15:33 +00:00
|
|
|
if (!m_interpreter.GetPromptOnQuit())
|
2013-01-17 21:36:19 +00:00
|
|
|
return false;
|
|
|
|
|
bool should_prompt = false;
|
|
|
|
|
is_a_detach = true;
|
|
|
|
|
for (uint32_t debugger_idx = 0; debugger_idx < Debugger::GetNumDebuggers();
|
|
|
|
|
debugger_idx++) {
|
|
|
|
|
DebuggerSP debugger_sp(Debugger::GetDebuggerAtIndex(debugger_idx));
|
|
|
|
|
if (!debugger_sp)
|
|
|
|
|
continue;
|
|
|
|
|
const TargetList &target_list(debugger_sp->GetTargetList());
|
|
|
|
|
for (uint32_t target_idx = 0;
|
2014-04-02 03:51:35 +00:00
|
|
|
target_idx < static_cast<uint32_t>(target_list.GetNumTargets());
|
2013-01-17 21:36:19 +00:00
|
|
|
target_idx++) {
|
|
|
|
|
TargetSP target_sp(target_list.GetTargetAtIndex(target_idx));
|
|
|
|
|
if (!target_sp)
|
|
|
|
|
continue;
|
|
|
|
|
ProcessSP process_sp(target_sp->GetProcessSP());
|
2013-05-11 00:52:25 +00:00
|
|
|
if (process_sp && process_sp->IsValid() && process_sp->IsAlive() &&
|
|
|
|
|
process_sp->WarnBeforeDetach()) {
|
2013-01-17 21:36:19 +00:00
|
|
|
should_prompt = true;
|
2018-12-15 00:15:33 +00:00
|
|
|
if (!process_sp->GetShouldDetach()) {
|
2013-01-17 21:36:19 +00:00
|
|
|
// if we need to kill at least one process, just say so and return
|
|
|
|
|
is_a_detach = false;
|
|
|
|
|
return should_prompt;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2013-01-17 21:36:19 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2013-01-17 21:36:19 +00:00
|
|
|
return should_prompt;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
bool CommandObjectQuit::DoExecute(Args &command, CommandReturnObject &result) {
|
2013-01-17 21:36:19 +00:00
|
|
|
bool is_a_detach = true;
|
|
|
|
|
if (ShouldAskForConfirmation(is_a_detach)) {
|
|
|
|
|
StreamString message;
|
|
|
|
|
message.Printf("Quitting LLDB will %s one or more processes. Do you really "
|
|
|
|
|
"want to proceed",
|
|
|
|
|
(is_a_detach ? "detach from" : "kill"));
|
2016-11-16 21:15:24 +00:00
|
|
|
if (!m_interpreter.Confirm(message.GetString(), true)) {
|
2013-01-17 21:36:19 +00:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2018-07-11 17:18:01 +00:00
|
|
|
|
|
|
|
|
if (command.GetArgumentCount() > 1) {
|
|
|
|
|
result.AppendError("Too many arguments for 'quit'. Only an optional exit "
|
|
|
|
|
"code is allowed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We parse the exit code argument if there is one.
|
|
|
|
|
if (command.GetArgumentCount() == 1) {
|
|
|
|
|
llvm::StringRef arg = command.GetArgumentAtIndex(0);
|
|
|
|
|
int exit_code;
|
|
|
|
|
if (arg.getAsInteger(/*autodetect radix*/ 0, exit_code)) {
|
|
|
|
|
lldb_private::StreamString s;
|
|
|
|
|
std::string arg_str = arg.str();
|
|
|
|
|
s.Printf("Couldn't parse '%s' as integer for exit code.", arg_str.data());
|
|
|
|
|
result.AppendError(s.GetString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!m_interpreter.SetQuitExitCode(exit_code)) {
|
|
|
|
|
result.AppendError("The current driver doesn't allow custom exit codes"
|
|
|
|
|
" for the quit command.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-27 23:43:24 +00:00
|
|
|
const uint32_t event_type =
|
|
|
|
|
CommandInterpreter::eBroadcastBitQuitCommandReceived;
|
|
|
|
|
m_interpreter.BroadcastEvent(event_type);
|
2010-06-08 16:52:24 +00:00
|
|
|
result.SetStatus(eReturnStatusQuit);
|
2020-07-21 16:29:16 +02:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
return true;
|
|
|
|
|
}
|