[4/7] Assume DW_AT_decl_line is unsigned

Message ID 20250311-attribute-unsigned-initial-v1-4-833f35aa0f29@adacore.com
State New
Headers
Series Handle unsigned DW_FORM_data* constants more nicely |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom Tromey March 11, 2025, 5 p.m. UTC
  This changes read_decl_line and new_symbol to assume that
DW_AT_decl_line should refer to an unsigned value.
---
 gdb/dwarf2/read.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e2f8cab6c3a26ea31717274e653f897f6fc3cf5b..224837abb65997a38e7bd2e0653792858def9139 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5999,17 +5999,14 @@  read_decl_line (struct die_info *die, struct dwarf2_cu *cu)
   struct attribute *decl_line = dwarf2_attr (die, DW_AT_decl_line, cu);
   if (decl_line == nullptr)
     return 0;
-  if (decl_line->form_is_constant ())
-    {
-      LONGEST val = decl_line->constant_value (0);
-      if (0 <= val && val <= UINT_MAX)
-	return (unsigned int) val;
 
+  std::optional<ULONGEST> val = decl_line->unsigned_constant ();
+  if (val.has_value ())
+    {
+      if (*val <= UINT_MAX)
+	return (unsigned int) *val;
       complaint (_("Declared line for using directive is too large"));
-      return 0;
     }
-
-  complaint (_("Declared line for using directive is of incorrect format"));
   return 0;
 }
 
@@ -17093,7 +17090,7 @@  new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 			  inlined_func ? DW_AT_call_line : DW_AT_decl_line,
 			  cu);
       if (attr != nullptr)
-	sym->set_line (attr->constant_value (0));
+	sym->set_line (attr->unsigned_constant ().value_or (0));
 
       struct dwarf2_cu *file_cu = cu;
       attr = dwarf2_attr (die,