[PATCH] Use block_enum instead of int for better typesafety

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Use block_enum instead of int for better typesafety

Sourceware - gdb-patches mailing list
---
 gdb/symtab.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 4920d94a24..54eb97ae0f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -92,7 +92,8 @@ struct block_symbol lookup_local_symbol (const char *name,
  enum language language);
 
 static struct block_symbol
-  lookup_symbol_in_objfile (struct objfile *objfile, int block_index,
+  lookup_symbol_in_objfile (struct objfile *objfile,
+    enum block_enum block_index,
     const char *name, const domain_enum domain);
 
 /* Type of the data stored on the program space.  */
@@ -2244,8 +2245,9 @@ lookup_global_symbol_from_objfile (struct objfile *main_objfile,
    static symbols.  */
 
 static struct block_symbol
-lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index,
-  const char *name, const domain_enum domain)
+lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
+  enum block_enum block_index, const char *name,
+  const domain_enum domain)
 {
   gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK);
 
@@ -2516,11 +2518,13 @@ lookup_symbol_in_static_block (const char *name,
    BLOCK_INDEX is one of GLOBAL_BLOCK or STATIC_BLOCK.  */
 
 static struct block_symbol
-lookup_symbol_in_objfile (struct objfile *objfile, int block_index,
+lookup_symbol_in_objfile (struct objfile *objfile, enum block_enum block_index,
   const char *name, const domain_enum domain)
 {
   struct block_symbol result;
 
+  gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK);
+
   if (symbol_lookup_debug)
     {
       fprintf_unfiltered (gdb_stdlog,
--
2.22.0.410.gd8fdbe21b5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH] Use block_enum instead of int for better typesafety

Sourceware - gdb-patches mailing list
gdb/ChangeLog:

2019-07-11  Christian Biesinger  <[hidden email]>

        * symtab.c (lookup_symbol_in_objfile_symtabs): Change int to block_enum.
        (lookup_symbol_in_objfile): Change int to block_enum and add a
        gdb_assert to make sure block_index is GLOBAL_BLOCK or STATIC_BLOCK.
---
 gdb/symtab.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 4920d94a24..54eb97ae0f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -87,17 +87,18 @@ static struct block_symbol
 static
 struct block_symbol lookup_local_symbol (const char *name,
  symbol_name_match_type match_type,
  const struct block *block,
  const domain_enum domain,
  enum language language);
 
 static struct block_symbol
-  lookup_symbol_in_objfile (struct objfile *objfile, int block_index,
+  lookup_symbol_in_objfile (struct objfile *objfile,
+    enum block_enum block_index,
     const char *name, const domain_enum domain);
 
 /* Type of the data stored on the program space.  */
 
 struct main_info
 {
   main_info () = default;
 
@@ -2239,18 +2240,19 @@ lookup_global_symbol_from_objfile (struct objfile *main_objfile,
 }
 
 /* Check to see if the symbol is defined in one of the OBJFILE's
    symtabs.  BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
    depending on whether or not we want to search global symbols or
    static symbols.  */
 
 static struct block_symbol
-lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index,
-  const char *name, const domain_enum domain)
+lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
+  enum block_enum block_index, const char *name,
+  const domain_enum domain)
 {
   gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK);
 
   if (symbol_lookup_debug > 1)
     {
       fprintf_unfiltered (gdb_stdlog,
   "lookup_symbol_in_objfile_symtabs (%s, %s, %s, %s)",
   objfile_debug_name (objfile),
@@ -2511,21 +2513,23 @@ lookup_symbol_in_static_block (const char *name,
 }
 
 /* Perform the standard symbol lookup of NAME in OBJFILE:
    1) First search expanded symtabs, and if not found
    2) Search the "quick" symtabs (partial or .gdb_index).
    BLOCK_INDEX is one of GLOBAL_BLOCK or STATIC_BLOCK.  */
 
 static struct block_symbol
-lookup_symbol_in_objfile (struct objfile *objfile, int block_index,
+lookup_symbol_in_objfile (struct objfile *objfile, enum block_enum block_index,
   const char *name, const domain_enum domain)
 {
   struct block_symbol result;
 
+  gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK);
+
   if (symbol_lookup_debug)
     {
       fprintf_unfiltered (gdb_stdlog,
   "lookup_symbol_in_objfile (%s, %s, %s, %s)\n",
   objfile_debug_name (objfile),
   block_index == GLOBAL_BLOCK
   ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
   name, domain_name (domain));
--
2.22.0.410.gd8fdbe21b5-goog

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Use block_enum instead of int for better typesafety

Tom Tromey-2
>>>>> "Christian" == Christian Biesinger via gdb-patches <[hidden email]> writes:

Christian> 2019-07-11  Christian Biesinger  <[hidden email]>

Christian> * symtab.c (lookup_symbol_in_objfile_symtabs): Change int to block_enum.
Christian> (lookup_symbol_in_objfile): Change int to block_enum and add a
Christian> gdb_assert to make sure block_index is GLOBAL_BLOCK or STATIC_BLOCK.

Thanks, this is ok.  Please check it in.

Tom
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Use block_enum instead of int for better typesafety

Sourceware - gdb-patches mailing list
On Fri, Jul 19, 2019, 08:54 Tom Tromey <[hidden email]> wrote:

> >>>>> "Christian" == Christian Biesinger via gdb-patches <
> [hidden email]> writes:
>
> Christian> 2019-07-11  Christian Biesinger  <[hidden email]>
>
> Christian>      * symtab.c (lookup_symbol_in_objfile_symtabs): Change int
> to block_enum.
> Christian>      (lookup_symbol_in_objfile): Change int to block_enum and
> add a
> Christian>      gdb_assert to make sure block_index is GLOBAL_BLOCK or
> STATIC_BLOCK.
>
> Thanks, this is ok.  Please check it in.
>

I don't have a committer account -- maybe I should take you up on the offer
last time and get one.


> Tom
>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Use block_enum instead of int for better typesafety

Sourceware - gdb-patches mailing list
On Fri, Jul 19, 2019 at 9:38 AM Christian Biesinger
<[hidden email]> wrote:

>
> On Fri, Jul 19, 2019, 08:54 Tom Tromey <[hidden email]> wrote:
>>
>> >>>>> "Christian" == Christian Biesinger via gdb-patches <[hidden email]> writes:
>>
>> Christian> 2019-07-11  Christian Biesinger  <[hidden email]>
>>
>> Christian>      * symtab.c (lookup_symbol_in_objfile_symtabs): Change int to block_enum.
>> Christian>      (lookup_symbol_in_objfile): Change int to block_enum and add a
>> Christian>      gdb_assert to make sure block_index is GLOBAL_BLOCK or STATIC_BLOCK.
>>
>> Thanks, this is ok.  Please check it in.
>
>
> I don't have a committer account -- maybe I should take you up on the offer last time and get one.

I have gotten the account now and pushed this patch.

Christian