aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-lang.c
AgeCommit message (Collapse)AuthorFilesLines
2024-04-23gdb: move a bunch of quit-related things to event-top.{c,h}Simon Marchi1-0/+1
Move some declarations related to the "quit" machinery from defs.h to event-top.h. Most of the definitions associated to these declarations are in event-top.c. The exceptions are `quit()` and `maybe_quit()`, that are defined in utils.c. For consistency, move these two definitions to event-top.c. Include "event-top.h" in many files that use these things. Change-Id: I6594f6df9047a9a480e7b9934275d186afb14378 Approved-By: Tom Tromey <tom@tromey.com>
2024-04-02Print type name when printing Rust sliceTom Tromey1-0/+11
The recent change to how unsized Rust values are printed included a small regression from past behavior. Previously, a slice's type would be printed, like: (gdb) print slice $80 = &[i32] [3] The patch changed this to just (gdb) print slice $80 = [3] This patch restores the previous behavior. Reviewed-By: Simon Marchi <simon.marchi@efficios.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30330 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31517
2024-03-26gdb, gdbserver, gdbsupport: remove includes of early headersSimon Marchi1-1/+0
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-02-20Rewrite Rust slice type handlingTom Tromey1-65/+174
This patch rewrites the handling of slice types in Rust. More recent versions of the Rust compiler changed how unsized types were emitted, letting gdb inspect them more nicely. However, gdb did not do this, and in fact treated all such types as if they were slices of arrays, which is incorrect. This patch rewrites this handling and removes the restriction that unsized types must be array slices. I've added a comment explaining how unsized types are represented to rust-lang.c as well. I looked into a different approach, namely changing the DWARF reader to fix up slice types to have a dynamic type. However, the approach taken here turned out to be simpler. Tested on x86-64 Fedora 38 with a variety of Rust compiler versions. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30330
2024-01-28Only search for functions in rust_structop::evaluate_funcallTom Tromey1-1/+1
This changes rust_structop::evaluate_funcall to only search for functions.
2024-01-28Use domain_search_flags in lookup_symbol et alTom Tromey1-3/+4
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-12Update copyright year range in header of all files managed by GDBAndrew Burgess1-1/+1
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.
2023-09-05Refactor Rust code for slice-to-array operationTom Tromey1-9/+28
This patch exposes rust_slice_type_p and introduces rust_slice_to_array, in preparation for subsequent patches that will need these.
2023-09-05Move rust_language::lookup_symbol_nonlocalTom Tromey1-0/+37
This moves rust_language::lookup_symbol_nonlocal to rust-lang.c. There's no need to have it in rust-lang.h and moving it lets us avoid adding new includes in a later patch.
2023-08-31gdb: remove TYPE_FIELD_ARTIFICIALSimon Marchi1-3/+3
Replace with type::field + field::is_artificial. Change-Id: Ie3bacae49d9bd02e83e504c1ce01470aba56a081 Approved-By: Tom Tromey <tom@tromey.com>
2023-08-31[gdb/symtab] Factor out type::{alloc_fields,copy_fields}Tom de Vries1-3/+1
After finding this code in buildsym_compunit::finish_block_internal: ... ftype->set_fields ((struct field *) TYPE_ALLOC (ftype, nparams * sizeof (struct field))); ... and fixing PR30810 by using TYPE_ZALLOC, I wondered if there were more locations that needed fixing. I decided to make things easier to spot by factoring out a new function alloc_fields: ... /* Allocate the fields array of this type, with NFIELDS elements. If INIT, zero-initialize the allocated memory. */ void type::alloc_fields (unsigned int nfields, bool init = true); ... where: - a regular use would be "alloc_fields (nfields)", and - an exceptional use that needed no initialization would be "alloc_fields (nfields, false)". Pretty soon I discovered that most of the latter cases are due to initialization by memcpy, so I added two variants of copy_fields as well. After this rewrite there are 8 uses of set_fields left: ... gdb/coffread.c: type->set_fields (nullptr); gdb/coffread.c: type->set_fields (nullptr); gdb/coffread.c: type->set_fields (nullptr); gdb/eval.c: type->set_fields gdb/gdbtypes.c: type->set_fields (args); gdb/gdbtypes.c: t->set_fields (XRESIZEVEC (struct field, t->fields (), gdb/dwarf2/read.c: type->set_fields (new_fields); gdb/dwarf2/read.c: sub_type->set_fields (sub_type->fields () + 1); ... These fall into the following categories: - set to nullptr (coffread.c), - type not owned by objfile or gdbarch (eval.c), and - modifying an existing fields array, like adding an element at the end or dropping an element at the start (the rest). Tested on x86_64-linux.
2023-08-30gdb: simplify vector construction in eval_op_rust_arraySimon Marchi1-8/+1
Replace the manual fill of the vector with the appropriate std::vector constructor that makes N copies of the provided value. Change-Id: I579570748c48f53d35024105269d83c716294746 Approved-By: Tom Tromey <tom@tromey.com>
2023-08-29Remove "highbound" parameter from value_arrayTom Tromey1-1/+1
value_array requires the passed-in bounds to match the length of the array_view it is given. This patch removes the redundant "highbound" parameter. Reviewed-by: John Baldwin <jhb@FreeBSD.org> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-08-29Use gdb::array_view for value_arrayTom Tromey1-1/+1
This changes value_array to accept an array view. I also replaced an alloca with a std::vector in array_operation::evaluate. This function can work on any size of array, so it seems bad to use alloca. Reviewed-by: John Baldwin <jhb@FreeBSD.org> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-08-18Remove most includes of psymtab.hTom Tromey1-1/+0
I found that most spots including psymtab.h do not need it. This patch removes these includes, and also one unnecessary include of psympriv.h.
2023-05-01Replace field_is_static with a methodTom Tromey1-4/+4
This changes field_is_static to be a method on struct field, and updates all the callers. Most of this patch was written by script. Regression tested on x86-64 Fedora 36.
2023-04-17Add 128-bit integer support to the Rust parserTom Tromey1-0/+2
This adds support for 128-bit integers to the Rust parser. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21185
2023-03-18Unify arch_float_type and init_float_typeTom Tromey1-2/+2
This unifies arch_float_type and init_float_type by using a type allocator. Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18Unify arch_boolean_type and init_boolean_typeTom Tromey1-1/+1
This unifies arch_boolean_type and init_boolean_type by using a type allocator. Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18Unify arch_character_type and init_character_typeTom Tromey1-1/+1
This unifies arch_character_type and init_character_type by using a type allocator. Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18Unify arch_integer_type and init_integer_typeTom Tromey1-11/+12
This unifies arch_integer_type and init_integer_type by using a type allocator. Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18Remove alloc_type_copyTom Tromey1-1/+1
This removes alloc_type_copy, replacing all uses with the new type allocator. Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-27Fix crash with "finish" in RustTom Tromey1-1/+1
PR rust/30090 points out that a certain "finish" in a Rust program will cause gdb to crash. This happens due to some confusion about field indices in rust_language::print_enum. The fix is to use value_primitive_field so that the correct type can be passed; other spots in rust-lang.c already do this. Note that the enclosed test case comes with an xfail. This is needed because for this function, rustc doesn't follow the platform ABI. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30090
2023-02-19Convert more block functions to methodsTom Tromey1-1/+1
This converts block_scope, block_set_scope, block_using, and block_set_using to be methods. These are all done at once to make it easier to also convert block_initialize_namespace at the same time. This was mostly written by script.
2023-02-13Remove deprecated_lval_hackTom Tromey1-2/+2
This removes deprecated_lval_hack and the VALUE_LVAL macro, replacing all uses with a call to value::lval. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13Introduce set_lval method on valueTom Tromey1-1/+1
This introduces the set_lval method on value, one step toward removing deprecated_lval_hack. Ultimately I think the goal should be for some of these set_* methods to be replaced with constructors; but I haven't done this, as the series is already too long. Other 'deprecated' methods can probably be handled the same way. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13Turn various value copying-related functions into methodsTom Tromey1-3/+3
This patch turns a grab bag of value functions to methods of value. These are done together because their implementations are interrelated. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13Turn remaining value_contents functions into methodsTom Tromey1-4/+4
This turns the remaining value_contents functions -- value_contents, value_contents_all, value_contents_for_printing, and value_contents_for_printing_const -- into methods of value. It also converts the static functions require_not_optimized_out and require_available to be private methods. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13Turn value_fetch_lazy into a methodTom Tromey1-1/+1
This changes value_fetch_lazy to be a method of value. A few helper functions are converted as well, to avoid problems in later patches when the data members are all made private. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13Turn value_zero into static "constructor"Tom Tromey1-4/+4
This turns value_zero into a static "constructor" of value. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13Turn allocate_value into a static "constructor"Tom Tromey1-2/+2
This changes allocate_value to be a static "constructor" of value. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13Turn allocate_value_lazy into a static "constructor"Tom Tromey1-1/+1
This changes allocate_value_lazy to be a static "constructor" of struct value. I considered trying to change value to use ordinary new/delete, but it seems to me that due to reference counting, we may someday want to change these static constructors to return value_ref_ptr instead. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13Turn value_address and set_value_address functions into methodsTom Tromey1-4/+4
This changes the value_address and set_value_address functions to be methods of value. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-13Turn value_type into methodTom Tromey1-28/+28
This changes value_type to be a method of value. Much of this patch was written by script. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-02-09Trivially simplify rust_language::print_enumTom Tromey1-1/+1
rust_language::print_enum computes: int nfields = variant_type->num_fields (); ... but then does not reuse this in one spot. This patch corrects the oversight.
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker1-1/+1
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.
2022-12-19Use bool constants for value_print_optionsTom Tromey1-3/+3
This changes the uses of value_print_options to use 'true' and 'false' rather than integers.
2022-10-10Remove c_printstrTom Tromey1-2/+3
This renames c_printstr, removing a layer of indirection.
2022-09-21gdb: remove TYPE_LENGTHSimon Marchi1-10/+10
Remove the macro, replace all uses with calls to type::length. Change-Id: Ib9bdc954576860b21190886534c99103d6a47afb
2022-09-21gdb: add type::length / type::set_lengthSimon Marchi1-3/+2
Add the `length` and `set_length` methods on `struct type`, in order to remove the `TYPE_LENGTH` macro. In this patch, the macro is changed to use the getter, so all the call sites of the macro that are used as a setter are changed to use the setter method directly. The next patch will remove the macro completely. Change-Id: Id1090244f15c9856969b9be5006aefe8d8897ca4
2022-09-21gdb: remove TYPE_TARGET_TYPESimon Marchi1-19/+19
Remove the macro, replace all uses by calls to type::target_type. Change-Id: Ie51d3e1e22f94130176d6abd723255282bb6d1ed
2022-05-10Always pass an explicit language down to c_type_printPedro Alves1-2/+3
The next patch will want to do language->print_type(type, ...), to print a type in a given language, avoiding a dependency on the current language. That doesn't work correctly currently, however, because most language implementations of language_defn::print_type call c_print_type without passing down the language. There are two overloads of c_print_type, one that takes a language, and one that does not. The one that does not uses the current language, defeating the point of calling language->print_type()... This commit removes the c_print_type overload that does not take a language, and adjusts the codebase throughout to always pass down a language. In most places, there's already an enum language handy. language_defn::print_type implementations naturally pass down this->la_language. In a couple spots, like in ada-typeprint.c and rust-lang.c there's no enum language handy, but the code is written for a specific language, so we just hardcode the language. In gnuv3_print_method_ptr, I wasn't sure whether we could hardcode C++ here, and we don't have an enum language handy, so I made it use the current language, just like today. Can always be improved later. Change-Id: Ib54fab4cf0fd307bfd55bf1dd5056830096a653b
2022-04-15Implement value_print for RustTom Tromey1-0/+21
This adds an implementation of the value_print method to Rust. As described in PR rust/22254, this removes a bit of weird-looking output from some "print"s -- because c_value_print is bypassed. I don't have a test for the bug that inspired this patch, because I only know how to reproduce it when using a relatively old Rust compiler. However, the new "cast-printing" code in value_print is required, because omitting this causes some existing tests to fail. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22254
2022-04-15Reimplement Rust slice printingTom Tromey1-26/+59
The current nightly Rust compiler (aka 1.61) added better DWARF representation for unsized types. Fixing this is PR rust/21466; but the code is actually the same as what is required to make slice printing more useful, which is PR rust/23871. This patch implements this. I tested this against various Rust compilers: 1.48, current stable, current beta, and current nightly. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21466 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23871
2022-04-15Remove some dead code from the Rust value printerTom Tromey1-8/+0
This removes a bit of dead code from the Rust value printer. This code wasn't always dead -- it fixed a real bug, and a test case was added for it. However, once val_print was removed, it became unnecessary.
2022-03-29Rename print_spaces_filteredTom Tromey1-6/+6
print_spaces_filtered is now misnamed, because whether filtering happens is up to the stream. So, rename it.
2022-03-29Unify gdb printf functionsTom Tromey1-23/+23
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-29Unify gdb putc functionsTom Tromey1-1/+1
Now that filtered and unfiltered output can be treated identically, we can unify the putc family of functions. This is done under the name "gdb_putc". Most of this patch was written by script.
2022-03-29Unify gdb puts functionsTom Tromey1-51/+51
Now that filtered and unfiltered output can be treated identically, we can unify the puts family of functions. This is done under the name "gdb_puts". Most of this patch was written by script.
2022-02-06gdb: remove SYMBOL_TYPE macroSimon Marchi1-1/+1
Add a getter and a setter for a symbol's type. Remove the corresponding macro and adjust all callers. Change-Id: Ie1a137744c5bfe1df4d4f9ae5541c5299577c8de