1## Test how we dump the .debug_str section.
2
3## a) Test dumping a .debug_str section with a default section header.
4
5# RUN: yaml2obj --docnum=1 %s | obj2yaml | \
6# RUN:   FileCheck %s --check-prefix=BASIC --implicit-check-not='Name: .debug_str'
7
8## b) Test dumping a .debug_str section whose section header properties are overridden.
9
10## Override the sh_type field.
11# RUN: yaml2obj --docnum=1 -DTYPE=STRTAB %s | obj2yaml | \
12# RUN:   FileCheck %s --check-prefixes=BASIC,COMMON \
13# RUN:     -DTYPE=STRTAB -DFLAGS="[ SHF_MERGE, SHF_STRINGS ]" -D#%x,ADDRALIGN=1
14
15## Override the sh_flags field.
16# RUN: yaml2obj --docnum=1 -DFLAGS=[SHF_ALLOC] %s | obj2yaml | \
17# RUN:   FileCheck %s --check-prefixes=BASIC,COMMON \
18# RUN:     -DTYPE=PROGBITS -DFLAGS="[ SHF_ALLOC ]" -D#%x,ADDRALIGN=1
19
20## Override the sh_link field.
21# RUN: yaml2obj --docnum=1 -DLINK=.sec %s | obj2yaml | \
22# RUN:   FileCheck %s --check-prefixes=BASIC,COMMON,LINK \
23# RUN:     -DTYPE=PROGBITS -DFLAGS="[ SHF_MERGE, SHF_STRINGS ]" -DLINK=.sec -D#%x,ADDRALIGN=1
24
25## Override the sh_addr field.
26# RUN: yaml2obj --docnum=1 -DADDRESS=0x2020 %s | obj2yaml | \
27# RUN:   FileCheck %s --check-prefixes=BASIC,COMMON,ADDRESS \
28# RUN:     -DTYPE=PROGBITS -DFLAGS="[ SHF_MERGE, SHF_STRINGS ]" -D#%x,ADDRALIGN=1 -D#%x,ADDRESS=0x2020
29
30## Override the sh_addralign field.
31# RUN: yaml2obj --docnum=1 -DADDRALIGN=3 %s | obj2yaml | \
32# RUN:   FileCheck %s --check-prefixes=BASIC,COMMON \
33# RUN:     -DTYPE=PROGBITS -DFLAGS="[ SHF_MERGE, SHF_STRINGS ]" -D#%x,ADDRALIGN=3
34
35## Override the sh_entsize field (sh_entsize=3).
36# RUN: yaml2obj --docnum=1 -DENTSIZE=3 %s | obj2yaml | \
37# RUN:   FileCheck %s --check-prefixes=BASIC,COMMON,ENTSIZE \
38# RUN:     -DTYPE=PROGBITS -DFLAGS="[ SHF_MERGE, SHF_STRINGS ]" -D#%x,ADDRALIGN=1 -D#%x,ENTSIZE=3
39
40## Override the sh_entsize field (sh_entsize=0).
41# RUN: yaml2obj --docnum=1 -DENTSIZE=0 %s | obj2yaml | \
42# RUN:   FileCheck %s --check-prefixes=BASIC,COMMON,ENTSIZE \
43# RUN:     -DTYPE=PROGBITS -DFLAGS="[ SHF_MERGE, SHF_STRINGS ]" -D#%x,ADDRALIGN=1 -D#%x,ENTSIZE=0
44
45## Override the sh_info field.
46# RUN: yaml2obj --docnum=1 -DINFO=3 %s | obj2yaml | \
47# RUN:   FileCheck %s --check-prefixes=BASIC,COMMON,INFO \
48# RUN:     -DTYPE=PROGBITS -DFLAGS="[ SHF_MERGE, SHF_STRINGS ]" -D#%x,INFO=3 -D#%x,ADDRALIGN=1 -D#%x,ENTSIZE=1
49
50--- !ELF
51FileHeader:
52  Class: ELFCLASS64
53  Data:  ELFDATA2LSB
54  Type:  ET_EXEC
55Sections:
56  - Name:         .debug_str
57    Type:         SHT_[[TYPE=PROGBITS]]
58    Flags:        [[FLAGS=<none>]]
59    Link:         [[LINK=<none>]]
60    EntSize:      [[ENTSIZE=1]]
61    Info:         [[INFO=<none>]]
62    AddressAlign: [[ADDRALIGN=1]]
63    Address:      [[ADDRESS=<none>]]
64  - Name:         .sec
65    Type:         SHT_PROGBITS
66DWARF:
67  debug_str:
68    - a
69    - b
70    - abc
71
72#       COMMON: - Name:         .debug_str
73#  COMMON-NEXT:   Type:         SHT_[[TYPE]]
74#  COMMON-NEXT:   Flags:        [[FLAGS]]
75#    LINK-NEXT:   Link:         .sec
76# ADDRESS-NEXT:   Address:      0x[[#%x,ADDRESS]]
77#  COMMON-NEXT:   AddressAlign: 0x[[#%x,ADDRALIGN]]
78# ENTSIZE-NEXT:   EntSize:      0x[[#%x,ENTSIZE]]
79#    INFO-NEXT:   Info:         0x[[#%x,INFO]]
80#        BASIC: DWARF:
81#   BASIC-NEXT:   debug_str:
82#   BASIC-NEXT:     - a
83#   BASIC-NEXT:     - b
84#   BASIC-NEXT:     - abc
85#   BASIC-NEXT: ...
86
87## c) Test dumping an empty .debug_str section.
88
89# RUN: yaml2obj --docnum=2 %s | obj2yaml | FileCheck %s --check-prefix=EMPTY --implicit-check-not=Sections
90
91#      EMPTY: DWARF:
92# EMPTY-NEXT:   debug_str:       []
93# EMPTY-NEXT: ...
94
95--- !ELF
96FileHeader:
97  Class: ELFCLASS64
98  Data:  ELFDATA2LSB
99  Type:  ET_EXEC
100DWARF:
101  debug_str: []
102
103## d) Test that yaml2obj stops parsing the .debug_str section if it encounters a
104## string without a null terminator. The output uses a raw content section instead of
105## the DWARF tag to represent the broken .debug_str section.
106
107# RUN: yaml2obj --docnum=3 %s | obj2yaml | FileCheck %s --check-prefix=NO-TERMINATOR
108
109#  NO-TERMINATOR-NOT: DWARF:
110#      NO-TERMINATOR: Sections:
111# NO-TERMINATOR-NEXT:   - Name:    .debug_str
112# NO-TERMINATOR-NEXT:     Type:    SHT_PROGBITS
113# NO-TERMINATOR-NEXT:     Flags:   [ SHF_MERGE, SHF_STRINGS ]
114# NO-TERMINATOR-NEXT:     Content: '61626300616263'
115# NO-TERMINATOR-NEXT: ...
116
117--- !ELF
118FileHeader:
119  Class: ELFCLASS64
120  Data:  ELFDATA2LSB
121  Type:  ET_EXEC
122Sections:
123  - Name:    .debug_str
124    Type:    SHT_PROGBITS
125    Content: "61626300616263" ## "abc\0abc"
126