[2/4] gdb/testsuite/dwarf: add support to generate DWARF 5 split compile units

Message ID 20250407175247.3312551-3-simon.marchi@polymtl.ca
State New
Headers
Series Fix split DWARF + type unit regression |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Simon Marchi April 7, 2025, 5:51 p.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

Add support to the DWARF assembler to generate DWARF 5 split compile
units.  The assembler knows how to generate DWARF < 5 split compile
units (fission), DWARF 5 compile units, but not DWARF 5 split compile
units.  What's missing is:

 - using the right unit type in the header: skeleton for the unit in the
   main file and split_compile for the unit in the DWO file
 - have a way for the caller to specify the DWO ID that will end up in
   the unit header

Add a dwo_id parameter to the cu proc.  In addition to specifying the
DWO ID, the presence of this parameter tells the assembler to use the
skeleton or split_compile unit type.

This is used in a subsequent patch.

Change-Id: I05d9b189a0843ea6c2771b1d5e5a91762426dea9
---
 gdb/testsuite/lib/dwarf.exp | 48 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)
  

Comments

Tom Tromey April 8, 2025, 3:02 p.m. UTC | #1
>>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes:

Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
Simon> Add support to the DWARF assembler to generate DWARF 5 split compile
Simon> units.  The assembler knows how to generate DWARF < 5 split compile
Simon> units (fission), DWARF 5 compile units, but not DWARF 5 split compile
Simon> units.

Thanks for doing this.

Simon> +	    # The presence of a DWO_ID indicates that we generate a skeleton
Simon> +	    # or split_compile unit.
Simon> +	    if { $dwo_id != 0 } {
Simon> +		if { $_cu_is_fission } {
Simon> +		    set unit_type 0x5
Simon> +		    set unit_type_name "DW_UT_split_compile"
Simon> +		} else {
Simon> +		    set unit_type 0x4
Simon> +		    set unit_type_name "DW_UT_skeleton"
Simon> +		}
Simon> +	    } else {
Simon> +		set unit_type 0x1
Simon> +		set unit_type_name "DW_UT_compile"
Simon> +	    }
Simon> +
Simon> +	    _op .byte $unit_type $unit_type_name

I think you could dispense with unit_type and use
$_constants($unit_type_name).  This would ensure the output is in sync
with the headers.

Tom
  
Simon Marchi April 8, 2025, 6:02 p.m. UTC | #2
On 4/8/25 11:02 AM, Tom Tromey wrote:
>>>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes:
> 
> Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
> Simon> Add support to the DWARF assembler to generate DWARF 5 split compile
> Simon> units.  The assembler knows how to generate DWARF < 5 split compile
> Simon> units (fission), DWARF 5 compile units, but not DWARF 5 split compile
> Simon> units.
> 
> Thanks for doing this.
> 
> Simon> +	    # The presence of a DWO_ID indicates that we generate a skeleton
> Simon> +	    # or split_compile unit.
> Simon> +	    if { $dwo_id != 0 } {
> Simon> +		if { $_cu_is_fission } {
> Simon> +		    set unit_type 0x5
> Simon> +		    set unit_type_name "DW_UT_split_compile"
> Simon> +		} else {
> Simon> +		    set unit_type 0x4
> Simon> +		    set unit_type_name "DW_UT_skeleton"
> Simon> +		}
> Simon> +	    } else {
> Simon> +		set unit_type 0x1
> Simon> +		set unit_type_name "DW_UT_compile"
> Simon> +	    }
> Simon> +
> Simon> +	    _op .byte $unit_type $unit_type_name
> 
> I think you could dispense with unit_type and use
> $_constants($unit_type_name).  This would ensure the output is in sync
> with the headers.
> 
> Tom

Good idea, it works.

Simon
  

Patch

diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 7dcf13f2ce7b..308ab852bd15 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -1441,6 +1441,17 @@  namespace eval Dwarf {
     #                default = default
     # fission 0|1  - boolean indicating if generating Fission debug info
     #                default = 0
+    # dwo_id       - The value to use as the dwo_id field of skeleton and
+    #                split_compile unit headers.  May only be used with DWARF
+    #                version 5.
+    #
+    #                If a dwo_id value is specified (is non-zero), this unit is
+    #                assumed to be part of a skeleton/split_unit pair.  The unit
+    #                type will be chosen according to the `fission` value.
+    #
+    #                When using DWARF version 5 and fission is non-zero, it is
+    #                mandatory to provide a non-zero dwo_id value.
+    #                default = 0
     # label <label>
     #              - string indicating label to be defined at the start
     #                of the CU header.
@@ -1463,6 +1474,7 @@  namespace eval Dwarf {
 	set _cu_version 4
 	set _cu_addr_size default
 	set _cu_is_fission 0
+	set dwo_id 0
 	set section ".debug_info"
 	set _abbrev_section ".debug_abbrev"
 	set label ""
@@ -1474,6 +1486,7 @@  namespace eval Dwarf {
 		version { set _cu_version $value }
 		addr_size { set _cu_addr_size $value }
 		fission { set _cu_is_fission $value }
+		dwo_id { set dwo_id $value }
 		label { set label $value }
 		default { error "unknown option $name" }
 	    }
@@ -1524,12 +1537,45 @@  namespace eval Dwarf {
 
 	# The CU header for DWARF 4 and 5 are slightly different.
 	if { $_cu_version == 5 } {
-	    _op .byte 0x1 "DW_UT_compile"
+	    # The presence of a DWO_ID indicates that we generate a skeleton
+	    # or split_compile unit.
+	    if { $dwo_id != 0 } {
+		if { $_cu_is_fission } {
+		    set unit_type 0x5
+		    set unit_type_name "DW_UT_split_compile"
+		} else {
+		    set unit_type 0x4
+		    set unit_type_name "DW_UT_skeleton"
+		}
+	    } else {
+		set unit_type 0x1
+		set unit_type_name "DW_UT_compile"
+	    }
+
+	    _op .byte $unit_type $unit_type_name
 	    _op .byte $_cu_addr_size "Pointer size"
 	    _op_offset $_cu_offset_size $my_abbrevs Abbrevs
+
+	    # Output DWO ID, if specified.
+	    if { $dwo_id != 0 } {
+		_op .8byte $dwo_id "DWO_ID"
+	    } else {
+		# To help catch user errors: if the caller asked to put this
+		# unit in the DWO file but didn't provide a DWO ID, it is likely
+		# an error.
+		if { $_cu_is_fission } {
+		    error "DWO ID not specified for DWARF 5 split compile"
+		}
+	    }
 	} else {
 	    _op_offset $_cu_offset_size $my_abbrevs Abbrevs
 	    _op .byte $_cu_addr_size "Pointer size"
+
+	    # For DWARF versions < 5, the DWO ID is not in the unit header,
+	    # so it makes not sense to specify one.
+	    if { $dwo_id != 0 } {
+		error "DWO ID specified for DWARF < 5 unit"
+	    }
 	}
 
 	_defer_output $_abbrev_section {