Skip to content

Commit fe08ab5

Browse files
committed
[DWARFYAML][debug_info] Replace 'InitialLength' with 'Format' and 'Length'.
'InitialLength' is replaced with 'Format' (DWARF32 by default) and 'Length' in this patch. Besides, test cases for DWARFv4 and DWARFv5, DWARF32 and DWARF64 is added. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D82622
1 parent 60cde47 commit fe08ab5

File tree

22 files changed

+470
-258
lines changed

22 files changed

+470
-258
lines changed

lldb/test/API/functionalities/source-map/a.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ DWARF:
296296
- Attribute: DW_AT_type
297297
Form: DW_FORM_ref4
298298
debug_info:
299-
- Length:
300-
TotalLength: 122
299+
- Length: 122
301300
Version: 4
302301
AbbrOffset: 0
303302
AddrSize: 8

lldb/unittests/Expression/DWARFExpressionTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ TEST(DWARFExpression, DW_OP_convert) {
9494
" - Attribute: DW_AT_byte_size\n"
9595
" Form: DW_FORM_data1\n"
9696
"debug_info:\n"
97-
" - Length:\n"
98-
" TotalLength: 0\n"
97+
" - Length: 0\n"
9998
" Version: 4\n"
10099
" AbbrOffset: 0\n"
101100
" AddrSize: 8\n"

lldb/unittests/Symbol/Inputs/inlined-functions.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ DWARF:
342342
- Attribute: DW_AT_type
343343
Form: DW_FORM_ref4
344344
debug_info:
345-
- Length:
346-
TotalLength: 579
345+
- Length: 579
347346
Version: 4
348347
AbbrOffset: 0
349348
AddrSize: 8

lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ TEST_F(DWARFASTParserClangTests,
5656
" - Attribute: DW_AT_byte_size\n"
5757
" Form: DW_FORM_data1\n"
5858
"debug_info:\n"
59-
" - Length:\n"
60-
" TotalLength: 0\n"
59+
" - Length: 0\n"
6160
" Version: 4\n"
6261
" AbbrOffset: 0\n"
6362
" AddrSize: 8\n"

llvm/include/llvm/ObjectYAML/DWARFYAML.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ struct Entry {
117117
};
118118

119119
struct Unit {
120-
InitialLength Length;
120+
dwarf::DwarfFormat Format;
121+
uint64_t Length;
121122
uint16_t Version;
122123
llvm::dwarf::UnitType Type; // Added in DWARF 5
123124
yaml::Hex64 AbbrOffset;

llvm/lib/ObjectYAML/DWARFEmitter.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,18 @@ class DumpVisitor : public DWARFYAML::ConstVisitor {
208208

209209
protected:
210210
void onStartCompileUnit(const DWARFYAML::Unit &CU) override {
211-
writeInitialLength(CU.Length, OS, DebugInfo.IsLittleEndian);
211+
writeInitialLength(CU.Format, CU.Length, OS, DebugInfo.IsLittleEndian);
212212
writeInteger((uint16_t)CU.Version, OS, DebugInfo.IsLittleEndian);
213213
if (CU.Version >= 5) {
214214
writeInteger((uint8_t)CU.Type, OS, DebugInfo.IsLittleEndian);
215215
writeInteger((uint8_t)CU.AddrSize, OS, DebugInfo.IsLittleEndian);
216216
cantFail(writeVariableSizedInteger(CU.AbbrOffset,
217-
CU.Length.isDWARF64() ? 8 : 4, OS,
218-
DebugInfo.IsLittleEndian));
217+
CU.Format == dwarf::DWARF64 ? 8 : 4,
218+
OS, DebugInfo.IsLittleEndian));
219219
} else {
220220
cantFail(writeVariableSizedInteger(CU.AbbrOffset,
221-
CU.Length.isDWARF64() ? 8 : 4, OS,
222-
DebugInfo.IsLittleEndian));
221+
CU.Format == dwarf::DWARF64 ? 8 : 4,
222+
OS, DebugInfo.IsLittleEndian));
223223
writeInteger((uint8_t)CU.AddrSize, OS, DebugInfo.IsLittleEndian);
224224
}
225225
}
@@ -442,9 +442,7 @@ class DIEFixupVisitor : public DWARFYAML::Visitor {
442442
Length = CU.Version >= 5 ? 8 : 7;
443443
}
444444

