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
)breakpointAtLine
:(unsigned long)line inFile
:(NSString
*)file
35 Breakpoint
* breakpoint
= [[[Breakpoint alloc
] init
] autorelease
];
36 breakpoint
->_type
= kBreakpointTypeFile
;
37 breakpoint
->_file
= [file copy
];
38 breakpoint
->_line
= line
;
42 + (instancetype
)breakpointOnFunctionNamed
:(NSString
*)name
44 Breakpoint
* breakpoint
= [[[Breakpoint alloc
] init
] autorelease
];
45 breakpoint
->_type
= kBreakpointTypeFunctionEntry
;
46 breakpoint
->_functionName
= [name copy
];
50 - (instancetype
)initWithDictionary
:(NSDictionary
*)dict
52 if ((self = [super init
])) {
53 NSString
* type
= [dict valueForKey
:@
"type"];
54 if (!type ||
[type isEqualToString
:kBreakpointTypeFile
]) {
55 _type
= kBreakpointTypeFile
;
56 _file
= [[dict valueForKey
:@
"file"] copy
];
57 _line
= [[dict valueForKey
:@
"line"] intValue
];
58 } else if ([type isEqualToString
:kBreakpointTypeFunctionEntry
]) {
59 _type
= kBreakpointTypeFunctionEntry
;
60 _functionName
= [[dict valueForKey
:@
"function"] copy
];
62 [NSException raise
:NSInvalidArgumentException
63 format
:@
"Unknown Breakpoint type: %@", type
];
72 [_functionName release
];
77 * Returns the string to display in the breakpoints list.
79 - (NSString
*)displayValue
81 if (self.type
== kBreakpointTypeFile
) {
82 return [NSString stringWithFormat
:@
"%@:%ld", self.file
, self.line
];
83 } else if (self.type
== kBreakpointTypeFunctionEntry
) {
84 return [NSString stringWithFormat
:@
"%@()", self.functionName
];
90 * Returns the transformed path for the breakpoint, as Xdebug needs it
92 - (NSString
*)transformedPath
94 NSString
* path
= self.file
;
96 NSMutableArray
* transforms
= [[NSUserDefaults standardUserDefaults
] mutableArrayValueForKey
:kPrefPathReplacements
];
97 if (!transforms ||
[transforms count
] < 1)
100 for (NSDictionary
* replacement
in transforms
)
103 stringByReplacingOccurrencesOfString
:[replacement valueForKey
:@
"local"]
104 withString
:[replacement valueForKey
:@
"remote"]
111 - (BOOL)isEqual
:(id)obj
113 if (![obj isKindOfClass
:[self class]]) {
117 Breakpoint
* other
= obj
;
118 if (self.type
!= other.type
) {
122 if (self.type
== kBreakpointTypeFile
) {
123 return [self.file isEqualToString
:other.file
] && self.line
== other.line
;
124 } else if (self.type
== kBreakpointTypeFunctionEntry
) {
125 return [self.functionName isEqualToString
:other.functionName
];
131 - (NSDictionary
*)dictionary
133 if (self.type
== kBreakpointTypeFile
) {
137 @
"line" : @
(self.line
)
139 } else if (self.type
== kBreakpointTypeFunctionEntry
) {
142 @
"function" : self.functionName
148 - (NSString
*)description
150 return [NSString stringWithFormat
:@
"Breakpoint %@", [[self dictionary
] description
]];