1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2013-2014, Rene Gollent, rene@gollent.com. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include "UserBreakpoint.h" 9 10 #include "Function.h" 11 #include "FunctionID.h" 12 #include "LocatableFile.h" 13 14 15 // #pragma mark - UserBreakpointLocation 16 17 18 UserBreakpointLocation::UserBreakpointLocation(FunctionID* functionID, 19 LocatableFile* sourceFile, const SourceLocation& sourceLocation, 20 target_addr_t relativeAddress) 21 : 22 fFunctionID(functionID), 23 fSourceFile(sourceFile), 24 fSourceLocation(sourceLocation), 25 fRelativeAddress(relativeAddress) 26 { 27 fFunctionID->AcquireReference(); 28 if (fSourceFile != NULL) 29 fSourceFile->AcquireReference(); 30 } 31 32 33 UserBreakpointLocation::UserBreakpointLocation( 34 const UserBreakpointLocation& other) 35 : 36 fFunctionID(other.fFunctionID), 37 fSourceFile(other.fSourceFile), 38 fSourceLocation(other.fSourceLocation), 39 fRelativeAddress(other.fRelativeAddress) 40 { 41 fFunctionID->AcquireReference(); 42 if (fSourceFile != NULL) 43 fSourceFile->AcquireReference(); 44 } 45 46 47 UserBreakpointLocation::~UserBreakpointLocation() 48 { 49 fFunctionID->ReleaseReference(); 50 if (fSourceFile != NULL) 51 fSourceFile->ReleaseReference(); 52 } 53 54 55 UserBreakpointLocation& 56 UserBreakpointLocation::operator=( 57 const UserBreakpointLocation& other) 58 { 59 other.fFunctionID->AcquireReference(); 60 if (other.fSourceFile != NULL) 61 other.fSourceFile->AcquireReference(); 62 63 fFunctionID->ReleaseReference(); 64 if (fSourceFile != NULL) 65 fSourceFile->ReleaseReference(); 66 67 fFunctionID = other.fFunctionID; 68 fSourceFile = other.fSourceFile; 69 fSourceLocation = other.fSourceLocation; 70 fRelativeAddress = other.fRelativeAddress; 71 72 return *this; 73 } 74 75 76 // #pragma mark - UserBreakpointInstance 77 78 79 UserBreakpointInstance::UserBreakpointInstance(UserBreakpoint* userBreakpoint, 80 target_addr_t address) 81 : 82 fAddress(address), 83 fUserBreakpoint(userBreakpoint), 84 fBreakpoint(NULL) 85 { 86 } 87 88 89 void 90 UserBreakpointInstance::SetBreakpoint(Breakpoint* breakpoint) 91 { 92 fBreakpoint = breakpoint; 93 } 94 95 96 // #pragma mark - UserBreakpoint 97 98 99 UserBreakpoint::UserBreakpoint(const UserBreakpointLocation& location) 100 : 101 fLocation(location), 102 fValid(false), 103 fEnabled(false), 104 fHidden(false), 105 fConditionExpression() 106 { 107 } 108 109 110 UserBreakpoint::~UserBreakpoint() 111 { 112 for (int32 i = 0; UserBreakpointInstance* instance = fInstances.ItemAt(i); 113 i++) { 114 delete instance; 115 } 116 } 117 118 119 int32 120 UserBreakpoint::CountInstances() const 121 { 122 return fInstances.CountItems(); 123 } 124 125 126 UserBreakpointInstance* 127 UserBreakpoint::InstanceAt(int32 index) const 128 { 129 return fInstances.ItemAt(index); 130 } 131 132 133 bool 134 UserBreakpoint::AddInstance(UserBreakpointInstance* instance) 135 { 136 return fInstances.AddItem(instance); 137 } 138 139 140 void 141 UserBreakpoint::RemoveInstance(UserBreakpointInstance* instance) 142 { 143 fInstances.RemoveItem(instance); 144 } 145 146 147 UserBreakpointInstance* 148 UserBreakpoint::RemoveInstanceAt(int32 index) 149 { 150 return fInstances.RemoveItemAt(index); 151 } 152 153 154 void 155 UserBreakpoint::SetValid(bool valid) 156 { 157 fValid = valid; 158 } 159 160 161 void 162 UserBreakpoint::SetEnabled(bool enabled) 163 { 164 fEnabled = enabled; 165 } 166 167 168 void 169 UserBreakpoint::SetHidden(bool hidden) 170 { 171 fHidden = hidden; 172 } 173 174 175 void 176 UserBreakpoint::SetCondition(const BString& conditionExpression) 177 { 178 fConditionExpression = conditionExpression; 179 } 180