| 215 | } |
| 216 | |
| 217 | bool CDebugger::CheckBreakPoint(asIScriptContext *ctx) |
| 218 | { |
| 219 | if( ctx == 0 ) |
| 220 | return false; |
| 221 | |
| 222 | // TODO: Should cache the break points in a function by checking which possible break points |
| 223 | // can be hit when entering a function. If there are no break points in the current function |
| 224 | // then there is no need to check every line. |
| 225 | |
| 226 | const char *tmp = 0; |
| 227 | int lineNbr = ctx->GetLineNumber(0, 0, &tmp); |
| 228 | |
| 229 | // Consider just filename, not the full path |
| 230 | string file = tmp ? tmp : ""; |
| 231 | size_t r = file.find_last_of("\\/"); |
| 232 | if( r != string::npos ) |
| 233 | file = file.substr(r+1); |
| 234 | |
| 235 | // Did we move into a new function? |
| 236 | asIScriptFunction *func = ctx->GetFunction(); |
| 237 | if( m_lastFunction != func ) |
| 238 | { |
| 239 | // Check if any breakpoints need adjusting |
| 240 | for( size_t n = 0; n < m_breakPoints.size(); n++ ) |
| 241 | { |
| 242 | // We need to check for a breakpoint at entering the function |
| 243 | if( m_breakPoints[n].func ) |
| 244 | { |
| 245 | if( m_breakPoints[n].name == func->GetName() ) |
| 246 | { |
| 247 | stringstream s; |
| 248 | s << "Entering function '" << m_breakPoints[n].name << "'. Transforming it into break point" << endl; |
| 249 | Output(s.str()); |
| 250 | |
| 251 | // Transform the function breakpoint into a file breakpoint |
| 252 | m_breakPoints[n].name = file; |
| 253 | m_breakPoints[n].lineNbr = lineNbr; |
| 254 | m_breakPoints[n].func = false; |
| 255 | m_breakPoints[n].needsAdjusting = false; |
| 256 | } |
| 257 | } |
| 258 | // Check if a given breakpoint fall on a line with code or else adjust it to the next line |
| 259 | else if( m_breakPoints[n].needsAdjusting && |
| 260 | m_breakPoints[n].name == file ) |
| 261 | { |
| 262 | int line = func->FindNextLineWithCode(m_breakPoints[n].lineNbr); |
| 263 | if( line >= 0 ) |
| 264 | { |
| 265 | m_breakPoints[n].needsAdjusting = false; |
| 266 | if( line != m_breakPoints[n].lineNbr ) |
| 267 | { |
| 268 | stringstream s; |
| 269 | s << "Moving break point " << n << " in file '" << file << "' to next line with code at line " << line << endl; |
| 270 | Output(s.str()); |
| 271 | |
| 272 | // Move the breakpoint to the next line |
| 273 | m_breakPoints[n].lineNbr = line; |
| 274 | } |
nothing calls this directly
no test coverage detected