1 /*
2  * Copyright Johannes Sixt
3  * This file is licensed under the GNU General Public License Version 2.
4  * See the file COPYING in the toplevel directory of the source directory.
5  */
6 
7 #ifndef DBGMAINWND_H
8 #define DBGMAINWND_H
9 
10 #include <QPointer>
11 #include <QTimer>
12 #include <ksharedconfig.h>
13 #include <kxmlguiwindow.h>
14 #include "regwnd.h"
15 
16 class QDockWidget;
17 class QProcess;
18 class QUrl;
19 class KAnimatedButton;
20 class KRecentFilesAction;
21 class KSqueezedTextLabel;
22 class WinStack;
23 class QListWidget;
24 class ExprWnd;
25 class BreakpointTable;
26 class ThreadList;
27 class MemoryWindow;
28 class TTYWindow;
29 class WatchWindow;
30 class KDebugger;
31 class DebuggerDriver;
32 struct DbgAddr;
33 
34 class DebuggerMainWnd : public KXmlGuiWindow
35 {
36     Q_OBJECT
37 public:
38     DebuggerMainWnd();
39     ~DebuggerMainWnd();
40 
41     bool debugProgram(const QString& exe, const QString& lang);
42 
43     /**
44      * Specifies the file where to write the transcript.
45      */
46     void setTranscript(const QString& name);
47     /**
48      * Specifies the process to attach to after the program is loaded.
49      */
50     void setAttachPid(const QString& pid);
51 
52     // the following are needed to handle program arguments
53     void setCoreFile(const QString& corefile);
54     void setRemoteDevice(const QString &remoteDevice);
55     void overrideProgramArguments(const QString& args);
56 
57 protected:
58     // session properties
59     virtual void saveProperties(KConfigGroup& cg);
60     virtual void readProperties(const KConfigGroup& cg);
61     // settings
62     void saveSettings(KSharedConfigPtr);
63     void restoreSettings(KSharedConfigPtr);
64 
65     void initAnimation();
66     void initStatusBar();
67     void initKAction();
68 
69     // view windows
70     WinStack* m_filesWindow;
71     QListWidget* m_btWindow;
72     ExprWnd* m_localVariables;
73     WatchWindow* m_watches;
74     RegisterView* m_registers;
75     BreakpointTable* m_bpTable;
76     TTYWindow* m_ttyWindow;
77     ThreadList* m_threads;
78     MemoryWindow* m_memoryWindow;
79 
80     QTimer m_backTimer;
81 
82     // recent execs in File menu
83     QAction* m_closeAction;
84     QAction* m_reloadAction;
85     QAction* m_fileExecAction;
86     KRecentFilesAction* m_recentExecAction;
87     QAction* m_coreDumpAction;
88     QAction* m_settingsAction;
89     QAction* m_findAction;
90     QAction* m_btWindowAction;
91     QAction* m_localVariablesAction;
92     QAction* m_watchesAction;
93     QAction* m_registersAction;
94     QAction* m_bpTableAction;
95     QAction* m_ttyWindowAction;
96     QAction* m_threadsAction;
97     QAction* m_memoryWindowAction;
98     QAction* m_runAction;
99     QAction* m_stepIntoAction;
100     QAction* m_stepOverAction;
101     QAction* m_stepOutAction;
102     QAction* m_toCursorAction;
103     QAction* m_stepIntoIAction;
104     QAction* m_stepOverIAction;
105     QAction* m_execMovePCAction;
106     QAction* m_breakAction;
107     QAction* m_killAction;
108     QAction* m_restartAction;
109     QAction* m_attachAction;
110     QAction* m_detachAction;
111     QAction* m_argumentsAction;
112     QAction* m_bpSetAction;
113     QAction* m_bpSetTempAction;
114     QAction* m_bpEnableAction;
115     QAction* m_editValueAction;
116     QString m_lastDirectory;		/* the dir of the most recently opened file */
117 
118 protected:
119     virtual bool queryClose();
120     QAction* createAction(const QString& text, const char* icon,
121 			int shortcut, const QObject* receiver,
122 			const char* slot, const char* name);
123     QAction* createAction(const QString& text,
124 			int shortcut, const QObject* receiver,
125 			const char* slot, const char* name);
126 
127     // the debugger proper
128     QString m_debuggerCmdStr;
129     KDebugger* m_debugger;
130     QString m_transcriptFile;		/* where gdb dialog is logged */
131 
132     /**
133      * Starts to debug the specified program using the specified language
134      * driver.
135      */
136     bool startDriver(const QString& executable, QString lang);
137     DebuggerDriver* driverFromLang(QString lang);
138     /**
139      * Derives a driver name from the contents of the named file.
140      */
141     QString driverNameFromFile(const QString& exe);
142 
143     // output window
144     QString m_outputTermCmdStr;
145     QString m_outputTermKeepScript;
146     QProcess* m_outputTermProc;
147     int m_ttyLevel;
148 
149     QString createOutputWindow();
150 
151     bool m_popForeground;		/* whether main wnd raises when prog stops */
152     int m_backTimeout;			/* when wnd goes back */
153     int m_tabWidth;			/* tab width in characters (can be 0) */
154     QString m_sourceFilter;
155     QString m_headerFilter;
156     void setTerminalCmd(const QString& cmd);
157     void setDebuggerCmdStr(const QString& cmd);
158 
159     QDockWidget* createDockWidget(const char* name, const QString& title);
160     QDockWidget* dockParent(QWidget* w);
161     void makeDefaultLayout();
162 
163     QString makeSourceFilter();
164 
165     // to avoid flicker when the status bar is updated,
166     // we store the last string that we put there
167     QPointer<KAnimatedButton> m_animation;
168     QString m_lastActiveStatusText;
169     bool m_animRunning;
170 
171     // statusbar texts
172     KSqueezedTextLabel* m_statusActiveLabel;
173     QString m_statusActive;
174     KSqueezedTextLabel* m_statusMsgLabel;
175 
176 signals:
177     void setTabWidth(int tabWidth);
178 
179 public slots:
180     virtual void updateUI();
181     virtual void updateLineItems();
182     void slotAddWatch();
183     void slotAddWatch(const QString& text);
184     void slotNewFileLoaded();
185     void slotNewStatusMsg();
186     void slotDebuggerStarting();
187     void slotToggleBreak(const QString&, int, const DbgAddr&, bool);
188     void slotEnaDisBreak(const QString&, int, const DbgAddr&);
189     void slotProgramStopped();
190     void slotBackTimer();
191     void slotRecentExec(const QUrl& url);
192     void slotLocalsPopup(const QPoint& pt);
193     void slotLocalsToWatch();
194     void slotEditValue();
195 
196     void slotFileOpen();
197     void slotFileExe();
198     void slotFileCore();
199     void slotFileGlobalSettings();
200     void slotFileProgSettings();
201     void slotViewStatusbar();
202     void slotExecUntil();
203     void slotExecAttach();
204     void slotExecArgs();
205     void intoBackground();
206     void slotConfigureKeys();
207 };
208 
209 #endif // DBGMAINWND_H
210