summaryrefslogtreecommitdiff
path: root/src/format/dwarf/info.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2016-03-14 22:18:27 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2016-03-14 22:18:27 (GMT)
commitfab9d7cd46922abea7d94f36dcd4630cdf3f4719 (patch)
treead41bb921db17631104a069e4df64fb4fc5ccfc1 /src/format/dwarf/info.c
parent8d8e5c02096f59a7227308a591fc5050ea5d92ff (diff)
Improved the basic support of Dwarf information.
Diffstat (limited to 'src/format/dwarf/info.c')
-rw-r--r--src/format/dwarf/info.c165
1 files changed, 165 insertions, 0 deletions
diff --git a/src/format/dwarf/info.c b/src/format/dwarf/info.c
index 8106114..4ef6484 100644
--- a/src/format/dwarf/info.c
+++ b/src/format/dwarf/info.c
@@ -24,6 +24,170 @@
#include "info.h"
+#include "die.h"
+#include "dwarf-int.h"
+#include "../debuggable-int.h"
+
+
+
+
+
+static bool extract_dies_from_debug_information(GDwarfFormat *format, vmpa2t *pos, SourceEndian endian, const dw_compil_unit_header *header, dw_die *parent, dw_die **die);
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations de débogage DWARF à compléter. *
+* *
+* Description : Charge les informations depuis une section ".debug_info". *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool load_dwarf_debug_information(GDwarfFormat *format)
+{
+ bool result; /* Bilan à renvoyer */
+
+
+
+ mrange_t range; /* Couverture d'une section */
+ vmpa2t end;
+ vmpa2t iter; /* Tête de lecture mouvante */
+
+ dw_compil_unit_header header;
+ dw_die *die;
+
+
+
+ result = g_exe_format_get_section_range_by_name(G_DBG_FORMAT(format)->executable, ".debug_info", &range);
+ if (!result) goto lddi_exit;
+
+ copy_vmpa(&iter, get_mrange_addr(&range));
+
+
+ printf("[%d] Passage :: 0x%08llx 0x%08llx\n",
+ result,
+ (unsigned long long)range.addr.physical,
+ (unsigned long long)range.addr.virtual);
+
+ compute_mrange_end_addr(&range, &end);
+
+ while (result)
+ {
+ /* Si il n'y a plus rien à lire dans la section... */
+ if (cmp_vmpa(&iter, &end) >= 0) break;
+
+
+ printf("========================================================================\n");
+ printf("========================================================================\n");
+ printf("========================================================================\n");
+ printf("========================================================================\n");
+ printf("\n");
+ printf("HEADER START :: 0x%x\n", (unsigned int)iter.physical);
+
+
+ result = read_dwarf_compil_unit_header(G_BIN_FORMAT(format)->content, &iter,
+ SRE_LITTLE /* FIXME */, &header);
+ if (!result) break;
+
+ printf("[%d] header :: addr size=%hhu\n", result, header.address_size);
+
+
+ result = extract_dies_from_debug_information(format, &iter,
+ SRE_LITTLE /* FIXME */, &header,
+ NULL, &die);
+
+
+
+ }
+
+
+ format->info_die = die;
+
+
+ lddi_exit:
+
+ return result;
+
+}
+
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations de débogage DWARF à compléter. *
+* pos = position de début de lecture. [OUT] *
+* endian = boutisme reconnu dans le format. *
+* header = en-tête de description de l'unité à traiter. *
+* parent = entrée parent de rattachement ou NULL si racine. *
+* die = emplacement de stockage de l'entrée. [OUT] *
+* *
+* Description : Procède à la lecture de l'en-tête d'un contenu binaire DWARF.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool extract_dies_from_debug_information(GDwarfFormat *format, vmpa2t *pos, SourceEndian endian, const dw_compil_unit_header *header, dw_die *parent, dw_die **die)
+{
+ bool result; /* Bilan à faire remonter */
+ dw_die *child; /* Entrée subordonnée à charger*/
+
+ printf("==================================\n");
+ printf("=== version : 0x%hx\n", header->version);
+ printf("=== offset abbrev : 0x%llx\n", (unsigned long long)header->debug_abbrev_offset);
+ printf("==================================\n");
+
+
+ phys_t start = 0x1039;
+
+ printf("start :: 0x%x\n", (unsigned int)(pos->physical - start));
+ printf("start :: 0x%x\n", (unsigned int)(0x0 + pos->physical));
+
+ result = build_dwarf_die(format, pos, SRE_LITTLE /* FIXME */, header, die);
+ if (*die == NULL) return result;
+
+ if (parent != NULL)
+ dw_die_append_child(parent, *die);
+
+ if (dw_die_has_children(*die))
+ {
+ printf("<<<< children >>>>\n");
+
+ printf("next :: 0x%x\n", (unsigned int)(pos->physical - start));
+
+ while (result)
+ {
+ result = extract_dies_from_debug_information(format, pos, endian, header, *die, &child);
+
+ if (!result)
+ delete_dwarf_die(*die);
+
+ /* Entrée avec un code nul -> fin */
+ if (child == NULL) break;
+
+ }
+
+ }
+
+ return result;
+
+}
+
+
+
+
+
+
+
+#if 0
#include <malloc.h>
#include <string.h>
@@ -686,3 +850,4 @@ char *resolve_dwarf_function_type(dwarf_format *format, const dw_abbrev *abbrev,
return result;
}
+#endif