3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
9 #include <klocale.h> /* i18n */
10 #include <kmessagebox.h>
13 #include <kcmdlineargs.h>
14 #include <kaboutdata.h>
15 #include <khelpmenu.h>
16 #include <kpopupmenu.h>
17 #else // QT_VERSION < 200
21 #include "dbgmainwnd.h"
22 #include "typetable.h"
30 #include <fcntl.h> /* open(2) */
33 #include <unistd.h> /* getopt(3) */
35 #include <stdlib.h> /* getenv(3) */
39 int main(int argc
, char** argv
)
42 KApplication
app(argc
, argv
, "kdbg");
44 QString about
= "KDbg " VERSION
" - ";
45 about
+= i18n("A Debugger\n"
46 "by Johannes Sixt <Johannes.Sixt@telecom.at>\n"
47 "with the help of many others");
49 static const char* description
=
52 KAboutData
aboutData("kdbg", "KDbg",
55 KAboutData::License_GPL
,
56 "(c) 1998-2001 Johannes Sixt",
58 "http://members.nextra.at/johsixt/kdbg.html",
59 "Johannes.Sixt@telecom.at");
60 aboutData
.addAuthor("Johannes Sixt", 0, "Johannes.Sixt@telecom.at");
61 aboutData
.addCredit("Max Judin",
62 I18N_NOOP("Docking windows"),
63 "novaprint@mtu-net.ru");
64 KCmdLineArgs::init( argc
, argv
, &aboutData
);
66 static KCmdLineOptions options
[] = {
67 { "t <file>", I18N_NOOP("transcript of conversation with the debugger"), 0 },
68 { "r <device>", I18N_NOOP("remote debugging via <device>"), 0 },
69 { "l <language>", I18N_NOOP("specify language: C, XSL"), "C"},
70 { "+[program]", I18N_NOOP("path of executable to debug"), 0 },
71 { "+[core]", I18N_NOOP("a core file to use"), 0},
74 KCmdLineArgs::addCmdLineOptions(options
);
78 KGlobal::dirs()->addResourceType("types", "share/apps/kdbg/types");
81 DebuggerMainWnd
debugger("kdbg_main");
86 helpMenu
= kapp
->getHelpMenu(false, about
);
88 KHelpMenu
* khm
= new KHelpMenu(&debugger
, &aboutData
, false);
89 helpMenu
= khm
->menu();
91 debugger
.menuBar()->insertSeparator();
92 debugger
.menuBar()->insertItem(i18n("&Help"), helpMenu
);
95 TypeTable::initTypeLibraries();
98 bool restored
= false;
99 if (app
.isRestored()) {
100 if (KMainWindow::canBeRestored(1)) {
106 app
.setMainWidget(&debugger
);
117 const char* transcript
= 0;
118 while ((ch
= getopt(argc
, argv
, "r:t:")) != -1) {
121 debugger
.setRemoteDevice(optarg
);
127 TRACE(QString().sprintf("ignoring option -%c", ch
));
133 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
134 QCString t
= args
->getOption("t");
135 const char* transcript
= t
.data();
136 QString remote
= args
->getOption("r");
137 if (!remote
.isEmpty())
138 debugger
.setRemoteDevice(remote
);
140 debugger
.setLanguage(args
->getOption("l"));
142 // check environment variable for transcript file name
143 if (transcript
== 0) {
144 transcript
= getenv("KDBG_TRANSCRIPT");
146 debugger
.setTranscript(transcript
);
149 if (!restored
&& argc
> 1) {
150 // check for core file
152 debugger
.setCoreFile(argv
[2]);
154 if (!debugger
.debugProgram(argv
[1])) {
156 TRACE("cannot start debugger");
157 KMsgBox::message(&debugger
, kapp
->appName(),
158 i18n("Cannot start debugger."),
161 debugger
.setCoreFile("");
165 if (!restored
&& args
->count() > 0) {
166 // check for core file
167 if (args
->count() > 1) {
168 debugger
.setCoreFile(args
->arg(1));
170 if (!debugger
.debugProgram(args
->arg(0))) {
172 TRACE("cannot start debugger");
173 KMessageBox::error(&debugger
, i18n("Cannot start debugger."));
174 debugger
.setCoreFile("");