3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
7 #include <klocale.h> /* i18n */
8 #include <kmessagebox.h>
10 #include <kstatusbar.h>
11 #include <kiconloader.h>
12 #include <kstdaccel.h>
13 #include <kstdaction.h>
15 #include <kpopupmenu.h>
16 #include <kfiledialog.h>
18 #include <kkeydialog.h>
19 #include <kanimwidget.h>
22 #include <qfileinfo.h>
23 #include "dbgmainwnd.h"
25 #include "commandids.h"
28 #include "threadlist.h"
29 #include "memwindow.h"
31 #include "procattach.h"
32 #include "dbgdriver.h"
39 DebuggerMainWnd::DebuggerMainWnd(const char* name
) :
40 KDockMainWindow(0, name
),
45 KDockWidget
* dw0
= createDockWidget("Source", p
, 0, i18n("Source"));
46 m_filesWindow
= new WinStack(dw0
, "files");
47 dw0
->setWidget(m_filesWindow
);
48 dw0
->setDockSite(KDockWidget::DockCorner
);
49 dw0
->setEnableDocking(KDockWidget::DockNone
);
51 setMainDockWidget(dw0
);
53 KDockWidget
* dw1
= createDockWidget("Stack", p
, 0, i18n("Stack"));
54 m_btWindow
= new QListBox(dw1
, "backtrace");
55 dw1
->setWidget(m_btWindow
);
56 KDockWidget
* dw2
= createDockWidget("Locals", p
, 0, i18n("Locals"));
57 m_localVariables
= new ExprWnd(dw2
, "locals");
58 dw2
->setWidget(m_localVariables
);
59 KDockWidget
* dw3
= createDockWidget("Watches", p
, 0, i18n("Watches"));
60 m_watches
= new WatchWindow(dw3
, "watches");
61 dw3
->setWidget(m_watches
);
62 KDockWidget
* dw4
= createDockWidget("Registers", p
, 0, i18n("Registers"));
63 m_registers
= new RegisterView(dw4
, "registers");
64 dw4
->setWidget(m_registers
);
65 KDockWidget
* dw5
= createDockWidget("Breakpoints", p
, 0, i18n("Breakpoints"));
66 m_bpTable
= new BreakpointTable(dw5
, "breakpoints");
67 dw5
->setWidget(m_bpTable
);
68 KDockWidget
* dw6
= createDockWidget("Output", p
, 0, i18n("Output"));
69 m_ttyWindow
= new TTYWindow(dw6
, "output");
70 dw6
->setWidget(m_ttyWindow
);
71 KDockWidget
* dw7
= createDockWidget("Threads", p
, 0, i18n("Threads"));
72 m_threads
= new ThreadList(dw7
, "threads");
73 dw7
->setWidget(m_threads
);
74 KDockWidget
* dw8
= createDockWidget("Memory", p
, 0, i18n("Memory"));
75 m_memoryWindow
= new MemoryWindow(dw8
, "memory");
76 dw8
->setWidget(m_memoryWindow
);
78 setupDebugger(this, m_localVariables
, m_watches
->watchVariables(), m_btWindow
);
79 m_bpTable
->setDebugger(m_debugger
);
80 m_memoryWindow
->setDebugger(m_debugger
);
83 initToolbar(); // kind of obsolete?
85 connect(m_watches
, SIGNAL(addWatch()), SLOT(slotAddWatch()));
86 connect(m_watches
, SIGNAL(deleteWatch()), m_debugger
, SLOT(slotDeleteWatch()));
88 KAction
* windowMenu
= actionCollection()->action("window");
89 m_filesWindow
->setWindowMenu(static_cast<KActionMenu
*>(windowMenu
)->popupMenu());
90 connect(&m_filesWindow
->m_findDlg
, SIGNAL(closed()), SLOT(updateUI()));
91 connect(m_filesWindow
, SIGNAL(newFileLoaded()),
92 SLOT(slotNewFileLoaded()));
93 connect(m_filesWindow
, SIGNAL(toggleBreak(const QString
&,int,const DbgAddr
&,bool)),
94 this, SLOT(slotToggleBreak(const QString
&,int,const DbgAddr
&,bool)));
95 connect(m_filesWindow
, SIGNAL(enadisBreak(const QString
&,int,const DbgAddr
&)),
96 this, SLOT(slotEnaDisBreak(const QString
&,int,const DbgAddr
&)));
97 connect(m_debugger
, SIGNAL(activateFileLine(const QString
&,int,const DbgAddr
&)),
98 m_filesWindow
, SLOT(activate(const QString
&,int,const DbgAddr
&)));
99 connect(m_debugger
, SIGNAL(executableUpdated()),
100 m_filesWindow
, SLOT(reloadAllFiles()));
101 connect(m_debugger
, SIGNAL(updatePC(const QString
&,int,const DbgAddr
&,int)),
102 m_filesWindow
, SLOT(updatePC(const QString
&,int,const DbgAddr
&,int)));
103 // value popup communication
104 connect(m_filesWindow
, SIGNAL(initiateValuePopup(const QString
&)),
105 m_debugger
, SLOT(slotValuePopup(const QString
&)));
106 connect(m_debugger
, SIGNAL(valuePopup(const QString
&)),
107 m_filesWindow
, SLOT(slotShowValueTip(const QString
&)));
109 connect(m_filesWindow
, SIGNAL(disassemble(const QString
&, int)),
110 m_debugger
, SLOT(slotDisassemble(const QString
&, int)));
111 connect(m_debugger
, SIGNAL(disassembled(const QString
&,int,const QList
<DisassembledCode
>&)),
112 m_filesWindow
, SLOT(slotDisassembled(const QString
&,int,const QList
<DisassembledCode
>&)));
113 connect(m_filesWindow
, SIGNAL(moveProgramCounter(const QString
&,int,const DbgAddr
&)),
114 m_debugger
, SLOT(setProgramCounter(const QString
&,int,const DbgAddr
&)));
116 connect(m_debugger
, SIGNAL(programStopped()), SLOT(slotProgramStopped()));
117 connect(&m_backTimer
, SIGNAL(timeout()), SLOT(slotBackTimer()));
119 connect(this, SIGNAL(setTabWidth(int)), m_filesWindow
, SIGNAL(setTabWidth(int)));
121 // Establish communication when right clicked on file window.
122 connect(m_filesWindow
, SIGNAL(filesRightClick(const QPoint
&)),
123 SLOT(slotFileWndMenu(const QPoint
&)));
125 // Connection when right clicked on file window before any file is
127 connect(m_filesWindow
, SIGNAL(clickedRight(const QPoint
&)),
128 SLOT(slotFileWndEmptyMenu(const QPoint
&)));
131 connect(m_filesWindow
, SIGNAL(fileChanged()), SLOT(slotFileChanged()));
132 connect(m_filesWindow
, SIGNAL(lineChanged()), SLOT(slotLineChanged()));
134 // connect breakpoint table
135 connect(m_bpTable
, SIGNAL(activateFileLine(const QString
&,int,const DbgAddr
&)),
136 m_filesWindow
, SLOT(activate(const QString
&,int,const DbgAddr
&)));
137 connect(m_debugger
, SIGNAL(updateUI()), m_bpTable
, SLOT(updateUI()));
138 connect(m_debugger
, SIGNAL(breakpointsChanged()), m_bpTable
, SLOT(updateBreakList()));
139 connect(m_debugger
, SIGNAL(breakpointsChanged()), m_bpTable
, SLOT(updateUI()));
141 connect(m_debugger
, SIGNAL(registersChanged(QList
<RegisterInfo
>&)),
142 m_registers
, SLOT(updateRegisters(QList
<RegisterInfo
>&)));
144 connect(m_debugger
, SIGNAL(memoryDumpChanged(const QString
&, QList
<MemoryDump
>&)),
145 m_memoryWindow
, SLOT(slotNewMemoryDump(const QString
&, QList
<MemoryDump
>&)));
146 connect(m_debugger
, SIGNAL(saveProgramSpecific(KConfigBase
*)),
147 m_memoryWindow
, SLOT(saveProgramSpecific(KConfigBase
*)));
148 connect(m_debugger
, SIGNAL(restoreProgramSpecific(KConfigBase
*)),
149 m_memoryWindow
, SLOT(restoreProgramSpecific(KConfigBase
*)));
152 connect(m_debugger
, SIGNAL(threadsChanged(QList
<ThreadInfo
>&)),
153 m_threads
, SLOT(updateThreads(QList
<ThreadInfo
>&)));
154 connect(m_threads
, SIGNAL(setThread(int)),
155 m_debugger
, SLOT(setThread(int)));
157 // view menu changes when docking state changes
158 connect(dockManager
, SIGNAL(change()), SLOT(updateUI()));
160 // popup menu of the local variables window
161 connect(m_localVariables
, SIGNAL(contextMenuRequested(QListViewItem
*, const QPoint
&, int)),
162 this, SLOT(slotLocalsPopup(QListViewItem
*, const QPoint
&)));
164 restoreSettings(kapp
->config());
167 m_bpTable
->updateUI();
171 DebuggerMainWnd::~DebuggerMainWnd()
173 saveSettings(kapp
->config());
174 // must delete m_debugger early since it references our windows
178 delete m_memoryWindow
;
184 delete m_localVariables
;
186 delete m_filesWindow
;
189 void DebuggerMainWnd::initKAction()
192 KAction
* open
= KStdAction::open(this, SLOT(slotFileOpen()),
194 open
->setText(i18n("&Open Source..."));
195 (void)new KAction(i18n("&Reload Source"), "reload", 0, m_filesWindow
,
196 SLOT(slotFileReload()), actionCollection(),
198 (void)new KAction(i18n("&Executable..."), "execopen", 0, this,
199 SLOT(slotFileExe()), actionCollection(),
201 m_recentExecAction
= new KRecentFilesAction(i18n("Recent E&xecutables"), 0,
202 this, SLOT(slotRecentExec(const KURL
&)),
203 actionCollection(), "file_executable_recent");
204 (void)new KAction(i18n("&Core dump..."), 0, this, SLOT(slotFileCore()),
205 actionCollection(), "file_core_dump");
206 KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection());
209 (void)new KAction(i18n("This &Program..."), 0, this,
210 SLOT(slotFileProgSettings()), actionCollection(),
212 (void)new KAction(i18n("&Global Options..."), 0, this,
213 SLOT(slotFileGlobalSettings()), actionCollection(),
215 KStdAction::keyBindings(this, SLOT(slotConfigureKeys()), actionCollection());
216 KStdAction::showToolbar(this, SLOT(slotViewToolbar()), actionCollection());
217 KStdAction::showStatusbar(this, SLOT(slotViewStatusbar()), actionCollection());
220 (void)new KToggleAction(i18n("&Find"), "find", CTRL
+Key_F
, m_filesWindow
,
221 SLOT(slotViewFind()), actionCollection(),
223 i18n("Source &code");
224 struct { QString text
; QWidget
* w
; QString id
; } dw
[] = {
225 { i18n("Stac&k"), m_btWindow
, "view_stack"},
226 { i18n("&Locals"), m_localVariables
, "view_locals"},
227 { i18n("&Watched expressions"), m_watches
, "view_watched_expressions"},
228 { i18n("&Registers"), m_registers
, "view_registers"},
229 { i18n("&Breakpoints"), m_bpTable
, "view_breakpoints"},
230 { i18n("T&hreads"), m_threads
, "view_threads"},
231 { i18n("&Output"), m_ttyWindow
, "view_output"},
232 { i18n("&Memory"), m_memoryWindow
, "view_memory"}
234 for (unsigned i
= 0; i
< sizeof(dw
)/sizeof(dw
[0]); i
++) {
235 KDockWidget
* d
= dockParent(dw
[i
].w
);
236 (void)new KToggleAction(dw
[i
].text
, 0, d
, SLOT(changeHideShowState()),
237 actionCollection(), dw
[i
].id
);
242 KAction
* a
= new KAction(i18n("&Run"), "pgmrun", Key_F5
, m_debugger
,
243 SLOT(programRun()), actionCollection(), "exec_run");
244 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
245 a
= new KAction(i18n("Step &into"), "pgmstep", Key_F8
, m_debugger
,
246 SLOT(programStep()), actionCollection(),
248 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
249 a
= new KAction(i18n("Step &over"), "pgmnext", Key_F10
, m_debugger
,
250 SLOT(programNext()), actionCollection(),
252 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
253 a
= new KAction(i18n("Step o&ut"), "pgmfinish", Key_F6
, m_debugger
,
254 SLOT(programFinish()), actionCollection(),
256 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
257 a
= new KAction(i18n("Run to &cursor"), Key_F7
, this,
258 SLOT(slotExecUntil()), actionCollection(),
259 "exec_run_to_cursor");
260 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
261 a
= new KAction(i18n("Step i&nto by instruction"), "pgmstepi",
262 SHIFT
+Key_F8
, m_debugger
, SLOT(programStepi()),
263 actionCollection(), "exec_step_into_by_insn");
264 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
265 a
= new KAction(i18n("Step o&ver by instruction"), "pgmnexti",
266 SHIFT
+Key_F10
, m_debugger
, SLOT(programNexti()),
267 actionCollection(), "exec_step_over_by_insn");
268 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
269 (void)new KAction(i18n("&Program counter to current line"), 0,
270 m_filesWindow
, SLOT(slotMoveProgramCounter()),
271 actionCollection(), "exec_movepc");
272 (void)new KAction(i18n("&Break"), 0, m_debugger
,
273 SLOT(programBreak()), actionCollection(),
275 (void)new KAction(i18n("&Kill"), 0, m_debugger
,
276 SLOT(programKill()), actionCollection(),
278 (void)new KAction(i18n("Re&start"), 0, m_debugger
,
279 SLOT(programRunAgain()), actionCollection(),
281 (void)new KAction(i18n("A&ttach..."), 0, this,
282 SLOT(slotExecAttach()), actionCollection(),
284 (void)new KAction(i18n("&Arguments..."), 0, this,
285 SLOT(slotExecArgs()), actionCollection(),
289 (void)new KAction(i18n("Set/Clear &breakpoint"), "brkpt", Key_F9
,
290 m_filesWindow
, SLOT(slotBrkptSet()), actionCollection(),
292 (void)new KAction(i18n("Set &temporary breakpoint"), SHIFT
+Key_F9
,
293 m_filesWindow
, SLOT(slotBrkptSetTemp()), actionCollection(),
294 "breakpoint_set_temporary");
295 (void)new KAction(i18n("&Enable/Disable breakpoint"), CTRL
+Key_F9
,
296 m_filesWindow
, SLOT(slotBrkptEnable()), actionCollection(),
297 "breakpoint_enable");
299 // only in popup menus
300 (void)new KAction(i18n("Watch Expression"), 0, this,
301 SLOT(slotLocalsToWatch()), actionCollection(),
303 (void)new KAction(i18n("Edit Value"), Key_F2
, this,
304 SLOT(slotEditValue()), actionCollection(),
307 (void)new KActionMenu(i18n("&Window"), actionCollection(), "window");
309 // all actions force an UI update
310 QValueList
<KAction
*> actions
= actionCollection()->actions();
311 QValueList
<KAction
*>::Iterator it
= actions
.begin();
312 for (; it
!= actions
.end(); ++it
) {
313 connect(*it
, SIGNAL(activated()), this, SLOT(updateUI()));
316 createGUI("kdbgui.rc");
319 void DebuggerMainWnd::initToolbar()
321 KToolBar
* toolbar
= toolBar("mainToolBar");
322 toolbar
->setBarPos(KToolBar::Top
);
323 //moveToolBar(toolbar);
325 toolbar
->insertAnimatedWidget(ID_STATUS_BUSY
,
326 actionCollection()->action("exec_break"), SLOT(activate()),
328 toolbar
->alignItemRight(ID_STATUS_BUSY
, true);
329 m_animRunning
= false;
331 KStatusBar
* statusbar
= statusBar();
332 statusbar
->insertItem(m_statusActive
, ID_STATUS_ACTIVE
);
333 m_lastActiveStatusText
= m_statusActive
;
334 statusbar
->insertItem(i18n("Line 00000"), ID_STATUS_LINENO
);
335 statusbar
->insertItem("", ID_STATUS_MSG
); /* message pane */
337 // reserve some translations
343 * We must override KTMainWindow's handling of close events since we have
344 * only one toplevel window, which lives on the stack (which KTMainWindow
345 * can't live with :-( )
347 void DebuggerMainWnd::closeEvent(QCloseEvent
* e
)
349 clearWFlags(WDestructiveClose
);
351 if (m_debugger
!= 0) {
352 m_debugger
->shutdown();
360 // instance properties
361 void DebuggerMainWnd::saveProperties(KConfig
* config
)
363 // session management
364 QString executable
= "";
365 if (m_debugger
!= 0) {
366 executable
= m_debugger
->executable();
368 config
->writeEntry("executable", executable
);
371 void DebuggerMainWnd::readProperties(KConfig
* config
)
373 // session management
374 QString execName
= config
->readEntry("executable");
376 TRACE("readProperties: executable=" + execName
);
377 if (!execName
.isEmpty()) {
378 debugProgram(execName
, "");
382 const char WindowGroup
[] = "Windows";
383 const char RecentExecutables
[] = "RecentExecutables";
385 void DebuggerMainWnd::saveSettings(KConfig
* config
)
387 KConfigGroupSaver
g(config
, WindowGroup
);
389 writeDockConfig(config
);
390 fixDockConfig(config
, false); // downgrade
392 m_recentExecAction
->saveEntries(config
, RecentExecutables
);
394 DebuggerMainWndBase::saveSettings(config
);
397 void DebuggerMainWnd::restoreSettings(KConfig
* config
)
399 KConfigGroupSaver
g(config
, WindowGroup
);
401 fixDockConfig(config
, true); // upgrade
402 readDockConfig(config
);
404 // Workaround bug #87787: KDockManager stores the titles of the KDockWidgets
405 // in the config files, although they are localized:
406 // If the user changes the language, the titles remain in the previous language.
407 struct { QString text
; QWidget
* w
; } dw
[] = {
408 { i18n("Stack"), m_btWindow
},
409 { i18n("Locals"), m_localVariables
},
410 { i18n("Watches"), m_watches
},
411 { i18n("Registers"), m_registers
},
412 { i18n("Breakpoints"), m_bpTable
},
413 { i18n("Threads"), m_threads
},
414 { i18n("Output"), m_ttyWindow
},
415 { i18n("Memory"), m_memoryWindow
}
417 for (int i
= 0; i
< sizeof(dw
)/sizeof(dw
[0]); i
++)
419 KDockWidget
* w
= dockParent(dw
[i
].w
);
420 w
->setTabPageLabel(dw
[i
].text
);
421 // this actually changes the captions in the tabs:
422 QEvent
ev(QEvent::CaptionChange
);
426 m_recentExecAction
->loadEntries(config
, RecentExecutables
);
428 DebuggerMainWndBase::restoreSettings(config
);
430 emit
setTabWidth(m_tabWidth
);
433 void DebuggerMainWnd::updateUI()
435 KToggleAction
* viewFind
=
436 static_cast<KToggleAction
*>(actionCollection()->action("view_find"));
437 viewFind
->setChecked(m_filesWindow
->m_findDlg
.isVisible());
438 viewFind
->setEnabled(m_filesWindow
->hasWindows());
439 actionCollection()->action("breakpoint_set")->setEnabled(m_debugger
->canChangeBreakpoints());
440 actionCollection()->action("breakpoint_set_temporary")->setEnabled(m_debugger
->canChangeBreakpoints());
441 actionCollection()->action("breakpoint_enable")->setEnabled(m_debugger
->canChangeBreakpoints());
442 dockUpdateHelper("view_breakpoints", m_bpTable
);
443 dockUpdateHelper("view_stack", m_btWindow
);
444 dockUpdateHelper("view_locals", m_localVariables
);
445 dockUpdateHelper("view_watched_expressions", m_watches
);
446 dockUpdateHelper("view_registers", m_registers
);
447 dockUpdateHelper("view_threads", m_threads
);
448 dockUpdateHelper("view_memory", m_memoryWindow
);
449 dockUpdateHelper("view_output", m_ttyWindow
);
451 // AB: maybe in mainwndbase.cpp?
452 actionCollection()->action("file_executable")->setEnabled(m_debugger
->isIdle());
453 actionCollection()->action("settings_program")->setEnabled(m_debugger
->haveExecutable());
454 actionCollection()->action("file_core_dump")->setEnabled(m_debugger
->canStart());
455 actionCollection()->action("exec_step_into")->setEnabled(m_debugger
->canSingleStep());
456 actionCollection()->action("exec_step_into_by_insn")->setEnabled(m_debugger
->canSingleStep());
457 actionCollection()->action("exec_step_over")->setEnabled(m_debugger
->canSingleStep());
458 actionCollection()->action("exec_step_over_by_insn")->setEnabled(m_debugger
->canSingleStep());
459 actionCollection()->action("exec_step_out")->setEnabled(m_debugger
->canSingleStep());
460 actionCollection()->action("exec_run_to_cursor")->setEnabled(m_debugger
->canSingleStep());
461 actionCollection()->action("exec_movepc")->setEnabled(m_debugger
->canSingleStep());
462 actionCollection()->action("exec_restart")->setEnabled(m_debugger
->canSingleStep());
463 actionCollection()->action("exec_attach")->setEnabled(m_debugger
->isReady());
464 actionCollection()->action("exec_run")->setEnabled(m_debugger
->canStart() || m_debugger
->canSingleStep());
465 actionCollection()->action("exec_kill")->setEnabled(m_debugger
->haveExecutable() && m_debugger
->isProgramActive());
466 actionCollection()->action("exec_break")->setEnabled(m_debugger
->isProgramRunning());
467 actionCollection()->action("exec_arguments")->setEnabled(m_debugger
->haveExecutable());
468 actionCollection()->action("edit_value")->setEnabled(m_debugger
->canSingleStep());
471 KAnimWidget
* w
= toolBar("mainToolBar")->animatedWidget(ID_STATUS_BUSY
);
472 if (m_debugger
->isIdle()) {
475 m_animRunning
= false;
478 if (!m_animRunning
) {
480 m_animRunning
= true;
486 if (m_debugger
->isProgramActive())
487 newStatus
= m_statusActive
;
488 if (newStatus
!= m_lastActiveStatusText
) {
489 statusBar()->changeItem(newStatus
, ID_STATUS_ACTIVE
);
490 m_lastActiveStatusText
= newStatus
;
492 // line number is updated in slotLineChanged
495 void DebuggerMainWnd::dockUpdateHelper(QString action
, QWidget
* w
)
497 KToggleAction
* item
=
498 static_cast<KToggleAction
*>(actionCollection()->action(action
));
499 bool canChange
= canChangeDockVisibility(w
);
500 item
->setEnabled(canChange
);
501 item
->setChecked(canChange
&& isDockVisible(w
));
504 void DebuggerMainWnd::updateLineItems()
506 m_filesWindow
->updateLineItems(m_debugger
);
509 void DebuggerMainWnd::slotAddWatch()
511 if (m_debugger
!= 0) {
512 QString t
= m_watches
->watchText();
513 m_debugger
->addWatch(t
);
517 void DebuggerMainWnd::slotFileChanged()
522 if (m_debugger
->haveExecutable()) {
523 // basename part of executable
524 QString executable
= m_debugger
->executable();
525 const char* execBase
= executable
.data();
526 int lastSlash
= executable
.findRev('/');
528 execBase
+= lastSlash
+ 1;
533 bool anyWindows
= m_filesWindow
->activeLine(file
, line
);
534 updateLineStatus(anyWindows
? line
: -1);
543 void DebuggerMainWnd::slotLineChanged()
547 bool anyWindows
= m_filesWindow
->activeLine(file
, line
);
548 updateLineStatus(anyWindows
? line
: -1);
551 void DebuggerMainWnd::slotNewFileLoaded()
553 // updates program counter in the new file
555 m_filesWindow
->updateLineItems(m_debugger
);
558 void DebuggerMainWnd::updateLineStatus(int lineNo
)
561 statusBar()->changeItem("", ID_STATUS_LINENO
);
564 strLine
.sprintf(i18n("Line %d"), lineNo
+ 1);
565 statusBar()->changeItem(strLine
, ID_STATUS_LINENO
);
569 KDockWidget
* DebuggerMainWnd::dockParent(QWidget
* w
)
571 while ((w
= w
->parentWidget()) != 0) {
572 if (w
->isA("KDockWidget"))
573 return static_cast<KDockWidget
*>(w
);
578 bool DebuggerMainWnd::isDockVisible(QWidget
* w
)
580 KDockWidget
* d
= dockParent(w
);
581 return d
!= 0 && d
->mayBeHide();
584 bool DebuggerMainWnd::canChangeDockVisibility(QWidget
* w
)
586 KDockWidget
* d
= dockParent(w
);
587 return d
!= 0 && (d
->mayBeHide() || d
->mayBeShow());
590 // upgrades the entries from version 0.0.4 to 0.0.5 and back
591 void DebuggerMainWnd::fixDockConfig(KConfig
* c
, bool upgrade
)
593 static const char dockGroup
[] = "dock_setting_default";
594 if (!c
->hasGroup(dockGroup
))
597 static const char oldVersion
[] = "0.0.4";
598 static const char newVersion
[] = "0.0.5";
599 const char* from
= upgrade
? oldVersion
: newVersion
;
600 const char* to
= upgrade
? newVersion
: oldVersion
;
601 QMap
<QString
,QString
> e
= c
->entryMap(dockGroup
);
602 if (e
["Version"] != from
)
605 KConfigGroupSaver
g(c
, dockGroup
);
606 c
->writeEntry("Version", to
);
607 TRACE(upgrade
? "upgrading dockconfig" : "downgrading dockconfig");
609 // turn all orientation entries from 0 to 1 and from 1 to 0
610 QMap
<QString
,QString
>::Iterator i
;
611 for (i
= e
.begin(); i
!= e
.end(); ++i
)
613 if (i
.key().right(12) == ":orientation") {
614 TRACE("upgrading " + i
.key() + " old value: " + *i
);
615 int orientation
= c
->readNumEntry(i
.key(), -1);
616 if (orientation
>= 0) { // paranoia
617 c
->writeEntry(i
.key(), 1 - orientation
);
623 TTYWindow
* DebuggerMainWnd::ttyWindow()
628 bool DebuggerMainWnd::debugProgram(const QString
& exe
, QCString lang
)
630 // check the file name
633 bool success
= fi
.isFile();
636 QString msg
= i18n("`%1' is not a file or does not exist");
637 KMessageBox::sorry(this, msg
.arg(exe
));
641 success
= DebuggerMainWndBase::debugProgram(fi
.absFilePath(), lang
, this);
646 m_recentExecAction
->addURL(KURL(fi
.absFilePath()));
648 // keep the directory
649 m_lastDirectory
= fi
.dirPath(true);
650 m_filesWindow
->setExtraDirectory(m_lastDirectory
);
654 m_recentExecAction
->removeURL(KURL(fi
.absFilePath()));
660 void DebuggerMainWnd::slotNewStatusMsg()
662 newStatusMsg(statusBar());
665 void DebuggerMainWnd::slotFileGlobalSettings()
667 int oldTabWidth
= m_tabWidth
;
669 doGlobalOptions(this);
671 if (m_tabWidth
!= oldTabWidth
) {
672 emit
setTabWidth(m_tabWidth
);
676 void DebuggerMainWnd::slotDebuggerStarting()
678 DebuggerMainWndBase::slotDebuggerStarting();
681 void DebuggerMainWnd::slotToggleBreak(const QString
& fileName
, int lineNo
,
682 const DbgAddr
& address
, bool temp
)
684 // lineNo is zero-based
685 if (m_debugger
!= 0) {
686 m_debugger
->setBreakpoint(fileName
, lineNo
, address
, temp
);
690 void DebuggerMainWnd::slotEnaDisBreak(const QString
& fileName
, int lineNo
,
691 const DbgAddr
& address
)
693 // lineNo is zero-based
694 if (m_debugger
!= 0) {
695 m_debugger
->enableDisableBreakpoint(fileName
, lineNo
, address
);
699 QString
DebuggerMainWnd::createOutputWindow()
701 QString tty
= DebuggerMainWndBase::createOutputWindow();
702 if (!tty
.isEmpty()) {
703 connect(m_outputTermProc
, SIGNAL(processExited(KProcess
*)),
704 SLOT(slotTermEmuExited()));
709 void DebuggerMainWnd::slotTermEmuExited()
711 shutdownTermWindow();
714 void DebuggerMainWnd::slotProgramStopped()
716 // when the program stopped, move the window to the foreground
717 if (m_popForeground
) {
718 // unfortunately, this requires quite some force to work :-(
719 KWin::raiseWindow(winId());
720 KWin::forceActiveWindow(winId());
725 void DebuggerMainWnd::intoBackground()
727 if (m_popForeground
) {
728 m_backTimer
.start(m_backTimeout
, true); /* single-shot */
732 void DebuggerMainWnd::slotBackTimer()
737 void DebuggerMainWnd::slotRecentExec(const KURL
& url
)
739 QString exe
= url
.path();
740 debugProgram(exe
, "");
743 QString
DebuggerMainWnd::makeSourceFilter()
746 f
= m_sourceFilter
+ " " + m_headerFilter
+ i18n("|All source files\n");
747 f
+= m_sourceFilter
+ i18n("|Source files\n");
748 f
+= m_headerFilter
+ i18n("|Header files\n");
749 f
+= i18n("*|All files");
754 * Pop up the context menu in the locals window
756 void DebuggerMainWnd::slotLocalsPopup(QListViewItem
*, const QPoint
& pt
)
759 static_cast<QPopupMenu
*>(factory()->container("popup_locals", this));
763 if (popup
->isVisible()) {
771 * Copies the currently selected item to the watch window.
773 void DebuggerMainWnd::slotLocalsToWatch()
775 VarTree
* item
= m_localVariables
->selectedItem();
777 if (item
!= 0 && m_debugger
!= 0) {
778 QString text
= item
->computeExpr();
779 m_debugger
->addWatch(text
);
784 * Starts editing a value in a value display
786 void DebuggerMainWnd::slotEditValue()
788 // does one of the value trees have the focus
789 QWidget
* f
= kapp
->focusWidget();
791 if (f
== m_localVariables
) {
792 wnd
= m_localVariables
;
793 } else if (f
== m_watches
->watchVariables()) {
794 wnd
= m_watches
->watchVariables();
799 if (m_localVariables
->isEditing() ||
800 m_watches
->watchVariables()->isEditing())
802 return; /* don't edit twice */
805 VarTree
* expr
= wnd
->currentItem();
806 if (expr
!= 0 && m_debugger
!= 0 && m_debugger
->canSingleStep())
809 // determine the text to edit
810 QString text
= m_debugger
->driver()->editableValue(expr
);
811 wnd
->editValue(expr
, text
);
815 // Pop up the context menu of the files window (for loaded files)
816 void DebuggerMainWnd::slotFileWndMenu(const QPoint
& pos
)
819 static_cast<QPopupMenu
*>(factory()->container("popup_files", this));
823 if (popup
->isVisible()) {
826 // pos is still in widget coordinates of the sender
827 const QWidget
* w
= static_cast<const QWidget
*>(sender());
828 popup
->popup(w
->mapToGlobal(pos
));
832 // Pop up the context menu of the files window (while no file is loaded)
833 void DebuggerMainWnd::slotFileWndEmptyMenu(const QPoint
& pos
)
836 static_cast<QPopupMenu
*>(factory()->container("popup_files_empty", this));
840 if (popup
->isVisible()) {
843 // pos is still in widget coordinates of the sender
844 const QWidget
* w
= static_cast<const QWidget
*>(sender());
845 popup
->popup(w
->mapToGlobal(pos
));
849 void DebuggerMainWnd::slotFileOpen()
851 // start browsing in the active file's directory
852 // fall back to last used directory (executable)
853 QString dir
= m_lastDirectory
;
854 QString fileName
= m_filesWindow
->activeFileName();
855 if (!fileName
.isEmpty()) {
856 QFileInfo
fi(fileName
);
860 fileName
= myGetFileName(i18n("Open"),
862 makeSourceFilter(), this);
864 if (!fileName
.isEmpty())
866 QFileInfo
fi(fileName
);
867 m_lastDirectory
= fi
.dirPath();
868 m_filesWindow
->setExtraDirectory(m_lastDirectory
);
869 m_filesWindow
->activateFile(fileName
);
873 void DebuggerMainWnd::slotFileQuit()
875 if (m_debugger
!= 0) {
876 m_debugger
->shutdown();
881 void DebuggerMainWnd::slotFileExe()
883 if (m_debugger
->isIdle())
885 // open a new executable
886 QString executable
= myGetFileName(i18n("Select the executable to debug"),
887 m_lastDirectory
, 0, this);
888 if (executable
.isEmpty())
891 debugProgram(executable
, "");
895 void DebuggerMainWnd::slotFileCore()
897 if (m_debugger
->canStart())
899 QString corefile
= myGetFileName(i18n("Select core dump"),
900 m_lastDirectory
, 0, this);
901 if (!corefile
.isEmpty()) {
902 m_debugger
->useCoreFile(corefile
, false);
907 void DebuggerMainWnd::slotFileProgSettings()
909 if (m_debugger
!= 0) {
910 m_debugger
->programSettings(this);
914 void DebuggerMainWnd::slotViewToolbar()
916 if (toolBar()->isVisible())
922 void DebuggerMainWnd::slotViewStatusbar()
924 if (statusBar()->isVisible())
930 void DebuggerMainWnd::slotExecUntil()
936 if (m_filesWindow
->activeLine(file
, lineNo
))
937 m_debugger
->runUntil(file
, lineNo
);
941 void DebuggerMainWnd::slotExecAttach()
944 ProcAttachPS
dlg(this);
945 // seed filter with executable name
946 QFileInfo fi
= m_debugger
->executable();
947 dlg
.filterEdit
->setText(fi
.fileName());
949 ProcAttach
dlg(this);
950 dlg
.setText(m_debugger
->attachedPid());
953 m_debugger
->attachProgram(dlg
.text());
957 void DebuggerMainWnd::slotExecArgs()
959 if (m_debugger
!= 0) {
960 m_debugger
->programArgs(this);
964 void DebuggerMainWnd::slotConfigureKeys()
966 KKeyDialog::configure(actionCollection(), this);
969 #include "dbgmainwnd.moc"