Re: [PATCH 2/6] gdb/testsuite/dwarf: convert _section proc to use parse_options

Andrew Burgess
2025-11-19T11:00:36Z

Simon Marchi <simon.marchi@efficios.com> writes:

> From: Simon Marchi <simon.marchi@polymtl.ca>
>
> The following patch will add more options to the _section proc, so
> convert it to use options, to be more user-friendly.

LGTM.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

>
> Change-Id: I971e4e10e55d63af2a5e29dc5e1d00f368b3ecaa
> ---
> gdb/testsuite/lib/dwarf.exp | 45 +++++++++++++++++++++++++++----------
> 1 file changed, 33 insertions(+), 12 deletions(-)
>
> diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
> index 919e2e05687f..5536b7656b8c 100644
> --- a/gdb/testsuite/lib/dwarf.exp
> +++ b/gdb/testsuite/lib/dwarf.exp
> @@ -1071,17 +1071,33 @@ namespace eval Dwarf {
> }
> }
>
> - proc _section {name {flags ""} {type ""}} {
> - if {$name == ".debug_str"} {
> - # Hard-code this because it's always desirable.
> - _emit " .section $name, \"MS\", %progbits, 1"
> - } elseif {$flags == "" && $type == ""} {
> - _emit " .section $name"
> - } elseif {$type == ""} {
> - _emit " .section $name, \"$flags\""
> - } else {
> - _emit " .section $name, \"$flags\", %$type"
> + proc _section {name {options {}}} {
> + parse_options {
> + { flags "" }
> + { type "" }
> }
> +
> + set directive ".section $name"
> +
> + if { $name == ".debug_str" } {
> + # Hard-code this because it's always desirable.
> + append directive ", \"MS\", %progbits, 1"
> + }
> +
> + if { $flags != "" } {
> + append directive ",\"$flags\""
> + }
> +
> + if { $type != "" } {
> + # Can't specify a type without flags.
> + if { $flags == "" } {
> + append directive ", \"\""
> + }
> +
> + append directive ", %$type"
> + }
> +
> + _emit " $directive"
> }
>
> # SECTION_SPEC is a list of arguments to _section.
> @@ -3173,7 +3189,10 @@ namespace eval Dwarf {
>
> # Emit a note section holding the given build-id.
> proc build_id {buildid} {
> - _defer_output {.note.gnu.build-id a note} {
> + _defer_output {.note.gnu.build-id {
> + flags a
> + type note
> + }} {
> # From elf/common.h.
> set NT_GNU_BUILD_ID 3
>
> @@ -3607,7 +3626,9 @@ namespace eval Dwarf {
>
> _write_deferred_output
>
> - _section .note.GNU-stack "" progbits
> + _section .note.GNU-stack {
> + type progbits
> + }
>
> if { $file_id == "" } {
> catch {close $_output_file}
> --
> 2.51.2