Skip to content

Commit 567995e

Browse files
committed
gdb/
Fix displacement of separate debug info files. * objfiles.c (objfile_relocate): Rename to ... (objfile_relocate1): ... here and make it static. Extend the comment. (objfile_relocate): New function. * solib-spu.c (spu_relocate_main_executable): Explicitly check if SYMFILE_OBJFILE is NULL. Remove variables objfile and old_chain. Remove following of SEPARATE_DEBUG_OBJFILE. new_offsets is now allocated using alloca. * symfile.c (copy_section_addr_info): Remove. (build_section_addr_info_from_objfile): Make it global. New variables addr_bit and mask, use them. * symfile.h (build_section_addr_info_from_objfile): New prototype. (copy_section_addr_info): Remove.
1 parent a2beed3 commit 567995e

File tree

5 files changed

+86
-50
lines changed

5 files changed

+86
-50
lines changed

gdb/ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2010-01-09 Jan Kratochvil <[email protected]>
2+
3+
Fix displacement of separate debug info files.
4+
* objfiles.c (objfile_relocate): Rename to ...
5+
(objfile_relocate1): ... here and make it static. Extend the comment.
6+
(objfile_relocate): New function.
7+
* solib-spu.c (spu_relocate_main_executable): Explicitly check if
8+
SYMFILE_OBJFILE is NULL. Remove variables objfile and old_chain.
9+
Remove following of SEPARATE_DEBUG_OBJFILE. new_offsets is now
10+
allocated using alloca.
11+
* symfile.c (copy_section_addr_info): Remove.
12+
(build_section_addr_info_from_objfile): Make it global. New variables
13+
addr_bit and mask, use them.
14+
* symfile.h (build_section_addr_info_from_objfile): New prototype.
15+
(copy_section_addr_info): Remove.
16+
117
2010-01-09 Joel Brobecker <[email protected]>
218

319
Signal unwinder for mips-irix N32.

gdb/objfiles.c

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,10 @@ free_all_objfiles (void)
693693
}
694694

