$NetBSD: patch-al,v 1.1 2004/06/04 11:19:32 shannonjr Exp $

--- ddd/GDBAgent.C.orig	2003-10-11 05:03:33.000000000 -0600
+++ ddd/GDBAgent.C
@@ -175,6 +175,7 @@ char GDBAgent_rcsid[] =
 
 DEFINE_TYPE_INFO_1(GDBAgent, TTYAgent);
 
+#define DBG_PROMPT "dbg>"
 
 //-----------------------------------------------------------------------------
 // Construction and setup
@@ -189,27 +190,28 @@ GDBAgent::GDBAgent (XtAppContext app_con
       state(BusyOnInitialCmds),
       _type(tp),
       _user_data(0),
-      _has_frame_command(tp == GDB || tp == XDB || tp == BASH),
+      _has_frame_command(tp == BASH  || tp == GDB || tp == XDB),
       _has_func_command(tp == DBX),
+      _has_file_command(tp == DBX),
       _has_run_io_command(false),
       _has_print_r_option(false),
       _has_output_command(false),
       _has_where_h_option(false),
-      _has_display_command(tp == GDB || tp == DBX || tp == PYDB || tp == BASH),
-      _has_clear_command(tp == GDB || tp == DBX || tp == JDB || tp == PERL || tp == BASH),
+      _has_display_command(tp == BASH  || tp == DBX || tp == GDB || tp == PYDB),
+      _has_clear_command(tp == BASH  || tp == DBX || tp == GDB || tp == JDB || tp == PERL),
       _has_handler_command(false),
-      _has_pwd_command(tp == GDB || tp == DBX || tp == PYDB || tp == PERL || tp == BASH),
+      _has_pwd_command(tp == BASH  || tp == DBX || tp == GDB || tp == PYDB || tp == PERL),
       _has_setenv_command(tp == DBX),
       _has_edit_command(tp == DBX),
       _has_make_command(tp == GDB || tp == DBX || tp == PERL),
       _has_jump_command(tp == GDB || tp == DBX || tp == XDB),
       _has_regs_command(tp == GDB),
       _has_watch_command(0),	// see below
-      _has_named_values(tp == GDB || tp == DBX || tp == JDB),
+      _has_named_values(tp == DBX || tp == GDB || tp == JDB),
       _has_when_command(tp == DBX),
       _has_when_semicolon(tp == DBX),
       _wants_delete_comma(false),
-      _has_err_redirection(tp == GDB || tp == DBX || tp == XDB),
+      _has_err_redirection(tp == DBX || tp == GDB ||  tp == XDB),
       _has_givenfile_command(false),
       _has_cont_sig_command(false),
       _has_examine_command(tp == GDB || tp == DBX),
@@ -219,10 +221,10 @@ GDBAgent::GDBAgent (XtAppContext app_con
       _has_addproc_command(false),
       _has_debug_command(true),
       _is_windriver_gdb(false),
-      _program_language((tp == JDB) ? LANGUAGE_JAVA :
-			(tp == PYDB) ? LANGUAGE_PYTHON : 
+      _program_language((tp == BASH) ? LANGUAGE_BASH : 
+			(tp == JDB)  ? LANGUAGE_JAVA :
 			(tp == PERL) ? LANGUAGE_PERL : 
-			(tp == BASH) ? LANGUAGE_BASH : 
+			(tp == PYDB) ? LANGUAGE_PYTHON : 
 			LANGUAGE_C),
       _verbatim(false),
       _recording(false),
@@ -280,6 +282,7 @@ GDBAgent::GDBAgent(const GDBAgent& gdb)
       _user_data(0),
       _has_frame_command(gdb.has_frame_command()),
       _has_func_command(gdb.has_func_command()),
+      _has_file_command(gdb.has_file_command()),
       _has_run_io_command(gdb.has_run_io_command()),
       _has_print_r_option(gdb.has_print_r_option()),
       _has_output_command(gdb.has_output_command()),
@@ -336,15 +339,15 @@ GDBAgent::GDBAgent(const GDBAgent& gdb)
 const string& GDBAgent::title() const
 {
 #define TITLES \
-X(tGDB,"GDB"),  \
-X(tWBD,"WDB"),  \
-X(tXDB,"XDB"),  \
-X(tLADEBUG,"Ladebug"),  \
+X(tBASH,"Bash"),  \
 X(tDBX,"DBX"),  \
+X(tGDB,"GDB"),  \
 X(tJDB,"JDB"),  \
-X(tPYDB,"PYDB"),  \
+X(tLADEBUG,"Ladebug"),  \
 X(tPERL,"Perl"),  \
-X(tBASH,"Bash"),  \
+X(tPYDB,"PYDB"),  \
+X(tWBD,"WDB"),  \
+X(tXDB,"XDB"),  \
 X(tDEBUGGER,"debugger")
     enum{
 #define X(a,b) a
@@ -363,11 +366,8 @@ X(tDEBUGGER,"debugger")
 
     switch (type())
     {
-    case GDB:
-	if (path().contains("wdb"))
-	    return titles[tWBD];
-	else
-	    return titles[tGDB];
+    case BASH:
+        return titles[tBASH];
 
     case DBX:
 	if (is_ladebug())
@@ -375,20 +375,23 @@ X(tDEBUGGER,"debugger")
 	else
 	    return titles[tDBX];
 
-    case XDB:
-	return titles[tXDB];
+    case GDB:
+	if (path().contains("wdb"))
+	    return titles[tWBD];
+	else
+	    return titles[tGDB];
 
     case JDB:
 	return titles[tJDB];
 
-    case PYDB:
-	return titles[tPYDB];
-
     case PERL:
 	return titles[tPERL];
 
-    case BASH:
-	return titles[tBASH];
+    case PYDB:
+	return titles[tPYDB];
+
+    case XDB:
+	return titles[tXDB];
     }
 
     return titles[tDEBUGGER];
@@ -620,8 +623,8 @@ void GDBAgent::init_qu_array (const Stri
     _qu_count = qu_count;
     _qa_data  = qa_data;
 
-    StringArray empty_s;
-    VoidArray   empty_v;
+    static const StringArray empty_s;
+    static const VoidArray   empty_v;
 
     complete_answers = empty_s;
     cmd_array        = empty_s;
@@ -830,13 +833,13 @@ bool GDBAgent::ends_with_prompt (const s
     return false;		// Never reached
 }
 
-static bool ends_in(const string& answer, const string& prompt)
+static bool ends_in(const string& answer, const char *prompt)
 {
-    return answer.contains(prompt, answer.length() - prompt.length());
+    return answer.contains(prompt, answer.length() - strlen(prompt));
 }
 
 // JDB should be applied on itself.
-bool GDBAgent::is_exception_answer(const string& answer)
+bool GDBAgent::is_exception_answer(const string& answer) const
 {
     // Any JDB backtrace contains these lines.
     return type() == JDB && 
@@ -862,7 +865,7 @@ void GDBAgent::set_exception_state(bool 
 
 
 // Return true iff ANSWER ends with secondary prompt.
-bool GDBAgent::ends_with_secondary_prompt (const string& ans)
+bool GDBAgent::ends_with_secondary_prompt (const string& ans) const
 {
     string answer = ans;
     strip_control(answer);
@@ -902,11 +905,11 @@ bool GDBAgent::ends_with_secondary_promp
 	// Prompt is `> ' at beginning of line
 	return answer == "> " || ends_in(answer, "\n> ");
 	
-    case XDB:
+    case BASH:
     case JDB:
-    case PYDB:
     case PERL:
-    case BASH:
+    case PYDB:
+    case XDB:
 	// Is there any secondary prompt in these debuggers? (FIXME)
 	return false;
     }
@@ -915,7 +918,7 @@ bool GDBAgent::ends_with_secondary_promp
 }
 
 // Return true iff ANSWER ends with (yes or no)
-bool GDBAgent::ends_with_yn (const string& answer)
+bool GDBAgent::ends_with_yn (const string& answer) const
 {
     if (ends_in(answer, "(y or n) "))
 	return true;		// GDB
@@ -1026,9 +1029,17 @@ void GDBAgent::cut_off_prompt(string& an
 	answer = answer.before('(', -1);
 	break;
 
-    case XDB:
-	answer = answer.before('>', -1);
+    case BASH:
+    case JDB:
+    {
+	// Check for prompt at the end of the last line
+	if (answer.contains(last_prompt, -1))
+	{
+	    answer = answer.before(int(answer.length()) - 
+				   int(last_prompt.length()));
+	}
 	break;
+    }
 
     case PERL:
     {
@@ -1039,18 +1050,10 @@ void GDBAgent::cut_off_prompt(string& an
 	break;
     }
 
-    case BASH:
-    case JDB:
-    {
-	// Check for prompt at the end of the last line
-	if (answer.contains(last_prompt, -1))
-	{
-	    answer = answer.before(int(answer.length()) - 
-				   int(last_prompt.length()));
-	}
+    case XDB:
+	answer = answer.before('>', -1);
 	break;
     }
-    }
 }
 
 // Strip annoying DBX comments
@@ -1702,7 +1705,7 @@ void GDBAgent::handle_died()
 //-----------------------------------------------------------------------------
 
 // DBX 3.0 wants `print -r' instead of `print' for C++
-string GDBAgent::print_command(const string& expr, bool internal) const
+string GDBAgent::print_command(const char *expr, bool internal) const
 {
     string cmd;
 
@@ -1737,26 +1740,30 @@ string GDBAgent::print_command(const str
 	break;
     }
 
-    if (!expr.empty())
-	cmd += " " + expr;
+    if (strlen(expr) != 0) {
+	cmd += ' ';
+	cmd += expr;
+    }
 
     return cmd;
 }
 
 // DBX 3.0 wants `display -r' instead of `display' for C++
-string GDBAgent::display_command(const string& expr) const
+string GDBAgent::display_command(const char *expr) const
 {
     string cmd;
     if (!has_display_command())
 	return cmd;
 
-    if (has_print_r_option() && !expr.empty())
+    if (has_print_r_option() && strlen(expr) != 0)
 	cmd = "display -r";
     else
 	cmd = "display";
 
-    if (!expr.empty())
-	cmd += " " + expr;
+    if (strlen(expr) != 0) {
+        cmd += ' ';
+        cmd += expr;
+    }
 
     return cmd;
 }
@@ -1767,8 +1774,9 @@ string GDBAgent::where_command(int count
     string cmd;
     switch (type())
     {
-    case GDB:
+    case BASH:
     case DBX:
+    case GDB:
     case JDB:
     case PYDB:
 	if (has_where_h_option())
@@ -1777,7 +1785,6 @@ string GDBAgent::where_command(int count
 	    cmd = "where";
 	break;
 
-    case BASH:
     case PERL:
 	cmd = "T";
 	break;
@@ -1813,6 +1820,8 @@ string GDBAgent::info_locals_command() c
     case BASH:
     case PERL:
 	return "V";
+
+
     }
 
     return "";			// Never reached
@@ -1934,10 +1943,10 @@ string GDBAgent::jump_command(const stri
     case DBX:
 	return "cont at " + pos;
 
+    case BASH:
     case JDB:
-    case PYDB:
     case PERL:
-    case BASH:
+    case PYDB:
 	return "";		// Not available
     }
 
@@ -1964,11 +1973,11 @@ string GDBAgent::regs_command(bool all) 
 	else
 	    return "regs";	
 
-    case XDB:
+    case BASH:
     case JDB:
     case PYDB:
     case PERL:
-    case BASH:
+    case XDB:
 	return "";		// Not available
     }
 
@@ -2027,8 +2036,8 @@ string GDBAgent::watch_command(const str
 	    return "watch access " + expr;
 	return "";
 
-    case PYDB:
     case PERL:
+    case PYDB:
 	return "";		// Not available
     }
 
@@ -2040,16 +2049,14 @@ string GDBAgent::kill_command() const
 {
     switch (type())
     {
-    case GDB:
     case DBX:
+    case GDB:
+    case PYDB:
 	return "kill";
    
     case XDB:
 	return "k";
 
-    case PYDB:
-	return "kill";
-
     case JDB:
     case PERL:
     case BASH:
@@ -2063,9 +2070,9 @@ string GDBAgent::frame_command() const
 {
     switch (type())
     {
-    case GDB:
-    case DBX:
     case BASH:
+    case DBX:
+    case GDB:
 	if (has_frame_command())
 	    return "frame";
 	else
@@ -2092,9 +2099,9 @@ string GDBAgent::frame_command(int num) 
 
     switch (type())
     {
-    case GDB:
-    case DBX:
     case BASH:
+    case DBX:
+    case GDB:
 	return frame_command() + " " + itostring(num);
 
     case XDB:
@@ -2131,12 +2138,12 @@ string GDBAgent::func_command() const
 {
     switch (type())
     {
+    case BASH:
     case GDB:
-    case XDB:
     case JDB:
-    case PYDB:
     case PERL:
-    case BASH:
+    case PYDB:
+    case XDB:
 	return frame_command();
 
     case DBX:
@@ -2215,9 +2222,9 @@ string GDBAgent::enable_command(string b
 
     switch (type())
     {
+    case BASH:
     case GDB:
     case PYDB:
-    case BASH:
 	return "enable" + bp;
 
     case DBX:
@@ -2247,9 +2254,9 @@ string GDBAgent::disable_command(string 
 
     switch (type())
     {
+    case BASH:
     case GDB:
     case PYDB:
-    case BASH:
 	return "disable" + bp;
 
     case DBX:
@@ -2279,10 +2286,10 @@ string GDBAgent::delete_command(string b
 
     switch (type())
     {
+    case BASH:
     case DBX:
     case GDB:
     case PYDB:
-    case BASH:
 	return "delete" + bp;
 
     case XDB:
@@ -2314,9 +2321,9 @@ string GDBAgent::ignore_command(const st
     case XDB:
 	return "bc " + bp + " " + itostring(count);
 
+    case BASH:
     case JDB:
     case PERL:
-    case BASH:
 	return "";		// Not available
     }
 
@@ -2324,7 +2331,7 @@ string GDBAgent::ignore_command(const st
 }
 
 // Set condition of breakpoint BP to EXPR
-string GDBAgent::condition_command(const string& bp, const string& expr) const
+string GDBAgent::condition_command(const string& bp, const char *expr) const
 {
     switch (type())
     {
@@ -2465,7 +2472,7 @@ string GDBAgent::quote_file(const string
 }
 
 // Return command to debug PROGRAM
-string GDBAgent::debug_command(const string& program, string args) const
+string GDBAgent::debug_command(const char *program, string args) const
 {
     if (!args.empty() && !args.contains(' ', 0))
 	args.prepend(' ');
@@ -2479,27 +2486,27 @@ string GDBAgent::debug_command(const str
 	    return "file " + quote_file(program);
 
     case PYDB:
-	return "file " + program;
+	return string("file ") + program;
 
     case DBX:
 	if (is_ladebug())
-	    return "load " + program;       // Compaq Ladebug
+	    return string("load ") + program;       // Compaq Ladebug
 	else if (has_givenfile_command())
-	    return "givenfile " + program; // SGI DBX
+	    return string("givenfile ") + program; // SGI DBX
 	else
-	    return "debug " + program;     // SUN DBX
+	    return string("debug ") + program;     // SUN DBX
 
     case XDB:
-	return "#file " + program; // just a dummy
+	return string("#file ") + program; // just a dummy
 
     case JDB:
-	return "load " + program;
+	return string("load ") + program;
 
     case PERL:
 	return "exec " + quote(debugger() + " -d " + program + args);
 
     case BASH:
-	return "debug " + program + args;
+	return string("debug ") + program + args;
     }
 
     return "";			// Never reached
@@ -2536,12 +2543,12 @@ string GDBAgent::signal_command(int sig)
 
 
 // Return a command that does nothing.
-string GDBAgent::nop_command(const string& comment) const
+string GDBAgent::nop_command(const char *comment) const
 {
     if (type() == JDB)
 	return " ";
 
-    return "# " + comment;	// Works for all other inferior debuggers
+    return string("# ") + comment;	// Works for all other inferior debuggers
 }
 
 // Run program with given ARGS
@@ -2591,10 +2598,10 @@ string GDBAgent::rerun_command() const
 {
     switch (type())
     {
+    case BASH:
     case GDB:
     case JDB:
     case PYDB:
-    case BASH:
 	return "run";
 
     case DBX:
@@ -2634,11 +2641,11 @@ string GDBAgent::attach_command(int pid,
 	else
 	    return "debug " + file + " " + itostring(pid); // Others
 
-    case XDB:
+    case BASH:
     case JDB:
-    case PYDB:
     case PERL:
-    case BASH:
+    case PYDB:
+    case XDB:
 	break;
     }
 
@@ -2658,11 +2665,11 @@ string GDBAgent::detach_command(int pid)
 	else
 	    return "detach";	// Others
 
-    case XDB:
+    case BASH:
     case JDB:
-    case PYDB:
     case PERL:
-    case BASH:
+    case PYDB:
+    case XDB:
 	break;
     }
 
@@ -2673,23 +2680,33 @@ string GDBAgent::detach_command(int pid)
 // Return PREFIX + EXPR, parenthesizing EXPR if needed
 string GDBAgent::prepend_prefix(const string& prefix, const string& expr)
 {
+  return prepend_prefix( prefix.chars(), expr);
+}
+
+string GDBAgent::prepend_prefix(const char *prefix, const string& expr)
+{
     if (expr.matches(rxidentifier)
 	|| expr.contains("(", 0) && expr.contains(")", -1))
 	return prefix + expr;
     else if (expr.empty())
 	return prefix;
     else
-	return prefix + "(" + expr + ")";
+	return string(prefix) + "(" + expr + ")";
 }
 
 // Return EXPR + SUFFIX, parenthesizing EXPR if needed
-string GDBAgent::append_suffix(const string& expr, const string& suffix)
+string GDBAgent::append_suffix(const string& expr, const string &suffix)
+{
+  return append_suffix( expr, suffix.chars() );
+}
+
+string GDBAgent::append_suffix(const string& expr, const char *suffix)
 {
     if (expr.matches(rxidentifier)
 	|| expr.contains("(", 0) && expr.contains(")", -1))
 	return expr + suffix;
     else if (expr.empty())
-	return suffix;
+	return string(suffix);
     else
 	return "(" + expr + ")" + suffix;
 }
@@ -2702,6 +2719,7 @@ string GDBAgent::dereferenced_expr(const
     case LANGUAGE_C:
 	return prepend_prefix("*", expr);
 
+    case LANGUAGE_PHP:
     case LANGUAGE_PERL:
 	// Perl has three `dereferencing' operators, depending on the
 	// type of reference.  The `deref()' function provides a
@@ -2770,6 +2788,7 @@ string GDBAgent::address_expr(string exp
 	return "";		// Not supported in Python
 
     case LANGUAGE_BASH:
+    case LANGUAGE_PHP:          // Is this right? 
     case LANGUAGE_PERL:
 	return "";		// No such thing in bash/Perl
 
@@ -2822,8 +2841,9 @@ int GDBAgent::default_index_base() const
     case LANGUAGE_ADA:
     case LANGUAGE_C:
     case LANGUAGE_JAVA:
-    case LANGUAGE_PYTHON:
     case LANGUAGE_PERL:
+    case LANGUAGE_PHP:
+    case LANGUAGE_PYTHON:
     case LANGUAGE_BASH:
     case LANGUAGE_OTHER:
 	return 0;
@@ -2843,6 +2863,7 @@ string GDBAgent::member_separator() cons
     case LANGUAGE_C:
     case LANGUAGE_PYTHON:
     case LANGUAGE_OTHER:
+    case LANGUAGE_PHP:
 	return " = ";
 
     case LANGUAGE_JAVA:
@@ -2908,12 +2929,13 @@ string GDBAgent::assign_command(const st
 
     switch (program_language())
     {
+    case LANGUAGE_BASH:
     case LANGUAGE_C:
-    case LANGUAGE_JAVA:
     case LANGUAGE_FORTRAN:
-    case LANGUAGE_PYTHON:	// FIXME: vrbl names can conflict with commands
+    case LANGUAGE_JAVA:
     case LANGUAGE_PERL:
-    case LANGUAGE_BASH:
+    case LANGUAGE_PHP:
+    case LANGUAGE_PYTHON:	// FIXME: vrbl names can conflict with commands
     case LANGUAGE_OTHER:
 	cmd += "=";
 	break;
@@ -2948,13 +2970,14 @@ void GDBAgent::normalize_address(string&
     {
 	switch (program_language())
 	{
+	case LANGUAGE_ADA:
+	case LANGUAGE_BASH:
 	case LANGUAGE_C:
-	case LANGUAGE_JAVA:
 	case LANGUAGE_FORTRAN:
-	case LANGUAGE_ADA:
-	case LANGUAGE_PYTHON:
+	case LANGUAGE_JAVA:
 	case LANGUAGE_PERL:
-	case LANGUAGE_BASH:
+	case LANGUAGE_PHP:
+	case LANGUAGE_PYTHON:
 	case LANGUAGE_OTHER:
 	    addr.prepend("0x");
 	    break;
@@ -2971,7 +2994,7 @@ void GDBAgent::normalize_address(string&
 }
 
 // Return disassemble command
-string GDBAgent::disassemble_command(string start, const string& end) const
+string GDBAgent::disassemble_command(string start, const char *end) const
 {
     string cmd;
     if (type() != GDB)
@@ -2980,11 +3003,12 @@ string GDBAgent::disassemble_command(str
     normalize_address(start);
     cmd = "disassemble " + start;
 
-    if (!end.empty())
+    if (strlen(end) != 0)
     {
         string end_( end );
 	normalize_address(end_);
-	cmd += " " + end_;
+	cmd += ' ';
+	cmd += end_;
     }
     return cmd;
 }
@@ -3003,11 +3027,11 @@ string GDBAgent::history_file() const
 	    return "./.gdb_history";
     }
 
+    case BASH:
     case DBX:
     case JDB:
-    case PYDB:
     case PERL:
-    case BASH:
+    case PYDB:
 	return "";		// Unknown
 
     case XDB:
@@ -3072,6 +3096,7 @@ ProgramLanguage GDBAgent::program_langua
 	{ "python",  LANGUAGE_PYTHON },
 	{ "bash",    LANGUAGE_BASH },
 	{ "perl",    LANGUAGE_PERL },
+	{ "php",     LANGUAGE_PHP },
 	{ "c",       LANGUAGE_C },
 	{ "c++",     LANGUAGE_C },
 	{ "auto",    LANGUAGE_OTHER }  // Keep current language
