KDevelop API Documentation

breakpoint.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           breakpoint.cpp  -  description
00003                              -------------------
00004     begin                : Sun Aug 8 1999
00005     copyright            : (C) 1999 by John Birch
00006     email                : jbb@kdevelop.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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_); // jdb command - not translatable
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 // called when debugger ends
00181 void Breakpoint::reset()
00182 {
00183     dbgId_                = -1;
00184     s_pending_            = true;
00185     s_actionAdd_          = true;     // waiting for the debugger to start
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_);  // jdb command - not translatable
00264     else {
00265         QFileInfo fi(fileName_);
00266         cmdStr = QString("stop at %1:%2").arg(fi.baseName()).arg(lineNo_); // jdb command
00267     }
00268 
00269     if (isTemporary())
00270         cmdStr = "t"+cmdStr;  // jdb command
00271 
00272     return cmdStr;
00273 }
00274 
00275 /***************************************************************************/
00276 
00277 bool FilePosBreakpoint::match(const Breakpoint *brkpt) const
00278 {
00279     // simple case
00280     if (this == brkpt)
00281         return true;
00282 
00283     // Type case
00284     const FilePosBreakpoint* check = dynamic_cast<const FilePosBreakpoint*>(brkpt);
00285     if (!check)
00286         return false;
00287 
00288     // member case
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_;    // jdb command - not translatable
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     // simple case
00340     if (this == brkpt)
00341         return true;
00342 
00343     // Type case
00344     const Watchpoint *check = dynamic_cast<const Watchpoint*>(brkpt);
00345     if (!check)
00346         return false;
00347 
00348     // member case
00349     return (varName_ == check->varName_);
00350 }
00351 
00352 /***************************************************************************/
00353 /***************************************************************************/
00354 /***************************************************************************/
00355 
00356 //ExitBreakpoint::ExitBreakpoint(bool temporary, bool enabled) :
00357 //  Breakpoint(temporary, enabled)
00358 //{
00359 //}
00360 //
00362 //
00363 //ExitBreakpoint::~ExitBreakpoint()
00364 //{
00365 //}
00366 //
00368 //
00369 //QString ExitBreakpoint::dbgSetCommand() const
00370 //{
00371 //  return "";
00372 //}
00373 //
00375 //
00376 //void ExitBreakpoint::configureDisplay()
00377 //{
00378 //  *display_ = 0;
00379 //  Breakpoint::configureDisplay();
00380 //}
00381 //
00383 //
00384 //bool ExitBreakpoint::match(const Breakpoint* brkpt) const
00385 //{
00386 //  // simple case
00387 //  if (this == brkpt)
00388 //    return true;
00389 //
00390 //  // Type case
00391 //  const ExitBreakpoint* check = dynamic_cast<const ExitBreakpoint*>(brkpt);
00392 //  if (!check)
00393 //    return false;
00394 //
00395 //  // member case
00396 //  return true;
00397 //}
00398 //
00399 /***************************************************************************/
00400 /***************************************************************************/
00401 /***************************************************************************/
00402 //
00403 // These are implemented in jdb but can cause a lot of breakpoints
00404 // to be set. This needs more thought before being implemented
00405 
00406 //RegExpBreakpoint::RegExpBreakpoint(bool temporary, bool enabled) :
00407 //  Breakpoint(temporary, enabled)
00408 //{
00409 //}
00410 //
00412 //
00413 //RegExpBreakpoint::~RegExpBreakpoint()
00414 //{
00415 //}
00416 //
00418 //
00419 //QString RegExpBreakpoint::dbgSetCommand() const
00420 //{
00421 //  return "";
00422 //}
00423 //
00425 //
00430 //
00432 //
00433 //void RegExpBreakpoint::configureDisplay()
00434 //{
00435 //  *display_ = 0;
00436 //  Breakpoint::configureDisplay();
00437 //}
00438 //
00439 /***************************************************************************/
00440 /***************************************************************************/
00441 /***************************************************************************/
00442 
00443 // Most catch options arn't implemented in jdb so ignore this for now.
00444 
00445 //CatchBreakpoint::CatchBreakpoint(bool temporary, bool enabled) :
00446 //  Breakpoint(temporary, enabled)
00447 //{
00448 //}
00449 //
00451 //
00452 //CatchBreakpoint::~CatchBreakpoint()
00453 //{
00454 //}
00455 //
00457 //
00458 //QString CatchBreakpoint::dbgSetCommand() const
00459 //{
00460 //  return "";
00461 //}
00462 //
00464 //
00469 //
00471 //
00472 //void CatchBreakpoint::configureDisplay()
00473 //{
00474 //  *display_ = 0;
00475 //  Breakpoint::configureDisplay();
00476 //}
00477 //
00478 /***************************************************************************/
00479 /***************************************************************************/
00480 /***************************************************************************/
00481 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:46 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003