[RFC PATCH 02/10] Add debuginfo interface for enum type size

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

 



This is needed in this patch set to determine whether or not a certain
enumeration type exists from a given debuginfo. The interface is a
simple extension from the existing one for enumeration value.

Signed-off-by: HATAYAMA Daisuke <d.hatayama at jp.fujitsu.com>
---

 dwarf_info.c   |   29 +++++++++++++++++++++--------
 dwarf_info.h   |    1 +
 makedumpfile.h |   13 +++++++++++--
 3 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/dwarf_info.c b/dwarf_info.c
index 1429858..98efc26 100644
--- a/dwarf_info.c
+++ b/dwarf_info.c
@@ -75,7 +75,8 @@ is_search_structure(int cmd)
 static int
 is_search_number(int cmd)
 {
-	if (cmd == DWARF_INFO_GET_ENUM_NUMBER)
+	if ((cmd == DWARF_INFO_GET_ENUM_NUMBER)
+	    || (cmd == DWARF_INFO_GET_ENUMERATION_TYPE_SIZE))
 		return TRUE;
 	else
 		return FALSE;
@@ -647,7 +648,7 @@ search_structure(Dwarf_Die *die, int *found)
 static void
 search_number(Dwarf_Die *die, int *found)
 {
-	int tag;
+	int tag, bytesize;
 	Dwarf_Word const_value;
 	Dwarf_Attribute attr;
 	Dwarf_Die child, *walker;
@@ -658,6 +659,22 @@ search_number(Dwarf_Die *die, int *found)
 		if (tag != DW_TAG_enumeration_type)
 			continue;
 
+		if (dwarf_info.cmd == DWARF_INFO_GET_ENUMERATION_TYPE_SIZE) {
+			name = dwarf_diename(die);
+
+			if (!name || strcmp(name, dwarf_info.struct_name))
+				continue;
+
+			if ((bytesize = dwarf_bytesize(die)) <= 0)
+				continue;
+
+			*found = TRUE;
+
+			dwarf_info.struct_size = bytesize;
+
+			return;
+		}
+
 		if (dwarf_child(die, &child) != 0)
 			continue;
 
@@ -1026,13 +1043,9 @@ out:
  * Get the size of structure.
  */
 long
-get_structure_size(char *structname, int flag_typedef)
+get_structure_size(char *structname, int cmd)
 {
-	if (flag_typedef)
-		dwarf_info.cmd = DWARF_INFO_GET_TYPEDEF_SIZE;
-	else
-		dwarf_info.cmd = DWARF_INFO_GET_STRUCT_SIZE;
-
+	dwarf_info.cmd = cmd;
 	dwarf_info.struct_name = structname;
 	dwarf_info.struct_size = NOT_FOUND_STRUCTURE;
 
diff --git a/dwarf_info.h b/dwarf_info.h
index 1e07484..b445738 100644
--- a/dwarf_info.h
+++ b/dwarf_info.h
@@ -47,6 +47,7 @@ enum {
 	DWARF_INFO_CHECK_SYMBOL_ARRAY_TYPE,
 	DWARF_INFO_GET_SYMBOL_TYPE,
 	DWARF_INFO_GET_MEMBER_TYPE,
+	DWARF_INFO_GET_ENUMERATION_TYPE_SIZE,
 };
 
 char *get_dwarf_module_name(void);
diff --git a/makedumpfile.h b/makedumpfile.h
index 6f5489d..95c0abc 100644
--- a/makedumpfile.h
+++ b/makedumpfile.h
@@ -225,14 +225,23 @@ do { \
 #define ARRAY_LENGTH(X)		(array_table.X)
 #define SIZE_INIT(X, Y) \
 do { \
-	if ((SIZE(X) = get_structure_size(Y, 0)) == FAILED_DWARFINFO) \
+	if ((SIZE(X) = get_structure_size(Y, DWARF_INFO_GET_STRUCT_SIZE)) \
+	     == FAILED_DWARFINFO) \
 		return FALSE; \
 } while (0)
 #define TYPEDEF_SIZE_INIT(X, Y) \
 do { \
-	if ((SIZE(X) = get_structure_size(Y, 1)) == FAILED_DWARFINFO) \
+	if ((SIZE(X) = get_structure_size(Y, DWARF_INFO_GET_TYPEDEF_SIZE)) \
+	     == FAILED_DWARFINFO) \
 		return FALSE; \
 } while (0)
+#define ENUM_TYPE_SIZE_INIT(X, Y) \
+do { \
+	if ((SIZE(X) = get_structure_size(Y,	\
+		DWARF_INFO_GET_ENUMERATION_TYPE_SIZE))	\
+	     == FAILED_DWARFINFO)			\
+ 		return FALSE; \
+ } while (0)
 #define OFFSET_INIT(X, Y, Z) \
 do { \
 	if ((OFFSET(X) = get_member_offset(Y, Z, DWARF_INFO_GET_MEMBER_OFFSET)) \




[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux