Machine Code Window does not work with newer GDBs

RenĂ© Schipp von Branitz Nielsen <[email protected]> Thu, 15 May 2014 09:45:34 +0200
Newsgroups gmane.comp.debugging.ddd.bugs
Message-ID <000401cf7011$a8cdac80$fa690580$@cc>
Hello,

Back in 2010, Paolo Canceda reported a Machine Code Window DDD bug
(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D597328). The GDB
=91disassemble=92 command had changed to use a comma instead of a space =
as
separator for its two arguments, causing the message =93A syntax error =
in
expression, near =91<hex_address>=92=94 to appear in the Machine Code =
Window.

Paolo also supplied a patch. His fix, however, only made new GDBs work =
with
DDD.

Below is a more complete patch that auto-detects whether GDB expects the
comma in the =91disassemble=92 command and inserts it whenever needed.

BR,
Ren=E9 Schipp von Branitz Nielsen

diff -ur ddd-3.3.12.old/ddd/GDBAgent.C ddd-3.3.12.new/ddd/GDBAgent.C
--- ddd-3.3.12.old/ddd/GDBAgent.C	2009-02-11 18:25:06.000000000 +0100
+++ ddd-3.3.12.new/ddd/GDBAgent.C	2014-05-14 17:23:14.000000000 +0200
@@ -223,6 +223,7 @@
       _has_addproc_command(false),
       _has_debug_command(true),
       _is_windriver_gdb(false),
+      _wants_disassemble_comma(false),
       _program_language((tp =3D=3D BASH) ? LANGUAGE_BASH :=20
 			(tp =3D=3D DBG)  ? LANGUAGE_PHP  :
 			(tp =3D=3D JDB)  ? LANGUAGE_JAVA :
@@ -317,6 +318,7 @@
       _has_addproc_command(gdb.has_addproc_command()),
       _has_debug_command(gdb.has_debug_command()),
       _is_windriver_gdb(gdb.is_windriver_gdb()),
+      _wants_disassemble_comma(gdb.wants_disassemble_comma()),
       _program_language(gdb.program_language()),
       _verbatim(gdb.verbatim()),
       _recording(gdb.recording()),
@@ -3200,8 +3202,12 @@
     {
         string end_( end );
 	normalize_address(end_);
-	cmd +=3D ' ';
-	cmd +=3D end_;
+        if (start !=3D "" && start.lastchar() !=3D ',') {
+            // No comma if only an end address or if #start
+            // already ends with a comma.
+            cmd +=3D wants_disassemble_comma() ? ',' : ' ';
+        }
+        cmd +=3D end_;
     }
     return cmd;
 }
diff -ur ddd-3.3.12.old/ddd/GDBAgent.h ddd-3.3.12.new/ddd/GDBAgent.h
--- ddd-3.3.12.old/ddd/GDBAgent.h	2009-02-11 18:25:06.000000000 +0100
+++ ddd-3.3.12.new/ddd/GDBAgent.h	2014-05-14 14:44:09.000000000 +0200
@@ -191,6 +191,7 @@
     bool _has_addproc_command;
     bool _has_debug_command;
     bool _is_windriver_gdb;
+    bool _wants_disassemble_comma;
=20
     ProgramLanguage _program_language; // Current program language
=20
@@ -427,6 +428,10 @@
     bool has_debug_command() const   { return _has_debug_command; }
     bool has_debug_command(bool val) { return _has_debug_command =3D =
val; }
=20
+    // True if debugger wants 'disassemble' arguments separated by `,'
+    bool wants_disassemble_comma() const  { return
_wants_disassemble_comma; }
+    bool wants_disassemble_comma(bool val){ return=20
+ _wants_disassemble_comma =3D val; }
+
     // True if debugger is the Windriver variant of GDB
     bool is_windriver_gdb() const   { return _is_windriver_gdb; }
     bool is_windriver_gdb(bool val) { return _is_windriver_gdb =3D val; =
}
diff -ur ddd-3.3.12.old/ddd/comm-manag.C ddd-3.3.12.new/ddd/comm-manag.C
--- ddd-3.3.12.old/ddd/comm-manag.C	2009-02-11 18:25:07.000000000 +0100
+++ ddd-3.3.12.new/ddd/comm-manag.C	2014-05-14 17:24:10.000000000 +0200
@@ -273,7 +273,7 @@
     bool     config_regs;	       // try 'help regs'
     bool     config_named_values;      // try 'print "ddd"'
     bool     config_when_semicolon;    // try 'help when'
-    bool     config_delete_comma;      // try 'delete 4711 4712'
+    bool     config_delete_comma;      // try 'delete 4711 4711'
     bool     config_err_redirection;   // try 'help run'
     bool     config_givenfile;         // try 'help givenfile'
     bool     config_cont_sig;          // try 'help cont'
@@ -283,6 +283,7 @@
     bool     config_output;            // try 'output'
     bool     config_program_language;  // try 'show language'
     bool     config_gdb_version;       // try 'show version'
+    bool     config_disassemble_comma; // try 'disassemble 4711 4711'
(Newer GDBs (2009+) use ',' as separator. Old GDBs use ' ')
=20
     OACProc  user_callback;	       // callback
     void     *user_data;	       // user data
@@ -344,6 +345,7 @@
 	  config_output(false),
 	  config_program_language(false),
 	  config_gdb_version(false),
+ 	  config_disassemble_comma(false),
=20
 	  user_callback(0),
 	  user_data(0)
@@ -458,6 +460,7 @@
     // Fetch initialization commands
     string init;
     string settings;
+
     switch (gdb->type())
     {
     case BASH:
@@ -542,6 +545,11 @@
 	extra_data->config_program_language =3D true;
 	cmds +=3D "show version";
 	extra_data->config_gdb_version =3D true;
+        if (config)
+        {
+	    cmds +=3D "disassemble " + print_cookie + " " + print_cookie;
+	    extra_data->config_disassemble_comma =3D true;
+        }
 	cmds +=3D "pwd";
 	extra_data->refresh_pwd =3D true;
 	cmds +=3D "info breakpoints";
@@ -694,7 +702,6 @@
 		     extra_completed,
 		     (void *)extra_data,
 		     extra_registered);
-
     if (!extra_registered)
       delete extra_data;
=20
@@ -1627,6 +1634,7 @@
     assert(!extra_data->config_output);
     assert(!extra_data->config_program_language);
     assert(!extra_data->config_gdb_version);
+    assert(!extra_data->config_disassemble_comma);
=20
     // Annotate state
     if (extra_data->refresh_breakpoints) @@ -2885,6 +2893,10 @@
     }
 }
=20
+static void process_config_disassemble_comma(const string& answer) {
+    gdb->wants_disassemble_comma(!is_known_command(answer));
+}
=20
=20
=20
//-----------------------------------------------------------------------=
---
---
@@ -3117,6 +3129,9 @@
     if (extra_data->config_gdb_version)
 	process_config_gdb_version(answers[qu_count++]);
=20
+    if (extra_data->config_disassemble_comma)
+	process_config_disassemble_comma(answers[qu_count++]);
+
     if (extra_data->refresh_pwd)
 	source_view->process_pwd(answers[qu_count++]);