[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 15:23:27 +08:00
|
|
|
//===-- Debugger.cpp ------------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-06-24 01:59:56 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Breakpoint/Breakpoint.h"
|
2015-02-05 06:00:53 +08:00
|
|
|
#include "lldb/Core/FormatEntity.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Core/Mangled.h"
|
|
|
|
#include "lldb/Core/ModuleList.h"
|
2012-10-20 02:02:49 +08:00
|
|
|
#include "lldb/Core/PluginManager.h"
|
2011-06-03 07:58:26 +08:00
|
|
|
#include "lldb/Core/StreamAsynchronousIO.h"
|
2014-01-28 07:43:24 +08:00
|
|
|
#include "lldb/Core/StreamFile.h"
|
2013-01-29 07:47:25 +08:00
|
|
|
#include "lldb/DataFormatters/DataVisualization.h"
|
2015-10-20 08:23:46 +08:00
|
|
|
#include "lldb/Expression/REPL.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Host/File.h"
|
2018-11-01 08:33:27 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2014-08-22 01:29:12 +08:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
2011-02-08 07:24:47 +08:00
|
|
|
#include "lldb/Host/Terminal.h"
|
2014-09-10 04:54:56 +08:00
|
|
|
#include "lldb/Host/ThreadLauncher.h"
|
2010-06-23 09:19:29 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2021-06-29 03:27:55 +08:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Interpreter/OptionValue.h"
|
2015-03-04 09:58:01 +08:00
|
|
|
#include "lldb/Interpreter/OptionValueProperties.h"
|
2012-08-23 01:17:09 +08:00
|
|
|
#include "lldb/Interpreter/OptionValueSInt64.h"
|
|
|
|
#include "lldb/Interpreter/OptionValueString.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Interpreter/Property.h"
|
|
|
|
#include "lldb/Interpreter/ScriptInterpreter.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/Symbol.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
2015-10-20 08:23:46 +08:00
|
|
|
#include "lldb/Target/Language.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2016-08-19 12:21:48 +08:00
|
|
|
#include "lldb/Target/StructuredDataPlugin.h"
|
2013-05-21 06:29:23 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/TargetList.h"
|
|
|
|
#include "lldb/Target/Thread.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Target/ThreadList.h"
|
2011-10-14 15:41:33 +08:00
|
|
|
#include "lldb/Utility/AnsiTerminal.h"
|
2018-12-14 23:59:49 +08:00
|
|
|
#include "lldb/Utility/Event.h"
|
|
|
|
#include "lldb/Utility/Listener.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-11-14 03:18:16 +08:00
|
|
|
#include "lldb/Utility/Reproducer.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/State.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-03-07 02:34:25 +08:00
|
|
|
#include "lldb/Utility/StreamCallback.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-04-10 21:33:45 +08:00
|
|
|
#if defined(_WIN32)
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Host/windows/PosixApi.h"
|
2018-09-06 06:06:58 +08:00
|
|
|
#include "lldb/Host/windows/windows.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
#endif
|
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "llvm/ADT/None.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "llvm/ADT/iterator.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
#include "llvm/Support/DynamicLibrary.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
2018-09-06 06:06:58 +08:00
|
|
|
#include "llvm/Support/Process.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
#include "llvm/Support/Threading.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <list>
|
|
|
|
#include <memory>
|
2017-04-07 05:28:29 +08:00
|
|
|
#include <mutex>
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <system_error>
|
2017-04-07 05:28:29 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
class Address;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2010-07-01 00:22:25 +08:00
|
|
|
static lldb::user_id_t g_unique_id = 1;
|
2014-10-25 06:06:29 +08:00
|
|
|
static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
|
2010-07-01 00:22:25 +08:00
|
|
|
|
2010-09-19 10:33:57 +08:00
|
|
|
#pragma mark Static Functions
|
|
|
|
|
|
|
|
typedef std::vector<DebuggerSP> DebuggerList;
|
2016-05-27 00:51:23 +08:00
|
|
|
static std::recursive_mutex *g_debugger_list_mutex_ptr =
|
|
|
|
nullptr; // NOTE: intentional leak to avoid issues with C++ destructor chain
|
|
|
|
static DebuggerList *g_debugger_list_ptr =
|
2012-08-23 01:17:09 +08:00
|
|
|
nullptr; // NOTE: intentional leak to avoid issues with C++ destructor chain
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-09-27 02:50:19 +08:00
|
|
|
static constexpr OptionEnumValueElement g_show_disassembly_enum_values[] = {
|
2019-08-02 08:18:44 +08:00
|
|
|
{
|
|
|
|
Debugger::eStopDisassemblyTypeNever,
|
|
|
|
"never",
|
|
|
|
"Never show disassembly when displaying a stop context.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Debugger::eStopDisassemblyTypeNoDebugInfo,
|
|
|
|
"no-debuginfo",
|
|
|
|
"Show disassembly when there is no debug information.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Debugger::eStopDisassemblyTypeNoSource,
|
|
|
|
"no-source",
|
|
|
|
"Show disassembly when there is no source information, or the source "
|
|
|
|
"file "
|
|
|
|
"is missing when displaying a stop context.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Debugger::eStopDisassemblyTypeAlways,
|
|
|
|
"always",
|
|
|
|
"Always show disassembly when displaying a stop context.",
|
|
|
|
},
|
|
|
|
};
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-09-27 02:50:19 +08:00
|
|
|
static constexpr OptionEnumValueElement g_language_enumerators[] = {
|
2019-08-02 08:18:44 +08:00
|
|
|
{
|
|
|
|
eScriptLanguageNone,
|
|
|
|
"none",
|
|
|
|
"Disable scripting languages.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eScriptLanguagePython,
|
|
|
|
"python",
|
|
|
|
"Select python as the default scripting language.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eScriptLanguageDefault,
|
|
|
|
"default",
|
|
|
|
"Select the lldb default as the default scripting language.",
|
|
|
|
},
|
|
|
|
};
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-09-27 02:50:19 +08:00
|
|
|
static constexpr OptionEnumValueElement s_stop_show_column_values[] = {
|
2019-08-02 08:18:44 +08:00
|
|
|
{
|
|
|
|
eStopShowColumnAnsiOrCaret,
|
|
|
|
"ansi-or-caret",
|
|
|
|
"Highlight the stop column with ANSI terminal codes when color/ANSI "
|
|
|
|
"mode is enabled; otherwise, fall back to using a text-only caret (^) "
|
|
|
|
"as if \"caret-only\" mode was selected.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eStopShowColumnAnsi,
|
|
|
|
"ansi",
|
|
|
|
"Highlight the stop column with ANSI terminal codes when running LLDB "
|
|
|
|
"with color/ANSI enabled.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eStopShowColumnCaret,
|
|
|
|
"caret",
|
|
|
|
"Highlight the stop column with a caret character (^) underneath the "
|
|
|
|
"stop column. This method introduces a new line in source listings "
|
|
|
|
"that display thread stop locations.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eStopShowColumnNone,
|
|
|
|
"none",
|
|
|
|
"Do not highlight the stop column.",
|
|
|
|
},
|
|
|
|
};
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-22 04:13:14 +08:00
|
|
|
|
2019-07-26 05:36:37 +08:00
|
|
|
#define LLDB_PROPERTIES_debugger
|
2019-07-30 01:22:10 +08:00
|
|
|
#include "CoreProperties.inc"
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
enum {
|
2019-07-26 05:36:37 +08:00
|
|
|
#define LLDB_PROPERTIES_debugger
|
2019-07-30 01:22:10 +08:00
|
|
|
#include "CorePropertiesEnum.inc"
|
2012-08-23 01:17:09 +08:00
|
|
|
};
|
2010-09-19 10:33:57 +08:00
|
|
|
|
2016-03-02 10:18:18 +08:00
|
|
|
LoadPluginCallbackType Debugger::g_load_plugin_callback = nullptr;
|
2012-09-01 08:38:36 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
|
|
|
|
VarSetOperationType op,
|
|
|
|
llvm::StringRef property_path,
|
|
|
|
llvm::StringRef value) {
|
2019-08-02 08:18:44 +08:00
|
|
|
bool is_load_script =
|
|
|
|
(property_path == "target.load-script-from-symbol-file");
|
2019-09-04 19:41:23 +08:00
|
|
|
// These properties might change how we visualize data.
|
|
|
|
bool invalidate_data_vis = (property_path == "escape-non-printables");
|
|
|
|
invalidate_data_vis |=
|
|
|
|
(property_path == "target.max-zero-padding-in-float-format");
|
|
|
|
if (invalidate_data_vis) {
|
|
|
|
DataVisualization::ForceUpdate();
|
|
|
|
}
|
|
|
|
|
2013-05-21 06:29:23 +08:00
|
|
|
TargetSP target_sp;
|
2013-05-22 04:13:34 +08:00
|
|
|
LoadScriptFromSymFile load_script_old_value;
|
2013-05-21 06:29:23 +08:00
|
|
|
if (is_load_script && exe_ctx->GetTargetSP()) {
|
|
|
|
target_sp = exe_ctx->GetTargetSP();
|
|
|
|
load_script_old_value =
|
|
|
|
target_sp->TargetProperties::GetLoadScriptFromSymbolFile();
|
|
|
|
}
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error(Properties::SetPropertyValue(exe_ctx, op, property_path, value));
|
2012-09-01 08:38:36 +08:00
|
|
|
if (error.Success()) {
|
2013-05-21 06:29:23 +08:00
|
|
|
// FIXME it would be nice to have "on-change" callbacks for properties
|
2019-07-30 00:41:30 +08:00
|
|
|
if (property_path == g_debugger_properties[ePropertyPrompt].name) {
|
2016-09-24 02:06:53 +08:00
|
|
|
llvm::StringRef new_prompt = GetPrompt();
|
2019-08-21 08:50:46 +08:00
|
|
|
std::string str = lldb_private::ansi::FormatAnsiTerminalCodes(
|
2013-05-24 04:47:45 +08:00
|
|
|
new_prompt, GetUseColor());
|
|
|
|
if (str.length())
|
2016-11-03 04:34:10 +08:00
|
|
|
new_prompt = str;
|
2014-01-28 07:43:24 +08:00
|
|
|
GetCommandInterpreter().UpdatePrompt(new_prompt);
|
2019-08-15 06:19:23 +08:00
|
|
|
auto bytes = std::make_unique<EventDataBytes>(new_prompt);
|
2017-04-07 05:28:29 +08:00
|
|
|
auto prompt_change_event_sp = std::make_shared<Event>(
|
|
|
|
CommandInterpreter::eBroadcastBitResetPrompt, bytes.release());
|
2012-09-01 08:38:36 +08:00
|
|
|
GetCommandInterpreter().BroadcastEvent(prompt_change_event_sp);
|
2019-07-30 00:41:30 +08:00
|
|
|
} else if (property_path == g_debugger_properties[ePropertyUseColor].name) {
|
2013-05-24 04:47:45 +08:00
|
|
|
// use-color changed. Ping the prompt so it can reset the ansi terminal
|
|
|
|
// codes.
|
|
|
|
SetPrompt(GetPrompt());
|
2020-04-20 22:17:17 +08:00
|
|
|
} else if (property_path == g_debugger_properties[ePropertyUseSourceCache].name) {
|
|
|
|
// use-source-cache changed. Wipe out the cache contents if it was disabled.
|
|
|
|
if (!GetUseSourceCache()) {
|
|
|
|
m_source_file_cache.Clear();
|
|
|
|
}
|
2013-05-22 04:13:34 +08:00
|
|
|
} else if (is_load_script && target_sp &&
|
|
|
|
load_script_old_value == eLoadScriptFromSymFileWarn) {
|
|
|
|
if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() ==
|
|
|
|
eLoadScriptFromSymFileTrue) {
|
2017-05-12 12:51:55 +08:00
|
|
|
std::list<Status> errors;
|
2013-05-21 08:00:30 +08:00
|
|
|
StreamString feedback_stream;
|
|
|
|
if (!target_sp->LoadScriptingResources(errors, &feedback_stream)) {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
Stream &s = GetErrorStream();
|
|
|
|
for (auto error : errors) {
|
|
|
|
s.Printf("%s\n", error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
if (feedback_stream.GetSize())
|
|
|
|
s.PutCString(feedback_stream.GetString());
|
2013-05-21 06:29:23 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-09-01 08:38:36 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-09-01 08:38:36 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
bool Debugger::GetAutoConfirm() const {
|
|
|
|
const uint32_t idx = ePropertyAutoConfirm;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2014-10-11 07:07:36 +08:00
|
|
|
const FormatEntity::Entry *Debugger::GetDisassemblyFormat() const {
|
|
|
|
const uint32_t idx = ePropertyDisassemblyFormat;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx);
|
2014-10-11 07:07:36 +08:00
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
const FormatEntity::Entry *Debugger::GetFrameFormat() const {
|
|
|
|
const uint32_t idx = ePropertyFrameFormat;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx);
|
2017-06-13 00:25:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const FormatEntity::Entry *Debugger::GetFrameFormatUnique() const {
|
|
|
|
const uint32_t idx = ePropertyFrameFormatUnique;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx);
|
2012-08-10 02:18:47 +08:00
|
|
|
}
|
|
|
|
|
2021-02-26 05:28:51 +08:00
|
|
|
uint32_t Debugger::GetStopDisassemblyMaxSize() const {
|
|
|
|
const uint32_t idx = ePropertyStopDisassemblyMaxSize;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsUInt64(
|
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value);
|
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
bool Debugger::GetNotifyVoid() const {
|
|
|
|
const uint32_t idx = ePropertyNotiftVoid;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2016-09-24 02:06:53 +08:00
|
|
|
llvm::StringRef Debugger::GetPrompt() const {
|
2012-08-23 01:17:09 +08:00
|
|
|
const uint32_t idx = ePropertyPrompt;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsString(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_cstr_value);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2016-09-24 02:06:53 +08:00
|
|
|
void Debugger::SetPrompt(llvm::StringRef p) {
|
2012-08-23 01:17:09 +08:00
|
|
|
const uint32_t idx = ePropertyPrompt;
|
2016-03-02 10:18:18 +08:00
|
|
|
m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, p);
|
2016-09-24 02:06:53 +08:00
|
|
|
llvm::StringRef new_prompt = GetPrompt();
|
2013-05-24 04:47:45 +08:00
|
|
|
std::string str =
|
2019-08-21 08:50:46 +08:00
|
|
|
lldb_private::ansi::FormatAnsiTerminalCodes(new_prompt, GetUseColor());
|
2013-05-24 04:47:45 +08:00
|
|
|
if (str.length())
|
2016-11-03 04:34:10 +08:00
|
|
|
new_prompt = str;
|
2014-01-28 07:43:24 +08:00
|
|
|
GetCommandInterpreter().UpdatePrompt(new_prompt);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2018-11-14 03:18:16 +08:00
|
|
|
llvm::StringRef Debugger::GetReproducerPath() const {
|
|
|
|
auto &r = repro::Reproducer::Instance();
|
|
|
|
return r.GetReproducerPath().GetCString();
|
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
const FormatEntity::Entry *Debugger::GetThreadFormat() const {
|
|
|
|
const uint32_t idx = ePropertyThreadFormat;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2016-11-09 04:36:40 +08:00
|
|
|
const FormatEntity::Entry *Debugger::GetThreadStopFormat() const {
|
|
|
|
const uint32_t idx = ePropertyThreadStopFormat;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx);
|
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
lldb::ScriptLanguage Debugger::GetScriptLanguage() const {
|
|
|
|
const uint32_t idx = ePropertyScriptLanguage;
|
2016-03-02 10:18:18 +08:00
|
|
|
return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
bool Debugger::SetScriptLanguage(lldb::ScriptLanguage script_lang) {
|
|
|
|
const uint32_t idx = ePropertyScriptLanguage;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->SetPropertyAtIndexAsEnumeration(nullptr, idx,
|
|
|
|
script_lang);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
uint32_t Debugger::GetTerminalWidth() const {
|
|
|
|
const uint32_t idx = ePropertyTerminalWidth;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsSInt64(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
bool Debugger::SetTerminalWidth(uint32_t term_width) {
|
2020-05-09 06:14:14 +08:00
|
|
|
if (auto handler_sp = m_io_handler_stack.Top())
|
|
|
|
handler_sp->TerminalSizeChanged();
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
const uint32_t idx = ePropertyTerminalWidth;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->SetPropertyAtIndexAsSInt64(nullptr, idx, term_width);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
bool Debugger::GetUseExternalEditor() const {
|
|
|
|
const uint32_t idx = ePropertyUseExternalEditor;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
bool Debugger::SetUseExternalEditor(bool b) {
|
|
|
|
const uint32_t idx = ePropertyUseExternalEditor;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
|
2011-11-22 05:44:34 +08:00
|
|
|
}
|
|
|
|
|
2013-05-24 04:47:45 +08:00
|
|
|
bool Debugger::GetUseColor() const {
|
|
|
|
const uint32_t idx = ePropertyUseColor;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
|
2013-05-24 04:47:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Debugger::SetUseColor(bool b) {
|
|
|
|
const uint32_t idx = ePropertyUseColor;
|
2016-03-02 10:18:18 +08:00
|
|
|
bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
|
2013-05-24 04:47:45 +08:00
|
|
|
SetPrompt(GetPrompt());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
[lldb] Display autosuggestion part in gray if there is one possible suggestion
This is relanding D81001. The patch originally failed as on newer editline
versions it seems CC_REFRESH will move the cursor to the start of the line via
\r and then back to the original position. On older editline versions like
the one used by default on macOS, CC_REFRESH doesn't move the cursor at all.
As the patch changed the way we handle tab completion (previously we did
REDISPLAY but now we're doing CC_REFRESH), this caused a few completion tests
to receive this unexpected cursor movement in the output stream.
This patch updates those tests to also accept output that contains the specific
cursor movement commands (\r and then \x1b[XC). lldbpexpect.py received an
utility method for generating the cursor movement escape sequence.
Original summary:
I implemented autosuggestion if there is one possible suggestion.
I set the keybinds for every character. When a character is typed, Editline::TypedCharacter is called.
Then, autosuggestion part is displayed in gray, and you can actually input by typing C-k.
Editline::Autosuggest is a function for finding completion, and it is like Editline::TabCommand now, but I will add more features to it.
Testing does not work well in my environment, so I can't confirm that it goes well, sorry. I am dealing with it now.
Reviewed By: teemperor, JDevlieghere, #lldb
Differential Revision: https://reviews.llvm.org/D81001
2020-08-12 18:54:28 +08:00
|
|
|
bool Debugger::GetUseAutosuggestion() const {
|
|
|
|
const uint32_t idx = ePropertyShowAutosuggestion;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
|
|
|
|
}
|
|
|
|
|
2020-04-20 22:17:17 +08:00
|
|
|
bool Debugger::GetUseSourceCache() const {
|
|
|
|
const uint32_t idx = ePropertyUseSourceCache;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Debugger::SetUseSourceCache(bool b) {
|
|
|
|
const uint32_t idx = ePropertyUseSourceCache;
|
|
|
|
bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
|
|
|
|
if (!ret) {
|
|
|
|
m_source_file_cache.Clear();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2018-08-02 08:30:15 +08:00
|
|
|
bool Debugger::GetHighlightSource() const {
|
|
|
|
const uint32_t idx = ePropertyHighlightSource;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value);
|
2018-08-02 08:30:15 +08:00
|
|
|
}
|
|
|
|
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-22 04:13:14 +08:00
|
|
|
StopShowColumn Debugger::GetStopShowColumn() const {
|
|
|
|
const uint32_t idx = ePropertyStopShowColumn;
|
|
|
|
return (lldb::StopShowColumn)m_collection_sp->GetPropertyAtIndexAsEnumeration(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value);
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-22 04:13:14 +08:00
|
|
|
}
|
|
|
|
|
2018-08-30 08:09:21 +08:00
|
|
|
llvm::StringRef Debugger::GetStopShowColumnAnsiPrefix() const {
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-22 04:13:14 +08:00
|
|
|
const uint32_t idx = ePropertyStopShowColumnAnsiPrefix;
|
2018-08-30 08:09:21 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-22 04:13:14 +08:00
|
|
|
}
|
|
|
|
|
2018-08-30 08:09:21 +08:00
|
|
|
llvm::StringRef Debugger::GetStopShowColumnAnsiSuffix() const {
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-22 04:13:14 +08:00
|
|
|
const uint32_t idx = ePropertyStopShowColumnAnsiSuffix;
|
2018-08-30 08:09:21 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-22 04:13:14 +08:00
|
|
|
}
|
|
|
|
|
2020-02-25 07:34:58 +08:00
|
|
|
llvm::StringRef Debugger::GetStopShowLineMarkerAnsiPrefix() const {
|
|
|
|
const uint32_t idx = ePropertyStopShowLineMarkerAnsiPrefix;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::StringRef Debugger::GetStopShowLineMarkerAnsiSuffix() const {
|
|
|
|
const uint32_t idx = ePropertyStopShowLineMarkerAnsiSuffix;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
|
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
uint32_t Debugger::GetStopSourceLineCount(bool before) const {
|
|
|
|
const uint32_t idx =
|
|
|
|
before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsSInt64(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value);
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
2011-11-22 05:44:34 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
Debugger::StopDisassemblyType Debugger::GetStopDisassemblyDisplay() const {
|
|
|
|
const uint32_t idx = ePropertyStopDisassemblyDisplay;
|
2016-03-02 10:18:18 +08:00
|
|
|
return (Debugger::StopDisassemblyType)
|
|
|
|
m_collection_sp->GetPropertyAtIndexAsEnumeration(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value);
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
2011-11-22 05:44:34 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
uint32_t Debugger::GetDisassemblyLineCount() const {
|
|
|
|
const uint32_t idx = ePropertyStopDisassemblyCount;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsSInt64(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value);
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
2011-11-22 05:44:34 +08:00
|
|
|
|
2013-11-01 05:01:07 +08:00
|
|
|
bool Debugger::GetAutoOneLineSummaries() const {
|
|
|
|
const uint32_t idx = ePropertyAutoOneLineSummaries;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true);
|
2014-11-06 05:20:48 +08:00
|
|
|
}
|
2013-10-26 07:09:40 +08:00
|
|
|
|
2014-11-06 05:20:48 +08:00
|
|
|
bool Debugger::GetEscapeNonPrintables() const {
|
|
|
|
const uint32_t idx = ePropertyEscapeNonPrintables;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true);
|
2013-10-26 07:09:40 +08:00
|
|
|
}
|
|
|
|
|
2015-10-20 07:11:07 +08:00
|
|
|
bool Debugger::GetAutoIndent() const {
|
|
|
|
const uint32_t idx = ePropertyAutoIndent;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true);
|
2015-10-20 07:11:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Debugger::SetAutoIndent(bool b) {
|
|
|
|
const uint32_t idx = ePropertyAutoIndent;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
|
2015-10-20 07:11:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Debugger::GetPrintDecls() const {
|
|
|
|
const uint32_t idx = ePropertyPrintDecls;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true);
|
2015-10-20 07:11:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Debugger::SetPrintDecls(bool b) {
|
|
|
|
const uint32_t idx = ePropertyPrintDecls;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
|
2015-10-20 07:11:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Debugger::GetTabSize() const {
|
|
|
|
const uint32_t idx = ePropertyTabSize;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsUInt64(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_debugger_properties[idx].default_uint_value);
|
2015-10-20 07:11:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Debugger::SetTabSize(uint32_t tab_size) {
|
|
|
|
const uint32_t idx = ePropertyTabSize;
|
2016-03-02 10:18:18 +08:00
|
|
|
return m_collection_sp->SetPropertyAtIndexAsUInt64(nullptr, idx, tab_size);
|
2015-10-20 07:11:07 +08:00
|
|
|
}
|
|
|
|
|
2010-09-19 10:33:57 +08:00
|
|
|
#pragma mark Debugger
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
// const DebuggerPropertiesSP &
|
|
|
|
// Debugger::GetSettings() const
|
|
|
|
//{
|
|
|
|
// return m_properties_sp;
|
|
|
|
//}
|
|
|
|
//
|
2010-11-19 07:32:35 +08:00
|
|
|
|
2015-03-20 06:00:21 +08:00
|
|
|
void Debugger::Initialize(LoadPluginCallbackType load_plugin_callback) {
|
2016-05-27 00:51:23 +08:00
|
|
|
assert(g_debugger_list_ptr == nullptr &&
|
|
|
|
"Debugger::Initialize called more than once!");
|
|
|
|
g_debugger_list_mutex_ptr = new std::recursive_mutex();
|
|
|
|
g_debugger_list_ptr = new DebuggerList();
|
2013-12-03 03:35:49 +08:00
|
|
|
g_load_plugin_callback = load_plugin_callback;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::Terminate() {
|
2016-05-27 00:51:23 +08:00
|
|
|
assert(g_debugger_list_ptr &&
|
|
|
|
"Debugger::Terminate called without a matching Debugger::Initialize!");
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2016-05-27 00:51:23 +08:00
|
|
|
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
|
2021-11-18 06:23:19 +08:00
|
|
|
// Clear our global list of debugger objects
|
2016-05-27 00:51:23 +08:00
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
|
|
|
|
for (const auto &debugger : *g_debugger_list_ptr)
|
|
|
|
debugger->Clear();
|
|
|
|
g_debugger_list_ptr->clear();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-03-11 06:14:10 +08:00
|
|
|
void Debugger::SettingsInitialize() { Target::SettingsInitialize(); }
|
|
|
|
|
|
|
|
void Debugger::SettingsTerminate() { Target::SettingsTerminate(); }
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
bool Debugger::LoadPlugin(const FileSpec &spec, Status &error) {
|
2013-12-03 03:35:49 +08:00
|
|
|
if (g_load_plugin_callback) {
|
2014-08-28 04:15:09 +08:00
|
|
|
llvm::sys::DynamicLibrary dynlib =
|
|
|
|
g_load_plugin_callback(shared_from_this(), spec, error);
|
|
|
|
if (dynlib.isValid()) {
|
|
|
|
m_loaded_plugins.push_back(dynlib);
|
2013-12-03 03:35:49 +08:00
|
|
|
return true;
|
2012-09-29 07:57:51 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// The g_load_plugin_callback is registered in SBDebugger::Initialize() and
|
|
|
|
// if the public API layer isn't available (code is linking against all of
|
|
|
|
// the internal LLDB static libraries), then we can't load plugins
|
2013-12-03 03:35:49 +08:00
|
|
|
error.SetErrorString("Public API layer is not available");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-09-29 07:57:51 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-01 08:33:27 +08:00
|
|
|
static FileSystem::EnumerateDirectoryResult
|
2017-03-09 01:56:08 +08:00
|
|
|
LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft,
|
2018-11-01 08:33:27 +08:00
|
|
|
llvm::StringRef path) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-06-14 00:23:21 +08:00
|
|
|
static ConstString g_dylibext(".dylib");
|
|
|
|
static ConstString g_solibext(".so");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-29 07:57:51 +08:00
|
|
|
if (!baton)
|
2018-11-01 08:33:27 +08:00
|
|
|
return FileSystem::eEnumerateDirectoryResultQuit;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-29 07:57:51 +08:00
|
|
|
Debugger *debugger = (Debugger *)baton;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-03-09 01:56:08 +08:00
|
|
|
namespace fs = llvm::sys::fs;
|
2018-05-01 00:49:04 +08:00
|
|
|
// If we have a regular file, a symbolic link or unknown file type, try and
|
|
|
|
// process the file. We must handle unknown as sometimes the directory
|
2012-09-29 07:57:51 +08:00
|
|
|
// enumeration might be enumerating a file system that doesn't have correct
|
|
|
|
// file type information.
|
2017-03-09 01:56:08 +08:00
|
|
|
if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file ||
|
|
|
|
ft == fs::file_type::type_unknown) {
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec plugin_file_spec(path);
|
|
|
|
FileSystem::Instance().Resolve(plugin_file_spec);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-06-27 10:42:12 +08:00
|
|
|
if (plugin_file_spec.GetFileNameExtension() != g_dylibext &&
|
2012-09-29 07:57:51 +08:00
|
|
|
plugin_file_spec.GetFileNameExtension() != g_solibext) {
|
2018-11-01 08:33:27 +08:00
|
|
|
return FileSystem::eEnumerateDirectoryResultNext;
|
2012-09-29 07:57:51 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status plugin_load_error;
|
2012-09-29 07:57:51 +08:00
|
|
|
debugger->LoadPlugin(plugin_file_spec, plugin_load_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-01 08:33:27 +08:00
|
|
|
return FileSystem::eEnumerateDirectoryResultNext;
|
2017-03-09 01:56:08 +08:00
|
|
|
} else if (ft == fs::file_type::directory_file ||
|
|
|
|
ft == fs::file_type::symlink_file ||
|
|
|
|
ft == fs::file_type::type_unknown) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Try and recurse into anything that a directory or symbolic link. We must
|
|
|
|
// also do this for unknown as sometimes the directory enumeration might be
|
|
|
|
// enumerating a file system that doesn't have correct file type
|
2012-09-29 07:57:51 +08:00
|
|
|
// information.
|
2018-11-01 08:33:27 +08:00
|
|
|
return FileSystem::eEnumerateDirectoryResultEnter;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2018-11-01 08:33:27 +08:00
|
|
|
return FileSystem::eEnumerateDirectoryResultNext;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-09-29 07:57:51 +08:00
|
|
|
void Debugger::InstanceInitialize() {
|
|
|
|
const bool find_directories = true;
|
|
|
|
const bool find_files = true;
|
|
|
|
const bool find_other = true;
|
|
|
|
char dir_path[PATH_MAX];
|
2018-06-19 23:09:07 +08:00
|
|
|
if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
|
2018-11-02 01:09:25 +08:00
|
|
|
if (FileSystem::Instance().Exists(dir_spec) &&
|
|
|
|
dir_spec.GetPath(dir_path, sizeof(dir_path))) {
|
2018-11-01 08:33:27 +08:00
|
|
|
FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
|
|
|
|
find_files, find_other,
|
|
|
|
LoadPluginCallback, this);
|
2012-09-29 07:57:51 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-08-22 01:29:12 +08:00
|
|
|
|
2018-06-19 23:09:07 +08:00
|
|
|
if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
|
2018-11-02 01:09:25 +08:00
|
|
|
if (FileSystem::Instance().Exists(dir_spec) &&
|
|
|
|
dir_spec.GetPath(dir_path, sizeof(dir_path))) {
|
2018-11-01 08:33:27 +08:00
|
|
|
FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
|
|
|
|
find_files, find_other,
|
|
|
|
LoadPluginCallback, this);
|
2012-09-29 07:57:51 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-10-20 02:02:49 +08:00
|
|
|
PluginManager::DebuggerInitialize(*this);
|
2012-09-29 07:57:51 +08:00
|
|
|
}
|
|
|
|
|
2012-02-21 10:23:08 +08:00
|
|
|
DebuggerSP Debugger::CreateInstance(lldb::LogOutputCallback log_callback,
|
|
|
|
void *baton) {
|
|
|
|
DebuggerSP debugger_sp(new Debugger(log_callback, baton));
|
2016-05-27 00:51:23 +08:00
|
|
|
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
|
|
|
|
g_debugger_list_ptr->push_back(debugger_sp);
|
2010-06-23 09:19:29 +08:00
|
|
|
}
|
2012-09-29 07:57:51 +08:00
|
|
|
debugger_sp->InstanceInitialize();
|
2010-06-23 09:19:29 +08:00
|
|
|
return debugger_sp;
|
|
|
|
}
|
|
|
|
|
2011-09-17 16:33:22 +08:00
|
|
|
void Debugger::Destroy(DebuggerSP &debugger_sp) {
|
2016-03-02 10:18:18 +08:00
|
|
|
if (!debugger_sp)
|
2011-01-22 09:02:07 +08:00
|
|
|
return;
|
2011-09-16 05:36:42 +08:00
|
|
|
|
2021-06-29 03:27:55 +08:00
|
|
|
CommandInterpreter &cmd_interpreter = debugger_sp->GetCommandInterpreter();
|
|
|
|
|
|
|
|
if (cmd_interpreter.GetSaveSessionOnQuit()) {
|
|
|
|
CommandReturnObject result(debugger_sp->GetUseColor());
|
|
|
|
cmd_interpreter.SaveTranscript(result);
|
|
|
|
if (result.Succeeded())
|
|
|
|
debugger_sp->GetOutputStream() << result.GetOutputData() << '\n';
|
|
|
|
else
|
|
|
|
debugger_sp->GetErrorStream() << result.GetErrorData() << '\n';
|
|
|
|
}
|
|
|
|
|
2011-09-16 05:36:42 +08:00
|
|
|
debugger_sp->Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-05-27 00:51:23 +08:00
|
|
|
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
|
|
|
|
DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
|
|
|
|
for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
|
2012-03-31 04:53:46 +08:00
|
|
|
if ((*pos).get() == debugger_sp.get()) {
|
2016-05-27 00:51:23 +08:00
|
|
|
g_debugger_list_ptr->erase(pos);
|
2012-03-31 04:53:46 +08:00
|
|
|
return;
|
2011-01-22 09:02:07 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-01-22 09:02:07 +08:00
|
|
|
}
|
|
|
|
|
2019-08-02 08:18:44 +08:00
|
|
|
DebuggerSP Debugger::FindDebuggerWithInstanceName(ConstString instance_name) {
|
2011-09-17 16:33:22 +08:00
|
|
|
DebuggerSP debugger_sp;
|
2016-05-27 00:51:23 +08:00
|
|
|
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
|
|
|
|
DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
|
|
|
|
for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
|
2016-03-02 10:18:18 +08:00
|
|
|
if ((*pos)->m_instance_name == instance_name) {
|
2012-08-23 02:39:03 +08:00
|
|
|
debugger_sp = *pos;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
return debugger_sp;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
TargetSP Debugger::FindTargetWithProcessID(lldb::pid_t pid) {
|
2011-09-17 16:33:22 +08:00
|
|
|
TargetSP target_sp;
|
2016-05-27 00:51:23 +08:00
|
|
|
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
|
|
|
|
DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
|
|
|
|
for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
|
2012-03-31 04:53:46 +08:00
|
|
|
target_sp = (*pos)->GetTargetList().FindTargetWithProcessID(pid);
|
|
|
|
if (target_sp)
|
|
|
|
break;
|
2010-06-23 09:19:29 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
return target_sp;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-11-16 13:37:56 +08:00
|
|
|
TargetSP Debugger::FindTargetWithProcess(Process *process) {
|
|
|
|
TargetSP target_sp;
|
2016-05-27 00:51:23 +08:00
|
|
|
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
|
|
|
|
DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
|
|
|
|
for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
|
2012-03-31 04:53:46 +08:00
|
|
|
target_sp = (*pos)->GetTargetList().FindTargetWithProcess(process);
|
|
|
|
if (target_sp)
|
|
|
|
break;
|
2011-11-16 13:37:56 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-11-16 13:37:56 +08:00
|
|
|
return target_sp;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2021-03-02 07:26:35 +08:00
|
|
|
ConstString Debugger::GetStaticBroadcasterClass() {
|
|
|
|
static ConstString class_name("lldb.debugger");
|
|
|
|
return class_name;
|
|
|
|
}
|
|
|
|
|
2014-09-12 09:50:46 +08:00
|
|
|
Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
|
|
|
|
: UserID(g_unique_id++),
|
2017-04-07 05:28:29 +08:00
|
|
|
Properties(std::make_shared<OptionValueProperties>()),
|
2019-10-03 12:31:46 +08:00
|
|
|
m_input_file_sp(std::make_shared<NativeFile>(stdin, false)),
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
m_output_stream_sp(std::make_shared<StreamFile>(stdout, false)),
|
|
|
|
m_error_stream_sp(std::make_shared<StreamFile>(stderr, false)),
|
2019-03-02 08:20:26 +08:00
|
|
|
m_input_recorder(nullptr),
|
2016-03-08 05:50:25 +08:00
|
|
|
m_broadcaster_manager_sp(BroadcasterManager::MakeBroadcasterManager()),
|
2014-09-12 09:50:46 +08:00
|
|
|
m_terminal_state(), m_target_list(*this), m_platform_list(),
|
2016-03-08 05:50:25 +08:00
|
|
|
m_listener_sp(Listener::MakeListener("lldb.Debugger")),
|
2019-02-13 14:25:41 +08:00
|
|
|
m_source_manager_up(), m_source_file_cache(),
|
2019-04-27 04:03:22 +08:00
|
|
|
m_command_interpreter_up(
|
2019-08-15 06:19:23 +08:00
|
|
|
std::make_unique<CommandInterpreter>(*this, false)),
|
2020-01-16 06:56:28 +08:00
|
|
|
m_io_handler_stack(), m_instance_name(), m_loaded_plugins(),
|
2019-12-22 09:11:12 +08:00
|
|
|
m_event_handler_thread(), m_io_handler_thread(),
|
2016-03-02 10:18:18 +08:00
|
|
|
m_sync_broadcaster(nullptr, "lldb.debugger.sync"),
|
2021-03-02 07:26:35 +08:00
|
|
|
m_broadcaster(m_broadcaster_manager_sp,
|
|
|
|
GetStaticBroadcasterClass().AsCString()),
|
2016-03-02 10:18:18 +08:00
|
|
|
m_forward_listener_sp(), m_clear_once() {
|
2020-07-27 20:05:23 +08:00
|
|
|
m_instance_name.SetString(llvm::formatv("debugger_{0}", GetID()).str());
|
2012-02-21 10:23:08 +08:00
|
|
|
if (log_callback)
|
2017-04-07 05:28:29 +08:00
|
|
|
m_log_callback_stream_sp =
|
|
|
|
std::make_shared<StreamCallback>(log_callback, baton);
|
2019-02-13 14:25:41 +08:00
|
|
|
m_command_interpreter_up->Initialize();
|
2016-05-05 06:26:42 +08:00
|
|
|
// Always add our default platform to the platform list
|
|
|
|
PlatformSP default_platform_sp(Platform::GetHostPlatform());
|
2016-03-02 10:18:18 +08:00
|
|
|
assert(default_platform_sp);
|
2016-05-05 06:26:42 +08:00
|
|
|
m_platform_list.Append(default_platform_sp, true);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-11-06 03:38:50 +08:00
|
|
|
// Create the dummy target.
|
|
|
|
{
|
|
|
|
ArchSpec arch(Target::GetDefaultArchitecture());
|
|
|
|
if (!arch.IsValid())
|
|
|
|
arch = HostInfo::GetArchitecture();
|
|
|
|
assert(arch.IsValid() && "No valid default or host archspec");
|
|
|
|
const bool is_dummy_target = true;
|
|
|
|
m_dummy_target_sp.reset(
|
|
|
|
new Target(*this, arch, default_platform_sp, is_dummy_target));
|
|
|
|
}
|
2019-08-26 17:20:59 +08:00
|
|
|
assert(m_dummy_target_sp.get() && "Couldn't construct dummy target?");
|
|
|
|
|
2019-07-30 00:41:30 +08:00
|
|
|
m_collection_sp->Initialize(g_debugger_properties);
|
2015-03-10 09:15:28 +08:00
|
|
|
m_collection_sp->AppendProperty(
|
2016-05-05 06:26:42 +08:00
|
|
|
ConstString("target"),
|
2012-08-23 01:17:09 +08:00
|
|
|
ConstString("Settings specify to debugging targets."), true,
|
2021-10-07 21:44:47 +08:00
|
|
|
Target::GetGlobalProperties().GetValueProperties());
|
2012-08-23 01:17:09 +08:00
|
|
|
m_collection_sp->AppendProperty(
|
|
|
|
ConstString("platform"), ConstString("Platform settings."), true,
|
2021-10-07 21:44:47 +08:00
|
|
|
Platform::GetGlobalPlatformProperties().GetValueProperties());
|
2018-03-03 06:42:44 +08:00
|
|
|
m_collection_sp->AppendProperty(
|
2018-03-10 09:11:25 +08:00
|
|
|
ConstString("symbols"), ConstString("Symbol lookup and cache settings."),
|
|
|
|
true, ModuleList::GetGlobalModuleListProperties().GetValueProperties());
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_command_interpreter_up) {
|
2015-03-10 09:15:28 +08:00
|
|
|
m_collection_sp->AppendProperty(
|
2012-08-23 08:22:02 +08:00
|
|
|
ConstString("interpreter"),
|
2012-08-23 01:17:09 +08:00
|
|
|
ConstString("Settings specify to the debugger's command interpreter."),
|
2019-02-13 14:25:41 +08:00
|
|
|
true, m_command_interpreter_up->GetValueProperties());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-08-23 08:22:02 +08:00
|
|
|
OptionValueSInt64 *term_width =
|
2012-08-23 01:17:09 +08:00
|
|
|
m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64(
|
|
|
|
nullptr, ePropertyTerminalWidth);
|
|
|
|
term_width->SetMinimumValue(10);
|
|
|
|
term_width->SetMaximumValue(1024);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-24 04:47:45 +08:00
|
|
|
// Turn off use-color if this is a dumb terminal.
|
2012-08-23 01:17:09 +08:00
|
|
|
const char *term = getenv("TERM");
|
|
|
|
if (term && !strcmp(term, "dumb"))
|
|
|
|
SetUseColor(false);
|
2018-08-27 23:16:25 +08:00
|
|
|
// Turn off use-color if we don't write to a terminal with color support.
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
if (!GetOutputFile().GetIsTerminalWithColors())
|
2018-08-27 23:16:25 +08:00
|
|
|
SetUseColor(false);
|
2018-09-06 06:06:58 +08:00
|
|
|
|
|
|
|
#if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
|
|
|
// Enabling use of ANSI color codes because LLDB is using them to highlight
|
|
|
|
// text.
|
|
|
|
llvm::sys::Process::UseANSIEscapeCodes(true);
|
|
|
|
#endif
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-05-05 06:26:42 +08:00
|
|
|
Debugger::~Debugger() { Clear(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
void Debugger::Clear() {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Make sure we call this function only once. With the C++ global destructor
|
|
|
|
// chain having a list of debuggers and with code that can be running on
|
|
|
|
// other threads, we need to ensure this doesn't happen multiple times.
|
2016-09-07 04:57:50 +08:00
|
|
|
//
|
2012-08-23 08:22:02 +08:00
|
|
|
// The following functions call Debugger::Clear():
|
2016-05-05 06:26:42 +08:00
|
|
|
// Debugger::~Debugger();
|
2012-08-23 08:22:02 +08:00
|
|
|
// static void Debugger::Destroy(lldb::DebuggerSP &debugger_sp);
|
|
|
|
// static void Debugger::Terminate();
|
2017-02-07 01:55:02 +08:00
|
|
|
llvm::call_once(m_clear_once, [this]() {
|
2012-08-23 08:22:02 +08:00
|
|
|
ClearIOHandlers();
|
2016-05-05 06:26:42 +08:00
|
|
|
StopIOHandlerThread();
|
2012-08-23 08:22:02 +08:00
|
|
|
StopEventHandlerThread();
|
2016-05-05 06:26:42 +08:00
|
|
|
m_listener_sp->Clear();
|
2021-07-14 01:34:27 +08:00
|
|
|
for (TargetSP target_sp : m_target_list.Targets()) {
|
2012-08-23 08:22:02 +08:00
|
|
|
if (target_sp) {
|
2021-07-14 01:34:27 +08:00
|
|
|
if (ProcessSP process_sp = target_sp->GetProcessSP())
|
2012-08-23 08:22:02 +08:00
|
|
|
process_sp->Finalize();
|
2016-05-05 06:26:42 +08:00
|
|
|
target_sp->Destroy();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-08-23 08:22:02 +08:00
|
|
|
}
|
2016-03-02 10:18:18 +08:00
|
|
|
m_broadcaster_manager_sp->Clear();
|
2013-05-24 04:47:45 +08:00
|
|
|
|
|
|
|
// Close the input file _before_ we close the input read communications
|
2018-05-01 00:49:04 +08:00
|
|
|
// class as it does NOT own the input file, our m_input_file does.
|
2013-05-24 04:47:45 +08:00
|
|
|
m_terminal_state.Clear();
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
GetInputFile().Close();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
m_command_interpreter_up->Clear();
|
2013-05-24 04:47:45 +08:00
|
|
|
});
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Debugger::GetCloseInputOnEOF() const {
|
2011-09-16 05:36:42 +08:00
|
|
|
// return m_input_comm.GetCloseOnEOF();
|
2014-01-28 07:43:24 +08:00
|
|
|
return false;
|
2011-09-16 05:36:42 +08:00
|
|
|
}
|
|
|
|
|
2016-05-05 06:26:42 +08:00
|
|
|
void Debugger::SetCloseInputOnEOF(bool b) {
|
2014-01-28 07:43:24 +08:00
|
|
|
// m_input_comm.SetCloseOnEOF(b);
|
2011-05-29 12:06:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Debugger::GetAsyncExecution() {
|
2019-02-13 14:25:41 +08:00
|
|
|
return !m_command_interpreter_up->GetSynchronous();
|
2011-05-29 12:06:55 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void Debugger::SetAsyncExecution(bool async_execution) {
|
2019-02-13 14:25:41 +08:00
|
|
|
m_command_interpreter_up->SetSynchronous(!async_execution);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-03-02 08:20:26 +08:00
|
|
|
repro::DataRecorder *Debugger::GetInputRecorder() { return m_input_recorder; }
|
|
|
|
|
2019-10-03 12:04:48 +08:00
|
|
|
void Debugger::SetInputFile(FileSP file_sp, repro::DataRecorder *recorder) {
|
|
|
|
assert(file_sp && file_sp->IsValid());
|
2019-03-02 08:20:26 +08:00
|
|
|
m_input_recorder = recorder;
|
2020-08-11 12:01:23 +08:00
|
|
|
m_input_file_sp = std::move(file_sp);
|
2018-05-01 00:49:04 +08:00
|
|
|
// Save away the terminal state if that is relevant, so that we can restore
|
|
|
|
// it in RestoreInputState.
|
2012-12-01 04:23:19 +08:00
|
|
|
SaveInputTerminalState();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-10-03 12:04:48 +08:00
|
|
|
void Debugger::SetOutputFile(FileSP file_sp) {
|
|
|
|
assert(file_sp && file_sp->IsValid());
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
m_output_stream_sp = std::make_shared<StreamFile>(file_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-10-03 12:04:48 +08:00
|
|
|
void Debugger::SetErrorFile(FileSP file_sp) {
|
|
|
|
assert(file_sp && file_sp->IsValid());
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
m_error_stream_sp = std::make_shared<StreamFile>(file_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-12-01 04:23:19 +08:00
|
|
|
void Debugger::SaveInputTerminalState() {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
int fd = GetInputFile().GetDescriptor();
|
|
|
|
if (fd != File::kInvalidDescriptor)
|
|
|
|
m_terminal_state.Save(fd, true);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-12-01 04:23:19 +08:00
|
|
|
void Debugger::RestoreInputTerminalState() { m_terminal_state.Restore(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-08-27 05:32:51 +08:00
|
|
|
ExecutionContext Debugger::GetSelectedExecutionContext() {
|
2021-02-02 03:24:30 +08:00
|
|
|
bool adopt_selected = true;
|
|
|
|
ExecutionContextRef exe_ctx_ref(GetSelectedTarget().get(), adopt_selected);
|
|
|
|
return ExecutionContext(exe_ctx_ref);
|
2012-12-01 04:23:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::DispatchInputInterrupt() {
|
2020-01-16 06:56:28 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
|
|
|
|
IOHandlerSP reader_sp(m_io_handler_stack.Top());
|
2011-02-10 09:15:13 +08:00
|
|
|
if (reader_sp)
|
2014-01-28 07:43:24 +08:00
|
|
|
reader_sp->Interrupt();
|
2012-12-01 04:23:19 +08:00
|
|
|
}
|
|
|
|
|
2010-08-27 05:32:51 +08:00
|
|
|
void Debugger::DispatchInputEndOfFile() {
|
2020-01-16 06:56:28 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
|
|
|
|
IOHandlerSP reader_sp(m_io_handler_stack.Top());
|
2011-09-22 12:58:26 +08:00
|
|
|
if (reader_sp)
|
|
|
|
reader_sp->GotEOF();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-11-20 04:47:54 +08:00
|
|
|
void Debugger::ClearIOHandlers() {
|
2016-05-18 09:59:10 +08:00
|
|
|
// The bottom input reader should be the main debugger input reader. We do
|
|
|
|
// not want to close that one here.
|
2020-01-16 06:56:28 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
|
|
|
|
while (m_io_handler_stack.GetSize() > 1) {
|
|
|
|
IOHandlerSP reader_sp(m_io_handler_stack.Top());
|
2011-02-10 09:15:13 +08:00
|
|
|
if (reader_sp)
|
2014-01-28 07:43:24 +08:00
|
|
|
PopIOHandler(reader_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-11-20 04:47:54 +08:00
|
|
|
}
|
|
|
|
|
2020-01-17 08:45:18 +08:00
|
|
|
void Debugger::RunIOHandlers() {
|
[lldb/IOHandler] Improve synchronization between IO handlers.
The way the IO handlers are currently managed by the debugger is wrong. The
implementation lacks proper synchronization between RunIOHandlerSync and
RunIOHandlers. The latter is meant to be run by the "main thread", while the
former is meant to be run synchronously, potentially from a different thread.
Imagine a scenario where RunIOHandlerSync is called from a different thread
than RunIOHandlers. Both functions manipulate the debugger's IOHandlerStack.
Although the push and pop operations are synchronized, the logic to activate,
deactivate and run IO handlers is not.
While investigating PR44352, I noticed some weird behavior in the Editline
implementation. One of its members (m_editor_status) was modified from another
thread. This happened because the main thread, while running RunIOHandlers
ended up execution the IOHandlerEditline created by the breakpoint callback
thread. Even worse, due to the lack of synchronization within the IO handler
implementation, both threads ended up executing the same IO handler.
Most of the time, the IO handlers don't need to run synchronously. The
exception is sourcing commands from external files, like the .lldbinit file.
I've added a (recursive) mutex to prevent another thread from messing with the
IO handlers wile another thread is running one synchronously. It has to be
recursive, because we might have to source another file when encountering a
command source in the original file.
Differential revision: https://reviews.llvm.org/D72748
2020-01-21 03:05:13 +08:00
|
|
|
IOHandlerSP reader_sp = m_io_handler_stack.Top();
|
2010-11-20 04:47:54 +08:00
|
|
|
while (true) {
|
2011-02-10 09:15:13 +08:00
|
|
|
if (!reader_sp)
|
2014-01-28 07:43:24 +08:00
|
|
|
break;
|
2010-11-20 04:47:54 +08:00
|
|
|
|
2016-05-18 09:59:10 +08:00
|
|
|
reader_sp->Run();
|
[lldb/IOHandler] Improve synchronization between IO handlers.
The way the IO handlers are currently managed by the debugger is wrong. The
implementation lacks proper synchronization between RunIOHandlerSync and
RunIOHandlers. The latter is meant to be run by the "main thread", while the
former is meant to be run synchronously, potentially from a different thread.
Imagine a scenario where RunIOHandlerSync is called from a different thread
than RunIOHandlers. Both functions manipulate the debugger's IOHandlerStack.
Although the push and pop operations are synchronized, the logic to activate,
deactivate and run IO handlers is not.
While investigating PR44352, I noticed some weird behavior in the Editline
implementation. One of its members (m_editor_status) was modified from another
thread. This happened because the main thread, while running RunIOHandlers
ended up execution the IOHandlerEditline created by the breakpoint callback
thread. Even worse, due to the lack of synchronization within the IO handler
implementation, both threads ended up executing the same IO handler.
Most of the time, the IO handlers don't need to run synchronously. The
exception is sourcing commands from external files, like the .lldbinit file.
I've added a (recursive) mutex to prevent another thread from messing with the
IO handlers wile another thread is running one synchronously. It has to be
recursive, because we might have to source another file when encountering a
command source in the original file.
Differential revision: https://reviews.llvm.org/D72748
2020-01-21 03:05:13 +08:00
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
m_io_handler_synchronous_mutex);
|
|
|
|
|
|
|
|
// Remove all input readers that are done from the top of the stack
|
|
|
|
while (true) {
|
|
|
|
IOHandlerSP top_reader_sp = m_io_handler_stack.Top();
|
|
|
|
if (top_reader_sp && top_reader_sp->GetIsDone())
|
|
|
|
PopIOHandler(top_reader_sp);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
reader_sp = m_io_handler_stack.Top();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ClearIOHandlers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::RunIOHandlerSync(const IOHandlerSP &reader_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_io_handler_synchronous_mutex);
|
|
|
|
|
|
|
|
PushIOHandler(reader_sp);
|
|
|
|
IOHandlerSP top_reader_sp = reader_sp;
|
2010-12-21 02:35:50 +08:00
|
|
|
|
[lldb/IOHandler] Improve synchronization between IO handlers.
The way the IO handlers are currently managed by the debugger is wrong. The
implementation lacks proper synchronization between RunIOHandlerSync and
RunIOHandlers. The latter is meant to be run by the "main thread", while the
former is meant to be run synchronously, potentially from a different thread.
Imagine a scenario where RunIOHandlerSync is called from a different thread
than RunIOHandlers. Both functions manipulate the debugger's IOHandlerStack.
Although the push and pop operations are synchronized, the logic to activate,
deactivate and run IO handlers is not.
While investigating PR44352, I noticed some weird behavior in the Editline
implementation. One of its members (m_editor_status) was modified from another
thread. This happened because the main thread, while running RunIOHandlers
ended up execution the IOHandlerEditline created by the breakpoint callback
thread. Even worse, due to the lack of synchronization within the IO handler
implementation, both threads ended up executing the same IO handler.
Most of the time, the IO handlers don't need to run synchronously. The
exception is sourcing commands from external files, like the .lldbinit file.
I've added a (recursive) mutex to prevent another thread from messing with the
IO handlers wile another thread is running one synchronously. It has to be
recursive, because we might have to source another file when encountering a
command source in the original file.
Differential revision: https://reviews.llvm.org/D72748
2020-01-21 03:05:13 +08:00
|
|
|
while (top_reader_sp) {
|
|
|
|
if (!top_reader_sp)
|
|
|
|
break;
|
|
|
|
|
|
|
|
top_reader_sp->Run();
|
|
|
|
|
|
|
|
// Don't unwind past the starting point.
|
|
|
|
if (top_reader_sp.get() == reader_sp.get()) {
|
|
|
|
if (PopIOHandler(reader_sp))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we pushed new IO handlers, pop them if they're done or restart the
|
|
|
|
// loop to run them if they're not.
|
2016-03-02 10:18:18 +08:00
|
|
|
while (true) {
|
[lldb/IOHandler] Improve synchronization between IO handlers.
The way the IO handlers are currently managed by the debugger is wrong. The
implementation lacks proper synchronization between RunIOHandlerSync and
RunIOHandlers. The latter is meant to be run by the "main thread", while the
former is meant to be run synchronously, potentially from a different thread.
Imagine a scenario where RunIOHandlerSync is called from a different thread
than RunIOHandlers. Both functions manipulate the debugger's IOHandlerStack.
Although the push and pop operations are synchronized, the logic to activate,
deactivate and run IO handlers is not.
While investigating PR44352, I noticed some weird behavior in the Editline
implementation. One of its members (m_editor_status) was modified from another
thread. This happened because the main thread, while running RunIOHandlers
ended up execution the IOHandlerEditline created by the breakpoint callback
thread. Even worse, due to the lack of synchronization within the IO handler
implementation, both threads ended up executing the same IO handler.
Most of the time, the IO handlers don't need to run synchronously. The
exception is sourcing commands from external files, like the .lldbinit file.
I've added a (recursive) mutex to prevent another thread from messing with the
IO handlers wile another thread is running one synchronously. It has to be
recursive, because we might have to source another file when encountering a
command source in the original file.
Differential revision: https://reviews.llvm.org/D72748
2020-01-21 03:05:13 +08:00
|
|
|
top_reader_sp = m_io_handler_stack.Top();
|
|
|
|
if (top_reader_sp && top_reader_sp->GetIsDone()) {
|
2015-05-27 20:40:32 +08:00
|
|
|
PopIOHandler(top_reader_sp);
|
[lldb/IOHandler] Improve synchronization between IO handlers.
The way the IO handlers are currently managed by the debugger is wrong. The
implementation lacks proper synchronization between RunIOHandlerSync and
RunIOHandlers. The latter is meant to be run by the "main thread", while the
former is meant to be run synchronously, potentially from a different thread.
Imagine a scenario where RunIOHandlerSync is called from a different thread
than RunIOHandlers. Both functions manipulate the debugger's IOHandlerStack.
Although the push and pop operations are synchronized, the logic to activate,
deactivate and run IO handlers is not.
While investigating PR44352, I noticed some weird behavior in the Editline
implementation. One of its members (m_editor_status) was modified from another
thread. This happened because the main thread, while running RunIOHandlers
ended up execution the IOHandlerEditline created by the breakpoint callback
thread. Even worse, due to the lack of synchronization within the IO handler
implementation, both threads ended up executing the same IO handler.
Most of the time, the IO handlers don't need to run synchronously. The
exception is sourcing commands from external files, like the .lldbinit file.
I've added a (recursive) mutex to prevent another thread from messing with the
IO handlers wile another thread is running one synchronously. It has to be
recursive, because we might have to source another file when encountering a
command source in the original file.
Differential revision: https://reviews.llvm.org/D72748
2020-01-21 03:05:13 +08:00
|
|
|
// Don't unwind past the starting point.
|
|
|
|
if (top_reader_sp.get() == reader_sp.get())
|
|
|
|
return;
|
|
|
|
} else {
|
2014-01-28 07:43:24 +08:00
|
|
|
break;
|
[lldb/IOHandler] Improve synchronization between IO handlers.
The way the IO handlers are currently managed by the debugger is wrong. The
implementation lacks proper synchronization between RunIOHandlerSync and
RunIOHandlers. The latter is meant to be run by the "main thread", while the
former is meant to be run synchronously, potentially from a different thread.
Imagine a scenario where RunIOHandlerSync is called from a different thread
than RunIOHandlers. Both functions manipulate the debugger's IOHandlerStack.
Although the push and pop operations are synchronized, the logic to activate,
deactivate and run IO handlers is not.
While investigating PR44352, I noticed some weird behavior in the Editline
implementation. One of its members (m_editor_status) was modified from another
thread. This happened because the main thread, while running RunIOHandlers
ended up execution the IOHandlerEditline created by the breakpoint callback
thread. Even worse, due to the lack of synchronization within the IO handler
implementation, both threads ended up executing the same IO handler.
Most of the time, the IO handlers don't need to run synchronously. The
exception is sourcing commands from external files, like the .lldbinit file.
I've added a (recursive) mutex to prevent another thread from messing with the
IO handlers wile another thread is running one synchronously. It has to be
recursive, because we might have to source another file when encountering a
command source in the original file.
Differential revision: https://reviews.llvm.org/D72748
2020-01-21 03:05:13 +08:00
|
|
|
}
|
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
2011-05-03 04:41:46 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
2011-05-03 04:41:46 +08:00
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
bool Debugger::IsTopIOHandler(const lldb::IOHandlerSP &reader_sp) {
|
2020-01-16 06:56:28 +08:00
|
|
|
return m_io_handler_stack.IsTop(reader_sp);
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
|
|
|
|
2015-10-20 07:11:07 +08:00
|
|
|
bool Debugger::CheckTopIOHandlerTypes(IOHandler::Type top_type,
|
|
|
|
IOHandler::Type second_top_type) {
|
2020-01-16 06:56:28 +08:00
|
|
|
return m_io_handler_stack.CheckTopIOHandlerTypes(top_type, second_top_type);
|
2015-10-20 07:11:07 +08:00
|
|
|
}
|
|
|
|
|
2015-05-27 20:40:32 +08:00
|
|
|
void Debugger::PrintAsync(const char *s, size_t len, bool is_stdout) {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
lldb_private::StreamFile &stream =
|
|
|
|
is_stdout ? GetOutputStream() : GetErrorStream();
|
2020-01-16 06:56:28 +08:00
|
|
|
m_io_handler_stack.PrintAsync(&stream, s, len);
|
2015-05-27 20:40:32 +08:00
|
|
|
}
|
2011-05-10 07:06:58 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
ConstString Debugger::GetTopIOHandlerControlSequence(char ch) {
|
2020-01-16 06:56:28 +08:00
|
|
|
return m_io_handler_stack.GetTopIOHandlerControlSequence(ch);
|
2011-05-10 07:06:58 +08:00
|
|
|
}
|
|
|
|
|
2015-01-15 08:52:41 +08:00
|
|
|
const char *Debugger::GetIOHandlerCommandPrefix() {
|
2020-01-16 06:56:28 +08:00
|
|
|
return m_io_handler_stack.GetTopIOHandlerCommandPrefix();
|
2015-01-15 08:52:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *Debugger::GetIOHandlerHelpPrologue() {
|
2020-01-16 06:56:28 +08:00
|
|
|
return m_io_handler_stack.GetTopIOHandlerHelpPrologue();
|
2015-01-15 08:52:41 +08:00
|
|
|
}
|
|
|
|
|
2020-01-16 06:56:28 +08:00
|
|
|
bool Debugger::RemoveIOHandler(const IOHandlerSP &reader_sp) {
|
|
|
|
return PopIOHandler(reader_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::RunIOHandlerAsync(const IOHandlerSP &reader_sp,
|
|
|
|
bool cancel_top_handler) {
|
|
|
|
PushIOHandler(reader_sp, cancel_top_handler);
|
|
|
|
}
|
|
|
|
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
void Debugger::AdoptTopIOHandlerFilesIfInvalid(FileSP &in, StreamFileSP &out,
|
2016-05-18 09:59:10 +08:00
|
|
|
StreamFileSP &err) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Before an IOHandler runs, it must have in/out/err streams. This function
|
|
|
|
// is called when one ore more of the streams are nullptr. We use the top
|
|
|
|
// input reader's in/out/err streams, or fall back to the debugger file
|
|
|
|
// handles, or we fall back onto stdin/stdout/stderr as a last resort.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-01-16 06:56:28 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
|
|
|
|
IOHandlerSP top_reader_sp(m_io_handler_stack.Top());
|
2014-01-28 07:43:24 +08:00
|
|
|
// If no STDIN has been set, then set it appropriately
|
2019-10-16 09:58:15 +08:00
|
|
|
if (!in || !in->IsValid()) {
|
2014-01-28 07:43:24 +08:00
|
|
|
if (top_reader_sp)
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
in = top_reader_sp->GetInputFileSP();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
in = GetInputFileSP();
|
2016-03-02 10:18:18 +08:00
|
|
|
// If there is nothing, use stdin
|
2014-01-28 07:43:24 +08:00
|
|
|
if (!in)
|
2019-10-03 12:31:46 +08:00
|
|
|
in = std::make_shared<NativeFile>(stdin, false);
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
|
|
|
// If no STDOUT has been set, then set it appropriately
|
2019-10-16 09:58:15 +08:00
|
|
|
if (!out || !out->GetFile().IsValid()) {
|
2014-01-28 07:43:24 +08:00
|
|
|
if (top_reader_sp)
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
out = top_reader_sp->GetOutputStreamFileSP();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
out = GetOutputStreamSP();
|
2014-01-28 07:43:24 +08:00
|
|
|
// If there is nothing, use stdout
|
|
|
|
if (!out)
|
2017-04-07 05:28:29 +08:00
|
|
|
out = std::make_shared<StreamFile>(stdout, false);
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
|
|
|
// If no STDERR has been set, then set it appropriately
|
2019-10-16 09:58:15 +08:00
|
|
|
if (!err || !err->GetFile().IsValid()) {
|
2014-01-28 07:43:24 +08:00
|
|
|
if (top_reader_sp)
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
err = top_reader_sp->GetErrorStreamFileSP();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
err = GetErrorStreamSP();
|
2014-01-28 07:43:24 +08:00
|
|
|
// If there is nothing, use stderr
|
|
|
|
if (!err)
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
err = std::make_shared<StreamFile>(stderr, false);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Don't cancel the current IOHandler when we push a handler for an utility function run.
Summary:
D48465 is currently blocked by the fact that tab-completing the first expression is deadlocking LLDB.
The reason for this deadlock is that when we push the ProcessIO handler for reading the Objective-C runtime
information from the executable (which is triggered when we parse the an expression for the first time),
the IOHandler can't be pushed as the Editline::Cancel method is deadlocking.
The deadlock in Editline is coming from the m_output_mutex, which is locked before we go into tab completion.
Even without this lock, calling Cancel on Editline will mean that Editline cleans up behind itself and deletes the
current user-input, which is screws up the console when we are tab-completing at the same time.
I think for now the most reasonable way of fixing this is to just not call Cancel on the current IOHandler when we push
the IOHandler for running an internal utility function.
As we can't really write unit tests for IOHandler itself (due to the hard dependency on an initialized Debugger including
all its global state) and Editline completion is currently also not really testable in an automatic fashion, the test for this has
to be that the expression command completion in D48465 doesn't fail when requesting completion the first time.
A more precise test plan for this is:
1. Apply D48465.
2. Start lldb and break in some function.
3. Type `expr foo` and press tab to request completion.
4. Without this patch, we deadlock and LLDB stops responding.
I'll provide an actual unit test for this once I got around and made the IOHandler code testable,
but for now unblocking D48465 is more critical.
Thanks to Jim for helping me debugging this.
Reviewers: jingham
Reviewed By: jingham
Subscribers: emaste, clayborg, abidh, lldb-commits
Differential Revision: https://reviews.llvm.org/D50912
llvm-svn: 340988
2018-08-30 06:50:54 +08:00
|
|
|
void Debugger::PushIOHandler(const IOHandlerSP &reader_sp,
|
|
|
|
bool cancel_top_handler) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (!reader_sp)
|
|
|
|
return;
|
2016-05-18 09:59:10 +08:00
|
|
|
|
2020-01-16 06:56:28 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
|
2015-05-27 20:40:32 +08:00
|
|
|
|
|
|
|
// Get the current top input reader...
|
2020-01-16 06:56:28 +08:00
|
|
|
IOHandlerSP top_reader_sp(m_io_handler_stack.Top());
|
2016-05-18 09:59:10 +08:00
|
|
|
|
2014-03-01 02:22:24 +08:00
|
|
|
// Don't push the same IO handler twice...
|
2015-05-27 20:40:32 +08:00
|
|
|
if (reader_sp == top_reader_sp)
|
|
|
|
return;
|
2014-01-28 07:43:24 +08:00
|
|
|
|
2015-05-27 20:40:32 +08:00
|
|
|
// Push our new input reader
|
2020-01-16 06:56:28 +08:00
|
|
|
m_io_handler_stack.Push(reader_sp);
|
2015-05-27 20:40:32 +08:00
|
|
|
reader_sp->Activate();
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Interrupt the top input reader to it will exit its Run() function and let
|
|
|
|
// this new input reader take over
|
2015-05-27 20:40:32 +08:00
|
|
|
if (top_reader_sp) {
|
|
|
|
top_reader_sp->Deactivate();
|
Don't cancel the current IOHandler when we push a handler for an utility function run.
Summary:
D48465 is currently blocked by the fact that tab-completing the first expression is deadlocking LLDB.
The reason for this deadlock is that when we push the ProcessIO handler for reading the Objective-C runtime
information from the executable (which is triggered when we parse the an expression for the first time),
the IOHandler can't be pushed as the Editline::Cancel method is deadlocking.
The deadlock in Editline is coming from the m_output_mutex, which is locked before we go into tab completion.
Even without this lock, calling Cancel on Editline will mean that Editline cleans up behind itself and deletes the
current user-input, which is screws up the console when we are tab-completing at the same time.
I think for now the most reasonable way of fixing this is to just not call Cancel on the current IOHandler when we push
the IOHandler for running an internal utility function.
As we can't really write unit tests for IOHandler itself (due to the hard dependency on an initialized Debugger including
all its global state) and Editline completion is currently also not really testable in an automatic fashion, the test for this has
to be that the expression command completion in D48465 doesn't fail when requesting completion the first time.
A more precise test plan for this is:
1. Apply D48465.
2. Start lldb and break in some function.
3. Type `expr foo` and press tab to request completion.
4. Without this patch, we deadlock and LLDB stops responding.
I'll provide an actual unit test for this once I got around and made the IOHandler code testable,
but for now unblocking D48465 is more critical.
Thanks to Jim for helping me debugging this.
Reviewers: jingham
Reviewed By: jingham
Subscribers: emaste, clayborg, abidh, lldb-commits
Differential Revision: https://reviews.llvm.org/D50912
llvm-svn: 340988
2018-08-30 06:50:54 +08:00
|
|
|
if (cancel_top_handler)
|
|
|
|
top_reader_sp->Cancel();
|
2014-03-01 02:22:24 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-05-18 09:59:10 +08:00
|
|
|
bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
|
|
|
|
if (!pop_reader_sp)
|
2015-05-27 20:40:32 +08:00
|
|
|
return false;
|
|
|
|
|
2020-01-16 06:56:28 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// The reader on the stop of the stack is done, so let the next read on the
|
|
|
|
// stack refresh its prompt and if there is one...
|
2020-01-16 06:56:28 +08:00
|
|
|
if (m_io_handler_stack.IsEmpty())
|
2015-05-27 20:40:32 +08:00
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2020-01-16 06:56:28 +08:00
|
|
|
IOHandlerSP reader_sp(m_io_handler_stack.Top());
|
2015-05-27 20:40:32 +08:00
|
|
|
|
|
|
|
if (pop_reader_sp != reader_sp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
reader_sp->Deactivate();
|
|
|
|
reader_sp->Cancel();
|
2020-01-16 06:56:28 +08:00
|
|
|
m_io_handler_stack.Pop();
|
2015-05-27 20:40:32 +08:00
|
|
|
|
2020-01-16 06:56:28 +08:00
|
|
|
reader_sp = m_io_handler_stack.Top();
|
2014-01-28 07:43:24 +08:00
|
|
|
if (reader_sp)
|
2015-05-27 20:40:32 +08:00
|
|
|
reader_sp->Activate();
|
2010-06-23 09:19:29 +08:00
|
|
|
|
2015-05-27 20:40:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
|
2011-06-03 07:58:26 +08:00
|
|
|
StreamSP Debugger::GetAsyncOutputStream() {
|
2017-04-07 05:28:29 +08:00
|
|
|
return std::make_shared<StreamAsynchronousIO>(*this, true);
|
2011-06-03 07:58:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StreamSP Debugger::GetAsyncErrorStream() {
|
2017-04-07 05:28:29 +08:00
|
|
|
return std::make_shared<StreamAsynchronousIO>(*this, false);
|
2011-06-03 07:58:26 +08:00
|
|
|
}
|
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
size_t Debugger::GetNumDebuggers() {
|
2016-05-27 00:51:23 +08:00
|
|
|
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
|
|
|
|
return g_debugger_list_ptr->size();
|
2012-03-31 04:53:46 +08:00
|
|
|
}
|
|
|
|
return 0;
|
2012-02-15 10:34:21 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
lldb::DebuggerSP Debugger::GetDebuggerAtIndex(size_t index) {
|
2012-02-15 10:34:21 +08:00
|
|
|
DebuggerSP debugger_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-05-27 00:51:23 +08:00
|
|
|
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
|
|
|
|
if (index < g_debugger_list_ptr->size())
|
|
|
|
debugger_sp = g_debugger_list_ptr->at(index);
|
2012-03-31 04:53:46 +08:00
|
|
|
}
|
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
return debugger_sp;
|
|
|
|
}
|
|
|
|
|
2010-07-01 00:22:25 +08:00
|
|
|
DebuggerSP Debugger::FindDebuggerWithID(lldb::user_id_t id) {
|
2011-09-17 16:33:22 +08:00
|
|
|
DebuggerSP debugger_sp;
|
2010-07-01 00:22:25 +08:00
|
|
|
|
2016-05-27 00:51:23 +08:00
|
|
|
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
|
|
|
|
DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
|
|
|
|
for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
|
2016-03-02 10:18:18 +08:00
|
|
|
if ((*pos)->GetID() == id) {
|
2012-03-31 04:53:46 +08:00
|
|
|
debugger_sp = *pos;
|
|
|
|
break;
|
2010-07-01 00:22:25 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-07-01 00:22:25 +08:00
|
|
|
return debugger_sp;
|
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
|
2015-02-05 06:00:53 +08:00
|
|
|
bool Debugger::FormatDisassemblerAddress(const FormatEntity::Entry *format,
|
2014-10-11 07:07:36 +08:00
|
|
|
const SymbolContext *sc,
|
|
|
|
const SymbolContext *prev_sc,
|
|
|
|
const ExecutionContext *exe_ctx,
|
|
|
|
const Address *addr, Stream &s) {
|
2015-02-05 06:00:53 +08:00
|
|
|
FormatEntity::Entry format_entry;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-02 10:18:18 +08:00
|
|
|
if (format == nullptr) {
|
|
|
|
if (exe_ctx != nullptr && exe_ctx->HasTargetScope())
|
2015-02-05 06:00:53 +08:00
|
|
|
format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
|
2016-03-02 10:18:18 +08:00
|
|
|
if (format == nullptr) {
|
2015-02-05 06:00:53 +08:00
|
|
|
FormatEntity::Parse("${addr}: ", format_entry);
|
|
|
|
format = &format_entry;
|
2014-10-11 07:07:36 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-10-11 07:07:36 +08:00
|
|
|
bool function_changed = false;
|
|
|
|
bool initial_function = false;
|
|
|
|
if (prev_sc && (prev_sc->function || prev_sc->symbol)) {
|
|
|
|
if (sc && (sc->function || sc->symbol)) {
|
|
|
|
if (prev_sc->symbol && sc->symbol) {
|
|
|
|
if (!sc->symbol->Compare(prev_sc->symbol->GetName(),
|
|
|
|
prev_sc->symbol->GetType())) {
|
|
|
|
function_changed = true;
|
|
|
|
}
|
|
|
|
} else if (prev_sc->function && sc->function) {
|
|
|
|
if (prev_sc->function->GetMangled() != sc->function->GetMangled()) {
|
|
|
|
function_changed = true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-10-11 07:07:36 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2018-05-01 00:49:04 +08:00
|
|
|
// The first context on a list of instructions will have a prev_sc that has
|
|
|
|
// no Function or Symbol -- if SymbolContext had an IsValid() method, it
|
2014-10-11 07:07:36 +08:00
|
|
|
// would return false. But we do get a prev_sc pointer.
|
|
|
|
if ((sc && (sc->function || sc->symbol)) && prev_sc &&
|
2016-03-02 10:18:18 +08:00
|
|
|
(prev_sc->function == nullptr && prev_sc->symbol == nullptr)) {
|
2014-10-11 07:07:36 +08:00
|
|
|
initial_function = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-03-02 10:18:18 +08:00
|
|
|
return FormatEntity::Format(*format, s, sc, exe_ctx, addr, nullptr,
|
|
|
|
function_changed, initial_function);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-21 10:23:08 +08:00
|
|
|
void Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,
|
|
|
|
void *baton) {
|
2012-02-23 06:49:20 +08:00
|
|
|
// For simplicity's sake, I am not going to deal with how to close down any
|
|
|
|
// open logging streams, I just redirect everything from here on out to the
|
|
|
|
// callback.
|
2017-04-07 05:28:29 +08:00
|
|
|
m_log_callback_stream_sp =
|
|
|
|
std::make_shared<StreamCallback>(log_callback, baton);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2021-03-02 07:26:35 +08:00
|
|
|
ConstString Debugger::ProgressEventData::GetFlavorString() {
|
|
|
|
static ConstString g_flavor("Debugger::ProgressEventData");
|
|
|
|
return g_flavor;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstString Debugger::ProgressEventData::GetFlavor() const {
|
|
|
|
return Debugger::ProgressEventData::GetFlavorString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::ProgressEventData::Dump(Stream *s) const {
|
|
|
|
s->Printf(" id = %" PRIu64 ", message = \"%s\"", m_id, m_message.c_str());
|
|
|
|
if (m_completed == 0 || m_completed == m_total)
|
|
|
|
s->Printf(", type = %s", m_completed == 0 ? "start" : "end");
|
|
|
|
else
|
|
|
|
s->PutCString(", type = update");
|
|
|
|
// If m_total is UINT64_MAX, there is no progress to report, just "start"
|
|
|
|
// and "end". If it isn't we will show the completed and total amounts.
|
|
|
|
if (m_total != UINT64_MAX)
|
|
|
|
s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Debugger::ProgressEventData *
|
|
|
|
Debugger::ProgressEventData::GetEventDataFromEvent(const Event *event_ptr) {
|
|
|
|
if (event_ptr)
|
|
|
|
if (const EventData *event_data = event_ptr->GetData())
|
|
|
|
if (event_data->GetFlavor() == ProgressEventData::GetFlavorString())
|
|
|
|
return static_cast<const ProgressEventData *>(event_ptr->GetData());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
|
|
|
|
const std::string &message,
|
|
|
|
uint64_t completed, uint64_t total,
|
|
|
|
bool is_debugger_specific) {
|
|
|
|
// Only deliver progress events if we have any progress listeners.
|
|
|
|
const uint32_t event_type = Debugger::eBroadcastBitProgress;
|
|
|
|
if (!debugger.GetBroadcaster().EventTypeHasListeners(event_type))
|
|
|
|
return;
|
|
|
|
EventSP event_sp(new Event(event_type, new Debugger::ProgressEventData(
|
|
|
|
progress_id, message, completed,
|
|
|
|
total, is_debugger_specific)));
|
|
|
|
debugger.GetBroadcaster().BroadcastEvent(event_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::ReportProgress(uint64_t progress_id, const std::string &message,
|
|
|
|
uint64_t completed, uint64_t total,
|
|
|
|
llvm::Optional<lldb::user_id_t> debugger_id) {
|
|
|
|
// Check if this progress is for a specific debugger.
|
|
|
|
if (debugger_id.hasValue()) {
|
|
|
|
// It is debugger specific, grab it and deliver the event if the debugger
|
|
|
|
// still exists.
|
|
|
|
DebuggerSP debugger_sp = FindDebuggerWithID(*debugger_id);
|
|
|
|
if (debugger_sp)
|
|
|
|
PrivateReportProgress(*debugger_sp, progress_id, message, completed,
|
|
|
|
total, /*is_debugger_specific*/ true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// The progress event is not debugger specific, iterate over all debuggers
|
|
|
|
// and deliver a progress event to each one.
|
|
|
|
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
|
|
|
|
DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
|
|
|
|
for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos)
|
|
|
|
PrivateReportProgress(*(*pos), progress_id, message, completed, total,
|
|
|
|
/*is_debugger_specific*/ false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-01 18:08:40 +08:00
|
|
|
bool Debugger::EnableLog(llvm::StringRef channel,
|
|
|
|
llvm::ArrayRef<const char *> categories,
|
|
|
|
llvm::StringRef log_file, uint32_t log_options,
|
2017-03-15 17:06:58 +08:00
|
|
|
llvm::raw_ostream &error_stream) {
|
2017-02-10 19:49:21 +08:00
|
|
|
const bool should_close = true;
|
|
|
|
const bool unbuffered = true;
|
|
|
|
|
|
|
|
std::shared_ptr<llvm::raw_ostream> log_stream_sp;
|
2012-08-09 08:50:26 +08:00
|
|
|
if (m_log_callback_stream_sp) {
|
2012-02-21 10:23:08 +08:00
|
|
|
log_stream_sp = m_log_callback_stream_sp;
|
|
|
|
// For now when using the callback mode you always get thread & timestamp.
|
|
|
|
log_options |=
|
|
|
|
LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
|
2017-03-01 18:08:40 +08:00
|
|
|
} else if (log_file.empty()) {
|
2017-02-10 19:49:21 +08:00
|
|
|
log_stream_sp = std::make_shared<llvm::raw_fd_ostream>(
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
GetOutputFile().GetDescriptor(), !should_close, unbuffered);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2017-02-10 19:49:21 +08:00
|
|
|
auto pos = m_log_streams.find(log_file);
|
2013-01-08 08:01:36 +08:00
|
|
|
if (pos != m_log_streams.end())
|
|
|
|
log_stream_sp = pos->second.lock();
|
|
|
|
if (!log_stream_sp) {
|
2020-06-11 09:12:59 +08:00
|
|
|
File::OpenOptions flags =
|
2021-07-29 02:07:03 +08:00
|
|
|
File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate;
|
2017-02-10 19:49:21 +08:00
|
|
|
if (log_options & LLDB_LOG_OPTION_APPEND)
|
2020-06-11 09:12:59 +08:00
|
|
|
flags |= File::eOpenOptionAppend;
|
|
|
|
else
|
|
|
|
flags |= File::eOpenOptionTruncate;
|
2020-08-17 16:30:23 +08:00
|
|
|
llvm::Expected<FileUP> file = FileSystem::Instance().Open(
|
2020-06-11 09:12:59 +08:00
|
|
|
FileSpec(log_file), flags, lldb::eFilePermissionsFileDefault, false);
|
|
|
|
if (!file) {
|
2020-08-17 16:30:23 +08:00
|
|
|
error_stream << "Unable to open log file '" << log_file
|
|
|
|
<< "': " << llvm::toString(file.takeError()) << "\n";
|
2017-02-10 19:49:21 +08:00
|
|
|
return false;
|
|
|
|
}
|
2020-06-11 09:12:59 +08:00
|
|
|
|
|
|
|
log_stream_sp = std::make_shared<llvm::raw_fd_ostream>(
|
|
|
|
(*file)->GetDescriptor(), should_close, unbuffered);
|
2012-02-21 10:23:08 +08:00
|
|
|
m_log_streams[log_file] = log_stream_sp;
|
2014-10-11 07:07:36 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-03-02 10:18:18 +08:00
|
|
|
assert(log_stream_sp);
|
2013-05-24 04:47:45 +08:00
|
|
|
|
2012-02-21 10:23:08 +08:00
|
|
|
if (log_options == 0)
|
2012-02-23 06:49:20 +08:00
|
|
|
log_options =
|
2012-02-21 10:23:08 +08:00
|
|
|
LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
|
|
|
|
|
|
|
|
return Log::EnableLogChannel(log_stream_sp, log_options, channel, categories,
|
2015-05-27 21:34:04 +08:00
|
|
|
error_stream);
|
2012-02-21 10:23:08 +08:00
|
|
|
}
|
|
|
|
|
2019-12-22 09:11:12 +08:00
|
|
|
ScriptInterpreter *
|
|
|
|
Debugger::GetScriptInterpreter(bool can_create,
|
|
|
|
llvm::Optional<lldb::ScriptLanguage> language) {
|
2019-04-27 06:43:16 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> locker(m_script_interpreter_mutex);
|
2019-12-22 09:11:12 +08:00
|
|
|
lldb::ScriptLanguage script_language =
|
|
|
|
language ? *language : GetScriptLanguage();
|
2019-04-27 06:43:16 +08:00
|
|
|
|
2019-12-22 09:11:12 +08:00
|
|
|
if (!m_script_interpreters[script_language]) {
|
2019-04-27 06:43:16 +08:00
|
|
|
if (!can_create)
|
|
|
|
return nullptr;
|
2019-12-22 09:11:12 +08:00
|
|
|
m_script_interpreters[script_language] =
|
|
|
|
PluginManager::GetScriptInterpreterForLanguage(script_language, *this);
|
2019-04-27 06:43:16 +08:00
|
|
|
}
|
|
|
|
|
2019-12-22 09:11:12 +08:00
|
|
|
return m_script_interpreters[script_language].get();
|
2019-04-27 06:43:16 +08:00
|
|
|
}
|
|
|
|
|
2013-03-19 08:20:55 +08:00
|
|
|
SourceManager &Debugger::GetSourceManager() {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (!m_source_manager_up)
|
2019-08-15 06:19:23 +08:00
|
|
|
m_source_manager_up = std::make_unique<SourceManager>(shared_from_this());
|
2019-02-13 14:25:41 +08:00
|
|
|
return *m_source_manager_up;
|
2013-03-19 08:20:55 +08:00
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
// This function handles events that were broadcast by the process.
|
|
|
|
void Debugger::HandleBreakpointEvent(const EventSP &event_sp) {
|
|
|
|
using namespace lldb;
|
|
|
|
const uint32_t event_type =
|
|
|
|
Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent(
|
|
|
|
event_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
// if (event_type & eBreakpointEventTypeAdded
|
|
|
|
// || event_type & eBreakpointEventTypeRemoved
|
|
|
|
// || event_type & eBreakpointEventTypeEnabled
|
|
|
|
// || event_type & eBreakpointEventTypeDisabled
|
|
|
|
// || event_type & eBreakpointEventTypeCommandChanged
|
|
|
|
// || event_type & eBreakpointEventTypeConditionChanged
|
|
|
|
// || event_type & eBreakpointEventTypeIgnoreChanged
|
|
|
|
// || event_type & eBreakpointEventTypeLocationsResolved)
|
|
|
|
// {
|
|
|
|
// // Don't do anything about these events, since the breakpoint
|
|
|
|
// commands already echo these actions.
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
if (event_type & eBreakpointEventTypeLocationsAdded) {
|
|
|
|
uint32_t num_new_locations =
|
|
|
|
Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(
|
|
|
|
event_sp);
|
|
|
|
if (num_new_locations > 0) {
|
|
|
|
BreakpointSP breakpoint =
|
|
|
|
Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp);
|
2015-05-27 20:40:32 +08:00
|
|
|
StreamSP output_sp(GetAsyncOutputStream());
|
2014-01-28 07:43:24 +08:00
|
|
|
if (output_sp) {
|
|
|
|
output_sp->Printf("%d location%s added to breakpoint %d\n",
|
|
|
|
num_new_locations, num_new_locations == 1 ? "" : "s",
|
|
|
|
breakpoint->GetID());
|
2015-05-27 20:40:32 +08:00
|
|
|
output_sp->Flush();
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
// else if (event_type & eBreakpointEventTypeLocationsRemoved)
|
|
|
|
// {
|
|
|
|
// // These locations just get disabled, not sure it is worth spamming
|
|
|
|
// folks about this on the command line.
|
|
|
|
// }
|
|
|
|
// else if (event_type & eBreakpointEventTypeLocationsResolved)
|
|
|
|
// {
|
|
|
|
// // This might be an interesting thing to note, but I'm going to
|
|
|
|
// leave it quiet for now, it just looked noisy.
|
|
|
|
// }
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-07-31 20:06:50 +08:00
|
|
|
void Debugger::FlushProcessOutput(Process &process, bool flush_stdout,
|
|
|
|
bool flush_stderr) {
|
|
|
|
const auto &flush = [&](Stream &stream,
|
|
|
|
size_t (Process::*get)(char *, size_t, Status &)) {
|
|
|
|
Status error;
|
|
|
|
size_t len;
|
|
|
|
char buffer[1024];
|
|
|
|
while ((len = (process.*get)(buffer, sizeof(buffer), error)) > 0)
|
|
|
|
stream.Write(buffer, len);
|
|
|
|
stream.Flush();
|
|
|
|
};
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> guard(m_output_flush_mutex);
|
|
|
|
if (flush_stdout)
|
|
|
|
flush(*GetAsyncOutputStream(), &Process::GetSTDOUT);
|
|
|
|
if (flush_stderr)
|
|
|
|
flush(*GetAsyncErrorStream(), &Process::GetSTDERR);
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// This function handles events that were broadcast by the process.
|
|
|
|
void Debugger::HandleProcessEvent(const EventSP &event_sp) {
|
|
|
|
using namespace lldb;
|
|
|
|
const uint32_t event_type = event_sp->GetType();
|
2016-08-19 12:21:48 +08:00
|
|
|
ProcessSP process_sp =
|
|
|
|
(event_type == Process::eBroadcastBitStructuredData)
|
|
|
|
? EventDataStructuredData::GetProcessFromEvent(event_sp.get())
|
|
|
|
: Process::ProcessEventData::GetProcessFromEvent(event_sp.get());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-27 20:40:32 +08:00
|
|
|
StreamSP output_stream_sp = GetAsyncOutputStream();
|
|
|
|
StreamSP error_stream_sp = GetAsyncErrorStream();
|
2014-01-28 07:43:24 +08:00
|
|
|
const bool gui_enabled = IsForwardingEvents();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-03-01 02:22:24 +08:00
|
|
|
if (!gui_enabled) {
|
|
|
|
bool pop_process_io_handler = false;
|
|
|
|
assert(process_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-27 20:40:32 +08:00
|
|
|
bool state_is_stopped = false;
|
|
|
|
const bool got_state_changed =
|
|
|
|
(event_type & Process::eBroadcastBitStateChanged) != 0;
|
|
|
|
const bool got_stdout = (event_type & Process::eBroadcastBitSTDOUT) != 0;
|
|
|
|
const bool got_stderr = (event_type & Process::eBroadcastBitSTDERR) != 0;
|
2016-08-19 12:21:48 +08:00
|
|
|
const bool got_structured_data =
|
|
|
|
(event_type & Process::eBroadcastBitStructuredData) != 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-27 20:40:32 +08:00
|
|
|
if (got_state_changed) {
|
|
|
|
StateType event_state =
|
|
|
|
Process::ProcessEventData::GetStateFromEvent(event_sp.get());
|
|
|
|
state_is_stopped = StateIsStoppedState(event_state, false);
|
2014-03-01 02:22:24 +08:00
|
|
|
}
|
2014-10-21 09:00:42 +08:00
|
|
|
|
2015-05-27 20:40:32 +08:00
|
|
|
// Display running state changes first before any STDIO
|
|
|
|
if (got_state_changed && !state_is_stopped) {
|
|
|
|
Process::HandleProcessStateChangedEvent(event_sp, output_stream_sp.get(),
|
|
|
|
pop_process_io_handler);
|
2014-03-01 02:22:24 +08:00
|
|
|
}
|
2014-10-21 09:00:42 +08:00
|
|
|
|
2019-07-31 20:06:50 +08:00
|
|
|
// Now display STDOUT and STDERR
|
|
|
|
FlushProcessOutput(*process_sp, got_stdout || got_state_changed,
|
|
|
|
got_stderr || got_state_changed);
|
2014-03-01 02:22:24 +08:00
|
|
|
|
2016-08-19 12:21:48 +08:00
|
|
|
// Give structured data events an opportunity to display.
|
|
|
|
if (got_structured_data) {
|
|
|
|
StructuredDataPluginSP plugin_sp =
|
|
|
|
EventDataStructuredData::GetPluginFromEvent(event_sp.get());
|
|
|
|
if (plugin_sp) {
|
|
|
|
auto structured_data_sp =
|
|
|
|
EventDataStructuredData::GetObjectFromEvent(event_sp.get());
|
|
|
|
if (output_stream_sp) {
|
|
|
|
StreamString content_stream;
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error =
|
2016-08-19 12:21:48 +08:00
|
|
|
plugin_sp->GetDescription(structured_data_sp, content_stream);
|
|
|
|
if (error.Success()) {
|
|
|
|
if (!content_stream.GetString().empty()) {
|
|
|
|
// Add newline.
|
|
|
|
content_stream.PutChar('\n');
|
|
|
|
content_stream.Flush();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-08-19 12:21:48 +08:00
|
|
|
// Print it.
|
2016-11-03 04:34:10 +08:00
|
|
|
output_stream_sp->PutCString(content_stream.GetString());
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2021-10-15 19:07:39 +08:00
|
|
|
error_stream_sp->Format("Failed to print structured "
|
|
|
|
"data with plugin {0}: {1}",
|
|
|
|
plugin_sp->GetPluginName(), error);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
2014-03-01 02:22:24 +08:00
|
|
|
}
|
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
|
|
|
|
// Now display any stopped state changes after any STDIO
|
|
|
|
if (got_state_changed && state_is_stopped) {
|
|
|
|
Process::HandleProcessStateChangedEvent(event_sp, output_stream_sp.get(),
|
2015-05-27 20:40:32 +08:00
|
|
|
pop_process_io_handler);
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
output_stream_sp->Flush();
|
|
|
|
error_stream_sp->Flush();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
if (pop_process_io_handler)
|
2014-03-01 02:22:24 +08:00
|
|
|
process_sp->PopProcessIOHandler();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
void Debugger::HandleThreadEvent(const EventSP &event_sp) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// At present the only thread event we handle is the Frame Changed event, and
|
|
|
|
// all we do for that is just reprint the thread status for that thread.
|
2014-01-28 07:43:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
const uint32_t event_type = event_sp->GetType();
|
2016-11-09 04:36:40 +08:00
|
|
|
const bool stop_format = true;
|
2014-01-28 07:43:24 +08:00
|
|
|
if (event_type == Thread::eBroadcastBitStackChanged ||
|
|
|
|
event_type == Thread::eBroadcastBitThreadSelected) {
|
|
|
|
ThreadSP thread_sp(
|
|
|
|
Thread::ThreadEventData::GetThreadFromEvent(event_sp.get()));
|
|
|
|
if (thread_sp) {
|
2016-11-09 04:36:40 +08:00
|
|
|
thread_sp->GetStatus(*GetAsyncOutputStream(), 0, 1, 1, stop_format);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 05:50:25 +08:00
|
|
|
bool Debugger::IsForwardingEvents() { return (bool)m_forward_listener_sp; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-08 05:50:25 +08:00
|
|
|
void Debugger::EnableForwardEvents(const ListenerSP &listener_sp) {
|
2014-01-28 07:43:24 +08:00
|
|
|
m_forward_listener_sp = listener_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-03-08 05:50:25 +08:00
|
|
|
void Debugger::CancelForwardEvents(const ListenerSP &listener_sp) {
|
2014-01-28 07:43:24 +08:00
|
|
|
m_forward_listener_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
void Debugger::DefaultEventHandler() {
|
2016-03-08 05:50:25 +08:00
|
|
|
ListenerSP listener_sp(GetListener());
|
|
|
|
ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
|
|
|
|
ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
|
|
|
|
ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
|
|
|
|
BroadcastEventSpec target_event_spec(broadcaster_class_target,
|
2014-01-28 07:43:24 +08:00
|
|
|
Target::eBroadcastBitBreakpointChanged);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-12-02 06:41:27 +08:00
|
|
|
BroadcastEventSpec process_event_spec(
|
2014-01-28 07:43:24 +08:00
|
|
|
broadcaster_class_process,
|
2014-12-02 06:41:27 +08:00
|
|
|
Process::eBroadcastBitStateChanged | Process::eBroadcastBitSTDOUT |
|
|
|
|
Process::eBroadcastBitSTDERR | Process::eBroadcastBitStructuredData);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-12-02 06:41:27 +08:00
|
|
|
BroadcastEventSpec thread_event_spec(broadcaster_class_thread,
|
2016-07-29 01:32:20 +08:00
|
|
|
Thread::eBroadcastBitStackChanged |
|
|
|
|
Thread::eBroadcastBitThreadSelected);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-29 01:32:20 +08:00
|
|
|
listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
|
2014-01-28 07:43:24 +08:00
|
|
|
target_event_spec);
|
|
|
|
listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
|
|
|
|
process_event_spec);
|
|
|
|
listener_sp->StartListeningForEventSpec(m_broadcaster_manager_sp,
|
|
|
|
thread_event_spec);
|
|
|
|
listener_sp->StartListeningForEvents(
|
2019-02-13 14:25:41 +08:00
|
|
|
m_command_interpreter_up.get(),
|
2014-01-28 07:43:24 +08:00
|
|
|
CommandInterpreter::eBroadcastBitQuitCommandReceived |
|
|
|
|
CommandInterpreter::eBroadcastBitAsynchronousOutputData |
|
|
|
|
CommandInterpreter::eBroadcastBitAsynchronousErrorData);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Let the thread that spawned us know that we have started up and that we
|
|
|
|
// are now listening to all required events so no events get missed
|
2014-01-28 07:43:24 +08:00
|
|
|
m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
bool done = false;
|
|
|
|
while (!done) {
|
|
|
|
EventSP event_sp;
|
2016-11-30 18:41:42 +08:00
|
|
|
if (listener_sp->GetEvent(event_sp, llvm::None)) {
|
2014-01-28 07:43:24 +08:00
|
|
|
if (event_sp) {
|
|
|
|
Broadcaster *broadcaster = event_sp->GetBroadcaster();
|
|
|
|
if (broadcaster) {
|
|
|
|
uint32_t event_type = event_sp->GetType();
|
|
|
|
ConstString broadcaster_class(broadcaster->GetBroadcasterClass());
|
|
|
|
if (broadcaster_class == broadcaster_class_process) {
|
|
|
|
HandleProcessEvent(event_sp);
|
|
|
|
} else if (broadcaster_class == broadcaster_class_target) {
|
|
|
|
if (Breakpoint::BreakpointEventData::GetEventDataFromEvent(
|
|
|
|
event_sp.get())) {
|
|
|
|
HandleBreakpointEvent(event_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
} else if (broadcaster_class == broadcaster_class_thread) {
|
2015-05-27 20:40:32 +08:00
|
|
|
HandleThreadEvent(event_sp);
|
2019-02-13 14:25:41 +08:00
|
|
|
} else if (broadcaster == m_command_interpreter_up.get()) {
|
2014-01-28 07:43:24 +08:00
|
|
|
if (event_type &
|
|
|
|
CommandInterpreter::eBroadcastBitQuitCommandReceived) {
|
|
|
|
done = true;
|
|
|
|
} else if (event_type &
|
|
|
|
CommandInterpreter::eBroadcastBitAsynchronousErrorData) {
|
2020-01-07 19:13:03 +08:00
|
|
|
const char *data = static_cast<const char *>(
|
2014-01-28 07:43:24 +08:00
|
|
|
EventDataBytes::GetBytesFromEvent(event_sp.get()));
|
|
|
|
if (data && data[0]) {
|
2015-05-27 20:40:32 +08:00
|
|
|
StreamSP error_sp(GetAsyncErrorStream());
|
2014-01-28 07:43:24 +08:00
|
|
|
if (error_sp) {
|
|
|
|
error_sp->PutCString(data);
|
|
|
|
error_sp->Flush();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
} else if (event_type & CommandInterpreter::
|
|
|
|
eBroadcastBitAsynchronousOutputData) {
|
2020-01-07 19:13:03 +08:00
|
|
|
const char *data = static_cast<const char *>(
|
2014-01-28 07:43:24 +08:00
|
|
|
EventDataBytes::GetBytesFromEvent(event_sp.get()));
|
|
|
|
if (data && data[0]) {
|
2015-05-27 20:40:32 +08:00
|
|
|
StreamSP output_sp(GetAsyncOutputStream());
|
2014-01-28 07:43:24 +08:00
|
|
|
if (output_sp) {
|
|
|
|
output_sp->PutCString(data);
|
2015-05-27 20:40:32 +08:00
|
|
|
output_sp->Flush();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
|
|
|
|
2014-09-24 02:32:09 +08:00
|
|
|
if (m_forward_listener_sp)
|
2016-03-08 05:50:25 +08:00
|
|
|
m_forward_listener_sp->AddEvent(event_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-10-16 02:03:59 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
lldb::thread_result_t Debugger::EventHandlerThread(lldb::thread_arg_t arg) {
|
|
|
|
((Debugger *)arg)->DefaultEventHandler();
|
[lldb] fix cannot convert from 'nullptr' to 'lldb::thread_result_t'
Summary:
On Windows `lldb::thread_result_t` resolves to `typedef unsigned thread_result_t;` and on other platforms it resolves to `typedef void *thread_result_t;`.
Therefore one cannot use `nullptr` when returning from a function that returns `thread_result_t`.
I've made this change because a windows build bot fails with these errors:
```
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Communication.cpp(362): error C2440: 'return': cannot convert from 'nullptr' to 'lldb::thread_result_t'
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Communication.cpp(362): note: A native nullptr can only be converted to bool or, using reinterpret_cast, to an integral type
```
and
```
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Debugger.cpp(1619): error C2440: 'return': cannot convert from 'nullptr' to 'lldb::thread_result_t'
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Debugger.cpp(1619): note: A native nullptr can only be converted to bool or, using reinterpret_cast, to an integral type
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Debugger.cpp(1664): error C2440: 'return': cannot convert from 'nullptr' to 'lldb::thread_result_t'
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Debugger.cpp(1664): note: A native nullptr can only be converted to bool or, using reinterpret_cast, to an integral type
```
This is the failing build: http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/5035/steps/build/logs/stdio
Reviewers: JDevlieghere, teemperor, jankratochvil, labath, clayborg, RKSimon, courbet, jhenderson
Reviewed By: labath, clayborg
Subscribers: labath, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D62305
llvm-svn: 361503
2019-05-23 23:17:39 +08:00
|
|
|
return {};
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
bool Debugger::StartEventHandlerThread() {
|
2014-09-24 02:32:09 +08:00
|
|
|
if (!m_event_handler_thread.IsJoinable()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// We must synchronize with the DefaultEventHandler() thread to ensure it
|
|
|
|
// is up and running and listening to events before we return from this
|
|
|
|
// function. We do this by listening to events for the
|
2014-12-02 06:41:27 +08:00
|
|
|
// eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
|
2018-07-13 19:21:06 +08:00
|
|
|
ConstString full_name("lldb.debugger.event-handler");
|
|
|
|
ListenerSP listener_sp(Listener::MakeListener(full_name.AsCString()));
|
2016-03-08 05:50:25 +08:00
|
|
|
listener_sp->StartListeningForEvents(&m_sync_broadcaster,
|
2014-12-02 06:41:27 +08:00
|
|
|
eBroadcastBitEventThreadIsListening);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-02-11 16:05:37 +08:00
|
|
|
llvm::StringRef thread_name =
|
2019-08-02 08:18:44 +08:00
|
|
|
full_name.GetLength() < llvm::get_max_thread_name_length()
|
2020-02-11 16:05:37 +08:00
|
|
|
? full_name.GetStringRef()
|
2019-08-02 08:18:44 +08:00
|
|
|
: "dbg.evt-handler";
|
2018-07-13 19:21:06 +08:00
|
|
|
|
2014-10-25 06:06:29 +08:00
|
|
|
// Use larger 8MB stack for this thread
|
2019-07-06 01:42:08 +08:00
|
|
|
llvm::Expected<HostThread> event_handler_thread =
|
|
|
|
ThreadLauncher::LaunchThread(thread_name, EventHandlerThread, this,
|
|
|
|
g_debugger_event_thread_stack_bytes);
|
|
|
|
|
|
|
|
if (event_handler_thread) {
|
|
|
|
m_event_handler_thread = *event_handler_thread;
|
|
|
|
} else {
|
|
|
|
LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST),
|
|
|
|
"failed to launch host thread: {}",
|
|
|
|
llvm::toString(event_handler_thread.takeError()));
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Make sure DefaultEventHandler() is running and listening to events
|
|
|
|
// before we return from this function. We are only listening for events of
|
|
|
|
// type eBroadcastBitEventThreadIsListening so we don't need to check the
|
|
|
|
// event, we just need to wait an infinite amount of time for it (nullptr
|
|
|
|
// timeout as the first parameter)
|
2014-12-02 06:41:27 +08:00
|
|
|
lldb::EventSP event_sp;
|
2016-11-30 18:41:42 +08:00
|
|
|
listener_sp->GetEvent(event_sp, llvm::None);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-09-24 02:32:09 +08:00
|
|
|
return m_event_handler_thread.IsJoinable();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
void Debugger::StopEventHandlerThread() {
|
2014-09-24 02:32:09 +08:00
|
|
|
if (m_event_handler_thread.IsJoinable()) {
|
2014-01-28 07:43:24 +08:00
|
|
|
GetCommandInterpreter().BroadcastEvent(
|
|
|
|
CommandInterpreter::eBroadcastBitQuitCommandReceived);
|
2014-09-10 04:54:56 +08:00
|
|
|
m_event_handler_thread.Join(nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
lldb::thread_result_t Debugger::IOHandlerThread(lldb::thread_arg_t arg) {
|
|
|
|
Debugger *debugger = (Debugger *)arg;
|
2020-01-17 08:45:18 +08:00
|
|
|
debugger->RunIOHandlers();
|
2014-01-28 07:43:24 +08:00
|
|
|
debugger->StopEventHandlerThread();
|
[lldb] fix cannot convert from 'nullptr' to 'lldb::thread_result_t'
Summary:
On Windows `lldb::thread_result_t` resolves to `typedef unsigned thread_result_t;` and on other platforms it resolves to `typedef void *thread_result_t;`.
Therefore one cannot use `nullptr` when returning from a function that returns `thread_result_t`.
I've made this change because a windows build bot fails with these errors:
```
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Communication.cpp(362): error C2440: 'return': cannot convert from 'nullptr' to 'lldb::thread_result_t'
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Communication.cpp(362): note: A native nullptr can only be converted to bool or, using reinterpret_cast, to an integral type
```
and
```
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Debugger.cpp(1619): error C2440: 'return': cannot convert from 'nullptr' to 'lldb::thread_result_t'
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Debugger.cpp(1619): note: A native nullptr can only be converted to bool or, using reinterpret_cast, to an integral type
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Debugger.cpp(1664): error C2440: 'return': cannot convert from 'nullptr' to 'lldb::thread_result_t'
E:\build_slave\lldb-x64-windows-ninja\llvm\tools\lldb\source\Core\Debugger.cpp(1664): note: A native nullptr can only be converted to bool or, using reinterpret_cast, to an integral type
```
This is the failing build: http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/5035/steps/build/logs/stdio
Reviewers: JDevlieghere, teemperor, jankratochvil, labath, clayborg, RKSimon, courbet, jhenderson
Reviewed By: labath, clayborg
Subscribers: labath, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D62305
llvm-svn: 361503
2019-05-23 23:17:39 +08:00
|
|
|
return {};
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-03-02 10:18:18 +08:00
|
|
|
bool Debugger::HasIOHandlerThread() { return m_io_handler_thread.IsJoinable(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
bool Debugger::StartIOHandlerThread() {
|
2019-07-06 01:42:08 +08:00
|
|
|
if (!m_io_handler_thread.IsJoinable()) {
|
|
|
|
llvm::Expected<HostThread> io_handler_thread = ThreadLauncher::LaunchThread(
|
|
|
|
"lldb.debugger.io-handler", IOHandlerThread, this,
|
2016-03-02 10:18:18 +08:00
|
|
|
8 * 1024 * 1024); // Use larger 8MB stack for this thread
|
2019-07-06 01:42:08 +08:00
|
|
|
if (io_handler_thread) {
|
|
|
|
m_io_handler_thread = *io_handler_thread;
|
|
|
|
} else {
|
|
|
|
LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST),
|
|
|
|
"failed to launch host thread: {}",
|
|
|
|
llvm::toString(io_handler_thread.takeError()));
|
|
|
|
}
|
|
|
|
}
|
2015-10-20 07:11:07 +08:00
|
|
|
return m_io_handler_thread.IsJoinable();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
void Debugger::StopIOHandlerThread() {
|
2014-09-24 02:32:09 +08:00
|
|
|
if (m_io_handler_thread.IsJoinable()) {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
GetInputFile().Close();
|
2014-09-10 04:54:56 +08:00
|
|
|
m_io_handler_thread.Join(nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger::JoinIOHandlerThread() {
|
2014-09-24 02:32:09 +08:00
|
|
|
if (HasIOHandlerThread()) {
|
2014-01-28 07:43:24 +08:00
|
|
|
thread_result_t result;
|
2014-09-10 04:54:56 +08:00
|
|
|
m_io_handler_thread.Join(&result);
|
|
|
|
m_io_handler_thread = LLDB_INVALID_HOST_THREAD;
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-10 07:25:59 +08:00
|
|
|
Target &Debugger::GetSelectedOrDummyTarget(bool prefer_dummy) {
|
2015-10-20 07:11:07 +08:00
|
|
|
if (!prefer_dummy) {
|
2020-11-10 07:25:59 +08:00
|
|
|
if (TargetSP target = m_target_list.GetSelectedTarget())
|
|
|
|
return *target;
|
2015-10-20 07:11:07 +08:00
|
|
|
}
|
2014-09-24 02:32:09 +08:00
|
|
|
return GetDummyTarget();
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Debugger::RunREPL(LanguageType language, const char *repl_options) {
|
|
|
|
Status err;
|
2014-01-28 07:43:24 +08:00
|
|
|
FileSpec repl_executable;
|
|
|
|
|
2015-10-20 07:11:07 +08:00
|
|
|
if (language == eLanguageTypeUnknown) {
|
2019-08-23 05:45:58 +08:00
|
|
|
LanguageSet repl_languages = Language::GetLanguagesSupportingREPLs();
|
2015-10-20 07:11:07 +08:00
|
|
|
|
2019-08-23 05:45:58 +08:00
|
|
|
if (auto single_lang = repl_languages.GetSingularLanguage()) {
|
|
|
|
language = *single_lang;
|
|
|
|
} else if (repl_languages.Empty()) {
|
2014-12-06 09:28:03 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"LLDB isn't configured with REPL support for any languages.");
|
|
|
|
return err;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2014-12-06 09:28:03 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"Multiple possible REPL languages. Please specify a language.");
|
|
|
|
return err;
|
|
|
|
}
|
2014-11-22 09:42:44 +08:00
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
|
2015-10-20 08:23:46 +08:00
|
|
|
Target *const target =
|
2015-10-22 03:31:17 +08:00
|
|
|
nullptr; // passing in an empty target means the REPL must create one
|
|
|
|
|
2015-10-21 08:28:44 +08:00
|
|
|
REPLSP repl_sp(REPL::Create(err, language, this, target, repl_options));
|
2015-10-20 08:23:46 +08:00
|
|
|
|
|
|
|
if (!err.Success()) {
|
|
|
|
return err;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-20 08:23:46 +08:00
|
|
|
if (!repl_sp) {
|
|
|
|
err.SetErrorStringWithFormat("couldn't find a REPL for %s",
|
|
|
|
Language::GetNameForLanguageType(language));
|
|
|
|
return err;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-10-20 08:23:46 +08:00
|
|
|
repl_sp->SetCompilerOptions(repl_options);
|
|
|
|
repl_sp->RunLoop();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-22 03:31:17 +08:00
|
|
|
return err;
|
2015-10-20 08:23:46 +08:00
|
|
|
}
|