Skip to content

Commit f419754

Browse files
authored
Merge pull request #6368 from Michael137/bugfix/lldb-ignore-ranges-frame-var-to-20221013
[cherry-pick][stable/20221013] [lldb] Ignore libcxx std::ranges global variables in frame var
2 parents 6b44bcc + 7670718 commit f419754

File tree

7 files changed

+69
-2
lines changed

7 files changed

+69
-2
lines changed

lldb/include/lldb/Target/LanguageRuntime.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ class LanguageRuntime : public Runtime, public PluginInterface {
172172
return llvm::None;
173173
}
174174

175+
/// Returns 'true' if we the variable with the specified 'name'
176+
/// should be hidden from variable views (e.g., when listing variables in
177+
/// 'frame variable' or 'target variable')
178+
virtual bool ShouldHideVariable(llvm::StringRef name) const { return false; }
179+
175180
void ModulesDidLoad(const ModuleList &module_list) override {}
176181

177182
// Called by ClangExpressionParser::PrepareForExecution to query for any

lldb/source/Core/ValueObject.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,12 +1679,20 @@ bool ValueObject::IsRuntimeSupportValue() {
16791679
if (!process)
16801680
return false;
16811681

1682+
if (!GetVariable())
1683+
return false;
1684+
1685+
auto *runtime = process->GetLanguageRuntime(GetVariable()->GetLanguage());
1686+
if (runtime)
1687+
if (runtime->ShouldHideVariable(GetName().GetStringRef()))
1688+
return true;
1689+
16821690
// We trust that the compiler did the right thing and marked runtime support
16831691
// values as artificial.
1684-
if (!GetVariable() || !GetVariable()->IsArtificial())
1692+
if (!GetVariable()->IsArtificial())
16851693
return false;
16861694

1687-
if (auto *runtime = process->GetLanguageRuntime(GetVariable()->GetLanguage()))
1695+
if (runtime)
16881696
if (runtime->IsAllowedRuntimeValue(GetName()))
16891697
return false;
16901698

lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "lldb/Target/StackFrame.h"
2929
#include "lldb/Target/ThreadPlanRunToAddress.h"
3030
#include "lldb/Target/ThreadPlanStepInRange.h"
31+
#include "lldb/Utility/RegularExpression.h"
3132
#include "lldb/Utility/Timer.h"
3233

3334
using namespace lldb;
@@ -40,6 +41,17 @@ char CPPLanguageRuntime::ID = 0;
4041
CPPLanguageRuntime::CPPLanguageRuntime(Process *process)
4142
: LanguageRuntime(process) {}
4243

44+
bool CPPLanguageRuntime::ShouldHideVariable(llvm::StringRef name) const {
45+
// Matches the global function objects in std::ranges/std::ranges::views
46+
// E.g.,
47+
// std::__1::ranges::views::__cpo::take
48+
// std::__1::ranges::__cpo::max_element
49+
static RegularExpression ignore_global_ranges_pattern(
50+
"std::__[[:alnum:]]+::ranges(::views)*::__cpo");
51+
52+
return ignore_global_ranges_pattern.Execute(name);
53+
}
54+
4355
bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) {
4456
return name == g_this;
4557
}

lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class CPPLanguageRuntime : public LanguageRuntime {
7777
lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
7878
bool stop_others) override;
7979

80+
bool ShouldHideVariable(llvm::StringRef name) const override;
81+
8082
bool IsAllowedRuntimeValue(ConstString name) override;
8183
protected:
8284
// Classes that inherit from CPPLanguageRuntime can see and modify these
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CXX_SOURCES := main.cpp
2+
CXXFLAGS_EXTRAS := -std=c++20
3+
4+
include Makefile.rules
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Test that frame var and target var hide
2+
the global function objects in the libc++
3+
ranges implementation"""
4+
5+
from lldbsuite.test.decorators import *
6+
from lldbsuite.test.lldbtest import *
7+
from lldbsuite.test import lldbutil
8+
9+
class HideGlobalRangesVarsTestCase(TestBase):
10+
11+
@add_test_categories(["libc++"])
12+
@skipIf(compiler=no_match("clang"))
13+
@skipIf(compiler="clang", compiler_version=['<', '16.0'])
14+
def test(self):
15+
self.build()
16+
17+
lldbutil.run_to_source_breakpoint(self, "return", lldb.SBFileSpec('main.cpp', False))
18+
19+
self.expect("frame variable --show-globals",
20+
substrs=["::ranges::views::__cpo",
21+
"::ranges::__cpo"],
22+
matching=False)
23+
24+
self.expect("target variable",
25+
substrs=["::ranges::views::__cpo",
26+
"::ranges::__cpo"],
27+
matching=False)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <ranges>
2+
3+
int main(int argc, char const *argv[]) {
4+
int arr[3] = {1, 2, 3};
5+
auto arr_view = std::ranges::views::all(arr);
6+
auto arr_max = std::ranges::max_element(arr);
7+
8+
return 0;
9+
}

0 commit comments

Comments
 (0)