From 267f3c00bec6f35c6e106d562f9874a30c637db1 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 4 Dec 2016 18:01:07 -0500 Subject: [PATCH] Add backend Breakpoint support for symbolic breakpoints. --- Source/Breakpoint.h | 28 ++++++++++----- Source/Breakpoint.m | 87 ++++++++++++++++++++++++++++----------------- 2 files changed, 75 insertions(+), 40 deletions(-) diff --git a/Source/Breakpoint.h b/Source/Breakpoint.h index 8275623..a5acf4f 100644 --- a/Source/Breakpoint.h +++ b/Source/Breakpoint.h @@ -16,24 +16,36 @@ #import +extern NSString* const kBreakpointTypeFile; +extern NSString* const kBreakpointTypeFunctionEntry; + // This represents a breakpoint at a certain file and line number. It also // maintains the identifier that the backend assigns to the breakpoint. @interface Breakpoint : NSObject -{ - NSString* file_; - unsigned long line_; - unsigned long debuggerId_; -} +// The type of breakpoint, one of the kBreakpointType constants above. +@property (readonly) NSString* type; + +// The unique identifier assigned by the debugger engine, only valid while +// connected. +@property (readwrite, assign) unsigned long debuggerId; + +// kBreakpointTypeFile: @property (readonly) NSString* file; @property (readonly) unsigned long line; -@property (readwrite, assign) unsigned long debuggerId; -- (id)initWithLine:(unsigned long)l inFile:(NSString*)f; -- (id)initWithDictionary:(NSDictionary*)dict; +// kBreakpointTypeFunctionEntry: +@property (readonly) NSString* functionName; + +- (instancetype)initWithLine:(unsigned long)l inFile:(NSString*)f; +- (instancetype)initWithFunctionNamed:(NSString*)function; + +// Initializer from NSUserDefaults. +- (instancetype)initWithDictionary:(NSDictionary*)dict; - (NSString*)transformedPath; +// Creates a dictionary representation for use in NSUserDefaults. - (NSDictionary*)dictionary; @end diff --git a/Source/Breakpoint.m b/Source/Breakpoint.m index 1629a65..7a4b44c 100644 --- a/Source/Breakpoint.m +++ b/Source/Breakpoint.m @@ -18,47 +18,62 @@ #import "PreferenceNames.h" -@implementation Breakpoint +NSString* const kBreakpointTypeFile = @"line"; +NSString* const kBreakpointTypeFunctionEntry = @"call"; -@synthesize file = file_; -@synthesize line = line_; -@synthesize debuggerId = debuggerId_; +@implementation Breakpoint { + NSString* _type; // weak + unsigned long _debuggerId; -/** - * Initializes a breakpoint with a file and line - */ -- (id)initWithLine:(NSUInteger)l inFile:(NSString*)f + NSString* _file; + + NSString* _functionName; +} + +- (instancetype)initWithLine:(NSUInteger)l inFile:(NSString*)f { - if (self = [super init]) - { - file_ = [f retain]; - line_ = l; + if ((self = [super init])) { + _type = kBreakpointTypeFile; + _file = [f copy]; + _line = l; } return self; } -/** - * Dealloc - */ -- (void)dealloc -{ - [file_ release]; - [super dealloc]; +- (instancetype)initWithFunctionNamed:(NSString *)function { + if ((self = [super init])) { + _type = kBreakpointTypeFunctionEntry; + _functionName = [function copy]; + } + return self; } -/** - * Creates a Breakpoint from the values of an NSDictionary - */ - (id)initWithDictionary:(NSDictionary*)dict { - if (self = [super init]) - { - file_ = [[dict valueForKey:@"file"] retain]; - line_ = [[dict valueForKey:@"line"] intValue]; + if ((self = [super init])) { + NSString* type = [dict valueForKey:@"type"]; + if (!type || [type isEqualToString:kBreakpointTypeFile]) { + _type = kBreakpointTypeFile; + _file = [[dict valueForKey:@"file"] copy]; + _line = [[dict valueForKey:@"line"] intValue]; + } else if ([type isEqualToString:kBreakpointTypeFunctionEntry]) { + _type = kBreakpointTypeFunctionEntry; + _functionName = [[dict valueForKey:@"function"] copy]; + } else { + [NSException raise:NSInvalidArgumentException + format:@"Unknown Breakpoint type: %@", type]; + } } return self; } +- (void)dealloc +{ + [_file release]; + [_functionName release]; + [super dealloc]; +} + /** * Returns the transformed path for the breakpoint, as Xdebug needs it */ @@ -102,11 +117,19 @@ */ - (NSDictionary*)dictionary { - return [NSDictionary dictionaryWithObjectsAndKeys: - self.file, @"file", - [NSNumber numberWithInt:self.line], @"line", - nil - ]; + if (_type == kBreakpointTypeFile) { + return @{ + @"type" : _type, + @"file" : self.file, + @"line" : @(self.line) + }; + } else if (_type == kBreakpointTypeFunctionEntry) { + return @{ + @"type" : _type, + @"function" : self.functionName + }; + } + return nil; } /** @@ -114,7 +137,7 @@ */ - (NSString*)description { - return [NSString stringWithFormat:@"%@:%lu", self.file, self.line]; + return [NSString stringWithFormat:@"Breakpoint %@", [[self dictionary] description]]; } @end -- 2.43.5