Update my email address.
[kdbg.git] / kdbg / dbgmainwnd.cpp
blob54cc8c264f00a33a43f2ec957ef95e7844fbe62d
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 initKAction();
83 initToolbar(); // kind of obsolete?
85 connect(m_watches, SIGNAL(addWatch()), SLOT(slotAddWatch()));
86 connect(m_watches, SIGNAL(deleteWatch()), m_debugger, SLOT(slotDeleteWatch()));
87 connect(m_watches, SIGNAL(textDropped(const QString&)), SLOT(slotAddWatch(const QString&)));
89 KAction* windowMenu = actionCollection()->action("window");
90 m_filesWindow->setWindowMenu(static_cast<KActionMenu*>(windowMenu)->popupMenu());
91 connect(&m_filesWindow->m_findDlg, SIGNAL(closed()), SLOT(updateUI()));
92 connect(m_filesWindow, SIGNAL(newFileLoaded()),
93 SLOT(slotNewFileLoaded()));
94 connect(m_filesWindow, SIGNAL(toggleBreak(const QString&,int,const DbgAddr&,bool)),
95 this, SLOT(slotToggleBreak(const QString&,int,const DbgAddr&,bool)));
96 connect(m_filesWindow, SIGNAL(enadisBreak(const QString&,int,const DbgAddr&)),
97 this, SLOT(slotEnaDisBreak(const QString&,int,const DbgAddr&)));
98 connect(m_debugger, SIGNAL(activateFileLine(const QString&,int,const DbgAddr&)),
99 m_filesWindow, SLOT(activate(const QString&,int,const DbgAddr&)));
100 connect(m_debugger, SIGNAL(executableUpdated()),
101 m_filesWindow, SLOT(reloadAllFiles()));
102 connect(m_debugger, SIGNAL(updatePC(const QString&,int,const DbgAddr&,int)),
103 m_filesWindow, SLOT(updatePC(const QString&,int,const DbgAddr&,int)));
104 // value popup communication
105 connect(m_filesWindow, SIGNAL(initiateValuePopup(const QString&)),
106 m_debugger, SLOT(slotValuePopup(const QString&)));
107 connect(m_debugger, SIGNAL(valuePopup(const QString&)),
108 m_filesWindow, SLOT(slotShowValueTip(const QString&)));
109 // disassembling
110 connect(m_filesWindow, SIGNAL(disassemble(const QString&, int)),
111 m_debugger, SLOT(slotDisassemble(const QString&, int)));
112 connect(m_debugger, SIGNAL(disassembled(const QString&,int,const QList<DisassembledCode>&)),
113 m_filesWindow, SLOT(slotDisassembled(const QString&,int,const QList<DisassembledCode>&)));
114 connect(m_filesWindow, SIGNAL(moveProgramCounter(const QString&,int,const DbgAddr&)),
115 m_debugger, SLOT(setProgramCounter(const QString&,int,const DbgAddr&)));
116 // program stopped
117 connect(m_debugger, SIGNAL(programStopped()), SLOT(slotProgramStopped()));
118 connect(&m_backTimer, SIGNAL(timeout()), SLOT(slotBackTimer()));
119 // tab width
120 connect(this, SIGNAL(setTabWidth(int)), m_filesWindow, SIGNAL(setTabWidth(int)));
122 // file/line updates
123 connect(m_filesWindow, SIGNAL(fileChanged()), SLOT(slotFileChanged()));
124 connect(m_filesWindow, SIGNAL(lineChanged()), SLOT(slotLineChanged()));
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::showToolbar(this, SLOT(slotViewToolbar()), actionCollection());
209 KStdAction::showStatusbar(this, SLOT(slotViewStatusbar()), actionCollection());
211 // view menu
212 (void)new KToggleAction(i18n("&Find"), "find", CTRL+Key_F, m_filesWindow,
213 SLOT(slotViewFind()), actionCollection(),
214 "view_find");
215 i18n("Source &code");
216 struct { QString text; QWidget* w; QString id; } dw[] = {
217 { i18n("Stac&k"), m_btWindow, "view_stack"},
218 { i18n("&Locals"), m_localVariables, "view_locals"},
219 { i18n("&Watched expressions"), m_watches, "view_watched_expressions"},
220 { i18n("&Registers"), m_registers, "view_registers"},
221 { i18n("&Breakpoints"), m_bpTable, "view_breakpoints"},
222 { i18n("T&hreads"), m_threads, "view_threads"},
223 { i18n("&Output"), m_ttyWindow, "view_output"},
224 { i18n("&Memory"), m_memoryWindow, "view_memory"}
226 for (unsigned i = 0; i < sizeof(dw)/sizeof(dw[0]); i++) {
227 KDockWidget* d = dockParent(dw[i].w);
228 (void)new KToggleAction(dw[i].text, 0, d, SLOT(changeHideShowState()),
229 actionCollection(), dw[i].id);
233 // execution menu
234 KAction* a = new KAction(i18n("&Run"), "pgmrun", Key_F5, m_debugger,
235 SLOT(programRun()), actionCollection(), "exec_run");
236 connect(a, SIGNAL(activated()), this, SLOT(intoBackground()));
237 a = new KAction(i18n("Step &into"), "pgmstep", Key_F8, m_debugger,
238 SLOT(programStep()), actionCollection(),
239 "exec_step_into");
240 connect(a, SIGNAL(activated()), this, SLOT(intoBackground()));
241 a = new KAction(i18n("Step &over"), "pgmnext", Key_F10, m_debugger,
242 SLOT(programNext()), actionCollection(),
243 "exec_step_over");
244 connect(a, SIGNAL(activated()), this, SLOT(intoBackground()));
245 a = new KAction(i18n("Step o&ut"), "pgmfinish", Key_F6, m_debugger,
246 SLOT(programFinish()), actionCollection(),
247 "exec_step_out");
248 connect(a, SIGNAL(activated()), this, SLOT(intoBackground()));
249 a = new KAction(i18n("Run to &cursor"), Key_F7, this,
250 SLOT(slotExecUntil()), actionCollection(),
251 "exec_run_to_cursor");
252 connect(a, SIGNAL(activated()), this, SLOT(intoBackground()));
253 a = new KAction(i18n("Step i&nto by instruction"), "pgmstepi",
254 SHIFT+Key_F8, m_debugger, SLOT(programStepi()),
255 actionCollection(), "exec_step_into_by_insn");
256 connect(a, SIGNAL(activated()), this, SLOT(intoBackground()));
257 a = new KAction(i18n("Step o&ver by instruction"), "pgmnexti",
258 SHIFT+Key_F10, m_debugger, SLOT(programNexti()),
259 actionCollection(), "exec_step_over_by_insn");
260 connect(a, SIGNAL(activated()), this, SLOT(intoBackground()));
261 (void)new KAction(i18n("&Program counter to current line"), 0,
262 m_filesWindow, SLOT(slotMoveProgramCounter()),
263 actionCollection(), "exec_movepc");
264 (void)new KAction(i18n("&Break"), 0, m_debugger,
265 SLOT(programBreak()), actionCollection(),
266 "exec_break");
267 (void)new KAction(i18n("&Kill"), 0, m_debugger,
268 SLOT(programKill()), actionCollection(),
269 "exec_kill");
270 (void)new KAction(i18n("Re&start"), 0, m_debugger,
271 SLOT(programRunAgain()), actionCollection(),
272 "exec_restart");
273 (void)new KAction(i18n("A&ttach..."), 0, this,
274 SLOT(slotExecAttach()), actionCollection(),
275 "exec_attach");
276 (void)new KAction(i18n("&Arguments..."), 0, this,
277 SLOT(slotExecArgs()), actionCollection(),
278 "exec_arguments");
280 // breakpoint menu
281 (void)new KAction(i18n("Set/Clear &breakpoint"), "brkpt", Key_F9,
282 m_filesWindow, SLOT(slotBrkptSet()), actionCollection(),
283 "breakpoint_set");
284 (void)new KAction(i18n("Set &temporary breakpoint"), SHIFT+Key_F9,
285 m_filesWindow, SLOT(slotBrkptSetTemp()), actionCollection(),
286 "breakpoint_set_temporary");
287 (void)new KAction(i18n("&Enable/Disable breakpoint"), CTRL+Key_F9,
288 m_filesWindow, SLOT(slotBrkptEnable()), actionCollection(),
289 "breakpoint_enable");
291 // only in popup menus
292 (void)new KAction(i18n("Watch Expression"), 0, this,
293 SLOT(slotLocalsToWatch()), actionCollection(),
294 "watch_expression");
295 (void)new KAction(i18n("Edit Value"), Key_F2, this,
296 SLOT(slotEditValue()), actionCollection(),
297 "edit_value");
299 (void)new KActionMenu(i18n("&Window"), actionCollection(), "window");
301 // all actions force an UI update
302 QValueList<KAction*> actions = actionCollection()->actions();
303 QValueList<KAction*>::Iterator it = actions.begin();
304 for (; it != actions.end(); ++it) {
305 connect(*it, SIGNAL(activated()), this, SLOT(updateUI()));
308 createGUI("kdbgui.rc");
311 void DebuggerMainWnd::initToolbar()
313 KToolBar* toolbar = toolBar("mainToolBar");
314 toolbar->setBarPos(KToolBar::Top);
315 //moveToolBar(toolbar);
317 toolbar->insertAnimatedWidget(ID_STATUS_BUSY,
318 actionCollection()->action("exec_break"), SLOT(activate()),
319 "pulse", -1);
320 toolbar->alignItemRight(ID_STATUS_BUSY, true);
321 m_animRunning = false;
323 KStatusBar* statusbar = statusBar();
324 statusbar->insertItem(m_statusActive, ID_STATUS_ACTIVE);
325 m_lastActiveStatusText = m_statusActive;
326 statusbar->insertItem(i18n("Line 00000"), ID_STATUS_LINENO);
327 statusbar->insertItem("", ID_STATUS_MSG); /* message pane */
329 // reserve some translations
330 i18n("Restart");
331 i18n("Core dump");
335 * We must override KTMainWindow's handling of close events since we have
336 * only one toplevel window, which lives on the stack (which KTMainWindow
337 * can't live with :-( )
339 void DebuggerMainWnd::closeEvent(QCloseEvent* e)
341 clearWFlags(WDestructiveClose);
343 if (m_debugger != 0) {
344 m_debugger->shutdown();
347 e->accept();
348 kapp->quit();
352 // instance properties
353 void DebuggerMainWnd::saveProperties(KConfig* config)
355 // session management
356 QString executable = "";
357 if (m_debugger != 0) {
358 executable = m_debugger->executable();
360 config->writeEntry("executable", executable);
363 void DebuggerMainWnd::readProperties(KConfig* config)
365 // session management
366 QString execName = config->readEntry("executable");
368 TRACE("readProperties: executable=" + execName);
369 if (!execName.isEmpty()) {
370 debugProgram(execName, "");
374 const char WindowGroup[] = "Windows";
375 const char RecentExecutables[] = "RecentExecutables";
376 const char LastSession[] = "LastSession";
378 void DebuggerMainWnd::saveSettings(KConfig* config)
380 KConfigGroupSaver g(config, WindowGroup);
382 writeDockConfig(config);
383 fixDockConfig(config, false); // downgrade
385 m_recentExecAction->saveEntries(config, RecentExecutables);
387 KConfigGroupSaver g2(config, LastSession);
388 config->writeEntry("Width0Locals", m_localVariables->columnWidth(0));
389 config->writeEntry("Width0Watches", m_watches->columnWidth(0));
391 DebuggerMainWndBase::saveSettings(config);
394 void DebuggerMainWnd::restoreSettings(KConfig* config)
396 KConfigGroupSaver g(config, WindowGroup);
398 fixDockConfig(config, true); // upgrade
399 readDockConfig(config);
401 // Workaround bug #87787: KDockManager stores the titles of the KDockWidgets
402 // in the config files, although they are localized:
403 // If the user changes the language, the titles remain in the previous language.
404 struct { QString text; QWidget* w; } dw[] = {
405 { i18n("Stack"), m_btWindow },
406 { i18n("Locals"), m_localVariables },
407 { i18n("Watches"), m_watches },
408 { i18n("Registers"), m_registers },
409 { i18n("Breakpoints"), m_bpTable },
410 { i18n("Threads"), m_threads },
411 { i18n("Output"), m_ttyWindow },
412 { i18n("Memory"), m_memoryWindow }
414 for (int i = 0; i < int(sizeof(dw)/sizeof(dw[0])); i++)
416 KDockWidget* w = dockParent(dw[i].w);
417 w->setTabPageLabel(dw[i].text);
418 // this actually changes the captions in the tabs:
419 QEvent ev(QEvent::CaptionChange);
420 w->event(&ev);
423 m_recentExecAction->loadEntries(config, RecentExecutables);
425 KConfigGroupSaver g2(config, LastSession);
426 int w;
427 w = config->readNumEntry("Width0Locals", -1);
428 if (w >= 0 && w < 30000)
429 m_localVariables->setColumnWidth(0, w);
430 w = config->readNumEntry("Width0Watches", -1);
431 if (w >= 0 && w < 30000)
432 m_watches->setColumnWidth(0, w);
434 DebuggerMainWndBase::restoreSettings(config);
436 emit setTabWidth(m_tabWidth);
439 void DebuggerMainWnd::updateUI()
441 KToggleAction* viewFind =
442 static_cast<KToggleAction*>(actionCollection()->action("view_find"));
443 viewFind->setChecked(m_filesWindow->m_findDlg.isVisible());
444 viewFind->setEnabled(m_filesWindow->hasWindows());
445 actionCollection()->action("breakpoint_set")->setEnabled(m_debugger->canChangeBreakpoints());
446 actionCollection()->action("breakpoint_set_temporary")->setEnabled(m_debugger->canChangeBreakpoints());
447 actionCollection()->action("breakpoint_enable")->setEnabled(m_debugger->canChangeBreakpoints());
448 dockUpdateHelper("view_breakpoints", m_bpTable);
449 dockUpdateHelper("view_stack", m_btWindow);
450 dockUpdateHelper("view_locals", m_localVariables);
451 dockUpdateHelper("view_watched_expressions", m_watches);
452 dockUpdateHelper("view_registers", m_registers);
453 dockUpdateHelper("view_threads", m_threads);
454 dockUpdateHelper("view_memory", m_memoryWindow);
455 dockUpdateHelper("view_output", m_ttyWindow);
457 // AB: maybe in mainwndbase.cpp?
458 actionCollection()->action("file_executable")->setEnabled(m_debugger->isIdle());
459 actionCollection()->action("settings_program")->setEnabled(m_debugger->haveExecutable());
460 actionCollection()->action("file_core_dump")->setEnabled(m_debugger->canStart());
461 actionCollection()->action("exec_step_into")->setEnabled(m_debugger->canSingleStep());
462 actionCollection()->action("exec_step_into_by_insn")->setEnabled(m_debugger->canSingleStep());
463 actionCollection()->action("exec_step_over")->setEnabled(m_debugger->canSingleStep());
464 actionCollection()->action("exec_step_over_by_insn")->setEnabled(m_debugger->canSingleStep());
465 actionCollection()->action("exec_step_out")->setEnabled(m_debugger->canSingleStep());
466 actionCollection()->action("exec_run_to_cursor")->setEnabled(m_debugger->canSingleStep());
467 actionCollection()->action("exec_movepc")->setEnabled(m_debugger->canSingleStep());
468 actionCollection()->action("exec_restart")->setEnabled(m_debugger->canSingleStep());
469 actionCollection()->action("exec_attach")->setEnabled(m_debugger->isReady());
470 actionCollection()->action("exec_run")->setEnabled(m_debugger->canStart() || m_debugger->canSingleStep());
471 actionCollection()->action("exec_kill")->setEnabled(m_debugger->haveExecutable() && m_debugger->isProgramActive());
472 actionCollection()->action("exec_break")->setEnabled(m_debugger->isProgramRunning());
473 actionCollection()->action("exec_arguments")->setEnabled(m_debugger->haveExecutable());
474 actionCollection()->action("edit_value")->setEnabled(m_debugger->canSingleStep());
476 // animation
477 KAnimWidget* w = toolBar("mainToolBar")->animatedWidget(ID_STATUS_BUSY);
478 if (m_debugger->isIdle()) {
479 if (m_animRunning) {
480 w->stop();
481 m_animRunning = false;
483 } else {
484 if (!m_animRunning) {
485 w->start();
486 m_animRunning = true;
490 // update statusbar
491 QString newStatus;
492 if (m_debugger->isProgramActive())
493 newStatus = m_statusActive;
494 if (newStatus != m_lastActiveStatusText) {
495 statusBar()->changeItem(newStatus, ID_STATUS_ACTIVE);
496 m_lastActiveStatusText = newStatus;
498 // line number is updated in slotLineChanged
501 void DebuggerMainWnd::dockUpdateHelper(QString action, QWidget* w)
503 KToggleAction* item =
504 static_cast<KToggleAction*>(actionCollection()->action(action));
505 bool canChange = canChangeDockVisibility(w);
506 item->setEnabled(canChange);
507 item->setChecked(canChange && isDockVisible(w));
510 void DebuggerMainWnd::updateLineItems()
512 m_filesWindow->updateLineItems(m_debugger);
515 void DebuggerMainWnd::slotAddWatch()
517 if (m_debugger != 0) {
518 QString t = m_watches->watchText();
519 m_debugger->addWatch(t);
523 void DebuggerMainWnd::slotAddWatch(const QString& text)
525 if (m_debugger != 0) {
526 m_debugger->addWatch(text);
530 void DebuggerMainWnd::slotFileChanged()
532 // set caption
533 QString caption;
535 if (m_debugger->haveExecutable()) {
536 // basename part of executable
537 QString executable = m_debugger->executable();
538 const char* execBase = executable.data();
539 int lastSlash = executable.findRev('/');
540 if (lastSlash >= 0)
541 execBase += lastSlash + 1;
542 caption += execBase;
544 QString file;
545 int line;
546 bool anyWindows = m_filesWindow->activeLine(file, line);
547 updateLineStatus(anyWindows ? line : -1);
548 if (anyWindows) {
549 caption += " (";
550 caption += file;
551 caption += ")";
553 setCaption(caption);
556 void DebuggerMainWnd::slotLineChanged()
558 QString file;
559 int line;
560 bool anyWindows = m_filesWindow->activeLine(file, line);
561 updateLineStatus(anyWindows ? line : -1);
564 void DebuggerMainWnd::slotNewFileLoaded()
566 // updates program counter in the new file
567 if (m_debugger != 0)
568 m_filesWindow->updateLineItems(m_debugger);
571 void DebuggerMainWnd::updateLineStatus(int lineNo)
573 if (lineNo < 0) {
574 statusBar()->changeItem("", ID_STATUS_LINENO);
575 } else {
576 QString strLine;
577 strLine.sprintf(i18n("Line %d"), lineNo + 1);
578 statusBar()->changeItem(strLine, ID_STATUS_LINENO);
582 KDockWidget* DebuggerMainWnd::dockParent(QWidget* w)
584 while ((w = w->parentWidget()) != 0) {
585 if (w->isA("KDockWidget"))
586 return static_cast<KDockWidget*>(w);
588 return 0;
591 bool DebuggerMainWnd::isDockVisible(QWidget* w)
593 KDockWidget* d = dockParent(w);
594 return d != 0 && d->mayBeHide();
597 bool DebuggerMainWnd::canChangeDockVisibility(QWidget* w)
599 KDockWidget* d = dockParent(w);
600 return d != 0 && (d->mayBeHide() || d->mayBeShow());
603 // upgrades the entries from version 0.0.4 to 0.0.5 and back
604 void DebuggerMainWnd::fixDockConfig(KConfig* c, bool upgrade)
606 static const char dockGroup[] = "dock_setting_default";
607 if (!c->hasGroup(dockGroup))
608 return;
610 static const char oldVersion[] = "0.0.4";
611 static const char newVersion[] = "0.0.5";
612 const char* from = upgrade ? oldVersion : newVersion;
613 const char* to = upgrade ? newVersion : oldVersion;
614 QMap<QString,QString> e = c->entryMap(dockGroup);
615 if (e["Version"] != from)
616 return;
618 KConfigGroupSaver g(c, dockGroup);
619 c->writeEntry("Version", to);
620 TRACE(upgrade ? "upgrading dockconfig" : "downgrading dockconfig");
622 // turn all orientation entries from 0 to 1 and from 1 to 0
623 QMap<QString,QString>::Iterator i;
624 for (i = e.begin(); i != e.end(); ++i)
626 if (i.key().right(12) == ":orientation") {
627 TRACE("upgrading " + i.key() + " old value: " + *i);
628 int orientation = c->readNumEntry(i.key(), -1);
629 if (orientation >= 0) { // paranoia
630 c->writeEntry(i.key(), 1 - orientation);
636 TTYWindow* DebuggerMainWnd::ttyWindow()
638 return m_ttyWindow;
641 bool DebuggerMainWnd::debugProgram(const QString& exe, QCString lang)
643 // check the file name
644 QFileInfo fi(exe);
646 bool success = fi.isFile();
647 if (!success)
649 QString msg = i18n("`%1' is not a file or does not exist");
650 KMessageBox::sorry(this, msg.arg(exe));
652 else
654 success = DebuggerMainWndBase::debugProgram(fi.absFilePath(), lang, this);
657 if (success)
659 m_recentExecAction->addURL(KURL(fi.absFilePath()));
661 // keep the directory
662 m_lastDirectory = fi.dirPath(true);
663 m_filesWindow->setExtraDirectory(m_lastDirectory);
665 else
667 m_recentExecAction->removeURL(KURL(fi.absFilePath()));
670 return true;
673 void DebuggerMainWnd::slotNewStatusMsg()
675 newStatusMsg(statusBar());
678 void DebuggerMainWnd::slotFileGlobalSettings()
680 int oldTabWidth = m_tabWidth;
682 doGlobalOptions(this);
684 if (m_tabWidth != oldTabWidth) {
685 emit setTabWidth(m_tabWidth);
689 void DebuggerMainWnd::slotDebuggerStarting()
691 DebuggerMainWndBase::slotDebuggerStarting();
694 void DebuggerMainWnd::slotToggleBreak(const QString& fileName, int lineNo,
695 const DbgAddr& address, bool temp)
697 // lineNo is zero-based
698 if (m_debugger != 0) {
699 m_debugger->setBreakpoint(fileName, lineNo, address, temp);
703 void DebuggerMainWnd::slotEnaDisBreak(const QString& fileName, int lineNo,
704 const DbgAddr& address)
706 // lineNo is zero-based
707 if (m_debugger != 0) {
708 m_debugger->enableDisableBreakpoint(fileName, lineNo, address);
712 QString DebuggerMainWnd::createOutputWindow()
714 QString tty = DebuggerMainWndBase::createOutputWindow();
715 if (!tty.isEmpty()) {
716 connect(m_outputTermProc, SIGNAL(processExited(KProcess*)),
717 SLOT(slotTermEmuExited()));
719 return tty;
722 void DebuggerMainWnd::slotTermEmuExited()
724 shutdownTermWindow();
727 void DebuggerMainWnd::slotProgramStopped()
729 // when the program stopped, move the window to the foreground
730 if (m_popForeground) {
731 // unfortunately, this requires quite some force to work :-(
732 KWin::raiseWindow(winId());
733 KWin::forceActiveWindow(winId());
735 m_backTimer.stop();
738 void DebuggerMainWnd::intoBackground()
740 if (m_popForeground) {
741 m_backTimer.start(m_backTimeout, true); /* single-shot */
745 void DebuggerMainWnd::slotBackTimer()
747 lower();
750 void DebuggerMainWnd::slotRecentExec(const KURL& url)
752 QString exe = url.path();
753 debugProgram(exe, "");
756 QString DebuggerMainWnd::makeSourceFilter()
758 QString f;
759 f = m_sourceFilter + " " + m_headerFilter + i18n("|All source files\n");
760 f += m_sourceFilter + i18n("|Source files\n");
761 f += m_headerFilter + i18n("|Header files\n");
762 f += i18n("*|All files");
763 return f;
767 * Pop up the context menu in the locals window
769 void DebuggerMainWnd::slotLocalsPopup(QListViewItem*, const QPoint& pt)
771 QPopupMenu* popup =
772 static_cast<QPopupMenu*>(factory()->container("popup_locals", this));
773 if (popup == 0) {
774 return;
776 if (popup->isVisible()) {
777 popup->hide();
778 } else {
779 popup->popup(pt);
784 * Copies the currently selected item to the watch window.
786 void DebuggerMainWnd::slotLocalsToWatch()
788 VarTree* item = m_localVariables->selectedItem();
790 if (item != 0 && m_debugger != 0) {
791 QString text = item->computeExpr();
792 m_debugger->addWatch(text);
797 * Starts editing a value in a value display
799 void DebuggerMainWnd::slotEditValue()
801 // does one of the value trees have the focus
802 QWidget* f = kapp->focusWidget();
803 ExprWnd* wnd;
804 if (f == m_localVariables) {
805 wnd = m_localVariables;
806 } else if (f == m_watches->watchVariables()) {
807 wnd = m_watches->watchVariables();
808 } else {
809 return;
812 if (m_localVariables->isEditing() ||
813 m_watches->watchVariables()->isEditing())
815 return; /* don't edit twice */
818 VarTree* expr = wnd->currentItem();
819 if (expr != 0 && m_debugger != 0 && m_debugger->canSingleStep())
821 TRACE("edit value");
822 // determine the text to edit
823 QString text = m_debugger->driver()->editableValue(expr);
824 wnd->editValue(expr, text);
828 void DebuggerMainWnd::slotFileOpen()
830 // start browsing in the active file's directory
831 // fall back to last used directory (executable)
832 QString dir = m_lastDirectory;
833 QString fileName = m_filesWindow->activeFileName();
834 if (!fileName.isEmpty()) {
835 QFileInfo fi(fileName);
836 dir = fi.dirPath();
839 fileName = myGetFileName(i18n("Open"),
840 dir,
841 makeSourceFilter(), this);
843 if (!fileName.isEmpty())
845 QFileInfo fi(fileName);
846 m_lastDirectory = fi.dirPath();
847 m_filesWindow->setExtraDirectory(m_lastDirectory);
848 m_filesWindow->activateFile(fileName);
852 void DebuggerMainWnd::slotFileQuit()
854 if (m_debugger != 0) {
855 m_debugger->shutdown();
857 kapp->quit();
860 void DebuggerMainWnd::slotFileExe()
862 if (m_debugger->isIdle())
864 // open a new executable
865 QString executable = myGetFileName(i18n("Select the executable to debug"),
866 m_lastDirectory, 0, this);
867 if (executable.isEmpty())
868 return;
870 debugProgram(executable, "");
874 void DebuggerMainWnd::slotFileCore()
876 if (m_debugger->canStart())
878 QString corefile = myGetFileName(i18n("Select core dump"),
879 m_lastDirectory, 0, this);
880 if (!corefile.isEmpty()) {
881 m_debugger->useCoreFile(corefile, false);
886 void DebuggerMainWnd::slotFileProgSettings()
888 if (m_debugger != 0) {
889 m_debugger->programSettings(this);
893 void DebuggerMainWnd::slotViewToolbar()
895 if (toolBar()->isVisible())
896 toolBar()->hide();
897 else
898 toolBar()->show();
901 void DebuggerMainWnd::slotViewStatusbar()
903 if (statusBar()->isVisible())
904 statusBar()->hide();
905 else
906 statusBar()->show();
909 void DebuggerMainWnd::slotExecUntil()
911 if (m_debugger != 0)
913 QString file;
914 int lineNo;
915 if (m_filesWindow->activeLine(file, lineNo))
916 m_debugger->runUntil(file, lineNo);
920 void DebuggerMainWnd::slotExecAttach()
922 #ifdef PS_COMMAND
923 ProcAttachPS dlg(this);
924 // seed filter with executable name
925 QFileInfo fi = m_debugger->executable();
926 dlg.filterEdit->setText(fi.fileName());
927 #else
928 ProcAttach dlg(this);
929 dlg.setText(m_debugger->attachedPid());
930 #endif
931 if (dlg.exec()) {
932 m_debugger->attachProgram(dlg.text());
936 void DebuggerMainWnd::slotExecArgs()
938 if (m_debugger != 0) {
939 m_debugger->programArgs(this);
943 void DebuggerMainWnd::slotConfigureKeys()
945 KKeyDialog::configure(actionCollection(), this);
948 #include "dbgmainwnd.moc"