Branch: master

50d3d788 2019-05-30 11:39:48 gregory guy
Drop gdb versionning.
Cherry picked and adapted from commit 0efc808f from the original author
of kdbg, code available at https://github.com/j6t/kdbg under GPL 2.0"

Quote from the author:
In early days of KDbg, it was important to use a suitable command to load
a core file. This was before gdb 4.16. To pick the right command, the
version number was parsed from gdb's greeting.

At least with modern gdb the regular expression does not match anymore.
So let's assume that nobody is using ancient gdb anymore, and always use
the modern command.

Signed-off-by: gregory guy <g-gregory@...>
M kdbg/gdbdriver.cpp
M kdbg/gdbdriver.h
M kdbg/xsldbgdriver.cpp
M kdbg/xsldbgdriver.h

kdbg/gdbdriver.cpp

diff --git a/kdbg/gdbdriver.cpp b/kdbg/gdbdriver.cpp
index 5a5ec05..f76f753 100644
--- a/kdbg/gdbdriver.cpp
+++ b/kdbg/gdbdriver.cpp
@@ -6,8 +6,8 @@
 
 #include "gdbdriver.h"
 #include "exprwnd.h"
-#include <ntqregexp.h>
-#include <ntqstringlist.h>
+#include <tqregexp.h>
+#include <tqstringlist.h>
 #include <tdelocale.h>			/* i18n */
 #include <ctype.h>
 #include <stdlib.h>			/* strtol, atoi */
@@ -71,7 +71,11 @@
     { DCtty, "tty %s\n", GdbCmdInfo::argString },
     { DCexecutable, "file \"%s\"\n", GdbCmdInfo::argString },
     { DCtargetremote, "target remote %s\n", GdbCmdInfo::argString },
-    { DCcorefile, "core-file %s\n", GdbCmdInfo::argString },
+#ifdef __FreeBSD__
+    { DCcorefile, "target FreeBSD-core %s\n", GdbCmdInfo::argString },
+#else
+    { DCcorefile, "target core %s\n", GdbCmdInfo::argString },
+#endif
     { DCattach, "attach %s\n", GdbCmdInfo::argString },
     { DCinfolinemain, "kdbg_infolinemain\n", GdbCmdInfo::argNone },
     { DCinfolocals, "kdbg__alllocals\n", GdbCmdInfo::argNone },
@@ -124,8 +128,7 @@
 #define MAX_FMTLEN 200
 
 GdbDriver::GdbDriver() :
-	DebuggerDriver(),
-	m_gdbMajor(4), m_gdbMinor(16)
+	DebuggerDriver()
 {
     strcpy(m_prompt, PROMPT);
     m_promptMinLen = PROMPT_LEN;
@@ -277,69 +280,6 @@
 	TRACE("calling " + (__PRETTY_FUNCTION__ + (" with uncommited command:\n\t" +
 	      cmd->m_cmdString)));
 	return;
-    }
-
-    switch (cmd->m_cmd) {
-    case DCinitialize:
-	// get version number from preamble
-	{
-	    int len;
-	    TQRegExp GDBVersion("\\nGDB [0-9]+\\.[0-9]+");
-	    int offset = GDBVersion.match(m_output, 0, &len);
-	    if (offset >= 0) {
-		char* start = m_output + offset + 5;	// skip "\nGDB "
-		char* end;
-		m_gdbMajor = strtol(start, &end, 10);
-		m_gdbMinor = strtol(end + 1, 0, 10);	// skip "."
-		if (start == end) {
-		    // nothing was parsed
-		    m_gdbMajor = 4;
-		    m_gdbMinor = 16;
-		}
-	    } else {
-		// assume some default version (what would make sense?)
-		m_gdbMajor = 4;
-		m_gdbMinor = 16;
-	    }
-	    // use a feasible core-file command
-	    if (m_gdbMajor > 4 || (m_gdbMajor == 4 && m_gdbMinor >= 16)) {
-#ifdef __FreeBSD__
-		cmds[DCcorefile].fmt = "target FreeBSD-core %s\n";
-#else
-		cmds[DCcorefile].fmt = "target core %s\n";
-#endif
-	    } else {
-		cmds[DCcorefile].fmt = "core-file %s\n";
-	    }
-	}
-	{
-	    /*
-	     * Check for GDB 7.1 or later; the syntax for the disassemble
-	     * command has changed.
-	     * This RE picks the last version number in the first line,
-	     * because at least OpenSUSE writes its own version number
-	     * in the first line (but before GDB's version number).
-	     */
-	    TQRegExp re(
-		" "			// must be preceded by space
-		"[(]?"			// SLES 10 embeds in parentheses
-		"(\\d+)\\.(\\d+)"	// major, minor
-		"[^ ]*\\n"		// no space until end of line
-		);
-	    int pos = re.search(m_output);
-	    const char* disass = "disassemble %s %s\n";
-	    if (pos >= 0) {
-		int major = re.cap(1).toInt();
-		int minor = re.cap(2).toInt();
-		if (major > 7 || (major == 7 && minor >= 1))
-		{
-		    disass = "disassemble %s, %s\n";
-		}
-	    }
-	    cmds[DCdisassemble].fmt = disass;
-	}
-	break;
-    default:;
     }
 
     /* ok, the command is ready */

