This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Interactively add symbols
- From: Lars Brinkhoff <lars at nocrew dot org>
- To: gdb at sourceware dot org
- Date: Tue, 08 Aug 2017 12:26:53 +0000
- Subject: Re: Interactively add symbols
- Authentication-results: sourceware.org; auth=none
- References: <7w8tizsozc.fsf@junk.nocrew.org>
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 ();
}