gdb: Convert language la_watch_location_expression field to a method
[deliverable/binutils-gdb.git] / gdb / dwarf2 / attribute.c
index 6e51fff53624982004700c1a4469bcb5f6978984..b39cfe2c00dbd74c6d31df8d2fc26815be56be13 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "defs.h"
 #include "dwarf2/attribute.h"
+#include "dwarf2/stringify.h"
+#include "complaints.h"
 
 /* See attribute.h.  */
 
@@ -59,15 +61,32 @@ attribute::value_as_address () const
 
 /* See attribute.h.  */
 
-int
-attr_form_is_block (const struct attribute *attr)
+const char *
+attribute::value_as_string () const
 {
-  return (attr == NULL ? 0 :
-      attr->form == DW_FORM_block1
-      || attr->form == DW_FORM_block2
-      || attr->form == DW_FORM_block4
-      || attr->form == DW_FORM_block
-      || attr->form == DW_FORM_exprloc);
+  if (form == DW_FORM_strp || form == DW_FORM_line_strp
+      || form == DW_FORM_string
+      || form == DW_FORM_strx
+      || form == DW_FORM_strx1
+      || form == DW_FORM_strx2
+      || form == DW_FORM_strx3
+      || form == DW_FORM_strx4
+      || form == DW_FORM_GNU_str_index
+      || form == DW_FORM_GNU_strp_alt)
+    return DW_STRING (this);
+  return nullptr;
+}
+
+/* See attribute.h.  */
+
+bool
+attribute::form_is_block () const
+{
+  return (form == DW_FORM_block1
+         || form == DW_FORM_block2
+         || form == DW_FORM_block4
+         || form == DW_FORM_block
+         || form == DW_FORM_exprloc);
 }
 
 /* See attribute.h.  */
@@ -77,7 +96,8 @@ attribute::form_is_section_offset () const
 {
   return (form == DW_FORM_data4
           || form == DW_FORM_data8
-         || form == DW_FORM_sec_offset);
+         || form == DW_FORM_sec_offset
+         || form == DW_FORM_loclistx);
 }
 
 /* See attribute.h.  */
@@ -100,23 +120,33 @@ attribute::form_is_constant () const
     }
 }
 
-/* DW_ADDR is always stored already as sect_offset; despite for the forms
-   besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file.  */
+/* See attribute.h.  */
 
-bool
-attribute::form_is_ref () const
+void
+attribute::get_ref_die_offset_complaint () const
 {
-  switch (form)
+  complaint (_("unsupported die ref attribute form: '%s'"),
+            dwarf_form_name (form));
+}
+
+/* See attribute.h.  */
+
+LONGEST
+attribute::constant_value (int default_value) const
+{
+  if (form == DW_FORM_sdata || form == DW_FORM_implicit_const)
+    return DW_SND (this);
+  else if (form == DW_FORM_udata
+          || form == DW_FORM_data1
+          || form == DW_FORM_data2
+          || form == DW_FORM_data4
+          || form == DW_FORM_data8)
+    return DW_UNSND (this);
+  else
     {
-    case DW_FORM_ref_addr:
-    case DW_FORM_ref1:
-    case DW_FORM_ref2:
-    case DW_FORM_ref4:
-    case DW_FORM_ref8:
-    case DW_FORM_ref_udata:
-    case DW_FORM_GNU_ref_alt:
-      return true;
-    default:
-      return false;
+      /* For DW_FORM_data16 see attribute::form_is_constant.  */
+      complaint (_("Attribute value is not a constant (%s)"),
+                dwarf_form_name (form));
+      return default_value;
     }
 }
This page took 0.069738 seconds and 4 git commands to generate.