diff options
| author | Johnny Chen <johnny.chen@apple.com> | 2011-07-22 00:47:58 +0000 |
|---|---|---|
| committer | Johnny Chen <johnny.chen@apple.com> | 2011-07-22 00:47:58 +0000 |
| commit | 989b7efd8ac6201d37c201d5ddf7bec6966eb106 (patch) | |
| tree | bbb6e548d53d244eb8000846554760e7ed862663 | |
| parent | 1eb27ae5808c50a2eedb4f2919582ac69ce1bb16 (diff) | |
| download | bcm5719-llvm-989b7efd8ac6201d37c201d5ddf7bec6966eb106.tar.gz bcm5719-llvm-989b7efd8ac6201d37c201d5ddf7bec6966eb106.zip | |
Add BasicFormatter and ChildVisitingFormatter utility classes to the lldbutil.py module
which provide some convenient ways to print an SBValue object. Use that in TestValueAPI.py
to print the 'days_of_week' char* array variable.
For an example:
cvf = lldbutil.ChildVisitingFormatter(indent=2)
print cvf.format(days_of_week)
produces:
(const char *[7]) days_of_week = 0x00000001026a5060 (location)
(const char *) [0] = "Sunday"
(const char *) [1] = "Monday"
(const char *) [2] = "Tuesday"
(const char *) [3] = "Wednesday"
(const char *) [4] = "Thursday"
(const char *) [5] = "Friday"
(const char *) [6] = "Saturday"
llvm-svn: 135736
| -rw-r--r-- | lldb/test/lldbutil.py | 36 | ||||
| -rw-r--r-- | lldb/test/python_api/value/TestValueAPI.py | 6 | ||||
| -rw-r--r-- | lldb/test/python_api/value/main.c | 2 |
3 files changed, 44 insertions, 0 deletions
diff --git a/lldb/test/lldbutil.py b/lldb/test/lldbutil.py index 8966f0710c9..31d6638f978 100644 --- a/lldb/test/lldbutil.py +++ b/lldb/test/lldbutil.py @@ -527,3 +527,39 @@ def get_ESRs(frame): ... """ return get_registers(frame, "exception state") + +# =============================== +# Utility functions for SBValue's +# =============================== + +class BasicFormatter(object): + def format(self, value, buffer=None, indent=0): + if not buffer: + output = StringIO.StringIO() + else: + output = buffer + sum = value.GetSummary() + if value.GetNumChildren() > 0 and sum == None: + sum = "%s (location)" % value.GetLocation() + print >> output, "{indentation}({type}) {name} = {summary}".format( + indentation = ' ' * indent, + type = value.GetTypeName(), + name = value.GetName(), + summary = sum) + return output.getvalue() + +class ChildVisitingFormatter(BasicFormatter): + def __init__(self, indent=2): + """Default indentation of 2 SPC's.""" + self.indentation = indent + def format(self, value, buffer=None): + if not buffer: + output = StringIO.StringIO() + else: + output = buffer + + BasicFormatter.format(self, value, buffer=output) + for child in value: + BasicFormatter.format(self, child, buffer=output, indent=self.indentation) + + return output.getvalue() diff --git a/lldb/test/python_api/value/TestValueAPI.py b/lldb/test/python_api/value/TestValueAPI.py index 1453af67854..f89ffbf58b2 100644 --- a/lldb/test/python_api/value/TestValueAPI.py +++ b/lldb/test/python_api/value/TestValueAPI.py @@ -66,6 +66,12 @@ class ValueAPITestCase(TestBase): self.assertTrue(days_of_week.GetNumChildren() == 7, VALID_VARIABLE) self.DebugSBValue(days_of_week) + fmt = lldbutil.BasicFormatter() + cvf = lldbutil.ChildVisitingFormatter(indent=2) + if self.TraceOn(): + print fmt.format(days_of_week) + print cvf.format(days_of_week) + # Get variable 'str_ptr'. value = frame0.FindVariable('str_ptr') self.assertTrue(value, VALID_VARIABLE) diff --git a/lldb/test/python_api/value/main.c b/lldb/test/python_api/value/main.c index 54d858033e3..108edfa8c8e 100644 --- a/lldb/test/python_api/value/main.c +++ b/lldb/test/python_api/value/main.c @@ -10,6 +10,8 @@ // This simple program is to test the lldb Python API SBValue.GetChildAtIndex(). +int g_my_int = 100; + const char *days_of_week[7] = { "Sunday", "Monday", "Tuesday", |

