Skip to content

🍒/austria/bfab18d86b27+5a27b99825a5+097d46f41c46+116715270d07+43374bee0e06+e618eb8727b0 #4043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12 changes: 12 additions & 0 deletions lldb/include/lldb/Core/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ class Debugger : public std::enable_shared_from_this<Debugger>,

bool SetUseColor(bool use_color);

bool GetShowProgress() const;

llvm::StringRef GetShowProgressAnsiPrefix() const;

llvm::StringRef GetShowProgressAnsiSuffix() const;

bool GetUseAutosuggestion() const;

llvm::StringRef GetAutosuggestionAnsiPrefix() const;
Expand Down Expand Up @@ -448,6 +454,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
uint64_t completed, uint64_t total,
llvm::Optional<lldb::user_id_t> debugger_id);

void PrintProgress(const Debugger::ProgressEventData &data);

bool StartEventHandlerThread();

void StopEventHandlerThread();
Expand Down Expand Up @@ -477,6 +485,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,

void HandleThreadEvent(const lldb::EventSP &event_sp);

void HandleProgressEvent(const lldb::EventSP &event_sp);

// Ensures two threads don't attempt to flush process output in parallel.
std::mutex m_output_flush_mutex;
void FlushProcessOutput(Process &process, bool flush_stdout,
Expand Down Expand Up @@ -525,6 +535,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
IOHandlerStack m_io_handler_stack;
std::recursive_mutex m_io_handler_synchronous_mutex;

llvm::Optional<uint64_t> m_current_event_id;

llvm::StringMap<std::weak_ptr<llvm::raw_ostream>> m_log_streams;
std::shared_ptr<llvm::raw_ostream> m_log_callback_stream_sp;
ConstString m_instance_name;
Expand Down
3 changes: 2 additions & 1 deletion lldb/include/lldb/Host/windows/windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
#undef NOMINMAX // undef a previous definition to avoid warning
#define NOMINMAX
#include <windows.h>
#undef CreateProcess
#undef GetMessage
#undef GetUserName
#undef LoadImage
#undef CreateProcess
#undef Yield
#undef far
#undef near
Expand Down
24 changes: 18 additions & 6 deletions lldb/source/Core/CoreProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ let Definition = "debugger" in {
def StopShowColumnAnsiPrefix: Property<"stop-show-column-ansi-prefix", "String">,
Global,
DefaultStringValue<"${ansi.underline}">,
Desc<"When displaying the column marker in a color-enabled (i.e. ANSI) terminal, use the ANSI terminal code specified in this format at the immediately before the column to be marked.">;
Desc<"When displaying the column marker in a color-enabled terminal, use the ANSI terminal code specified in this format at the immediately before the column to be marked.">;
def StopShowColumnAnsiSuffix: Property<"stop-show-column-ansi-suffix", "String">,
Global,
DefaultStringValue<"${ansi.normal}">,
Desc<"When displaying the column marker in a color-enabled (i.e. ANSI) terminal, use the ANSI terminal code specified in this format immediately after the column to be marked.">;
Desc<"When displaying the column marker in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the column to be marked.">;
def StopShowLineMarkerAnsiPrefix: Property<"stop-show-line-ansi-prefix", "String">,
Global,
DefaultStringValue<"${ansi.fg.yellow}">,
Desc<"When displaying the line marker in a color-enabled (i.e. ANSI) terminal, use the ANSI terminal code specified in this format at the immediately before the line to be marked.">;
Desc<"When displaying the line marker in a color-enabled terminal, use the ANSI terminal code specified in this format at the immediately before the line to be marked.">;
def StopShowLineMarkerAnsiSuffix: Property<"stop-show-line-ansi-suffix", "String">,
Global,
DefaultStringValue<"${ansi.normal}">,
Desc<"When displaying the line marker in a color-enabled (i.e. ANSI) terminal, use the ANSI terminal code specified in this format immediately after the line to be marked.">;
Desc<"When displaying the line marker in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the line to be marked.">;
def TerminalWidth: Property<"term-width", "SInt64">,
Global,
DefaultUnsignedValue<80>,
Expand All @@ -129,6 +129,18 @@ let Definition = "debugger" in {
Global,
DefaultTrue,
Desc<"Whether to use Ansi color codes or not.">;
def ShowProgress: Property<"show-progress", "Boolean">,
Global,
DefaultTrue,
Desc<"Whether to show progress or not if the debugger's output is an interactive color-enabled terminal.">;
def ShowProgressAnsiPrefix: Property<"show-progress-ansi-prefix", "String">,
Global,
DefaultStringValue<"${ansi.faint}">,
Desc<"When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately before the progress message.">;
def ShowProgressAnsiSuffix: Property<"show-progress-ansi-suffix", "String">,
Global,
DefaultStringValue<"${ansi.normal}">,
Desc<"When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the progress message.">;
def UseSourceCache: Property<"use-source-cache", "Boolean">,
Global,
DefaultTrue,
Expand Down Expand Up @@ -164,9 +176,9 @@ let Definition = "debugger" in {
def ShowAutosuggestionAnsiPrefix: Property<"show-autosuggestion-ansi-prefix", "String">,
Global,
DefaultStringValue<"${ansi.faint}">,
Desc<"When displaying suggestion in a color-enabled (i.e. ANSI) terminal, use the ANSI terminal code specified in this format immediately before the suggestion.">;
Desc<"When displaying suggestion in a color-enabled terminal, use the ANSI terminal code specified in this format immediately before the suggestion.">;
def ShowAutosuggestionAnsiSuffix: Property<"show-autosuggestion-ansi-suffix", "String">,
Global,
DefaultStringValue<"${ansi.normal}">,
Desc<"When displaying suggestion in a color-enabled (i.e. ANSI) terminal, use the ANSI terminal code specified in this format immediately after the suggestion.">;
Desc<"When displaying suggestion in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the suggestion.">;
}
89 changes: 89 additions & 0 deletions lldb/source/Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,22 @@ bool Debugger::SetUseColor(bool b) {
return ret;
}

bool Debugger::GetShowProgress() const {
const uint32_t idx = ePropertyShowProgress;
return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
}

llvm::StringRef Debugger::GetShowProgressAnsiPrefix() const {
const uint32_t idx = ePropertyShowProgressAnsiPrefix;
return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
}

llvm::StringRef Debugger::GetShowProgressAnsiSuffix() const {
const uint32_t idx = ePropertyShowProgressAnsiSuffix;
return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
}

bool Debugger::GetUseAutosuggestion() const {
const uint32_t idx = ePropertyShowAutosuggestion;
return m_collection_sp->GetPropertyAtIndexAsBoolean(
Expand Down Expand Up @@ -1667,6 +1683,9 @@ void Debugger::DefaultEventHandler() {
CommandInterpreter::eBroadcastBitAsynchronousOutputData |
CommandInterpreter::eBroadcastBitAsynchronousErrorData);

listener_sp->StartListeningForEvents(&m_broadcaster,
Debugger::eBroadcastBitProgress);

// 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
m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening);
Expand Down Expand Up @@ -1716,6 +1735,9 @@ void Debugger::DefaultEventHandler() {
}
}
}
} else if (broadcaster == &m_broadcaster) {
if (event_type & Debugger::eBroadcastBitProgress)
HandleProgressEvent(event_sp);
}
}

