[1/7] Handle ^C in gnu_source_highlight_test

Message ID 20240827140021.32660-1-tdevries@suse.de
State Committed
Headers
Series [1/7] Handle ^C in gnu_source_highlight_test |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom de Vries Aug. 27, 2024, 2 p.m. UTC
  In gnu_source_highlight_test we have:
...
  try
    {
      res = try_source_highlight (styled_prog, language_c, fullname);
    }
  catch (...)
    {
      saw_exception = true;
    }
...

This also swallows gdb_exception_quit and gdb_exception_forced_quit.  I don't
know whether these can actually happen here, but if not it's better to
accommodate for the possibility anyway.

Fix this by handling gdb_exception explicitly, and rethrowing
gdb_exception_quit and gdb_exception_forced_quit.

Tested on aarch64-linux.
---
 gdb/source-cache.c | 6 ++++++
 1 file changed, 6 insertions(+)


base-commit: fd8ec8ed8258990700aaf422cea0e12208356014
  

Comments

Tom de Vries Sept. 23, 2024, 8:13 a.m. UTC | #1
On 8/27/24 16:00, Tom de Vries wrote:
> In gnu_source_highlight_test we have:
> ...
>    try
>      {
>        res = try_source_highlight (styled_prog, language_c, fullname);
>      }
>    catch (...)
>      {
>        saw_exception = true;
>      }
> ...
> 
> This also swallows gdb_exception_quit and gdb_exception_forced_quit.  I don't
> know whether these can actually happen here, but if not it's better to
> accommodate for the possibility anyway.
> 
> Fix this by handling gdb_exception explicitly, and rethrowing
> gdb_exception_quit and gdb_exception_forced_quit.
> 

Ping.

Thanks,
- Tom

> Tested on aarch64-linux.
> ---
>   gdb/source-cache.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/gdb/source-cache.c b/gdb/source-cache.c
> index 6af984fb88b..5486c1b8c2d 100644
> --- a/gdb/source-cache.c
> +++ b/gdb/source-cache.c
> @@ -282,6 +282,12 @@ static void gnu_source_highlight_test ()
>       {
>         res = try_source_highlight (styled_prog, language_c, fullname);
>       }
> +  catch (const gdb_exception &e)
> +    {
> +      if (e.reason != RETURN_ERROR)
> +	throw;
> +      saw_exception = true;
> +    }
>     catch (...)
>       {
>         saw_exception = true;
> 
> base-commit: fd8ec8ed8258990700aaf422cea0e12208356014
  
Tom Tromey Sept. 23, 2024, 5:45 p.m. UTC | #2
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> In gnu_source_highlight_test we have:
Tom> ...
Tom>   try
Tom>     {
Tom>       res = try_source_highlight (styled_prog, language_c, fullname);
Tom>     }
Tom>   catch (...)
Tom>     {
Tom>       saw_exception = true;
Tom>     }
Tom> ...

Tom> This also swallows gdb_exception_quit and gdb_exception_forced_quit.  I don't
Tom> know whether these can actually happen here, but if not it's better to
Tom> accommodate for the possibility anyway.

It's doubtful but safe enough.

Tom> Fix this by handling gdb_exception explicitly, and rethrowing
Tom> gdb_exception_quit and gdb_exception_forced_quit.

Approved-By: Tom Tromey <tom@tromey.com>

Tom
  
Tom de Vries Sept. 24, 2024, 2:52 p.m. UTC | #3
On 9/23/24 19:45, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> In gnu_source_highlight_test we have:
> Tom> ...
> Tom>   try
> Tom>     {
> Tom>       res = try_source_highlight (styled_prog, language_c, fullname);
> Tom>     }
> Tom>   catch (...)
> Tom>     {
> Tom>       saw_exception = true;
> Tom>     }
> Tom> ...
> 
> Tom> This also swallows gdb_exception_quit and gdb_exception_forced_quit.  I don't
> Tom> know whether these can actually happen here, but if not it's better to
> Tom> accommodate for the possibility anyway.
> 
> It's doubtful but safe enough.
> 
> Tom> Fix this by handling gdb_exception explicitly, and rethrowing
> Tom> gdb_exception_quit and gdb_exception_forced_quit.
> 
> Approved-By: Tom Tromey <tom@tromey.com>

I've pushed this series as posted, unless mentioned otherwise in an 
individual reply.

Thanks for the reviews.

- Tom
  

Patch

diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 6af984fb88b..5486c1b8c2d 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -282,6 +282,12 @@  static void gnu_source_highlight_test ()
     {
       res = try_source_highlight (styled_prog, language_c, fullname);
     }
+  catch (const gdb_exception &e)
+    {
+      if (e.reason != RETURN_ERROR)
+	throw;
+      saw_exception = true;
+    }
   catch (...)
     {
       saw_exception = true;