summaryrefslogtreecommitdiffstats
path: root/libdw/dwarf_getlocation.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2009-06-14 20:19:45 -0700
committerUlrich Drepper <drepper@redhat.com>2009-06-14 20:19:45 -0700
commit99d2372b25d1231d786b70278478c7a112f2b27c (patch)
treeca307d5078971fdef16f324e8ffd32b25ddd0df1 /libdw/dwarf_getlocation.c
parentf189493154d0041deced00e6a99cc5426dc9d260 (diff)
Squashed commit of the following:
commit 77abb31cb8d55980ef92260917a7ecdd228b1a44 Author: Petr Machata <pmachata@redhat.com> Date: Mon Jun 8 15:46:16 2009 +0200 Fix a bug in offset checking commit b794eac4f8d3e08101b5d2924523b1259bbc1b17 Author: Petr Machata <pmachata@redhat.com> Date: Wed Jun 3 16:00:01 2009 +0200 Cosmetic, get rid of defining several variables per line commit a23938fe35d515a3d75a51f6204771f3cf6c9ec4 Author: Petr Machata <pmachata@redhat.com> Date: Wed Jun 3 15:50:03 2009 +0200 Restructure the code to decrease the binary size commit 7c301e3d4e8584dfb3174855fb6af3d5791dfeed Author: Petr Machata <pmachata@redhat.com> Date: Mon Jun 1 19:43:28 2009 +0200 Shuffle a couple pieces of code around to make the code smaller commit 6325323482c2a3e17409d32c7feec9461be26614 Merge: 83ac53d... e94b1b2... Author: Petr Machata <pmachata@redhat.com> Date: Fri May 22 08:49:07 2009 +0200 Merge branch 'master' of ssh://pmachata@git.fedorahosted.org/git/elfutils into pmachata/reader_hooks Conflicts: libdw/ChangeLog commit 83ac53db400945c074e77ec9904efe550903a0e2 Author: Petr Machata <pmachata@redhat.com> Date: Fri May 22 08:40:25 2009 +0200 Call reloc hook with the original address, not incremented commit f1996388745566abc1ca1c1700b3b7eded208575 Author: Petr Machata <pmachata@redhat.com> Date: Wed May 6 16:53:03 2009 +0200 Rewrite boundary checking logic so that it's immune to arithmetic overflow * ... also get rid of some code redundancy. commit 0c1df732822d83548edd0d005f3450281ed1701b Author: Petr Machata <pmachata@redhat.com> Date: Wed May 6 16:25:09 2009 +0200 __libdw_read_offset* take extra argument for header size checks * also presence of debug data and buffer is checked in __libdw_in_section commit 6fb192e360f842cacb34a90c03cd0524cccc3dec Author: Petr Machata <pmachata@redhat.com> Date: Wed May 6 15:51:20 2009 +0200 Check for presence of data before loading the offset commit a2e7612b165d83dd241225f87075fa4f58d18781 Author: Petr Machata <pmachata@redhat.com> Date: Wed May 6 15:04:16 2009 +0200 Cosmetic changes commit 8b1aad2c2f6c8dc02b3e704e4f386c1827e385cb Author: Petr Machata <pmachata@redhat.com> Date: Tue May 5 15:34:13 2009 +0200 Improve reader hook functions a bit * ... so that they are closer match to what's need on call sites commit 3854b7fbab2fe331711365f94a295af82164d0d2 Author: Petr Machata <pmachata@redhat.com> Date: Tue May 5 14:33:50 2009 +0200 Fixes in use of reader hooks in __libdw_formptr and dwarf_formudata * and a bit more commit 335075596b6acef6e59919155e2b087e690a572d Author: Petr Machata <pmachata@redhat.com> Date: Tue May 5 14:32:39 2009 +0200 Rename __libdw_read_udata_addr to __libdw_formptr commit 8273a2adaf8cb2ee203926af2849e4f96f8a6eaf Author: Petr Machata <pmachata@redhat.com> Date: Tue May 5 02:53:40 2009 +0200 Introduce __libdw_read_udata_address * the use in dwarf_ranges is iffy, there's a functionality mismatch. Need to find some better way commit 1c897f4abde1530038d332f4fc03a596a24f6aaf Author: Petr Machata <pmachata@redhat.com> Date: Mon May 4 18:09:13 2009 +0200 ChangeLog entries for previous commit commit 90d7c39454468b91c0fd6514a4e8d821222d6adb Author: Petr Machata <pmachata@redhat.com> Date: Mon May 4 18:07:54 2009 +0200 Fix bugs, introduce __libdw_read_begin_end_pair_inc commit 9b3923f5b69a3e56590769435c4693f057acdc1f Merge: 6200ba6... 589b3d3... Author: Petr Machata <pmachata@redhat.com> Date: Mon May 4 12:22:21 2009 +0200 Merge branch 'master' of ssh://pmachata@git.fedorahosted.org/git/elfutils into pmachata/reader_hooks commit 6200ba62aa9ea3cb9318f73a27181907a528dbe4 Author: Petr Machata <pmachata@redhat.com> Date: Wed Apr 29 15:31:28 2009 +0200 dwarf_getlocation_addr uses read hooks commit ecbb8cdd8b500e37dc34fc246b912f704fe31ca4 Author: Petr Machata <pmachata@redhat.com> Date: Wed Apr 29 15:16:09 2009 +0200 dwarf_ranges and dwarf_formref use read hooks commit cb8f67b29a896c2660c10aa1028a9dbb377553e9 Author: Petr Machata <pmachata@redhat.com> Date: Tue Apr 28 18:39:04 2009 +0200 Convert several new functions to use read hooks commit b130453eb16a8cf042915e312cc5f189b8b92c01 Author: Petr Machata <pmachata@redhat.com> Date: Tue Apr 28 18:38:27 2009 +0200 Add length read hooks commit bd885ff694817b965231d99f1ab867947998e734 Author: Petr Machata <pmachata@redhat.com> Date: Tue Apr 28 18:36:17 2009 +0200 Constify read hook arguments commit 66fe03f1e489a88b89a15c9e13f9bd33db2729b1 Author: Petr Machata <pmachata@redhat.com> Date: Tue Apr 28 16:11:05 2009 +0200 Change type of return value of offset read hooks to Dwarf_Off commit 22b36e00cc228f5a966f84ca3323e5d652923ce8 Merge: 5b3534b... a7cb532... Author: Petr Machata <pmachata@redhat.com> Date: Mon Apr 27 19:05:25 2009 +0200 Merge branch 'master' of ssh://pmachata@git.fedorahosted.org/git/elfutils into pmachata/reader_hooks commit 5b3534b62cbd45fe4f11dd1be3e492237938cce0 Author: Petr Machata <pmachata@redhat.com> Date: Mon Apr 27 18:53:06 2009 +0200 Rewrites in read hooks * Have the checking and reading logic itself in the header so that it gets optimized out/inlined. Call external relocating hook from there, there will presumably be more work to do, and we presumably don't want to keep this in the header. commit 9e265d71d0eb900e76d6fdb0196ef4fc6507f3a7 Merge: 1783089... 300f3a4... Author: Petr Machata <pmachata@redhat.com> Date: Thu Apr 23 17:45:25 2009 +0200 Merge branch 'master' of ssh://pmachata@git.fedorahosted.org/git/elfutils into pmachata/reader_hooks commit 1783089b184ddea2081bbe5ac4e80420cb6b0803 Author: Petr Machata <pmachata@redhat.com> Date: Thu Apr 23 17:44:48 2009 +0200 Use the new reader hooks in several places commit 11c3d97a5b40ea15edf324092b03da3050610d01 Author: Petr Machata <pmachata@redhat.com> Date: Thu Apr 23 17:40:03 2009 +0200 Introduce reader hooks
Diffstat (limited to 'libdw/dwarf_getlocation.c')
-rw-r--r--libdw/dwarf_getlocation.c94
1 files changed, 30 insertions, 64 deletions
diff --git a/libdw/dwarf_getlocation.c b/libdw/dwarf_getlocation.c
index f680aa96..f829e72b 100644
--- a/libdw/dwarf_getlocation.c
+++ b/libdw/dwarf_getlocation.c
@@ -113,7 +113,7 @@ loc_compare (const void *p1, const void *p2)
static int
getlocation (struct Dwarf_CU *cu, const Dwarf_Block *block,
- Dwarf_Op **llbuf, size_t *listlen)
+ Dwarf_Op **llbuf, size_t *listlen, int sec_index)
{
Dwarf *dbg = cu->dbg;
@@ -151,24 +151,9 @@ getlocation (struct Dwarf_CU *cu, const Dwarf_Block *block,
{
case DW_OP_addr:
/* Address, depends on address size of CU. */
- if (cu->address_size == 4)
- {
- if (unlikely (data + 4 > end_data))
- {
- invalid:
- __libdw_seterrno (DWARF_E_INVALID_DWARF);
- return -1;
- }
-
- newloc->number = read_4ubyte_unaligned_inc (dbg, data);
- }
- else
- {
- if (unlikely (data + 8 > end_data))
- goto invalid;
-
- newloc->number = read_8ubyte_unaligned_inc (dbg, data);
- }
+ if (__libdw_read_address_inc (dbg, sec_index, (unsigned char **)&data,
+ cu->address_size, &newloc->number))
+ return -1;
break;
case DW_OP_deref:
@@ -211,7 +196,11 @@ getlocation (struct Dwarf_CU *cu, const Dwarf_Block *block,
case DW_OP_deref_size:
case DW_OP_xderef_size:
if (unlikely (data >= end_data))
- goto invalid;
+ {
+ invalid:
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
newloc->number = *data++;
break;
@@ -352,7 +341,7 @@ dwarf_getlocation (attr, llbuf, listlen)
if (INTUSE(dwarf_formblock) (attr, &block) != 0)
return -1;
- return getlocation (attr->cu, &block, llbuf, listlen);
+ return getlocation (attr->cu, &block, llbuf, listlen, IDX_debug_info);
}
int
@@ -376,7 +365,8 @@ dwarf_getlocation_addr (attr, address, llbufs, listlens, maxlocs)
if (maxlocs == 0)
return 0;
if (llbufs != NULL &&
- getlocation (attr->cu, &block, &llbufs[0], &listlens[0]) != 0)
+ getlocation (attr->cu, &block, &llbufs[0], &listlens[0],
+ IDX_debug_info) != 0)
return -1;
return listlens[0] == 0 ? 0 : 1;
}
@@ -388,25 +378,17 @@ dwarf_getlocation_addr (attr, address, llbufs, listlens, maxlocs)
return -1;
}
- /* Must have the form data4 or data8 which act as an offset. */
- Dwarf_Word offset;
- if (unlikely (INTUSE(dwarf_formudata) (attr, &offset) != 0))
+ unsigned char *endp;
+ unsigned char *readp = __libdw_formptr (attr, IDX_debug_loc,
+ DWARF_E_NO_LOCLIST, &endp, NULL);
+ if (readp == NULL)
return -1;
- const Elf_Data *d = attr->cu->dbg->sectiondata[IDX_debug_loc];
- if (unlikely (d == NULL))
- {
- __libdw_seterrno (DWARF_E_NO_LOCLIST);
- return -1;
- }
-
Dwarf_Addr base = (Dwarf_Addr) -1;
- unsigned char *readp = d->d_buf + offset;
size_t got = 0;
while (got < maxlocs)
{
- if ((unsigned char *) d->d_buf + d->d_size - readp
- < attr->cu->address_size * 2)
+ if (endp - readp < attr->cu->address_size * 2)
{
invalid:
__libdw_seterrno (DWARF_E_INVALID_DWARF);
@@ -415,42 +397,25 @@ dwarf_getlocation_addr (attr, address, llbufs, listlens, maxlocs)
Dwarf_Addr begin;
Dwarf_Addr end;
- if (attr->cu->address_size == 8)
- {
- begin = read_8ubyte_unaligned_inc (attr->cu->dbg, readp);
- end = read_8ubyte_unaligned_inc (attr->cu->dbg, readp);
-
- if (begin == (Elf64_Addr) -1l) /* Base address entry. */
- {
- base = end;
- if (unlikely (base == (Dwarf_Addr) -1))
- goto invalid;
- continue;
- }
- }
- else
- {
- begin = read_4ubyte_unaligned_inc (attr->cu->dbg, readp);
- end = read_4ubyte_unaligned_inc (attr->cu->dbg, readp);
-
- if (begin == (Elf32_Addr) -1) /* Base address entry. */
- {
- base = end;
- continue;
- }
- }
- if (begin == 0 && end == 0) /* End of list entry. */
+ int status
+ = __libdw_read_begin_end_pair_inc (attr->cu->dbg, IDX_debug_loc,
+ &readp, attr->cu->address_size,
+ &begin, &end, &base);
+ if (status == 2) /* End of list entry. */
break;
+ else if (status == 1) /* Base address selected. */
+ continue;
+ else if (status < 0)
+ return status;
- if ((unsigned char *) d->d_buf + d->d_size - readp < 2)
+ if (endp - readp < 2)
goto invalid;
/* We have a location expression. */
block.length = read_2ubyte_unaligned_inc (attr->cu->dbg, readp);
block.data = readp;
- if ((unsigned char *) d->d_buf + d->d_size - readp
- < (ptrdiff_t) block.length)
+ if (endp - readp < (ptrdiff_t) block.length)
goto invalid;
readp += block.length;
@@ -486,7 +451,8 @@ dwarf_getlocation_addr (attr, address, llbufs, listlens, maxlocs)
/* This one matches the address. */
if (llbufs != NULL
&& unlikely (getlocation (attr->cu, &block,
- &llbufs[got], &listlens[got]) != 0))
+ &llbufs[got], &listlens[got],
+ IDX_debug_loc) != 0))
return -1;
++got;
}