gdb: Support DW_OP_constx (the standardized version of DW_OP_GNU_const_index).

Message ID 20240907152005.6608-1-khuey@kylehuey.com
State New
Headers
Series gdb: Support DW_OP_constx (the standardized version of DW_OP_GNU_const_index). |

Checks

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

Commit Message

Kyle Huey Sept. 7, 2024, 3:20 p.m. UTC
  ---
 gdb/dwarf2/expr.c | 3 ++-
 gdb/dwarf2/loc.c  | 9 +++++++--
 gdb/dwarf2/read.c | 1 +
 3 files changed, 10 insertions(+), 3 deletions(-)
  

Comments

Tom Tromey Sept. 11, 2024, 3:06 p.m. UTC | #1
>>>>> "Kyle" == Kyle Huey <me@kylehuey.com> writes:

I'm checking this in.  I think it's small enough to allow this without a
copyright assignment.  However if you intend to submit more gdb patches,
we'll need paperwork.  I can get you started on that (email me directly)
if you want.

thanks,
Tom
  

Patch

diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index cb80dbf60b1..5ad17eaaaff 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -1593,8 +1593,9 @@  dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
 					     uoffset)));
 	  result_val = value_from_ulongest (address_type, result);
 	  break;
+	case DW_OP_constx:
 	case DW_OP_GNU_const_index:
-	  ensure_have_per_cu (this->m_per_cu, "DW_OP_GNU_const_index");
+	  ensure_have_per_cu (this->m_per_cu, "DW_OP_constx");
 
 	  op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
 	  result = (ULONGEST) dwarf2_read_addr_index (this->m_per_cu,
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 3a47805ab3a..5d1a557cb98 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -1967,6 +1967,7 @@  dwarf2_get_symbol_read_needs (gdb::array_view<const gdb_byte> expr,
 	case DW_OP_GNU_reinterpret:
 	case DW_OP_addrx:
 	case DW_OP_GNU_addr_index:
+	case DW_OP_constx:
 	case DW_OP_GNU_const_index:
 	case DW_OP_constu:
 	case DW_OP_plus_uconst:
@@ -3265,10 +3266,13 @@  locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
   /* With -gsplit-dwarf a TLS variable can also look like this:
      DW_AT_location    : 3 byte block: fc 4 e0
 			(DW_OP_GNU_const_index: 4;
-			 DW_OP_GNU_push_tls_address)  */
+			 DW_OP_GNU_push_tls_address) |
+			 3 byte block a2 4 e0
+			(DW_OP_constx: 4;
+			 DW_OP_form_tls_address)  */
   else if (data + 3 <= end
 	   && data + 1 + (leb128_size = skip_leb128 (data + 1, end)) < end
-	   && data[0] == DW_OP_GNU_const_index
+	   && (data[0] == DW_OP_constx || data[0] == DW_OP_GNU_const_index)
 	   && leb128_size > 0
 	   && (data[1 + leb128_size] == DW_OP_GNU_push_tls_address
 	       || data[1 + leb128_size] == DW_OP_form_tls_address)
@@ -3675,6 +3679,7 @@  disassemble_dwarf_expression (struct ui_file *stream,
 	  gdb_printf (stream, " 0x%s", phex_nz (ul, addr_size));
 	  break;
 
+	case DW_OP_constx:
 	case DW_OP_GNU_const_index:
 	  data = safe_read_uleb128 (data, end, &ul);
 	  ul = (uint64_t) dwarf2_read_addr_index (per_cu, per_objfile, ul);
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 769ca91facc..e0dcf940402 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -21142,6 +21142,7 @@  decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu,
 
 	case DW_OP_addrx:
 	case DW_OP_GNU_addr_index:
+	case DW_OP_constx:
 	case DW_OP_GNU_const_index:
 	  stack[++stacki]
 	    = (CORE_ADDR) read_addr_index_from_leb128 (cu, &data[i],