• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Debugger Support Library
 

KDevelop Debugger Support Library

  • languages
  • lib
  • debugger
debugger.cpp
1
2#include "debugger.h"
3
4#include <kdebug.h>
5#include <tdelocale.h>
6#include <tdetexteditor/document.h>
7
8// #include "editorproxy.h"
9#include <kdevpartcontroller.h>
10
11
12using namespace KTextEditor;
13
14Debugger *Debugger::s_instance = 0;
15
16Debugger::Debugger(KDevPartController *partController)
17 :m_partController(partController)
18{
19 connect( m_partController, TQ_SIGNAL(partAdded(KParts::Part*)),
20 this, TQ_SLOT(partAdded(KParts::Part*)) );
21}
22
23
24Debugger::~Debugger()
25{}
26
27
28// Debugger *Debugger::getInstance()
29// {
30// if (!s_instance)
31// s_instance = new Debugger;
32//
33// return s_instance;
34// }
35
36
37void Debugger::setBreakpoint(const TQString &fileName, int lineNum, int id, bool enabled, bool pending)
38{
39 KParts::Part *part = m_partController->partForURL(KURL(fileName));
40 if( !part )
41 return;
42
43 MarkInterface *iface = dynamic_cast<MarkInterface*>(part);
44 if (!iface)
45 return;
46
47 // Temporarily disconnect so we don't get confused by receiving extra
48 // marksChanged signals
49 disconnect( part, TQ_SIGNAL(marksChanged()), this, TQ_SLOT(marksChanged()) );
50 iface->removeMark( lineNum, Breakpoint | ActiveBreakpoint | ReachedBreakpoint | DisabledBreakpoint );
51
52 BPItem bpItem(fileName, lineNum);
53 TQValueList<BPItem>::Iterator it = BPList.find(bpItem);
54 if (it != BPList.end())
55 {
56// kdDebug(9012) << "Removing BP=" << fileName << ":" << lineNum << endl;
57 BPList.remove(it);
58 }
59
60 // An id of -1 means this breakpoint should be hidden from the user.
61 // I believe this functionality is not used presently.
62 if( id != -1 )
63 {
64 uint markType = Breakpoint;
65 if( !pending )
66 markType |= ActiveBreakpoint;
67 if( !enabled )
68 markType |= DisabledBreakpoint;
69 iface->addMark( lineNum, markType );
70// kdDebug(9012) << "Appending BP=" << fileName << ":" << lineNum << endl;
71 BPList.append(BPItem(fileName, lineNum));
72 }
73
74 connect( part, TQ_SIGNAL(marksChanged()), this, TQ_SLOT(marksChanged()) );
75}
76
77
78void Debugger::clearExecutionPoint()
79{
80 TQPtrListIterator<KParts::Part> it(*m_partController->parts());
81 for ( ; it.current(); ++it)
82 {
83 MarkInterface *iface = dynamic_cast<MarkInterface*>(it.current());
84 if (!iface)
85 continue;
86
87 TQPtrList<Mark> list = iface->marks();
88 TQPtrListIterator<Mark> markIt(list);
89 for( ; markIt.current(); ++markIt )
90 {
91 Mark* mark = markIt.current();
92 if( mark->type & ExecutionPoint )
93 iface->removeMark( mark->line, ExecutionPoint );
94 }
95 }
96}
97
98
99void Debugger::gotoExecutionPoint(const KURL &url, int lineNum)
100{
101 clearExecutionPoint();
102
103 m_partController->editDocument(url, lineNum);
104
105 KParts::Part *part = m_partController->partForURL(url);
106 if( !part )
107 return;
108 MarkInterface *iface = dynamic_cast<MarkInterface*>(part);
109 if( !iface )
110 return;
111
112 iface->addMark( lineNum, ExecutionPoint );
113}
114
115void Debugger::marksChanged()
116{
117 if(sender()->inherits("KTextEditor::Document") )
118 {
119 KTextEditor::Document* doc = (KTextEditor::Document*) sender();
120 MarkInterface* iface = KTextEditor::markInterface( doc );
121
122 if (iface)
123 {
124 if( !m_partController->partForURL( doc->url() ) )
125 return; // Probably means the document is being closed.
126
127 KTextEditor::Mark *m;
128 TQValueList<BPItem> oldBPList = BPList;
129 TQPtrList<KTextEditor::Mark> newMarks = iface->marks();
130
131 // Compare the oldBPlist to the new list from the editor.
132 //
133 // If we don't have some of the old breakpoints in the new list
134 // then they have been moved by the user adding or removing source
135 // code. Remove these old breakpoints
136 //
137 // If we _can_ find these old breakpoints in the newlist then
138 // nothing has happened to them. We can just ignore these and to
139 // do that we must remove them from the new list.
140
141 bool bpchanged = false;
142
143 for (uint i = 0; i < oldBPList.count(); i++)
144 {
145 if (oldBPList[i].fileName() != doc->url().path())
146 continue;
147
148 bool found=false;
149 for (uint newIdx=0; newIdx < newMarks.count(); newIdx++)
150 {
151 m = newMarks.at(newIdx);
152 if ((m->type & Breakpoint) &&
153 m->line == oldBPList[i].lineNum() &&
154 doc->url().path() == oldBPList[i].fileName())
155 {
156 newMarks.remove(newIdx);
157 found=true;
158 break;
159 }
160 }
161
162 if (!found)
163 {
164 emit toggledBreakpoint( doc->url().path(), oldBPList[i].lineNum() );
165 bpchanged = true;
166 }
167 }
168
169 // Any breakpoints left in the new list are the _new_ position of
170 // the moved breakpoints. So add these as new breakpoints via
171 // toggling them.
172 for (uint i = 0; i < newMarks.count(); i++)
173 {
174 m = newMarks.at(i);
175 if (m->type & Breakpoint)
176 {
177 emit toggledBreakpoint( doc->url().path(), m->line );
178 bpchanged = true;
179 }
180 }
181
182 if ( bpchanged && m_partController->activePart() == doc )
183 {
184 //bring focus back to the editor
185 m_partController->activatePart( doc );
186 }
187 }
188 }
189}
190
191
192void Debugger::partAdded( KParts::Part* part )
193{
194 MarkInterfaceExtension *iface = dynamic_cast<MarkInterfaceExtension*>(part);
195 if( !iface )
196 return;
197
198 iface->setDescription((MarkInterface::MarkTypes)Breakpoint, i18n("Breakpoint"));
199 iface->setPixmap((MarkInterface::MarkTypes)Breakpoint, *inactiveBreakpointPixmap());
200 iface->setPixmap((MarkInterface::MarkTypes)ActiveBreakpoint, *activeBreakpointPixmap());
201 iface->setPixmap((MarkInterface::MarkTypes)ReachedBreakpoint, *reachedBreakpointPixmap());
202 iface->setPixmap((MarkInterface::MarkTypes)DisabledBreakpoint, *disabledBreakpointPixmap());
203 iface->setPixmap((MarkInterface::MarkTypes)ExecutionPoint, *executionPointPixmap());
204 iface->setMarksUserChangable( Bookmark | Breakpoint );
205
206 connect( part, TQ_SIGNAL(marksChanged()), this, TQ_SLOT(marksChanged()) );
207}
208
209#include "debugger.moc"
BPItem
Describes a single breakpoint in the system.
Definition debugger.h:23
Debugger
Handles signals from the editor that relate to breakpoints and the execution point of the debugger.
Definition debugger.h:57
Debugger::clearExecutionPoint
void clearExecutionPoint()
Remove the executution point being displayed.
Definition debugger.cpp:78
Debugger::gotoExecutionPoint
void gotoExecutionPoint(const KURL &url, int lineNum=-1)
Displays an icon in the file at the line that the debugger has stoped at.
Definition debugger.cpp:99
Debugger::setBreakpoint
void setBreakpoint(const TQString &fileName, int lineNum, int id, bool enabled, bool pending)
Controls the breakpoint icon being displayed in the editor through the markinterface.
Definition debugger.cpp:37
KDevDebugger::toggledBreakpoint
void toggledBreakpoint(const TQString &fileName, int lineNum)
The user has toggled a breakpoint.

KDevelop Debugger Support Library

Skip menu "KDevelop Debugger Support Library"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDevelop Debugger Support Library

Skip menu "KDevelop Debugger Support Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Debugger Support Library by doxygen 1.15.0
This website is maintained by Timothy Pearson.