From 2ca6d0de96c9709f814228c0c8e620fdd706cb26 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 8 Mar 2002 20:48:39 +0000 Subject: [PATCH] The driver name is now stored in the per-program config file. This way the recent file entries now select the language that was originally specified for the program. --- kdbg/dbgmainwnd.cpp | 10 ++++----- kdbg/dbgmainwnd.h | 3 ++- kdbg/debugger.cpp | 17 ++++++++++++--- kdbg/debugger.h | 11 ++++++++++ kdbg/main.cpp | 10 ++++----- kdbg/mainwndbase.cpp | 61 +++++++++++++++++++++++++++++++++++++++++----------- kdbg/mainwndbase.h | 16 +++++++++----- 7 files changed, 96 insertions(+), 32 deletions(-) diff --git a/kdbg/dbgmainwnd.cpp b/kdbg/dbgmainwnd.cpp index 9bb2014..eb24d2f 100644 --- a/kdbg/dbgmainwnd.cpp +++ b/kdbg/dbgmainwnd.cpp @@ -420,7 +420,7 @@ void DebuggerMainWnd::readProperties(KConfig* config) TRACE("readProperties: executable=" + execName); if (!execName.isEmpty()) { - debugProgram(execName); + debugProgram(execName, ""); } } @@ -679,7 +679,7 @@ TTYWindow* DebuggerMainWnd::ttyWindow() return m_ttyWindow; } -bool DebuggerMainWnd::debugProgram(const QString& exe) +bool DebuggerMainWnd::debugProgram(const QString& exe, QCString lang) { // check the file name QFileInfo fi(exe); @@ -692,7 +692,7 @@ bool DebuggerMainWnd::debugProgram(const QString& exe) } else { - success = DebuggerMainWndBase::debugProgram(fi.absFilePath(), this); + success = DebuggerMainWndBase::debugProgram(fi.absFilePath(), lang, this); } if (success) @@ -796,7 +796,7 @@ void DebuggerMainWnd::slotRecentExec(int item) { if (item >= 0 && item < int(m_recentExecList.count())) { QString exe = m_recentExecList.at(item); - debugProgram(exe); + debugProgram(exe, ""); } } @@ -900,7 +900,7 @@ void DebuggerMainWnd::slotFileExe() if (executable.isEmpty()) return; - debugProgram(executable); + debugProgram(executable, ""); } } diff --git a/kdbg/dbgmainwnd.h b/kdbg/dbgmainwnd.h index 07c75af..99f925a 100644 --- a/kdbg/dbgmainwnd.h +++ b/kdbg/dbgmainwnd.h @@ -14,6 +14,7 @@ class WinStack; class QPopupMenu; class QListBox; +class QCString; class ExprWnd; class DockWidget; class BreakpointTable; @@ -28,7 +29,7 @@ public: DebuggerMainWnd(const char* name); ~DebuggerMainWnd(); - bool debugProgram(const QString& exe); + bool debugProgram(const QString& exe, QCString lang); protected: // session properties diff --git a/kdbg/debugger.cpp b/kdbg/debugger.cpp index 0892500..10bae35 100644 --- a/kdbg/debugger.cpp +++ b/kdbg/debugger.cpp @@ -94,6 +94,7 @@ void KDebugger::restoreSettings(KConfig* /*config*/) const char GeneralGroup[] = "General"; const char DebuggerCmdStr[] = "DebuggerCmdStr"; const char TTYLevelEntry[] = "TTYLevel"; +const char KDebugger::DriverNameEntry[] = "DriverName"; bool KDebugger::debugProgram(const QString& name, DebuggerDriver* driver) @@ -530,10 +531,8 @@ void KDebugger::gdbExited(KProcess*) emit updatePC(QString(), -1, DbgAddr(), 0); } -void KDebugger::openProgramConfig(const QString& name) +QString KDebugger::getConfigForExe(const QString& name) { - ASSERT(m_programConfig == 0); - QFileInfo fi(name); QString pgmConfigFile = fi.dirPath(true); if (!pgmConfigFile.isEmpty()) { @@ -541,6 +540,14 @@ void KDebugger::openProgramConfig(const QString& name) } pgmConfigFile += ".kdbgrc." + fi.fileName(); TRACE("program config file = " + pgmConfigFile); + return pgmConfigFile; +} + +void KDebugger::openProgramConfig(const QString& name) +{ + ASSERT(m_programConfig == 0); + + QString pgmConfigFile = getConfigForExe(name); // check whether we can write to the file QFile file(pgmConfigFile); bool readonly = true; @@ -575,6 +582,10 @@ void KDebugger::saveProgramSettings() m_programConfig->writeEntry(WorkingDirectory, m_programWD); m_programConfig->writeEntry(DebuggerCmdStr, m_debuggerCmd); m_programConfig->writeEntry(TTYLevelEntry, int(m_ttyLevel)); + QString driverName; + if (m_d != 0) + driverName = m_d->driverName(); + m_programConfig->writeEntry(DriverNameEntry, driverName); // write environment variables m_programConfig->deleteGroup(EnvironmentGroup); diff --git a/kdbg/debugger.h b/kdbg/debugger.h index 955d015..656278a 100644 --- a/kdbg/debugger.h +++ b/kdbg/debugger.h @@ -66,6 +66,17 @@ public: */ void attachProgram(const QString& pid); + /** + * Returns the file name of the per-program config file for the + * specified program. + */ + static QString getConfigForExe(const QString& exe); + + /** + * The driver name entry in the per-program config file. + */ + static const char DriverNameEntry[]; + public slots: /** * Runs the program or continues it if it is stopped at a breakpoint. diff --git a/kdbg/main.cpp b/kdbg/main.cpp index 4653fb8..2e435cc 100644 --- a/kdbg/main.cpp +++ b/kdbg/main.cpp @@ -100,14 +100,14 @@ int main(int argc, char** argv) if (!remote.isEmpty()) debugger.setRemoteDevice(remote); - // deprecated option; -l overrides it + QCString lang = args->getOption("l"); + + // deprecated option; overrides -l if (args->isSet("x")){ /* run in xsldbg mode */ - debugger.setLanguage("xsl"); + lang = "xslt"; } - debugger.setLanguage(args->getOption("l")); - // check environment variable for transcript file name if (transcript == 0) { transcript = getenv("KDBG_TRANSCRIPT"); @@ -119,7 +119,7 @@ int main(int argc, char** argv) if (args->count() > 1) { debugger.setCoreFile(args->arg(1)); } - if (!debugger.debugProgram(args->arg(0))) { + if (!debugger.debugProgram(args->arg(0), lang)) { // failed TRACE("cannot start debugger"); KMessageBox::error(&debugger, i18n("Cannot start debugger.")); diff --git a/kdbg/mainwndbase.cpp b/kdbg/mainwndbase.cpp index e331f60..b7d5bfe 100644 --- a/kdbg/mainwndbase.cpp +++ b/kdbg/mainwndbase.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include "mainwndbase.h" #include "debugger.h" #include "gdbdriver.h" @@ -184,11 +184,6 @@ 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"; @@ -202,6 +197,7 @@ const char FilesGroup[] = "Files"; const char RecentExecutables[] = "RecentExecutables"; const char SourceFileFilter[] = "SourceFileFilter"; const char HeaderFileFilter[] = "HeaderFileFilter"; +const char GeneralGroup[] = "General"; void DebuggerMainWndBase::saveSettings(KConfig* config) { @@ -255,16 +251,48 @@ void DebuggerMainWndBase::restoreSettings(KConfig* config) config->readListEntry(RecentExecutables, m_recentExecList,','); } -bool DebuggerMainWndBase::debugProgram(const QString& executable, QWidget* parent) +bool DebuggerMainWndBase::debugProgram(const QString& executable, + QCString lang, QWidget* parent) { assert(m_debugger != 0); - DebuggerDriver* driver = driverFromLang(m_language); + TRACE(QString().sprintf("trying language '%s'...", lang.data())); + DebuggerDriver* driver = driverFromLang(lang); + + if (driver == 0) + { + // see if there is a language in the per-program config file + QString configName = m_debugger->getConfigForExe(executable); + if (QFile::exists(configName)) + { + KSimpleConfig c(configName, true); // read-only + c.setGroup(GeneralGroup); + + // Using "GDB" as default here is for backwards compatibility: + // The config file exists but doesn't have an entry, + // so it must have been created by an old version of KDbg + // that had only the GDB driver. + lang = c.readEntry(KDebugger::DriverNameEntry, "GDB").latin1(); + + TRACE(QString().sprintf("...bad, trying config driver %s...", + lang.data())); + driver = driverFromLang(lang); + } + + } + if (driver == 0) + { + QCString name = driverNameFromFile(executable); + + TRACE(QString().sprintf("...no luck, trying %s derived" + " from file contents", name.data())); + driver = driverFromLang(name); + } if (driver == 0) { // oops QString msg = i18n("Don't know how to debug language `%1'"); - KMessageBox::sorry(parent, msg.arg(m_language)); + KMessageBox::sorry(parent, msg.arg(lang)); return false; } @@ -285,10 +313,10 @@ bool DebuggerMainWndBase::debugProgram(const QString& executable, QWidget* paren } // derive driver from language -DebuggerDriver* DebuggerMainWndBase::driverFromLang(const QCString& lang) +DebuggerDriver* DebuggerMainWndBase::driverFromLang(QCString lang) { - // lang must be in all lowercase - assert(lang == lang.lower()); + // lang is needed in all lowercase + lang = lang.lower(); // The following table relates languages and debugger drivers static const struct L { @@ -300,11 +328,13 @@ DebuggerDriver* DebuggerMainWndBase::driverFromLang(const QCString& lang) { "f", "fortran", 1 }, { "p", "python", 3 }, { "x", "xslt", 2 }, + // the following are actually driver names + { "gdb", "gdb", 1 }, + { "xsldbg", "xsldbg", 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++) { @@ -341,6 +371,11 @@ DebuggerDriver* DebuggerMainWndBase::driverFromLang(const QCString& lang) return driver; } +QCString DebuggerMainWndBase::driverNameFromFile(const QString& exe) +{ + return "GDB"; +} + // helper that gets a file name (it only differs in the caption of the dialog) QString DebuggerMainWndBase::myGetFileName(QString caption, QString dir, QString filter, diff --git a/kdbg/mainwndbase.h b/kdbg/mainwndbase.h index 8ec51a7..09c01d0 100644 --- a/kdbg/mainwndbase.h +++ b/kdbg/mainwndbase.h @@ -69,12 +69,15 @@ public: * Specifies the file where to write the transcript. */ void setTranscript(const char* name); + /** + * Starts to debug the specified program using the specified language + * driver. + */ + bool debugProgram(const QString& executable, QCString lang, QWidget* parent); // the following are needed to handle program arguments - 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, @@ -135,9 +138,12 @@ protected: ExprWnd* localVars, ExprWnd* watchVars, QListBox* backtrace); - // which language are we debugging? - QCString m_language; - DebuggerDriver* driverFromLang(const QCString& lang); + DebuggerDriver* driverFromLang(QCString lang); + /** + * This function derives a driver name from the contents of the named + * file. + */ + QCString driverNameFromFile(const QString& exe); public: /* -- 2.11.4.GIT