Extend copyright to 2018.
[kdbg.git] / kdbg / main.cpp
blob7b37ab4a633db24667b8bdb73ee5f7ca97901a30
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 */
8 #include <klocalizedstring.h> /* i18n */
9 #include <kaboutdata.h>
10 #include <kmessagebox.h>
11 #include <QApplication>
12 #include <QCommandLineParser>
13 #include <QCommandLineOption>
14 #include "dbgmainwnd.h"
15 #include "typetable.h"
16 #include "version.h"
17 #include <stdlib.h> /* getenv(3) */
18 #include "mydebug.h"
21 int main(int argc, char** argv)
23 QApplication app(argc, argv);
24 app.setApplicationName(QStringLiteral("kdbg"));
25 KLocalizedString::setApplicationDomain("kdbg");
27 KAboutData aboutData("kdbg", i18n("KDbg"),
28 KDBG_VERSION,
29 i18n("A Debugger"),
30 KAboutLicense::GPL_V2,
31 i18n("(c) 1998-2018 Johannes Sixt"),
32 {}, /* any text */
33 "http://www.kdbg.org/",
34 "j6t@kdbg.org");
35 aboutData.addAuthor(i18n("Johannes Sixt"), QString(), "j6t@kdbg.org");
36 aboutData.addCredit(i18n("Keith Isdale"),
37 i18n("XSLT debugging"),
38 "k_isdale@tpg.com.au");
39 aboutData.addCredit(i18n("Daniel Kristjansson"),
40 i18n("Register groups and formatting"),
41 "danielk@cat.nyu.edu");
42 aboutData.addCredit(i18n("David Edmundson"),
43 i18n("KDE4 porting"),
44 "david@davidedmundson.co.uk");
45 KAboutData::setApplicationData(aboutData);
47 /* take component name and org. name from KAboutData */
48 app.setApplicationName(aboutData.componentName());
49 app.setApplicationDisplayName(aboutData.displayName());
50 app.setOrganizationDomain(aboutData.organizationDomain());
51 app.setApplicationVersion(aboutData.version());
53 QApplication::setWindowIcon(QIcon::fromTheme(QLatin1String("kdbg")));
55 QCommandLineParser parser;
56 aboutData.setupCommandLine(&parser);
57 parser.setApplicationDescription(aboutData.shortDescription());
58 parser.addHelpOption();
59 parser.addVersionOption();
61 auto opt = [&](const char* opt, QString desc, const char* arg) {
62 parser.addOption(QCommandLineOption(QStringList() << QLatin1String(opt), desc, QLatin1String(arg)));
64 auto opt0 = [&](const char* opt, QString desc) {
65 parser.addOption(QCommandLineOption(QStringList() << QLatin1String(opt), desc));
67 opt("t", i18n("transcript of conversation with the debugger"), "file");
68 opt("r", i18n("remote debugging via <device>"), "device");
69 opt("l", i18n("specify language: C, XSLT"), "language");
70 opt0("x", i18n("use language XSLT (deprecated)"));
71 opt("a", i18n("specify arguments of debugged executable"), "args");
72 opt("p", i18n("specify PID of process to debug"), "pid");
73 parser.addPositionalArgument(QLatin1String("[program]"), i18n("path of executable to debug"));
74 parser.addPositionalArgument(QLatin1String("[core]"), i18n("a core file to use"));
76 parser.process(app);
78 /* process standard options */
79 aboutData.processCommandLine(&parser);
81 DebuggerMainWnd* debugger = new DebuggerMainWnd;
82 debugger->setObjectName("mainwindow");
84 /* type libraries */
85 TypeTable::initTypeLibraries();
87 // session management
88 bool restored = false;
89 if (app.isSessionRestored()) {
90 if (KMainWindow::canBeRestored(1)) {
91 debugger->restore(1);
92 restored = true;
96 debugger->show();
98 // handle options
100 QString transcript = parser.value("t");
101 QString remote = parser.value("r");
102 if (!remote.isEmpty())
103 debugger->setRemoteDevice(remote);
105 QString lang = parser.value("l");
107 // deprecated option; overrides -l
108 if (parser.isSet("x")){
109 /* run in xsldbg mode */
110 lang = "xslt";
113 // check environment variable for transcript file name
114 if (transcript.isEmpty()) {
115 transcript = getenv("KDBG_TRANSCRIPT");
117 debugger->setTranscript(transcript);
119 QString pid = parser.value("p");
120 QString programArgs = parser.value("a");
121 QStringList posArgs = parser.positionalArguments();
123 if (!restored && posArgs.count() > 0) {
124 // attach to process?
125 if (!pid.isEmpty()) {
126 TRACE("pid: " + pid);
127 debugger->setAttachPid(pid);
129 // check for core file; use it only if we're not attaching to a process
130 else if (posArgs.count() > 1 && pid.isEmpty()) {
131 debugger->setCoreFile(posArgs[1]);
133 if (!debugger->debugProgram(posArgs[0], lang)) {
134 // failed
135 TRACE("cannot start debugger");
136 KMessageBox::error(debugger, i18n("Cannot start debugger."));
138 debugger->setCoreFile(QString());
139 debugger->setAttachPid(QString());
140 } else {
141 if (!programArgs.isEmpty()) {
142 debugger->overrideProgramArguments(programArgs);
147 int rc = app.exec();
148 return rc;