]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite/dwarf: convert _section proc to use parse_options
authorSimon Marchi <simon.marchi@polymtl.ca>
Fri, 21 Nov 2025 20:14:00 +0000 (15:14 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 1 Dec 2025 17:45:09 +0000 (12:45 -0500)
New in v2: return early if the section is .debug_str

The following patch will add more options to the _section proc, so
convert it to use options, to be more user-friendly.

Change-Id: I971e4e10e55d63af2a5e29dc5e1d00f368b3ecaa
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/testsuite/lib/dwarf.exp

index cedc12aed57d761cd1d1adb273ada5f1c73831d0..a0da797ca3ffcdb5949dcbb1450ecfd75cd3049d 100644 (file)
@@ -1074,17 +1074,34 @@ namespace eval Dwarf {
        }
     }
 
-    proc _section {name {flags ""} {type ""}} {
-       if {$name == ".debug_str"} {
+    proc _section {name {options {}}} {
+       parse_options {
+           { 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"
+           _emit "        .section .debug_str, \"MS\", %progbits, 1"
+           return
+       }
+
+       set directive ".section $name"
+
+       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.
@@ -3176,7 +3193,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
 
@@ -3610,7 +3630,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}