Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
Cc: Doug Evans <xdje42@gmail.com>, Hui Zhu <hui_zhu@mentor.com>,
	       gdb-patches ml <gdb-patches@sourceware.org>
Subject: [PATCH] Eliminate UNSUPPORTED_ERROR.
Date: Tue, 10 Dec 2013 18:14:00 -0000	[thread overview]
Message-ID: <52A75A05.60006@redhat.com> (raw)
In-Reply-To: <52A750AA.1080807@redhat.com>

On 12/10/2013 05:34 PM, Pedro Alves wrote:
> On 12/09/2013 09:07 PM, Doug Evans wrote:

>>>> --- a/gdb/cli/cli-cmds.c
>>>> +++ b/gdb/cli/cli-cmds.c
>>>> @@ -527,24 +527,16 @@ source_script_from_stream (FILE *stream, const char *file)
>>>>      {
>>>>        volatile struct gdb_exception e;
>>>>  
>>>> -      TRY_CATCH (e, RETURN_MASK_ERROR)
>>>> -	{
>>>> -	  source_python_script (stream, file);
>>>> -	}
>>>> -      if (e.reason < 0)
>>>> +      if (!source_python_script (stream, file))
>> If we must change things, I would prefer having a predicate
>> and call that first.
> 
> I can try that.

OK?

----------
Subject: [PATCH] Eliminate UNSUPPORTED_ERROR.

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-10  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/cli/cli-cmds.c  | 27 ++++++++-------------------
 gdb/exceptions.h    |  3 ---
 gdb/python/python.c |  5 +++--
 gdb/python/python.h | 13 +++++++++++++
 4 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 52a6bc9..a0586ff 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -525,27 +525,16 @@ 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.  */
+	  fseek (stream, 0, SEEK_SET);
+	  script_from_file (stream, (char*) file);
 	}
+      else
+	error (_("Python scripting is not supported in this copy of GDB."));
     }
   else
     script_from_file (stream, file);
diff --git a/gdb/exceptions.h b/gdb/exceptions.h
index 705f1a1..2cb8242 100644
--- a/gdb/exceptions.h
+++ b/gdb/exceptions.h
@@ -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,
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 1873936..55bb6cf 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -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
diff --git a/gdb/python/python.h b/gdb/python/python.h
index c07b2aa..abbb581 100644
--- a/gdb/python/python.h
+++ b/gdb/python/python.h
@@ -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 *);
-- 
1.7.11.7



  reply	other threads:[~2013-12-10 18:14 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21 10:30 [PATCH] Let gdbserver doesn't tell GDB it support target-side breakpoint conditions and commands if it doesn't support 'Z' packet Hui Zhu
2013-10-21 15:37 ` Pedro Alves
2013-11-28 10:56   ` Hui Zhu
2013-11-28 17:38     ` Maciej W. Rozycki
2013-11-29  9:41       ` Hui Zhu
2013-11-29 15:27     ` [pushed] Plug target side conditions and commands leaks (was: Re: [PATCH] Let gdbserver doesn't tell GDB it support target-side breakpoint conditions and commands if it doesn't support 'Z' packet) Pedro Alves
2013-11-29 16:05     ` [PATCH] Let gdbserver doesn't tell GDB it support target-side breakpoint conditions and commands if it doesn't support 'Z' packet Pedro Alves
2013-12-02 12:45       ` Hui Zhu
2013-12-02 14:38         ` Pedro Alves
2013-12-03  4:50           ` Hui Zhu
2013-12-03  4:54             ` Hui Zhu
2013-12-06 19:29             ` Pedro Alves
2013-12-08  5:19               ` Hui Zhu
2013-12-08  8:34                 ` Doug Evans
2013-12-08 14:18                   ` Hui Zhu
2013-12-09 19:48                 ` Pedro Alves
2013-12-09 21:07                   ` Doug Evans
2013-12-10 17:34                     ` Pedro Alves
2013-12-10 18:14                       ` Pedro Alves [this message]
2013-12-11 16:33                         ` [PATCH] Eliminate UNSUPPORTED_ERROR Doug Evans
2013-12-11 19:17                           ` Pedro Alves
2013-12-12  4:23                             ` Doug Evans
2013-12-12 10:23                               ` Pedro Alves
2013-12-11 16:40                       ` [PATCH] Let gdbserver doesn't tell GDB it support target-side breakpoint conditions and commands if it doesn't support 'Z' packet Doug Evans
2013-12-12 10:55                     ` breakpoint.c:insert_bp_location: Constify local. (was: Re: [PATCH] Let gdbserver doesn't tell GDB it support target-side breakpoint conditions and commands if it doesn't support 'Z' packet) Pedro Alves
2013-12-12 12:55                     ` [PATCH] Let gdbserver doesn't tell GDB it support target-side breakpoint conditions and commands if it doesn't support 'Z' packet Pedro Alves
2014-01-09 18:36                       ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52A75A05.60006@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=hui_zhu@mentor.com \
    --cc=xdje42@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox