This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2 07/13] script language API for GDB: cli changes


This patch contains the changes to CLI.
They're pretty simple and straightforward.

Changes will be needed here and/or in extension.c if UNSUPPORTED_ERROR is
removed for this bit of code, but that'll be straightforward.

Changes from v1:
- updates for scripting -> extension renaming

2013-12-10  Doug Evans  <xdje42@gmail.com>

	* cli/cli-cmds.c (source_script_from_stream): Rewrite to use
	extension language API.
	* cli/cli-script.c (execute_control_command): Update to call
	eval_ext_lang_from_control_command.

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 85f1713..f3a343bb 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -522,33 +522,32 @@ find_and_open_script (const char *script_file, int search_path,
 static void
 source_script_from_stream (FILE *stream, const char *file)
 {
-  if (script_ext_mode != script_ext_off
-      && strlen (file) > 3 && !strcmp (&file[strlen (file) - 3], ".py"))
+  if (script_ext_mode != script_ext_off)
     {
-      volatile struct gdb_exception e;
+      const struct extension_language_defn *extlang
+	= get_ext_lang_of_file (file);
 
-      TRY_CATCH (e, RETURN_MASK_ERROR)
+      if (extlang != NULL)
 	{
-	  source_python_script (stream, file);
-	}
-      if (e.reason < 0)
-	{
-	  /* Should we fallback to ye olde GDB script mode?  */
-	  if (script_ext_mode == script_ext_soft
-	      && e.reason == RETURN_ERROR && e.error == UNSUPPORTED_ERROR)
+	  if (ext_lang_present_p (extlang))
 	    {
-	      fseek (stream, 0, SEEK_SET);
-	      script_from_file (stream, (char*) file);
+	      script_sourcer_func *sourcer
+		= ext_lang_script_sourcer (extlang);
+
+	      gdb_assert (sourcer != NULL);
+	      sourcer (extlang, stream, file);
 	    }
-	  else
+	  else if (script_ext_mode == script_ext_soft)
 	    {
-	      /* Nope, just punt.  */
-	      throw_exception (e);
+	      /* Assume the file is a gdb script.
+		 This is handled below.  */
 	    }
+	  else
+	    throw_ext_lang_unsupported (extlang);
 	}
     }
-  else
-    script_from_file (stream, file);
+
+  script_from_file (stream, file);
 }
 
 /* Worker to perform the "source" command.
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 387a11e..acce041 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -590,7 +590,7 @@ execute_control_command (struct command_line *cmd)
 
     case python_control:
       {
-	eval_python_from_control_command (cmd);
+	eval_ext_lang_from_control_command (cmd);
 	ret = simple_control;
 	break;
       }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]