Cleanup config.h usage.
[kdbg.git] / kdbg / main.cpp
blob948af38681b4aed24615a09f2c0edbd0a2a01f92
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 */
7 #include <kapplication.h>
8 #include <klocale.h> /* i18n */
9 #include <kmessagebox.h>
10 #include <kglobal.h>
11 #include <kstandarddirs.h>
12 #include <kcmdlineargs.h>
13 #include <kaboutdata.h>
14 #include <kpopupmenu.h>
15 #include <kmenubar.h>
16 #include "dbgmainwnd.h"
17 #include "typetable.h"
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 #ifndef VERSION
22 #define VERSION ""
23 #endif
24 #include <stdlib.h> /* getenv(3) */
25 #include "mydebug.h"
28 int main(int argc, char** argv)
30 KAboutData aboutData("kdbg", "KDbg",
31 VERSION,
32 I18N_NOOP("A Debugger"),
33 KAboutData::License_GPL,
34 "(c) 1998-2009 Johannes Sixt",
35 0, /* any text */
36 "http://www.kdbg.org/",
37 "j6t@kdbg.org");
38 aboutData.addAuthor("Johannes Sixt", 0, "j6t@kdbg.org");
39 aboutData.addCredit("Keith Isdale",
40 I18N_NOOP("XSLT debugging"),
41 "k_isdale@tpg.com.au");
42 aboutData.addCredit("Daniel Kristjansson",
43 I18N_NOOP("Register groups and formating"),
44 "danielk@cat.nyu.edu");
45 KCmdLineArgs::init( argc, argv, &aboutData );
47 static KCmdLineOptions options[] = {
48 { "t <file>", I18N_NOOP("transcript of conversation with the debugger"), 0 },
49 { "r <device>", I18N_NOOP("remote debugging via <device>"), 0 },
50 { "l <language>", I18N_NOOP("specify language: C, XSLT"), ""},
51 { "x", I18N_NOOP("use language XSLT (deprecated)"), 0 },
52 { "a <args>", I18N_NOOP("specify arguments of debugged executable"), 0},
53 { "p <pid>", I18N_NOOP("specify PID of process to debug"), 0},
54 { "+[program]", I18N_NOOP("path of executable to debug"), 0 },
55 { "+[core]", I18N_NOOP("a core file to use"), 0},
56 { 0, 0, 0 }
58 KCmdLineArgs::addCmdLineOptions(options);
60 KApplication app;
62 KGlobal::dirs()->addResourceType("types", "share/apps/kdbg/types");
64 DebuggerMainWnd* debugger = new DebuggerMainWnd("kdbg_main");
66 /* type libraries */
67 TypeTable::initTypeLibraries();
69 // session management
70 bool restored = false;
71 if (app.isRestored()) {
72 if (KMainWindow::canBeRestored(1)) {
73 debugger->restore(1);
74 restored = true;
78 app.setMainWidget(debugger);
80 debugger->show();
82 // handle options
84 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
85 QString transcript = args->getOption("t");
86 QString remote = args->getOption("r");
87 if (!remote.isEmpty())
88 debugger->setRemoteDevice(remote);
90 QString lang = args->getOption("l");
92 // deprecated option; overrides -l
93 if (args->isSet("x")){
94 /* run in xsldbg mode */
95 lang = "xslt";
98 // check environment variable for transcript file name
99 if (transcript.isEmpty()) {
100 transcript = getenv("KDBG_TRANSCRIPT");
102 debugger->setTranscript(transcript);
104 QString pid = args->getOption("p");
105 QString programArgs = args->getOption("a");
107 if (!restored && args->count() > 0) {
108 // attach to process?
109 if (!pid.isEmpty()) {
110 TRACE("pid: " + pid);
111 debugger->setAttachPid(pid);
113 // check for core file; use it only if we're not attaching to a process
114 else if (args->count() > 1 && pid.isEmpty()) {
115 debugger->setCoreFile(args->arg(1));
117 if (!debugger->debugProgram(args->arg(0), lang)) {
118 // failed
119 TRACE("cannot start debugger");
120 KMessageBox::error(debugger, i18n("Cannot start debugger."));
122 debugger->setCoreFile(QString());
123 debugger->setAttachPid(QString());
124 } else {
125 if (!programArgs.isEmpty()) {
126 debugger->overrideProgramArguments(programArgs);
131 int rc = app.exec();
132 return rc;