Add const to catch gdb_exception

Message ID 20240821150801.28396-1-tdevries@suse.de
State Committed
Headers
Series Add const to catch gdb_exception |

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. 21, 2024, 3:08 p.m. UTC
  I did a review of lines containing "catch (gdb_exception" and found a few
where we can add const.

Tested on x86_64-linux.
---
 gdb/exec.c                            | 2 +-
 gdb/python/py-breakpoint.c            | 4 ++--
 gdb/python/py-inferior.c              | 4 ++--
 gdb/python/py-value.c                 | 4 ++--
 gdb/unittests/scoped_mmap-selftests.c | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)


base-commit: 28c3bf55f0f9aca8619c6d01be34a02a887c5577
  

Comments

Tom Tromey Aug. 21, 2024, 5:04 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> I did a review of lines containing "catch (gdb_exception" and found a few
Tom> where we can add const.

Thanks.

IIRC there's at least one spot where the exception is moved and so can't
be const.  But this should definitely be the default.

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

Tom
  

Patch

diff --git a/gdb/exec.c b/gdb/exec.c
index 63eee4297bc..683b0a17b14 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -294,7 +294,7 @@  validate_exec_file (int from_tty)
 	      symbol_file_add_main (exec_file_target.c_str (), add_flags);
 	      exec_file_attach (exec_file_target.c_str (), from_tty);
 	    }
-	  catch (gdb_exception_error &err)
+	  catch (const gdb_exception_error &err)
 	    {
 	      warning (_("loading %ps %s"),
 		       styled_string (file_name_style.style (),
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index e7dd47020c5..74013977f0d 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -611,7 +611,7 @@  bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
     {
       set_breakpoint_condition (self_bp->bp, exp, 0, false);
     }
-  catch (gdb_exception &ex)
+  catch (const gdb_exception &ex)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (ex);
     }
@@ -677,7 +677,7 @@  bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
       counted_command_line lines = read_command_lines_1 (reader, 1, nullptr);
       breakpoint_set_commands (self_bp->bp, std::move (lines));
     }
-  catch (gdb_exception &ex)
+  catch (const gdb_exception &ex)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (ex);
     }
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index a1042ee72ac..ccc3e881702 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -631,7 +631,7 @@  infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
 
       write_memory_with_notification (addr, buffer, length);
     }
-  catch (gdb_exception &ex)
+  catch (const gdb_exception &ex)
     {
       GDB_PY_HANDLE_EXCEPTION (ex);
     }
@@ -705,7 +705,7 @@  infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
 				    buffer, pattern_size,
 				    &found_addr);
     }
-  catch (gdb_exception &ex)
+  catch (const gdb_exception &ex)
     {
       GDB_PY_HANDLE_EXCEPTION (ex);
     }
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 5c62ef681d4..4980076a0ef 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1178,7 +1178,7 @@  valpy_getitem (PyObject *self, PyObject *key)
       if (res_val)
 	result = value_to_value_object (res_val);
     }
-  catch (gdb_exception &ex)
+  catch (const gdb_exception &ex)
     {
       GDB_PY_HANDLE_EXCEPTION (ex);
     }
@@ -1704,7 +1704,7 @@  valpy_nonzero (PyObject *self)
 	/* All other values are True.  */
 	nonzero = 1;
     }
-  catch (gdb_exception &ex)
+  catch (const gdb_exception &ex)
     {
       /* This is not documented in the Python documentation, but if
 	 this function fails, return -1 as slot_nb_nonzero does (the
diff --git a/gdb/unittests/scoped_mmap-selftests.c b/gdb/unittests/scoped_mmap-selftests.c
index 7b3a6f5202b..09a94ed6590 100644
--- a/gdb/unittests/scoped_mmap-selftests.c
+++ b/gdb/unittests/scoped_mmap-selftests.c
@@ -114,7 +114,7 @@  test_invalid_filename ()
 
   try {
       ::scoped_mmap m = ::mmap_file ("/this/file/should/not/exist");
-  } catch (gdb_exception &e) {
+  } catch (const gdb_exception &e) {
       threw = true;
   }