-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLDB] Add SBProgress so Python scripts can also report progress #119052
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d28deda
Add SBPRogress class to enable commands to async report to lldb-dap t…
Jlalond 956c600
Add dtor, amend Jonas's feedback on docstrings and formatting
Jlalond 2d56e1d
Rebase and refactor SBProgress, add positive and negative test cases
Jlalond 61d323b
Update debugger to listen to external progress events by default
Jlalond dba3f0e
Implement test feedback, delete the copy assignment operator from SBP…
Jlalond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
%feature("docstring", | ||
"A Progress indicator helper class. | ||
|
||
Any potentially long running sections of code in LLDB should report | ||
progress so that clients are aware of delays that might appear during | ||
debugging. Delays commonly include indexing debug information, parsing | ||
symbol tables for object files, downloading symbols from remote | ||
repositories, and many more things. | ||
|
||
The Progress class helps make sure that progress is correctly reported | ||
and will always send an initial progress update, updates when | ||
Progress::Increment() is called, and also will make sure that a progress | ||
completed update is reported even if the user doesn't explicitly cause one | ||
to be sent.") lldb::SBProgress; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//===-- SBProgress.h --------------------------------------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLDB_API_SBPROGRESS_H | ||
#define LLDB_API_SBPROGRESS_H | ||
|
||
#include "lldb/API/SBDebugger.h" | ||
#include "lldb/API/SBDefines.h" | ||
|
||
namespace lldb { | ||
|
||
/// A Progress indicator helper class. | ||
/// | ||
/// Any potentially long running sections of code in LLDB should report | ||
/// progress so that clients are aware of delays that might appear during | ||
/// debugging. Delays commonly include indexing debug information, parsing | ||
/// symbol tables for object files, downloading symbols from remote | ||
/// repositories, and many more things. | ||
/// | ||
/// The Progress class helps make sure that progress is correctly reported | ||
/// and will always send an initial progress update, updates when | ||
/// Progress::Increment() is called, and also will make sure that a progress | ||
/// completed update is reported even if the user doesn't explicitly cause one | ||
/// to be sent. | ||
class LLDB_API SBProgress { | ||
public: | ||
/// Construct a progress object with a title, details and a given debugger. | ||
/// \param title | ||
/// The title of the progress object. | ||
/// \param details | ||
/// The details of the progress object. | ||
/// \param debugger | ||
/// The debugger for this progress object to report to. | ||
SBProgress(const char *title, const char *details, SBDebugger &debugger); | ||
|
||
/// Construct a progress object with a title, details, the total units of work | ||
/// to be done, and a given debugger. | ||
/// \param title | ||
/// The title of the progress object. | ||
/// \param details | ||
/// The details of the progress object. | ||
/// \param total_units | ||
/// The total number of units of work to be done. | ||
/// \param debugger | ||
/// The debugger for this progress object to report to. | ||
SBProgress(const char *title, const char *details, uint64_t total_units, | ||
SBDebugger &debugger); | ||
|
||
~SBProgress(); | ||
|
||
void Increment(uint64_t amount, const char *description = nullptr); | ||
|
||
protected: | ||
lldb_private::Progress &ref() const; | ||
|
||
private: | ||
std::unique_ptr<lldb_private::Progress> m_opaque_up; | ||
}; // SBProgress | ||
} // namespace lldb | ||
|
||
#endif // LLDB_API_SBPROGRESS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===-- SBProgress.cpp --------------------------------------------------*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "lldb/API/SBProgress.h" | ||
#include "lldb/Core/Progress.h" | ||
#include "lldb/Utility/Instrumentation.h" | ||
|
||
using namespace lldb; | ||
|
||
SBProgress::SBProgress(const char *title, const char *details, | ||
SBDebugger &debugger) { | ||
LLDB_INSTRUMENT_VA(this, title, details, debugger); | ||
|
||
m_opaque_up = std::make_unique<lldb_private::Progress>( | ||
title, details, /*total=*/std::nullopt, debugger.get(), | ||
/*minimum_report_time=*/std::nullopt, | ||
lldb_private::Progress::Origin::eExternal); | ||
} | ||
|
||
SBProgress::SBProgress(const char *title, const char *details, | ||
uint64_t total_units, SBDebugger &debugger) { | ||
LLDB_INSTRUMENT_VA(this, title, details, total_units, debugger); | ||
|
||
m_opaque_up = std::make_unique<lldb_private::Progress>( | ||
title, details, total_units, debugger.get(), | ||
/*minimum_report_time=*/std::nullopt, | ||
lldb_private::Progress::Origin::eExternal); | ||
} | ||
|
||
SBProgress::~SBProgress() = default; | ||
|
||
void SBProgress::Increment(uint64_t amount, const char *description) { | ||
LLDB_INSTRUMENT_VA(amount, description); | ||
|
||
m_opaque_up->Increment(amount, description); | ||
} | ||
|
||
lldb_private::Progress &SBProgress::ref() const { return *m_opaque_up; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Test the SBProgress API.""" | ||
|
||
import lldb | ||
from lldbsuite.test.lldbtest import * | ||
|
||
|
||
class SBProgressTestCase(TestBase): | ||
def test_with_external_bit_set(self): | ||
"""Test SBProgress events are listened to when the external bit is set.""" | ||
|
||
progress = lldb.SBProgress("Test SBProgress", "Test progress", self.dbg) | ||
listener = lldb.SBListener("Test listener") | ||
broadcaster = self.dbg.GetBroadcaster() | ||
broadcaster.AddListener(listener, lldb.eBroadcastBitExternalProgress) | ||
event = lldb.SBEvent() | ||
|
||
expected_string = "Test progress first increment" | ||
progress.Increment(1, expected_string) | ||
self.assertTrue(listener.PeekAtNextEvent(event)) | ||
stream = lldb.SBStream() | ||
event.GetDescription(stream) | ||
self.assertIn(expected_string, stream.GetData()) | ||
|
||
def test_without_external_bit_set(self): | ||
"""Test SBProgress events are not listened to on the internal progress bit.""" | ||
|
||
progress = lldb.SBProgress("Test SBProgress", "Test progress", self.dbg) | ||
listener = lldb.SBListener("Test listener") | ||
broadcaster = self.dbg.GetBroadcaster() | ||
broadcaster.AddListener(listener, lldb.eBroadcastBitProgress) | ||
event = lldb.SBEvent() | ||
|
||
expected_string = "Test progress first increment" | ||
progress.Increment(1, expected_string) | ||
self.assertFalse(listener.PeekAtNextEvent(event)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.