Skip to content

Commit 127e455

Browse files
authored
Merge pull request #4043 from apple/🍒/austria/bfab18d86b27+5a27b99825a5+097d46f41c46+116715270d07+43374bee0e06+e618eb8727b0
🍒/austria/bfab18d86b27+5a27b99825a5+097d46f41c46+116715270d07+43374bee0e06+e618eb8727b0
2 parents b1c3bbf + 91777ab commit 127e455

File tree

5 files changed

+126
-7
lines changed

5 files changed

+126
-7
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
333333

334334
bool SetUseColor(bool use_color);
335335

336+
bool GetShowProgress() const;
337+
338+
llvm::StringRef GetShowProgressAnsiPrefix() const;
339+
340+
llvm::StringRef GetShowProgressAnsiSuffix() const;
341+
336342
bool GetUseAutosuggestion() const;
337343

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

457+
void PrintProgress(const Debugger::ProgressEventData &data);
458+
451459
bool StartEventHandlerThread();
452460

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

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

488+
void HandleProgressEvent(const lldb::EventSP &event_sp);
489+
480490
// Ensures two threads don't attempt to flush process output in parallel.
481491
std::mutex m_output_flush_mutex;
482492
void FlushProcessOutput(Process &process, bool flush_stdout,
@@ -525,6 +535,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
525535
IOHandlerStack m_io_handler_stack;
526536
std::recursive_mutex m_io_handler_synchronous_mutex;
527537

538+
llvm::Optional<uint64_t> m_current_event_id;
539+
528540
llvm::StringMap<std::weak_ptr<llvm::raw_ostream>> m_log_streams;
529541
std::shared_ptr<llvm::raw_ostream> m_log_callback_stream_sp;
530542
ConstString m_instance_name;

lldb/include/lldb/Host/windows/windows.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
#undef NOMINMAX // undef a previous definition to avoid warning
1818
#define NOMINMAX
1919
#include <windows.h>
20+
#undef CreateProcess
21+
#undef GetMessage
2022
#undef GetUserName
2123
#undef LoadImage
22-
#undef CreateProcess
2324
#undef Yield
2425
#undef far
2526
#undef near

lldb/source/Core/CoreProperties.td

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,19 @@ let Definition = "debugger" in {
9696
def StopShowColumnAnsiPrefix: Property<"stop-show-column-ansi-prefix", "String">,
9797
Global,
9898
DefaultStringValue<"${ansi.underline}">,
99-
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.">;
99+
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.">;
100100
def StopShowColumnAnsiSuffix: Property<"stop-show-column-ansi-suffix", "String">,
101101
Global,
102102
DefaultStringValue<"${ansi.normal}">,
103-
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.">;
103+
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.">;
104104
def StopShowLineMarkerAnsiPrefix: Property<"stop-show-line-ansi-prefix", "String">,
105105
Global,
106106
DefaultStringValue<"${ansi.fg.yellow}">,
107-
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.">;
107+
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.">;
108108
def StopShowLineMarkerAnsiSuffix: Property<"stop-show-line-ansi-suffix", "String">,
109109
Global,
110110
DefaultStringValue<"${ansi.normal}">,
111-
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.">;
111+
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.">;
112112
def TerminalWidth: Property<"term-width", "SInt64">,
113113
Global,
114114
DefaultUnsignedValue<80>,
@@ -129,6 +129,18 @@ let Definition = "debugger" in {
129129
Global,
130130
DefaultTrue,
131131
Desc<"Whether to use Ansi color codes or not.">;
132+
def ShowProgress: Property<"show-progress", "Boolean">,
133+
Global,
134+
DefaultTrue,
135+
Desc<"Whether to show progress or not if the debugger's output is an interactive color-enabled terminal.">;
136+
def ShowProgressAnsiPrefix: Property<"show-progress-ansi-prefix", "String">,
137+
Global,
138+
DefaultStringValue<"${ansi.faint}">,
139+
Desc<"When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately before the progress message.">;
140+
def ShowProgressAnsiSuffix: Property<"show-progress-ansi-suffix", "String">,
141+
Global,
142+
DefaultStringValue<"${ansi.normal}">,
143+
Desc<"When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the progress message.">;
132144
def UseSourceCache: Property<"use-source-cache", "Boolean">,
133145
Global,
134146
DefaultTrue,
@@ -164,9 +176,9 @@ let Definition = "debugger" in {
164176
def ShowAutosuggestionAnsiPrefix: Property<"show-autosuggestion-ansi-prefix", "String">,
165177
Global,
166178
DefaultStringValue<"${ansi.faint}">,
167-
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.">;
179+
Desc<"When displaying suggestion in a color-enabled terminal, use the ANSI terminal code specified in this format immediately before the suggestion.">;
168180
def ShowAutosuggestionAnsiSuffix: Property<"show-autosuggestion-ansi-suffix", "String">,
169181
Global,
170182
DefaultStringValue<"${ansi.normal}">,
171-
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.">;
183+
Desc<"When displaying suggestion in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the suggestion.">;
172184
}

lldb/source/Core/Debugger.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,22 @@ bool Debugger::SetUseColor(bool b) {
378378
return ret;
379379
}
380380

381+
bool Debugger::GetShowProgress() const {
382+
const uint32_t idx = ePropertyShowProgress;
383+
return m_collection_sp->GetPropertyAtIndexAsBoolean(
384+
nullptr, idx, g_debugger_properties[idx].default_uint_value != 0);
385+
}
386+
387+
llvm::StringRef Debugger::GetShowProgressAnsiPrefix() const {
388+
const uint32_t idx = ePropertyShowProgressAnsiPrefix;
389+
return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
390+
}
391+
392+
llvm::StringRef Debugger::GetShowProgressAnsiSuffix() const {
393+
const uint32_t idx = ePropertyShowProgressAnsiSuffix;
394+
return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
395+
}
396+
381397
bool Debugger::GetUseAutosuggestion() const {
382398
const uint32_t idx = ePropertyShowAutosuggestion;
383399
return m_collection_sp->GetPropertyAtIndexAsBoolean(
@@ -1667,6 +1683,9 @@ void Debugger::DefaultEventHandler() {
16671683
CommandInterpreter::eBroadcastBitAsynchronousOutputData |
16681684
CommandInterpreter::eBroadcastBitAsynchronousErrorData);
16691685

1686+
listener_sp->StartListeningForEvents(&m_broadcaster,
1687+
Debugger::eBroadcastBitProgress);
1688+
16701689
// Let the thread that spawned us know that we have started up and that we
16711690
// are now listening to all required events so no events get missed
16721691
m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening);
@@ -1716,6 +1735,9 @@ void Debugger::DefaultEventHandler() {
17161735
}
17171736
}
17181737
}
1738+
} else if (broadcaster == &m_broadcaster) {
1739+
if (event_type & Debugger::eBroadcastBitProgress)
1740+
HandleProgressEvent(event_sp);
17191741
}
17201742
}
17211743

