Use the standard menu entry to show and hide the toolbar.
[kdbg.git] / kdbg / dbgmainwnd.cpp
blobde1fbbd999c3f662b773727eab44ecbd7c5cb96b
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #include <kapp.h>
7 #include <klocale.h> /* i18n */
8 #include <kmessagebox.h>
9 #include <kconfig.h>
10 #include <kstatusbar.h>
11 #include <kiconloader.h>
12 #include <kstdaccel.h>
13 #include <kstdaction.h>
14 #include <kaction.h>
15 #include <kpopupmenu.h>
16 #include <kfiledialog.h>
17 #include <kprocess.h>
18 #include <kkeydialog.h>
19 #include <kanimwidget.h>
20 #include <kwin.h>
21 #include <qlistbox.h>
22 #include <qfileinfo.h>
23 #include "dbgmainwnd.h"
24 #include "debugger.h"
25 #include "commandids.h"
26 #include "winstack.h"
27 #include "brkpt.h"
28 #include "threadlist.h"
29 #include "memwindow.h"
30 #include "ttywnd.h"
31 #include "procattach.h"
32 #include "dbgdriver.h"
33 #include "mydebug.h"
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
39 DebuggerMainWnd::DebuggerMainWnd(const char* name) :
40 KDockMainWindow(0, name),
41 DebuggerMainWndBase()
43 QPixmap p;
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);
50 setView(dw0);
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);
82 setStandardToolBarMenuEnabled(true);
83 initKAction();
84 initToolbar(); // kind of obsolete?
86 connect(m_watches, SIGNAL(addWatch()), SLOT(slotAddWatch()));
87 connect(m_watches, SIGNAL(deleteWatch()), m_debugger, SLOT(slotDeleteWatch()));
88 connect(m_watches, SIGNAL(textDropped(const QString&)), SLOT(slotAddWatch(const QString&)));
90 KAction* windowMenu = actionCollection()->action("window");
91 m_filesWindow->setWindowMenu(static_cast<KActionMenu*>(windowMenu)->popupMenu());
92 connect(&m_filesWindow->m_findDlg, SIGNAL(closed()), SLOT(updateUI()));
93 connect(m_filesWindow, SIGNAL(newFileLoaded()),
94 SLOT(slotNewFileLoaded()));
95 connect(m_filesWindow, SIGNAL(toggleBreak(const QString&,int,const DbgAddr&,bool)),
96 this, SLOT(slotToggleBreak(const QString&,int,const DbgAddr&,bool)));
97 connect(m_filesWindow, SIGNAL(enadisBreak(const QString&,int,const DbgAddr&)),
98 this, SLOT(slotEnaDisBreak(const QString&,int,const DbgAddr&)));
99 connect(m_debugger, SIGNAL(activateFileLine(const QString&,int,const DbgAddr&)),
100 m_filesWindow, SLOT(activate(const QString&,int,const DbgAddr&)));
101 connect(m_debugger, SIGNAL(executableUpdated()),
102 m_filesWindow, SLOT(reloadAllFiles()));
103 connect(m_debugger, SIGNAL(updatePC(const QString&,int,const DbgAddr&,int)),
104 m_filesWindow, SLOT(updatePC(const QString&,int,const DbgAddr&,int)));
105 // value popup communication
106 connect(m_filesWindow, SIGNAL(initiateValuePopup(const QString&)),
107 m_debugger, SLOT(slotValuePopup(const QString&)));
108 connect(m_debugger, SIGNAL(valuePopup(const QString&)),
109 m_filesWindow, SLOT(slotShowValueTip(const QString&)));
110 // disassembling
111 connect(m_filesWindow, SIGNAL(disassemble(const QString&, int)),
112 m_debugger, SLOT(slotDisassemble(const QString&, int)));
113 connect(m_debugger, SIGNAL(disassembled(const QString&,int,const QList<DisassembledCode>&)),
114 m_filesWindow, SLOT(slotDisassembled(const QString&,int,const QList<DisassembledCode>&)));
115 connect(m_filesWindow, SIGNAL(moveProgramCounter(const QString&,int,const DbgAddr&)),
116 m_debugger, SLOT(setProgramCounter(const QString&,int,const DbgAddr&)));
117 // program stopped
118 connect(m_debugger, SIGNAL(programStopped()), SLOT(slotProgramStopped()));
119 connect(&m_backTimer, SIGNAL(timeout()), SLOT(slotBackTimer()));
120 // tab width
121 connect(this, SIGNAL(setTabWidth(int)), m_filesWindow, SIGNAL(setTabWidth(int)));
123 // file/line updates
124 connect(m_filesWindow, SIGNAL(fileChanged()), SLOT(slotFileChanged()));
126 // connect breakpoint table
127 connect(m_bpTable, SIGNAL(activateFileLine(const QString&,int,const DbgAddr&)),
128 m_filesWindow, SLOT(activate(const QString&,int,const DbgAddr&)));
129 connect(m_debugger, SIGNAL(updateUI()), m_bpTable, SLOT(updateUI()));
130 connect(m_debugger, SIGNAL(breakpointsChanged()), m_bpTable, SLOT(updateBreakList()));
131 connect(m_debugger, SIGNAL(breakpointsChanged()), m_bpTable, SLOT(updateUI()));
133 connect(m_debugger, SIGNAL(registersChanged(QList<RegisterInfo>&)),
134 m_registers, SLOT(updateRegisters(QList<RegisterInfo>&)));
136 connect(m_debugger, SIGNAL(memoryDumpChanged(const QString&, QList<MemoryDump>&)),
137 m_memoryWindow, SLOT(slotNewMemoryDump(const QString&, QList<MemoryDump>&)));
138 connect(m_debugger, SIGNAL(saveProgramSpecific(KConfigBase*)),
139 m_memoryWindow, SLOT(saveProgramSpecific(KConfigBase*)));
140 connect(m_debugger, SIGNAL(restoreProgramSpecific(KConfigBase*)),
141 m_memoryWindow, SLOT(restoreProgramSpecific(KConfigBase*)));
143 // thread window
144 connect(m_debugger, SIGNAL(threadsChanged(QList<ThreadInfo>&)),
145 m_threads, SLOT(updateThreads(QList<ThreadInfo>&)));
146 connect(m_threads, SIGNAL(setThread(int)),
147 m_debugger, SLOT(setThread(int)));
149 // view menu changes when docking state changes
150 connect(dockManager, SIGNAL(change()), SLOT(updateUI()));
152 // popup menu of the local variables window
153 connect(m_localVariables, SIGNAL(contextMenuRequested(QListViewItem*, const QPoint&, int)),
154 this, SLOT(slotLocalsPopup(QListViewItem*, const QPoint&)));
156 restoreSettings(kapp->config());
158 updateUI();
159 m_bpTable->updateUI();
160 slotFileChanged();
163 DebuggerMainWnd::~DebuggerMainWnd()
165 saveSettings(kapp->config());
166 // must delete m_debugger early since it references our windows
167 delete m_debugger;
168 m_debugger = 0;
170 delete m_memoryWindow;
171 delete m_threads;
172 delete m_ttyWindow;
173 delete m_bpTable;
174 delete m_registers;
175 delete m_watches;
176 delete m_localVariables;
177 delete m_btWindow;
178 delete m_filesWindow;
181 void DebuggerMainWnd::initKAction()
183 // file menu
184 KAction* open = KStdAction::open(this, SLOT(slotFileOpen()),
185 actionCollection());
186 open->setText(i18n("&Open Source..."));
187 (void)new KAction(i18n("&Reload Source"), "reload", 0, m_filesWindow,
188 SLOT(slotFileReload()), actionCollection(),
189 "file_reload");
190 (void)new KAction(i18n("&Executable..."), "execopen", 0, this,
191 SLOT(slotFileExe()), actionCollection(),
192 "file_executable");
193 m_recentExecAction = new KRecentFilesAction(i18n("Recent E&xecutables"), 0,
194 this, SLOT(slotRecentExec(const KURL&)),
195 actionCollection(), "file_executable_recent");
196 (void)new KAction(i18n("&Core dump..."), 0, this, SLOT(slotFileCore()),
197 actionCollection(), "file_core_dump");
198 KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection());
200 // settings menu
201 (void)new KAction(i18n("This &Program..."), 0, this,
202 SLOT(slotFileProgSettings()), actionCollection(),
203 "settings_program");
204 (void)new KAction(i18n("&Global Options..."), 0, this,
205 SLOT(slotFileGlobalSettings()), actionCollection(),
206 "settings_global");
207 KStdAction::keyBindings(this, SLOT(slotConfigureKeys()), actionCollection());
208 KStdAction::showStatusbar(this, SLOT(slotViewStatusbar()), actionCollection());
210 // view menu
211 (void)new KToggleAction(i18n("&Find"), "find", CTRL+Key_F, m_filesWindow,
212 SLOT(slotViewFind()), actionCollection(),
213 "view_find");
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);
232 // execution menu
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(),
238 "exec_step_into");
239 connect(a, SIGNAL(activated()), this, SLOT(intoBackground()));
240 a = new KAction(i18n("Step &over"), "pgmnext", Key_F10, m_debugger,
241 SLOT(programNext()), actionCollection(),
242 "exec_step_over");
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(),
246 "exec_step_out");
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(),
265 "exec_break");
266 (void)new KAction(i18n("&Kill"), 0, m_debugger,
267 SLOT(programKill()), actionCollection(),
268 "exec_kill");
269 (void)new KAction(i18n("Re&start"), 0, m_debugger,
270 SLOT(programRunAgain()), actionCollection(),
271 "exec_restart");
272 (void)new KAction(i18n("A&ttach..."), 0, this,
273 SLOT(slotExecAttach()), actionCollection(),
274 "exec_attach");
275 (void)new KAction(i18n("&Arguments..."), 0, this,
276 SLOT(slotExecArgs()), actionCollection(),
277 "exec_arguments");
279 // breakpoint menu
280 (void)new KAction(i18n("Set/Clear &breakpoint"), "brkpt", Key_F9,
281 m_filesWindow, SLOT(slotBrkptSet()), actionCollection(),
282 "breakpoint_set");
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(),
293 "watch_expression");
294 (void)new KAction(i18n("Edit Value"), Key_F2, this,
295 SLOT(slotEditValue()), actionCollection(),
296 "edit_value");
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->insertAnimatedWidget(ID_STATUS_BUSY,
314 actionCollection()->action("exec_break"), SLOT(activate()),
315 "pulse", -1);
316 toolbar->alignItemRight(ID_STATUS_BUSY, true);
317 m_animRunning = false;
319 KStatusBar* statusbar = statusBar();
320 statusbar->insertItem(m_statusActive, ID_STATUS_ACTIVE);
321 m_lastActiveStatusText = m_statusActive;
322 statusbar->insertItem("", ID_STATUS_MSG); /* message pane */
324 // reserve some translations
325 i18n("Restart");
326 i18n("Core dump");
330 * We must override KTMainWindow's handling of close events since we have
331 * only one toplevel window, which lives on the stack (which KTMainWindow
332 * can't live with :-( )
334 void DebuggerMainWnd::closeEvent(QCloseEvent* e)
336 clearWFlags(WDestructiveClose);
338 if (m_debugger != 0) {
339 m_debugger->shutdown();
342 e->accept();
343 kapp->quit();
347 // instance properties
348 void DebuggerMainWnd::saveProperties(KConfig* config)
350 // session management
351 QString executable = "";
352 if (m_debugger != 0) {
353 executable = m_debugger->executable();
355 config->writeEntry("executable", executable);
358 void DebuggerMainWnd::readProperties(KConfig* config)
360 // session management
361 QString execName = config->readEntry("executable");
363 TRACE("readProperties: executable=" + execName);
364 if (!execName.isEmpty()) {
365 debugProgram(execName, "");
369 const char WindowGroup[] = "Windows";
370 const char RecentExecutables[] = "RecentExecutables";
371 const char LastSession[] = "LastSession";
373 void DebuggerMainWnd::saveSettings(KConfig* config)
375 KConfigGroupSaver g(config, WindowGroup);
377 writeDockConfig(config);
378 fixDockConfig(config, false); // downgrade
380 m_recentExecAction->saveEntries(config, RecentExecutables);
382 KConfigGroupSaver g2(config, LastSession);
383 config->writeEntry("Width0Locals", m_localVariables->columnWidth(0));
384 config->writeEntry("Width0Watches", m_watches->columnWidth(0));
386 DebuggerMainWndBase::saveSettings(config);
389 void DebuggerMainWnd::restoreSettings(KConfig* config)
391 KConfigGroupSaver g(config, WindowGroup);
393 fixDockConfig(config, true); // upgrade
394 readDockConfig(config);
396 // Workaround bug #87787: KDockManager stores the titles of the KDockWidgets
397 // in the config files, although they are localized:
398 // If the user changes the language, the titles remain in the previous language.
399 struct { QString text; QWidget* w; } dw[] = {
400 { i18n("Stack"), m_btWindow },
401 { i18n("Locals"), m_localVariables },
402 { i18n("Watches"), m_watches },
403 { i18n("Registers"), m_registers },
404 { i18n("Breakpoints"), m_bpTable },
405 { i18n("Threads"), m_threads },
406 { i18n("Output"), m_ttyWindow },
407 { i18n("Memory"), m_memoryWindow }
409 for (int i = 0; i < int(sizeof(dw)/sizeof(dw[0])); i++)
411 KDockWidget* w = dockParent(dw[i].w);
412 w->setTabPageLabel(dw[i].text);
413 // this actually changes the captions in the tabs:
414 QEvent ev(QEvent::CaptionChange);
415 w->event(&ev);
418 m_recentExecAction->loadEntries(config, RecentExecutables);
420 KConfigGroupSaver g2(config, LastSession);
421 int w;
422 w = config->readNumEntry("Width0Locals", -1);
423 if (w >= 0 && w < 30000)
424 m_localVariables->setColumnWidth(0, w);
425 w = config->readNumEntry("Width0Watches", -1);
426 if (w >= 0 && w < 30000)
427 m_watches->setColumnWidth(0, w);
429 DebuggerMainWndBase::restoreSettings(config);
431 emit setTabWidth(m_tabWidth);
434 void DebuggerMainWnd::updateUI()
436 KToggleAction* viewFind =
437 static_cast<KToggleAction*>(actionCollection()->action("view_find"));
438 viewFind->setChecked(m_filesWindow->m_findDlg.isVisible());
439 viewFind->setEnabled(m_filesWindow->hasWindows());
440 actionCollection()->action("breakpoint_set")->setEnabled(m_debugger->canChangeBreakpoints());
441 actionCollection()->action("breakpoint_set_temporary")->setEnabled(m_debugger->canChangeBreakpoints());
442 actionCollection()->action("breakpoint_enable")->setEnabled(m_debugger->canChangeBreakpoints());
443 dockUpdateHelper("view_breakpoints", m_bpTable);
444 dockUpdateHelper("view_stack", m_btWindow);
445 dockUpdateHelper("view_locals", m_localVariables);
446 dockUpdateHelper("view_watched_expressions", m_watches);
447 dockUpdateHelper("view_registers", m_registers);
448 dockUpdateHelper("view_threads", m_threads);
449 dockUpdateHelper("view_memory", m_memoryWindow);
450 dockUpdateHelper("view_output", m_ttyWindow);
452 // AB: maybe in mainwndbase.cpp?
453 actionCollection()->action("file_executable")->setEnabled(m_debugger->isIdle());
454 actionCollection()->action("settings_program")->setEnabled(m_debugger->haveExecutable());
455 actionCollection()->action("file_core_dump")->setEnabled(m_debugger->canStart());
456 actionCollection()->action("exec_step_into")->setEnabled(m_debugger->canSingleStep());
457 actionCollection()->action("exec_step_into_by_insn")->setEnabled(m_debugger->canSingleStep());
458 actionCollection()->action("exec_step_over")->setEnabled(m_debugger->canSingleStep());
459 actionCollection()->action("exec_step_over_by_insn")->setEnabled(m_debugger->canSingleStep());
460 actionCollection()->action("exec_step_out")->setEnabled(m_debugger->canSingleStep());
461 actionCollection()->action("exec_run_to_cursor")->setEnabled(m_debugger->canSingleStep());
462 actionCollection()->action("exec_movepc")->setEnabled(m_debugger->canSingleStep());
463 actionCollection()->action("exec_restart")->setEnabled(m_debugger->canSingleStep());
464 actionCollection()->action("exec_attach")->setEnabled(m_debugger->isReady());
465 actionCollection()->action("exec_run")->setEnabled(m_debugger->canStart() || m_debugger->canSingleStep());
466 actionCollection()->action("exec_kill")->setEnabled(m_debugger->haveExecutable() && m_debugger->isProgramActive());
467 actionCollection()->action("exec_break")->setEnabled(m_debugger->isProgramRunning());
468 actionCollection()->action("exec_arguments")->setEnabled(m_debugger->haveExecutable());
469 actionCollection()->action("edit_value")->setEnabled(m_debugger->canSingleStep());
471 // animation
472 KAnimWidget* w = toolBar("mainToolBar")->animatedWidget(ID_STATUS_BUSY);
473 if (m_debugger->isIdle()) {
474 if (m_animRunning) {
475 w->stop();
476 m_animRunning = false;
478 } else {
479 if (!m_animRunning) {
480 w->start();
481 m_animRunning = true;
485 // update statusbar
486 QString newStatus;
487 if (m_debugger->isProgramActive())
488 newStatus = m_statusActive;
489 if (newStatus != m_lastActiveStatusText) {
490 statusBar()->changeItem(newStatus, ID_STATUS_ACTIVE);
491 m_lastActiveStatusText = newStatus;
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::slotAddWatch(const QString& text)
519 if (m_debugger != 0) {
520 m_debugger->addWatch(text);
524 void DebuggerMainWnd::slotFileChanged()
526 // set caption
527 QString caption;
529 if (m_debugger->haveExecutable()) {
530 // basename part of executable
531 QString executable = m_debugger->executable();
532 const char* execBase = executable.data();
533 int lastSlash = executable.findRev('/');
534 if (lastSlash >= 0)
535 execBase += lastSlash + 1;
536 caption += execBase;
538 QString file;
539 int line;
540 bool anyWindows = m_filesWindow->activeLine(file, line);
541 if (anyWindows) {
542 caption += " (";
543 caption += file;
544 caption += ")";
546 setCaption(caption);
549 void DebuggerMainWnd::slotNewFileLoaded()
551 // updates program counter in the new file
552 if (m_debugger != 0)
553 m_filesWindow->updateLineItems(m_debugger);
556 KDockWidget* DebuggerMainWnd::dockParent(QWidget* w)
558 while ((w = w->parentWidget()) != 0) {
559 if (w->isA("KDockWidget"))
560 return static_cast<KDockWidget*>(w);
562 return 0;
565 bool DebuggerMainWnd::isDockVisible(QWidget* w)
567 KDockWidget* d = dockParent(w);
568 return d != 0 && d->mayBeHide();
571 bool DebuggerMainWnd::canChangeDockVisibility(QWidget* w)
573 KDockWidget* d = dockParent(w);
574 return d != 0 && (d->mayBeHide() || d->mayBeShow());
577 // upgrades the entries from version 0.0.4 to 0.0.5 and back
578 void DebuggerMainWnd::fixDockConfig(KConfig* c, bool upgrade)
580 static const char dockGroup[] = "dock_setting_default";
581 if (!c->hasGroup(dockGroup))
582 return;
584 static const char oldVersion[] = "0.0.4";
585 static const char newVersion[] = "0.0.5";
586 const char* from = upgrade ? oldVersion : newVersion;
587 const char* to = upgrade ? newVersion : oldVersion;
588 QMap<QString,QString> e = c->entryMap(dockGroup);
589 if (e["Version"] != from)
590 return;
592 KConfigGroupSaver g(c, dockGroup);
593 c->writeEntry("Version", to);
594 TRACE(upgrade ? "upgrading dockconfig" : "downgrading dockconfig");
596 // turn all orientation entries from 0 to 1 and from 1 to 0
597 QMap<QString,QString>::Iterator i;
598 for (i = e.begin(); i != e.end(); ++i)
600 if (i.key().right(12) == ":orientation") {
601 TRACE("upgrading " + i.key() + " old value: " + *i);
602 int orientation = c->readNumEntry(i.key(), -1);
603 if (orientation >= 0) { // paranoia
604 c->writeEntry(i.key(), 1 - orientation);
610 TTYWindow* DebuggerMainWnd::ttyWindow()
612 return m_ttyWindow;
615 bool DebuggerMainWnd::debugProgram(const QString& exe, QCString lang)
617 // check the file name
618 QFileInfo fi(exe);
620 bool success = fi.isFile();
621 if (!success)
623 QString msg = i18n("`%1' is not a file or does not exist");
624 KMessageBox::sorry(this, msg.arg(exe));
626 else
628 success = DebuggerMainWndBase::debugProgram(fi.absFilePath(), lang, this);
631 if (success)
633 m_recentExecAction->addURL(KURL(fi.absFilePath()));
635 // keep the directory
636 m_lastDirectory = fi.dirPath(true);
637 m_filesWindow->setExtraDirectory(m_lastDirectory);
639 else
641 m_recentExecAction->removeURL(KURL(fi.absFilePath()));
644 return true;
647 void DebuggerMainWnd::slotNewStatusMsg()
649 newStatusMsg(statusBar());
652 void DebuggerMainWnd::slotFileGlobalSettings()
654 int oldTabWidth = m_tabWidth;
656 doGlobalOptions(this);
658 if (m_tabWidth != oldTabWidth) {
659 emit setTabWidth(m_tabWidth);
663 void DebuggerMainWnd::slotDebuggerStarting()
665 DebuggerMainWndBase::slotDebuggerStarting();
668 void DebuggerMainWnd::slotToggleBreak(const QString& fileName, int lineNo,
669 const DbgAddr& address, bool temp)
671 // lineNo is zero-based
672 if (m_debugger != 0) {
673 m_debugger->setBreakpoint(fileName, lineNo, address, temp);
677 void DebuggerMainWnd::slotEnaDisBreak(const QString& fileName, int lineNo,
678 const DbgAddr& address)
680 // lineNo is zero-based
681 if (m_debugger != 0) {
682 m_debugger->enableDisableBreakpoint(fileName, lineNo, address);
686 QString DebuggerMainWnd::createOutputWindow()
688 QString tty = DebuggerMainWndBase::createOutputWindow();
689 if (!tty.isEmpty()) {
690 connect(m_outputTermProc, SIGNAL(processExited(KProcess*)),
691 SLOT(slotTermEmuExited()));
693 return tty;
696 void DebuggerMainWnd::slotTermEmuExited()
698 shutdownTermWindow();
701 void DebuggerMainWnd::slotProgramStopped()
703 // when the program stopped, move the window to the foreground
704 if (m_popForeground) {
705 // unfortunately, this requires quite some force to work :-(
706 KWin::raiseWindow(winId());
707 KWin::forceActiveWindow(winId());
709 m_backTimer.stop();
712 void DebuggerMainWnd::intoBackground()
714 if (m_popForeground) {
715 m_backTimer.start(m_backTimeout, true); /* single-shot */
719 void DebuggerMainWnd::slotBackTimer()
721 lower();
724 void DebuggerMainWnd::slotRecentExec(const KURL& url)
726 QString exe = url.path();
727 debugProgram(exe, "");
730 QString DebuggerMainWnd::makeSourceFilter()
732 QString f;
733 f = m_sourceFilter + " " + m_headerFilter + i18n("|All source files\n");
734 f += m_sourceFilter + i18n("|Source files\n");
735 f += m_headerFilter + i18n("|Header files\n");
736 f += i18n("*|All files");
737 return f;
741 * Pop up the context menu in the locals window
743 void DebuggerMainWnd::slotLocalsPopup(QListViewItem*, const QPoint& pt)
745 QPopupMenu* popup =
746 static_cast<QPopupMenu*>(factory()->container("popup_locals", this));
747 if (popup == 0) {
748 return;
750 if (popup->isVisible()) {
751 popup->hide();
752 } else {
753 popup->popup(pt);
758 * Copies the currently selected item to the watch window.
760 void DebuggerMainWnd::slotLocalsToWatch()
762 VarTree* item = m_localVariables->selectedItem();
764 if (item != 0 && m_debugger != 0) {
765 QString text = item->computeExpr();
766 m_debugger->addWatch(text);
771 * Starts editing a value in a value display
773 void DebuggerMainWnd::slotEditValue()
775 // does one of the value trees have the focus
776 QWidget* f = kapp->focusWidget();
777 ExprWnd* wnd;
778 if (f == m_localVariables) {
779 wnd = m_localVariables;
780 } else if (f == m_watches->watchVariables()) {
781 wnd = m_watches->watchVariables();
782 } else {
783 return;
786 if (m_localVariables->isEditing() ||
787 m_watches->watchVariables()->isEditing())
789 return; /* don't edit twice */
792 VarTree* expr = wnd->currentItem();
793 if (expr != 0 && m_debugger != 0 && m_debugger->canSingleStep())
795 TRACE("edit value");
796 // determine the text to edit
797 QString text = m_debugger->driver()->editableValue(expr);
798 wnd->editValue(expr, text);
802 void DebuggerMainWnd::slotFileOpen()
804 // start browsing in the active file's directory
805 // fall back to last used directory (executable)
806 QString dir = m_lastDirectory;
807 QString fileName = m_filesWindow->activeFileName();
808 if (!fileName.isEmpty()) {
809 QFileInfo fi(fileName);
810 dir = fi.dirPath();
813 fileName = myGetFileName(i18n("Open"),
814 dir,
815 makeSourceFilter(), this);
817 if (!fileName.isEmpty())
819 QFileInfo fi(fileName);
820 m_lastDirectory = fi.dirPath();
821 m_filesWindow->setExtraDirectory(m_lastDirectory);
822 m_filesWindow->activateFile(fileName);
826 void DebuggerMainWnd::slotFileQuit()
828 if (m_debugger != 0) {
829 m_debugger->shutdown();
831 kapp->quit();
834 void DebuggerMainWnd::slotFileExe()
836 if (m_debugger->isIdle())
838 // open a new executable
839 QString executable = myGetFileName(i18n("Select the executable to debug"),
840 m_lastDirectory, 0, this);
841 if (executable.isEmpty())
842 return;
844 debugProgram(executable, "");
848 void DebuggerMainWnd::slotFileCore()
850 if (m_debugger->canStart())
852 QString corefile = myGetFileName(i18n("Select core dump"),
853 m_lastDirectory, 0, this);
854 if (!corefile.isEmpty()) {
855 m_debugger->useCoreFile(corefile, false);
860 void DebuggerMainWnd::slotFileProgSettings()
862 if (m_debugger != 0) {
863 m_debugger->programSettings(this);
867 void DebuggerMainWnd::slotViewStatusbar()
869 if (statusBar()->isVisible())
870 statusBar()->hide();
871 else
872 statusBar()->show();
873 setSettingsDirty();
876 void DebuggerMainWnd::slotExecUntil()
878 if (m_debugger != 0)
880 QString file;
881 int lineNo;
882 if (m_filesWindow->activeLine(file, lineNo))
883 m_debugger->runUntil(file, lineNo);
887 void DebuggerMainWnd::slotExecAttach()
889 #ifdef PS_COMMAND
890 ProcAttachPS dlg(this);
891 // seed filter with executable name
892 QFileInfo fi = m_debugger->executable();
893 dlg.filterEdit->setText(fi.fileName());
894 #else
895 ProcAttach dlg(this);
896 dlg.setText(m_debugger->attachedPid());
897 #endif
898 if (dlg.exec()) {
899 m_debugger->attachProgram(dlg.text());
903 void DebuggerMainWnd::slotExecArgs()
905 if (m_debugger != 0) {
906 m_debugger->programArgs(this);
910 void DebuggerMainWnd::slotConfigureKeys()
912 KKeyDialog::configure(actionCollection(), this);
915 #include "dbgmainwnd.moc"