This is the mail archive of the
gdb-prs@sources.redhat.com
mailing list for the GDB project.
pending/972: [RFC] Sort linetables in objfile_relocate.
- From: Klee Dienes <klee at apple dot com>
- To: gdb-gnats at sources dot redhat dot com
- Date: Sun, 24 Nov 2002 02:44:03 -0500
- Subject: pending/972: [RFC] Sort linetables in objfile_relocate.
>Number: 972
>Category: pending
>Synopsis: [RFC] Sort linetables in objfile_relocate.
>Confidential: yes
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: unknown
>Arrival-Date: Thu Jan 30 03:38:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:
>Release:
>Organization:
>Environment:
>Description:
--Apple-Mail-2--312898535
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
When using objfile_relocate, if any of the entries in the linetable
overflow or underflow, the linetable can end up unsorted.
The following patch adds code to objfile_relocate to handle the
overflow/underflow case. For efficiency, it special-cases for a
linetable that was pre-sorted and then overflowed/underflowed, and just
rotates the linetable in the linetable buffer for that case. If the
linetable wasn't pre-sorted, the sort code issues a warning and sorts
it anyway using qsort().
Questions:
* Should it warn on the case where the objfile wasn't sorted before the
relocation? What about warning for overflow/underflow?
* Is the special-case code for a single overflow/underflow worth it?
We could just use qsort() for everything.
* The qsort code needed compare_line_numbers to be exported from
buildsym.c. Wouldn't this be better named compare_line_addresses, or
perhaps something else?
--Apple-Mail-2--312898535
Content-Disposition: attachment;
filename=sort-linetable.txt
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
x-unix-mode=0644;
name="sort-linetable.txt"
2002-11-23 Klee Dienes <kdienes@apple.com>
* objfiles.c: Include buildsym.h.
(objfile_relocate): Re-sort the linetable after relocating.
* Makefile.in (objfiles.o): Update dependencies.
* buildsym.c (compare_line_numbers): Make global.
* buildsym.h (compare_line_numbers): Add prototype.
Index: objfiles.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/Darwin/src/live/cygnus/src/gdb/objfiles.c,v
retrieving revision 1.25
diff -u -r1.25 objfiles.c
--- objfiles.c 2002/11/15 14:33:39 1.25
+++ objfiles.c 2002/11/23 20:56:02
@@ -39,7 +40,7 @@
#include <fcntl.h>
#include "gdb_obstack.h"
#include "gdb_string.h"
-
+#include "buildsym.h"
#include "breakpoint.h"
=20
/* Prototypes for local functions */
@@ -556,10 +569,48 @@
l =3D LINETABLE (s);
if (l)
{
+ unsigned int num_discontinuities =3D 0;
+ int discontinuity_index =3D -1;
+
for (i =3D 0; i < l->nitems; ++i)
l->item[i].pc +=3D ANOFFSET (delta, s->block_line_section);
- }
=20
+ /* Re-sort the line-table. The table should have started
+ off sorted, so even if entries have over/underflowed,
+ we should be able to re-sort it by rotating the values. */
+
+ for (i =3D 0; i < (l->nitems - 1); ++i)
+ if (l->item[i].pc > l->item[i + 1].pc)
+ {
+ num_discontinuities++;
+ discontinuity_index =3D i + 1;
+ }
+ =20
+ if (num_discontinuities =3D=3D 1)
+ {
+ struct linetable *new_linetable =3D NULL;
+ size_t size =3D ((l->nitems - 1) * sizeof (struct =
linetable_entry))
+ + sizeof (struct linetable);
+ =20
+ new_linetable =3D (struct linetable *) xmalloc (size);
+ memcpy (new_linetable, l, sizeof (struct linetable));
+ memcpy (new_linetable->item,
+ l->item + discontinuity_index,
+ (l->nitems - discontinuity_index) * sizeof (struct =
linetable_entry));
+ memcpy (new_linetable->item + (l->nitems - =
discontinuity_index),
+ l->item,
+ discontinuity_index * sizeof (struct =
linetable_entry));
+ memcpy (l->item, new_linetable->item, l->nitems * sizeof =
(struct linetable_entry));
+
+ xfree (new_linetable);
+ }
+ else if (num_discontinuities > 0)
+ {
+ warning ("line table was not properly sorted; =
re-sorting");
+ qsort (l->item, l->nitems, sizeof (struct =
linetable_entry), compare_line_numbers);
+ }
+ }
+ =20
/* Don't relocate a shared blockvector more than once. */
if (!s->primary)
continue;
Index: Makefile.in
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/Darwin/src/live/cygnus/src/gdb/Makefile.in,v
retrieving revision 1.56
diff -u -r1.56 Makefile.in
--- Makefile.in 2002/11/22 07:06:27 1.56
+++ Makefile.in 2002/11/23 20:56:11
@@ -1986,7 +1986,7 @@
$(gdb_regex_h) $(regcache_h)
objfiles.o: objfiles.c $(defs_h) $(bfd_h) $(symtab_h) $(symfile_h) \
$(objfiles_h) $(gdb_stabs_h) $(target_h) $(bcache_h) =
$(gdb_stat_h) \
- $(gdb_obstack_h) $(gdb_string_h) $(breakpoint_h) $(mmalloc_h)
+ $(gdb_obstack_h) $(gdb_string_h) $(buildsym_h) $(breakpoint_h) =
$(mmalloc_h)
ocd.o: ocd.c $(defs_h) $(gdbcore_h) $(gdb_string_h) $(frame_h) =
$(inferior_h) \
$(bfd_h) $(symfile_h) $(target_h) $(gdbcmd_h) $(objfiles_h) \
$(gdb_stabs_h) $(serial_h) $(ocd_h) $(regcache_h)
Index: buildsym.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/Darwin/src/live/cygnus/src/gdb/buildsym.c,v
retrieving revision 1.19
diff -u -r1.19 buildsym.c
--- buildsym.c 2002/11/22 07:06:28 1.19
+++ buildsym.c 2002/11/23 20:56:14
@@ -62,8 +62,6 @@
=20
static int have_line_numbers;
=0C
-static int compare_line_numbers (const void *ln1p, const void *ln2p);
-=0C
=20
/* Initial sizes of data structures. These are realloc'd larger if
needed, and realloc'd down to the size actually used, when
@@ -774,7 +772,7 @@
=20
/* Needed in order to sort line tables from IBM xcoff files. Sigh! */
=20
-static int
+int
compare_line_numbers (const void *ln1p, const void *ln2p)
{
struct linetable_entry *ln1 =3D (struct linetable_entry *) ln1p;
Index: buildsym.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/Darwin/src/live/cygnus/src/gdb/buildsym.h,v
retrieving revision 1.8
diff -u -r1.8 buildsym.h
--- buildsym.h 2002/11/18 21:13:20 1.8
+++ buildsym.h 2002/11/23 20:56:14
@@ -270,6 +270,8 @@
=20
extern void record_line (struct subfile *subfile, int line, CORE_ADDR =
pc);
=20
+int compare_line_numbers (const void *ln1p, const void *ln2p);
+
extern void start_symtab (char *name, char *dirname, CORE_ADDR =
start_addr);
=20
extern int hashname (char *name);
--Apple-Mail-2--312898535--
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: