[gdb/testsuite] Factor out _line_finalize_header
authorTom de Vries <tdevries@suse.de>
Mon, 22 Nov 2021 08:14:15 +0000 (09:14 +0100)
committerTom de Vries <tdevries@suse.de>
Mon, 22 Nov 2021 08:14:15 +0000 (09:14 +0100)
Rather than generate dwarf immediately in procs include_dir and file_name,
postpone generation and store the data in variables.  Then handle the
generation in a new proc _line_finalize_header.

Tested on x86-64-linux.

gdb/testsuite/lib/dwarf.exp

index fd914c365baee0c483367acf130725fa9afe8e41..d5451db90aadbabec464cc8f5fb7f9a262043e98 100644 (file)
@@ -2176,6 +2176,9 @@ namespace eval Dwarf {
     proc lines {options label body} {
        variable _line_count
        variable _line_saw_file
+       variable _line_include_dirs
+       variable _line_file_names
+       variable _line_header_finalized
        variable _line_saw_program
        variable _line_header_end_label
 
@@ -2185,6 +2188,9 @@ namespace eval Dwarf {
        set _unit_addr_size default
        set _line_saw_program 0
        set _line_saw_file 0
+       set _line_include_dirs {}
+       set _line_file_names {}
+       set _line_header_finalized 0
        set _default_is_stmt 1
 
        foreach { name value } $options {
@@ -2265,21 +2271,50 @@ namespace eval Dwarf {
        _op .byte 1 "standard opcode 9"
 
        proc include_dir {dirname} {
-           _op .ascii [_quote $dirname]
+           variable _line_include_dirs
+           lappend _line_include_dirs $dirname
        }
 
        proc file_name {filename diridx} {
-           variable _line_saw_file
-           if "! $_line_saw_file" {
-               # Terminate the dir list.
-               _op .byte 0 "Terminator."
-               set _line_saw_file 1
+           variable _line_file_names
+           lappend _line_file_names $filename $diridx
+
+           variable _line_saw_file 1
+           set _line_saw_file 1
+       }
+
+       proc _line_finalize_header {} {
+           variable _line_header_finalized
+           if { $_line_header_finalized } {
+               return
            }
+           set _line_header_finalized 1
 
-           _op .ascii [_quote $filename]
-           _op .sleb128 $diridx
-           _op .sleb128 0 "mtime"
-           _op .sleb128 0 "length"
+           variable _line_include_dirs
+           variable _line_file_names
+
+           if { 1 } {
+               foreach dirname $_line_include_dirs {
+                   _op .ascii [_quote $dirname]
+               }
+
+               _op .byte 0 "Terminator (include_directories)"
+
+               foreach { filename diridx } $_line_file_names {
+                   _op .ascii [_quote $filename]
+                   _op .sleb128 $diridx
+                   _op .sleb128 0 "mtime"
+                   _op .sleb128 0 "length"
+               }
+
+               _op .byte 0 "Terminator (file_names)"
+           }
+
+           set _line_include_dirs {}
+           set _line_file_names {}
+
+           variable _line_header_end_label
+           define_label $_line_header_end_label
        }
 
        proc program {statements} {
@@ -2287,14 +2322,11 @@ namespace eval Dwarf {
            variable _line_header_end_label
            variable _line
 
+           set _line_saw_program 1
+
            set _line 1
 
-           if "! $_line_saw_program" {
-               # Terminate the file list.
-               _op .byte 0 "Terminator."
-               define_label $_line_header_end_label
-               set _line_saw_program 1
-           }
+           _line_finalize_header
 
            proc DW_LNE_set_address {addr} {
                _op .byte 0
@@ -2385,16 +2417,7 @@ namespace eval Dwarf {
        rename include_dir ""
        rename file_name ""
 
-       # Terminate dir list if we saw no files.
-       if "! $_line_saw_file" {
-           _op .byte 0 "Terminator."
-       }
-
-       # Terminate the file list.
-       if "! $_line_saw_program" {
-           _op .byte 0 "Terminator."
-           define_label $_line_header_end_label
-       }
+       _line_finalize_header
 
        define_label $unit_end_label
     }