Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/libdwarf/dist sync with FreeBSD



details:   https://anonhg.NetBSD.org/src/rev/1581ead0930b
branches:  trunk
changeset: 784087:1581ead0930b
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 17 22:03:02 2013 +0000

description:
sync with FreeBSD

diffstat:

 external/bsd/libdwarf/dist/Makefile     |   11 +-
 external/bsd/libdwarf/dist/dwarf.h      |    5 +-
 external/bsd/libdwarf/dist/dwarf_func.c |  230 ++++++++++++++++++++++++++++++++
 external/bsd/libdwarf/dist/libdwarf.h   |   18 ++-
 4 files changed, 254 insertions(+), 10 deletions(-)

diffs (truncated from 344 to 300 lines):

diff -r 4966236ae5e0 -r 1581ead0930b external/bsd/libdwarf/dist/Makefile
--- a/external/bsd/libdwarf/dist/Makefile       Thu Jan 17 21:53:14 2013 +0000
+++ b/external/bsd/libdwarf/dist/Makefile       Thu Jan 17 22:03:02 2013 +0000
@@ -1,4 +1,4 @@
-# $FreeBSD: src/lib/libdwarf/Makefile,v 1.2.2.1 2009/08/03 08:13:06 kensmith Exp $
+# $FreeBSD: src/lib/libdwarf/Makefile,v 1.7 2012/11/17 01:49:48 svnexp Exp $
 
 LIB=   dwarf
 
@@ -14,17 +14,16 @@
        dwarf_errno.c           \
        dwarf_finish.c          \
        dwarf_form.c            \
+       dwarf_func.c            \
        dwarf_init.c            \
        dwarf_loc.c
 
 INCS=  dwarf.h libdwarf.h
 
-CFLAGS+=       -I. -I${.CURDIR}
-
-SHLIB_MAJOR=   2
+CFLAGS+=       -I${.CURDIR}
 
-WARNS?=        6
+SHLIB_MAJOR=   3
 
-WITHOUT_MAN=   yes
+WITHOUT_MAN=
 
 .include <bsd.lib.mk>
diff -r 4966236ae5e0 -r 1581ead0930b external/bsd/libdwarf/dist/dwarf.h
--- a/external/bsd/libdwarf/dist/dwarf.h        Thu Jan 17 21:53:14 2013 +0000
+++ b/external/bsd/libdwarf/dist/dwarf.h        Thu Jan 17 22:03:02 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dwarf.h,v 1.1.1.1 2009/12/23 00:03:27 darran Exp $     */
+/*     $NetBSD: dwarf.h,v 1.1.1.2 2013/01/17 22:03:02 christos Exp $   */
 
 /*-
  * Copyright (c) 2007 John Birrell (jb%freebsd.org@localhost)
@@ -25,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libdwarf/dwarf.h,v 1.1.4.1 2009/08/03 08:13:06 kensmith Exp $
+ * $FreeBSD: src/lib/libdwarf/dwarf.h,v 1.3 2012/11/17 01:49:48 svnexp Exp $
  */
 
 #ifndef        _DWARF_H_
@@ -186,6 +186,7 @@
 #define DW_FORM_ref8                   0x14
 #define DW_FORM_ref_udata              0x15
 #define DW_FORM_indirect               0x16
+#define DW_FORM_flag_present           0x19
 
 #define DW_OP_addr                     0x03
 #define DW_OP_deref                    0x06
