summaryrefslogtreecommitdiff
path: root/lldb/test/API/functionalities/data-formatter
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2024-06-03 10:34:44 +0200
committerGitHub <noreply@github.com>2024-06-03 10:34:44 +0200
commit763b96c86d81d51d0db430791a61fd1e8a406bce (patch)
treee5a7f1ba5b3f930a4363d535d5087e95c5afb348 /lldb/test/API/functionalities/data-formatter
parentce73e17e3ab5ccfa33a977843e82a9bbfb6b4ce3 (diff)
[lldb] Avoid (unlimited) GetNumChildren calls when printing values (#93946)
For some data formatters, even getting the number of children can be an expensive operations (e.g., needing to walk a linked list to determine the number of elements). This is then wasted work when we know we will be printing only small number of them. This patch replaces the calls to GetNumChildren (at least those on the "frame var" path) with the calls to the capped version, passing the value of `max-children-count` setting (plus one)
Diffstat (limited to 'lldb/test/API/functionalities/data-formatter')
-rw-r--r--lldb/test/API/functionalities/data-formatter/synthcapping/TestSyntheticCapping.py11
-rw-r--r--lldb/test/API/functionalities/data-formatter/synthcapping/fooSynthProvider.py15
2 files changed, 25 insertions, 1 deletions
diff --git a/lldb/test/API/functionalities/data-formatter/synthcapping/TestSyntheticCapping.py b/lldb/test/API/functionalities/data-formatter/synthcapping/TestSyntheticCapping.py
index d53dadef836e..9ca232abefa0 100644
--- a/lldb/test/API/functionalities/data-formatter/synthcapping/TestSyntheticCapping.py
+++ b/lldb/test/API/functionalities/data-formatter/synthcapping/TestSyntheticCapping.py
@@ -68,6 +68,11 @@ class SyntheticCappingTestCase(TestBase):
"r = 34",
],
)
+ # num_children() should be called with at most max_num_children=257
+ # (target.max-children-count + 1)
+ self.expect(
+ "script fooSynthProvider.reset_max_num_children_max()", substrs=["257"]
+ )
# check that capping works
self.runCmd("settings set target.max-children-count 2", check=False)
@@ -80,9 +85,15 @@ class SyntheticCappingTestCase(TestBase):
"...",
],
)
+ self.expect(
+ "script fooSynthProvider.reset_max_num_children_max()", substrs=["3"]
+ )
self.expect("frame variable f00_1", matching=False, substrs=["r = 34"])
self.runCmd("settings set target.max-children-count 256", check=False)
self.expect("frame variable f00_1", matching=True, substrs=["r = 34"])
+ self.expect(
+ "script fooSynthProvider.reset_max_num_children_max()", substrs=["257"]
+ )
diff --git a/lldb/test/API/functionalities/data-formatter/synthcapping/fooSynthProvider.py b/lldb/test/API/functionalities/data-formatter/synthcapping/fooSynthProvider.py
index 3bfa3130cc01..5ea392ac8829 100644
--- a/lldb/test/API/functionalities/data-formatter/synthcapping/fooSynthProvider.py
+++ b/lldb/test/API/functionalities/data-formatter/synthcapping/fooSynthProvider.py
@@ -2,11 +2,24 @@ import lldb
class fooSynthProvider:
+ # For testing purposes, we'll keep track of the maximum value of
+ # max_num_children we've been called with.
+ MAX_NUM_CHILDREN_MAX = 0
+
+ @classmethod
+ def reset_max_num_children_max(cls):
+ old_value = fooSynthProvider.MAX_NUM_CHILDREN_MAX
+ fooSynthProvider.MAX_NUM_CHILDREN_MAX = 0
+ return old_value
+
def __init__(self, valobj, dict):
self.valobj = valobj
self.int_type = valobj.GetType().GetBasicType(lldb.eBasicTypeInt)
- def num_children(self):
+ def num_children(self, max_num_children):
+ fooSynthProvider.MAX_NUM_CHILDREN_MAX = max(
+ fooSynthProvider.MAX_NUM_CHILDREN_MAX, max_num_children
+ )
return 3
def get_child_at_index(self, index):