Create target sections for user-added symbol files.
Add the sections of the symbol files that are provided via 'add-symbol-file' to the set of current target sections. User-added sections are removed upon notification of free_objfile when their corresponding object file is deleted. 2013-10-29 Nicolas Blanc <nicolas.blanc@intel.com> * exec.h (add_target_sections_of_objfile): New declaration. * exec.c (add_target_sections_of_objfile): New function. * symfile.c (add_symbol_file_command): Update current target sections. (symfile_free_objfile): New function. (_initialize_symfile): Register observer for free_objfile events. Signed-off-by: Nicolas Blanc <nicolas.blanc@intel.com>
This commit is contained in:
parent
98297bf675
commit
76ad5e1e2a
3 changed files with 69 additions and 2 deletions
45
gdb/exec.c
45
gdb/exec.c
|
@ -438,6 +438,51 @@ add_target_sections (void *owner,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add the sections of OBJFILE to the current set of target sections. */
|
||||||
|
|
||||||
|
void
|
||||||
|
add_target_sections_of_objfile (struct objfile *objfile)
|
||||||
|
{
|
||||||
|
struct target_section_table *table = current_target_sections;
|
||||||
|
struct obj_section *osect;
|
||||||
|
int space;
|
||||||
|
unsigned count = 0;
|
||||||
|
struct target_section *ts;
|
||||||
|
|
||||||
|
if (objfile == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Compute the number of sections to add. */
|
||||||
|
ALL_OBJFILE_OSECTIONS (objfile, osect)
|
||||||
|
{
|
||||||
|
if (bfd_get_section_size (osect->the_bfd_section) == 0)
|
||||||
|
continue;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
space = resize_section_table (table, count);
|
||||||
|
|
||||||
|
ts = table->sections + space;
|
||||||
|
|
||||||
|
ALL_OBJFILE_OSECTIONS (objfile, osect)
|
||||||
|
{
|
||||||
|
if (bfd_get_section_size (osect->the_bfd_section) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gdb_assert (ts < table->sections + space + count);
|
||||||
|
|
||||||
|
ts->addr = obj_section_addr (osect);
|
||||||
|
ts->endaddr = obj_section_endaddr (osect);
|
||||||
|
ts->the_bfd_section = osect->the_bfd_section;
|
||||||
|
ts->owner = (void *) objfile;
|
||||||
|
|
||||||
|
ts++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove all target sections owned by OWNER.
|
/* Remove all target sections owned by OWNER.
|
||||||
OWNER must be the same value passed to add_target_sections. */
|
OWNER must be the same value passed to add_target_sections. */
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
struct target_section;
|
struct target_section;
|
||||||
struct target_ops;
|
struct target_ops;
|
||||||
struct bfd;
|
struct bfd;
|
||||||
|
struct objfile;
|
||||||
|
|
||||||
extern struct target_ops exec_ops;
|
extern struct target_ops exec_ops;
|
||||||
|
|
||||||
|
@ -93,6 +94,11 @@ extern void add_target_sections (void *owner,
|
||||||
struct target_section *sections,
|
struct target_section *sections,
|
||||||
struct target_section *sections_end);
|
struct target_section *sections_end);
|
||||||
|
|
||||||
|
/* Add the sections of OBJFILE to the current set of target sections.
|
||||||
|
* OBJFILE owns the new target sections. */
|
||||||
|
|
||||||
|
extern void add_target_sections_of_objfile (struct objfile *objfile);
|
||||||
|
|
||||||
/* Prints info about all sections defined in the TABLE. ABFD is
|
/* Prints info about all sections defined in the TABLE. ABFD is
|
||||||
special cased --- it's filename is omitted; if it is the executable
|
special cased --- it's filename is omitted; if it is the executable
|
||||||
file, its entry point is printed. */
|
file, its entry point is printed. */
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
#include "gdb_bfd.h"
|
#include "gdb_bfd.h"
|
||||||
#include "cli/cli-utils.h"
|
#include "cli/cli-utils.h"
|
||||||
|
#include "target.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -2206,6 +2207,7 @@ add_symbol_file_command (char *args, int from_tty)
|
||||||
int expecting_sec_name = 0;
|
int expecting_sec_name = 0;
|
||||||
int expecting_sec_addr = 0;
|
int expecting_sec_addr = 0;
|
||||||
char **argv;
|
char **argv;
|
||||||
|
struct objfile *objf;
|
||||||
|
|
||||||
struct sect_opt
|
struct sect_opt
|
||||||
{
|
{
|
||||||
|
@ -2332,8 +2334,10 @@ add_symbol_file_command (char *args, int from_tty)
|
||||||
if (from_tty && (!query ("%s", "")))
|
if (from_tty && (!query ("%s", "")))
|
||||||
error (_("Not confirmed."));
|
error (_("Not confirmed."));
|
||||||
|
|
||||||
symbol_file_add (filename, from_tty ? SYMFILE_VERBOSE : 0,
|
objf = symbol_file_add (filename, from_tty ? SYMFILE_VERBOSE : 0,
|
||||||
section_addrs, flags);
|
section_addrs, flags);
|
||||||
|
|
||||||
|
add_target_sections_of_objfile (objf);
|
||||||
|
|
||||||
/* Getting new symbols may change our opinion about what is
|
/* Getting new symbols may change our opinion about what is
|
||||||
frameless. */
|
frameless. */
|
||||||
|
@ -3819,11 +3823,23 @@ symfile_find_segment_sections (struct objfile *objfile)
|
||||||
free_symfile_segment_data (data);
|
free_symfile_segment_data (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Listen for free_objfile events. */
|
||||||
|
|
||||||
|
static void
|
||||||
|
symfile_free_objfile (struct objfile *objfile)
|
||||||
|
{
|
||||||
|
/* Remove the target sections of user-added objfiles. */
|
||||||
|
if (objfile != 0 && objfile->flags & OBJF_USERLOADED)
|
||||||
|
remove_target_sections ((void *) objfile);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_initialize_symfile (void)
|
_initialize_symfile (void)
|
||||||
{
|
{
|
||||||
struct cmd_list_element *c;
|
struct cmd_list_element *c;
|
||||||
|
|
||||||
|
observer_attach_free_objfile (symfile_free_objfile);
|
||||||
|
|
||||||
c = add_cmd ("symbol-file", class_files, symbol_file_command, _("\
|
c = add_cmd ("symbol-file", class_files, symbol_file_command, _("\
|
||||||
Load symbol table from executable file FILE.\n\
|
Load symbol table from executable file FILE.\n\
|
||||||
The `file' command can also load symbol tables, as well as setting the file\n\
|
The `file' command can also load symbol tables, as well as setting the file\n\
|
||||||
|
|
Loading…
Reference in a new issue