Skip to content

Commit

Permalink
Detect and unbox pointers to objects from void *
Browse files Browse the repository at this point in the history
- Also unbox C strings into NSString
- Also adds return type encoding string to method calling view controller
  • Loading branch information
NSExceptional committed Mar 30, 2019
1 parent 22b7c6c commit 867ae61
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Classes/Editing/FLEXMethodCallingViewController.m
Expand Up @@ -9,12 +9,15 @@
#import "FLEXMethodCallingViewController.h"
#import "FLEXRuntimeUtility.h"
#import "FLEXFieldEditorView.h"
#import "FLEXObjectExplorerFactory.h"
#import "FLEXObjectExplorerViewController.h"
#import "FLEXArgumentInputView.h"
#import "FLEXArgumentInputViewFactory.h"

@interface FLEXMethodCallingViewController ()

@property (nonatomic, assign) Method method;
@property (nonatomic, assign) FLEXTypeEncoding *returnType;

@end

Expand All @@ -25,7 +28,8 @@ - (id)initWithTarget:(id)target method:(Method)method
self = [super initWithTarget:target];
if (self) {
self.method = method;
self.title = [self isClassMethod] ? @"Class Method" : @"Method";
self.returnType = [FLEXRuntimeUtility returnTypeForMethod:method];
self.title = [self isClassMethod] ? @"Class Method" : @"Method";;
}
return self;
}
Expand All @@ -34,7 +38,11 @@ - (void)viewDidLoad
{
[super viewDidLoad];

self.fieldEditorView.fieldDescription = [FLEXRuntimeUtility prettyNameForMethod:self.method isClassMethod:[self isClassMethod]];
NSString *returnType = @((const char *)self.returnType);
NSString *methodDescription = [FLEXRuntimeUtility prettyNameForMethod:self.method isClassMethod:[self isClassMethod]];
NSString *format = @"Signature:\n%@\n\nReturn Type:\n%@";
NSString *info = [NSString stringWithFormat:format, methodDescription, returnType];
self.fieldEditorView.fieldDescription = info;

NSArray<NSString *> *methodComponents = [FLEXRuntimeUtility prettyArgumentComponentsForMethod:self.method];
NSMutableArray<FLEXArgumentInputView *> *argumentInputViews = [NSMutableArray array];
Expand All @@ -52,6 +60,12 @@ - (void)viewDidLoad
self.fieldEditorView.argumentInputViews = argumentInputViews;
}

- (void)dealloc
{
free(self.returnType);
self.returnType = NULL;
}

