[ltrace-commits] 04/07: In Dwarf prototype provider, represent unions as character arrays

Petr Machata pmachata-guest at moszumanska.debian.org
Fri Jan 16 19:32:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

pmachata-guest pushed a commit to branch master
in repository ltrace.

commit 28d6400b322ad09706bbb2a09d2ca33eff263e1a
Author: Petr Machata <pmachata at redhat.com>
Date:   Fri Jan 16 18:34:35 2015 +0100

    In Dwarf prototype provider, represent unions as character arrays
---
 dwarf_prototypes.c | 54 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 45 insertions(+), 9 deletions(-)

diff --git a/dwarf_prototypes.c b/dwarf_prototypes.c
index de7d6c2..bfac177 100644
--- a/dwarf_prototypes.c
+++ b/dwarf_prototypes.c
@@ -14,18 +14,19 @@
 #include <string.h>
 
 #include "config.h"
-#include "prototype.h"
-#include "type.h"
-#include "param.h"
+#include "debug.h"
 #include "dict.h"
+#include "expr.h"
+#include "filter.h"
 #include "lens.h"
+#include "lens_default.h"
 #include "lens_enum.h"
-#include "value.h"
-#include "expr.h"
 #include "library.h"
 #include "options.h"
-#include "filter.h"
-#include "debug.h"
+#include "param.h"
+#include "prototype.h"
+#include "type.h"
+#include "value.h"
 
 #define complain(die, format, ...)					\
 	debug(DEBUG_FUNCTION, "%s() die '%s' @ 0x%" PRIx64 ": " format, \
@@ -808,10 +809,45 @@ static struct arg_type_info *get_type(int *newly_allocated_result,
 		return result;
 
 	case DW_TAG_union_type:
-		result = type_get_simple(ARGTYPE_VOID);
-		complain(type_die, "Storing union-as-void type");
+	{
+		uint64_t sz;
+		if (! get_die_numeric(&sz, type_die, DW_AT_byte_size)) {
+			complain(type_die, "Can't determine type size");
+			CLEANUP_AND_RETURN_ERROR(NULL);
+
+		} else if (sz != (uint64_t) (unsigned long) sz) {
+			complain(type_die, "Union size too big");
+			CLEANUP_AND_RETURN_ERROR(NULL);
+
+		} else {
+			complain(type_die, "Storing union as byte array");
+
+			*newly_allocated_result = 1;
+
+			/* Allocate the array type and its element
+			 * type in one bunch.  */
+			result = calloc(2, sizeof *result);
+			struct expr_node *len_expr = calloc(1, sizeof *len_expr);
+			if (result == NULL || len_expr == NULL) {
+				complain(type_die, "alloc error");
+				free(result);
+				free(len_expr);
+				CLEANUP_AND_RETURN_ERROR(NULL);
+			}
+
+			result[1].type = ARGTYPE_CHAR;
+			result[1].lens = &hex_lens;
+			result[1].own_lens = 0;
+
+			expr_init_const_word(len_expr, (unsigned long) sz,
+					     type_get_simple(ARGTYPE_ULONG), 0);
+
+			/* Don't own element type, own length.  */
+			type_init_array(&result[0], &result[1], 0, len_expr, 1);
+		}
 		DICT_INSERT_AND_CHECK(type_dieoffset_hash, &die_offset, &result);
 		return result;
+	}
 
 	default:
 		complain(type_die, "Unknown type tag 0x%x. Returning void",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/ltrace.git



More information about the ltrace-commits mailing list