public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: throw OPTIMIZED_OUT_ERROR rather than GENERIC_ERROR
@ 2021-11-09 13:32 Andrew Burgess
  2021-11-15  0:34 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2021-11-09 13:32 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

While reviewing this patch:

  https://sourceware.org/pipermail/gdb-patches/2021-November/183227.html

I spotted that the patch could be improved if we threw
OPTIMIZED_OUT_ERROR rather than GENERIC_ERROR in a few places.

This commit updates error_value_optimized_out and
require_not_optimized_out to throw OPTIMIZED_OUT_ERROR.

I ran the testsuite and saw no regressions.  This doesn't really
surprise me, we don't usually write code like:

  catch (const gdb_exception_error &ex)
    {
      (if ex.error == GENERIC_ERROR)
        ...
      else
        ...
    }

There are a three places where we write something like:

  catch (const gdb_exception_error &ex)
    {
      (if ex.error == OPTIMIZED_OUT_ERROR)
        ...
    }

In frame.c:unwind_pc, stack.c:info_frame_command_core, and
value.c:value_optimized_out, but if we are hitting these cases then
it's not significantly changing GDB's behaviour.
---
 gdb/value.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/value.c b/gdb/value.c
index 998bec321a2..10edf3bb931 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1221,7 +1221,7 @@ value_actual_type (struct value *value, int resolve_simple_types,
 void
 error_value_optimized_out (void)
 {
-  error (_("value has been optimized out"));
+  throw_error (OPTIMIZED_OUT_ERROR, _("value has been optimized out"));
 }
 
 static void
@@ -1230,7 +1230,8 @@ require_not_optimized_out (const struct value *value)
   if (!value->optimized_out.empty ())
     {
       if (value->lval == lval_register)
-	error (_("register has not been saved in frame"));
+	throw_error (OPTIMIZED_OUT_ERROR,
+		     _("register has not been saved in frame"));
       else
 	error_value_optimized_out ();
     }
-- 
2.25.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: throw OPTIMIZED_OUT_ERROR rather than GENERIC_ERROR
  2021-11-09 13:32 [PATCH] gdb: throw OPTIMIZED_OUT_ERROR rather than GENERIC_ERROR Andrew Burgess
@ 2021-11-15  0:34 ` Simon Marchi
  2021-11-15 11:06   ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2021-11-15  0:34 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches



On 2021-11-09 08:32, Andrew Burgess via Gdb-patches wrote:
> While reviewing this patch:
> 
>   https://sourceware.org/pipermail/gdb-patches/2021-November/183227.html
> 
> I spotted that the patch could be improved if we threw
> OPTIMIZED_OUT_ERROR rather than GENERIC_ERROR in a few places.
> 
> This commit updates error_value_optimized_out and
> require_not_optimized_out to throw OPTIMIZED_OUT_ERROR.
> 
> I ran the testsuite and saw no regressions.  This doesn't really
> surprise me, we don't usually write code like:
> 
>   catch (const gdb_exception_error &ex)
>     {
>       (if ex.error == GENERIC_ERROR)
>         ...
>       else
>         ...
>     }
> 
> There are a three places where we write something like:
> 
>   catch (const gdb_exception_error &ex)
>     {
>       (if ex.error == OPTIMIZED_OUT_ERROR)
>         ...
>     }
> 
> In frame.c:unwind_pc, stack.c:info_frame_command_core, and
> value.c:value_optimized_out, but if we are hitting these cases then
> it's not significantly changing GDB's behaviour.

Just by the naming, this seems logical to me.  Is it maybe that
OPTIMIZED_OUT_ERROR has been introduced after error_value_optimized_out
and require_not_optimized_out, and they simply have never been updated
until now?

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: throw OPTIMIZED_OUT_ERROR rather than GENERIC_ERROR
  2021-11-15  0:34 ` Simon Marchi
@ 2021-11-15 11:06   ` Pedro Alves
  0 siblings, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2021-11-15 11:06 UTC (permalink / raw)
  To: Simon Marchi, Andrew Burgess, gdb-patches

On 2021-11-15 00:34, Simon Marchi via Gdb-patches wrote:
>> In frame.c:unwind_pc, stack.c:info_frame_command_core, and
>> value.c:value_optimized_out, but if we are hitting these cases then
>> it's not significantly changing GDB's behaviour.
> Just by the naming, this seems logical to me.  Is it maybe that
> OPTIMIZED_OUT_ERROR has been introduced after error_value_optimized_out
> and require_not_optimized_out, and they simply have never been updated
> until now?

I don't remember that detail offhand, but the patch also looks good to me.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-15 11:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 13:32 [PATCH] gdb: throw OPTIMIZED_OUT_ERROR rather than GENERIC_ERROR Andrew Burgess
2021-11-15  0:34 ` Simon Marchi
2021-11-15 11:06   ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).