- (BOOL)isClassMethod
{
return self.target && self.target == [self.target class];
Expand Down Expand Up @@ -84,6 +98,11 @@ - (void)actionButtonPressed:(id)sender
NSString *message = [error localizedDescription];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
} else if (returnedObject) {
// For non-nil (or void) return types, push an explorer view controller to display the returned object
returnedObject = [FLEXRuntimeUtility potentiallyUnwrapBoxedPointer:returnedObject type:self.returnType];
FLEXObjectExplorerViewController *explorerViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:returnedObject];
[self.navigationController pushViewController:explorerViewController animated:YES];
} else {
[self exploreObjectOrPopViewController:returnedObject];
}
Expand Down
5 changes: 5 additions & 0 deletions Classes/ObjectExplorers/FLEXObjectExplorerViewController.m
Expand Up @@ -367,7 +367,10 @@ - (id)valueForPropertyAtIndex:(NSInteger)index
id value = nil;
if ([self canHaveInstanceState]) {
FLEXPropertyBox *propertyBox = self.filteredProperties[index];
NSString *typeString = [FLEXRuntimeUtility typeEncodingForProperty:propertyBox.property];
const FLEXTypeEncoding *encoding = [typeString cStringUsingEncoding:NSUTF8StringEncoding];
value = [FLEXRuntimeUtility valueForProperty:propertyBox.property onObject:self.object];
value = [FLEXRuntimeUtility potentiallyUnwrapBoxedPointer:value type:encoding];
}
return value;
}
Expand Down Expand Up @@ -449,7 +452,9 @@ - (id)valueForIvarAtIndex:(NSInteger)index
id value = nil;
if ([self canHaveInstanceState]) {
FLEXIvarBox *ivarBox = self.filteredIvars[index];
const FLEXTypeEncoding *encoding = ivar_getTypeEncoding(ivarBox.ivar);
value = [FLEXRuntimeUtility valueForIvar:ivarBox.ivar onObject:self.object];
value = [FLEXRuntimeUtility potentiallyUnwrapBoxedPointer:value type:encoding];

This comment has been minimized.

Copy link
@ryanolsonk

ryanolsonk May 31, 2019

Member

@NSExceptional Noticed this is crashing if you tap on the frame or bounds properties on a view on device (iPhone 7). Looks like it gets choked up on the _typeInfo field of NSValue. We should be pushing an editor rather than an object explorer for those properties, so I'm going to put up a commit for that, but it would be awesome to handle the crash that's happening for exploring certain NSValue objects also.

This comment has been minimized.

Copy link
@NSExceptional

NSExceptional May 31, 2019

Author Collaborator

Interesting. I've seen reports of this but I've been unable to reproduce it—I still see the editor. Do you have a crash log?

This comment has been minimized.

Copy link
@ryanolsonk

ryanolsonk May 31, 2019

Member

I think if you hardcode canEditProperty:currentValue: to return NO you'll hit this. I'll paste the trace in a minute.

This comment has been minimized.

Copy link
@ryanolsonk

ryanolsonk May 31, 2019

Member
OS Version:          iPhone OS 12.2 (16E227)
Baseband Version:    5.55.00
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000040
VM Region Info: 0x40 is not in any region.  Bytes before following region: 4298866624
      REGION TYPE                      START - END             [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                 00000001003b8000-0000000100b34000 [ 7664K] r-x/r-x SM=COW  ...app/<redacted>

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [19498]
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib               	0x0000000190bdbbf0 objc_retain + 16
1   <redacted>                     	0x000000010043d730 0x1003b8000 + 546608
<img width="474" alt="Screen Shot 2019-05-30 at 7 30 43 PM" src="https://user-images.githubusercontent.com/1422245/58677609-858ffe80-8311-11e9-931f-d1b4d136bcdf.png">

2   <redacted>                     	0x000000010042d178 0x1003b8000 + 479608
3   <redacted>                     	0x000000010042f824 0x1003b8000 + 489508
4   <redacted>                     	0x000000010043125c 0x1003b8000 + 496220
5   UIKitCore                     	0x00000001be1796a0 -[_UIFilteredDataSource tableView:cellForRowAtIndexPath:] + 100
6   UIKitCore                     	0x00000001be146a38 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 680
7   UIKitCore                     	0x00000001be146f38 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
8   UIKitCore                     	0x00000001be113740 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2260
9   UIKitCore                     	0x00000001be130a60 -[UITableView layoutSubviews] + 140
10  UIKitCore                     	0x00000001be3b3e54 -[UIView+ 13905492 (CALayerDelegate) layoutSublayersOfLayer:] + 1292
11  QuartzCore                    	0x0000000195e761f0 -[CALayer layoutSublayers] + 184
12  QuartzCore                    	0x0000000195e7b198 CA::Layer::layout_if_needed+ 1319320 (CA::Transaction*) + 332
13  QuartzCore                    	0x0000000195dde0a8 CA::Context::commit_transaction+ 676008 (CA::Transaction*) + 348
14  QuartzCore                    	0x0000000195e0c108 CA::Transaction::commit+ 864520 () + 640
15  UIKitCore                     	0x00000001bdf527b0 _afterCACommitHandler + 224
16  CoreFoundation                	0x000000019197989c __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
17  CoreFoundation                	0x00000001919745c4 __CFRunLoopDoObservers + 412
18  CoreFoundation                	0x0000000191974b40 __CFRunLoopRun + 1228
19  CoreFoundation                	0x0000000191974354 CFRunLoopRunSpecific + 436
20  GraphicsServices              	0x0000000193b7479c GSEventRunModal + 104
21  UIKitCore                     	0x00000001bdf2bb68 UIApplicationMain + 212
22  libUnfocused.dylib            	0x000000010283a224 0x1016f4000 + 18113060
23  <redacted>                     	0x00000001003befa4 0x1003b8000 + 28580
24  libdyld.dylib                 	0x000000019143a8e0 start + 4

Screen Shot 2019-05-30 at 7 32 15 PM

This comment has been minimized.

Copy link
@ryanolsonk

ryanolsonk May 31, 2019

Member

e07bfa8 ensures we get the editor VC on these properties

This comment has been minimized.

Copy link
@NSExceptional

NSExceptional Jun 13, 2019

Author Collaborator

70264c1 fixes the crash. See the commit message for what was happening. In this case, the CGRect is returned as NSConcreteValue, and when we have an NSValue we first try to "unwrap it." The unwrapping part was mistakenly detecting that the underlying memory (.pointerValue) was a real object, and it's not.

}
return value;
}
Expand Down

0 comments on commit 867ae61

Please sign in to comment.