]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use arrays rather than pointers for global string constants
authorTom Tromey <tromey@adacore.com>
Tue, 15 Sep 2020 14:38:22 +0000 (08:38 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 15 Sep 2020 14:38:22 +0000 (08:38 -0600)
My understanding is that it's mildly better to use a static const
array, as opposed to a "const char *", for a global string constant,
when possible.  This makes sense to me because the pointer requires a
load from an address, whereas the array is just the address.

So, I searched for these in gdb and gdbserver.  This patch fixes the
ones I found.

gdb/ChangeLog
2020-09-15  Tom Tromey  <tromey@adacore.com>

* unittests/memory-map-selftests.c (valid_mem_map): Now array.
* ui-style.c (ansi_regex_text): Now array.
* rust-exp.y (number_regex_text): Now array.
* linespec.c (linespec_quote_characters): Now array.
* jit.c (jit_break_name, jit_descriptor_name, reader_init_fn_sym):
Now arrays.

gdbserver/ChangeLog
2020-09-15  Tom Tromey  <tromey@adacore.com>

* linux-x86-low.cc (xmltarget_i386_linux_no_xml)
(xmltarget_amd64_linux_no_xml): Now arrays.

gdb/ChangeLog
gdb/jit.c
gdb/linespec.c
gdb/rust-exp.y
gdb/ui-style.c
gdb/unittests/memory-map-selftests.c
gdbserver/ChangeLog
gdbserver/linux-x86-low.cc

index 7ed944aa97617def2276918118333b8f1fa17e54..fe19f19d47bc07ee3655cc119c12a5a798cd31e3 100644 (file)
@@ -1,3 +1,12 @@
+2020-09-15  Tom Tromey  <tromey@adacore.com>
+
+       * unittests/memory-map-selftests.c (valid_mem_map): Now array.
+       * ui-style.c (ansi_regex_text): Now array.
+       * rust-exp.y (number_regex_text): Now array.
+       * linespec.c (linespec_quote_characters): Now array.
+       * jit.c (jit_break_name, jit_descriptor_name, reader_init_fn_sym):
+       Now arrays.
+
 2020-09-14  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * debuginfod-support.c (debuginfod_client_deleter): New.
index 024c66e7add34c5b2183871e88a95db9da9169d1..5634c9e2b5d318b670afbb1a1fd1b714edaf3f50 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -45,9 +45,9 @@
 
 static std::string jit_reader_dir;
 
-static const char *const jit_break_name = "__jit_debug_register_code";
+static const char jit_break_name[] = "__jit_debug_register_code";
 
-static const char *const jit_descriptor_name = "__jit_debug_descriptor";
+static const char jit_descriptor_name[] = "__jit_debug_descriptor";
 
 static void jit_inferior_init (struct gdbarch *gdbarch);
 static void jit_inferior_exit_hook (struct inferior *inf);
@@ -173,7 +173,7 @@ struct jit_reader
 static struct jit_reader *loaded_jit_reader = NULL;
 
 typedef struct gdb_reader_funcs * (reader_init_fn_type) (void);
-static const char *reader_init_fn_sym = "gdb_init_reader";
+static const char reader_init_fn_sym[] = "gdb_init_reader";
 
 /* Try to load FILE_NAME as a JIT debug info reader.  */
 
index 9c80864c34e0adf782efdd08a84bbbdb64a9bcd2..686992ea8ae0bb1ecadfba387cf4633095937514 100644 (file)
@@ -421,7 +421,7 @@ static bool compare_msymbols (const bound_minimal_symbol &a,
 /* Permitted quote characters for the parser.  This is different from the
    completer's quote characters to allow backward compatibility with the
    previous parser.  */
-static const char *const linespec_quote_characters = "\"\'";
+static const char linespec_quote_characters[] = "\"\'";
 
 /* Lexer functions.  */
 
index 4e7878f67e1f93fe5cc4b02fe609d3eff008ee30..db888098c4a6b878d3eb47bf87435149d1b11d60 100644 (file)
@@ -123,7 +123,7 @@ static struct stoken make_stoken (const char *);
    since it is very long and this gives us a way to comment the
    sections.  */
 
-static const char *number_regex_text =
+static const char number_regex_text[] =
   /* subexpression 1: allows use of alternation, otherwise uninteresting */
   "^("
   /* First comes floating point.  */
index 2d6640bc700c303c2995fc334a2893a4c38c5831..4ed08dadc329b4112a8cbef5cdfc75c4aa3a0f76 100644 (file)
@@ -23,7 +23,7 @@
 /* A regular expression that is used for matching ANSI terminal escape
    sequences.  */
 
-static const char *ansi_regex_text =
+static const char ansi_regex_text[] =
   /* Introduction.  */
   "^\033\\["
 #define DATA_SUBEXP 1
index 42b5db6974ac67c265b28e0253e94e60f1647b9c..0be5cb573e5b74279f257313e8d602a74cb95827 100644 (file)
@@ -28,7 +28,7 @@ namespace memory_map_tests {
 
 /* A simple valid test input for parse_memory_map.  */
 
-static const char *valid_mem_map = R"(<?xml version="1.0"?>
+static const char valid_mem_map[] = R"(<?xml version="1.0"?>
 <!DOCTYPE memory-map
           PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
                  "http://sourceware.org/gdb/gdb-memory-map.dtd">
index 3b08ef393bc173c5ba6df39429e351014fca603f..576c96e93b8bbfcd51c613499847cb03b765f57c 100644 (file)
@@ -1,3 +1,8 @@
+2020-09-15  Tom Tromey  <tromey@adacore.com>
+
+       * linux-x86-low.cc (xmltarget_i386_linux_no_xml)
+       (xmltarget_amd64_linux_no_xml): Now arrays.
+
 2020-09-14  Tom Tromey  <tromey@adacore.com>
 
        * tracepoint.cc (eval_result_names): Now const.
index 37d3626e1f73671f8852ecf4cef1f933823377d0..eeaced8c8d521c5e9c2880a9fcdecac4ef73fec7 100644 (file)
@@ -58,13 +58,13 @@ static unsigned char small_jump_insn[] = { 0x66, 0xe9, 0, 0 };
 
 /* Backward compatibility for gdb without XML support.  */
 
-static const char *xmltarget_i386_linux_no_xml = "@<target>\
+static const char xmltarget_i386_linux_no_xml[] = "@<target>\
 <architecture>i386</architecture>\
 <osabi>GNU/Linux</osabi>\
 </target>";
 
 #ifdef __x86_64__
-static const char *xmltarget_amd64_linux_no_xml = "@<target>\
+static const char xmltarget_amd64_linux_no_xml[] = "@<target>\
 <architecture>i386:x86-64</architecture>\
 <osabi>GNU/Linux</osabi>\
 </target>";