This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Interactively add symbols


Lars Brinkhoff wrote:
> As far as I have seen, there's no way for a user to interactively add a
> symbol to a running GDB session, other than specifying an object file
> from which to load symbols.  I suggest there should be a simple way to
> do this from the command line.

Here is some proof of concept code.  Obviously, I don't quite know what
I'm doing.  I couldn't find a way to add a symbol without having a file
loaded.


void
add_symbol_command (char *args, int from_tty)
{
  if (args == NULL)
    error (_("add-symbol takes a symbol name and an address"));

  const char *name = args;
  char *val = strchr (args, ' ');
  if (val == NULL)
    error (_("add-symbol takes a symbol name and an address"));

  *val = 0;
  CORE_ADDR addr = parse_and_eval_address (val + 1);

  struct objfile *objfile = current_program_space->objfiles;
  if (objfile == NULL)
    error (_("a file must be loaded for add-symbol to work"));

  objfile->per_bfd->minsyms_read = 0;
  minimal_symbol_reader reader (objfile);
  reader.record (name, addr, mst_text);
  reader.install ();
  objfile->per_bfd->minsyms_read = 1;

  /* Getting new symbols may change our opinion about
     what is frameless.  */
   reinit_frame_cache ();
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]