aboutsummaryrefslogtreecommitdiff
path: root/libdwarf/dwarf_cu.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdwarf/dwarf_cu.c')
-rw-r--r--libdwarf/dwarf_cu.c92
1 files changed, 77 insertions, 15 deletions
diff --git a/libdwarf/dwarf_cu.c b/libdwarf/dwarf_cu.c
index c203dc2f1fc7..d103488d1098 100644
--- a/libdwarf/dwarf_cu.c
+++ b/libdwarf/dwarf_cu.c
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2007 John Birrell (jb@freebsd.org)
+ * Copyright (c) 2014 Kai Wang
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -26,14 +27,15 @@
#include "_libdwarf.h"
-ELFTC_VCSID("$Id: dwarf_cu.c 2072 2011-10-27 03:26:49Z jkoshy $");
+ELFTC_VCSID("$Id: dwarf_cu.c 3041 2014-05-18 15:11:03Z kaiwang27 $");
int
-dwarf_next_cu_header_b(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
- Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset,
- Dwarf_Half *cu_pointer_size, Dwarf_Half *cu_offset_size,
- Dwarf_Half *cu_extension_size, Dwarf_Unsigned *cu_next_offset,
- Dwarf_Error *error)
+dwarf_next_cu_header_c(Dwarf_Debug dbg, Dwarf_Bool is_info,
+ Dwarf_Unsigned *cu_length, Dwarf_Half *cu_version,
+ Dwarf_Off *cu_abbrev_offset, Dwarf_Half *cu_pointer_size,
+ Dwarf_Half *cu_offset_size, Dwarf_Half *cu_extension_size,
+ Dwarf_Sig8 *type_signature, Dwarf_Unsigned *type_offset,
+ Dwarf_Unsigned *cu_next_offset, Dwarf_Error *error)
{
Dwarf_CU cu;
int ret;
@@ -43,10 +45,17 @@ dwarf_next_cu_header_b(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
return (DW_DLV_ERROR);
}
- if (dbg->dbg_cu_current == NULL)
- ret = _dwarf_info_first_cu(dbg, error);
- else
- ret = _dwarf_info_next_cu(dbg, error);
+ if (is_info) {
+ if (dbg->dbg_cu_current == NULL)
+ ret = _dwarf_info_first_cu(dbg, error);
+ else
+ ret = _dwarf_info_next_cu(dbg, error);
+ } else {
+ if (dbg->dbg_tu_current == NULL)
+ ret = _dwarf_info_first_tu(dbg, error);
+ else
+ ret = _dwarf_info_next_tu(dbg, error);
+ }
if (ret == DW_DLE_NO_ENTRY) {
DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
@@ -54,11 +63,19 @@ dwarf_next_cu_header_b(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
} else if (ret != DW_DLE_NONE)
return (DW_DLV_ERROR);
- if (dbg->dbg_cu_current == NULL) {
- DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
- return (DW_DLV_NO_ENTRY);
+ if (is_info) {
+ if (dbg->dbg_cu_current == NULL) {
+ DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
+ return (DW_DLV_NO_ENTRY);
+ }
+ cu = dbg->dbg_cu_current;
+ } else {
+ if (dbg->dbg_tu_current == NULL) {
+ DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
+ return (DW_DLV_NO_ENTRY);
+ }
+ cu = dbg->dbg_tu_current;
}
- cu = dbg->dbg_cu_current;
if (cu_length)
*cu_length = cu->cu_length;
@@ -81,11 +98,32 @@ dwarf_next_cu_header_b(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
*cu_extension_size = 4;
}
if (cu_next_offset)
- *cu_next_offset = dbg->dbg_cu_current->cu_next_offset;
+ *cu_next_offset = cu->cu_next_offset;
+
+ if (!is_info) {
+ if (type_signature)
+ *type_signature = cu->cu_type_sig;
+ if (type_offset)
+ *type_offset = cu->cu_type_offset;
+ }
return (DW_DLV_OK);
}
+
+int
+dwarf_next_cu_header_b(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
+ Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset,
+ Dwarf_Half *cu_pointer_size, Dwarf_Half *cu_offset_size,
+ Dwarf_Half *cu_extension_size, Dwarf_Unsigned *cu_next_offset,
+ Dwarf_Error *error)
+{
+
+ return (dwarf_next_cu_header_c(dbg, 1, cu_length, cu_version,
+ cu_abbrev_offset, cu_pointer_size, cu_offset_size,
+ cu_extension_size, NULL, NULL, cu_next_offset, error));
+}
+
int
dwarf_next_cu_header(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset,
@@ -97,3 +135,27 @@ dwarf_next_cu_header(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,
cu_abbrev_offset, cu_pointer_size, NULL, NULL, cu_next_offset,
error));
}
+
+int
+dwarf_next_types_section(Dwarf_Debug dbg, Dwarf_Error *error)
+{
+
+ /* Free resource allocated for current .debug_types section. */
+ _dwarf_type_unit_cleanup(dbg);
+ dbg->dbg_types_loaded = 0;
+ dbg->dbg_types_off = 0;
+
+ /* Reset type unit pointer. */
+ dbg->dbg_tu_current = NULL;
+
+ /* Search for the next .debug_types section. */
+ dbg->dbg_types_sec = _dwarf_find_next_types_section(dbg,
+ dbg->dbg_types_sec);
+
+ if (dbg->dbg_types_sec == NULL) {
+ DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
+ return (DW_DLV_NO_ENTRY);
+ }
+
+ return (DW_DLV_OK);
+}