From 9a2b766d1e76e16078fc35c426881cae4154c5b9 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sun, 17 Feb 2002 20:27:12 +0000 Subject: [PATCH] Added a framework to specify different debugger drivers on the command line. --- kdbg/dbgmainwnd.cpp | 5 +++ kdbg/dbgmainwnd.h | 2 ++ kdbg/main.cpp | 3 ++ kdbg/mainwndbase.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++--------- kdbg/mainwndbase.h | 8 ++++- 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/kdbg/dbgmainwnd.cpp b/kdbg/dbgmainwnd.cpp index c6890c1..c2f8ec5 100644 --- a/kdbg/dbgmainwnd.cpp +++ b/kdbg/dbgmainwnd.cpp @@ -695,6 +695,11 @@ TTYWindow* DebuggerMainWnd::ttyWindow() return m_ttyWindow; } +bool DebuggerMainWnd::debugProgram(const QString& exe) +{ + return DebuggerMainWndBase::debugProgram(exe, this); +} + void DebuggerMainWnd::slotNewStatusMsg() { DebuggerMainWndBase::slotNewStatusMsg(); diff --git a/kdbg/dbgmainwnd.h b/kdbg/dbgmainwnd.h index 8c2f207..07c75af 100644 --- a/kdbg/dbgmainwnd.h +++ b/kdbg/dbgmainwnd.h @@ -28,6 +28,8 @@ public: DebuggerMainWnd(const char* name); ~DebuggerMainWnd(); + bool debugProgram(const QString& exe); + protected: // session properties virtual void saveProperties(KConfig*); diff --git a/kdbg/main.cpp b/kdbg/main.cpp index 7523c29..dc6dfa3 100644 --- a/kdbg/main.cpp +++ b/kdbg/main.cpp @@ -66,6 +66,7 @@ int main(int argc, char** argv) static KCmdLineOptions options[] = { { "t ", I18N_NOOP("transcript of conversation with the debugger"), 0 }, { "r ", I18N_NOOP("remote debugging via "), 0 }, + { "l ", I18N_NOOP("specify language: C, XSL"), "C"}, { "+[program]", I18N_NOOP("path of executable to debug"), 0 }, { "+[core]", I18N_NOOP("a core file to use"), 0}, { 0, 0, 0 } @@ -135,6 +136,8 @@ int main(int argc, char** argv) QString remote = args->getOption("r"); if (!remote.isEmpty()) debugger.setRemoteDevice(remote); + + debugger.setLanguage(args->getOption("l")); #endif // check environment variable for transcript file name if (transcript == 0) { diff --git a/kdbg/mainwndbase.cpp b/kdbg/mainwndbase.cpp index ad17c82..2942bc9 100644 --- a/kdbg/mainwndbase.cpp +++ b/kdbg/mainwndbase.cpp @@ -196,6 +196,11 @@ void DebuggerMainWndBase::setTranscript(const char* name) m_debugger->driver()->setLogFileName(m_transcriptFile); } +void DebuggerMainWndBase::setLanguage(const QCString& lang) +{ + m_language = lang.lower(); +} + const char OutputWindowGroup[] = "OutputWindow"; const char TermCmdStr[] = "TermCmdStr"; const char KeepScript[] = "KeepScript"; @@ -262,21 +267,85 @@ void DebuggerMainWndBase::restoreSettings(KConfig* config) config->readListEntry(RecentExecutables, m_recentExecList,','); } -bool DebuggerMainWndBase::debugProgram(const QString& executable) +bool DebuggerMainWndBase::debugProgram(const QString& executable, QWidget* parent) { assert(m_debugger != 0); - GdbDriver* driver = new GdbDriver; + DebuggerDriver* driver = driverFromLang(m_language); + if (driver == 0) + { + // oops + QString msg = i18n("Don't know how to debug language `%1'"); + KMessageBox::sorry(parent, msg.arg(m_language)); + return false; + } + driver->setLogFileName(m_transcriptFile); bool success = m_debugger->debugProgram(executable, driver); if (!success) + { delete driver; + QString msg = i18n("Could not start the debugger process.\n" + "Please shut down KDbg and resolve the problem."); + KMessageBox::sorry(parent, msg); + } + return success; } +// derive driver from language +DebuggerDriver* DebuggerMainWndBase::driverFromLang(const QCString& lang) +{ + // lang must be in all lowercase + assert(lang == lang.lower()); + + // The following table relates languages and debugger drivers + static const struct L { + const char* shortest; // abbreviated to this is still unique + const char* full; // full name of language + int driver; + } langs[] = { + { "c", "c++", 1 }, + { "f", "fortran", 1 }, + { "p", "python", 3 }, + { "x", "xsl", 2 }, + }; + const int N = sizeof(langs)/sizeof(langs[0]); + + // lookup the language name + // note that it has been set to lower-case in setLanguage() + int driverID = 0; + for (int i = 0; i < N; i++) + { + const L& l = langs[i]; + + // shortest must match + if (strncmp(l.shortest, lang, strlen(l.shortest)) != 0) + continue; + + // lang must not be longer than the full name, and it must match + if (lang.length() <= strlen(l.full) && + strncmp(l.full, lang, lang.length()) == 0) + { + driverID = l.driver; + break; + } + } + DebuggerDriver* driver = 0; + switch (driverID) { + case 1: + driver = new GdbDriver; + break; + default: + // unknown language + break; + } + return driver; +} + // helper that gets a file name (it only differs in the caption of the dialog) QString DebuggerMainWndBase::myGetFileName(QString caption, QString dir, QString filter, @@ -687,19 +756,7 @@ bool DebuggerMainWndBase::debugProgramInteractive(const QString& executable, return false; } - if (!debugProgram(executable)) { - QString msg = i18n("Could not start the debugger process.\n" - "Please shut down KDbg and resolve the problem."); -#if QT_VERSION < 200 - KMsgBox::message(parent, kapp->appName(), - msg, - KMsgBox::STOP, - i18n("OK")); -#else - KMessageBox::sorry(parent, msg); -#endif - } - return true; + return debugProgram(executable, parent); } diff --git a/kdbg/mainwndbase.h b/kdbg/mainwndbase.h index d15fbe8..ca08710 100644 --- a/kdbg/mainwndbase.h +++ b/kdbg/mainwndbase.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "exprwnd.h" #include "sys/types.h" /* pid_t */ @@ -19,6 +20,7 @@ class UpdateUI; class KToolBar; class KStatusBar; class KProcess; +class DebuggerDriver; class WatchWindow : public QWidget { @@ -69,9 +71,10 @@ public: void setTranscript(const char* name); // the following are needed to handle program arguments - bool debugProgram(const QString& executable); + bool debugProgram(const QString& executable, QWidget* parent); void setCoreFile(const QString& corefile); void setRemoteDevice(const QString &remoteDevice); + void setLanguage(const QCString& lang); /** helper around KFileDialog */ static QString myGetFileName(QString caption, QString dir, QString filter, @@ -134,6 +137,9 @@ protected: ExprWnd* localVars, ExprWnd* watchVars, QListBox* backtrace); + // which language are we debugging? + QCString m_language; + static DebuggerDriver* driverFromLang(const QCString& lang); public: /* -- 2.11.4.GIT