diff options
author | Tom Tromey <tom@tromey.com> | 2023-01-16 18:14:47 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2023-02-19 12:51:06 -0700 |
commit | d24e14a0c62181b49f513f6ed3704212fd276c79 (patch) | |
tree | 341cbf16737b778d0a4cb71276adfe209cf4bb6c /gdb | |
parent | 99f3dfd0f94144d295885e79f4ff5a5f8119fb04 (diff) | |
download | binutils-d24e14a0c62181b49f513f6ed3704212fd276c79.zip binutils-d24e14a0c62181b49f513f6ed3704212fd276c79.tar.gz binutils-d24e14a0c62181b49f513f6ed3704212fd276c79.tar.bz2 |
Convert block_static_block and block_global_block to methods
This converts block_static_block and block_global_block to be methods.
This was mostly written by script. It was simpler to convert them at
the same time because they're often used near each other.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ada-lang.c | 2 | ||||
-rw-r--r-- | gdb/block.c | 18 | ||||
-rw-r--r-- | gdb/block.h | 13 | ||||
-rw-r--r-- | gdb/compile/compile-c-symbols.c | 6 | ||||
-rw-r--r-- | gdb/compile/compile-cplus-symbols.c | 4 | ||||
-rw-r--r-- | gdb/cp-namespace.c | 2 | ||||
-rw-r--r-- | gdb/cp-support.c | 8 | ||||
-rw-r--r-- | gdb/findvar.c | 6 | ||||
-rw-r--r-- | gdb/guile/scm-block.c | 4 | ||||
-rw-r--r-- | gdb/python/py-block.c | 4 | ||||
-rw-r--r-- | gdb/rust-parse.c | 2 | ||||
-rw-r--r-- | gdb/symtab.c | 10 |
12 files changed, 43 insertions, 36 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index e7e40cc..1f381a2 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13798,7 +13798,7 @@ public: sym = ada_lookup_symbol (name, (block == nullptr ? nullptr - : block_static_block (block)), + : block->static_block ()), domain); if (sym.symbol != NULL) return sym; diff --git a/gdb/block.c b/gdb/block.c index 31916ce..c0d6ed7 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -47,7 +47,7 @@ block::objfile () const if (function () != nullptr) return function ()->objfile (); - global_block = (struct global_block *) block_global_block (this); + global_block = (struct global_block *) this->global_block (); return global_block->compunit_symtab->objfile (); } @@ -349,26 +349,28 @@ block::set_using (struct using_direct *using_decl, struct obstack *obstack) m_namespace_info->using_decl = using_decl; } -/* Return the static block associated to BLOCK. Return NULL if block - is a global block. */ +/* See block.h. */ const struct block * -block_static_block (const struct block *block) +block::static_block () const { - if (block->superblock () == NULL) - return NULL; + if (superblock () == nullptr) + return nullptr; + const block *block = this; while (block->superblock ()->superblock () != NULL) block = block->superblock (); return block; } -/* Return the static block associated to BLOCK. */ +/* See block.h. */ const struct block * -block_global_block (const struct block *block) +block::global_block () const { + const block *block = this; + while (block->superblock () != NULL) block = block->superblock (); diff --git a/gdb/block.h b/gdb/block.h index 9f1ba93..9ce8ef5 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -245,6 +245,15 @@ struct block struct symbol *containing_function () const; + /* Return the static block associated with this block. Return NULL + if block is a global block. */ + + const struct block *static_block () const; + + /* Return the static block associated with block. */ + + const struct block *global_block () const; + /* Addresses in the executable code that are in this block. */ CORE_ADDR m_start; @@ -404,10 +413,6 @@ extern const struct block *block_for_pc (CORE_ADDR); extern const struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *); -extern const struct block *block_static_block (const struct block *block); - -extern const struct block *block_global_block (const struct block *block); - extern struct block *allocate_block (struct obstack *obstack); extern struct block *allocate_global_block (struct obstack *obstack); diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c index 7af0bff..73b4c4d 100644 --- a/gdb/compile/compile-c-symbols.c +++ b/gdb/compile/compile-c-symbols.c @@ -228,7 +228,7 @@ convert_symbol_sym (compile_c_instance *context, const char *identifier, const struct block *static_block = nullptr; if (sym.block != nullptr) - static_block = block_static_block (sym.block); + static_block = sym.block->static_block (); /* STATIC_BLOCK is NULL if FOUND_BLOCK is the global block. */ is_local_symbol = (sym.block != static_block && static_block != NULL); if (is_local_symbol) @@ -239,7 +239,7 @@ convert_symbol_sym (compile_c_instance *context, const char *identifier, /* If the outer symbol is in the static block, we ignore it, as it cannot be referenced. */ if (global_sym.symbol != NULL - && global_sym.block != block_static_block (global_sym.block)) + && global_sym.block != global_sym.block->static_block ()) { if (compile_debug) gdb_printf (gdb_stdlog, @@ -617,7 +617,7 @@ generate_c_for_variable_locations (compile_instance *compiler, if (block == nullptr) return {}; - const struct block *static_block = block_static_block (block); + const struct block *static_block = block->static_block (); /* If we're already in the static or global block, there is nothing to write. */ diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c index c183d08..02b7b89 100644 --- a/gdb/compile/compile-cplus-symbols.c +++ b/gdb/compile/compile-cplus-symbols.c @@ -241,7 +241,7 @@ convert_symbol_sym (compile_cplus_instance *instance, const struct block *static_block = nullptr; if (sym.block != nullptr) - static_block = block_static_block (sym.block); + static_block = sym.block->static_block (); /* STATIC_BLOCK is NULL if FOUND_BLOCK is the global block. */ bool is_local_symbol = (sym.block != static_block && static_block != nullptr); if (is_local_symbol) @@ -252,7 +252,7 @@ convert_symbol_sym (compile_cplus_instance *instance, /* If the outer symbol is in the static block, we ignore it, as it cannot be referenced. */ if (global_sym.symbol != nullptr - && global_sym.block != block_static_block (global_sym.block)) + && global_sym.block != global_sym.block->static_block ()) { if (compile_debug) gdb_printf (gdb_stdlog, diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 2d44b7b..14d8076 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -141,7 +141,7 @@ cp_basic_lookup_symbol (const char *name, const struct block *block, but should be treated as local to a single file nonetheless. So we only search the current file's global block. */ - const struct block *global_block = block_global_block (block); + const struct block *global_block = block->global_block (); if (global_block != NULL) { diff --git a/gdb/cp-support.c b/gdb/cp-support.c index fd5a286..c434d5a 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1308,13 +1308,13 @@ add_symbol_overload_list_namespace (const char *func_name, /* Look in the static block. */ block = get_selected_block (0); - block = block == nullptr ? nullptr : block_static_block (block); + block = block == nullptr ? nullptr : block->static_block (); if (block != nullptr) { add_symbol_overload_list_block (name, block, overload_list); /* Look in the global block. */ - block = block_global_block (block); + block = block->global_block (); if (block) add_symbol_overload_list_block (name, block, overload_list); } @@ -1458,10 +1458,10 @@ add_symbol_overload_list_qualified (const char *func_name, b = b->superblock ()) add_symbol_overload_list_block (func_name, b, overload_list); - surrounding_static_block = block_static_block (get_selected_block (0)); + surrounding_static_block = get_selected_block (0); surrounding_static_block = (surrounding_static_block == nullptr ? nullptr - : block_static_block (surrounding_static_block)); + : surrounding_static_block->static_block ()); /* Go through the symtabs and check the externs and statics for symbols which match. */ diff --git a/gdb/findvar.c b/gdb/findvar.c index 528181d..806f41d 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -460,8 +460,8 @@ get_hosting_frame (struct symbol *var, const struct block *var_block, tests that embed global/static symbols with null location lists. We want to get <optimized out> instead of <frame required> when evaluating them so return a frame instead of raising an error. */ - else if (var_block == block_global_block (var_block) - || var_block == block_static_block (var_block)) + else if (var_block == var_block->global_block () + || var_block == var_block->static_block ()) return frame; /* We have to handle the "my_func::my_local_var" notation. This requires us @@ -486,7 +486,7 @@ get_hosting_frame (struct symbol *var, const struct block *var_block, /* If we failed to find the proper frame, fallback to the heuristic method below. */ - else if (frame_block == block_global_block (frame_block)) + else if (frame_block == frame_block->global_block ()) { frame = NULL; break; diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c index 02cd3ff..c9d847a 100644 --- a/gdb/guile/scm-block.c +++ b/gdb/guile/scm-block.c @@ -438,7 +438,7 @@ gdbscm_block_global_block (SCM self) const struct block *block = b_smob->block; const struct block *global_block; - global_block = block_global_block (block); + global_block = block->global_block (); return bkscm_scm_from_block (global_block, b_smob->objfile); } @@ -458,7 +458,7 @@ gdbscm_block_static_block (SCM self) if (block->superblock () == NULL) return SCM_BOOL_F; - static_block = block_static_block (block); + static_block = block->static_block (); return bkscm_scm_from_block (static_block, b_smob->objfile); } diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index c399a01..bd2ce7f 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -188,7 +188,7 @@ blpy_get_global_block (PyObject *self, void *closure) BLPY_REQUIRE_VALID (self, block); - global_block = block_global_block (block); + global_block = block->global_block (); return block_to_block_object (global_block, self_obj->objfile); @@ -210,7 +210,7 @@ blpy_get_static_block (PyObject *self, void *closure) if (block->superblock () == NULL) Py_RETURN_NONE; - static_block = block_static_block (block); + static_block = block->static_block (); return block_to_block_object (static_block, self_obj->objfile); } diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index 9074d65..545d014 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -421,7 +421,7 @@ munge_name_and_block (const char **name, const struct block **block) if (startswith (*name, "::")) { *name += 2; - *block = block_static_block (*block); + *block = (*block)->static_block (); } } diff --git a/gdb/symtab.c b/gdb/symtab.c index bd6abbf..d6dc323 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2159,7 +2159,7 @@ lookup_local_symbol (const char *name, return {}; struct symbol *sym; - const struct block *static_block = block_static_block (block); + const struct block *static_block = block->static_block (); const char *scope = block->scope (); /* Check if it's a global block. */ @@ -2463,7 +2463,7 @@ lookup_symbol_in_static_block (const char *name, if (block == nullptr) return {}; - const struct block *static_block = block_static_block (block); + const struct block *static_block = block->static_block (); struct symbol *sym; if (static_block == NULL) @@ -2598,7 +2598,7 @@ lookup_global_symbol (const char *name, global block first. This yields "more expected" behavior, and is needed to support 'FILENAME'::VARIABLE lookups. */ const struct block *global_block - = block == nullptr ? nullptr : block_global_block (block); + = block == nullptr ? nullptr : block->global_block (); symbol *sym = NULL; if (global_block != nullptr) { @@ -5831,8 +5831,8 @@ default_collect_symbol_completion_matches_break_on visible from current context. */ b = get_selected_block (0); - surrounding_static_block = b == nullptr ? nullptr : block_static_block (b); - surrounding_global_block = b == nullptr : nullptr : block_global_block (b); + surrounding_static_block = b == nullptr ? nullptr : b->static_block (); + surrounding_global_block = b == nullptr ? nullptr : b->global_block (); if (surrounding_static_block != NULL) while (b != surrounding_static_block) { |