summaryrefslogtreecommitdiff
path: root/src/format/dwarf/abbrev.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/format/dwarf/abbrev.c')
-rw-r--r--src/format/dwarf/abbrev.c95
1 files changed, 69 insertions, 26 deletions
diff --git a/src/format/dwarf/abbrev.c b/src/format/dwarf/abbrev.c
index 2eec460..a9fee2c 100644
--- a/src/format/dwarf/abbrev.c
+++ b/src/format/dwarf/abbrev.c
@@ -41,13 +41,13 @@
void free_dwarf_abbrev(dw_abbrev *);
/* Charge une abréviations DWARF. */
-dw_abbrev *read_dwarf_abbreviations(dwarf_format *, off_t *, int64_t *);
+dw_abbrev *read_dwarf_abbreviations(dwarf_format *, off_t *, uint64_t *);
/* Recherche une abréviation DWARF donnée. */
const dw_abbrev *_find_dwarf_abbreviations(const dw_abbrev *, uint8_t *);
/* Lit la valeur d'un attribut DWARF. */
-bool _read_dwarf_abbrev_attribute(dwarf_format *, off_t *, DwarfForm, DwarfAttrib, ...);
+bool _read_dwarf_abbrev_attribute(dwarf_format *, off_t *, DwarfForm, ...);
@@ -80,7 +80,7 @@ bool load_dwarf_abbreviations(dwarf_format *format)
dw_abbrev *abbrev;
- int64_t index;
+ uint64_t index;
printf("Searching...\n");
@@ -202,13 +202,13 @@ void free_dwarf_abbrev(dw_abbrev *abbrev)
* *
******************************************************************************/
-dw_abbrev *read_dwarf_abbreviations(dwarf_format *format, off_t *pos, int64_t *index)
+dw_abbrev *read_dwarf_abbreviations(dwarf_format *format, off_t *pos, uint64_t *index)
{
dw_abbrev *result; /* Abréviation à retourner */
bool has_children; /* Indique la présence de fils */
- int64_t value1; /* Valeur quelconque lue #1 */
- int64_t value2; /* Valeur quelconque lue #2 */
- int64_t sub_index; /* Indice d'un sous-élément */
+ uint64_t value1; /* Valeur quelconque lue #1 */
+ uint64_t value2; /* Valeur quelconque lue #2 */
+ uint64_t sub_index; /* Indice d'un sous-élément */
dw_abbrev *child; /* Sous-élément à intégrer */
result = (dw_abbrev *)calloc(1, sizeof(dw_abbrev));
@@ -216,9 +216,9 @@ dw_abbrev *read_dwarf_abbreviations(dwarf_format *format, off_t *pos, int64_t *i
result->offset = *pos;
/* Code de l'élément */
- if (!read_leb128(format, pos, index)) goto rda_error;
+ if (!read_uleb128(format, pos, index, true)) goto rda_error;
- if (!read_leb128(format, pos, &value1)) goto rda_error;
+ if (!read_uleb128(format, pos, &value1, true)) goto rda_error;
result->tag = value1;
printf(" --ta :: 0x%02llx\n", value1);
@@ -232,8 +232,8 @@ dw_abbrev *read_dwarf_abbreviations(dwarf_format *format, off_t *pos, int64_t *i
while (DBG_FORMAT(format)->content[*pos] != 0x00)
{
- if (!read_leb128(format, pos, &value1)) goto rda_error;
- if (!read_leb128(format, pos, &value2)) goto rda_error;
+ if (!read_uleb128(format, pos, &value1, true)) goto rda_error;
+ if (!read_uleb128(format, pos, &value2, true)) goto rda_error;
result->attribs = (dw_abbrev_attr *)realloc(result->attribs, ++result->attribs_count * sizeof(dw_abbrev_attr));
@@ -305,11 +305,34 @@ const dw_abbrev *_find_dwarf_abbreviations(const dw_abbrev *abbrev, uint8_t *ind
}
+const dw_abbrev *find_dwarf_abbreviations_old(dwarf_format *format, const off_t *offset, uint8_t index)
+{
+ const dw_abbrev *result; /* Structure à retourner */
+ size_t i; /* Boucle de parcours */
+
+ if (index == 0) return NULL;
+
+ result = NULL;
+
+ for (i = 0; i < format->abbrevs_count; i++)
+ if (format->abbrevs[i]->offset == *offset) break;
+
+ if (i < format->abbrevs_count)
+ {
+ index--;
+ result = _find_dwarf_abbreviations(format->abbrevs[i], &index);
+ }
+
+ return result;
+
+}
+
+
/******************************************************************************
* *
* Paramètres : format = informations de débogage à consulter. *
* offset = position dans les abréviations. *
-* index = code de l'abréviation. *
+* pos = position dans le flux binaire courant. [OUT] *
* *
* Description : Recherche une abréviation DWARF donnée. *
* *
@@ -319,15 +342,24 @@ const dw_abbrev *_find_dwarf_abbreviations(const dw_abbrev *abbrev, uint8_t *ind
* *
******************************************************************************/
-const dw_abbrev *find_dwarf_abbreviations(dwarf_format *format, const off_t *offset, uint8_t index)
+const dw_abbrev *find_dwarf_abbreviations(dwarf_format *format, const off_t *offset, off_t *pos)
{
const dw_abbrev *result; /* Structure à retourner */
+ uint64_t index; /* Code de l'abréviation */
size_t i; /* Boucle de parcours */
- if (index == 0) return NULL;
-
result = NULL;
+ do
+ {
+ if (!read_uleb128(format, pos, &index, true))
+ {
+ printf("error skipping padding...\n");
+ return NULL;
+ }
+ }
+ while (index == 0);
+
for (i = 0; i < format->abbrevs_count; i++)
if (format->abbrevs[i]->offset == *offset) break;
@@ -347,7 +379,6 @@ const dw_abbrev *find_dwarf_abbreviations(dwarf_format *format, const off_t *off
* Paramètres : format = informations de débogage à compléter. *
* pos = tête de lecture à mettre à jour. [OUT] *
* form = format des données à lire. *
-* attrib = attribut visé par la lecture. *
* ... = lieu d'enregistrement ou NULL. [OUT] *
* *
* Description : Lit la valeur d'un attribut DWARF. *
@@ -358,7 +389,7 @@ const dw_abbrev *find_dwarf_abbreviations(dwarf_format *format, const off_t *off
* *
******************************************************************************/
-bool _read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, DwarfForm form, DwarfAttrib attrib, ...)
+bool _read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, DwarfForm form, ...)
{
bool result; /* Bilan à revoyer */
va_list ap; /* Adresse fournie en dernier */
@@ -376,7 +407,7 @@ bool _read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, DwarfForm fo
char **strval; /* Chaîne de caractères */
size_t length; /* Taille d'une chaîne */
- va_start(ap, attrib);
+ va_start(ap, form);
switch (form)
{
@@ -486,11 +517,12 @@ bool _read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, DwarfForm fo
if (strval != NULL)
(*strval)[length] = 0;
+
}
- else
+ else if (strval != NULL)
{
- if (strval != NULL)
- free(*strval);
+ free(*strval);
+ *strval = NULL;
}
}
@@ -498,7 +530,7 @@ bool _read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, DwarfForm fo
break;
case DWF_BLOCK:
- result = read_uleb128(format, pos, &size_to_read);
+ result = read_uleb128(format, pos, &size_to_read, true);
result &= ((*pos + size_to_read) <= DBG_FORMAT(format)->length);
if (result)
{
@@ -550,6 +582,11 @@ bool _read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, DwarfForm fo
result = read_abbrev_offset(format, pos, &offset);
if (result)
{
+ if (va_arg(ap, bool *) != NULL)
+ {
+ printf("TODO\n");
+ exit(0);
+ }
/*
boolval = va_arg(ap, bool *);
if (boolval != NULL) *boolval = (DBG_FORMAT(format)->content[*pos] != 0x00);
@@ -649,6 +686,7 @@ bool _read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, DwarfForm fo
* *
* Paramètres : format = informations de débogage à compléter. *
* pos = tête de lecture à mettre à jour. [OUT] *
+* update = indique si la position est à mettre à jour. *
* abbrev = informations à parcourir. *
* attrib = attribut visé par la lecture. *
* ... = lieu d'enregistrement ou NULL. [OUT] *
@@ -661,24 +699,27 @@ bool _read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, DwarfForm fo
* *
******************************************************************************/
-bool read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, const dw_abbrev *abbrev, DwarfAttrib attrib, ...)
+bool read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, bool update, const dw_abbrev *abbrev, DwarfAttrib attrib, ...)
{
bool result; /* Bilan à retourner */
+ off_t curpos; /* Tête de lecture effective */
size_t i; /* Boucle de parcours */
va_list ap; /* Adresse fournie en dernier */
result = true;
+ curpos = *pos;
+
for (i = 0; i < abbrev->attribs_count && result; i++)
if (abbrev->attribs[i].attrib == attrib) break;
- else result = _read_dwarf_abbrev_attribute(format, pos, abbrev->attribs[i].form, abbrev->attribs[i].attrib, NULL);
+ else result = _read_dwarf_abbrev_attribute(format, &curpos, abbrev->attribs[i].form, NULL);
if (result)
{
va_start(ap, attrib);
if (i < abbrev->attribs_count)
- result = _read_dwarf_abbrev_attribute(format, pos, abbrev->attribs[i].form, attrib, va_arg(ap, void *));
+ result = _read_dwarf_abbrev_attribute(format, &curpos, abbrev->attribs[i].form, va_arg(ap, void *));
else
result = false;
@@ -686,6 +727,8 @@ bool read_dwarf_abbrev_attribute(dwarf_format *format, off_t *pos, const dw_abbr
}
+ if (result && update) *pos = curpos;
+
return result;
}
@@ -713,7 +756,7 @@ bool skip_dwarf_abbrev(dwarf_format *format, off_t *pos, const dw_abbrev *abbrev
result = true;
for (i = 0; i < abbrev->attribs_count && result; i++)
- result = _read_dwarf_abbrev_attribute(format, pos, abbrev->attribs[i].form, abbrev->attribs[i].attrib, NULL);
+ result = _read_dwarf_abbrev_attribute(format, pos, abbrev->attribs[i].form, NULL);
return result;