Skip to content

Commit

Permalink
Add libflex
Browse files Browse the repository at this point in the history
  • Loading branch information
NSExceptional committed Sep 21, 2022
1 parent e616004 commit 98f4409
Show file tree
Hide file tree
Showing 175 changed files with 6,818 additions and 0 deletions.
209 changes: 209 additions & 0 deletions FLEX/ActivityStreamAPI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
//
// Taken from https://github.com/llvm-mirror/lldb/blob/master/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h
// by Tanner Bennett on 03/03/2019 with minimal modifications.
//

//===-- ActivityStreamAPI.h -------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef ActivityStreamSPI_h
#define ActivityStreamSPI_h

#include <Foundation/Foundation.h>

#include <sys/time.h>
// #include <xpc/xpc.h>

/* By default, XPC objects are declared as Objective-C types when building with
* an Objective-C compiler. This allows them to participate in ARC, in RR
* management by the Blocks runtime and in leaks checking by the static
* analyzer, and enables them to be added to Cocoa collections.
*
* See <os/object.h> for details.
*/
#if !TARGET_OS_MACCATALYST
#if OS_OBJECT_USE_OBJC
OS_OBJECT_DECL(xpc_object);
#else
typedef void * xpc_object_t;
#endif
#endif

#define OS_ACTIVITY_MAX_CALLSTACK 32

// Enums

typedef NS_ENUM(uint32_t, os_activity_stream_flag_t) {
OS_ACTIVITY_STREAM_PROCESS_ONLY = 0x00000001,
OS_ACTIVITY_STREAM_SKIP_DECODE = 0x00000002,
OS_ACTIVITY_STREAM_PAYLOAD = 0x00000004,
OS_ACTIVITY_STREAM_HISTORICAL = 0x00000008,
OS_ACTIVITY_STREAM_CALLSTACK = 0x00000010,
OS_ACTIVITY_STREAM_DEBUG = 0x00000020,
OS_ACTIVITY_STREAM_BUFFERED = 0x00000040,
OS_ACTIVITY_STREAM_NO_SENSITIVE = 0x00000080,
OS_ACTIVITY_STREAM_INFO = 0x00000100,
OS_ACTIVITY_STREAM_PROMISCUOUS = 0x00000200,
OS_ACTIVITY_STREAM_PRECISE_TIMESTAMPS = 0x00000200
};

typedef NS_ENUM(uint32_t, os_activity_stream_type_t) {
OS_ACTIVITY_STREAM_TYPE_ACTIVITY_CREATE = 0x0201,
OS_ACTIVITY_STREAM_TYPE_ACTIVITY_TRANSITION = 0x0202,
OS_ACTIVITY_STREAM_TYPE_ACTIVITY_USERACTION = 0x0203,

OS_ACTIVITY_STREAM_TYPE_TRACE_MESSAGE = 0x0300,

OS_ACTIVITY_STREAM_TYPE_LOG_MESSAGE = 0x0400,
OS_ACTIVITY_STREAM_TYPE_LEGACY_LOG_MESSAGE = 0x0480,

OS_ACTIVITY_STREAM_TYPE_SIGNPOST_BEGIN = 0x0601,
OS_ACTIVITY_STREAM_TYPE_SIGNPOST_END = 0x0602,
OS_ACTIVITY_STREAM_TYPE_SIGNPOST_EVENT = 0x0603,

OS_ACTIVITY_STREAM_TYPE_STATEDUMP_EVENT = 0x0A00,
};

typedef NS_ENUM(uint32_t, os_activity_stream_event_t) {
OS_ACTIVITY_STREAM_EVENT_STARTED = 1,
OS_ACTIVITY_STREAM_EVENT_STOPPED = 2,
OS_ACTIVITY_STREAM_EVENT_FAILED = 3,
OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED = 4,
OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED = 5,
};

// Types

typedef uint64_t os_activity_id_t;
typedef struct os_activity_stream_s *os_activity_stream_t;
typedef struct os_activity_stream_entry_s *os_activity_stream_entry_t;

#define OS_ACTIVITY_STREAM_COMMON() \
uint64_t trace_id; \
uint64_t timestamp; \
uint64_t thread; \
const uint8_t *image_uuid; \
const char *image_path; \
struct timeval tv_gmt; \
struct timezone tz; \
uint32_t offset

typedef struct os_activity_stream_common_s {
OS_ACTIVITY_STREAM_COMMON();
} * os_activity_stream_common_t;

struct os_activity_create_s {
OS_ACTIVITY_STREAM_COMMON();
const char *name;
os_activity_id_t creator_aid;
uint64_t unique_pid;
};

struct os_activity_transition_s {
OS_ACTIVITY_STREAM_COMMON();
os_activity_id_t transition_id;
};

typedef struct os_log_message_s {
OS_ACTIVITY_STREAM_COMMON();
const char *format;
const uint8_t *buffer;
size_t buffer_sz;
const uint8_t *privdata;
size_t privdata_sz;
const char *subsystem;
const char *category;
uint32_t oversize_id;
uint8_t ttl;
bool persisted;
} * os_log_message_t;

typedef struct os_trace_message_v2_s {
OS_ACTIVITY_STREAM_COMMON();
const char *format;
const void *buffer;
size_t bufferLen;
xpc_object_t __unsafe_unretained payload;
} * os_trace_message_v2_t;

typedef struct os_activity_useraction_s {
OS_ACTIVITY_STREAM_COMMON();
const char *action;
bool persisted;
} * os_activity_useraction_t;

typedef struct os_signpost_s {
OS_ACTIVITY_STREAM_COMMON();
const char *format;
const uint8_t *buffer;
size_t buffer_sz;
const uint8_t *privdata;
size_t privdata_sz;
const char *subsystem;
const char *category;
uint64_t duration_nsec;
uint32_t callstack_depth;
uint64_t callstack[OS_ACTIVITY_MAX_CALLSTACK];
} * os_signpost_t;

typedef struct os_activity_statedump_s {
OS_ACTIVITY_STREAM_COMMON();
char *message;
size_t message_size;
char image_path_buffer[PATH_MAX];
} * os_activity_statedump_t;

struct os_activity_stream_entry_s {
os_activity_stream_type_t type;

// information about the process streaming the data
pid_t pid;
uint64_t proc_id;
const uint8_t *proc_imageuuid;
const char *proc_imagepath;

// the activity associated with this streamed event
os_activity_id_t activity_id;
os_activity_id_t parent_id;

union {
struct os_activity_stream_common_s common;
struct os_activity_create_s activity_create;
struct os_activity_transition_s activity_transition;
struct os_log_message_s log_message;
struct os_trace_message_v2_s trace_message;
struct os_activity_useraction_s useraction;
struct os_signpost_s signpost;
struct os_activity_statedump_s statedump;
};
};

// Blocks

typedef bool (^os_activity_stream_block_t)(os_activity_stream_entry_t entry,
int error);

typedef void (^os_activity_stream_event_block_t)(
os_activity_stream_t stream, os_activity_stream_event_t event);

// SPI entry point prototypes

typedef os_activity_stream_t (*os_activity_stream_for_pid_t)(
pid_t pid, os_activity_stream_flag_t flags,
os_activity_stream_block_t stream_block);

typedef void (*os_activity_stream_resume_t)(os_activity_stream_t stream);

typedef void (*os_activity_stream_cancel_t)(os_activity_stream_t stream);

typedef char *(*os_log_copy_formatted_message_t)(os_log_message_t log_message);

typedef void (*os_activity_stream_set_event_handler_t)(
os_activity_stream_t stream, os_activity_stream_event_block_t block);

#endif /* ActivityStreamSPI_h */
15 changes: 15 additions & 0 deletions FLEX/CALayer+FLEX.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// CALayer+FLEX.h
// FLEX
//
// Created by Tanner on 2/28/20.
// Copyright © 2020 FLEX Team. All rights reserved.
//

#import <QuartzCore/QuartzCore.h>

@interface CALayer (FLEX)

@property (nonatomic) BOOL flex_continuousCorners;

@end
22 changes: 22 additions & 0 deletions FLEX/FHSRangeSlider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// FHSRangeSlider.h
// FLEX
//
// Created by Tanner Bennett on 1/7/20.
// Copyright © 2020 FLEX Team. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface FHSRangeSlider : UIControl

@property (nonatomic) CGFloat allowedMinValue;
@property (nonatomic) CGFloat allowedMaxValue;
@property (nonatomic) CGFloat minValue;
@property (nonatomic) CGFloat maxValue;

@end

NS_ASSUME_NONNULL_END
37 changes: 37 additions & 0 deletions FLEX/FHSSnapshotNodes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// FHSSnapshotNodes.h
// FLEX
//
// Created by Tanner Bennett on 1/7/20.
//

#import "FHSViewSnapshot.h"
#import <SceneKit/SceneKit.h>

NS_ASSUME_NONNULL_BEGIN

/// Container that holds references to the SceneKit nodes associated with a snapshot.
@interface FHSSnapshotNodes : NSObject

+ (instancetype)snapshot:(FHSViewSnapshot *)snapshot depth:(NSInteger)depth;

@property (nonatomic, readonly) FHSViewSnapshot *snapshotItem;
@property (nonatomic, readonly) NSInteger depth;

/// The view image itself
@property (nonatomic, nullable) SCNNode *snapshot;
/// Goes on top of the snapshot, has rounded top corners
@property (nonatomic, nullable) SCNNode *header;
/// The bounding box drawn around the snapshot
@property (nonatomic, nullable) SCNNode *border;

/// Used to indicate when a view is selected
@property (nonatomic, getter=isHighlighted) BOOL highlighted;
/// Used to indicate when a view is de-emphasized
@property (nonatomic, getter=isDimmed) BOOL dimmed;

@property (nonatomic) BOOL forceHideHeader;

@end

NS_ASSUME_NONNULL_END
46 changes: 46 additions & 0 deletions FLEX/FHSSnapshotView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// FHSSnapshotView.h
// FLEX
//
// Created by Tanner Bennett on 1/7/20.
// Copyright © 2020 FLEX Team. All rights reserved.
//

#import "FHSViewSnapshot.h"
#import "FHSRangeSlider.h"

NS_ASSUME_NONNULL_BEGIN

@protocol FHSSnapshotViewDelegate <NSObject>

- (void)didSelectView:(FHSViewSnapshot *)snapshot;
- (void)didDeselectView:(FHSViewSnapshot *)snapshot;
- (void)didLongPressView:(FHSViewSnapshot *)snapshot;

@end

@interface FHSSnapshotView : UIView

+ (instancetype)delegate:(id<FHSSnapshotViewDelegate>)delegate;

@property (nonatomic, weak) id<FHSSnapshotViewDelegate> delegate;

@property (nonatomic) NSArray<FHSViewSnapshot *> *snapshots;
@property (nonatomic, nullable) FHSViewSnapshot *selectedView;

/// Views of these classes will have their headers hidden
@property (nonatomic) NSArray<Class> *headerExclusions;

@property (nonatomic, readonly) UISlider *spacingSlider;
@property (nonatomic, readonly) FHSRangeSlider *depthSlider;

- (void)emphasizeViews:(NSArray<UIView *> *)emphasizedViews;

- (void)toggleShowHeaders;
- (void)toggleShowBorders;

- (void)hideView:(FHSViewSnapshot *)view;

@end

NS_ASSUME_NONNULL_END
35 changes: 35 additions & 0 deletions FLEX/FHSView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// FHSView.h
// FLEX
//
// Created by Tanner Bennett on 1/6/20.
//

#import <UIKit/UIKit.h>

@interface FHSView : NSObject {
@private
BOOL _inScrollView;
}

+ (instancetype)forView:(UIView *)view isInScrollView:(BOOL)inScrollView;

/// Intentionally not weak
@property (nonatomic, readonly) UIView *view;
@property (nonatomic, readonly) NSString *identifier;

@property (nonatomic, readonly) NSString *title;
/// Whether or not this view item should be visually distinguished
@property (nonatomic, readwrite) BOOL important;

@property (nonatomic, readonly) CGRect frame;
@property (nonatomic, readonly) BOOL hidden;
@property (nonatomic, readonly) UIImage *snapshotImage;

@property (nonatomic, readonly) NSArray<FHSView *> *children;
@property (nonatomic, readonly) NSString *summary;

/// @return importantAttr if .important, otherwise normalAttr
//- (id)ifImportant:(id)importantAttr ifNormal:(id)normalAttr;

@end
29 changes: 29 additions & 0 deletions FLEX/FHSViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// FHSViewController.h
// FLEX
//
// Created by Tanner Bennett on 1/6/20.
// Copyright © 2020 FLEX Team. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/// The view controller
/// "FHS" stands for "FLEX (view) hierarchy snapshot"
@interface FHSViewController : UIViewController

/// Use this when you want to snapshot a set of windows.
+ (instancetype)snapshotWindows:(NSArray<UIWindow *> *)windows;
/// Use this when you want to snapshot a specific slice of the view hierarchy.
+ (instancetype)snapshotView:(UIView *)view;
/// Use this when you want to emphasize specific views on the screen.
/// These views must all be in the same window as the selected view.
+ (instancetype)snapshotViewsAtTap:(NSArray<UIView *> *)viewsAtTap selectedView:(UIView *)view;

@property (nonatomic, nullable) UIView *selectedView;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 98f4409

Please sign in to comment.