@@ -1785,6 +1807,73 @@ lldb::thread_result_t Debugger::IOHandlerThread(lldb::thread_arg_t arg) {
17851807
return {};
17861808
}
17871809

1810+
void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
1811+
auto *data =
1812+
Debugger::ProgressEventData::GetEventDataFromEvent(event_sp.get());
1813+
if (!data)
1814+
return;
1815+
1816+
// Do some bookkeeping for the current event, regardless of whether we're
1817+
// going to show the progress.
1818+
const uint64_t id = data->GetID();
1819+
if (m_current_event_id) {
1820+
if (id != *m_current_event_id)
1821+
return;
1822+
if (data->GetCompleted())
1823+
m_current_event_id.reset();
1824+
} else {
1825+
m_current_event_id = id;
1826+
}
1827+
1828+
// Decide whether we actually are going to show the progress. This decision
1829+
// can change between iterations so check it inside the loop.
1830+
if (!GetShowProgress())
1831+
return;
1832+
1833+
// Determine whether the current output file is an interactive terminal with
1834+
// color support. We assume that if we support ANSI escape codes we support
1835+
// vt100 escape codes.
1836+
File &output = GetOutputFile();
1837+
if (!output.GetIsInteractive() || !output.GetIsTerminalWithColors())
1838+
return;
1839+
1840+
// Print over previous line, if any.
1841+
output.Printf("\r");
1842+
1843+
if (data->GetCompleted()) {
1844+
// Clear the current line.
1845+
output.Printf("\x1B[2K");
1846+
output.Flush();
1847+
return;
1848+
}
1849+
1850+
const bool use_color = GetUseColor();
1851+
llvm::StringRef ansi_prefix = GetShowProgressAnsiPrefix();
1852+
if (!ansi_prefix.empty())
1853+
output.Printf(
1854+
"%s", ansi::FormatAnsiTerminalCodes(ansi_prefix, use_color).c_str());
1855+
1856+
// Print the progress message.
1857+
std::string message = data->GetMessage();
1858+
if (data->GetTotal() != UINT64_MAX) {
1859+
output.Printf("[%" PRIu64 "/%" PRIu64 "] %s...", data->GetCompleted(), data->GetTotal(),
1860+
message.c_str());
1861+
} else {
1862+
output.Printf("%s...", message.c_str());
1863+
}
1864+
1865+
llvm::StringRef ansi_suffix = GetShowProgressAnsiSuffix();
1866+
if (!ansi_suffix.empty())
1867+
output.Printf(
1868+
"%s", ansi::FormatAnsiTerminalCodes(ansi_suffix, use_color).c_str());
1869+
1870+
// Clear until the end of the line.
1871+
output.Printf("\x1B[K\r");
1872+
1873+
// Flush the output.
1874+
output.Flush();
1875+
}
1876+
17881877
bool Debugger::HasIOHandlerThread() { return m_io_handler_thread.IsJoinable(); }
17891878

17901879
bool Debugger::StartIOHandlerThread() {

lldb/source/Symbol/LocateSymbolFile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "lldb/Core/ModuleList.h"
1212
#include "lldb/Core/ModuleSpec.h"
13+
#include "lldb/Core/Progress.h"
1314
#include "lldb/Host/FileSystem.h"
1415
#include "lldb/Symbol/ObjectFile.h"
1516
#include "lldb/Utility/ArchSpec.h"
@@ -262,6 +263,10 @@ Symbols::LocateExecutableSymbolFile(const ModuleSpec &module_spec,
262263
FileSystem::Instance().Exists(symbol_file_spec))
263264
return symbol_file_spec;
264265

266+
Progress progress(llvm::formatv(
267+
"Locating external symbol file for {0}",
268+
module_spec.GetFileSpec().GetFilename().AsCString("<Unknown>")));
269+
265270
FileSpecList debug_file_search_paths = default_search_paths;
266271

267272
// Add module directory.

0 commit comments

Comments
 (0)