1 /* Ada Pragma Import support.
3 Copyright (C) 2023-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "dwarf2/loc.h"
25 /* Helper to get the imported symbol's real name. */
27 get_imported_name (const struct symbol
*sym
)
29 return (const char *) SYMBOL_LOCATION_BATON (sym
);
32 /* Implement the read_variable method from symbol_computed_ops. */
35 ada_imported_read_variable (struct symbol
*symbol
, frame_info_ptr frame
)
37 const char *name
= get_imported_name (symbol
);
38 bound_minimal_symbol minsym
= lookup_minimal_symbol_linkage (name
, false);
39 if (minsym
.minsym
== nullptr)
40 error (_("could not find imported name %s"), name
);
41 return value_at (symbol
->type (), minsym
.value_address ());
44 /* Implement the read_variable method from symbol_computed_ops. */
46 static enum symbol_needs_kind
47 ada_imported_get_symbol_read_needs (struct symbol
*symbol
)
49 return SYMBOL_NEEDS_NONE
;
52 /* Implement the describe_location method from
53 symbol_computed_ops. */
56 ada_imported_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
57 struct ui_file
*stream
)
59 gdb_printf (stream
, "an imported name for '%s'",
60 get_imported_name (symbol
));
63 /* Implement the tracepoint_var_ref method from
64 symbol_computed_ops. */
67 ada_imported_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
68 struct axs_value
*value
)
70 /* Probably could be done, but not needed right now. */
71 error (_("not implemented: trace of imported Ada symbol"));
74 /* Implement the generate_c_location method from
75 symbol_computed_ops. */
78 ada_imported_generate_c_location (struct symbol
*symbol
, string_file
*stream
,
79 struct gdbarch
*gdbarch
,
80 std::vector
<bool> ®isters_used
,
81 CORE_ADDR pc
, const char *result_name
)
83 /* Probably could be done, but not needed right now, and perhaps not
85 error (_("not implemented: compile translation of imported Ada symbol"));
88 const struct symbol_computed_ops ada_imported_funcs
=
90 ada_imported_read_variable
,
92 ada_imported_get_symbol_read_needs
,
93 ada_imported_describe_location
,
95 ada_imported_tracepoint_var_ref
,
96 ada_imported_generate_c_location
99 /* Implement the get_block_value method from symbol_block_ops. */
102 ada_alias_get_block_value (const struct symbol
*sym
)
104 const char *name
= get_imported_name (sym
);
105 block_symbol real_symbol
= lookup_global_symbol (name
, nullptr,
107 if (real_symbol
.symbol
== nullptr)
108 error (_("could not find alias '%s' for function '%s'"),
109 name
, sym
->print_name ());
110 if (real_symbol
.symbol
->aclass () != LOC_BLOCK
)
111 error (_("alias '%s' for function '%s' is not a function"),
112 name
, sym
->print_name ());
114 return real_symbol
.symbol
->value_block ();
117 const struct symbol_block_ops ada_function_alias_funcs
=
121 ada_alias_get_block_value