Commit f08649c0 by Pierre-Marie de Rodat Committed by Pierre-Marie de Rodat

Add a few debug utilities for DWARF expressions

	* dwarf2out.c (print_loc_descr): New.
	(print_dw_val): New.
	(print_attribute): New.
	(print_loc_descr): New.
	(print_die): Use print_dw_val.
	(debug_dwarf_loc_descr): New.
	* dwarf2out.h (debug_dwarf_loc_descr): New declaration.

From-SVN: r218826
parent ce37c297
2014-12-17 Pierre-Marie de Rodat <derodat@adacore.com> 2014-12-17 Pierre-Marie de Rodat <derodat@adacore.com>
* dwarf2out.c (print_loc_descr): New.
(print_dw_val): New.
(print_attribute): New.
(print_loc_descr): New.
(print_die): Use print_dw_val.
(debug_dwarf_loc_descr): New.
* dwarf2out.h (debug_dwarf_loc_descr): New declaration.
2014-12-17 Pierre-Marie de Rodat <derodat@adacore.com>
* dwarf2out.c (gen_type_die_with_usage): Enable the array lang-hook * dwarf2out.c (gen_type_die_with_usage): Enable the array lang-hook
even when (dwarf_version < 3 && dwarf_strict). even when (dwarf_version < 3 && dwarf_strict).
(gen_descr_array_die): Do not output DW_AT_data_locationn, (gen_descr_array_die): Do not output DW_AT_data_locationn,
...@@ -5370,39 +5370,15 @@ print_signature (FILE *outfile, char *sig) ...@@ -5370,39 +5370,15 @@ print_signature (FILE *outfile, char *sig)
fprintf (outfile, "%02x", sig[i] & 0xff); fprintf (outfile, "%02x", sig[i] & 0xff);
} }
/* Print the information associated with a given DIE, and its children. static void print_loc_descr (dw_loc_descr_ref, FILE *);
This routine is a debugging aid only. */
/* Print the value associated to the VAL DWARF value node to OUTFILE. If
RECURSE, output location descriptor operations. */
static void static void
print_die (dw_die_ref die, FILE *outfile) print_dw_val (dw_val_node *val, bool recurse, FILE *outfile)
{ {
dw_attr_ref a; switch (val->val_class)
dw_die_ref c;
unsigned ix;
print_spaces (outfile);
fprintf (outfile, "DIE %4ld: %s (%p)\n",
die->die_offset, dwarf_tag_name (die->die_tag),
(void*) die);
print_spaces (outfile);
fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
fprintf (outfile, " offset: %ld", die->die_offset);
fprintf (outfile, " mark: %d\n", die->die_mark);
if (die->comdat_type_p)
{
print_spaces (outfile);
fprintf (outfile, " signature: ");
print_signature (outfile, die->die_id.die_type_node->signature);
fprintf (outfile, "\n");
}
FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
{
print_spaces (outfile);
fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
switch (AT_class (a))
{ {
case dw_val_class_addr: case dw_val_class_addr:
fprintf (outfile, "address"); fprintf (outfile, "address");
...@@ -5412,38 +5388,49 @@ print_die (dw_die_ref die, FILE *outfile) ...@@ -5412,38 +5388,49 @@ print_die (dw_die_ref die, FILE *outfile)
break; break;
case dw_val_class_loc: case dw_val_class_loc:
fprintf (outfile, "location descriptor"); fprintf (outfile, "location descriptor");
if (val->v.val_loc == NULL)
fprintf (outfile, " -> <null>\n");
else if (recurse)
{
fprintf (outfile, ":\n");
print_indent += 4;
print_loc_descr (val->v.val_loc, outfile);
print_indent -= 4;
}
else
fprintf (outfile, " (%p)\n", (void *) val->v.val_loc);
break; break;
case dw_val_class_loc_list: case dw_val_class_loc_list:
fprintf (outfile, "location list -> label:%s", fprintf (outfile, "location list -> label:%s",
AT_loc_list (a)->ll_symbol); val->v.val_loc_list->ll_symbol);
break; break;
case dw_val_class_range_list: case dw_val_class_range_list:
fprintf (outfile, "range list"); fprintf (outfile, "range list");
break; break;
case dw_val_class_const: case dw_val_class_const:
fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a)); fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, val->v.val_int);
break; break;
case dw_val_class_unsigned_const: case dw_val_class_unsigned_const:
fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a)); fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, val->v.val_unsigned);
break; break;
case dw_val_class_const_double: case dw_val_class_const_double:
fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\ fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
HOST_WIDE_INT_PRINT_UNSIGNED")", HOST_WIDE_INT_PRINT_UNSIGNED")",
a->dw_attr_val.v.val_double.high, val->v.val_double.high,
a->dw_attr_val.v.val_double.low); val->v.val_double.low);
break; break;
case dw_val_class_wide_int: case dw_val_class_wide_int:
{ {
int i = a->dw_attr_val.v.val_wide->get_len (); int i = val->v.val_wide->get_len ();
fprintf (outfile, "constant ("); fprintf (outfile, "constant (");
gcc_assert (i > 0); gcc_assert (i > 0);
if (a->dw_attr_val.v.val_wide->elt (i - 1) == 0) if (val->v.val_wide->elt (i - 1) == 0)
fprintf (outfile, "0x"); fprintf (outfile, "0x");
fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, fprintf (outfile, HOST_WIDE_INT_PRINT_HEX,
a->dw_attr_val.v.val_wide->elt (--i)); val->v.val_wide->elt (--i));
while (--i >= 0) while (--i >= 0)
fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX, fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX,
a->dw_attr_val.v.val_wide->elt (i)); val->v.val_wide->elt (i));
fprintf (outfile, ")"); fprintf (outfile, ")");
break; break;
} }
...@@ -5451,59 +5438,138 @@ print_die (dw_die_ref die, FILE *outfile) ...@@ -5451,59 +5438,138 @@ print_die (dw_die_ref die, FILE *outfile)
fprintf (outfile, "floating-point or vector constant"); fprintf (outfile, "floating-point or vector constant");
break; break;
case dw_val_class_flag: case dw_val_class_flag:
fprintf (outfile, "%u", AT_flag (a)); fprintf (outfile, "%u", val->v.val_flag);
break; break;
case dw_val_class_die_ref: case dw_val_class_die_ref:
if (AT_ref (a) != NULL) if (val->v.val_die_ref.die != NULL)
{ {
if (AT_ref (a)->comdat_type_p) dw_die_ref die = val->v.val_die_ref.die;
if (die->comdat_type_p)
{ {
fprintf (outfile, "die -> signature: "); fprintf (outfile, "die -> signature: ");
print_signature (outfile, print_signature (outfile,
AT_ref (a)->die_id.die_type_node->signature); die->die_id.die_type_node->signature);
} }
else if (AT_ref (a)->die_id.die_symbol) else if (die->die_id.die_symbol)
fprintf (outfile, "die -> label: %s", fprintf (outfile, "die -> label: %s", die->die_id.die_symbol);
AT_ref (a)->die_id.die_symbol);
else else
fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset); fprintf (outfile, "die -> %ld", die->die_offset);
fprintf (outfile, " (%p)", (void *) AT_ref (a)); fprintf (outfile, " (%p)", (void *) die);
} }
else else
fprintf (outfile, "die -> <null>"); fprintf (outfile, "die -> <null>");
break; break;
case dw_val_class_vms_delta: case dw_val_class_vms_delta:
fprintf (outfile, "delta: @slotcount(%s-%s)", fprintf (outfile, "delta: @slotcount(%s-%s)",
AT_vms_delta2 (a), AT_vms_delta1 (a)); val->v.val_vms_delta.lbl2, val->v.val_vms_delta.lbl1);
break; break;
case dw_val_class_lbl_id: case dw_val_class_lbl_id:
case dw_val_class_lineptr: case dw_val_class_lineptr:
case dw_val_class_macptr: case dw_val_class_macptr:
case dw_val_class_high_pc: case dw_val_class_high_pc:
fprintf (outfile, "label: %s", AT_lbl (a)); fprintf (outfile, "label: %s", val->v.val_lbl_id);
break; break;
case dw_val_class_str: case dw_val_class_str:
if (AT_string (a) != NULL) if (val->v.val_str->str != NULL)
fprintf (outfile, "\"%s\"", AT_string (a)); fprintf (outfile, "\"%s\"", val->v.val_str->str);
else else
fprintf (outfile, "<null>"); fprintf (outfile, "<null>");
break; break;
case dw_val_class_file: case dw_val_class_file:
fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename, fprintf (outfile, "\"%s\" (%d)", val->v.val_file->filename,
AT_file (a)->emitted_number); val->v.val_file->emitted_number);
break; break;
case dw_val_class_data8: case dw_val_class_data8:
{ {
int i; int i;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]); fprintf (outfile, "%02x", val->v.val_data8[i]);
break; break;
} }
default: default:
break; break;
} }
}
/* Likewise, for a DIE attribute. */
static void
print_attribute (dw_attr_ref a, bool recurse, FILE *outfile)
{
print_dw_val (&a->dw_attr_val, recurse, outfile);
}
/* Print the list of operands in the LOC location description to OUTFILE. This
routine is a debugging aid only. */
static void
print_loc_descr (dw_loc_descr_ref loc, FILE *outfile)
{
dw_loc_descr_ref l = loc;
if (loc == NULL)
{
print_spaces (outfile);
fprintf (outfile, "<null>\n");
return;
}
for (l = loc; l != NULL; l = l->dw_loc_next)
{
print_spaces (outfile);
fprintf (outfile, "(%p) %s",
(void *) l,
dwarf_stack_op_name (l->dw_loc_opc));
if (l->dw_loc_oprnd1.val_class != dw_val_class_none)
{
fprintf (outfile, " ");
print_dw_val (&l->dw_loc_oprnd1, false, outfile);
}
if (l->dw_loc_oprnd2.val_class != dw_val_class_none)
{
fprintf (outfile, ", ");
print_dw_val (&l->dw_loc_oprnd2, false, outfile);
}
fprintf (outfile, "\n");
}
}
/* Print the information associated with a given DIE, and its children.
This routine is a debugging aid only. */
static void
print_die (dw_die_ref die, FILE *outfile)
{
dw_attr_ref a;
dw_die_ref c;
unsigned ix;
print_spaces (outfile);
fprintf (outfile, "DIE %4ld: %s (%p)\n",
die->die_offset, dwarf_tag_name (die->die_tag),
(void*) die);
print_spaces (outfile);
fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
fprintf (outfile, " offset: %ld", die->die_offset);
fprintf (outfile, " mark: %d\n", die->die_mark);
if (die->comdat_type_p)
{
print_spaces (outfile);
fprintf (outfile, " signature: ");
print_signature (outfile, die->die_id.die_type_node->signature);
fprintf (outfile, "\n");
}
FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
{
print_spaces (outfile);
fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
print_attribute (a, true, outfile);
fprintf (outfile, "\n"); fprintf (outfile, "\n");
} }
...@@ -5517,6 +5583,14 @@ print_die (dw_die_ref die, FILE *outfile) ...@@ -5517,6 +5583,14 @@ print_die (dw_die_ref die, FILE *outfile)
fprintf (outfile, "\n"); fprintf (outfile, "\n");
} }
/* Print the list of operations in the LOC location description. */
DEBUG_FUNCTION void
debug_dwarf_loc_descr (dw_loc_descr_ref loc)
{
print_loc_descr (loc, stderr);
}
/* Print the information collected for a given DIE. */ /* Print the information collected for a given DIE. */
DEBUG_FUNCTION void DEBUG_FUNCTION void
......
...@@ -254,6 +254,7 @@ extern void dwarf2out_emit_cfi (dw_cfi_ref cfi); ...@@ -254,6 +254,7 @@ extern void dwarf2out_emit_cfi (dw_cfi_ref cfi);
extern void debug_dwarf (void); extern void debug_dwarf (void);
struct die_struct; struct die_struct;
extern void debug_dwarf_die (struct die_struct *); extern void debug_dwarf_die (struct die_struct *);
extern void debug_dwarf_loc_descr (dw_loc_descr_ref);
extern void debug (die_struct &ref); extern void debug (die_struct &ref);
extern void debug (die_struct *ptr); extern void debug (die_struct *ptr);
extern void dwarf2out_set_demangle_name_func (const char *(*) (const char *)); extern void dwarf2out_set_demangle_name_func (const char *(*) (const char *));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment