breakpoint.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "breakpoint.h"
00017
00018 #include <klocale.h>
00019
00020 #include <qfileinfo.h>
00021 #include <qfontmetrics.h>
00022 #include <qpainter.h>
00023 #include <qregexp.h>
00024 #include <qstring.h>
00025
00026 #include <stdio.h>
00027
00028
00029
00030
00031
00032 namespace GDBDebugger
00033 {
00034
00035 static int BPKey_ = 0;
00036
00037
00038
00039
00040
00041 Breakpoint::Breakpoint(bool temporary, bool enabled)
00042 : s_pending_(true),
00043 s_actionAdd_(true),
00044 s_actionClear_(false),
00045 s_actionModify_(false),
00046 s_actionDie_(false),
00047 s_dbgProcessing_(false),
00048 s_enabled_(enabled),
00049 s_temporary_(temporary),
00050 s_changedCondition_(false),
00051 s_changedIgnoreCount_(false),
00052 s_changedEnable_(false),
00053 s_hardwareBP_(false),
00054 dbgId_(-1),
00055 hits_(0),
00056 key_(BPKey_++),
00057 active_(-1),
00058 ignoreCount_(0),
00059 condition_("")
00060 {
00061 }
00062
00063
00064
00065 Breakpoint::~Breakpoint()
00066 {
00067 }
00068
00069
00070
00071 QString Breakpoint::dbgRemoveCommand() const
00072 {
00073 if (dbgId_>0)
00074 return QString("delete %1").arg(dbgId_);
00075
00076 return QString();
00077 }
00078
00079
00080
00081
00082 void Breakpoint::reset()
00083 {
00084 dbgId_ = -1;
00085 s_pending_ = true;
00086 s_actionAdd_ = true;
00087 s_actionClear_ = false;
00088 s_changedCondition_ = !condition_.isEmpty();
00089 s_changedIgnoreCount_ = (ignoreCount_>0);
00090 s_changedEnable_ = !s_enabled_;
00091 s_actionModify_ = s_changedCondition_ || s_changedIgnoreCount_ || s_changedEnable_;
00092 s_dbgProcessing_ = false;
00093 s_hardwareBP_ = false;
00094 hits_ = 0;
00095 active_ = -1;
00096 }
00097
00098
00099
00100 void Breakpoint::setActive(int active, int id)
00101 {
00102 active_ = active;
00103 dbgId_ = id;
00104
00105 if (s_pending_ && !(s_actionAdd_ && s_actionModify_)) {
00106 s_pending_ = false;
00107 s_actionModify_ = false;
00108 }
00109
00110 s_actionAdd_ = false;
00111 s_actionClear_ = false;
00112 s_actionDie_ = false;
00113 s_dbgProcessing_ = false;
00114
00115 if (!s_actionModify_) {
00116 s_changedCondition_ = false;
00117 s_changedIgnoreCount_ = false;
00118 s_changedEnable_ = false;
00119 }
00120 }
00121
00122
00123
00124 QString Breakpoint::statusDisplay(int activeFlag) const
00125 {
00126 QString status="";
00127 if (!s_enabled_)
00128 status = i18n("Disabled");
00129 else
00130 if (s_pending_)
00131 {
00132 if (s_actionAdd_)
00133 status = i18n("Pending (add)");
00134 if (s_actionClear_)
00135 status = i18n("Pending (clear)");
00136 if (s_actionModify_)
00137 status = i18n("Pending (modify)");
00138 }
00139 else
00140 if (isActive(activeFlag))
00141 status = i18n("Active");
00142
00143 return status;
00144 }
00145
00146
00147
00148
00149
00150 FilePosBreakpoint::FilePosBreakpoint(const QString &fileName, int lineNum,
00151 bool temporary, bool enabled)
00152 : Breakpoint(temporary, enabled),
00153 fileName_(fileName),
00154 lineNo_(lineNum)
00155 {
00156 }
00157
00158
00159
00160 FilePosBreakpoint::~FilePosBreakpoint()
00161 {
00162 }
00163
00164
00165
00166 QString FilePosBreakpoint::dbgSetCommand() const
00167 {
00168 QString cmdStr;
00169 if (fileName_.isEmpty())
00170 cmdStr = QString("break %1").arg(lineNo_);
00171 else {
00172 QFileInfo fi(fileName_);
00173 cmdStr = QString("break %1:%2").arg(fi.fileName()).arg(lineNo_);
00174 }
00175
00176 if (isTemporary())
00177 cmdStr = "t"+cmdStr;
00178
00179 return cmdStr;
00180 }
00181
00182
00183
00184 bool FilePosBreakpoint::match(const Breakpoint *brkpt) const
00185 {
00186
00187 if (this == brkpt)
00188 return true;
00189
00190
00191 const FilePosBreakpoint* check = dynamic_cast<const FilePosBreakpoint*>(brkpt);
00192 if (!check)
00193 return false;
00194
00195
00196 return ( (fileName_ == check->fileName_) &&
00197 (lineNo_ == check->lineNo_));
00198 }
00199
00200
00201
00202 QString FilePosBreakpoint::location(bool compact)
00203 {
00204 if (compact)
00205 return QFileInfo(fileName_).fileName()+":"+QString::number(lineNo_);
00206
00207 return fileName_+":"+QString::number(lineNo_);
00208 }
00209
00210
00211
00212 void FilePosBreakpoint::setLocation(const QString& location)
00213 {
00214 QRegExp regExp1("(.*):(\\d+)$");
00215 regExp1.setMinimal(true);
00216 if ( regExp1.search(location, 0) >= 0 )
00217 {
00218 QString t = regExp1.cap(1);
00219 QString dirPath = QFileInfo(t).dirPath();
00220 if ( dirPath == "." )
00221 fileName_ = QFileInfo(fileName_).dirPath()+"/"+regExp1.cap(1);
00222 else
00223 fileName_ = regExp1.cap(1);
00224
00225 lineNo_ = regExp1.cap(2).toInt();
00226 }
00227 }
00228
00229
00230
00231
00232
00233 Watchpoint::Watchpoint(const QString& varName, bool temporary, bool enabled)
00234 : Breakpoint(temporary, enabled),
00235 varName_(varName)
00236 {
00237 }
00238
00239
00240
00241 Watchpoint::~Watchpoint()
00242 {
00243 }
00244
00245
00246
00247 QString Watchpoint::dbgSetCommand() const
00248 {
00249 return QString("watch ")+varName_;
00250 }
00251
00252
00253
00254 bool Watchpoint::match(const Breakpoint* brkpt) const
00255 {
00256
00257 if (this == brkpt)
00258 return true;
00259
00260
00261 const Watchpoint *check = dynamic_cast<const Watchpoint*>(brkpt);
00262 if (!check)
00263 return false;
00264
00265
00266 return (varName_ == check->varName_);
00267 }
00268
00269
00270
00271
00272
00273 AddressBreakpoint::AddressBreakpoint(const QString& breakAddress, bool temporary, bool enabled)
00274 : Breakpoint(temporary, enabled),
00275 m_breakAddress(breakAddress)
00276 {
00277 }
00278
00279
00280
00281 AddressBreakpoint::~AddressBreakpoint()
00282 {
00283 }
00284
00285
00286
00287 QString AddressBreakpoint::dbgSetCommand() const
00288 {
00289 return QString("break ")+m_breakAddress;
00290 }
00291
00292
00293
00294 bool AddressBreakpoint::match(const Breakpoint* brkpt) const
00295 {
00296
00297 if (this == brkpt)
00298 return true;
00299
00300
00301 const AddressBreakpoint *check = dynamic_cast<const AddressBreakpoint*>(brkpt);
00302 if (!check)
00303 return false;
00304
00305
00306 return (m_breakAddress == check->m_breakAddress);
00307 }
00308
00309
00310
00311
00312
00313 FunctionBreakpoint::FunctionBreakpoint(const QString& functionName, bool temporary, bool enabled)
00314 : Breakpoint(temporary, enabled),
00315 m_functionName(functionName)
00316 {
00317 }
00318
00319
00320
00321 FunctionBreakpoint::~FunctionBreakpoint()
00322 {
00323 }
00324
00325
00326
00327 QString FunctionBreakpoint::dbgSetCommand() const
00328 {
00329 return QString("break ")+m_functionName;
00330 }
00331
00332
00333
00334 bool FunctionBreakpoint::match(const Breakpoint* brkpt) const
00335 {
00336
00337 if (this == brkpt)
00338 return true;
00339
00340
00341 const FunctionBreakpoint *check = dynamic_cast<const FunctionBreakpoint*>(brkpt);
00342 if (!check)
00343 return false;
00344
00345
00346 return (m_functionName == check->m_functionName);
00347 }
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00359
00360
00361
00362
00363
00365
00366
00367
00368
00369
00370
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00401
00402
00403
00404
00405
00407
00408
00409
00410
00411
00412
00414
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00432
00433
00434
00435
00436
00438
00439
00440
00441
00442
00443
00445
00450
00451
00452
00453
00454
00455 }
This file is part of the documentation for KDevelop Version 3.1.2.