Remote Logging and Object Inspection #46

Merged
merged 11 commits into from Apr 30, 2013

Projects

None yet

5 participants

@wlue
Collaborator
wlue commented Feb 3, 2013

EDIT: README done!

This pull request adds remote logging via PDLog() and PDLogObjects() functions. It outputs the results into the Console tab of DevTools. This is the precursor to getting a functional REPL working for PonyDebugger.

PDLog() works like NSLog(). PDLogObjects() takes NSObjects and outputs them with full inspection capability. So doing PDLogObjects(@"This is the app:", [UIApplication sharedApplication]) would show the full text, and the introspectable application singleton.

Things that I did in this pull request:

  • Updated PDTwitterTest, since Twitter deprecated their public timeline endpoint. The test app only uses search functionality. However, this is going to be deprecated at some point, so we'll have to find an alternative eventually.
  • Added PDConsoleDomainController to handle console output.
  • Removed PDArrayContainer/PDDictionaryContainer, and replaced it with implementations using categories. It simplified the code that creates PDRuntimeRemoteObjects, though it does make NSSet slower since order is never stored anywhere.
@mikelikespie mikelikespie was assigned Feb 3, 2013
wlue added some commits Jan 30, 2013
@wlue wlue Basic PDLog functionality. Need to fix up interface, and add more var…
…iables.
724c2c8
@wlue wlue Re-organizing classes/categories.
Making PDLog/PDLogObjects. Re-working property descriptor calculation, fixing Twitter Test app.
27521b9
@wlue
Collaborator
wlue commented Mar 10, 2013

README done!

@ryanolsonk ryanolsonk commented on the diff Mar 14, 2013
ObjC/PonyDebugger/NSObject+PDRuntimePropertyDescriptor.m
@@ -160,12 +187,21 @@ - (PDRuntimePropertyDescriptor *)PD_propertyDescriptorForSelector:(SEL)selector;
return descriptor;
}
-- (PDRuntimePropertyDescriptor *)PD_propertyDescriptorForProperty:(NSString *)propertyName;
+- (PDRuntimePropertyDescriptor *)PD_propertyDescriptorForPropertyName:(NSString *)propertyName property:(objc_property_t)property
@ryanolsonk
ryanolsonk Mar 14, 2013 Contributor

What is the reason for adding the property argument here? I don't see it referenced in the method.

@wlue
wlue Mar 16, 2013 Collaborator

I originally did that because valueForKey does not work for all types of data. In the future, when I have a bit more time to hack around with the runtime, the way to grab the actual data would be to use the reference of the property_t, which is computed where it's called.

@ryanolsonk ryanolsonk and 1 other commented on an outdated diff Mar 14, 2013
ObjC/PonyDebugger/NSObject+PDRuntimePropertyDescriptor.m
@@ -16,13 +16,93 @@
#import <PonyDebugger/PDRuntimeTypes.h>
#import <PonyDebugger/PDArrayContainer.h>
#import <PonyDebugger/PDDictionaryContainer.h>
@ryanolsonk
ryanolsonk Mar 14, 2013 Contributor

PDDictionaryContainer and PDArrayContainer have been removed/renamed.

@wlue
wlue Mar 16, 2013 Collaborator

Good catch!

@ryanolsonk ryanolsonk and 1 other commented on an outdated diff Mar 14, 2013
...nyDebugger/NSOrderedSet+PDRuntimePropertyDescriptor.h
+// NSOrderedSet+PDRuntimePropertyDescriptor.h
+// PonyDebugger
+//
+// Created by Wen-Hao Lue on 2013-02-03.
+//
+// Licensed to Square, Inc. under one or more contributor license agreements.
+// See the LICENSE file distributed with this work for the terms under
+// which Square, Inc. licenses this file to you.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSOrderedSet (PDRuntimePropertyDescriptor)
+
+- (id)PD_objectAtIndex:(NSUInteger)index;
+
@ryanolsonk
ryanolsonk Mar 14, 2013 Contributor

Does this category need - (PDRuntimePropertyDescriptor *)PD_propertyDescriptorForPropertyObject:(NSObject *)property; like the others?

@wlue
wlue Mar 16, 2013 Collaborator

It uses the superclass method, which is on NSSet, so it should be fine.

@ryanolsonk
ryanolsonk Mar 16, 2013 Contributor

NSOrderedSet is (somewhat surprisingly) not a subclass of NSSet. It inherits directly from NSObject. http://nshipster.com/nsorderedset/

@wlue
wlue Mar 16, 2013 Collaborator

Ah, I assumed wrong, thanks.

@ryanolsonk ryanolsonk commented on the diff Mar 14, 2013
ObjC/PonyDebugger/PDConsoleDomainController.m
+ }
+
+ [text deleteCharactersInRange:NSMakeRange(text.length - 1, 1)];
+
+ PDConsoleConsoleMessage *consoleMessage = [[PDConsoleConsoleMessage alloc] init];
+ consoleMessage.level = @"log";
+ consoleMessage.source = @"console-api";
+ consoleMessage.stackTrace = [[NSArray alloc] init];
+ consoleMessage.parameters = parameters;
+ consoleMessage.repeatCount = [NSNumber numberWithInteger:1];
+ consoleMessage.text = text;
+
+ [self.domain messageAddedWithMessage:consoleMessage];
+}
+
+- (void)clear;
@ryanolsonk
ryanolsonk Mar 14, 2013 Contributor

Would it make sense to expose this in the header and add a public method on PDDebugger that calls through to it?

@wlue
wlue Mar 16, 2013 Collaborator

Great idea!

@ryanolsonk ryanolsonk commented on the diff Mar 14, 2013
ObjC/PonyDebugger/PDConsoleDomainController.m
+ });
+
+ return defaultInstance;
+}
+
++ (Class)domainClass;
+{
+ return [PDConsoleDomain class];
+}
+
+#pragma mark - PDConsoleCommandDelegate
+
+// Clears console messages collected in the browser.
+- (void)domain:(PDConsoleDomain *)domain clearMessagesWithCallback:(void (^)(id error))callback;
+{
+ callback(nil);
@ryanolsonk
ryanolsonk Mar 14, 2013 Contributor

I'm wondering if the PDRuntimeDomainController could get rid of its objectReferences when the console is cleared. Seems unnecessary to keep them around.

@wlue
wlue Mar 16, 2013 Collaborator

Right, probably could do that with a list that temporarily stores the references it's holding. Good catch.

@ryanolsonk
Contributor

I checked out the branch and took a look through the code. Very cool stuff! It's awesome to see this project continue to move forward. I haven't had a chance to test it other than what's in the example app, but for the most part it looks pretty good to me.

@ryanolsonk
Contributor

It would also be cool to have something like an "inherited" pseudo property on all objects that have a superclass so that you could view any inherited properties. I tried just showing all the inherited properties alongside the properties of the instance's class but it gets too crowded. I think it's useful information though if the presentation was right.

Without inherited:
Screen Shot 2013-03-14 at 5 23 41 PM

With inherited:
Screen Shot 2013-03-14 at 5 19 22 PM

This was referenced Mar 16, 2013
@jakemarsh

This seems wonderful, any idea when this might be merged into master?

@mikelikespie
Collaborator

LGTM btw

@wlue
Collaborator
wlue commented Apr 4, 2013

@jakemarsh Working on it!

@siuying
siuying commented Apr 15, 2013

very cool!

@wlue wlue merged commit 7c9f983 into square:master Apr 30, 2013
@wlue wlue deleted the wlue:remote-logging branch Apr 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment