Skip to content

Commit 99c0b86

Browse files
author
git apple-llvm automerger
committed
Merge commit 'ff59629b8650' from swift/release/6.1 into stable/20240723
2 parents 725cb2b + ff59629 commit 99c0b86

File tree

24 files changed

+1235
-260
lines changed

24 files changed

+1235
-260
lines changed

lldb/bindings/headers.swig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "lldb/API/SBProcess.h"
5353
#include "lldb/API/SBProcessInfo.h"
5454
#include "lldb/API/SBProcessInfoList.h"
55+
#include "lldb/API/SBProgress.h"
5556
#include "lldb/API/SBQueue.h"
5657
#include "lldb/API/SBQueueItem.h"
5758
#include "lldb/API/SBReproducer.h"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
%feature("docstring",
2+
"A Progress indicator helper class.
3+
4+
Any potentially long running sections of code in LLDB should report
5+
progress so that clients are aware of delays that might appear during
6+
debugging. Delays commonly include indexing debug information, parsing
7+
symbol tables for object files, downloading symbols from remote
8+
repositories, and many more things.
9+
10+
The Progress class helps make sure that progress is correctly reported
11+
and will always send an initial progress update, updates when
12+
Progress::Increment() is called, and also will make sure that a progress
13+
completed update is reported even if the user doesn't explicitly cause one
14+
to be sent.") lldb::SBProgress;

lldb/bindings/interfaces.swig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
%include "./interface/SBPlatformDocstrings.i"
5555
%include "./interface/SBProcessDocstrings.i"
5656
%include "./interface/SBProcessInfoDocstrings.i"
57+
%include "./interface/SBProgressDocstrings.i"
5758
%include "./interface/SBQueueDocstrings.i"
5859
%include "./interface/SBQueueItemDocstrings.i"
5960
%include "./interface/SBReproducerDocstrings.i"
@@ -133,6 +134,7 @@
133134
%include "lldb/API/SBProcess.h"
134135
%include "lldb/API/SBProcessInfo.h"
135136
%include "lldb/API/SBProcessInfoList.h"
137+
%include "lldb/API/SBProgress.h"
136138
%include "lldb/API/SBQueue.h"
137139
%include "lldb/API/SBQueueItem.h"
138140
%include "lldb/API/SBReproducer.h"

lldb/bindings/python/static-binding/LLDBWrapPython.cpp

Lines changed: 553 additions & 200 deletions
Large diffs are not rendered by default.

lldb/bindings/python/static-binding/lldb.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,10 @@ def lldb_iter(obj, getsize, getelem):
18071807

18081808
eBroadcastBitProgressCategory = _lldb.eBroadcastBitProgressCategory
18091809

1810+
eBroadcastBitExternalProgress = _lldb.eBroadcastBitExternalProgress
1811+
1812+
eBroadcastBitExternalProgressCategory = _lldb.eBroadcastBitExternalProgressCategory
1813+
18101814
eSeverityError = _lldb.eSeverityError
18111815

18121816
eSeverityWarning = _lldb.eSeverityWarning
@@ -4652,6 +4656,10 @@ def disassemble_instructions (insts):
46524656

46534657
eBroadcastBitProgressCategory = _lldb.SBDebugger_eBroadcastBitProgressCategory
46544658

4659+
eBroadcastBitExternalProgress = _lldb.SBDebugger_eBroadcastBitExternalProgress
4660+
4661+
eBroadcastBitExternalProgressCategory = _lldb.SBDebugger_eBroadcastBitExternalProgressCategory
4662+
46554663

46564664
def __init__(self, *args):
46574665
r"""
@@ -9885,6 +9893,40 @@ def __iter__(self):
98859893

98869894
# Register SBProcessInfoList in _lldb:
98879895
_lldb.SBProcessInfoList_swigregister(SBProcessInfoList)
9896+
class SBProgress(object):
9897+
r"""
9898+
A Progress indicator helper class.
9899+
9900+
Any potentially long running sections of code in LLDB should report
9901+
progress so that clients are aware of delays that might appear during
9902+
debugging. Delays commonly include indexing debug information, parsing
9903+
symbol tables for object files, downloading symbols from remote
9904+
repositories, and many more things.
9905+
9906+
The Progress class helps make sure that progress is correctly reported
9907+
and will always send an initial progress update, updates when
9908+
Progress::Increment() is called, and also will make sure that a progress
9909+
completed update is reported even if the user doesn't explicitly cause one
9910+
to be sent.
9911+
"""
9912+
9913+
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
9914+
__repr__ = _swig_repr
9915+
9916+
def __init__(self, *args):
9917+
r"""
9918+
__init__(SBProgress self, char const * title, char const * details, SBDebugger debugger) -> SBProgress
9919+
__init__(SBProgress self, char const * title, char const * details, uint64_t total_units, SBDebugger debugger) -> SBProgress
9920+
"""
9921+
_lldb.SBProgress_swiginit(self, _lldb.new_SBProgress(*args))
9922+
__swig_destroy__ = _lldb.delete_SBProgress
9923+
9924+
def Increment(self, amount, description=None):
9925+
r"""Increment(SBProgress self, uint64_t amount, char const * description=None)"""
9926+
return _lldb.SBProgress_Increment(self, amount, description)
9927+
9928+
# Register SBProgress in _lldb:
9929+
_lldb.SBProgress_swigregister(SBProgress)
98889930
class SBQueue(object):
98899931
r"""Represents a libdispatch queue in the process."""
98909932

lldb/include/lldb/API/SBDebugger.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ class LLDB_API SBInputReader {
4242

4343
class LLDB_API SBDebugger {
4444
public:
45-
FLAGS_ANONYMOUS_ENUM(){
46-
eBroadcastBitProgress = lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
47-
eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
48-
eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
49-
eBroadcastBitProgressCategory =
50-
lldb::DebuggerBroadcastBit::eBroadcastBitProgressCategory,
45+
FLAGS_ANONYMOUS_ENUM() {
46+
eBroadcastBitProgress = lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
47+
eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
48+
eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
49+
eBroadcastBitProgressCategory =
50+
lldb::DebuggerBroadcastBit::eBroadcastBitProgressCategory,
51+
eBroadcastBitExternalProgress =
52+
lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgress,
53+
eBroadcastBitExternalProgressCategory =
54+
lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgressCategory,
5155
};
5256
SBDebugger();
5357

@@ -203,7 +207,7 @@ class LLDB_API SBDebugger {
203207
lldb::SBCommandInterpreter GetCommandInterpreter();
204208

205209
void HandleCommand(const char *command);
206-
210+
207211
void RequestInterrupt();
208212
void CancelInterruptRequest();
209213
bool InterruptRequested();
@@ -517,6 +521,7 @@ class LLDB_API SBDebugger {
517521
friend class SBPlatform;
518522
friend class SBTarget;
519523
friend class SBTrace;
524+
friend class SBProgress;
520525

521526
lldb::SBTarget FindTargetWithLLDBProcess(const lldb::ProcessSP &processSP);
522527

lldb/include/lldb/API/SBProgress.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===-- SBProgress.h --------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_API_SBPROGRESS_H
10+
#define LLDB_API_SBPROGRESS_H
11+
12+
#include "lldb/API/SBDebugger.h"
13+
#include "lldb/API/SBDefines.h"
14+
15+
namespace lldb {
16+
17+
/// A Progress indicator helper class.
18+
///
19+
/// Any potentially long running sections of code in LLDB should report
20+
/// progress so that clients are aware of delays that might appear during
21+
/// debugging. Delays commonly include indexing debug information, parsing
22+
/// symbol tables for object files, downloading symbols from remote
23+
/// repositories, and many more things.
24+
///
25+
/// The Progress class helps make sure that progress is correctly reported
26+
/// and will always send an initial progress update, updates when
27+
/// Progress::Increment() is called, and also will make sure that a progress
28+
/// completed update is reported even if the user doesn't explicitly cause one
29+
/// to be sent.
30+
class LLDB_API SBProgress {
31+
public:
32+
/// Construct a progress object with a title, details and a given debugger.
33+
/// \param title
34+
/// The title of the progress object.
35+
/// \param details
36+
/// The details of the progress object.
37+
/// \param debugger
38+
/// The debugger for this progress object to report to.
39+
SBProgress(const char *title, const char *details, SBDebugger &debugger);
40+
41+
/// Construct a progress object with a title, details, the total units of work
42+
/// to be done, and a given debugger.
43+
/// \param title
44+
/// The title of the progress object.
45+
/// \param details
46+
/// The details of the progress object.
47+
/// \param total_units
48+
/// The total number of units of work to be done.
49+
/// \param debugger
50+
/// The debugger for this progress object to report to.
51+
SBProgress(const char *title, const char *details, uint64_t total_units,
52+
SBDebugger &debugger);
53+
54+
~SBProgress();
55+
56+
void Increment(uint64_t amount, const char *description = nullptr);
57+
58+
protected:
59+
lldb_private::Progress &ref() const;
60+
61+
private:
62+
std::unique_ptr<lldb_private::Progress> m_opaque_up;
63+
}; // SBProgress
64+
} // namespace lldb
65+
66+
#endif // LLDB_API_SBPROGRESS_H

lldb/include/lldb/Core/Progress.h

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLDB_CORE_PROGRESS_H
1111

1212
#include "lldb/Host/Alarm.h"
13+
#include "lldb/Utility/Timeout.h"
1314
#include "lldb/lldb-forward.h"
1415
#include "lldb/lldb-types.h"
1516
#include "llvm/ADT/StringMap.h"
@@ -58,6 +59,12 @@ namespace lldb_private {
5859

5960
class Progress {
6061
public:
62+
/// Enum to indicate the origin of a progress event, internal or external.
63+
enum class Origin : uint8_t {
64+
eInternal = 0,
65+
eExternal = 1,
66+
};
67+
6168
/// Construct a progress object that will report information.
6269
///
6370
/// The constructor will create a unique progress reporting object and
@@ -81,7 +88,9 @@ class Progress {
8188
/// progress is to be reported only to specific debuggers.
8289
Progress(std::string title, std::string details = {},
8390
std::optional<uint64_t> total = std::nullopt,
84-
lldb_private::Debugger *debugger = nullptr);
91+
lldb_private::Debugger *debugger = nullptr,
92+
Timeout<std::nano> minimum_report_time = std::nullopt,
93+
Origin origin = Origin::eInternal);
8594

8695
/// Destroy the progress object.
8796
///
@@ -116,26 +125,40 @@ class Progress {
116125
/// The optional debugger ID to report progress to. If this has no value
117126
/// then all debuggers will receive this event.
118127
std::optional<lldb::user_id_t> debugger_id;
128+
129+
/// The origin of the progress event, wheter it is internal or external.
130+
Origin origin;
119131
};
120132

121133
private:
122134
void ReportProgress();
123135
static std::atomic<uint64_t> g_id;
124-
/// More specific information about the current file being displayed in the
125-
/// report.
126-
std::string m_details;
127-
/// How much work ([0...m_total]) that has been completed.
128-
uint64_t m_completed;
136+
129137
/// Total amount of work, use a std::nullopt in the constructor for non
130138
/// deterministic progress.
131-
uint64_t m_total;
132-
std::mutex m_mutex;
133-
/// Set to true when progress has been reported where m_completed == m_total
134-
/// to ensure that we don't send progress updates after progress has
135-
/// completed.
136-
bool m_complete = false;
139+
const uint64_t m_total;
140+
141+
// Minimum amount of time between two progress reports.
142+
const Timeout<std::nano> m_minimum_report_time;
143+
137144
/// Data needed by the debugger to broadcast a progress event.
138-
ProgressData m_progress_data;
145+
const ProgressData m_progress_data;
146+
147+
/// How much work ([0...m_total]) that has been completed.
148+
std::atomic<uint64_t> m_completed = 0;
149+
150+
/// Time (in nanoseconds since epoch) of the last progress report.
151+
std::atomic<uint64_t> m_last_report_time_ns;
152+
153+
/// Guards non-const non-atomic members of the class.
154+
std::mutex m_mutex;
155+
156+
/// More specific information about the current file being displayed in the
157+
/// report.
158+
std::string m_details;
159+
160+
/// The "completed" value of the last reported event.
161+
std::optional<uint64_t> m_prev_completed;
139162
};
140163

141164
/// A class used to group progress reports by category. This is done by using a

lldb/include/lldb/lldb-enumerations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,8 @@ enum DebuggerBroadcastBit {
13841384
eBroadcastBitError = (1 << 2),
13851385
eBroadcastSymbolChange = (1 << 3),
13861386
eBroadcastBitProgressCategory = (1 << 4),
1387+
eBroadcastBitExternalProgress = (1 << 5),
1388+
eBroadcastBitExternalProgressCategory = (1 << 6),
13871389
};
13881390

13891391
/// Used for expressing severity in logs and diagnostics.

lldb/include/lldb/lldb-forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ class Symtab;
231231
class SyntheticChildren;
232232
class SyntheticChildrenFrontEnd;
233233
class SystemRuntime;
234+
class Progress;
234235
class Target;
235236
class TargetList;
236237
class TargetProperties;

lldb/source/API/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
9393
SBModule.cpp
9494
SBModuleSpec.cpp
9595
SBPlatform.cpp
96+
SBProgress.cpp
9697
SBProcess.cpp
9798
SBProcessInfo.cpp
9899
SBProcessInfoList.cpp

lldb/source/API/SBProgress.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===-- SBProgress.cpp --------------------------------------------------*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "lldb/API/SBProgress.h"
10+
#include "lldb/Core/Progress.h"
11+
#include "lldb/Utility/Instrumentation.h"
12+
13+
using namespace lldb;
14+
15+
SBProgress::SBProgress(const char *title, const char *details,
16+
SBDebugger &debugger) {
17+
LLDB_INSTRUMENT_VA(this, title, details, debugger);
18+
19+
m_opaque_up = std::make_unique<lldb_private::Progress>(
20+
title, details, /*total=*/std::nullopt, debugger.get(),
21+
/*minimum_report_time=*/std::nullopt,
22+
lldb_private::Progress::Origin::eExternal);
23+
}
24+
25+
SBProgress::SBProgress(const char *title, const char *details,
26+
uint64_t total_units, SBDebugger &debugger) {
27+
LLDB_INSTRUMENT_VA(this, title, details, total_units, debugger);
28+
29+
m_opaque_up = std::make_unique<lldb_private::Progress>(
30+
title, details, total_units, debugger.get(),
31+
/*minimum_report_time=*/std::nullopt,
32+
lldb_private::Progress::Origin::eExternal);
33+
}
34+
35+
SBProgress::~SBProgress() = default;
36+
37+
void SBProgress::Increment(uint64_t amount, const char *description) {
38+
LLDB_INSTRUMENT_VA(amount, description);
39+
40+
m_opaque_up->Increment(amount, description);
41+
}
42+
43+
lldb_private::Progress &SBProgress::ref() const { return *m_opaque_up; }

lldb/source/Core/Debugger.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,8 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
20042004
listener_sp->StartListeningForEvents(
20052005
&m_broadcaster, lldb::eBroadcastBitProgress | lldb::eBroadcastBitWarning |
20062006
lldb::eBroadcastBitError |
2007-
lldb::eBroadcastSymbolChange);
2007+
lldb::eBroadcastSymbolChange |
2008+
lldb::eBroadcastBitExternalProgress);
20082009

20092010
// Let the thread that spawned us know that we have started up and that we
20102011
// are now listening to all required events so no events get missed

0 commit comments

Comments
 (0)