When looking at template arguments in LLDB, we usually care about what the user passed in his code, not whether some of those arguments where passed as a variadic parameter pack. This patch extends all the C++ APIs to look at template parameters to take an additional 'expand_pack' boolean that automatically unwraps the potential argument packs. The equivalent SBAPI calls have been changed to pass true for this parameter. A byproduct of the patch is to also fix the support for template type that have only a parameter pack as argument (like the OnlyPack type in the test). Those were not recognized as template instanciations before. The added test verifies that the SBAPI is able to iterate over the arguments of a variadic template. The original patch was written by Fred Riss almost 4 years ago. Differential revision: https://reviews.llvm.org/D51387
39 lines
1.8 KiB
Python
39 lines
1.8 KiB
Python
"""
|
|
Test that the type of arguments to C++ template classes that have variadic
|
|
parameters can be enumerated.
|
|
"""
|
|
import lldb
|
|
from lldbsuite.test.decorators import *
|
|
from lldbsuite.test.lldbtest import *
|
|
from lldbsuite.test import lldbutil
|
|
|
|
|
|
class TemplatePackArgsTestCase(TestBase):
|
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
def test_template_argument_pack(self):
|
|
self.build()
|
|
(_, _, thread, _) = lldbutil.run_to_source_breakpoint(self,
|
|
'breakpoint here', lldb.SBFileSpec('main.cpp'), exe_name = 'a.out')
|
|
frame = thread.GetSelectedFrame()
|
|
|
|
empty_pack = frame.FindVariable('emptyPack')
|
|
self.assertTrue(empty_pack.IsValid(),
|
|
'make sure we find the emptyPack variable')
|
|
|
|
only_pack = frame.FindVariable('onlyPack')
|
|
self.assertTrue(only_pack.IsValid(),
|
|
'make sure we find the onlyPack variable')
|
|
self.assertEqual(only_pack.GetType().GetNumberOfTemplateArguments(), 4)
|
|
self.assertEqual(only_pack.GetType().GetTemplateArgumentType(0).GetName(), 'int')
|
|
self.assertEqual(only_pack.GetType().GetTemplateArgumentType(1).GetName(), 'char')
|
|
self.assertEqual(only_pack.GetType().GetTemplateArgumentType(2).GetName(), 'double')
|
|
# Access the C<double, 42> template parameter.
|
|
nested_template = only_pack.GetType().GetTemplateArgumentType(3)
|
|
self.assertEqual(nested_template.GetName(), 'D<int, int, bool>')
|
|
self.assertEqual(nested_template.GetNumberOfTemplateArguments(), 3)
|
|
self.assertEqual(nested_template.GetTemplateArgumentType(0).GetName(), 'int')
|
|
self.assertEqual(nested_template.GetTemplateArgumentType(1).GetName(), 'int')
|
|
self.assertEqual(nested_template.GetTemplateArgumentType(2).GetName(), 'bool')
|