Commit Graph

360 Commits

Author SHA1 Message Date
Simon Marchi
5b9707eb87 gdb: remove gdbcmd.h
Most files including gdbcmd.h currently rely on it to access things
actually declared in cli/cli-cmds.h (setlist, showlist, etc).  To make
things easy, replace all includes of gdbcmd.h with includes of
cli/cli-cmds.h.  This might lead to some unused includes of
cli/cli-cmds.h, but it's harmless, and much faster than going through
the 170 or so files by hand.

Change-Id: I11f884d4d616c12c05f395c98bbc2892950fb00f
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-25 12:59:02 -04:00
Simon Marchi
18d2988e5d gdb, gdbserver, gdbsupport: remove includes of early headers
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>
2024-03-26 21:13:22 -04:00
Tom Tromey
ccf41c2487 Use domain_search_flags in lookup_symbol et al
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.
2024-01-28 10:58:16 -07:00
Andrew Burgess
1d506c26d9 Update copyright year range in header of all files managed by GDB
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.
2024-01-12 15:49:57 +00:00
Andrew Burgess
b7a5722ebd gdb: improve error reporting from expression parser
This commits changes how errors are reported from the expression
parser.  Previously, parser errors were reported like this:

  (gdb) p a1 +}= 432
  A syntax error in expression, near `}= 432'.
  (gdb) p a1 +
  A syntax error in expression, near `'.

The first case is fine, a user can figure out what's going wrong, but
the second case is a little confusing; as the error occurred at the
end of the expression GDB just reports the empty string to the user.

