From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH][gdb/testsuite] Support .debug_aranges in dwarf assembly
Date: Thu, 26 Aug 2021 13:56:26 +0200 [thread overview]
Message-ID: <20210826115625.GA22715@delia> (raw)
Hi,
Add a proc aranges such that we can generate .debug_aranges sections in dwarf
assembly using:
...
cu { label cu_label } {
...
}
aranges {} cu_label {
arange -c <comment> $addr $len
}
...
Tested on x86_64-linux.
Any comments?
Thanks,
- Tom
[gdb/testsuite] Support .debug_aranges in dwarf assembly
---
gdb/testsuite/lib/dwarf.exp | 173 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 173 insertions(+)
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 8dda798ddf8..32b110b3f3e 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -2208,6 +2208,179 @@ namespace eval Dwarf {
define_label $unit_end_label
}
+ # Emit a DWARF .debug_aranges unit.
+ #
+ # OPTIONS is a list with an even number of elements containing
+ # option-name and option-value pairs.
+ # Current options are:
+ # is_64 0|1 - boolean indicating if you want to emit 64-bit DWARF
+ # default = 0 (32-bit)
+ # cu_is_64 0|1 - boolean indicating if LABEL refers to a 64-bit DWARF CU
+ # default = 0 (32-bit)
+ # section_version n
+ # - section version number to emit
+ # default = 2
+ # seg_size n - the size of the adress selector in bytes: 0, 4, or 8
+ # default = 0
+ #
+ # LABEL is the label of the corresponding CU.
+ #
+ # BODY is Tcl code that emits the parts which make up the body of
+ # the aranges unit. It is evaluated in the caller's context. The
+ # following commands are available for the BODY section:
+ #
+ # arange [-c <comment>] [<segment selector>] <start> <length>
+ # -- adds an address range.
+
+ proc aranges { options label body } {
+ variable _addr_size
+ variable _seg_size
+
+ # Establish the defaults.
+ set is_64 0
+ set cu_is_64 0
+ set section_version 2
+ set _seg_size 0
+
+ # Handle options.
+ foreach { name value } $options {
+ switch -exact -- $name {
+ is_64 { set is_64 $value }
+ cu_is_64 { set cu_is_64 $value }
+ section_version {set section_version $value }
+ seg_size { set _seg_size $value }
+ default { error "unknown option $name" }
+ }
+ }
+
+ if { [is_64_target] } {
+ set _addr_size 8
+ } else {
+ set _addr_size 4
+ }
+
+ # Switch to .debug_aranges section.
+ _section .debug_aranges
+
+ # Keep track of offset from start of section entry to determine
+ # padding amount.
+ set offset 0
+
+ # Initial length.
+ declare_labels aranges_start aranges_end
+ set length "$aranges_end - $aranges_start"
+ set comment "Length"
+ if { $is_64 } {
+ _op .4byte 0xffffffff
+ _op .8byte $length $comment
+ incr offset 12
+ } else {
+ _op .4byte $length $comment
+ incr offset 4
+ }
+
+ # Start label.
+ aranges_start:
+
+ # Section version.
+ _op .2byte $section_version "Section version"
+ incr offset 2
+
+ # Offset into .debug_info.
+ upvar $label my_label
+ if { $cu_is_64 } {
+ _op .8byte $my_label "Offset into .debug_info"
+ incr offset 8
+ } else {
+ _op .4byte $my_label "Offset into .debug_info"
+ incr offset 4
+ }
+
+ # Address size.
+ _op .byte $_addr_size "Address size"
+ incr offset
+
+ # Segment selector size.
+ _op .byte $_seg_size "Segment selector size"
+ incr offset
+
+ # Padding.
+ set tuple_size [expr 2 * $_addr_size + $_seg_size]
+ while { 1 } {
+ if { [expr $offset % $tuple_size] == 0 } {
+ break
+ }
+ _op .byte 0 "Pad to $tuple_size byte boundary"
+ incr offset
+ }
+
+ proc arange { args } {
+ set nargs [llength $args]
+
+ # Handle optional -c <comment>.
+ if { $nargs >= 2 && [lindex $args 0] == "-c" } {
+ set comment [lindex $args 1]
+ # Wrap
+ set comment " ($comment)"
+ # Shift 2.
+ set args [lrange $args 2 end]
+ set nargs [llength $args]
+ } else {
+ set comment ""
+ }
+
+ # Handle optional seg_sel.
+ if { $nargs == 2 } {
+ set seg_sel ""
+ } elseif { $nargs == 3 } {
+ set seg_sel [lindex $args 0]
+ # Shift 1.
+ set args [lrange $args 1 end]
+ } else {
+ error "Incorrect number of args"
+ }
+
+ set arange_start [lindex $args 0]
+ set arange_length [lindex $args 1]
+
+ if { $seg_sel != "" } {
+ variable _seg_size
+ if { $_seg_size == 8 } {
+ set seg_op .8byte
+ } elseif { $_segsize_size == 4 } {
+ set seg_op .4byte
+ } else {
+ error [join "Don't know how to handle" \
+ "segment selector size $_seg_size"]
+ }
+ _op $seg_op $seg_sel "Address range segment selector$comment"
+ }
+
+ variable _addr_size
+ if { $_addr_size == 8 } {
+ set addr_op .8byte
+ } elseif { $_addr_size == 4 } {
+ set addr_op .4byte
+ }
+
+ _op $addr_op $arange_start "Address range start$comment"
+ _op $addr_op $arange_length "Address range length$comment"
+ }
+
+ # Range tuples.
+ uplevel $body
+
+ # Terminator tuple.
+ if { $_seg_size == 0 } {
+ arange -c terminator 0 0
+ } else {
+ arange -c terminator 0 0 0
+ }
+
+ # End label.
+ aranges_end:
+ }
+
proc _empty_array {name} {
upvar $name the_array
next reply other threads:[~2021-08-26 11:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-26 11:56 Tom de Vries [this message]
2021-08-27 13:35 ` Tom Tromey
2021-08-27 14:39 ` Tom de Vries
2021-08-27 15:09 ` Simon Marchi
2021-08-27 16:11 ` Keith Seitz
2021-08-27 16:14 ` Tom Tromey
2021-08-27 17:03 ` Simon Marchi
2021-08-27 17:10 ` Tom Tromey
2021-08-27 17:23 ` Simon Marchi
2021-08-28 15:31 ` Tom de Vries
2021-08-28 20:29 ` Simon Marchi
2021-08-28 21:28 ` Simon Marchi
2021-08-29 15:31 ` Tom de Vries
2021-08-29 19:54 ` Simon Marchi
2021-08-29 21:11 ` Tom de Vries
2021-08-30 8:35 ` Tom de Vries
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=20210826115625.GA22715@delia \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).