kdbg/gdbdriver.h

diff --git a/kdbg/gdbdriver.h b/kdbg/gdbdriver.h
index 2cbbb85..4cdfc4b 100644
--- a/kdbg/gdbdriver.h
+++ b/kdbg/gdbdriver.h
@@ -75,7 +75,6 @@
     virtual TQString parseSetVariable(const char* output);
     virtual TQString editableValue(VarTree* value);
 protected:
-    int m_gdbMajor, m_gdbMinor;
     TQString m_programWD;		/* just an intermediate storage */
     TQString m_redirect;			/* redirection to /dev/null */
     bool m_haveCoreFile;

kdbg/xsldbgdriver.cpp

diff --git a/kdbg/xsldbgdriver.cpp b/kdbg/xsldbgdriver.cpp
index d59023f..63b3227 100644
--- a/kdbg/xsldbgdriver.cpp
+++ b/kdbg/xsldbgdriver.cpp
@@ -6,7 +6,7 @@
 
 #include "xsldbgdriver.h"
 #include "exprwnd.h"
-#include <ntqstringlist.h>
+#include <tqstringlist.h>
 #include <tdelocale.h>            /* i18n */
 #include <ctype.h>
 #include <stdlib.h>             /* strtol, atoi */
@@ -104,7 +104,7 @@
 #define MAX_FMTLEN 200
 
 XsldbgDriver::XsldbgDriver():
-DebuggerDriver(), m_gdbMajor(2), m_gdbMinor(0)
+	DebuggerDriver()
 {
     m_promptRE.setPattern("\\(xsldbg\\) .*> ");
     m_promptMinLen = 11;
@@ -258,39 +258,6 @@
         return;
     }
 
-    switch (cmd->m_cmd) {
-        case DCinitialize:
-            // get version number from preamble
-            {
-                int len;
-                TQRegExp xsldbgVersion("^XSLDBG [0-9]+\\.[0-9]+\\.[0-9]+");
-                int offset = xsldbgVersion.match(m_output, 0, &len);
-
-                if (offset >= 0) {
-                    char *start = m_output + offset + 7;        // skip "^XSLDBG "
-                    char *end;
-
-                    TRACE("Reading version");
-                    TRACE(start);
-                    m_gdbMajor = strtol(start, &end, 10);
-                    m_gdbMinor = strtol(end + 1, 0, 10);        // skip "."
-                    if (start == end) {
-                        // nothing was parsed
-                        m_gdbMajor = 0;
-                        m_gdbMinor = 7;
-                    }
-                } else {
-                    // assume some default version (what would make sense?)
-                    m_gdbMajor = 0;
-                    m_gdbMinor = 7;
-                }
-                TRACE(TQString("Got version ") +
-                      TQString::number(m_gdbMajor) + "." +
-                      TQString::number(m_gdbMinor));
-                break;
-            }
-        default:;
-    }
     /* ok, the command is ready */
     emit commandReceived(cmd, m_output);
 

kdbg/xsldbgdriver.h

diff --git a/kdbg/xsldbgdriver.h b/kdbg/xsldbgdriver.h
index b4e2f43..bc24af4 100644
--- a/kdbg/xsldbgdriver.h
+++ b/kdbg/xsldbgdriver.h
@@ -8,7 +8,7 @@
 #define XSLDBGDRIVER_H
 
 #include "dbgdriver.h"
-#include "ntqregexp.h"
+#include "tqregexp.h"
 
 
 class XsldbgDriver:public DebuggerDriver {
@@ -86,7 +86,6 @@
     virtual TQString parseSetVariable(const char* output);
 
   protected:
-    int m_gdbMajor, m_gdbMinor;
     TQString m_programWD;        /* just an intermediate storage */
     TQString m_xslFile;		/* needed to display it initially */
     bool m_haveDataFile;       /* have we set the XML data file to use? */