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 07/13] script language API for GDB


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

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

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

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 85f1713..3c67337 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -522,23 +522,28 @@ 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 script_language_defn *slang;
+      script_sourcer_func *sourcer = get_script_sourcer (file, &slang);
 
-      TRY_CATCH (e, RETURN_MASK_ERROR)
-	{
-	  source_python_script (stream, file);
-	}
-      if (e.reason < 0)
+      if (sourcer != NULL)
 	{
+	  volatile struct gdb_exception e;
+
+	  TRY_CATCH (e, RETURN_MASK_ERROR)
+	    {
+	      sourcer (slang, stream, file);
+	    }
+	  if (e.reason >= 0)
+	    return;
 	  /* Should we fallback to ye olde GDB script mode?  */
 	  if (script_ext_mode == script_ext_soft
-	      && e.reason == RETURN_ERROR && e.error == UNSUPPORTED_ERROR)
+	      && e.reason == RETURN_ERROR
+	      && e.error == UNSUPPORTED_ERROR)
 	    {
 	      fseek (stream, 0, SEEK_SET);
-	      script_from_file (stream, (char*) file);
+	      /* Script is loaded below.  */
 	    }
 	  else
 	    {
@@ -547,8 +552,8 @@ source_script_from_stream (FILE *stream, const char *file)
 	    }
 	}
     }
-  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..f0b4b2d 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_script_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]