Skip to content

Commit d28deda

Browse files
committed
Add SBPRogress class to enable commands to async report to lldb-dap their progress
1 parent 29ed600 commit d28deda

File tree

8 files changed

+111
-1
lines changed

8 files changed

+111
-1
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/include/lldb/API/SBDebugger.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class LLDB_API SBDebugger {
203203
lldb::SBCommandInterpreter GetCommandInterpreter();
204204

205205
void HandleCommand(const char *command);
206-
206+
207207
void RequestInterrupt();
208208
void CancelInterruptRequest();
209209
bool InterruptRequested();
@@ -517,6 +517,7 @@ class LLDB_API SBDebugger {
517517
friend class SBPlatform;
518518
friend class SBTarget;
519519
friend class SBTrace;
520+
friend class SBProgress;
520521

521522
lldb::SBTarget FindTargetWithLLDBProcess(const lldb::ProcessSP &processSP);
522523

lldb/include/lldb/API/SBProgress.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 SB API Wrapper around lldb_private::Progress
18+
class LLDB_API SBProgress {
19+
public:
20+
/// Construct a progress object with a title, details and a given debugger.
21+
/// \param title
22+
/// The title of the progress object.
23+
/// \param details
24+
/// The details of the progress object.
25+
/// \param debugger
26+
/// The debugger for this progress object to report to.
27+
SBProgress(const char *title, const char *details, SBDebugger &debugger);
28+
29+
/// Construct a progress object with a title, details, the total units of work
30+
/// to be done, and a given debugger.
31+
/// \param title
32+
/// The title of the progress object.
33+
/// \param details
34+
/// The details of the progress object.
35+
/// \param total_units
36+
/// The total number of units of work to be done.
37+
/// \param debugger
38+
/// The debugger for this progress object to report to.
39+
SBProgress(const char *title, const char *details, uint64_t total_units,
40+
SBDebugger &debugger);
41+
SBProgress(const lldb::SBProgress &rhs);
42+
~SBProgress();
43+
44+
const SBProgress &operator=(const lldb::SBProgress &rhs);
45+
46+
void Increment(uint64_t amount = 1, const char *description = nullptr);
47+
48+
protected:
49+
lldb_private::Progress &ref() const;
50+
51+
private:
52+
std::unique_ptr<lldb_private::Progress> m_opaque_up;
53+
}; // SBProgress
54+
} // namespace lldb
55+
56+
#endif // LLDB_API_SBPROGRESS_H

lldb/include/lldb/lldb-forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class Symtab;
233233
class SyntheticChildren;
234234
class SyntheticChildrenFrontEnd;
235235
class SystemRuntime;
236+
class Progress;
236237
class Target;
237238
class TargetList;
238239
class TargetProperties;

lldb/source/API/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
8383
SBModule.cpp
8484
SBModuleSpec.cpp
8585
SBPlatform.cpp
86+
SBProgress.cpp
8687
SBProcess.cpp
8788
SBProcessInfo.cpp
8889
SBProcessInfoList.cpp

lldb/source/API/SBProgress.cpp

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

0 commit comments

Comments
 (0)