]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/dwarf2/ada-imported.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / dwarf2 / ada-imported.c
1 /* Ada Pragma Import support.
2
3 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "value.h"
23 #include "dwarf2/loc.h"
24
25 /* Helper to get the imported symbol's real name. */
26 static const char *
27 get_imported_name (const struct symbol *sym)
28 {
29 return (const char *) SYMBOL_LOCATION_BATON (sym);
30 }
31
32 /* Implement the read_variable method from symbol_computed_ops. */
33
34 static struct value *
35 ada_imported_read_variable (struct symbol *symbol, frame_info_ptr frame)
36 {
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 ());
42 }
43
44 /* Implement the read_variable method from symbol_computed_ops. */
45
46 static enum symbol_needs_kind
47 ada_imported_get_symbol_read_needs (struct symbol *symbol)
48 {
49 return SYMBOL_NEEDS_NONE;
50 }
51
52 /* Implement the describe_location method from
53 symbol_computed_ops. */
54
55 static void
56 ada_imported_describe_location (struct symbol *symbol, CORE_ADDR addr,
57 struct ui_file *stream)
58 {
59 gdb_printf (stream, "an imported name for '%s'",
60 get_imported_name (symbol));
61 }
62
63 /* Implement the tracepoint_var_ref method from
64 symbol_computed_ops. */
65
66 static void
67 ada_imported_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
68 struct axs_value *value)
69 {
70 /* Probably could be done, but not needed right now. */
71 error (_("not implemented: trace of imported Ada symbol"));
72 }
73
74 /* Implement the generate_c_location method from
75 symbol_computed_ops. */
76
77 static void
78 ada_imported_generate_c_location (struct symbol *symbol, string_file *stream,
79 struct gdbarch *gdbarch,
80 std::vector<bool> &registers_used,
81 CORE_ADDR pc, const char *result_name)
82 {
83 /* Probably could be done, but not needed right now, and perhaps not
84 ever. */
85 error (_("not implemented: compile translation of imported Ada symbol"));
86 }
87
88 const struct symbol_computed_ops ada_imported_funcs =
89 {
90 ada_imported_read_variable,
91 nullptr,
92 ada_imported_get_symbol_read_needs,
93 ada_imported_describe_location,
94 0,
95 ada_imported_tracepoint_var_ref,
96 ada_imported_generate_c_location
97 };
98
99 /* Implement the get_block_value method from symbol_block_ops. */
100
101 static const block *
102 ada_alias_get_block_value (const struct symbol *sym)
103 {
104 const char *name = get_imported_name (sym);
105 block_symbol real_symbol = lookup_global_symbol (name, nullptr,
106 VAR_DOMAIN);
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 ());
113
114 return real_symbol.symbol->value_block ();
115 }
116
117 const struct symbol_block_ops ada_function_alias_funcs =
118 {
119 nullptr,
120 nullptr,
121 ada_alias_get_block_value
122 };