llvm-project/lldb/source/API/SBProgress.cpp
Jacob Lalonde 6b048aeaf8
[LLDB] Add SBProgress so Python scripts can also report progress (#119052)
Recently I've been working on a lot of internal Python tooling, and in
certain cases I want to report async to the script over DAP. Progress.h
already handles this, so I've exposed Progress via the SB API so Python
scripts can also update progress objects.

I actually have no idea how to test this, so I just wrote a [toy command
to test
it](https://gist.github.com/Jlalond/48d85e75a91f7a137e3142e6a13d0947)


![image](https://github.com/user-attachments/assets/7317cbb8-9145-4fdb-bacf-9864bf50c467)

I also copied the first section of the extensive Progress.h class
documentation to the docstrings.
2025-01-17 12:00:31 -08:00

44 lines
1.5 KiB
C++

//===-- 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; }