diff -r 4966236ae5e0 -r 1581ead0930b external/bsd/libdwarf/dist/dwarf_func.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/libdwarf/dist/dwarf_func.c   Thu Jan 17 22:03:02 2013 +0000
@@ -0,0 +1,230 @@
+/*     $NetBSD: dwarf_func.c,v 1.1.1.1 2013/01/17 22:03:02 christos Exp $      */
+
+/*-
+ * Copyright (c) 2008-2009, 2011, Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *     JNPR: dwarf_func.c 336441 2009-10-17 09:19:54Z deo
+ */
+
+#include <sys/cdefs.h>
+/* __FBSDID("$FreeBSD: src/lib/libdwarf/dwarf_func.c,v 1.2 2012/11/17 01:49:48 svnexp Exp $"); */
+__RCSID("$NetBSD: dwarf_func.c,v 1.1.1.1 2013/01/17 22:03:02 christos Exp $");
+
+#include <stdlib.h>
+#include <string.h>
+#include <libdwarf.h>
+#include <_libdwarf.h>
+
+static void
+dwarf_add_function(Dwarf_Debug dbg, Dwarf_Func func)
+{
+
+       STAILQ_INSERT_TAIL(&dbg->dbg_func, func, func_next);
+}
+
+int
+dwarf_function_get_addr_range(Dwarf_Func f, Dwarf_Addr *low_pc,
+    Dwarf_Addr *high_pc)
+{
+
+       *low_pc = f->func_low_pc;
+       *high_pc = f->func_high_pc;
+       return 0;
+}
+
+int
+dwarf_inlined_function_get_addr_range(Dwarf_Inlined_Func f, Dwarf_Addr *low_pc,
+    Dwarf_Addr *high_pc)
+{
+
+       *low_pc = f->ifunc_low_pc;
+       *high_pc = f->ifunc_high_pc;
+       return 0;
+}
+
+int
+dwarf_function_is_inlined(Dwarf_Func f)
+{
+
+       if (f->func_is_inlined == DW_INL_inlined ||
+           f->func_is_inlined == DW_INL_declared_inlined)
+               return 1;
+       else
+               return 0;
+}
+
+Dwarf_Func
+dwarf_find_function_by_name(Dwarf_Debug dbg, const char *name)
+{
+       /* XXX: replace with a fast version */
+
+       Dwarf_Func func;
+       STAILQ_FOREACH(func, &dbg->dbg_func, func_next) {
+               if (strcmp(name, func->func_name) == 0)
+                       return func;
+       }
+       return NULL;
+}
+
+Dwarf_Func
+dwarf_find_function_by_offset(Dwarf_Debug dbg, Dwarf_Off off)
+{
+
+       Dwarf_Func func;
+       Dwarf_Die die;
+       /* printf("look for %llx\n", off); */
+       STAILQ_FOREACH(func, &dbg->dbg_func, func_next) {
+               die = func->func_die;
+               if ((off_t)die->die_offset == off) {
+                       return func;
+               }
+       }
+       return NULL;
+}
+
+void
+dwarf_build_function_table(Dwarf_Debug dbg)
+{
+       Dwarf_CU cu;
+       Dwarf_AttrValue av;
+       Dwarf_Die die, origin_die;
+       Dwarf_Func func, origin_func;
+       Dwarf_Inlined_Func ifunc;
+       unsigned long long offset;
+       const char *name;
+       Dwarf_Error error;
+
+       /*
+        * find out all the functions
+        */
+       STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) {
+               STAILQ_FOREACH(die, &cu->cu_die, die_next) {
+                       if (die->die_a->a_tag == DW_TAG_subprogram) {
+                               /*
+                                * Some function has multiple entries, i.e.
+                                * if a function is inlined, it has many
+                                * abstract/concrete instances, the abstract
+                                * instances are with DW_TAG_subprogram.
+                                */
+                               dwarf_attrval_string(die, DW_AT_name, &name,
+                                   &error);
+                               func = dwarf_find_function_by_name(dbg, name);
+                               if (func == NULL) {
+                                       func = malloc(
+                                           sizeof(struct _Dwarf_Func));
+                                       DWARF_ASSERT(func);
+
+                                       func->func_die = die;
+                                       func->func_name = name;
+                                       STAILQ_INIT(
+                                           &func->func_inlined_instances);
+
+                                       dwarf_add_function(dbg, func);
+                                       STAILQ_FOREACH(av, &die->die_attrval,
+                                           av_next) {
+                                               switch (av->av_attrib) {
+                                               case DW_AT_low_pc:
+                                                       func->func_low_pc =
+                                                           av->u[0].u64;
+                                                       break;
+                                               case DW_AT_high_pc:
+                                                       func->func_high_pc =
+                                                           av->u[0].u64;
+                                                       break;
+                                               case DW_AT_inline:
+                                                       func->func_is_inlined =
+                                                           av->u[0].u64;
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /*
+        * Now check the concrete inlined instances.
+        */
+       STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) {
+               STAILQ_FOREACH(die, &cu->cu_die, die_next) {
+                       if (die->die_a->a_tag == DW_TAG_inlined_subroutine) {
+                               ifunc = malloc(
+                                   sizeof(struct _Dwarf_Inlined_Func));
+                               DWARF_ASSERT(ifunc);
+                               STAILQ_FOREACH(av, &die->die_attrval, av_next) {
+                                       switch (av->av_attrib) {
+                                       case DW_AT_abstract_origin:
+                                               offset = av->u[0].u64 +
+                                                   die->die_cu->cu_offset;
+                                               origin_die = dwarf_die_find(
+                                                       die, offset);
+                                               DWARF_ASSERT(origin_die != 0);
+
+                                               /*
+                                                * the abstract origin must
+                                                * have been merged with
+                                                * another die
+                                                */
+                                               dwarf_attrval_string(
+                                                   origin_die, DW_AT_name,
+                                                   &name, &error);
+                                               origin_func =
+                                                   dwarf_find_function_by_name
+                                                   (dbg, name);
+                                               DWARF_ASSERT(origin_func != 0);
+
+                                               STAILQ_INSERT_TAIL(
+                                                   &origin_func->
+                                                   func_inlined_instances,
+                                                   ifunc, ifunc_next);
+
+                                               break;
+                                       case DW_AT_low_pc:
+                                               ifunc->ifunc_low_pc =
+                                                   av->u[0].u64;
+                                               break;
+                                       case DW_AT_high_pc:
+                                               ifunc->ifunc_high_pc =
+                                                   av->u[0].u64;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
+void
+dwarf_function_iterate_inlined_instance(Dwarf_Func func,
+    Dwarf_Inlined_Callback f, void *data)
+{
+       Dwarf_Inlined_Func ifunc;
+
+       if (!dwarf_function_is_inlined(func))
+               return;
+       STAILQ_FOREACH(ifunc, &func->func_inlined_instances, ifunc_next) {
+               f(ifunc, data);
+       }
+}
diff -r 4966236ae5e0 -r 1581ead0930b external/bsd/libdwarf/dist/libdwarf.h
--- a/external/bsd/libdwarf/dist/libdwarf.h     Thu Jan 17 21:53:14 2013 +0000
+++ b/external/bsd/libdwarf/dist/libdwarf.h     Thu Jan 17 22:03:02 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: libdwarf.h,v 1.1.1.1 2009/12/23 00:03:27 darran Exp $  */
+/*     $NetBSD: libdwarf.h,v 1.1.1.2 2013/01/17 22:03:03 christos Exp $        */
 
 /*-
  * Copyright (c) 2007 John Birrell (jb%freebsd.org@localhost)



Home | Main Index | Thread Index | Old Index