After this commit the first case is unchanged, but the second case now
reports like this:

  (gdb) p a1 +
  A syntax error in expression, near the end of `a1 +'.

Which I think is clearer.  There is a possible issue if the expression
being parsed is very long, GDB will repeat the whole expression.  But
this issue already exists in the standard case; if the error occurs
early in a long expression GDB will repeat everything after the syntax
error.  So I've not worried about this case in my new code either,
which keeps things simpler.

I did consider trying to have multi-line errors here, in the style
that gcc produces, with some kind of '~~~~~^' marker on the second
line to indicate where the error occurred; but I rejected this due to
the places in GDB where we catch an error and repackage the message
within some longer string, I don't think multi-line error messages
would work well in that case.  At a minimum it would require some
significant work in order to make all our error handling multi-line
aware.

I've added a couple of extra tests in gdb.base/exprs.exp.

Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-01-04 09:24:18 +00:00
Andrew Burgess
e89496f42a gdb: merge error handling from different expression parsers
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>
2024-01-04 09:24:18 +00:00
Lancelot Six
6b09f1342c gdb: Replace gdb::optional with std::optional
Since GDB now requires C++17, we don't need the internally maintained
gdb::optional implementation.  This patch does the following replacing:
  - gdb::optional -> std::optional
  - gdb::in_place -> std::in_place
  - #include "gdbsupport/gdb_optional.h" -> #include <optional>

This change has mostly been done automatically.  One exception is
gdbsupport/thread-pool.* which did not use the gdb:: prefix as it
already lives in the gdb namespace.

Change-Id: I19a92fa03e89637bab136c72e34fd351524f65e9
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21 11:52:35 +00:00
Tom Tromey
ef0f16ccf8 Remove explanatory comments from includes
I noticed a comment by an include and remembered that I think these
don't really provide much value -- sometimes they are just editorial,
and sometimes they are obsolete.  I think it's better to just remove
them.  Tested by rebuilding.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-20 11:45:16 -06:00
Tom Tromey
87b647cfb1 Add PARSER_LEAVE_BLOCK_ALONE flag
This adds a PARSER_LEAVE_BLOCK_ALONE flag, and changes the parse API
to respect it.  This flag lets callers avoid any change to the
passed-in block and expression PC, letting them specify the context
exactly.  In particular, now nullptr can be used to indicate that the
parse should not examine any local variables.
2023-05-23 13:57:54 -06:00
Tom Tromey
e360af5af8 Add PARSER_DEBUG flag
This adds a new PARSER_DEBUG constant and changes the parser code to
use it.  This lets us make the 'parser_debug' global 'static'.
2023-05-23 13:57:54 -06:00
Tom Tromey
b5688cda0e Simplify parser_state constructor
This simplifies the parser_state constructor by having it accept a
parser_flags parameter.
2023-05-23 13:57:54 -06:00
Tom Tromey
b8c03634d6 Introduce and use parser flags
This patch adds a new parser_flags type and changes the parser APIs to
use it rather than a collection of 'int' and 'bool'.  More flags will
be added in subsquent patches.
2023-05-23 13:57:54 -06:00
Tom Tromey
98d630e910 Avoid forward declaration in parse.c
This minorly rearranges parse.c to avoid the need for a forward
declaration.
2023-05-23 13:57:53 -06:00
Tom Tromey
005b65e801 Move find_minimal_symbol_address to minsyms.c
I found find_minimal_symbol_address in parse.c, but it seems to me
that it belongs in minsyms.c.

Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-04-28 11:16:59 -06:00
Tom Tromey
fc53c8e021 Remove some "goto"s from parse.c
parser_state::push_dollar has some unnecessary "goto"s.  Replacing
them cleans up the code.  Regression tested on x86-64 Fedora 36.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-04-25 11:54:28 -06:00
Tom Tromey
64f33c6938 Add overload of fits_in_type
This adds an overload of fits_in_type that accepts a gdb_mpz.  A
subsequent patch will use this.
2023-04-17 10:43:06 -06:00
Tom Tromey
93d50cd8f0 Rename "raw" to "unrelocated"
Per an earlier discussion, this patch renames the existing "raw" APIs
to use the word "unrelocated" instead.
2023-03-28 15:12:44 -06:00
Tom Tromey
9675da2535 Use unrelocated_addr in minimal symbols
This changes minimal symbols to use unrelocated_addr.  I believe this
detected a latent bug in add_pe_forwarded_sym.
2023-03-28 15:12:44 -06:00
Tom Tromey
a8ed3dde83 Rename objfile_type to builtin_type
This renames objfile_type to be an overload of builtin_type, in
preparation for their unification.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Kevin Buettner
b1ffd1124a Catch gdb_exception_error instead of gdb_exception (in many places)
As described in the previous commit for this series, I became
concerned that there might be instances in which a QUIT (due to either
a SIGINT or SIGTERM) might not cause execution to return to the top
level.  In some (though very few) instances, it is okay to not
propagate the exception for a Ctrl-C / SIGINT, but I don't think that
it is ever okay to swallow the exception caused by a SIGTERM.
Allowing that to happen would definitely be a deviation from the
current behavior in which GDB exits upon receipt of a SIGTERM.

I looked at all cases where an exception handler catches a
gdb_exception.  Handlers which did NOT need modification were those
which satisifed one or more of the following conditions:

  1) There is no call path to maybe_quit() in the try block.  I used a
     static analysis tool to help make this determination.  In
     instances where the tool didn't provide an answer of "yes, this
     call path can result in maybe_quit() being called", I reviewed it
     by hand.

  2) The catch block contains a throw for conditions that it
     doesn't want to handle; these "not handled" conditions
     must include the quit exception and the new "forced quit" exception.

  3) There was (also) a catch for gdb_exception_quit.

Any try/catch blocks not meeting the above conditions could
potentially swallow a QUIT exception.

My first thought was to add catch blocks for gdb_exception_quit and
then rethrow the exception.  But Pedro pointed out that this can be
handled without adding additional code by simply catching
gdb_exception_error instead.  That's what this patch series does.

There are some oddball cases which needed to be handled differently,
plus the extension languages, but those are handled in later patches.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761
Tested-by: Tom de Vries <tdevries@suse.de>
Approved-by: Pedro Alves <pedro@palves.net>
2023-02-27 16:20:39 -07:00
Tom Tromey
0d1912950e Convert contained_in to method
This converts contained_in to be a method of block.
2023-02-19 12:51:06 -07:00
Tom Tromey
3c9d050626 Convert block_linkage_function to method
This converts block_linkage_function to be a method.  This was mostly
written by script.
2023-02-19 12:51:05 -07:00
Tom Tromey
aa9bd44528 Convert exp_uses_objfile to a method of expression
This changes the exp_uses_objfile function to be a method of
'expression'.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
2023-01-04 09:46:58 -07:00
Joel Brobecker
213516ef31 Update copyright year range in header of all files managed by GDB
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.
2023-01-01 17:01:16 +04:00
Tom Tromey
1970731043 Remove dump_prefix_expression
Since the expression rewrite, dump_prefix_expression has been
misnamed.  This patch cleans this up by removing the function, turning
it into a method on struct expression.
2022-11-14 10:19:08 -07:00
Tom de Vries
1d8c0dfae7 [gdb/c] Fix type of 2147483648 and literal truncation
[ Assuming arch i386:x86-64, sizeof (int) == 4,
sizeof (long) == sizeof (long long) == 8. ]

Currently we have (decimal for 0x80000000):
...
(gdb) ptype 2147483648
type = unsigned int
...

According to C language rules, unsigned types cannot be used for decimal
constants, so the type should be long instead (reported in PR16377).

Fix this by making sure the type of 2147483648 is long.

The next interesting case is (decimal for 0x8000000000000000):
...
(gdb) ptype 9223372036854775808
type = unsigned long
...

According to the same rules, unsigned long is incorrect.

Current gcc uses __int128 as type, which is allowed, but we don't have that
available in gdb, so the strict response here would be erroring out with
overflow.

Older gcc without __int128 support, as well as clang use an unsigned type, but with
a warning.  Interestingly, clang uses "unsigned long long" while gcc uses
"unsigned long", which seems the better choice.

Given that the compilers allow this as a convience, do the same in gdb
and keep type "unsigned long", and make this explicit in parser and test-case.

Furthermore, make sure we error out on overflow instead of truncating in all
cases.

Tested on x86_64-linux with --enable-targets=all.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16377
2022-06-04 13:17:33 +02:00
Simon Marchi
63d609debb gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macros
Replace with calls to blockvector::blocks, and the appropriate method
call on the returned array_view.

Change-Id: I04d1f39603e4d4c21c96822421431d9a029d8ddd
2022-04-27 22:05:03 -04:00
Simon Marchi
6395b62847 gdb: remove BLOCK_ENTRY_PC macro
Replace with equivalent method.

Change-Id: I0e033095e7358799930775e61028b48246971a7d
2022-04-27 22:05:03 -04:00
Simon Marchi
60f62e2b83 gdb: remove MSYMBOL_TYPE macro
Add a getter and a setter for a minimal symbol's type.  Remove the
corresponding macro and adjust all callers.

Change-Id: I89900df5ffa5687133fe1a16b2e0d4684e67a77d
2022-04-11 10:46:07 -04:00
Simon Marchi
4aeddc50d7 gdb: remove symbol value macros
Remove all macros related to getting and setting some symbol value:

    #define SYMBOL_VALUE(symbol)           (symbol)->value.ivalue
    #define SYMBOL_VALUE_ADDRESS(symbol)                         \
    #define SET_SYMBOL_VALUE_ADDRESS(symbol, new_value)    \
    #define SYMBOL_VALUE_BYTES(symbol)     (symbol)->value.bytes
    #define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->value.common_block
    #define SYMBOL_BLOCK_VALUE(symbol)     (symbol)->value.block
    #define SYMBOL_VALUE_CHAIN(symbol)     (symbol)->value.chain
    #define MSYMBOL_VALUE(symbol)          (symbol)->value.ivalue
    #define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->value.address + 0)
    #define MSYMBOL_VALUE_ADDRESS(objfile, symbol)                         \
    #define BMSYMBOL_VALUE_ADDRESS(symbol) \
    #define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value)   \
    #define MSYMBOL_VALUE_BYTES(symbol)    (symbol)->value.bytes
    #define MSYMBOL_BLOCK_VALUE(symbol)    (symbol)->value.block

Replace them with equivalent methods on the appropriate objects.

Change-Id: Iafdab3b8eefc6dc2fd895aa955bf64fafc59ed50
2022-04-11 10:45:36 -04:00
Simon Marchi
44281e6c08 gdb: remove symtab::blockvector
symtab::blockvector is a wrapper around compunit_symtab::blockvector.
It is a bit misleadnig, as it gives the impression that a symtab has a
blockvector.  Remove it, change all users to fetch the blockvector
through the compunit instead.

Change-Id: Ibd062cd7926112a60d52899dff9224591cbdeebf
2022-04-07 13:04:53 -04:00
Tom Tromey
1e237aba22 Refactor expression completion
This refactors the gdb expression completion code to make it easier to
add more types of completers.

In the old approach, just two kinds of completers were supported:
field names for some sub-expression, or tag names (like "enum
something").  The data for each kind was combined in single structure,
"expr_completion_state", and handled explicitly by
complete_expression.

In the new approach, the parser state just holds an object that is
responsible for implementing completion.  This way, new completion
types can be added by subclassing this base object.

The structop completer is moved into structop_base_operation, and new
objects are defined for use by the completion code.  This moves much
of the logic of expression completion out of completer.c as well.
2022-04-04 12:46:09 -06:00
Tom Tromey
6cb06a8cda Unify gdb printf functions
Now that filtered and unfiltered output can be treated identically, we
can unify the printf family of functions.  This is done under the name
"gdb_printf".  Most of this patch was written by script.
2022-03-29 12:46:24 -06:00
Tom Tromey
19a7b8ab87 Unify vprintf functions
Now that filtered and unfiltered output can be treated identically, we
can unify the vprintf family of functions: vprintf_filtered,
vprintf_unfiltered, vfprintf_filtered and vfprintf_unfiltered.  (For
the gdb_stdout variants, recall that only printf_unfiltered gets truly
unfiltered output at this point.)  This removes one such function and
renames the remaining two to "gdb_vprintf".  All callers are updated.
Much of this patch was written by script.
2022-03-29 12:46:24 -06:00
Simon Marchi
012cfab919 gdb: remove SYMTAB_BLOCKVECTOR macro
Remove the macro, replace with an equivalent method.

Change-Id: Id6fe2a79c04bcd6c69ccaefb7a69bc06a476288c
2022-02-06 16:03:46 -05:00
Joel Brobecker
4a94e36819 Automatic Copyright Year update after running gdb/copyright.py
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.
2022-01-01 19:13:23 +04:00
Tom Tromey
be77dd73c7 Introduce make_unique_xstrndup
This adds a new make_unique_xstrndup function, which is the "n"
analogue of make_unique_xstrdup.  It also updates a couple existing
places to use this function.
2021-11-05 13:58:48 -06:00
Tom Tromey
9e5e03df52 Use block_symbol in var_value_operation
I noticed that var_value_operation takes a block and a symbol, and
most callers destructure a block_symbol to pass in.  It seems better
for this class to simply hold a block_symbol instead.

Tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-04-15  Tom Tromey  <tromey@adacore.com>

	* rust-exp.y (rust_parser::convert_ast_to_expression): Update.
	* parse.c (parser_state::push_symbol, parser_state::push_dollar):
	Update.
	* p-exp.y (variable): Update.
	* m2-exp.y (variable): Update.
	* go-exp.y (variable): Update.
	* expprint.c (dump_for_expression): New overload.
	* expop.h (check_objfile): New overload.
	(check_constant): New overload.
	(class var_value_operation): Use block_symbol.
	<get_symbol>: Rewrite.
	* eval.c (var_value_operation::evaluate)
	(var_value_operation::evaluate_funcall)
	(var_value_operation::evaluate_for_address)
	(var_value_operation::evaluate_for_address)
	(var_value_operation::evaluate_with_coercion)
	(var_value_operation::evaluate_for_sizeof)
	(var_value_operation::evaluate_for_cast): Update.
	* d-exp.y (PrimaryExpression): Update.
	* c-exp.y (variable): Update.
	* ax-gdb.c (var_value_operation::do_generate_ax): Update.
	* ada-lang.c (ada_var_value_operation::evaluate_for_cast)
	(ada_var_value_operation::evaluate)
	(ada_var_value_operation::resolve)
	(ada_funcall_operation::resolve): Update.
	* ada-exp.y (write_var_from_sym, write_object_renaming)
	(write_ambiguous_var, write_var_or_type, write_name_assoc)
	(maybe_overload): Update.
	* ada-exp.h (class ada_var_value_operation) <get_block>: Rewrite.
2021-04-15 10:05:00 -06:00
Tom Tromey
9c79936b3d Use bound_minimal_symbol in var_msym_value_operation
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.
2021-03-08 07:28:44 -07:00
Tom Tromey
40d07d07d0 Change exp_uses_objfile to return bool
This change exp_uses_objfile to return bool.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* parser-defs.h (exp_uses_objfile): Return bool.
	* parse.c (exp_uses_objfile): Return bool.
2021-03-08 07:28:44 -07:00
Tom Tromey
ce284361a2 Inline expr_builder methods
This inlines the expr_builder constructor and release method.  These
are straightforward, so this seemed simpler.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* parser-defs.h (struct expr_builder) <expr_builder>: Inline.
	<release>: Inline.
	* parse.c (expr_builder::expr_builder, expr_builder::release):
	Remove.
2021-03-08 07:28:43 -07:00
Tom Tromey
b9d06571f9 Inline expression constructor
The struct expression constructor no longer does any real work, so
this inlines it.  The default destructor can also be used now as well.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* parse.c (expression::expression, expression::~expression):
	Remove.
	* expression.h (struct expression): Inline constructor.  Remove
	destructor.
2021-03-08 07:28:43 -07:00
Tom Tromey
1eaebe02cf Remove union exp_element
This removes union exp_element functions that either create such
elements or walk them.  struct expression no longer holds
exp_elements.  A couple of language_defn methods are also removed, as
they are obsolete.

Note that this patch also removes the print_expression code.  The only
in-tree caller of this was from dump_prefix_expression, which is only
called when expression debugging is enabled.  Implementing this would
involve a fair amount of code, and it seems to me that prefix dumping
is preferable anyway, as it is unambiguous.  So, I have not
reimplemented this feature.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* value.h (evaluate_subexp_with_coercion): Don't declare.
	* parse.c (exp_descriptor_standard): Remove.
	(expr_builder::expr_builder, expr_builder::release): Update.
	(expression::expression): Remove size_t parameter.
	(expression::~expression): Simplify.
	(expression::resize): Remove.
	(write_exp_elt, write_exp_elt_opcode, write_exp_elt_sym)
	(write_exp_elt_msym, write_exp_elt_block, write_exp_elt_objfile)
	(write_exp_elt_longcst, write_exp_elt_floatcst)
	(write_exp_elt_type, write_exp_elt_intern, write_exp_string)
	(write_exp_string_vector, write_exp_bitstring): Remove.
	* p-lang.h (class pascal_language) <opcode_print_table,
	op_print_tab>: Remove.
	* p-lang.c (pascal_language::op_print_tab): Remove.
	* opencl-lang.c (class opencl_language) <opcode_print_table>:
	Remove.
	* objc-lang.c (objc_op_print_tab): Remove.
	(class objc_language) <opcode_print_table>: Remove.
	* m2-lang.h (class m2_language) <opcode_print_table,
	op_print_tab>: Remove.
	* m2-lang.c (m2_language::op_print_tab): Remove.
	* language.h (struct language_defn) <post_parser, expression_ops,
	opcode_print_table>: Remove.
	* language.c (language_defn::expression_ops)
	(auto_or_unknown_language::opcode_print_table): Remove.
	* go-lang.h (class go_language) <opcode_print_table,
	op_print_tab>: Remove.
	* go-lang.c (go_language::op_print_tab): Remove.
	* f-lang.h (class f_language) <opcode_print_table>: Remove
	<op_print_tab>: Remove.
	* f-lang.c (f_language::op_print_tab): Remove.
	* expression.h (union exp_element): Remove.
	(struct expression): Remove size_t parameter from constructor.
	<resize>: Remove.
	<first_opcode>: Update.
	<nelts, elts>: Remove.
	(EXP_ELEM_TO_BYTES, BYTES_TO_EXP_ELEM): Remove.
	(evaluate_subexp_standard, print_expression, op_string)
	(dump_raw_expression): Don't declare.
	* expprint.c (print_expression, print_subexp)
	(print_subexp_funcall, print_subexp_standard, op_string)
	(dump_raw_expression, dump_subexp, dump_subexp_body)
	(dump_subexp_body_funcall, dump_subexp_body_standard): Remove.
	(dump_prefix_expression): Update.
	* eval.c (evaluate_subexp): Remove.
	(evaluate_expression, evaluate_type): Update.
	(evaluate_subexpression_type): Remove.
	(fetch_subexp_value): Remove "pc" parameter.  Update.
	(extract_field_op, evaluate_struct_tuple, evaluate_funcall)
	(evaluate_subexp_standard, evaluate_subexp_for_address)
	(evaluate_subexp_with_coercion, evaluate_subexp_for_sizeof)
	(evaluate_subexp_for_cast): Remove.
	(parse_and_eval_type): Update.
	* dtrace-probe.c (dtrace_probe::compile_to_ax): Update.
	* d-lang.c (d_op_print_tab): Remove.
	(class d_language) <opcode_print_table>: Remove.
	* c-lang.h (c_op_print_tab): Don't declare.
	* c-lang.c (c_op_print_tab): Remove.
	(class c_language, class cplus_language, class asm_language, class
	minimal_language) <opcode_print_table>: Remove.
	* breakpoint.c (update_watchpoint, watchpoint_check)
	(watchpoint_exp_is_const, watch_command_1): Update.
	* ax-gdb.h (union exp_element): Don't declare.
	* ax-gdb.c (const_var_ref, const_expr, maybe_const_expr)
	(gen_repeat, gen_sizeof, gen_expr_for_cast, gen_expr)
	(gen_expr_binop_rest): Remove.
	(gen_trace_for_expr, gen_eval_for_expr, gen_printf): Update.
	* ada-lang.c (ada_op_print_tab): Remove.
	(class ada_language) <post_parser, opcode_print_table>: Remove.
2021-03-08 07:28:41 -07:00
Tom Tromey
8227d9e2f4 Add operation-related methods to parser_state
This adds several operation-related methods to parser_state.  These
methods make it more convenient to change the parsers to be
operation-based.

Because byacc has poor support for C++, a stack of operations is added
to parser_state.  A parser can push operations, then later pop them
for combination into new operations.  This approach avoids the memory
leaks that would result if raw pointers were used in the parsers, at
the cost of parser productions not being type-safe (they can't
indicate that they return an operation).

This also introduces analogs of some write_exp functions, like
write_exp_string_vector, write_dollar_variable, and
write_exp_symbol_reference.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* parser-defs.h (struct parser_state) <push, push_new,
	push_c_string, push_symbol, push_dollar, pop, pop_vector, wrap,
	wrap2>: New methods.
	<m_operations>: New member.
	* parse.c (parser_state::push_c_string)
	(parser_state::push_symbol, parser_state::push_dollar): New
	methods.
2021-03-08 07:28:37 -07:00
Tom Tromey
4933522da0 Add completion for operations
This patch adds the necessary support for field name completion for
expressions using class operation.

This patch takes an approach similar to what is done today.  It might
be good, in the future, to change completion to be a method on the
base class, to enable context-sensitive completion in more areas.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* parser-defs.h (struct expr_completion_state) <expout_last_op>:
	New member.
	(struct parser_state) <mark_struct_expression>: New method.
	* parse.c (parser_state::mark_struct_expression): Update assert.
	(parser_state::mark_struct_expression): New method.
	(parser_state::mark_completion_tag): Update assert.
	(parse_expression_for_completion): Handle expout_last_op.
2021-03-08 07:28:37 -07:00
Tom Tromey
413403fc34 Add an expr::operation_up to struct expression
This adds an expr::operation_up to struct expression, and then
modifies various parts of GDB to use this member when it is non-null.
The list of such spots was a bit surprising to me, and found only
after writing most of the code and then noticing what no longer
compiled.

In a few spots, new accessor methods are added to operation
subclasses, so that code that dissects an expression will work with
the new scheme.

After this change, code that constructs an expression can be switched
to the new form without breaking.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* ada-exp.h (class ada_var_value_operation) <get_symbol>: Remove;
	now in superclass.
	* value.h (fetch_subexp_value): Add "op" parameter.
	* value.c (init_if_undefined_command): Update.
	* tracepoint.c (validate_actionline, encode_actions_1): Update.
	* stap-probe.c (stap_probe::compile_to_ax): Update.
	* printcmd.c (set_command): Update.
	* ppc-linux-nat.c (ppc_linux_nat_target::check_condition):
	Update.
	* parser-defs.h (struct expr_builder) <set_operation>: New
	method.
	* parse.c (parse_exp_in_context, exp_uses_objfile): Update.
	* expression.h (struct expression) <first_opcode>: Update.
	<op>: New member.
	* expprint.c (dump_raw_expression, dump_prefix_expression):
	Update.
	* expop.h (class var_value_operation) <get_symbol>: New method.
	(class register_operation) <get_name>: New method.
	(class equal_operation): No longer a typedef, now a subclass.
	(class unop_memval_operation) <get_type>: New method.
	(class assign_operation) <get_lhs>: New method.
	(class unop_cast_operation) <get_type>: New method.
	* eval.c (evaluate_expression, evaluate_type)
	(evaluate_subexpression_type): Update.
	(fetch_subexp_value): Add "op" parameter.
	(parse_and_eval_type): Update.
	* dtrace-probe.c (dtrace_probe::compile_to_ax): Update.
	* breakpoint.c (update_watchpoint, watchpoint_check)
	(watchpoint_exp_is_const, watch_command_1): Update.
	* ax-gdb.c (gen_trace_for_expr, gen_eval_for_expr, gen_printf):
	Update.
2021-03-08 07:28:37 -07:00
Tom Tromey
b260f8d60c Fix two Fortran regressions
Luis pointed out that an earlier patch of mine caused two regressions
in gdb.fortran.  This patch fixes the problem.

Regression tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-02-11  Tom Tromey  <tromey@adacore.com>

	PR gdb/27383:
	* parse.c (write_exp_symbol_reference): Write sym.block.
2021-02-11 08:32:50 -07:00
Andrew Burgess
ebbc3a7d56 gdb: Delete SYMBOL_OBJ_SECTION and MSYMBOL_OBJ_SECTION
Replace the two macros SYMBOL_OBJ_SECTION and MSYMBOL_OBJ_SECTION with
a member function on general_symbol_info.

There should be no user visible change after this commit.

gdb/ChangeLog:

	* breakpoint.c (resolve_sal_pc): Replace SYMBOL_OBJ_SECTION and
	MSYMBOL_OBJ_SECTION.
	* findvar.c (language_defn::read_var_value): Likewise.
	* infcmd.c (jump_command): Likewise.
	* linespec.c (minsym_found): Likewise.
	* maint.c (maintenance_translate_address): Likewise.
	* minsyms.c (lookup_minimal_symbol_by_pc_section): Likewise.
	(minimal_symbol_upper_bound): Likewise.
	* parse.c (find_minsym_type_and_address): Likewise.
	(operator_check_standard): Likewise.
	* printcmd.c (info_address_command): Likewise.
	* symmisc.c (dump_msymbols): Likewise.
	(print_symbol): Likewise.
	* symtab.c (general_symbol_info::obj_section): Define new
	function.
	(fixup_symbol_section): Replace SYMBOL_OBJ_SECTION.
	(find_pc_sect_compunit_symtab): Likewise.
	(find_function_start_sal): Likewise.
	(skip_prologue_sal): Replace SYMBOL_OBJ_SECTION and
	MSYMBOL_OBJ_SECTION.
	* symtab.h (struct general_symbol_info) <obj_section>: Declare new
	function.
	(SYMBOL_OBJ_SECTION): Delete.
	(MSYMBOL_OBJ_SECTION): Delete.
2021-02-10 14:38:08 +00:00
Tom Tromey
1b30f42106 Extract symbol-writing function from parsers
I noticed that several parsers shared the same code to write a symbol
reference to an expression.  This patch factors this code out into a
new function.

Regression tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-02-05  Tom Tromey  <tom@tromey.com>

	* parser-defs.h (write_exp_symbol_reference): Declare.
	* parse.c (write_exp_symbol_reference): New function.
	* p-exp.y (variable): Use write_exp_symbol_reference.
	* m2-exp.y (variable): Use write_exp_symbol_reference.
	* f-exp.y (variable): Use write_exp_symbol_reference.
	* d-exp.y (PrimaryExpression): Use write_exp_symbol_reference.
	* c-exp.y (variable): Use write_exp_symbol_reference.
2021-02-05 07:11:01 -07:00
Simon Marchi
6ac373717c gdb: rename type::{arch,objfile} -> type::{arch_owner,objfile_owner}
I think this makes the names of the methods clearer, especially for the
arch.  The type::arch method (which gets the arch owner, or NULL if the
type is not arch owned) is easily confused with the get_type_arch method
(which returns an arch no matter what).  The name "arch_owner" will make
it intuitive that the method returns NULL if the type is not arch-owned.

Also, this frees the type::arch name, so we will be able to morph the
get_type_arch function into the type::arch method.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <arch>: Rename to...
	<arch_owner>: ... this, update all users.
	<objfile>: Rename to...
	<objfile_owner>: ... this, update all users.

Change-Id: Ie7c28684c7b565adec05a7619c418c69429bd8c0
2021-01-28 10:09:02 -05:00