Eliminate UNSUPPORTED_ERROR.
authorPedro Alves <palves@redhat.com>
Wed, 11 Dec 2013 09:49:08 +0000 (09:49 +0000)
committerPedro Alves <palves@redhat.com>
Thu, 12 Dec 2013 10:15:48 +0000 (10:15 +0000)
I have a case that could use an exception for "unsupported feature".
I found UNSUPPORTED_ERROR, but looking deeper, I think as is, reusing
it for other things would be fragile.  E.g., if the Python script
sourced by source_script_from_stream triggers any other missing
functionality that would result in UNSUPPORTED_ERROR being propagated
out to source_script_from_stream, that would confuse the error for
Python not being built into GDB.

This patch thus redoes things a little.  Instead of using an exception
for the "No Python" scenario, check whether Python is configured in
before actually trying to source the file.  It adds a new function
instead of using #ifdef HAVE_PYTHON directly, as that is better at
avoiding bitrot, as both Python and !Python paths are visible to the
compiler this way.

Tested on Fedora 17, with and without Python.

gdb/
2013-12-12  Pedro Alves  <palves@redhat.com>

* cli/cli-cmds.c (source_script_from_stream) Use have_python
instead of catching UNSUPPORTED_ERROR.
* exceptions.h (UNSUPPORTED_ERROR): Delete.
* python/python.c (source_python_script) [!HAVE_PYTHON]: Internal
error if called.
* python/python.h (have_python): New static inline function.

gdb/ChangeLog
gdb/cli/cli-cmds.c
gdb/exceptions.h
gdb/python/python.c
gdb/python/python.h

index 40368b55bd8d0e7fda86ec170385b753cd6381fe..637a462b6f4bfa2ee7f157be8045675094a0b86d 100644 (file)
@@ -1,3 +1,12 @@
+2013-12-12  Pedro Alves  <palves@redhat.com>
+
+       * cli/cli-cmds.c (source_script_from_stream) Use have_python
+       instead of catching UNSUPPORTED_ERROR.
+       * exceptions.h (UNSUPPORTED_ERROR): Delete.
+       * python/python.c (source_python_script) [!HAVE_PYTHON]: Internal
+       error if called.
+       * python/python.h (have_python): New static inline function.
+
 2013-12-11  Doug Evans  <dje@google.com>
 
        * dwarf2read.c (lookup_dwo_cutu): Include name of dwp file in
index 52a6bc90a78c62f99c5e10511dd7ca490a29a7b0..73e03cf3da0c6f0a52132260330984972a612b37 100644 (file)
@@ -525,27 +525,15 @@ 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"))
     {
-      volatile struct gdb_exception e;
-
-      TRY_CATCH (e, RETURN_MASK_ERROR)
+      if (have_python ())
+       source_python_script (stream, file);
+      else if (script_ext_mode == script_ext_soft)
        {
-         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)
-           {
-             fseek (stream, 0, SEEK_SET);
-             script_from_file (stream, (char*) file);
-           }
-         else
-           {
-             /* Nope, just punt.  */
-             throw_exception (e);
-           }
+         /* Fallback to GDB script mode.  */
+         script_from_file (stream, file);
        }
+      else
+       error (_("Python scripting is not supported in this copy of GDB."));
     }
   else
     script_from_file (stream, file);
index 705f1a1f617dbbfab76fb16c6cc335523aca9785..2cb82425d190de24c903e9514094cb5386d6dc9e 100644 (file)
@@ -79,9 +79,6 @@ enum errors {
   /* Error accessing memory.  */
   MEMORY_ERROR,
 
-  /* Feature is not supported in this copy of GDB.  */
-  UNSUPPORTED_ERROR,
-
   /* Value not available.  E.g., a register was not collected in a
      traceframe.  */
   NOT_AVAILABLE_ERROR,
index 1873936a5bcf7ddce88755c1f628016c7227f3c6..55bb6cfc313829ccc8a28dd4b2117b018375b779 100644 (file)
@@ -1390,8 +1390,9 @@ eval_python_from_control_command (struct command_line *cmd)
 void
 source_python_script (FILE *file, const char *filename)
 {
-  throw_error (UNSUPPORTED_ERROR,
-              _("Python scripting is not supported in this copy of GDB."));
+  internal_error (__FILE__, __LINE__,
+                 _("source_python_script called when Python scripting is "
+                   "not supported."));
 }
 
 int
index c07b2aa719cb8d503e1e2f11202b234de78c8d57..abbb5816c376ed73f0a47b17823f81690fe3bf37 100644 (file)
@@ -89,6 +89,19 @@ typedef enum py_frame_args
   CLI_ALL_VALUES
 } py_frame_args;
 
+/* Returns true if Python support is built into GDB, false
+   otherwise.  */
+
+static inline int
+have_python (void)
+{
+#ifdef HAVE_PYTHON
+  return 1;
+#else
+  return 0;
+#endif
+}
+
 extern void finish_python_initialization (void);
 
 void eval_python_from_control_command (struct command_line *);
This page took 0.041383 seconds and 4 git commands to generate.