KDevelop API Documentation

src/debugger.cpp

Go to the documentation of this file.
00001 00002 #include "debugger.h" 00003 00004 #include <kdebug.h> 00005 #include <klocale.h> 00006 #include <ktexteditor/document.h> 00007 00008 #include "editorproxy.h" 00009 #include "partcontroller.h" 00010 00011 00012 using namespace KTextEditor; 00013 00014 Debugger *Debugger::s_instance = 0; 00015 00016 Debugger::Debugger() 00017 { 00018 connect( PartController::getInstance(), SIGNAL(partAdded(KParts::Part*)), 00019 this, SLOT(partAdded(KParts::Part*)) ); 00020 } 00021 00022 00023 Debugger::~Debugger() 00024 {} 00025 00026 00027 Debugger *Debugger::getInstance() 00028 { 00029 if (!s_instance) 00030 s_instance = new Debugger; 00031 00032 return s_instance; 00033 } 00034 00035 00036 void Debugger::setBreakpoint(const QString &fileName, int lineNum, int id, bool enabled, bool pending) 00037 { 00038 KParts::Part *part = PartController::getInstance()->partForURL(KURL(fileName)); 00039 if( !part ) 00040 return; 00041 00042 MarkInterface *iface = dynamic_cast<MarkInterface*>(part); 00043 if (!iface) 00044 return; 00045 00046 // Temporarily disconnect so we don't get confused by receiving extra 00047 // marksChanged signals 00048 disconnect( part, SIGNAL(marksChanged()), this, SLOT(marksChanged()) ); 00049 iface->removeMark( lineNum, Breakpoint | ActiveBreakpoint | ReachedBreakpoint | DisabledBreakpoint ); 00050 00051 BPItem bpItem(fileName, lineNum); 00052 QValueList<BPItem>::Iterator it = BPList.find(bpItem); 00053 if (it != BPList.end()) 00054 { 00055 // kdDebug(9012) << "Removing BP=" << fileName << ":" << lineNum << endl; 00056 BPList.remove(it); 00057 } 00058 00059 // An id of -1 means this breakpoint should be hidden from the user. 00060 // I believe this functionality is not used presently. 00061 if( id != -1 ) 00062 { 00063 uint markType = Breakpoint; 00064 if( !pending ) 00065 markType |= ActiveBreakpoint; 00066 if( !enabled ) 00067 markType |= DisabledBreakpoint; 00068 iface->addMark( lineNum, markType ); 00069 // kdDebug(9012) << "Appending BP=" << fileName << ":" << lineNum << endl; 00070 BPList.append(BPItem(fileName, lineNum)); 00071 } 00072 00073 connect( part, SIGNAL(marksChanged()), this, SLOT(marksChanged()) ); 00074 } 00075 00076 00077 void Debugger::clearExecutionPoint() 00078 { 00079 QPtrListIterator<KParts::Part> it(*PartController::getInstance()->parts()); 00080 for ( ; it.current(); ++it) 00081 { 00082 MarkInterface *iface = dynamic_cast<MarkInterface*>(it.current()); 00083 if (!iface) 00084 continue; 00085 00086 QPtrList<Mark> list = iface->marks(); 00087 QPtrListIterator<Mark> markIt(list); 00088 for( ; markIt.current(); ++markIt ) 00089 { 00090 Mark* mark = markIt.current(); 00091 if( mark->type & ExecutionPoint ) 00092 iface->removeMark( mark->line, ExecutionPoint ); 00093 } 00094 } 00095 } 00096 00097 00098 void Debugger::gotoExecutionPoint(const KURL &url, int lineNum) 00099 { 00100 clearExecutionPoint(); 00101 00102 PartController::getInstance()->editDocument(url, lineNum); 00103 00104 KParts::Part *part = PartController::getInstance()->partForURL(url); 00105 if( !part ) 00106 return; 00107 MarkInterface *iface = dynamic_cast<MarkInterface*>(part); 00108 if( !iface ) 00109 return; 00110 00111 iface->addMark( lineNum, ExecutionPoint ); 00112 } 00113 00114 void Debugger::marksChanged() 00115 { 00116 if(sender()->inherits("KTextEditor::Document") ) 00117 { 00118 KTextEditor::Document* doc = (KTextEditor::Document*) sender(); 00119 #if (KDE_VERSION > 305) 00120 MarkInterface* iface = KTextEditor::markInterface( doc ); 00121 #else 00122 KParts::Part *part = PartController::getInstance()->partForURL(doc->url()); 00123 if( !part ) 00124 return; 00125 00126 MarkInterface *iface = dynamic_cast<MarkInterface*>(part); 00127 #endif 00128 00129 if (iface) 00130 { 00131 if( !PartController::getInstance()->partForURL( doc->url() ) ) 00132 return; // Probably means the document is being closed. 00133 00134 KTextEditor::Mark *m; 00135 QValueList<BPItem> oldBPList = BPList; 00136 QPtrList<KTextEditor::Mark> newMarks = iface->marks(); 00137 00138 // Compare the oldBPlist to the new list from the editor. 00139 // 00140 // If we don't have some of the old breakpoints in the new list 00141 // then they have been moved by the user adding or removing source 00142 // code. Remove these old breakpoints 00143 // 00144 // If we _can_ find these old breakpoints in the newlist then 00145 // nothing has happened to them. We can just ignore these and to 00146 // do that we must remove them from the new list. 00147 00148 for (uint i = 0; i < oldBPList.count(); i++) 00149 { 00150 if (oldBPList[i].fileName() != doc->url().path()) 00151 continue; 00152 00153 bool found=false; 00154 for (uint newIdx=0; newIdx < newMarks.count(); newIdx++) 00155 { 00156 m = newMarks.at(newIdx); 00157 if ((m->type & Breakpoint) && 00158 m->line == oldBPList[i].lineNum() && 00159 doc->url().path() == oldBPList[i].fileName()) 00160 { 00161 newMarks.remove(newIdx); 00162 found=true; 00163 break; 00164 } 00165 } 00166 00167 if (!found) 00168 emit toggledBreakpoint( doc->url().path(), oldBPList[i].lineNum() ); 00169 } 00170 00171 // Any breakpoints left in the new list are the _new_ position of 00172 // the moved breakpoints. So add these as new breakpoints via 00173 // toggling them. 00174 for (uint i = 0; i < newMarks.count(); i++) 00175 { 00176 m = newMarks.at(i); 00177 if (m->type & Breakpoint) 00178 emit toggledBreakpoint( doc->url().path(), m->line ); 00179 } 00180 } 00181 } 00182 } 00183 00184 00185 void Debugger::partAdded( KParts::Part* part ) 00186 { 00187 MarkInterfaceExtension *iface = dynamic_cast<MarkInterfaceExtension*>(part); 00188 if( !iface ) 00189 return; 00190 00191 iface->setDescription((MarkInterface::MarkTypes)Breakpoint, i18n("Breakpoint")); 00192 iface->setPixmap((MarkInterface::MarkTypes)Breakpoint, *inactiveBreakpointPixmap()); 00193 iface->setPixmap((MarkInterface::MarkTypes)ActiveBreakpoint, *activeBreakpointPixmap()); 00194 iface->setPixmap((MarkInterface::MarkTypes)ReachedBreakpoint, *reachedBreakpointPixmap()); 00195 iface->setPixmap((MarkInterface::MarkTypes)DisabledBreakpoint, *disabledBreakpointPixmap()); 00196 iface->setPixmap((MarkInterface::MarkTypes)ExecutionPoint, *executionPointPixmap()); 00197 iface->setMarksUserChangable( Bookmark | Breakpoint ); 00198 00199 connect( part, SIGNAL(marksChanged()), this, SLOT(marksChanged()) ); 00200 } 00201 00202 #include "debugger.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:52 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003