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
00017
00018 #include "breakpoint.h"
00019 #include "breakpointdlg.h"
00020
00021 #include <klocale.h>
00022
00023 #include <qfileinfo.h>
00024 #include <qfontmetrics.h>
00025 #include <qpainter.h>
00026 #include <qstring.h>
00027
00028 #include <stdio.h>
00029
00030 namespace JAVADebugger
00031 {
00032
00033
00034
00035
00036
00037 static int BPKey_ = 0;
00038
00039
00040
00041
00042
00043 Breakpoint::Breakpoint(bool temporary, bool enabled)
00044 : QListBoxItem (),
00045 display_(QString::null),
00046 s_pending_(true),
00047 s_actionAdd_(false),
00048 s_actionClear_(false),
00049 s_actionModify_(false),
00050 s_actionDie_(false),
00051 s_dbgProcessing_(false),
00052 s_enabled_(enabled),
00053 s_temporary_(temporary),
00054 s_changedCondition_(false),
00055 s_changedIgnoreCount_(false),
00056 s_changedEnable_(false),
00057 s_hardwareBP_(false),
00058 dbgId_(-1),
00059 hits_(0),
00060 key_(BPKey_++),
00061 active_(0),
00062 ignoreCount_(0),
00063 condition_(QString::null)
00064 {
00065 }
00066
00067
00068
00069 Breakpoint::~Breakpoint()
00070 {
00071 }
00072
00073
00074
00075 int Breakpoint::height(const QListBox *lb) const
00076 {
00077 return lb->fontMetrics().lineSpacing() + 1 ;
00078 }
00079
00080
00081
00082 int Breakpoint::width(const QListBox *lb) const
00083 {
00084 return lb->fontMetrics().width( text() ) + 6;
00085 }
00086
00087
00088
00089 void Breakpoint::paint( QPainter *p )
00090 {
00091 QFontMetrics fm = p->fontMetrics();
00092 int yPos = fm.ascent() + fm.leading()/2;
00093 p->drawText( 0, yPos, text() );
00094 }
00095
00096
00097
00098 QString Breakpoint::text () const
00099 {
00100 return display_;
00101 }
00102
00103
00104
00105 void Breakpoint::configureDisplay()
00106 {
00107 if (s_temporary_)
00108 display_ += i18n("\ttemporary");
00109
00110 if (!s_enabled_)
00111 display_ += i18n("\tdisabled");
00112
00113 if (!condition_.isEmpty())
00114 display_ += i18n("\tif %1").arg(condition_);
00115
00116 if (hits_)
00117 display_ += i18n("\thits %1").arg(hits_);
00118
00119 if (ignoreCount_)
00120 display_ += i18n("\tignore count %1").arg(ignoreCount_);
00121
00122 if (s_hardwareBP_)
00123 display_ = i18n("hw %1").arg(display_);
00124
00125 if (dbgId_>0) {
00126 QString t(display_);
00127 display_ = QString("%1 %2").arg(dbgId_).arg(display_);
00128 }
00129
00130 if (s_pending_) {
00131 QString pending(i18n("Breakpoint state. The 'Pending ' state is the first state displayed",
00132 "Pending "));
00133 if (s_actionAdd_)
00134 pending += i18n("Breakpoint state. The 'add ' state is appended to the other states",
00135 "add ");
00136 if (s_actionClear_)
00137 pending += i18n("Breakpoint state. The 'clear ' state is appended to the other states",
00138 "clear ");
00139 if (s_actionModify_)
00140 pending += i18n("Breakpoint state. The 'modify ' state is appended to the other states",
00141 "modify ");
00142
00143 display_ = i18n("%1>\t%2").arg(pending).arg(display_);
00144 }
00145 }
00146
00147
00148
00149 QString Breakpoint::dbgRemoveCommand() const
00150 {
00151 if (dbgId_>0)
00152 return QString("delete %1").arg(dbgId_);
00153
00154 return QString();
00155 }
00156
00157
00158
00159 bool Breakpoint::hasSourcePosition() const
00160 {
00161 return false;
00162 }
00163
00164
00165
00166 QString Breakpoint::fileName() const
00167 {
00168 return QString();
00169 }
00170
00171
00172
00173 int Breakpoint::lineNum() const
00174 {
00175 return 0;
00176 }
00177
00178
00179
00180
00181 void Breakpoint::reset()
00182 {
00183 dbgId_ = -1;
00184 s_pending_ = true;
00185 s_actionAdd_ = true;
00186 s_actionClear_ = false;
00187 s_changedCondition_ = !condition_.isEmpty();
00188 s_changedIgnoreCount_ = (ignoreCount_>0);
00189 s_changedEnable_ = !s_enabled_;
00190 s_actionModify_ = s_changedCondition_ || s_changedIgnoreCount_ || s_changedEnable_;
00191 s_dbgProcessing_ = false;
00192 s_hardwareBP_ = false;
00193 hits_ = 0;
00194
00195 configureDisplay();
00196 }
00197
00198
00199
00200 void Breakpoint::setActive(int active, int id)
00201 {
00202 active_ = active;
00203 dbgId_ = id;
00204
00205 if (s_pending_ && !(s_actionAdd_ && s_actionModify_)) {
00206 s_pending_ = false;
00207 s_actionModify_ = false;
00208 }
00209
00210 s_actionAdd_ = false;
00211 s_actionClear_ = false;
00212 s_actionDie_ = false;
00213 s_dbgProcessing_ = false;
00214
00215 if (!s_actionModify_) {
00216 s_changedCondition_ = false;
00217 s_changedIgnoreCount_ = false;
00218 s_changedEnable_ = false;
00219 }
00220
00221 configureDisplay();
00222 }
00223
00224
00225 bool Breakpoint::modifyDialog()
00226 {
00227 BPDialog* modifyBPDialog = new BPDialog(this);
00228 if (modifyBPDialog->exec()) {
00229 setConditional(modifyBPDialog->getConditional());
00230 setIgnoreCount(modifyBPDialog->getIgnoreCount());
00231 setEnabled(modifyBPDialog->isEnabled());
00232 }
00233
00234 delete modifyBPDialog;
00235 return (s_changedCondition_ || s_changedIgnoreCount_ || s_changedEnable_);
00236 }
00237
00238
00239
00240
00241
00242 FilePosBreakpoint::FilePosBreakpoint(const QString &fileName, int lineNum,
00243 bool temporary, bool enabled)
00244 : Breakpoint(temporary, enabled),
00245 fileName_(fileName),
00246 lineNo_(lineNum)
00247 {
00248 configureDisplay();
00249 }
00250
00251
00252
00253 FilePosBreakpoint::~FilePosBreakpoint()
00254 {
00255 }
00256
00257
00258
00259 QString FilePosBreakpoint::dbgSetCommand() const
00260 {
00261 QString cmdStr;
00262 if (fileName_.isEmpty())
00263 cmdStr = QString("stop at %1").arg(lineNo_);
00264 else {
00265 QFileInfo fi(fileName_);
00266 cmdStr = QString("stop at %1:%2").arg(fi.baseName()).arg(lineNo_);
00267 }
00268
00269 if (isTemporary())
00270 cmdStr = "t"+cmdStr;
00271
00272 return cmdStr;
00273 }
00274
00275
00276
00277 bool FilePosBreakpoint::match(const Breakpoint *brkpt) const
00278 {
00279
00280 if (this == brkpt)
00281 return true;
00282
00283
00284 const FilePosBreakpoint* check = dynamic_cast<const FilePosBreakpoint*>(brkpt);
00285 if (!check)
00286 return false;
00287
00288
00289 return ( (fileName_ == check->fileName_) &&
00290 (lineNo_ == check->lineNo_));
00291 }
00292
00293
00294
00295 void FilePosBreakpoint::configureDisplay()
00296 {
00297 QFileInfo fi(fileName_);
00298 display_ = i18n("breakpoint at %1:%2").arg(fi.baseName()).arg(lineNo_);
00299 Breakpoint::configureDisplay();
00300 }
00301
00302
00303
00304
00305
00306
00307 Watchpoint::Watchpoint(const QString& varName, bool temporary, bool enabled)
00308 : Breakpoint(temporary, enabled),
00309 varName_(varName)
00310 {
00311 configureDisplay();
00312 }
00313
00314
00315
00316 Watchpoint::~Watchpoint()
00317 {
00318 }
00319
00320
00321
00322 QString Watchpoint::dbgSetCommand() const
00323 {
00324 return QString("watch ")+varName_;
00325 }
00326
00327
00328
00329 void Watchpoint::configureDisplay()
00330 {
00331 display_ = i18n("watchpoint on %1").arg(varName_);
00332 Breakpoint::configureDisplay();
00333 }
00334
00335
00336
00337 bool Watchpoint::match(const Breakpoint* brkpt) const
00338 {
00339
00340 if (this == brkpt)
00341 return true;
00342
00343
00344 const Watchpoint *check = dynamic_cast<const Watchpoint*>(brkpt);
00345 if (!check)
00346 return false;
00347
00348
00349 return (varName_ == check->varName_);
00350 }
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00362
00363
00364
00365
00366
00368
00369
00370
00371
00372
00373
00375
00376
00377
00378
00379
00380
00381
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00412
00413
00414
00415
00416
00418
00419
00420
00421
00422
00423
00425
00430
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00451
00452
00453
00454
00455
00457
00458
00459
00460
00461
00462
00464
00469
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481 }
This file is part of the documentation for KDevelop Version 3.1.2.