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 #else // QT_VERSION < 200
19 #include <kstdaccel.h>
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 { "+[program]", I18N_NOOP("path of executable to debug"), 0 },
70 { "+[core]", I18N_NOOP("a core file to use"), 0}
72 KCmdLineArgs::addCmdLineOptions(options
);
76 KGlobal::dirs()->addResourceType("types", "share/apps/kdbg/types");
79 keys
= new KStdAccel();
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 // check environment variable for transcript file name
141 if (transcript
== 0) {
142 transcript
= getenv("KDBG_TRANSCRIPT");
144 debugger
.setTranscript(transcript
);
147 if (!restored
&& argc
> 1) {
148 // check for core file
150 debugger
.setCoreFile(argv
[2]);
152 if (!debugger
.debugProgram(argv
[1])) {
154 TRACE("cannot start debugger");
155 KMsgBox::message(&debugger
, kapp
->appName(),
156 i18n("Cannot start debugger."),
159 debugger
.setCoreFile("");
163 if (!restored
&& args
->count() > 0) {
164 // check for core file
165 if (args
->count() > 1) {
166 debugger
.setCoreFile(args
->arg(1));
168 if (!debugger
.debugProgram(args
->arg(0))) {
170 TRACE("cannot start debugger");
171 KMessageBox::error(&debugger
, i18n("Cannot start debugger."));
172 debugger
.setCoreFile("");