Home | History | Annotate | Line # | Download | only in dwarf2
      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 "symtab.h"
     21 #include "value.h"
     22 #include "dwarf2/loc.h"
     23 
     24 /* Helper to get the imported symbol's real name.  */
     25 static const char *
     26 get_imported_name (const struct symbol *sym)
     27 {
     28   return (const char *) SYMBOL_LOCATION_BATON (sym);
     29 }
     30 
     31 /* Implement the read_variable method from symbol_computed_ops.  */
     32 
     33 static struct value *
     34 ada_imported_read_variable (struct symbol *symbol, const frame_info_ptr &frame)
     35 {
     36   const char *name = get_imported_name (symbol);
     37   bound_minimal_symbol minsym = lookup_minimal_symbol_linkage (name, false);
     38   if (minsym.minsym == nullptr)
     39     error (_("could not find imported name %s"), name);
     40   return value_at (symbol->type (), minsym.value_address ());
     41 }
     42 
     43 /* Implement the read_variable method from symbol_computed_ops.  */
     44 
     45 static enum symbol_needs_kind
     46 ada_imported_get_symbol_read_needs (struct symbol *symbol)
     47 {
     48   return SYMBOL_NEEDS_NONE;
     49 }
     50 
     51 /* Implement the describe_location method from
     52    symbol_computed_ops.  */
     53 
     54 static void
     55 ada_imported_describe_location (struct symbol *symbol, CORE_ADDR addr,
     56 				struct ui_file *stream)
     57 {
     58   gdb_printf (stream, "an imported name for '%s'",
     59 	      get_imported_name (symbol));
     60 }
     61 
     62 /* Implement the tracepoint_var_ref method from
     63    symbol_computed_ops.  */
     64 
     65 static void
     66 ada_imported_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
     67 				 struct axs_value *value)
     68 {
     69   /* Probably could be done, but not needed right now.  */
     70   error (_("not implemented: trace of imported Ada symbol"));
     71 }
     72 
     73 /* Implement the generate_c_location method from
     74    symbol_computed_ops.  */
     75 
     76 static void
     77 ada_imported_generate_c_location (struct symbol *symbol, string_file *stream,
     78 				  struct gdbarch *gdbarch,
     79 				  std::vector<bool> &registers_used,
     80 				  CORE_ADDR pc, const char *result_name)
     81 {
     82   /* Probably could be done, but not needed right now, and perhaps not
     83      ever.  */
     84   error (_("not implemented: compile translation of imported Ada symbol"));
     85 }
     86 
     87 const struct symbol_computed_ops ada_imported_funcs =
     88 {
     89   ada_imported_read_variable,
     90   nullptr,
     91   ada_imported_get_symbol_read_needs,
     92   ada_imported_describe_location,
     93   0,
     94   ada_imported_tracepoint_var_ref,
     95   ada_imported_generate_c_location
     96 };
     97 
     98 /* Implement the get_block_value method from symbol_block_ops.  */
     99 
    100 static const block *
    101 ada_alias_get_block_value (const struct symbol *sym)
    102 {
    103   const char *name = get_imported_name (sym);
    104   block_symbol real_symbol = lookup_global_symbol (name, nullptr,
    105 						   SEARCH_FUNCTION_DOMAIN);
    106   if (real_symbol.symbol == nullptr)
    107     error (_("could not find alias '%s' for function '%s'"),
    108 	   name, sym->print_name ());
    109   if (real_symbol.symbol->aclass () != LOC_BLOCK)
    110     error (_("alias '%s' for function '%s' is not a function"),
    111 	   name, sym->print_name ());
    112 
    113   return real_symbol.symbol->value_block ();
    114 }
    115 
    116 const struct symbol_block_ops ada_function_alias_funcs =
    117 {
    118   nullptr,
    119   nullptr,
    120   ada_alias_get_block_value
    121 };
    122