aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
AgeCommit message (Collapse)AuthorFilesLines
2022-07-28Rewrite registry.hTom Tromey1-2/+3
This rewrites registry.h, removing all the macros and replacing it with relatively ordinary template classes. The result is less code than the previous setup. It replaces large macros with a relatively straightforward C++ class, and now manages its own cleanup. The existing type-safe "key" class is replaced with the equivalent template class. This approach ended up requiring relatively few changes to the users of the registry code in gdb -- code using the key system just required a small change to the key's declaration. All existing users of the old C-like API are now converted to use the type-safe API. This mostly involved changing explicit deletion functions to be an operator() in a deleter class. The old "save/free" two-phase process is removed, and replaced with a single "free" phase. No existing code used both phases. The old "free" callbacks took a parameter for the enclosing container object. However, this wasn't truly needed and is removed here as well.
2022-07-18Remove array typedef assumption for AdaTom Tromey1-0/+6
Currently the Ada code assumes that it can distinguish between a multi-dimensional array and an array of arrays by looking for an intervening typedef -- that is, for an array of arrays, there will be a typedef wrapping the innermost array type. A recent compiler change removes this typedef, which causes a gdb failure in the internal AdaCore test suite. This patch handles this case by checking whether the array type in question has a name.
2022-06-17event_location -> location_specPedro Alves1-2/+2
Currently, GDB internally uses the term "location" for both the location specification the user input (linespec, explicit location, or an address location), and for actual resolved locations, like the breakpoint locations, or the result of decoding a location spec to SaLs. This is expecially confusing in the breakpoints module, as struct breakpoint has these two fields: breakpoint::location; breakpoint::loc; "location" is the location spec, and "loc" is the resolved locations. And then, we have a method called "locations()", which returns the resolved locations as range... The location spec type is presently called event_location: /* Location we used to set the breakpoint. */ event_location_up location; and it is described like this: /* The base class for all an event locations used to set a stop event in the inferior. */ struct event_location { and even that is incorrect... Location specs are used for finding actual locations in the program in scenarios that have nothing to do with stop events. E.g., "list" works with location specs. To clean all this confusion up, this patch renames "event_location" to "location_spec" throughout, and then all the variables that hold a location spec, they are renamed to include "spec" in their name, like e.g., "location" -> "locspec". Similarly, functions that work with location specs, and currently have just "location" in their name are renamed to include "spec" in their name too. Change-Id: I5814124798aa2b2003e79496e78f95c74e5eddca
2022-05-23[gdb/ada] Fix gdb.ada/dynamic-iface.exp with gcc 7Tom de Vries1-1/+2
This test in test-case gdb.ada/dynamic-iface.exp passes with gcc 8: ... (gdb) print obj^M $1 = (n => 3, a => "ABC", value => 93)^M (gdb) PASS: gdb.ada/dynamic-iface.exp: print local as interface ... but fails with gcc 7: ... (gdb) print obj^M $1 = ()^M (gdb) FAIL: gdb.ada/dynamic-iface.exp: print local as interface ... More concretely, we have trouble finding the type of obj. With gcc 8: ... $ gdb -q -batch main -ex "b concrete.adb:20" -ex run -ex "ptype obj" ... type = <ref> new concrete.intermediate with record value: integer; end record ... and with gcc 7: ... type = <ref> tagged record null; end record ... The translation from tagged type to "full view" type happens in ada_tag_value_at_base_address, where we hit this code: ... /* Storage_Offset'Last is used to indicate that a dynamic offset to top is used. In this situation the offset is stored just after the tag, in the object itself. */ if (offset_to_top == last) { struct value *tem = value_addr (tag); tem = value_ptradd (tem, 1); tem = value_cast (ptr_type, tem); offset_to_top = value_as_long (value_ind (tem)); } ... resulting in an offset_to_top for gcc 8: ... (gdb) p offset_to_top $1 = -16 ... and for gcc 7: ... (gdb) p offset_to_top $1 = 16 ... The difference is expected, it bisects to gcc commit d0567dc0dbf ("[multiple changes]") which mentions this change. There's some code right after the code quoted above that deals with this change: ... else if (offset_to_top > 0) { /* OFFSET_TO_TOP used to be a positive value to be subtracted from the base address. This was however incompatible with C++ dispatch table: C++ uses a *negative* value to *add* to the base address. Ada's convention has therefore been changed in GNAT 19.0w 20171023: since then, C++ and Ada use the same convention. Here, we support both cases by checking the sign of OFFSET_TO_TOP. */ offset_to_top = -offset_to_top; } ... but it's not activated because of the 'else'. Fix this by removing the 'else'. Tested on x86_64-linux, with gcc 7.5.0. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29057
2022-05-20Rename base_breakpoint -> code_breakpointPedro Alves1-4/+4
Even after the previous patches reworking the inheritance of several breakpoint types, the present breakpoint hierarchy looks a bit surprising, as we have "breakpoint" as the superclass, and then "base_breakpoint" inherits from "breakpoint". Like so, simplified: breakpoint base_breakpoint ordinary_breakpoint internal_breakpoint momentary_breakpoint ada_catchpoint exception_catchpoint tracepoint watchpoint catchpoint exec_catchpoint ... The surprising part to me is having "base_breakpoint" being a subclass of "breakpoint". I'm just refering to naming here -- I mean, you'd expect that it would be the top level baseclass that would be called "base". Just flipping the names of breakpoint and base_breakpoint around wouldn't be super great for us, IMO, given we think of every type of *point as a breakpoint at the user visible level. E.g., "info breakpoints" shows watchpoints, tracepoints, etc. So it makes to call the top level class breakpoint. Instead, I propose renaming base_breakpoint to code_breakpoint. The previous patches made sure that all code breakpoints inherit from base_breakpoint, so it's fitting. Also, "code breakpoint" contrasts nicely with a watchpoint also being typically known as a "data breakpoint". After this commit, the resulting hierarchy looks like: breakpoint code_breakpoint ordinary_breakpoint internal_breakpoint momentary_breakpoint ada_catchpoint exception_catchpoint tracepoint watchpoint catchpoint exec_catchpoint ... ... which makes a lot more sense to me. I've left this patch as last in the series in case people want to bikeshed on the naming. "code" has a nice property that it's exactly as many letters as "base", so this patch didn't require any reindentation. :-) Change-Id: Id8dc06683a69fad80d88e674f65e826d6a4e3f66
2022-05-20Convert init_ada_exception_catchpoint to a ctorPedro Alves1-4/+39
Currently, init_ada_exception_catchpoint is defined in breakpoint.c, I presume so it can call the static describe_other_breakpoints function. I think this is a dependency inversion. init_ada_exception_catchpoint, being code specific to Ada catchpoints, should be in ada-lang.c, and describe_other_breakpoints, a core function, should be exported. And then, we can convert init_ada_exception_catchpoint to an ada_catchpoint ctor. Change-Id: I07695572dabc5a75d3d3740fd9b95db1529406a1
2022-05-20Make ada_catchpoint_location's owner ctor parameter be ada_catchpointPedro Alves1-16/+16
This commit changes ada_catchpoint_location's ctor from: ada_catchpoint_location (breakpoint *owner) to: ada_catchpoint_location (ada_catchpoint *owner) just to make the code better document intention. To do this, we need to move the ada_catchpoint_location type's definition to after ada_catchpoint is defined, otherwise the compiler doesn't know that ada_catchpoint is convertible to struct breakpoint. Change-Id: Id908b2e38bde30b262381e00c5637adb9bf0129d
2022-05-16Fix Ada exception regression on WindowsTom Tromey1-1/+1
The breakpoint c++-ification series introduced another bug in Ada -- it caused "catch exception" and related commands to fail on Windows. The problem is that the re_set method calls the wrong superclass method, so the breakpoint doesn't get correctly re-set when the runtime offsets change. This patch fixes the problem.
2022-05-06Remove init_raw_breakpoint_without_locationTom Tromey1-3/+5
This removes init_raw_breakpoint_without_location, replacing it with a constructor on 'breakpoint' itself. The subclasses and callers are all updated.
2022-05-06Constify breakpoint::print_recreateTom Tromey1-2/+2
This constifies breakpoint::print_recreate.
2022-05-06Constify breakpoint::print_mentionTom Tromey1-2/+2
This constifies breakpoint::print_mention.
2022-05-06Constify breakpoint::print_oneTom Tromey1-2/+2
This constifies breakpoint::print_one.
2022-05-06Constify breakpoint::print_itTom Tromey1-8/+6
This constifies breakpoint::print_it. Doing this pointed out some code in ada-lang.c that can be simplified a little as well.
2022-05-06Change print_recreate_thread to a methodTom Tromey1-1/+1
This changes print_recreate_thread to be a method on breakpoint. This function is only used as a helper by print_recreate methods, so I thought this transformation made sense.
2022-05-02Fix Ada catchpoint regressionTom Tromey1-1/+1
The breakpoint C++-ification series introduced a regression for Ada catchpoints. Specifically, commit 2b5ab5b8 ("Convert base breakpoints to vtable ops") caused these to start failing. I didn't notice this because testing Ada using a Linux distro compiler requires installing the GNAT debuginfo, which I hadn't done. This patch fixes the problem. I'm checking it in.
2022-04-29Remove breakpoint_ops from init_ada_exception_breakpointTom Tromey1-1/+0
init_ada_exception_breakpoint is only ever passed a single breakpoint_ops structure, so remove the parameter.
2022-04-29Convert Ada catchpoints to vtable opsTom Tromey1-91/+65
This converts Ada catchpoints to use vtable_breakpoint_ops.
2022-04-29Convert ordinary breakpoints to vtable opsTom Tromey1-2/+2
This converts "ordinary" breakpoint to use vtable_breakpoint_ops. Recall that an ordinary breakpoint is both the kind normally created by users, and also a base class used by other classes.
2022-04-29Return bool from breakpoint_ops::print_oneTom Tromey1-1/+3
This changes breakpoint_ops::print_one to return bool, and updates all the implementations and the caller. The caller is changed so that a NULL check is no longer needed -- something that will be impossible with a real method.
2022-04-27gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macrosSimon Marchi1-11/+12
Replace with calls to blockvector::blocks, and the appropriate method call on the returned array_view. Change-Id: I04d1f39603e4d4c21c96822421431d9a029d8ddd
2022-04-27gdb: remove BLOCK_SUPERBLOCK macroSimon Marchi1-4/+4
Replace with equivalent methods. Change-Id: I334a319909a50b5cc5570a45c38c70e10dc00630
2022-04-27gdb: remove BLOCK_FUNCTION macroSimon Marchi1-2/+2
Replace with equivalent methods. Change-Id: I31ec00f5bf85335c8b23d306ca0fe0b84d489101
2022-04-20Replace symbol_symtab with symbol::symtabTom Tromey1-3/+3
This turns symbol_symtab into a method on symbol. It also replaces symbol_set_symtab with a method.
2022-04-20Add accessors for symbol's artificial fieldTom Tromey1-3/+3
For a series I'm experimenting with, it was handy to hide a symbol's "artificial" field behind accessors. This patch is the result.
2022-04-12Allow ada_decode not to decode operatorsTom Tromey1-5/+8
The new DWARF scanner records names as they appear in DWARF. However, because Ada is unusual, it also decodes the Ada names to synthesize package components for them. In order for this to work out properly, gdb also needs a mode where ada_decode can be instructed not to decode Ada operator names. That is what this patch implements.
2022-04-11gdb: remove MSYMBOL_TYPE macroSimon Marchi1-3/+3
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-11gdb: remove symbol value macrosSimon Marchi1-9/+9
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-07gdb: remove symtab::objfileSimon Marchi1-2/+2
Same idea as previous patch, but for symtab::objfile. I find it clearer without this wrapper, as it shows that the objfile is common to all symtabs of a given compunit. Otherwise, you could think that each symtab (of a given compunit) can have a specific objfile. Change-Id: Ifc0dbc7ec31a06eefa2787c921196949d5a6fcc6
2022-04-07gdb: remove symtab::blockvectorSimon Marchi1-2/+2
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-04Handle ghost entities in symbol lookupTom Tromey1-0/+12
Normally, SPARK ghost entities are removed from the executable. However, with -gnata, they will be preserved. In this situation, it's handy to be able to inspect them. This patch allows this by removing the "___ghost_" prefix in the appropriate places.
2022-03-30Decode "dynamic" interface types in AdaTom Tromey1-13/+38
In Ada, if a class implements an interface and has a dynamic superclass, then the "offset to top" -- the offset that says how to turn a pointer to the interface into a pointer to the whole object -- is stored in the object itself. This patch changes GDB to understand this. Because this only touches Ada code, and because Joel already reviewed it internally, I am checking it in.
2022-03-29Unify gdb printf functionsTom Tromey1-44/+44
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-16Reimplement array concatenation for Ada and DTom Tromey1-1/+57
This started as a patch to implement string concatenation for Ada. However, while working on this, I looked at how this code could possibly be called. It turns out there are only two users of concat_operation: Ada and D. So, in addition to implementing this for Ada, this patch rewrites value_concat, removing the odd "concatenate or repeat" semantics, which were completely unused. As Ada and D both seem to represent strings using TYPE_CODE_ARRAY, this removes the TYPE_CODE_STRING code from there as well.
2022-03-16Ada support for wide stringsTom Tromey1-6/+57
This adds some basic support for Wide_String and Wide_Wide_String to the Ada expression evaluator. In particular, a string literal may be converted to a wide or wide-wide string depending on context. The patch updates an existing test case. Note that another test, namely something like: ptype Wide_Wide_String'("literal") ... would be nice to add, but when tested against a distro GNAT, this did not work (probably due to lack of debuginfo); so, I haven't included it here.
2022-03-07Handle non-ASCII identifiers in AdaTom Tromey1-17/+380
Ada allows non-ASCII identifiers, and GNAT supports several such encodings. This patch adds the corresponding support to gdb. GNAT encodes non-ASCII characters using special symbol names. For character sets like Latin-1, where all characters are a single byte, it uses a "U" followed by the hex for the character. So, for example, thorn would be encoded as "Ufe" (0xFE being lower case thorn). For wider characters, despite what the manual says (it claims Shift-JIS and EUC can be used), in practice recent versions only support Unicode. Here, characters in the base plane are represented using "Wxxxx" and characters outside the base plane using "WWxxxxxxxx". GNAT has some further quirks here. Ada is case-insensitive, and GNAT emits symbols that have been case-folded. For characters in ASCII, and for all characters in non-Unicode character sets, lower case is used. For Unicode, however, characters that fit in a single byte are converted to lower case, but all others are converted to upper case. Furthermore, there is a bug in GNAT where two symbols that differ only in the case of "Y WITH DIAERESIS" (and potentially others, I did not check exhaustively) can be used in one program. I chose to omit handling this case from gdb, on the theory that it is hard to figure out the logic, and anyway if the bug is ever fixed, we'll regret having a heuristic. This patch introduces a new "ada source-charset" setting. It defaults to Latin-1, as that is GNAT's default. This setting controls how "U" characters are decoded -- W/WW are always handled as UTF-32. The ada_tag_name_from_tsd change is needed because this function will read memory from the inferior and interpret it -- and this caused an encoding failure on PPC when running a test that tries to read uninitialized memory. This patch implements its own UTF-32-based case folder. This avoids host platform quirks, and is relatively simple. A short Python program to generate the case-folding table is included. It simply relies on whatever version of Unicode is used by the host Python, which seems basically acceptable. Test cases for UTF-8, Latin-1, and Latin-3 are included. This exercises most of the new code paths, aside from Y WITH DIAERESIS as noted above.
2022-03-07Don't pre-size result string in ada_decodeTom Tromey1-14/+6
Currently, ada_decode pre-sizes the output string, filling it with 'X' characters. However, it's a bit simpler and more flexible to let std::string do the work here, and simply append characters to the string as we go. This turns out to be useful for a subsequent patch.
2022-02-28Handle multi-byte bracket sequences in Ada lexerTom Tromey1-4/+10
As noted in an earlier patch, the Ada lexer does not handle multi-byte bracket sequences. This patch adds support for these for character literals. gdb does not generally seem to handle the Ada wide string types, so for the time being these continue to be excluded -- but an explicit error is added to make this more clear.
2022-02-28Handle 'QWW' encoding case in Ada enumsTom Tromey1-3/+11
In Ada, an enum can contain character literals. GNAT encodes these values in a special way. For example, the Unicode character U+0178 would be represented as 'QW0178' in the DWARF: <3><112f>: Abbrev Number: 2 (DW_TAG_enumerator) <1130> DW_AT_name : (indirect string, offset: 0x19ff): QW0178 <1134> DW_AT_const_value : 2 gdb handles this reasonably well, but failed to handle the 'QWW' encoding, which is used for characters outside the base plane. Also, while working on this, I noticed that gdb will print the decimal value for an enum character constant: (gdb) print Char_X $2 = 1 'x' This is a nice feature, IMO, because in this situation the 'x' enum constant does not have its usual decimal value -- it has the value that's assigned based on the enumeration type. However, gdb did not do this when it decided to print the constant using the bracket notation: (gdb) print Char_Thorn $3 = ["de"] This patch changes gdb to print the decimal value here as well, and to put the bracket notation in single quotes -- otherwise gdb will be printing something that it can't then read. Now it looks like: (gdb) print Char_Thorn $3 = 4 '["de"]' Note that gdb can't read longer bracket notations, like the other ones printed in this test case: (gdb) print Char_King $4 = 3 '["01fa00"]' While I think this is a bug, I plan to fix it separately. Finally, in the new test case, the copyright dates are chosen this way because this all started as a copy of an existing test.
2022-02-11Add initializers to bound_minimal_symbolTom Tromey1-2/+0
This adds initializers to bound_minimal_symbol, allowing for the removal of some calls to memset.
2022-02-06gdb: remove SYMBOL_LINE macroSimon Marchi1-2/+2
Add a getter and a setter for a symbol's line. Remove the corresponding macro and adjust all callers. Change-Id: I229f2b8fcf938c07975f641361313a8761fad9a5
2022-02-06gdb: remove SYMBOL_TYPE macroSimon Marchi1-26/+26
Add a getter and a setter for a symbol's type. Remove the corresponding macro and adjust all callers. Change-Id: Ie1a137744c5bfe1df4d4f9ae5541c5299577c8de
2022-02-06gdb: remove SYMBOL_IS_ARGUMENT macroSimon Marchi1-3/+3
Add a getter and a setter for whether a symbol is an argument. Remove the corresponding macro and adjust all callers. Change-Id: I71b4f0465f3dfd2ed8b9e140bd3f7d5eb8d9ee81
2022-02-06gdb: remove SYMBOL_OBJFILE_OWNED macroSimon Marchi1-2/+2
Add a getter and a setter for whether a symbol is objfile owned. Remove the corresponding macro and adjust all callers. Change-Id: Ib7ef3718d65553ae924ca04c3fd478b0f4f3147c
2022-02-06gdb: remove SYMBOL_DOMAIN macroSimon Marchi1-7/+7
Add a getter and a setter for a symbol's domain. Remove the corresponding macro and adjust all callers. Change-Id: I54465b50ac89739c663859a726aef8cdc6e4b8f3
2022-02-06gdb: remove SYMBOL_CLASS macro, add getterSimon Marchi1-28/+28
Change-Id: I83211d5a47efc0564386e5b5ea4a29c00b1fd46a
2022-02-06gdb: remove SYMTAB_OBJFILE macroSimon Marchi1-2/+2
Remove the macro, replace with an equivalent method. Change-Id: I8f9ecd290ad28502e53c1ceca5006ba78bf042eb
2022-02-06gdb: remove SYMTAB_BLOCKVECTOR macroSimon Marchi1-2/+2
Remove the macro, replace with an equivalent method. Change-Id: Id6fe2a79c04bcd6c69ccaefb7a69bc06a476288c
2022-02-06gdb: remove COMPUNIT_BLOCKVECTOR macro, add getter/setterSimon Marchi1-5/+5
Add a getter and a setter for a compunit_symtab's blockvector. Remove the corresponding macro and adjust all callers. Change-Id: I99484c6619dcbbea7c5d89c72aa660316ca62f64
2022-01-26gdb: add string_file::release methodSimon Marchi1-1/+1
A common pattern for string_file is to want to move out the internal string buffer, because it is the result of the computation that we want to return. It is the reason why string_file::string returns a non-const reference, as explained in the comment. I think it would make sense to have a dedicated method for that instead and make string_file::string return a const reference. This allows removing the explicit std::move in the typical case. Note that compile_program::compute was missing a move, meaning that the resulting string was copied. With the new version, it's not possible to forget to move. Change-Id: Ieaefa35b73daa7930b2f3a26988b6e3b4121bb79
2022-01-18Simplify Ada catchpointsTom Tromey1-65/+3
All the Ada catchpoints use the same breakpoint_ops contents, because the catchpoint itself records its kind. This patch simplifies the code by removing the redundant ops structures.