Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Simon Marchi <simon.marchi@polymtl.ca>,
	Tom de Vries <tdevries@suse.de>,
	gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: Re: [PATCH][gdb/symtab] Handle DW_AT_ranges with DW_FORM_sec_off in partial DIE
Date: Mon, 25 Jan 2021 19:53:11 +0100	[thread overview]
Message-ID: <AM8PR10MB47086F34F027C127061C643AE4BD0@AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <b36ce9f9-2d6e-76bd-7153-5422d9f44eb4@polymtl.ca>

[-- Attachment #1: Type: text/plain, Size: 3171 bytes --]

On 1/25/21 7:12 PM, Simon Marchi wrote:
> 
> 
> On 2021-01-25 12:42 p.m., Bernd Edlinger wrote:
>> On 1/25/21 5:36 PM, Simon Marchi wrote:
>>>> Yes, unfortunately I have not any experience with writing such assembly
>>>> tests, but I am always impressed when one of you does it though :-)
>>>>
>>>> Nevertheless, the test case seems to be stable from gcc-4.8 .. gcc-11,
>>>> that it fails without the patch and passes with the patch.
>>>>
>>>> So is it okay to push my partial symbols test as-is?
>>>
>>> My patch here adds a test that uses DW_FORM_sec_offset to point
>>> to a .debug_rnglists (DWARF5) section.  Maybe that's sufficient,
>>> but if not I could probably do a DWARF4 equivalent.
>>>
>>>   https://sourceware.org/pipermail/gdb-patches/2021-January/175229.html
>>>
>>
>> Yeah, the hardest part on a one-line change like this is always the test case.
>>
>> So, I tried this patch on current trunk, but it fails:
>>
>> Running /home/ed/gnu/gdb-build-1/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.dwarf2/rnglists-multiple-cus.exp ...
>> ERROR: Couldn't load rnglists-multiple-cus-dw32 into GDB (GDB internal error).
>> ERROR: Couldn't load rnglists-multiple-cus-dw64 into GDB (GDB internal error).
>> Running /home/ed/gnu/gdb-build-1/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.dwarf2/rnglists-sec-offset.exp ...
>> FAIL: gdb.dwarf2/rnglists-sec-offset.exp: is_64=false: p/x &foo
>> FAIL: gdb.dwarf2/rnglists-sec-offset.exp: is_64=true: p/x &foo
>>
>> This probably means that your test tests more than this single-line change alone?
> 
> Hmm, with current master (so with Tom's patch merged),
> gdb.dwarf2/rnglists-sec-offset.exp passes for me.
> 

That will probably need investigation.
Let's first check if I applied the corrrect test case,
see attached patch.txt.

tried to do "readelf --debug-dump rnglists-sec-offset-dw32" and
"readelf --debug-dump rnglists-sec-offset-dw64"

I used GNU readelf (GNU Binutils) 2.35.1

I see a warning:
readelf: Warnung: The .debug_rnglists section contains unsupported offset entry count: 2.


what does that mean?
Doesn't that indicate that the debug-info somehow wrong?


> But gdb.dwarf2/rnglists-multiple-cus.exp is expected to fail if you don't
> have the other patches in my series.
>  
>> I always thought that the partial symbols are replaced by the
>> full symbols as soon as the first item from the CU is accessed, say "main".
>> Can you explain how that can be?
>> I was never able to get a reproducer for partial symbols with only one CU.
> 
> The bug fixed by this patch triggers as soon as you have a function
> (DW_TAG_subprogram) with a DW_AT_ranges, I don't think it matters whether
> there is one or more CUs.  But perhaps it's difficult to force the compiler
> to emit a function with DW_AT_ranges (so, with a non-contiguous range) when
> using a single CU.
> 

It happens pretty reliably when you have a function that contains an error
handling that looks obvously "unlinkely" to the compiler, because it is guarded
by an if-condition and calls abort(), while there are also code paths that
don't call about.  The parts that call abort are then in a separate cold section.


Bernd.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 6303 bytes --]

diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 7462890..aba4afb 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -473,7 +473,8 @@ namespace eval Dwarf {
 	    }
 
 	    DW_FORM_ref_udata -
