3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 #import "Breakpoint.h"
19 #import "PreferenceNames.h"
21 NSString
* const kBreakpointTypeFile
= @
"line";
22 NSString
* const kBreakpointTypeFunctionEntry
= @
"call";
24 @implementation Breakpoint
{
25 NSString
* _type
; // weak
26 unsigned long _debuggerId
;
30 NSString
* _functionName
;
33 - (instancetype
)initWithLine
:(NSUInteger
)l inFile
:(NSString
*)f
35 if ((self = [super init
])) {
36 _type
= kBreakpointTypeFile
;
43 - (instancetype
)initWithFunctionNamed
:(NSString
*)function
{
44 if ((self = [super init
])) {
45 _type
= kBreakpointTypeFunctionEntry
;
46 _functionName
= [function copy
];
51 - (id)initWithDictionary
:(NSDictionary
*)dict
53 if ((self = [super init
])) {
54 NSString
* type
= [dict valueForKey
:@
"type"];
55 if (!type ||
[type isEqualToString
:kBreakpointTypeFile
]) {
56 _type
= kBreakpointTypeFile
;
57 _file
= [[dict valueForKey
:@
"file"] copy
];
58 _line
= [[dict valueForKey
:@
"line"] intValue
];
59 } else if ([type isEqualToString
:kBreakpointTypeFunctionEntry
]) {
60 _type
= kBreakpointTypeFunctionEntry
;
61 _functionName
= [[dict valueForKey
:@
"function"] copy
];
63 [NSException raise
:NSInvalidArgumentException
64 format
:@
"Unknown Breakpoint type: %@", type
];
73 [_functionName release
];
78 * Returns the transformed path for the breakpoint, as Xdebug needs it
80 - (NSString
*)transformedPath
82 NSString
* path
= self.file
;
84 NSMutableArray
* transforms
= [[NSUserDefaults standardUserDefaults
] mutableArrayValueForKey
:kPrefPathReplacements
];
85 if (!transforms ||
[transforms count
] < 1)
88 for (NSDictionary
* replacement
in transforms
)
91 stringByReplacingOccurrencesOfString
:[replacement valueForKey
:@
"local"]
92 withString
:[replacement valueForKey
:@
"remote"]
100 * Determines if two breakpoints are equal
102 - (BOOL)isEqual
:(id)obj
104 return ([[obj file
] isEqualToString
:self.file
] && [obj line
] == self.line
);
108 * Returns the hash value of a breakpoint
112 return ([self.file hash
] << 8) + self.line
;
116 * Returns an NSDictionary of the data so it can be stored in NSUserDefaults
118 - (NSDictionary
*)dictionary
120 if (_type
== kBreakpointTypeFile
) {
124 @
"line" : @
(self.line
)
126 } else if (_type
== kBreakpointTypeFunctionEntry
) {
129 @
"function" : self.functionName
138 - (NSString
*)description
140 return [NSString stringWithFormat
:@
"Breakpoint %@", [[self dictionary
] description
]];