695695
/* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS
696-
entries in new_offsets. */
697-
void
698-
objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
696+
entries in new_offsets. SEPARATE_DEBUG_OBJFILE is not touched here. */
697+
698+
static void
699+
objfile_relocate1 (struct objfile *objfile, struct section_offsets *new_offsets)
699700
{
700701
struct obj_section *s;
701702
struct section_offsets *delta =
@@ -849,6 +850,54 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
849850
exec_set_section_address (bfd_get_filename (objfile->obfd), idx,
850851
obj_section_addr (s));
851852
}
853+
}
854+
855+
/* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS
856+
entries in new_offsets. Process also OBJFILE's SEPARATE_DEBUG_OBJFILEs.
857+
858+
The number and ordering of sections does differ between the two objfiles.
859+
Only their names match. Also the file offsets will differ (objfile being
860+
possibly prelinked but separate_debug_objfile is probably not prelinked) but
861+
the in-memory absolute address as specified by NEW_OFFSETS must match both
862+
files. */
863+
864+
void
865+
objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
866+
{
867+
struct objfile *debug_objfile;
868+
869+
objfile_relocate1 (objfile, new_offsets);
870+
871+
for (debug_objfile = objfile->separate_debug_objfile;
872+
debug_objfile;
873+
debug_objfile = objfile_separate_debug_iterate (objfile, debug_objfile))
874+
{
875+
struct section_addr_info *objfile_addrs;
876+
struct section_offsets *new_debug_offsets;
877+
int new_debug_num_sections;
878+
struct cleanup *my_cleanups;
879+
880+
objfile_addrs = build_section_addr_info_from_objfile (objfile);
881+
my_cleanups = make_cleanup (xfree, objfile_addrs);
882+
883+
/* Here OBJFILE_ADDRS contain the correct absolute addresses, the
884+
relative ones must be already created according to debug_objfile. */
885+
886+
addr_info_make_relative (objfile_addrs, debug_objfile->obfd);
887+
888+
gdb_assert (debug_objfile->num_sections
889+
== bfd_count_sections (debug_objfile->obfd));
890+
new_debug_offsets = xmalloc (SIZEOF_N_SECTION_OFFSETS
891+
(debug_objfile->num_sections));
892+
make_cleanup (xfree, new_debug_offsets);
893+
relative_addr_info_to_section_offsets (new_debug_offsets,
894+
debug_objfile->num_sections,
895+
objfile_addrs);
896+
897+
objfile_relocate1 (debug_objfile, new_debug_offsets);
898+
899+
do_cleanups (my_cleanups);
900+
}
852901

853902
/* Relocate breakpoints as necessary, after things are relocated. */
854903
breakpoint_re_set ();

gdb/solib-spu.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,19 @@
5050
static void
5151
spu_relocate_main_executable (int spufs_fd)
5252
{
53-
struct objfile *objfile;
54-
struct cleanup *old_chain;
5553
struct section_offsets *new_offsets;
5654
int i;
5755

58-
for (objfile = symfile_objfile;
59-
objfile;
60-
objfile = objfile->separate_debug_objfile)
61-
{
62-
new_offsets = xcalloc (objfile->num_sections,
63-
sizeof (struct section_offsets));
64-
old_chain = make_cleanup (xfree, new_offsets);
56+
if (symfile_objfile == NULL)
57+
return;
6558

66-
for (i = 0; i < objfile->num_sections; i++)
67-
new_offsets->offsets[i] = SPUADDR (spufs_fd, 0);
59+
new_offsets = alloca (symfile_objfile->num_sections
60+
* sizeof (struct section_offsets));
6861

69-
objfile_relocate (objfile, new_offsets);
70-
do_cleanups (old_chain);
71-
}
62+
for (i = 0; i < symfile_objfile->num_sections; i++)
63+
new_offsets->offsets[i] = SPUADDR (spufs_fd, 0);
64+
65+
objfile_relocate (symfile_objfile, new_offsets);
7266
}
7367

7468
/* When running a stand-alone SPE executable, we may need to skip one more

gdb/symfile.c

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -328,32 +328,6 @@ alloc_section_addr_info (size_t num_sections)
328328
return sap;
329329
}
330330

331-
332-
/* Return a freshly allocated copy of ADDRS. The section names, if
333-
any, are also freshly allocated copies of those in ADDRS. */
334-
struct section_addr_info *
335-
copy_section_addr_info (struct section_addr_info *addrs)
336-
{
337-
struct section_addr_info *copy
338-
= alloc_section_addr_info (addrs->num_sections);
339-
int i;
340-
341-
copy->num_sections = addrs->num_sections;
342-
for (i = 0; i < addrs->num_sections; i++)
343-
{
344-
copy->other[i].addr = addrs->other[i].addr;
345-
if (addrs->other[i].name)
346-
copy->other[i].name = xstrdup (addrs->other[i].name);
347-
else
348-
copy->other[i].name = NULL;
349-
copy->other[i].sectindex = addrs->other[i].sectindex;
350-
}
351-
352-
return copy;
353-
}
354-
355-
356-
357331
/* Build (allocate and populate) a section_addr_info struct from
358332
an existing section table. */
359333

@@ -386,12 +360,17 @@ build_section_addr_info_from_section_table (const struct target_section *start,
386360

387361
/* Create a section_addr_info from section offsets in OBJFILE. */
388362

389-
static struct section_addr_info *
363+
struct section_addr_info *
390364
build_section_addr_info_from_objfile (const struct objfile *objfile)
391365
{
392366
struct section_addr_info *sap;
393367
int i;
394368
struct bfd_section *sec;
369+
int addr_bit = gdbarch_addr_bit (objfile->gdbarch);
370+
CORE_ADDR mask = CORE_ADDR_MAX;
371+
372+
if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
373+
mask = ((CORE_ADDR) 1 << addr_bit) - 1;
395374

396375
sap = alloc_section_addr_info (objfile->num_sections);
397376
for (i = 0, sec = objfile->obfd->sections;
@@ -400,7 +379,7 @@ build_section_addr_info_from_objfile (const struct objfile *objfile)
400379
{
401380
gdb_assert (sec != NULL);
402381
sap->other[i].addr = (bfd_get_section_vma (objfile->obfd, sec)
403-
+ objfile->section_offsets->offsets[i]);
382+
+ objfile->section_offsets->offsets[i]) & mask;
404383
sap->other[i].name = xstrdup (bfd_get_section_name (objfile->obfd, sec));
405384
sap->other[i].sectindex = sec->index;
406385
}

gdb/symfile.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ struct sym_fns
174174

175175
};
176176

177+
extern struct section_addr_info *
178+
build_section_addr_info_from_objfile (const struct objfile *objfile);
179+
177180
extern void relative_addr_info_to_section_offsets
178181
(struct section_offsets *section_offsets, int num_sections,
179182
struct section_addr_info *addrs);
@@ -254,11 +257,6 @@ extern char *find_separate_debug_file_by_debuglink (struct objfile *);
254257
extern struct section_addr_info *alloc_section_addr_info (size_t
255258
num_sections);
256259

257-
/* Return a freshly allocated copy of ADDRS. The section names, if
258-
any, are also freshly allocated copies of those in ADDRS. */
259-
extern struct section_addr_info *(copy_section_addr_info
260-
(struct section_addr_info *addrs));
261-
262260
/* Build (allocate and populate) a section_addr_info struct from an
263261
existing section table. */
264262

0 commit comments

Comments
 (0)