forked from OSchip/llvm-project
Change the formula for tagged NSIndexPath data formatting
Fixes rdar://25192935 llvm-svn: 280389
This commit is contained in:
parent
5c7c2307a8
commit
df43d25fd3
|
@ -0,0 +1,9 @@
|
|||
LEVEL = ../../../../make
|
||||
|
||||
OBJC_SOURCES := main.m
|
||||
|
||||
CFLAGS_EXTRAS += -w
|
||||
|
||||
include $(LEVEL)/Makefile.rules
|
||||
|
||||
LDFLAGS += -framework Foundation
|
|
@ -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'])
|
|
@ -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;
|
||||
}
|
|
@ -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};
|
||||
|
|
Loading…
Reference in New Issue