This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH 3/3] libdw: save startp/endp boundaries in Dwarf_CU
- From: Josh Stone <jistone at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Wed, 10 Dec 2014 18:48:05 -0800
- Subject: [PATCH 3/3] libdw: save startp/endp boundaries in Dwarf_CU
Rather than looking up section data every time, we can simply save the
range of each CU as pointers in Dwarf_CU.
Signed-off-by: Josh Stone <jistone@redhat.com>
---
libdw/ChangeLog | 8 ++++++++
libdw/dwarf_child.c | 3 +--
libdw/dwarf_cuoffset.c | 4 ++--
libdw/dwarf_dieoffset.c | 4 ++--
libdw/dwarf_siblingof.c | 6 ++----
libdw/libdwP.h | 4 ++++
libdw/libdw_findcu.c | 6 +++++-
7 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 2a69bea371fc..83a8c751f936 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,4 +1,12 @@
2014-12-10 Josh Stone <jistone@redhat.com>
+ * libdwP.h (Dwarf_CU): Add startp and endp boundaries.
+ * libdw_findcu.c (__libdw_intern_next_unit): Set startp and endp.
+ * dwarf_child.c (dwarf_child): Use cu->endp.
+ * dwarf_cuoffset.c (dwarf_cuoffset): Use cu->startp.
+ * dwarf_dieoffset.c (dwarf_dieoffset): Use cu->startp.
+ * dwarf_siblingof.c (dwarf_siblingof): Use both.
+
+2014-12-10 Josh Stone <jistone@redhat.com>
* dwarf_hasattr.c (dwarf_hasattr): Just walk abbrev for presence.
2014-12-10 Josh Stone <jistone@redhat.com>
diff --git a/libdw/dwarf_child.c b/libdw/dwarf_child.c
index 3e88fedf1df7..21185f4feda8 100644
--- a/libdw/dwarf_child.c
+++ b/libdw/dwarf_child.c
@@ -146,13 +146,12 @@ dwarf_child (die, result)
/* RESULT can be the same as DIE. So preserve what we need. */
struct Dwarf_CU *cu = die->cu;
- Elf_Data *cu_sec = cu_data (cu);
/* It's kosher (just suboptimal) to have a null entry first thing (7.5.3).
So if this starts with ULEB128 of 0 (even with silly encoding of 0),
it is a kosher null entry and we do not really have any children. */
const unsigned char *code = addr;
- const unsigned char *endp = (cu_sec->d_buf + cu_sec->d_size);
+ const unsigned char *endp = cu->endp;
while (1)
{
if (unlikely (code >= endp)) /* Truncated section. */
diff --git a/libdw/dwarf_cuoffset.c b/libdw/dwarf_cuoffset.c
index 7aea3f91f088..3ceffdb0b29a 100644
--- a/libdw/dwarf_cuoffset.c
+++ b/libdw/dwarf_cuoffset.c
@@ -1,5 +1,5 @@
/* Return offset of DIE in CU.
- Copyright (C) 2003-2010 Red Hat, Inc.
+ Copyright (C) 2003-2010, 2014 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2003.
@@ -41,5 +41,5 @@ dwarf_cuoffset (die)
{
return (die == NULL
? (Dwarf_Off) -1l
- : (die->addr - cu_data (die->cu)->d_buf - die->cu->start));
+ : (Dwarf_Off) (die->addr - die->cu->startp));
}
diff --git a/libdw/dwarf_dieoffset.c b/libdw/dwarf_dieoffset.c
index c92123ce5842..965b2c8dc76f 100644
--- a/libdw/dwarf_dieoffset.c
+++ b/libdw/dwarf_dieoffset.c
@@ -1,5 +1,5 @@
/* Return offset of DIE.
- Copyright (C) 2003-2010 Red Hat, Inc.
+ Copyright (C) 2003-2010, 2014 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2003.
@@ -41,6 +41,6 @@ dwarf_dieoffset (die)
{
return (die == NULL
? ~0ul
- : (Dwarf_Off) (die->addr - cu_data (die->cu)->d_buf));
+ : (Dwarf_Off) (die->addr - die->cu->startp + die->cu->start));
}
INTDEF(dwarf_dieoffset)
diff --git a/libdw/dwarf_siblingof.c b/libdw/dwarf_siblingof.c
index f2dc46888e91..27830ea450d4 100644
--- a/libdw/dwarf_siblingof.c
+++ b/libdw/dwarf_siblingof.c
@@ -62,8 +62,7 @@ dwarf_siblingof (die, result)
/* That's the address we start looking. */
unsigned char *addr = this_die.addr;
/* End of the buffer. */
- unsigned char *endp
- = ((unsigned char *) cu_data (sibattr.cu)->d_buf + sibattr.cu->end);
+ unsigned char *endp = sibattr.cu->endp;
/* Search for the beginning of the next die on this level. We
must not return the dies for children of the given die. */
@@ -81,8 +80,7 @@ dwarf_siblingof (die, result)
return -1;
/* Compute the next address. */
- addr = ((unsigned char *) cu_data (sibattr.cu)->d_buf
- + sibattr.cu->start + offset);
+ addr = sibattr.cu->startp + offset;
}
else if (unlikely (addr == NULL)
|| unlikely (this_die.abbrev == DWARF_END_ABBREV))
diff --git a/libdw/libdwP.h b/libdw/libdwP.h
index f391c94ed647..fa3dd7f27070 100644
--- a/libdw/libdwP.h
+++ b/libdw/libdwP.h
@@ -310,6 +310,10 @@ struct Dwarf_CU
/* Known location lists. */
void *locs;
+
+ /* Memory boundaries of this CU. */
+ void *startp;
+ void *endp;
};
/* Compute the offset of a CU's first DIE from its offset. This
diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c
index c0bff2af2a69..3c9633e2b863 100644
--- a/libdw/libdw_findcu.c
+++ b/libdw/libdw_findcu.c
@@ -1,5 +1,5 @@
/* Find CU for given offset.
- Copyright (C) 2003-2010 Red Hat, Inc.
+ Copyright (C) 2003-2010, 2014 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2003.
@@ -113,6 +113,10 @@ __libdw_intern_next_unit (dbg, debug_types)
if (debug_types)
Dwarf_Sig8_Hash_insert (&dbg->sig8_hash, type_sig8, newp);
+ void *buf = cu_data (newp)->d_buf;
+ newp->startp = buf + newp->start;
+ newp->endp = buf + newp->end;
+
/* Add the new entry to the search tree. */
if (tsearch (newp, tree, findcu_cb) == NULL)
{
--
2.1.0