Re: Interactively add symbols

Lars Brinkhoff <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
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 ();
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.