From 571d4ed2f01c1117237b1a9684ad9b1d1ad8963a Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Mon, 26 Sep 2022 17:07:52 -0400 Subject: DebugInfo: make parseInfo have a progress callback This will enable us to have progress bars and cancellation of debuginfo application --- debuginfo.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'debuginfo.cpp') diff --git a/debuginfo.cpp b/debuginfo.cpp index c9a6f319..9783cba8 100644 --- a/debuginfo.cpp +++ b/debuginfo.cpp @@ -337,19 +337,25 @@ string DebugInfoParser::GetName() const } -Ref DebugInfoParser::Parse(Ref view, Ref existingDebugInfo) const +Ref DebugInfoParser::Parse(Ref view, Ref existingDebugInfo, std::function progress) const { + ProgressContext ctxt; + if (progress) + ctxt.callback = progress; + else + ctxt.callback = [=](size_t, size_t) { return true; }; + BNDebugInfo* info = nullptr; if (existingDebugInfo) { - info = BNParseDebugInfo(m_object, view->GetObject(), existingDebugInfo->GetObject()); + info = BNParseDebugInfo(m_object, view->GetObject(), existingDebugInfo->GetObject(), ProgressCallback, &ctxt); if (!info) return nullptr; info = BNNewDebugInfoReference(info); } else { - info = BNParseDebugInfo(m_object, view->GetObject(), nullptr); + info = BNParseDebugInfo(m_object, view->GetObject(), nullptr, ProgressCallback, &ctxt); if (!info) return nullptr; } @@ -375,10 +381,12 @@ bool CustomDebugInfoParser::IsValidCallback(void* ctxt, BNBinaryView* view) } -bool CustomDebugInfoParser::ParseCallback(void* ctxt, BNDebugInfo* debugInfo, BNBinaryView* view) +bool CustomDebugInfoParser::ParseCallback(void* ctxt, BNDebugInfo* debugInfo, BNBinaryView* view, bool (*progress)(void*, size_t, size_t), void* progressCtxt) { CustomDebugInfoParser* parser = (CustomDebugInfoParser*)ctxt; - return parser->ParseInfo(new DebugInfo(debugInfo), new BinaryView(view)); + return parser->ParseInfo(new DebugInfo(debugInfo), new BinaryView(view), [=](size_t cur, size_t max) { + return progress(progressCtxt, cur, max); + }); } -- cgit v1.3.1