>From what I can see, lookup_minimal_symbol doesn't have any dependencies
on the global current state other than the single reference to
current_program_space. Add a program_space parameter and make that
current_program_space reference bubble up one level.
Change-Id: I759415e2f9c74c9627a2fe05bd44eb4147eee6fe
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
Now that lookup_minimal_symbol has default values for sfile and objf,
calling lookup_bound_minimal_symbol is identical to calling
lookup_minimal_symbol without sfile and objf. Remove
lookup_bound_minimal_symbol, replace call sites with
lookup_minimal_symbol.
Change-Id: I0a420fb56de1de8bee8a7303228c9e4546e3577b
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
This is a simple find / replace from "struct bound_minimal_symbol" to
"bound_minimal_symbol", to make things shorter and more consisten
througout. In some cases, move variable declarations where first used.
Change-Id: Ica4af11c4ac528aa842bfa49a7afe8fe77a66849
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
Make the current program space reference bubble up one level.
Change-Id: I19c4fc2ca955f9c828ef426a077b43983865697b
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
A few spots (mostly in the parsers) use alloca to ensure that a string
is terminated before passing it to a printf-like function (mostly
'error'). However, this isn't needed as the "%.*s" format can be used
instead.
This patch makes this change.
In one spot the alloca is dead code and is simply removed.
Regression tested on x86-64 Fedora 38.
Approved-By: John Baldwin <jhb@FreeBSD.org>
Now that defs.h, server.h and common-defs.h are included via the
`-include` option, it is no longer necessary for source files to include
them. Remove all the inclusions of these files I could find. Update
the generation scripts where relevant.
Change-Id: Ia026cff269c1b7ae7386dd3619bc9bb6a5332837
Approved-By: Pedro Alves <pedro@palves.net>
This patch changes the DWARF reader to use the new symbol domains. It
also adjusts many bits of associated code to adapt to this change.
The non-DWARF readers are updated on a best-effort basis. This is
somewhat simpler since most of them only support C and C++. I have no
way to test a few of these.
I went back and forth a few times on how to handle the "tag"
situation. The basic problem is that C has a special namespace for
tags, which is separate from the type namespace. Other languages
don't do this. So, the question is, should a DW_TAG_structure_type
end up in the tag domain, or the type domain, or should it be
language-dependent?
I settled on making it language-dependent using a thought experiment.
Suppose there was a Rust compiler that only emitted nameless
DW_TAG_structure_type objects, and specified all structure type names
using DW_TAG_typedef. This DWARF would be correct, in that it
faithfully represents the source language -- but would not work with a
purely struct-domain implementation in gdb. Therefore gdb would be
wrong.
Now, this approach is a little tricky for C++, which uses tags but
also enters a typedef for them. I notice that some other readers --
like stabsread -- actually emit a typedef symbol as well. And, I
think this is a reasonable approach. It uses more memory, but it
makes the internals simpler. However, DWARF never did this for
whatever reason, and so in the interest of keeping the series slightly
shorter, I've left some C++-specific hacks in place here.
Note that this patch includes language_minimal as a language that uses
tags. I did this to avoid regressing gdb.dwarf2/debug-names-tu.exp,
which doesn't specify the language for a type unit. Arguably this
test case is wrong.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30164
This changes lookup_symbol and associated APIs to accept
domain_search_flags rather than a domain_enum.
Note that this introduces some new constants to Python and Guile. I
chose to break out the documentation patch for this, because the
internals here do not change until a later patch, and it seemed
simpler to patch the docs just once, rather than twice.
This commit is the result of the following actions:
- Running gdb/copyright.py to update all of the copyright headers to
include 2024,
- Manually updating a few files the copyright.py script told me to
update, these files had copyright headers embedded within the
file,
- Regenerating gdbsupport/Makefile.in to refresh it's copyright
date,
- Using grep to find other files that still mentioned 2023. If
these files were updated last year from 2022 to 2023 then I've
updated them this year to 2024.
I'm sure I've probably missed some dates. Feel free to fix them up as
you spot them.
Many (all?) of the expression parsers implement yyerror to handle
parser errors, and all of these functions are basically identical.
This commit adds a new parser_state::parse_error() function, which
implements the common error handling code, this function can then be
called from all the different yyerror functions.
The benefit of this is that (in a future commit) I can improve the
error output, and all the expression parsers will benefit.
This commit is pure refactoring though, and so, there should be no
user visible changes after this commit.
Approved-By: John Baldwin <jhb@FreeBSD.org>
This changes gdb to use the C++17 [[fallthrough]] attribute rather
than special comments.
This was mostly done by script, but I neglected a few spellings and so
also fixed it up by hand.
I suspect this fixes the bug mentioned below, by switching to a
standard approach that, presumably, clang supports.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23159
Approved-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Pedro Alves <pedro@palves.net>
When building gdb with -O2 -flto I run into:
...
/data/vries/gdb/src/gdb/c-exp.y:2450:8: warning: type 'struct token' \
violates the C++ One Definition Rule [-Wodr]
struct token
^
/data/vries/gdb/src/gdb/d-exp.y:939:8: note: a different type is defined in \
another translation unit
struct token
^
...
Fix this by renaming to c_token and d_token.
Likewise in:
- fortran-exp.y, renaming to f_token,
- go-exp.y, renaming to go_token, and
- p-exp.y, renaming to p_token.
Tested on x86_64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR build/22395
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
When build gdb with -O2 -flto I run into:
...
gdb/c-exp.y:3003:8: warning: type 'struct token_and_value' violates the C++ \
One Definition Rule [-Wodr]
struct token_and_value
^
gdb/d-exp.y:1310:8: note: a different type is defined in another translation \
unit
struct token_and_value
^
...
Fix this by renaming to c_token_and_value and d_token_and_value.
Likewise in gdb/go-exp.y, renaming to go_token_and_value.
Tested on x86_64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR build/22395
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
I noticed a weird comment in one of the .y files, and then ended up
removing some unnecessary #includes from these files.
Tested by rebuilding.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is the result of running the gdb/copyright.py script,
which automated the update of the copyright year range for all
source files managed by the GDB project to be updated to include
year 2023.
Make sure we error out on overflow instead of truncating in all cases.
The current implementation of parse_number contains a comment about PR16377,
but that's related to C-like languages. In absence of information of whether
the same fix is needed for go, take the conservative approach and keep
behaviour for decimals unchanged.
Tested on x86_64-linux, with a build with --enable-targets=all.
This commit ports these two fixes to the C parser:
commit ebf13736b4
CommitDate: Thu Sep 4 21:46:28 2014 +0100
parse_number("0") reads uninitialized memory
commit 20562150d8
CommitDate: Wed Oct 3 15:19:06 2018 -0600
Avoid undefined behavior in parse_number
... to the Fortran, Go, and Fortran number parsers, fixing the same
problems there.
Also add a new testcase that exercises printing 0xffffffffffffffff
(max 64-bit) in all languages, which crashes a GDB built with UBsan
without the fix.
I moved get_set_option_choices out of all-architectures.exp.tcl to
common code to be able to extract all the supported languages. I did
a tweak to it to generalize it a bit -- you now have to pass down the
"set" part of the command as well. This is so that the proc can be
used with "maintenance set" commands as well in future.
Change-Id: I8e8f2fdc1e8407f63d923c26fd55d98148b9e16a
Add a getter and a setter for a symbol's type. Remove the corresponding
macro and adjust all callers.
Change-Id: Ie1a137744c5bfe1df4d4f9ae5541c5299577c8de
Add a getter and a setter for whether a symbol is an argument. Remove
the corresponding macro and adjust all callers.
Change-Id: I71b4f0465f3dfd2ed8b9e140bd3f7d5eb8d9ee81
This commit brings all the changes made by running gdb/copyright.py
as per GDB's Start of New Year Procedure.
For the avoidance of doubt, all changes in this commits were
performed by the script.
There are some loops in gdb that use ARRAY_SIZE (or a wordier
equivalent) to loop over a static array. This patch changes some of
these to use foreach instead.
Regression tested on x86-64 Fedora 34.
This changes var_msym_value_operation to use a bound_minimal_symbol
rather than separate minsym and objfile parameters. The main benefit
of this is removing the possibly-confusing check_objfile overload for
a plain minimal symbol.
gdb/ChangeLog
2021-03-08 Tom Tromey <tom@tromey.com>
* parse.c (parser_state::push_symbol, parser_state::push_dollar):
Update.
* p-exp.y (variable): Update.
* go-exp.y (variable): Update.
* expprint.c (dump_for_expression): Use bound_minimal_symbol.
Remove overload for objfile.
* expop.h (eval_op_var_msym_value): Use bound_minimal_symbol
parameter.
(check_objfile): Likewise.
(dump_for_expression): Likewise. Remove overload for objfile.
(class var_msym_value_operation): Use bound_minimal_symbol.
* eval.c (eval_op_var_msym_value): Use bound_minimal_symbol
parameter.
(var_msym_value_operation::evaluate_for_address)
(var_msym_value_operation::evaluate_for_sizeof)
(var_msym_value_operation::evaluate_for_cast): Update.
* d-exp.y (PrimaryExpression): Update.
* c-exp.y (variable): Update.
* ax-gdb.c (var_msym_value_operation::do_generate_ax): Update.
* ada-lang.c (ada_var_msym_value_operation::evaluate_for_cast):
Update.
* ada-exp.y (write_var_or_type): Update.
BINOP_END is used only as a "meaningless" value in various tables.
This patch changes these to use OP_NULL instead, and removes
BINOP_END.
gdb/ChangeLog
2021-03-08 Tom Tromey <tom@tromey.com>
* std-operator.def (BINOP_END): Remove.
* p-exp.y (tokentab3, tokentab2): Use OP_NULL, not BINOP_END.
* go-exp.y (tokentab2): Use OP_NULL, not BINOP_END.
* f-exp.y (dot_ops, f77_keywords): Use OP_NULL, not BINOP_END.
* d-exp.y (tokentab2, ident_tokens): Use OP_NULL, not BINOP_END.
* c-exp.y (tokentab3, tokentab2, ident_tokens): Use OP_NULL, not
BINOP_END.
This converts the Go parser to generate operations rather than
exp_elements.
gdb/ChangeLog
2021-03-08 Tom Tromey <tom@tromey.com>
* go-exp.y: Create operations.
(go_language::parser): Update.
This commits the result of running gdb/copyright.py as per our Start
of New Year procedure...
gdb/ChangeLog
Update copyright year range in copyright header of all GDB files.
Move the go_language class into go-lang.h, this allows us to have
member functions implemented directly in the different go-*.c files
instead of having to trampoline out to global functions.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* go-exp.y (go_parse): Rename to...
(go_language::parser): ...this.
* go-lang.c (go_demangle): Rename to...
(go_language::demangle_symbol): ...this.
(go_language::expression_ops): Implementation moved here out of
class declaration.
(go_op_print_tab): Rename to...
(go_language::op_print_tab): ...this, update comment.
(class go_language): Declaration moved to go-lang.h.
(go_language::language_arch_info): Implementation moved here out
of class declaration.
* go-lang.h (go_parse): Delete declaration.
(go_demangle): Delete declaration.
(go_print_type): Delete declaration.
(go_value_print_inner): Delete declaration.
(class go_language): Declaration moved here from go-lang.c.
* go-typeprint.c (go_print_type): Rename to...
(go_language::print_type): ...this.
* go-valprint.c (go_value_print_inner): Rename to...
(go_language::value_print_inner): ...this.
* symtab.c (demangle_for_lookup): Call demangle_symbol method on
the go_language object.
This patch started by adding comprehensive unit tests for enum_flags.
For the testing part, it adds:
- tests of normal expected uses of the API.
- checks that _invalid_ uses of the API would fail to compile. I.e.,
it validates that enum_flags really is a strong type, and that
incorrect mixing of enum types would be caught at compile time. It
pulls that off making use of SFINEA and C++11's decltype/constexpr.
This revealed many holes in the enum_flags API. For example, the f1
assignment below currently incorrectly fails to compile:
enum_flags<flags> f1 = FLAG1;
enum_flags<flags> f2 = FLAG2 | f1;
The unit tests also revealed that this useful use case doesn't work:
enum flag { FLAG1 = 1, FLAG2 = 2 };
enum_flags<flag> src = FLAG1;
enum_flags<flag> f1 = condition ? src : FLAG2;
It fails to compile because enum_flags<flag> and flag are convertible
to each other.
Turns out that making enum_flags be implicitly convertible to the
backing raw enum type was not a good idea.
If we make it convertible to the underlying type instead, we fix that
ternary operator use case, and, we find cases throughout the codebase
that should be using the enum_flags but were using the raw backing
enum instead. So it's a good change overall.
Also, several operators were missing.
These holes and more are plugged by this patch, by reworking how the
enum_flags operators are implemented, and making use of C++11's
feature of being able to delete methods/functions.
There are cases in gdb/compile/ where we need to call a function in a
C plugin API that expects the raw enum. To address cases like that,
this adds a "raw()" method to enum_flags. This way we can keep using
the safer enum_flags to construct the value, and then be explicit when
we need to get at the raw enum.
This makes most of the enum_flags operators constexpr. Beyond
enabling more compiler optimizations and enabling the new unit tests,
this has other advantages, like making it possible to use operator|
with enum_flags values in switch cases, where only compile-time
constants are allowed:
enum_flags<flags> f = FLAG1 | FLAG2;
switch (f)
{
case FLAG1 | FLAG2:
break;
}
Currently that fails to compile.
It also switches to a different mechanism of enabling the global
operators. The current mechanism isn't namespace friendly, the new
one is.
It also switches to C++11-style SFINAE -- instead of wrapping the
return type in a SFINAE-friently structure, we use an unnamed template
parameter. I.e., this:
template <typename enum_type,
typename = is_enum_flags_enum_type_t<enum_type>>
enum_type
operator& (enum_type e1, enum_type e2)
instead of:
template <typename enum_type>
typename enum_flags_type<enum_type>::type
operator& (enum_type e1, enum_type e2)
Note that the static_assert inside operator~() was converted to a
couple overloads (signed vs unsigned), because static_assert is too
late for SFINAE-based tests, which is important for the CHECK_VALID
unit tests.
Tested with gcc {4.8, 7.1, 9.3} and clang {5.0.2, 10.0.0}.
gdb/ChangeLog:
* Makefile.in (SELFTESTS_SRCS): Add
unittests/enum-flags-selftests.c.
* btrace.c (ftrace_update_caller, ftrace_fixup_calle): Use
btrace_function_flags instead of enum btrace_function_flag.
* compile/compile-c-types.c (convert_qualified): Use
enum_flags::raw.
* compile/compile-cplus-symbols.c (convert_one_symbol)
(convert_symbol_bmsym):
* compile/compile-cplus-types.c (compile_cplus_convert_method)
(compile_cplus_convert_struct_or_union_methods)
(compile_cplus_instance::convert_qualified_base):
* go-exp.y (parse_string_or_char): Add cast to int.
* unittests/enum-flags-selftests.c: New file.
* record-btrace.c (btrace_thread_flag_to_str): Change parameter's
type to btrace_thread_flags from btrace_thread_flag.
(record_btrace_cancel_resume, record_btrace_step_thread): Change
local's type to btrace_thread_flags from btrace_thread_flag. Add
cast in DEBUG call.
gdbsupport/ChangeLog:
* enum-flags.h: Include "traits.h".
(DEF_ENUM_FLAGS_TYPE): Declare a function instead of defining a
structure.
(enum_underlying_type): Update comment.
(namespace enum_flags_detail): New. Move struct zero_type here.
(EnumIsUnsigned, EnumIsSigned): New.
(class enum_flags): Make most methods constexpr.
(operator&=, operator|=, operator^=): Take an enum_flags instead
of an enum_type. Make rvalue ref versions deleted.
(operator enum_type()): Delete.
(operator&, operator|, operator^, operator~): Delete, moved out of
class.
(raw()): New method.
(is_enum_flags_enum_type_t): Declare.
(ENUM_FLAGS_GEN_BINOP, ENUM_FLAGS_GEN_COMPOUND_ASSIGN)
(ENUM_FLAGS_GEN_COMP): New. Use them to reimplement global
operators.
(operator~): Now constexpr and reimplemented.
(operator<<, operator>>): New deleted functions.
* valid-expr.h (CHECK_VALID_EXPR_5, CHECK_VALID_EXPR_6): New.
Remove TYPE_CODE, changing all the call sites to use type::code
directly. This is quite a big diff, but this was mostly done using sed
and coccinelle. A few call sites were done by hand.
gdb/ChangeLog:
* gdbtypes.h (TYPE_CODE): Remove. Change all call sites to use
type::code instead.
This removes the "paren_depth" global. In most cases, it is made into
a static global in a given parser. I consider this a slight
improvement, because it makes it clear that the variable isn't used
for communication between different modules of gdb. The one exception
is the Rust parser, which already incorporates all local state into a
transient object; in this case the parser depth is now a member.
gdb/ChangeLog
2019-04-04 Tom Tromey <tom@tromey.com>
* rust-exp.y (struct rust_parser) <paren_depth>: New member.
(rustyylex, rust_lex_test_init, rust_lex_test_one)
(rust_lex_test_sequence, rust_lex_test_push_back): Update.
* parser-defs.h (paren_depth): Don't declare.
* parse.c (paren_depth): Remove global.
(parse_exp_in_context): Update.
* p-exp.y (paren_depth): New global.
(pascal_parse): Initialize it.
* m2-exp.y (paren_depth): New global.
(m2_parse): Initialize it.
* go-exp.y (paren_depth): New global.
(go_parse): Initialize it.
* f-exp.y (paren_depth): New global.
(f_parse): Initialize it.
* d-exp.y (paren_depth): New global.
(d_parse): Initialize it.
* c-exp.y (paren_depth): New global.
(c_parse): Initialize it.
* ada-lex.l (paren_depth): New global.
(lexer_init): Initialize it.
This changes parse_language into a method of parser_state. This patch
was written by a script.
gdb/ChangeLog
2019-04-04 Tom Tromey <tom@tromey.com>
* rust-exp.y: Replace "parse_language" with method call.
* p-exp.y:
(yylex): Replace "parse_language" with method call.
* m2-exp.y:
(yylex): Replace "parse_language" with method call.
* go-exp.y (classify_name): Replace "parse_language" with method
call.
* f-exp.y (yylex): Replace "parse_language" with method call.
* d-exp.y (lex_one_token): Replace "parse_language" with method
call.
* c-exp.y:
(lex_one_token, classify_name, yylex): Replace "parse_language"
with method call.
* ada-exp.y (find_primitive_type, type_char)
(type_system_address): Replace "parse_language" with method call.
This commit applies all changes made after running the gdb/copyright.py
script.
Note that one file was flagged by the script, due to an invalid
copyright header
(gdb/unittests/basic_string_view/element_access/char/empty.cc).
As the file was copied from GCC's libstdc++-v3 testsuite, this commit
leaves this file untouched for the time being; a patch to fix the header
was sent to gcc-patches first.
gdb/ChangeLog:
Update copyright year range in all GDB files.
This changes some uses of VEC in a few parsers to std::vector instead.
Tested by the buildbot.
gdb/ChangeLog
2018-08-28 Tom Tromey <tom@tromey.com>
* c-exp.y (struct token_and_value): Remove typedef and DEF_VEC.
(token_fifo): Now a std::vector.
(yylex, c_parse): Update.
* d-exp.y (struct token_and_value): Remove typedef and DEF_VEC.
(token_fifo): Now a std::vector.
(yylex, d_parse): Update.
* go-exp.y (struct token_and_value): Remove typedef and DEF_VEC.
(token_fifo): Now a std::vector.
(yylex, go_parse): Update.
While working on the parser code, I noticed that yyerror is exported
from each parser. It is used by this code in parse.c:
TRY
{
if (lang->la_parser (&ps))
lang->la_error (NULL);
}
However, it seems to me that la_error will never be called here,
because in every case, la_parser throws an exception on error -- each
implementation of yyerror just calls error.
So, this patch removes la_error and makes all the yyerror functions
static. This is handy primarily because it makes it simpler to make
the expression parsers pure.
Tested by the buildbot.
gdb/ChangeLog
2018-06-18 Tom Tromey <tom@tromey.com>
* rust-lang.h (rust_yyerror): Don't declare.
* rust-lang.c (rust_language_defn): Update.
* rust-exp.y (yyerror): Now static.
* parse.c (parse_exp_in_context_1): Update.
* p-lang.h (p_yyerror): Don't declare.
* p-lang.c (p_language_defn): Update.
* p-exp.y (yyerror): Now static.
* opencl-lang.c (opencl_language_defn): Update.
* objc-lang.c (objc_language_defn): Update.
* m2-lang.h (m2_yyerror): Don't declare.
* m2-lang.c (m2_language_defn): Update.
* m2-exp.y (yyerror): Now static.
* language.h (struct language_defn) <la_error>: Remove.
* language.c (unk_lang_error): Remove.
(unknown_language_defn, auto_language_defn): Remove.
* go-lang.h (go_yyerror): Don't declare.
* go-lang.c (go_language_defn): Update.
* go-exp.y (yyerror): Now static.
* f-lang.h (f_yyerror): Don't declare.
* f-lang.c (f_language_defn): Update.
* f-exp.y (yyerror): Now static.
* d-lang.h (d_yyerror): Don't declare.
* d-lang.c (d_language_defn): Update.
* d-exp.y (yyerror): Now static.
* c-lang.h (c_yyerror): Don't declare.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Update.
* c-exp.y (yyerror): Now static.
* ada-lang.h (ada_yyerror): Don't declare.
* ada-lang.c (ada_language_defn): Update.
* ada-exp.y (yyerror): Now static.
This commit is preparation for a later change, at this point there
should be no user visible change.
We currently maintain a global innermost_block which tracks the most
inner block encountered when parsing an expression.
This commit wraps the innermost_block into a new class, and switches all
direct accesses to the variable to use the class API.
gdb/ChangeLog:
* ada-exp.y (write_var_from_sym): Switch to innermost_block API.
* ada-lang.c (resolve_subexp): Likewise.
* breakpoint.c (set_breakpoint_condition) Likewise.
(watch_command_1) Likewise.
* c-exp.y (variable): Likewise.
* d-exp.y (PrimaryExpression): Likewise.
* f-exp.y (variable): Likewise.
* go-exp.y (variable): Likewise.
* m2-exp.y (variable): Likewise.
* objfiles.c (objfile::~objfile): Likewise.
* p-exp.y (variable): Likewise.
* parse.c (innermost_block): Change type.
* parser-defs.h (class innermost_block_tracker): New.
(innermost_block): Change to innermost_block_tracker.
* printcmd.c (display_command): Switch to innermost_block API.
(do_one_display): Likewise.
* rust-exp.y (do_one_display): Likewise.
* symfile.c (clear_symtab_users): Likewise.
* varobj.c (varobj_create): Switch to innermost_block API, replace
use of innermost_block with block stored on varobj object.