]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Fix attrs that can be an expression block or a constant.
authorRoland McGrath <roland@redhat.com>
Mon, 30 Mar 2009 00:36:22 +0000 (17:36 -0700)
committerRoland McGrath <roland@redhat.com>
Mon, 30 Mar 2009 00:36:22 +0000 (17:36 -0700)
libdw/c++/dwarf-knowledge.cc
libdw/c++/values.cc
tests/dwarf-print.cc

index b7827a4577be42ec578a96cb2847667441e37406..de526fe50894ea62a5515a72b373c365985fde29 100644 (file)
@@ -68,14 +68,15 @@ expected_value_space (int attr, int tag)
 
     case DW_AT_byte_size:
     case DW_AT_byte_stride:
-    case DW_AT_bit_offset:
     case DW_AT_bit_size:
+    case DW_AT_bit_offset:
+    case DW_AT_bit_stride:
     case DW_AT_lower_bound:
     case DW_AT_upper_bound:
     case DW_AT_count:
     case DW_AT_allocated:
     case DW_AT_associated:
-      return VS(reference) | VS(constant);
+      return VS(reference) | VS(constant) | VS(location); // XXX non-loc expr
 
     case DW_AT_stmt_list:
       return VS(lineptr);
@@ -126,7 +127,6 @@ expected_value_space (int attr, int tag)
     case DW_AT_start_scope:
       return VS(constant);
 
-    case DW_AT_bit_stride:
     case DW_AT_binary_scale:
     case DW_AT_decimal_scale:
     case DW_AT_decimal_sign:
index 63686eea3efce734393d44137909e840c1c1932a..9fd96dfaa5f7d2f88f1a2b43c44c59883cea9401 100644 (file)
@@ -70,8 +70,9 @@ using namespace std;
 dwarf::value_space
 dwarf::attr_value::what_space () const
 {
+  unsigned int expected = expected_value_space (dwarf_whatattr (thisattr ()),
+                                               _m_tag);
   unsigned int possible = 0;
-
   switch (dwarf_whatform (thisattr ()))
     {
     case DW_FORM_flag:
@@ -86,6 +87,9 @@ dwarf::attr_value::what_space () const
     case DW_FORM_block4:
       /* Location expression or target constant.  */
       possible = VS(location) | VS(constant);
+      if ((expected & possible) == possible)
+       /* When both are expected, a block is a location expression.  */
+       return VS_location;
       break;
 
     case DW_FORM_data1:
@@ -99,6 +103,9 @@ dwarf::attr_value::what_space () const
                  | VS(source_file) | VS(source_line) | VS(source_column)
                  | VS(location) // loclistptr
                  | VS(lineptr) | VS(macptr) | VS(rangelistptr));
+      if ((expected & possible) == (VS(constant) | VS(location)))
+       /* When both are expected, a constant is not a loclistptr.  */
+       return VS_constant;
       break;
 
     case DW_FORM_string:
@@ -120,8 +127,6 @@ dwarf::attr_value::what_space () const
       throw std::runtime_error ("XXX bad form");
     }
 
-  unsigned int expected = expected_value_space (dwarf_whatattr (thisattr ()),
-                                               _m_tag);
   if (unlikely ((expected & possible) == 0))
     {
       if (expected == 0 && possible == (VS(unit_reference) | VS(reference)))
@@ -537,5 +542,5 @@ dwarf::location_attr::to_string () const
 {
   if (is_list ())
     return hex_string (_m_attr.constant (), "#");
-  return "XXX";
+  return "XXX-expr";
 }
index ece96757850bc8a002a8936a6aa636db9ca91e88..8aa12ca970b1e7563170b263ec075fb694a54466 100644 (file)
@@ -71,7 +71,7 @@ print_die (const dwarf::debug_info_entry &die,
 
   if (die.has_children ())
     {
-      if (indent >= limit)
+      if (limit != 0 && indent >= limit)
        {
          cout << ">...\n";
          return;
@@ -96,11 +96,10 @@ process_file (const char *file, unsigned int limit)
 
   cout << file << ":\n";
 
-  if (limit > 0)
-    for (dwarf::compile_units::const_iterator i = dw.compile_units ().begin ();
-        i != dw.compile_units ().end ();
-        ++i)
-      print_die (*i, 1, limit);
+  for (dwarf::compile_units::const_iterator i = dw.compile_units ().begin ();
+       i != dw.compile_units ().end ();
+       ++i)
+    print_die (*i, 1, limit);
 }
 
 int
@@ -117,7 +116,7 @@ main (int argc, char *argv[])
 
   cout << hex << setiosflags (ios::showbase);
 
-  unsigned int depth = 1;
+  unsigned int depth = 0;
   if (argc > 1 && sscanf (argv[1], "--depth=%u", &depth) == 1)
     {
       --argc;