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
, i18n("Variable"), "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)));
122 connect(m_filesWindow
, SIGNAL(fileChanged()), SLOT(slotFileChanged()));
123 connect(m_filesWindow
, SIGNAL(lineChanged()), SLOT(slotLineChanged()));
125 // connect breakpoint table
126 connect(m_bpTable
, SIGNAL(activateFileLine(const QString
&,int,const DbgAddr
&)),
127 m_filesWindow
, SLOT(activate(const QString
&,int,const DbgAddr
&)));
128 connect(m_debugger
, SIGNAL(updateUI()), m_bpTable
, SLOT(updateUI()));
129 connect(m_debugger
, SIGNAL(breakpointsChanged()), m_bpTable
, SLOT(updateBreakList()));
130 connect(m_debugger
, SIGNAL(breakpointsChanged()), m_bpTable
, SLOT(updateUI()));
132 connect(m_debugger
, SIGNAL(registersChanged(QList
<RegisterInfo
>&)),
133 m_registers
, SLOT(updateRegisters(QList
<RegisterInfo
>&)));
135 connect(m_debugger
, SIGNAL(memoryDumpChanged(const QString
&, QList
<MemoryDump
>&)),
136 m_memoryWindow
, SLOT(slotNewMemoryDump(const QString
&, QList
<MemoryDump
>&)));
137 connect(m_debugger
, SIGNAL(saveProgramSpecific(KConfigBase
*)),
138 m_memoryWindow
, SLOT(saveProgramSpecific(KConfigBase
*)));
139 connect(m_debugger
, SIGNAL(restoreProgramSpecific(KConfigBase
*)),
140 m_memoryWindow
, SLOT(restoreProgramSpecific(KConfigBase
*)));
143 connect(m_debugger
, SIGNAL(threadsChanged(QList
<ThreadInfo
>&)),
144 m_threads
, SLOT(updateThreads(QList
<ThreadInfo
>&)));
145 connect(m_threads
, SIGNAL(setThread(int)),
146 m_debugger
, SLOT(setThread(int)));
148 // view menu changes when docking state changes
149 connect(dockManager
, SIGNAL(change()), SLOT(updateUI()));
151 // popup menu of the local variables window
152 connect(m_localVariables
, SIGNAL(contextMenuRequested(QListViewItem
*, const QPoint
&, int)),
153 this, SLOT(slotLocalsPopup(QListViewItem
*, const QPoint
&)));
155 restoreSettings(kapp
->config());
158 m_bpTable
->updateUI();
162 DebuggerMainWnd::~DebuggerMainWnd()
164 saveSettings(kapp
->config());
165 // must delete m_debugger early since it references our windows
169 delete m_memoryWindow
;
175 delete m_localVariables
;
177 delete m_filesWindow
;
180 void DebuggerMainWnd::initKAction()
183 KAction
* open
= KStdAction::open(this, SLOT(slotFileOpen()),
185 open
->setText(i18n("&Open Source..."));
186 (void)new KAction(i18n("&Reload Source"), "reload", 0, m_filesWindow
,
187 SLOT(slotFileReload()), actionCollection(),
189 (void)new KAction(i18n("&Executable..."), "execopen", 0, this,
190 SLOT(slotFileExe()), actionCollection(),
192 m_recentExecAction
= new KRecentFilesAction(i18n("Recent E&xecutables"), 0,
193 this, SLOT(slotRecentExec(const KURL
&)),
194 actionCollection(), "file_executable_recent");
195 (void)new KAction(i18n("&Core dump..."), 0, this, SLOT(slotFileCore()),
196 actionCollection(), "file_core_dump");
197 KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection());
200 (void)new KAction(i18n("This &Program..."), 0, this,
201 SLOT(slotFileProgSettings()), actionCollection(),
203 (void)new KAction(i18n("&Global Options..."), 0, this,
204 SLOT(slotFileGlobalSettings()), actionCollection(),
206 KStdAction::keyBindings(this, SLOT(slotConfigureKeys()), actionCollection());
207 KStdAction::showToolbar(this, SLOT(slotViewToolbar()), actionCollection());
208 KStdAction::showStatusbar(this, SLOT(slotViewStatusbar()), actionCollection());
211 (void)new KToggleAction(i18n("&Find"), "find", CTRL
+Key_F
, m_filesWindow
,
212 SLOT(slotViewFind()), actionCollection(),
214 i18n("Source &code");
215 struct { QString text
; QWidget
* w
; QString id
; } dw
[] = {
216 { i18n("Stac&k"), m_btWindow
, "view_stack"},
217 { i18n("&Locals"), m_localVariables
, "view_locals"},
218 { i18n("&Watched expressions"), m_watches
, "view_watched_expressions"},
219 { i18n("&Registers"), m_registers
, "view_registers"},
220 { i18n("&Breakpoints"), m_bpTable
, "view_breakpoints"},
221 { i18n("T&hreads"), m_threads
, "view_threads"},
222 { i18n("&Output"), m_ttyWindow
, "view_output"},
223 { i18n("&Memory"), m_memoryWindow
, "view_memory"}
225 for (unsigned i
= 0; i
< sizeof(dw
)/sizeof(dw
[0]); i
++) {
226 KDockWidget
* d
= dockParent(dw
[i
].w
);
227 (void)new KToggleAction(dw
[i
].text
, 0, d
, SLOT(changeHideShowState()),
228 actionCollection(), dw
[i
].id
);
233 KAction
* a
= new KAction(i18n("&Run"), "pgmrun", Key_F5
, m_debugger
,
234 SLOT(programRun()), actionCollection(), "exec_run");
235 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
236 a
= new KAction(i18n("Step &into"), "pgmstep", Key_F8
, m_debugger
,
237 SLOT(programStep()), actionCollection(),
239 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
240 a
= new KAction(i18n("Step &over"), "pgmnext", Key_F10
, m_debugger
,
241 SLOT(programNext()), actionCollection(),
243 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
244 a
= new KAction(i18n("Step o&ut"), "pgmfinish", Key_F6
, m_debugger
,
245 SLOT(programFinish()), actionCollection(),
247 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
248 a
= new KAction(i18n("Run to &cursor"), Key_F7
, this,
249 SLOT(slotExecUntil()), actionCollection(),
250 "exec_run_to_cursor");
251 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
252 a
= new KAction(i18n("Step i&nto by instruction"), "pgmstepi",
253 SHIFT
+Key_F8
, m_debugger
, SLOT(programStepi()),
254 actionCollection(), "exec_step_into_by_insn");
255 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
256 a
= new KAction(i18n("Step o&ver by instruction"), "pgmnexti",
257 SHIFT
+Key_F10
, m_debugger
, SLOT(programNexti()),
258 actionCollection(), "exec_step_over_by_insn");
259 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
260 (void)new KAction(i18n("&Program counter to current line"), 0,
261 m_filesWindow
, SLOT(slotMoveProgramCounter()),
262 actionCollection(), "exec_movepc");
263 (void)new KAction(i18n("&Break"), 0, m_debugger
,
264 SLOT(programBreak()), actionCollection(),
266 (void)new KAction(i18n("&Kill"), 0, m_debugger
,
267 SLOT(programKill()), actionCollection(),
269 (void)new KAction(i18n("Re&start"), 0, m_debugger
,
270 SLOT(programRunAgain()), actionCollection(),
272 (void)new KAction(i18n("A&ttach..."), 0, this,
273 SLOT(slotExecAttach()), actionCollection(),
275 (void)new KAction(i18n("&Arguments..."), 0, this,
276 SLOT(slotExecArgs()), actionCollection(),
280 (void)new KAction(i18n("Set/Clear &breakpoint"), "brkpt", Key_F9
,
281 m_filesWindow
, SLOT(slotBrkptSet()), actionCollection(),
283 (void)new KAction(i18n("Set &temporary breakpoint"), SHIFT
+Key_F9
,
284 m_filesWindow
, SLOT(slotBrkptSetTemp()), actionCollection(),
285 "breakpoint_set_temporary");
286 (void)new KAction(i18n("&Enable/Disable breakpoint"), CTRL
+Key_F9
,
287 m_filesWindow
, SLOT(slotBrkptEnable()), actionCollection(),
288 "breakpoint_enable");
290 // only in popup menus
291 (void)new KAction(i18n("Watch Expression"), 0, this,
292 SLOT(slotLocalsToWatch()), actionCollection(),
294 (void)new KAction(i18n("Edit Value"), Key_F2
, this,
295 SLOT(slotEditValue()), actionCollection(),
298 (void)new KActionMenu(i18n("&Window"), actionCollection(), "window");
300 // all actions force an UI update
301 QValueList
<KAction
*> actions
= actionCollection()->actions();
302 QValueList
<KAction
*>::Iterator it
= actions
.begin();
303 for (; it
!= actions
.end(); ++it
) {
304 connect(*it
, SIGNAL(activated()), this, SLOT(updateUI()));
307 createGUI("kdbgui.rc");
310 void DebuggerMainWnd::initToolbar()
312 KToolBar
* toolbar
= toolBar("mainToolBar");
313 toolbar
->setBarPos(KToolBar::Top
);
314 //moveToolBar(toolbar);
316 toolbar
->insertAnimatedWidget(ID_STATUS_BUSY
,
317 actionCollection()->action("exec_break"), SLOT(activate()),
319 toolbar
->alignItemRight(ID_STATUS_BUSY
, true);
320 m_animRunning
= false;
322 KStatusBar
* statusbar
= statusBar();
323 statusbar
->insertItem(m_statusActive
, ID_STATUS_ACTIVE
);
324 m_lastActiveStatusText
= m_statusActive
;
325 statusbar
->insertItem(i18n("Line 00000"), ID_STATUS_LINENO
);
326 statusbar
->insertItem("", ID_STATUS_MSG
); /* message pane */
328 // reserve some translations
334 * We must override KTMainWindow's handling of close events since we have
335 * only one toplevel window, which lives on the stack (which KTMainWindow
336 * can't live with :-( )
338 void DebuggerMainWnd::closeEvent(QCloseEvent
* e
)
340 clearWFlags(WDestructiveClose
);
342 if (m_debugger
!= 0) {
343 m_debugger
->shutdown();
351 // instance properties
352 void DebuggerMainWnd::saveProperties(KConfig
* config
)
354 // session management
355 QString executable
= "";
356 if (m_debugger
!= 0) {
357 executable
= m_debugger
->executable();
359 config
->writeEntry("executable", executable
);
362 void DebuggerMainWnd::readProperties(KConfig
* config
)
364 // session management
365 QString execName
= config
->readEntry("executable");
367 TRACE("readProperties: executable=" + execName
);
368 if (!execName
.isEmpty()) {
369 debugProgram(execName
, "");
373 const char WindowGroup
[] = "Windows";
374 const char RecentExecutables
[] = "RecentExecutables";
375 const char LastSession
[] = "LastSession";
377 void DebuggerMainWnd::saveSettings(KConfig
* config
)
379 KConfigGroupSaver
g(config
, WindowGroup
);
381 writeDockConfig(config
);
382 fixDockConfig(config
, false); // downgrade
384 m_recentExecAction
->saveEntries(config
, RecentExecutables
);
386 KConfigGroupSaver
g2(config
, LastSession
);
387 config
->writeEntry("Width0Locals", m_localVariables
->columnWidth(0));
388 config
->writeEntry("Width0Watches", m_watches
->columnWidth(0));
390 DebuggerMainWndBase::saveSettings(config
);
393 void DebuggerMainWnd::restoreSettings(KConfig
* config
)
395 KConfigGroupSaver
g(config
, WindowGroup
);
397 fixDockConfig(config
, true); // upgrade
398 readDockConfig(config
);
400 // Workaround bug #87787: KDockManager stores the titles of the KDockWidgets
401 // in the config files, although they are localized:
402 // If the user changes the language, the titles remain in the previous language.
403 struct { QString text
; QWidget
* w
; } dw
[] = {
404 { i18n("Stack"), m_btWindow
},
405 { i18n("Locals"), m_localVariables
},
406 { i18n("Watches"), m_watches
},
407 { i18n("Registers"), m_registers
},
408 { i18n("Breakpoints"), m_bpTable
},
409 { i18n("Threads"), m_threads
},
410 { i18n("Output"), m_ttyWindow
},
411 { i18n("Memory"), m_memoryWindow
}
413 for (int i
= 0; i
< int(sizeof(dw
)/sizeof(dw
[0])); i
++)
415 KDockWidget
* w
= dockParent(dw
[i
].w
);
416 w
->setTabPageLabel(dw
[i
].text
);
417 // this actually changes the captions in the tabs:
418 QEvent
ev(QEvent::CaptionChange
);
422 m_recentExecAction
->loadEntries(config
, RecentExecutables
);
424 KConfigGroupSaver
g2(config
, LastSession
);
426 w
= config
->readNumEntry("Width0Locals", -1);
427 if (w
>= 0 && w
< 30000)
428 m_localVariables
->setColumnWidth(0, w
);
429 w
= config
->readNumEntry("Width0Watches", -1);
430 if (w
>= 0 && w
< 30000)
431 m_watches
->setColumnWidth(0, w
);
433 DebuggerMainWndBase::restoreSettings(config
);
435 emit
setTabWidth(m_tabWidth
);
438 void DebuggerMainWnd::updateUI()
440 KToggleAction
* viewFind
=
441 static_cast<KToggleAction
*>(actionCollection()->action("view_find"));
442 viewFind
->setChecked(m_filesWindow
->m_findDlg
.isVisible());
443 viewFind
->setEnabled(m_filesWindow
->hasWindows());
444 actionCollection()->action("breakpoint_set")->setEnabled(m_debugger
->canChangeBreakpoints());
445 actionCollection()->action("breakpoint_set_temporary")->setEnabled(m_debugger
->canChangeBreakpoints());
446 actionCollection()->action("breakpoint_enable")->setEnabled(m_debugger
->canChangeBreakpoints());
447 dockUpdateHelper("view_breakpoints", m_bpTable
);
448 dockUpdateHelper("view_stack", m_btWindow
);
449 dockUpdateHelper("view_locals", m_localVariables
);
450 dockUpdateHelper("view_watched_expressions", m_watches
);
451 dockUpdateHelper("view_registers", m_registers
);
452 dockUpdateHelper("view_threads", m_threads
);
453 dockUpdateHelper("view_memory", m_memoryWindow
);
454 dockUpdateHelper("view_output", m_ttyWindow
);
456 // AB: maybe in mainwndbase.cpp?
457 actionCollection()->action("file_executable")->setEnabled(m_debugger
->isIdle());
458 actionCollection()->action("settings_program")->setEnabled(m_debugger
->haveExecutable());
459 actionCollection()->action("file_core_dump")->setEnabled(m_debugger
->canStart());
460 actionCollection()->action("exec_step_into")->setEnabled(m_debugger
->canSingleStep());
461 actionCollection()->action("exec_step_into_by_insn")->setEnabled(m_debugger
->canSingleStep());
462 actionCollection()->action("exec_step_over")->setEnabled(m_debugger
->canSingleStep());
463 actionCollection()->action("exec_step_over_by_insn")->setEnabled(m_debugger
->canSingleStep());
464 actionCollection()->action("exec_step_out")->setEnabled(m_debugger
->canSingleStep());
465 actionCollection()->action("exec_run_to_cursor")->setEnabled(m_debugger
->canSingleStep());
466 actionCollection()->action("exec_movepc")->setEnabled(m_debugger
->canSingleStep());
467 actionCollection()->action("exec_restart")->setEnabled(m_debugger
->canSingleStep());
468 actionCollection()->action("exec_attach")->setEnabled(m_debugger
->isReady());
469 actionCollection()->action("exec_run")->setEnabled(m_debugger
->canStart() || m_debugger
->canSingleStep());
470 actionCollection()->action("exec_kill")->setEnabled(m_debugger
->haveExecutable() && m_debugger
->isProgramActive());
471 actionCollection()->action("exec_break")->setEnabled(m_debugger
->isProgramRunning());
472 actionCollection()->action("exec_arguments")->setEnabled(m_debugger
->haveExecutable());
473 actionCollection()->action("edit_value")->setEnabled(m_debugger
->canSingleStep());
476 KAnimWidget
* w
= toolBar("mainToolBar")->animatedWidget(ID_STATUS_BUSY
);
477 if (m_debugger
->isIdle()) {
480 m_animRunning
= false;
483 if (!m_animRunning
) {
485 m_animRunning
= true;
491 if (m_debugger
->isProgramActive())
492 newStatus
= m_statusActive
;
493 if (newStatus
!= m_lastActiveStatusText
) {
494 statusBar()->changeItem(newStatus
, ID_STATUS_ACTIVE
);
495 m_lastActiveStatusText
= newStatus
;
497 // line number is updated in slotLineChanged
500 void DebuggerMainWnd::dockUpdateHelper(QString action
, QWidget
* w
)
502 KToggleAction
* item
=
503 static_cast<KToggleAction
*>(actionCollection()->action(action
));
504 bool canChange
= canChangeDockVisibility(w
);
505 item
->setEnabled(canChange
);
506 item
->setChecked(canChange
&& isDockVisible(w
));
509 void DebuggerMainWnd::updateLineItems()
511 m_filesWindow
->updateLineItems(m_debugger
);
514 void DebuggerMainWnd::slotAddWatch()
516 if (m_debugger
!= 0) {
517 QString t
= m_watches
->watchText();
518 m_debugger
->addWatch(t
);
522 void DebuggerMainWnd::slotFileChanged()
527 if (m_debugger
->haveExecutable()) {
528 // basename part of executable
529 QString executable
= m_debugger
->executable();
530 const char* execBase
= executable
.data();
531 int lastSlash
= executable
.findRev('/');
533 execBase
+= lastSlash
+ 1;
538 bool anyWindows
= m_filesWindow
->activeLine(file
, line
);
539 updateLineStatus(anyWindows
? line
: -1);
548 void DebuggerMainWnd::slotLineChanged()
552 bool anyWindows
= m_filesWindow
->activeLine(file
, line
);
553 updateLineStatus(anyWindows
? line
: -1);
556 void DebuggerMainWnd::slotNewFileLoaded()
558 // updates program counter in the new file
560 m_filesWindow
->updateLineItems(m_debugger
);
563 void DebuggerMainWnd::updateLineStatus(int lineNo
)
566 statusBar()->changeItem("", ID_STATUS_LINENO
);
569 strLine
.sprintf(i18n("Line %d"), lineNo
+ 1);
570 statusBar()->changeItem(strLine
, ID_STATUS_LINENO
);
574 KDockWidget
* DebuggerMainWnd::dockParent(QWidget
* w
)
576 while ((w
= w
->parentWidget()) != 0) {
577 if (w
->isA("KDockWidget"))
578 return static_cast<KDockWidget
*>(w
);
583 bool DebuggerMainWnd::isDockVisible(QWidget
* w
)
585 KDockWidget
* d
= dockParent(w
);
586 return d
!= 0 && d
->mayBeHide();
589 bool DebuggerMainWnd::canChangeDockVisibility(QWidget
* w
)
591 KDockWidget
* d
= dockParent(w
);
592 return d
!= 0 && (d
->mayBeHide() || d
->mayBeShow());
595 // upgrades the entries from version 0.0.4 to 0.0.5 and back
596 void DebuggerMainWnd::fixDockConfig(KConfig
* c
, bool upgrade
)
598 static const char dockGroup
[] = "dock_setting_default";
599 if (!c
->hasGroup(dockGroup
))
602 static const char oldVersion
[] = "0.0.4";
603 static const char newVersion
[] = "0.0.5";
604 const char* from
= upgrade
? oldVersion
: newVersion
;
605 const char* to
= upgrade
? newVersion
: oldVersion
;
606 QMap
<QString
,QString
> e
= c
->entryMap(dockGroup
);
607 if (e
["Version"] != from
)
610 KConfigGroupSaver
g(c
, dockGroup
);
611 c
->writeEntry("Version", to
);
612 TRACE(upgrade
? "upgrading dockconfig" : "downgrading dockconfig");
614 // turn all orientation entries from 0 to 1 and from 1 to 0
615 QMap
<QString
,QString
>::Iterator i
;
616 for (i
= e
.begin(); i
!= e
.end(); ++i
)
618 if (i
.key().right(12) == ":orientation") {
619 TRACE("upgrading " + i
.key() + " old value: " + *i
);
620 int orientation
= c
->readNumEntry(i
.key(), -1);
621 if (orientation
>= 0) { // paranoia
622 c
->writeEntry(i
.key(), 1 - orientation
);
628 TTYWindow
* DebuggerMainWnd::ttyWindow()
633 bool DebuggerMainWnd::debugProgram(const QString
& exe
, QCString lang
)
635 // check the file name
638 bool success
= fi
.isFile();
641 QString msg
= i18n("`%1' is not a file or does not exist");
642 KMessageBox::sorry(this, msg
.arg(exe
));
646 success
= DebuggerMainWndBase::debugProgram(fi
.absFilePath(), lang
, this);
651 m_recentExecAction
->addURL(KURL(fi
.absFilePath()));
653 // keep the directory
654 m_lastDirectory
= fi
.dirPath(true);
655 m_filesWindow
->setExtraDirectory(m_lastDirectory
);
659 m_recentExecAction
->removeURL(KURL(fi
.absFilePath()));
665 void DebuggerMainWnd::slotNewStatusMsg()
667 newStatusMsg(statusBar());
670 void DebuggerMainWnd::slotFileGlobalSettings()
672 int oldTabWidth
= m_tabWidth
;
674 doGlobalOptions(this);
676 if (m_tabWidth
!= oldTabWidth
) {
677 emit
setTabWidth(m_tabWidth
);
681 void DebuggerMainWnd::slotDebuggerStarting()
683 DebuggerMainWndBase::slotDebuggerStarting();
686 void DebuggerMainWnd::slotToggleBreak(const QString
& fileName
, int lineNo
,
687 const DbgAddr
& address
, bool temp
)
689 // lineNo is zero-based
690 if (m_debugger
!= 0) {
691 m_debugger
->setBreakpoint(fileName
, lineNo
, address
, temp
);
695 void DebuggerMainWnd::slotEnaDisBreak(const QString
& fileName
, int lineNo
,
696 const DbgAddr
& address
)
698 // lineNo is zero-based
699 if (m_debugger
!= 0) {
700 m_debugger
->enableDisableBreakpoint(fileName
, lineNo
, address
);
704 QString
DebuggerMainWnd::createOutputWindow()
706 QString tty
= DebuggerMainWndBase::createOutputWindow();
707 if (!tty
.isEmpty()) {
708 connect(m_outputTermProc
, SIGNAL(processExited(KProcess
*)),
709 SLOT(slotTermEmuExited()));
714 void DebuggerMainWnd::slotTermEmuExited()
716 shutdownTermWindow();
719 void DebuggerMainWnd::slotProgramStopped()
721 // when the program stopped, move the window to the foreground
722 if (m_popForeground
) {
723 // unfortunately, this requires quite some force to work :-(
724 KWin::raiseWindow(winId());
725 KWin::forceActiveWindow(winId());
730 void DebuggerMainWnd::intoBackground()
732 if (m_popForeground
) {
733 m_backTimer
.start(m_backTimeout
, true); /* single-shot */
737 void DebuggerMainWnd::slotBackTimer()
742 void DebuggerMainWnd::slotRecentExec(const KURL
& url
)
744 QString exe
= url
.path();
745 debugProgram(exe
, "");
748 QString
DebuggerMainWnd::makeSourceFilter()
751 f
= m_sourceFilter
+ " " + m_headerFilter
+ i18n("|All source files\n");
752 f
+= m_sourceFilter
+ i18n("|Source files\n");
753 f
+= m_headerFilter
+ i18n("|Header files\n");
754 f
+= i18n("*|All files");
759 * Pop up the context menu in the locals window
761 void DebuggerMainWnd::slotLocalsPopup(QListViewItem
*, const QPoint
& pt
)
764 static_cast<QPopupMenu
*>(factory()->container("popup_locals", this));
768 if (popup
->isVisible()) {
776 * Copies the currently selected item to the watch window.
778 void DebuggerMainWnd::slotLocalsToWatch()
780 VarTree
* item
= m_localVariables
->selectedItem();
782 if (item
!= 0 && m_debugger
!= 0) {
783 QString text
= item
->computeExpr();
784 m_debugger
->addWatch(text
);
789 * Starts editing a value in a value display
791 void DebuggerMainWnd::slotEditValue()
793 // does one of the value trees have the focus
794 QWidget
* f
= kapp
->focusWidget();
796 if (f
== m_localVariables
) {
797 wnd
= m_localVariables
;
798 } else if (f
== m_watches
->watchVariables()) {
799 wnd
= m_watches
->watchVariables();
804 if (m_localVariables
->isEditing() ||
805 m_watches
->watchVariables()->isEditing())
807 return; /* don't edit twice */
810 VarTree
* expr
= wnd
->currentItem();
811 if (expr
!= 0 && m_debugger
!= 0 && m_debugger
->canSingleStep())
814 // determine the text to edit
815 QString text
= m_debugger
->driver()->editableValue(expr
);
816 wnd
->editValue(expr
, text
);
820 void DebuggerMainWnd::slotFileOpen()
822 // start browsing in the active file's directory
823 // fall back to last used directory (executable)
824 QString dir
= m_lastDirectory
;
825 QString fileName
= m_filesWindow
->activeFileName();
826 if (!fileName
.isEmpty()) {
827 QFileInfo
fi(fileName
);
831 fileName
= myGetFileName(i18n("Open"),
833 makeSourceFilter(), this);
835 if (!fileName
.isEmpty())
837 QFileInfo
fi(fileName
);
838 m_lastDirectory
= fi
.dirPath();
839 m_filesWindow
->setExtraDirectory(m_lastDirectory
);
840 m_filesWindow
->activateFile(fileName
);
844 void DebuggerMainWnd::slotFileQuit()
846 if (m_debugger
!= 0) {
847 m_debugger
->shutdown();
852 void DebuggerMainWnd::slotFileExe()
854 if (m_debugger
->isIdle())
856 // open a new executable
857 QString executable
= myGetFileName(i18n("Select the executable to debug"),
858 m_lastDirectory
, 0, this);
859 if (executable
.isEmpty())
862 debugProgram(executable
, "");
866 void DebuggerMainWnd::slotFileCore()
868 if (m_debugger
->canStart())
870 QString corefile
= myGetFileName(i18n("Select core dump"),
871 m_lastDirectory
, 0, this);
872 if (!corefile
.isEmpty()) {
873 m_debugger
->useCoreFile(corefile
, false);
878 void DebuggerMainWnd::slotFileProgSettings()
880 if (m_debugger
!= 0) {
881 m_debugger
->programSettings(this);
885 void DebuggerMainWnd::slotViewToolbar()
887 if (toolBar()->isVisible())
893 void DebuggerMainWnd::slotViewStatusbar()
895 if (statusBar()->isVisible())
901 void DebuggerMainWnd::slotExecUntil()
907 if (m_filesWindow
->activeLine(file
, lineNo
))
908 m_debugger
->runUntil(file
, lineNo
);
912 void DebuggerMainWnd::slotExecAttach()
915 ProcAttachPS
dlg(this);
916 // seed filter with executable name
917 QFileInfo fi
= m_debugger
->executable();
918 dlg
.filterEdit
->setText(fi
.fileName());
920 ProcAttach
dlg(this);
921 dlg
.setText(m_debugger
->attachedPid());
924 m_debugger
->attachProgram(dlg
.text());
928 void DebuggerMainWnd::slotExecArgs()
930 if (m_debugger
!= 0) {
931 m_debugger
->programArgs(this);
935 void DebuggerMainWnd::slotConfigureKeys()
937 KKeyDialog::configure(actionCollection(), this);
940 #include "dbgmainwnd.moc"