445-
virtual void onEndCompileUnit(DWARFYAML::Unit &CU) {
446-
CU.Length.setLength(Length);
447-
}
445+
virtual void onEndCompileUnit(DWARFYAML::Unit &CU) { CU.Length = Length; }
448446

449447
virtual void onStartDIE(DWARFYAML::Unit &CU, DWARFYAML::Entry &DIE) {
450448
Length += getULEB128Size(DIE.AbbrCode);

llvm/lib/ObjectYAML/DWARFVisitor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//===----------------------------------------------------------------------===//
1010

1111
#include "DWARFVisitor.h"
12+
#include "llvm/BinaryFormat/Dwarf.h"
1213
#include "llvm/ObjectYAML/DWARFYAML.h"
1314
#include "llvm/Support/Errc.h"
1415
#include "llvm/Support/Error.h"
@@ -36,7 +37,7 @@ void DWARFYAML::VisitorImpl<T>::onVariableSizeValue(uint64_t U, unsigned Size) {
3637
}
3738

3839
static unsigned getOffsetSize(const DWARFYAML::Unit &Unit) {
39-
return Unit.Length.isDWARF64() ? 8 : 4;
40+
return Unit.Format == dwarf::DWARF64 ? 8 : 4;
4041
}
4142

4243
static unsigned getRefSize(const DWARFYAML::Unit &Unit) {

llvm/lib/ObjectYAML/DWARFYAML.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ void MappingTraits<DWARFYAML::PubSection>::mapping(
132132
}
133133

134134
void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
135+
IO.mapOptional("Format", Unit.Format, dwarf::DWARF32);
135136
IO.mapRequired("Length", Unit.Length);
136137
IO.mapRequired("Version", Unit.Version);
137138
if (Unit.Version >= 5)

llvm/test/ObjectYAML/MachO/DWARF-debug_info.yaml

Lines changed: 196 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# RUN: yaml2obj %s | obj2yaml | FileCheck %s
1+
## This file contains test cases for generating a DAWRFv4 .debug_info
2+
## section in object files from the DWARF entry of Mach-O YAML inputs.
3+
4+
## a) Test that yaml2obj emits a DWARF32 .debug_info sections and obj2yaml
5+
## converts it back.
6+
7+
# RUN: yaml2obj --docnum=1 %s | obj2yaml | FileCheck %s --check-prefix=DWARF32
28

39
--- !mach-o
410
FileHeader:
@@ -384,8 +390,7 @@ DWARF:
384390
- Address: 0x0000000100000F50
385391
Length: 52
386392
debug_info:
387-
- Length:
388-
TotalLength: 117
393+
- Length: 117
389394
Version: 4
390395
AbbrOffset: 0
391396
AddrSize: 8
@@ -506,69 +511,192 @@ DWARF:
506511
...
507512
...
508513

514+
# DWARF32: DWARF:
515+
# DWARF32: debug_info:
516+
# DWARF32-NEXT: - Length: 117
517+
# DWARF32-NEXT: Version: 4
518+
# DWARF32-NEXT: AbbrOffset: 0
519+
# DWARF32-NEXT: AddrSize: 8
520+
# DWARF32-NEXT: Entries:
521+
# DWARF32-NEXT: - AbbrCode: 0x00000001
522+
# DWARF32-NEXT: Values:
523+
# DWARF32-NEXT: - Value: 0x0000000000000001
524+
# DWARF32-NEXT: - Value: 0x000000000000000C
525+
# DWARF32-NEXT: - Value: 0x0000000000000038
526+
# DWARF32-NEXT: - Value: 0x0000000000000000
527+
# DWARF32-NEXT: - Value: 0x0000000000000046
528+
# DWARF32-NEXT: - Value: 0x0000000100000F50
529+
# DWARF32-NEXT: - Value: 0x0000000000000034
530+
# DWARF32-NEXT: - AbbrCode: 0x00000002
531+
# DWARF32-NEXT: Values:
532+
# DWARF32-NEXT: - Value: 0x0000000100000F50
533+
# DWARF32-NEXT: - Value: 0x0000000000000034
534+
# DWARF32-NEXT: - Value: 0x0000000000000001
535+
# DWARF32-NEXT: BlockData: [ 0x56 ]
536+
# DWARF32-NEXT: - Value: 0x0000000000000076
537+
# DWARF32-NEXT: - Value: 0x0000000000000001
538+
# DWARF32-NEXT: - Value: 0x0000000000000003
539+
# DWARF32-NEXT: - Value: 0x0000000000000001
540+
# DWARF32-NEXT: - Value: 0x0000000000000060
541+
# DWARF32-NEXT: - Value: 0x0000000000000001
542+
# DWARF32-NEXT: - AbbrCode: 0x00000003
543+
# DWARF32-NEXT: Values:
544+
# DWARF32-NEXT: - Value: 0x0000000000000002
545+
# DWARF32-NEXT: BlockData: [ 0x91, 0x78 ]
546+
# DWARF32-NEXT: - Value: 0x000000000000007B
547+
# DWARF32-NEXT: - Value: 0x0000000000000001
548+
# DWARF32-NEXT: - Value: 0x0000000000000003
549+
# DWARF32-NEXT: - Value: 0x0000000000000060
550+
# DWARF32-NEXT: - AbbrCode: 0x00000003
551+
# DWARF32-NEXT: Values:
552+
# DWARF32-NEXT: - Value: 0x0000000000000002
553+
# DWARF32-NEXT: BlockData: [ 0x91, 0x70 ]
554+
# DWARF32-NEXT: - Value: 0x0000000000000080
555+
# DWARF32-NEXT: - Value: 0x0000000000000001
556+
# DWARF32-NEXT: - Value: 0x0000000000000003
557+
# DWARF32-NEXT: - Value: 0x0000000000000067
558+
# DWARF32-NEXT: - AbbrCode: 0x00000000
559+
# DWARF32-NEXT: Values:
560+
# DWARF32-NEXT: - AbbrCode: 0x00000004
561+
# DWARF32-NEXT: Values:
562+
# DWARF32-NEXT: - Value: 0x0000000000000085
563+
# DWARF32-NEXT: - Value: 0x0000000000000005
564+
# DWARF32-NEXT: - Value: 0x0000000000000004
565+
# DWARF32-NEXT: - AbbrCode: 0x00000005
566+
# DWARF32-NEXT: Values:
567+
# DWARF32-NEXT: - Value: 0x000000000000006C
568+
# DWARF32-NEXT: - AbbrCode: 0x00000005
569+
# DWARF32-NEXT: Values:
570+
# DWARF32-NEXT: - Value: 0x0000000000000071
571+
# DWARF32-NEXT: - AbbrCode: 0x00000004
572+
# DWARF32-NEXT: Values:
573+
# DWARF32-NEXT: - Value: 0x0000000000000089
574+
# DWARF32-NEXT: - Value: 0x0000000000000006
575+
# DWARF32-NEXT: - Value: 0x0000000000000001
576+
# DWARF32-NEXT: - AbbrCode: 0x00000000
577+
# DWARF32-NEXT: Values:
578+
579+
## b) Test that yaml2obj emits a correct unit header and obj2yaml is able to convert it back.
580+
581+
## Test DWARF32 unit header.
582+
583+
# RUN: yaml2obj --docnum=2 -DFORMAT=DWARF32 %s -o %t2.dwarf32.o
584+
# RUN: llvm-readobj --hex-dump=__debug_info %t2.dwarf32.o | \
585+
# RUN: FileCheck %s --check-prefix=DWARF32-HEADER
586+
587+
# DWARF32-HEADER: Hex dump of section '__debug_info':
588+
# DWARF32-HEADER-NEXT: 0x00000000 0c000000 04000000 00000801 34120000 ............4...
589+
## ^------- unit_length (4-byte)
590+
## ^--- version (2-byte)
591+
## ^-------- debug_abbrev_offset (4-byte)
592+
## ^- address_size (1-byte)
593+
## ^- abbrev code (ULEB128)
594+
## ^------- value, Form: DW_FORM_addr (4-byte)
595+
596+
# RUN: obj2yaml %t2.dwarf32.o | FileCheck %s --check-prefix=DWARF32-YAML
597+
598+
# DWARF32-YAML: debug_info:
599+
# DWARF32-YAML-NEXT: - Length: 12
600+
# DWARF32-YAML-NEXT: Version: 4
601+
# DWARF32-YAML-NEXT: AbbrOffset: 0
602+
# DWARF32-YAML-NEXT: AddrSize: 8
603+
# DWARF32-YAML-NEXT: Entries:
604+
# DWARF32-YAML-NEXT: - AbbrCode: 0x00000001
605+
# DWARF32-YAML-NEXT: Values:
606+
# DWARF32-YAML-NEXT: - Value: 0x0000000000001234
607+
608+
--- !mach-o
609+
FileHeader:
610+
magic: 0xFEEDFACF
611+
cputype: 0x01000007
612+
cpusubtype: 0x00000003
613+
filetype: 0x0000000A
614+
ncmds: 1
615+
sizeofcmds: 232
616+
flags: 0x00000000
617+
reserved: 0x00000000
618+
LoadCommands:
619+
- cmd: LC_SEGMENT_64
620+
cmdsize: 232
621+
segname: __DWARF
622+
vmaddr: 0x00
623+
vmsize: 0x00
624+
fileoff: 0x00
625+
filesize: 0x00
626+
maxprot: 0
627+
initprot: 0
628+
nsects: 2
629+
flags: 0
630+
Sections:
631+
- sectname: __debug_abbrev
632+
segname: __DWARF
633+
addr: 0x00
634+
size: 12
635+
offset: 528
636+
align: 0
637+
reloff: 0x00000000
638+
nreloc: 0
639+
flags: 0x00000000
640+
reserved1: 0x00000000
641+
reserved2: 0x00000000
642+
reserved3: 0x00000000
643+
- sectname: __debug_info
644+
segname: __DWARF
645+
addr: 0x00
646+
size: 0xffff
647+
offset: 1070
648+
align: 0
649+
reloff: 0x00000000
650+
nreloc: 0
651+
flags: 0x00000000
652+
reserved1: 0x00000000
653+
reserved2: 0x00000000
654+
reserved3: 0x00000000
655+
DWARF:
656+
debug_abbrev:
657+
- Code: 1
658+
Tag: DW_TAG_compile_unit
659+
Children: DW_CHILDREN_no
660+
Attributes:
661+
- Attribute: DW_AT_low_pc
662+
Form: DW_FORM_addr
663+
debug_info:
664+
- Format: [[FORMAT]]
665+
Length: 12
666+
Version: 4
667+
AbbrOffset: 0
668+
AddrSize: 8
669+
Entries:
670+
- AbbrCode: 1
671+
Values:
672+
- Value: 0x1234
673+
674+
## Test DWARF64 unit header.
675+
676+
# RUN: yaml2obj --docnum=2 -DFORMAT=DWARF64 %s -o %t2.dwarf64.o
677+
# RUN: llvm-readobj --hex-dump=__debug_info %t2.dwarf64.o | \
678+
# RUN: FileCheck %s --check-prefix=DWARF64-HEADER
679+
680+
# DWARF64-HEADER: Hex dump of section '__debug_info':
681+
# DWARF64-HEADER-NEXT: 0x00000000 ffffffff 0c000000 00000000 04000000 ................
682+
## ^------------------------- unit_length (12-byte)
683+
## ^--- version (2-byte)
684+
## ^--- debug_abbrev_offset (8-byte)
685+
# DWARF64-HEADER-NEXT: 0x00000010 00000000 00000801 34120000 00000000 ........4.......
686+
## -------------
687+
## ^- address_size (1-byte)
688+
## ^- abbrev code (ULEB128)
689+
## ^---------------- value, Form: DW_FORM_addr (8-byte)
690+
691+
# RUN: obj2yaml %t2.dwarf64.o | FileCheck %s --check-prefix=DWARF64-YAML
509692

510-
#CHECK: DWARF:
511-
#CHECK: debug_info:
512-
#CHECK: - Length:
513-
#CHECK: TotalLength: 117
514-
#CHECK: Version: 4
515-
#CHECK: AbbrOffset: 0
516-
#CHECK: AddrSize: 8
517-
#CHECK: Entries:
518-
#CHECK: - AbbrCode: 0x00000001
519-
#CHECK: Values:
520-
#CHECK: - Value: 0x0000000000000001
521-
#CHECK: - Value: 0x000000000000000C
522-
#CHECK: - Value: 0x0000000000000038
523-
#CHECK: - Value: 0x0000000000000000
524-
#CHECK: - Value: 0x0000000000000046
525-
#CHECK: - Value: 0x0000000100000F50
526-
#CHECK: - Value: 0x0000000000000034
527-
#CHECK: - AbbrCode: 0x00000002
528-
#CHECK: Values:
529-
#CHECK: - Value: 0x0000000100000F50
530-
#CHECK: - Value: 0x0000000000000034
531-
#CHECK: - Value: 0x0000000000000001
532-
#CHECK: BlockData: [ 0x56 ]
533-
#CHECK: - Value: 0x0000000000000076
534-
#CHECK: - Value: 0x0000000000000001
535-
#CHECK: - Value: 0x0000000000000003
536-
#CHECK: - Value: 0x0000000000000001
537-
#CHECK: - Value: 0x0000000000000060
538-
#CHECK: - Value: 0x0000000000000001
539-
#CHECK: - AbbrCode: 0x00000003
540-
#CHECK: Values:
541-
#CHECK: - Value: 0x0000000000000002
542-
#CHECK: BlockData: [ 0x91, 0x78 ]
543-
#CHECK: - Value: 0x000000000000007B
544-
#CHECK: - Value: 0x0000000000000001
545-
#CHECK: - Value: 0x0000000000000003
546-
#CHECK: - Value: 0x0000000000000060
547-
#CHECK: - AbbrCode: 0x00000003
548-
#CHECK: Values:
549-
#CHECK: - Value: 0x0000000000000002
550-
#CHECK: BlockData: [ 0x91, 0x70 ]
551-
#CHECK: - Value: 0x0000000000000080
552-
#CHECK: - Value: 0x0000000000000001
553-
#CHECK: - Value: 0x0000000000000003
554-
#CHECK: - Value: 0x0000000000000067
555-
#CHECK: - AbbrCode: 0x00000000
556-
#CHECK: Values:
557-
#CHECK: - AbbrCode: 0x00000004
558-
#CHECK: Values:
559-
#CHECK: - Value: 0x0000000000000085
560-
#CHECK: - Value: 0x0000000000000005
561-
#CHECK: - Value: 0x0000000000000004
562-
#CHECK: - AbbrCode: 0x00000005
563-
#CHECK: Values:
564-
#CHECK: - Value: 0x000000000000006C
565-
#CHECK: - AbbrCode: 0x00000005
566-
#CHECK: Values:
567-
#CHECK: - Value: 0x0000000000000071
568-
#CHECK: - AbbrCode: 0x00000004
569-
#CHECK: Values:
570-
#CHECK: - Value: 0x0000000000000089
571-
#CHECK: - Value: 0x0000000000000006
572-
#CHECK: - Value: 0x0000000000000001
573-
#CHECK: - AbbrCode: 0x00000000
574-
#CHECK: Values:
693+
# DWARF64-YAML: debug_info:
694+
# DWARF64-YAML-NEXT: - Format: DWARF64
695+
# DWARF64-YAML-NEXT: Length: 12
696+
# DWARF64-YAML-NEXT: Version: 4
697+
# DWARF64-YAML-NEXT: AbbrOffset: 0
698+
# DWARF64-YAML-NEXT: AddrSize: 8
699+
# DWARF64-YAML-NEXT: Entries:
700+
# DWARF64-YAML-NEXT: - AbbrCode: 0x00000001
701+
# DWARF64-YAML-NEXT: Values:
702+
# DWARF64-YAML-NEXT: - Value: 0x0000000000001234

llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ DWARF:
423423
- DieOffset: 0x00000071
424424
Name: char
425425
debug_info:
426-
- Length:
427-
TotalLength: 117
426+
- Length: 117
428427
Version: 4
429428
AbbrOffset: 0
430429
AddrSize: 8

0 commit comments

Comments
 (0)