summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2016-09-01 18:09:01 +0000
committerEnrico Granata <egranata@apple.com>2016-09-01 18:09:01 +0000
commitdf43d25fd366d96cd7af1ead8938ed0d2394e2fb (patch)
treeb9a9bcb87e3831384559c79976341616170b1a0b
parent5c7c2307a83665c4861e173a8f4ec4f514c0bbd6 (diff)
downloadbcm5719-llvm-df43d25fd366d96cd7af1ead8938ed0d2394e2fb.tar.gz
bcm5719-llvm-df43d25fd366d96cd7af1ead8938ed0d2394e2fb.zip
Change the formula for tagged NSIndexPath data formatting
Fixes rdar://25192935 llvm-svn: 280389
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/Makefile9
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/TestDataFormatterNSIndexPath.py70
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/main.m31
-rw-r--r--lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp40
4 files changed, 139 insertions, 11 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/Makefile
new file mode 100644
index 00000000000..0d94c2247f1
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/Makefile
@@ -0,0 +1,9 @@
+LEVEL = ../../../../make
+
+OBJC_SOURCES := main.m
+
+CFLAGS_EXTRAS += -w
+
+include $(LEVEL)/Makefile.rules
+
+LDFLAGS += -framework Foundation
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/TestDataFormatterNSIndexPath.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/TestDataFormatterNSIndexPath.py
new file mode 100644
index 00000000000..89145553d35
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/TestDataFormatterNSIndexPath.py
@@ -0,0 +1,70 @@
+# encoding: utf-8
+"""
+Test lldb data formatter subsystem.
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+import datetime
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class NSIndexPathDataFormatterTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def appkit_tester_impl(self,commands):
+ self.build()
+ self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+ lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['stopped',
+ 'stop reason = breakpoint'])
+
+ # This is the function to remove the custom formats in order to have a
+ # clean slate for the next test case.
+ def cleanup():
+ self.runCmd('type format clear', check=False)
+ self.runCmd('type summary clear', check=False)
+ self.runCmd('type synth clear', check=False)
+
+
+ # Execute the cleanup function during test case tear down.
+ self.addTearDownHook(cleanup)
+ commands()
+
+ @skipUnlessDarwin
+ def test_nsindexpath_with_run_command(self):
+ """Test formatters for NSIndexPath."""
+ self.appkit_tester_impl(self.nsindexpath_data_formatter_commands)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break at.
+ self.line = line_number('main.m', '// break here')
+
+ def nsindexpath_data_formatter_commands(self):
+ # check 'frame variable'
+ self.expect('frame variable --ptr-depth=1 -d run -- indexPath1', substrs = ['[0] = 1'])
+ self.expect('frame variable --ptr-depth=1 -d run -- indexPath2', substrs = ['[0] = 1', '[1] = 2'])
+ self.expect('frame variable --ptr-depth=1 -d run -- indexPath3', substrs = ['[0] = 1', '[1] = 2', '[2] = 3'])
+ self.expect('frame variable --ptr-depth=1 -d run -- indexPath4', substrs = ['[0] = 1', '[1] = 2', '[2] = 3', '[3] = 4'])
+ self.expect('frame variable --ptr-depth=1 -d run -- indexPath5', substrs = ['[0] = 1', '[1] = 2', '[2] = 3', '[3] = 4', '[4] = 5'])
+
+ # and 'expression'
+ self.expect('expression --ptr-depth=1 -d run -- indexPath1', substrs = ['[0] = 1'])
+ self.expect('expression --ptr-depth=1 -d run -- indexPath2', substrs = ['[0] = 1', '[1] = 2'])
+ self.expect('expression --ptr-depth=1 -d run -- indexPath3', substrs = ['[0] = 1', '[1] = 2', '[2] = 3'])
+ self.expect('expression --ptr-depth=1 -d run -- indexPath4', substrs = ['[0] = 1', '[1] = 2', '[2] = 3', '[3] = 4'])
+ self.expect('expression --ptr-depth=1 -d run -- indexPath5', substrs = ['[0] = 1', '[1] = 2', '[2] = 3', '[3] = 4', '[4] = 5'])
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/main.m b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/main.m
new file mode 100644
index 00000000000..baaff180e34
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/main.m
@@ -0,0 +1,31 @@
+//===-- main.m ------------------------------------------------*- ObjC -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#import <Foundation/Foundation.h>
+
+int main(int argc, const char **argv)
+{
+ @autoreleasepool
+ {
+ const NSUInteger values[] = { 1, 2, 3, 4, 5 };
+
+ NSIndexPath* indexPath1 = [NSIndexPath indexPathWithIndexes:values length:1];
+ NSIndexPath* indexPath2 = [NSIndexPath indexPathWithIndexes:values length:2];
+ NSIndexPath* indexPath3 = [NSIndexPath indexPathWithIndexes:values length:3];
+ NSIndexPath* indexPath4 = [NSIndexPath indexPathWithIndexes:values length:4];
+ NSIndexPath* indexPath5 = [NSIndexPath indexPathWithIndexes:values length:5];
+
+ NSLog(@"%@", indexPath1); // break here
+ NSLog(@"%@", indexPath2);
+ NSLog(@"%@", indexPath3);
+ NSLog(@"%@", indexPath4);
+ NSLog(@"%@", indexPath5);
+ }
+ return 0;
+}
diff --git a/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp b/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp
index 0c8a54d76df..0bebaca256b 100644
--- a/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp
@@ -26,6 +26,18 @@ using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
+static constexpr size_t
+PACKED_INDEX_SHIFT_64(size_t i)
+{
+ return (60 - (13 * (4-i)));
+}
+
+static constexpr size_t
+PACKED_INDEX_SHIFT_32(size_t i)
+{
+ return (32 - (13 * (2-i)));
+}
+
class NSIndexPathSyntheticFrontEnd : public SyntheticChildrenFrontEnd
{
public:
@@ -284,23 +296,29 @@ protected:
std::pair<uint64_t, bool>
_indexAtPositionForInlinePayload(size_t pos)
{
+ static const uint64_t PACKED_INDEX_MASK = ((1 << 13) - 1);
if (m_ptr_size == 8)
{
- switch (pos) {
- case 5: return {((m_indexes >> 51) & 0x1ff),true};
- case 4: return {((m_indexes >> 42) & 0x1ff),true};
- case 3: return {((m_indexes >> 33) & 0x1ff),true};
- case 2: return {((m_indexes >> 24) & 0x1ff),true};
- case 1: return {((m_indexes >> 15) & 0x1ff),true};
- case 0: return {((m_indexes >> 6) & 0x1ff),true};
+ switch (pos)
+ {
+ case 3:
+ case 2:
+ case 1:
+ case 0:
+ return {(m_indexes >> PACKED_INDEX_SHIFT_64(pos)) & PACKED_INDEX_MASK,true};
+ default:
+ return {0,false};
}
}
else
{
- switch (pos) {
- case 2: return {((m_indexes >> 23) & 0x1ff),true};
- case 1: return {((m_indexes >> 14) & 0x1ff),true};
- case 0: return {((m_indexes >> 5) & 0x1ff),true};
+ switch (pos)
+ {
+ case 0:
+ case 1:
+ return {(m_indexes >> PACKED_INDEX_SHIFT_32(pos)) & PACKED_INDEX_MASK,true};
+ default:
+ return {0,false};
}
}
return {0,false};
OpenPOWER on IntegriCloud