Expand Down Expand Up @@ -1785,6 +1807,73 @@ lldb::thread_result_t Debugger::IOHandlerThread(lldb::thread_arg_t arg) {
return {};
}

void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
auto *data =
Debugger::ProgressEventData::GetEventDataFromEvent(event_sp.get());
if (!data)
return;

// Do some bookkeeping for the current event, regardless of whether we're
// going to show the progress.
const uint64_t id = data->GetID();
if (m_current_event_id) {
if (id != *m_current_event_id)
return;
if (data->GetCompleted())
m_current_event_id.reset();
} else {
m_current_event_id = id;
}

// Decide whether we actually are going to show the progress. This decision
// can change between iterations so check it inside the loop.
if (!GetShowProgress())
return;

// Determine whether the current output file is an interactive terminal with
// color support. We assume that if we support ANSI escape codes we support
// vt100 escape codes.
File &output = GetOutputFile();
if (!output.GetIsInteractive() || !output.GetIsTerminalWithColors())
return;

// Print over previous line, if any.
output.Printf("\r");

if (data->GetCompleted()) {
// Clear the current line.
output.Printf("\x1B[2K");
output.Flush();
return;
}

const bool use_color = GetUseColor();
llvm::StringRef ansi_prefix = GetShowProgressAnsiPrefix();
if (!ansi_prefix.empty())
output.Printf(
"%s", ansi::FormatAnsiTerminalCodes(ansi_prefix, use_color).c_str());

// Print the progress message.
std::string message = data->GetMessage();
if (data->GetTotal() != UINT64_MAX) {
output.Printf("[%" PRIu64 "/%" PRIu64 "] %s...", data->GetCompleted(), data->GetTotal(),
message.c_str());
} else {
output.Printf("%s...", message.c_str());
}

llvm::StringRef ansi_suffix = GetShowProgressAnsiSuffix();
if (!ansi_suffix.empty())
output.Printf(
"%s", ansi::FormatAnsiTerminalCodes(ansi_suffix, use_color).c_str());

// Clear until the end of the line.
output.Printf("\x1B[K\r");

// Flush the output.
output.Flush();
}

bool Debugger::HasIOHandlerThread() { return m_io_handler_thread.IsJoinable(); }

bool Debugger::StartIOHandlerThread() {
Expand Down
5 changes: 5 additions & 0 deletions lldb/source/Symbol/LocateSymbolFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/Progress.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Utility/ArchSpec.h"
Expand Down Expand Up @@ -262,6 +263,10 @@ Symbols::LocateExecutableSymbolFile(const ModuleSpec &module_spec,
FileSystem::Instance().Exists(symbol_file_spec))
return symbol_file_spec;

Progress progress(llvm::formatv(
"Locating external symbol file for {0}",
module_spec.GetFileSpec().GetFilename().AsCString("<Unknown>")));

FileSpecList debug_file_search_paths = default_search_paths;

// Add module directory.
Expand Down