-	    DW_FORM_udata {
+	    DW_FORM_udata -
+	    DW_FORM_rnglistx {
 		_op .uleb128 $value
 	    }
 
@@ -1115,8 +1116,16 @@ namespace eval Dwarf {
 	}
 	define_label $start_label
 	_op .2byte $_cu_version Version
-	_op .${_cu_offset_size}byte $my_abbrevs Abbrevs
-	_op .byte $_cu_addr_size "Pointer size"
+
+	# The CU header for DWARF 4 and 5 are slightly different.
+	if { $_cu_version == 5 } {
+	    _op .byte 0x1 "DW_UT_compile"
+	    _op .byte $_cu_addr_size "Pointer size"
+	    _op .${_cu_offset_size}byte $my_abbrevs Abbrevs
+	} else {
+	    _op .${_cu_offset_size}byte $my_abbrevs Abbrevs
+	    _op .byte $_cu_addr_size "Pointer size"
+	}
 
 	_defer_output $_abbrev_section {
 	    define_label $my_abbrevs
@@ -1306,6 +1315,178 @@ namespace eval Dwarf {
 	uplevel $body
     }
 
+    # Emit a DWARF .debug_rnglists section.
+    #
+    # The target address size is based on the current target's address size.
+    #
+    # There is one mandatory positional argument, BODY, which must be Tcl code
+    # that emits the content of the section.  It is evaluated in the caller's
+    # context.
+    #
+    # The following option can be used:
+    #
+    #  - -is-64 true|false: Whether to use 64-bit DWARF instead of 32-bit DWARF.
+    #                       The default is 32-bit.
+
+    proc rnglists { args } {
+	variable _debug_rnglists_addr_size
+	variable _debug_rnglists_offset_size
+	variable _debug_rnglists_is_64_dwarf
+
+	parse_args {{"is-64" "false"}}
+
+	if { [llength $args] != 1 } {
+	    error "rnglists proc expects one positional argument (body)"
+	}
+
+	lassign $args body
+
+	if [is_64_target] {
+	    set _debug_rnglists_addr_size 8
+	} else {
+	    set _debug_rnglists_addr_size 4
+	}
+
+	if { ${is-64} } {
+	    set _debug_rnglists_offset_size 8
+	    set _debug_rnglists_is_64_dwarf true
+	} else {
+	    set _debug_rnglists_offset_size 4
+	    set _debug_rnglists_is_64_dwarf false
+	}
+
+	_section ".debug_rnglists"
+
+	# Count of tables in the section.
+	variable _debug_rnglists_table_count 0
+
+	# Compute the label name for list at index LIST_IDX, for the current
+	# table.
+
+	proc _compute_list_label { list_idx } {
+	    variable _debug_rnglists_table_count
+
+	    return ".Lrnglists_table_${_debug_rnglists_table_count}_list_${list_idx}"
+	}
+
+	# Generate one table (header + offset array + range lists).
+	#
+	# Accepts one positional argument, BODY.  BODY may call the LIST_
+	# procedure to generate rnglists.
+	#
+	# The -post-header-label option can be used to define a label just after
+	# the header of the table.  This is the label that a DW_AT_rnglists_base
+	# attribute will usually refer to.
+
+	proc table { args } {
+	    variable _debug_rnglists_table_count
+	    variable _debug_rnglists_addr_size
+	    variable _debug_rnglists_offset_size
+	    variable _debug_rnglists_is_64_dwarf
+
+	    parse_args {{post-header-label ""}}
+
+	    if { [llength $args] != 1 } {
+		error "table proc expects one positional argument (body)"
+	    }
+
+	    lassign $args body
+
+	    # Generate one range list.
+	    #
+	    # BODY may call the various procs defined below to generate list entries.
+	    # They correspond to the range list entry kinds described in section 2.17.3
+	    # of the DWARF 5 spec.
+	    #
+	    # To define a label pointing to the beginning of the list, use
+	    # the conventional way of declaring and defining labels:
+	    #
+	    #   declare_labels the_list
+	    #
+	    #   the_list: list_ {
+	    #     ...
+	    #   }
+
+	    proc list_ { body } {
+		variable _debug_rnglists_list_count
+
+		# Define a label for this list.  It is used to build the offset
+		# array later.
+		set list_label [_compute_list_label $_debug_rnglists_list_count]
+		define_label $list_label
+
+		# Emit a DW_RLE_start_end entry.
+
+		proc start_end { start end } {
+		    variable _debug_rnglists_addr_size
+
+		    _op .byte 0x06 "DW_RLE_start_end"
+		    _op .${_debug_rnglists_addr_size}byte $start "start"
+		    _op .${_debug_rnglists_addr_size}byte $end "end"
+		}
+
+		uplevel $body
+
+		# Emit end of list.
+		_op .byte 0x00 "DW_RLE_end_of_list"
+
+		incr _debug_rnglists_list_count
+	    }
+
+	    # Count of lists in the table.
+	    variable _debug_rnglists_list_count 0
+
+	    # Generate the lists ops first, because we need to know how many
+	    # lists there are to generate the header and offset table.
+	    set lists_ops [_defer_to_string {
+		uplevel $body
+	    }]
+
+	    set post_unit_len_label \
+		[_compute_label "rnglists_table_${_debug_rnglists_table_count}_post_unit_len"]
+	    set post_header_label \
+		[_compute_label "rnglists_table_${_debug_rnglists_table_count}_post_header"]
+	    set table_end_label \
+		[_compute_label "rnglists_table_${_debug_rnglists_table_count}_end"]
+
+	    # Emit the table header.
+	    if { $_debug_rnglists_is_64_dwarf } {
+		_op .4byte 0xffffffff "unit length 1/2"
+		_op .8byte "$table_end_label - $post_unit_len_label" "unit length 2/2"
+	    } else {
+		_op .4byte "$table_end_label - $post_unit_len_label" "unit length"
+	    }
+
+	    define_label $post_unit_len_label
+
+	    _op .2byte 5 "dwarf version"
+	    _op .byte $_debug_rnglists_addr_size "address size"
+	    _op .byte 0 "segment selector size"
+	    _op .4byte "$_debug_rnglists_list_count" "offset entry count"
+
+	    define_label $post_header_label
+
+	    # Define the user post-header label, if provided.
+	    if { ${post-header-label} != "" } {
+		define_label ${post-header-label}
+	    }
+
+	    # Emit the offset array.
+	    for {set list_idx 0} {$list_idx < $_debug_rnglists_list_count} {incr list_idx} {
+		set list_label [_compute_list_label $list_idx]
+		_op .${_debug_rnglists_offset_size}byte "$list_label - $post_header_label" "offset of list $list_idx"
+	    }
+
+	    # Emit the actual list data.
+	    _emit "$lists_ops"
+
+	    define_label $table_end_label
+
+	    incr _debug_rnglists_table_count
+	}
+
+	uplevel $body
+    }
 
     # Emit a DWARF .debug_line unit.
     # OPTIONS is a list with an even number of elements containing

[-- Attachment #3: rnglists-sec-offset-dw32.txt --]
[-- Type: text/plain, Size: 1567 bytes --]

Inhalt der .debug_info-Sektion:

  Compilation Unit @ offset 0x0:
   Länge: 0x17 (32-bit)
   Version:       5
   Abbrev Offset: 0x0
   Zeigergröße:   8
 <0><c>: Zahl abkürzen: 2 (DW_TAG_compile_unit)
    <d>   DW_AT_ranges      : 0x14
 <1><11>: Zahl abkürzen: 3 (DW_TAG_subprogram)
    <12>   DW_AT_name        : foo
    <16>   DW_AT_ranges      : 0x26
 <1><1a>: Abbrev Number: 0

Inhalt der .debug_abbrev-Sektion:

  Number TAG (0x0)
   2      DW_TAG_compile_unit    [hat Kinder]
    DW_AT_ranges       DW_FORM_sec_offset
    DW_AT value: 0     DW_FORM value: 0
   3      DW_TAG_subprogram    [keine Kinder]
    DW_AT_name         DW_FORM_string
    DW_AT_ranges       DW_FORM_sec_offset
    DW_AT value: 0     DW_FORM value: 0

Raw dump of debug contents of section .debug_line:

  Versatz:                      0x0
  Länge:                        25
  DWARF Version:                3
  Länge des Prologs:            19
  Minimale Instruktionslänge:   1
  Initialer Wert von ‚is_stmt‛: 1
  Zeilenbasis:                  -5
  Zeilenreichweite:             14
  Opcode-Basis:                 13

 Opcodes:
  Opcode 1 has 0 args
  Opcode 2 has 1 arg
  Opcode 3 has 1 arg
  Opcode 4 has 1 arg
  Opcode 5 has 1 arg
  Opcode 6 has 0 args
  Opcode 7 has 0 args
  Opcode 8 has 0 args
  Opcode 9 has 1 arg
  Opcode 10 has 0 args
  Opcode 11 has 0 args
  Opcode 12 has 1 arg

 Die Verzeichnistabelle ist leer.

 Die Dateinamentabelle ist leer.

 No Line Number Statements.
readelf: Warnung: The .debug_rnglists section contains unsupported offset entry count: 2.

[-- Attachment #4: rnglists-sec-offset-dw64.txt --]
[-- Type: text/plain, Size: 1569 bytes --]

Inhalt der .debug_info-Sektion:

  Compilation Unit @ offset 0x0:
   Länge: 0x23 (64-bit)
   Version:       5
   Abbrev Offset: 0x0
   Zeigergröße:   8
 <0><18>: Zahl abkürzen: 2 (DW_TAG_compile_unit)
    <19>   DW_AT_ranges      : 0x24
 <1><21>: Zahl abkürzen: 3 (DW_TAG_subprogram)
    <22>   DW_AT_name        : foo
    <26>   DW_AT_ranges      : 0x36
 <1><2e>: Abbrev Number: 0

Inhalt der .debug_abbrev-Sektion:

  Number TAG (0x0)
   2      DW_TAG_compile_unit    [hat Kinder]
    DW_AT_ranges       DW_FORM_sec_offset
    DW_AT value: 0     DW_FORM value: 0
   3      DW_TAG_subprogram    [keine Kinder]
    DW_AT_name         DW_FORM_string
    DW_AT_ranges       DW_FORM_sec_offset
    DW_AT value: 0     DW_FORM value: 0

Raw dump of debug contents of section .debug_line:

  Versatz:                      0x0
  Länge:                        25
  DWARF Version:                3
  Länge des Prologs:            19
  Minimale Instruktionslänge:   1
  Initialer Wert von ‚is_stmt‛: 1
  Zeilenbasis:                  -5
  Zeilenreichweite:             14
  Opcode-Basis:                 13

 Opcodes:
  Opcode 1 has 0 args
  Opcode 2 has 1 arg
  Opcode 3 has 1 arg
  Opcode 4 has 1 arg
  Opcode 5 has 1 arg
  Opcode 6 has 0 args
  Opcode 7 has 0 args
  Opcode 8 has 0 args
  Opcode 9 has 1 arg
  Opcode 10 has 0 args
  Opcode 11 has 0 args
  Opcode 12 has 1 arg

 Die Verzeichnistabelle ist leer.

 Die Dateinamentabelle ist leer.

 No Line Number Statements.
readelf: Warnung: The .debug_rnglists section contains unsupported offset entry count: 2.

  reply	other threads:[~2021-01-25 18:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25 12:24 Tom de Vries
2021-01-25 12:52 ` Bernd Edlinger
2021-01-25 15:27   ` Simon Marchi via Gdb-patches
2021-01-25 15:37     ` Tom de Vries
2021-01-25 15:47       ` Bernd Edlinger
2021-01-25 16:36         ` Simon Marchi via Gdb-patches
2021-01-25 17:42           ` Bernd Edlinger
2021-01-25 18:12             ` Simon Marchi via Gdb-patches
2021-01-25 18:53               ` Bernd Edlinger [this message]
2021-01-25 19:20                 ` Bernd Edlinger
2021-01-26  1:52                 ` Simon Marchi via Gdb-patches
2021-01-26  7:47                   ` Bernd Edlinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM8PR10MB47086F34F027C127061C643AE4BD0@AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM \
    --to=bernd.edlinger@hotmail.de \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --cc=tdevries@suse.de \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox