Skip to content

Commit 8c5f334

Browse files
committed
Add a unit test for llvm-gcc producer strings and cleanup code. (NFC)
1 parent 2edb905 commit 8c5f334

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -671,16 +671,17 @@ void DWARFUnit::ParseProducerInfo() {
671671
if (producer.empty())
672672
return;
673673

674-
static RegularExpression llvm_gcc_regex(
675-
llvm::StringRef("^4\\.[012]\\.[01] \\(Based on Apple "
676-
"Inc\\. build [0-9]+\\) \\(LLVM build "
677-
"[\\.0-9]+\\)$"));
678-
if (llvm_gcc_regex.Execute(producer)) {
674+
static RegularExpression g_llvm_gcc_regex(
675+
llvm::StringRef(R"(4\.[012]\.[01] )"
676+
R"(\(Based on Apple Inc\. build [0-9]+\) )"
677+
R"(\(LLVM build [\.0-9]+\)$)"));
678+
static RegularExpression g_clang_version_regex(
679+
llvm::StringRef(R"(clang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))"));
680+
681+
if (g_llvm_gcc_regex.Execute(producer)) {
679682
m_producer = eProducerLLVMGCC;
680683
} else if (producer.contains("clang")) {
681-
static RegularExpression g_clang_version_regex(
682-
llvm::StringRef(R"(clang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))"));
683-
llvm::SmallVector<llvm::StringRef, 4> matches;
684+
llvm::SmallVector<llvm::StringRef, 3> matches;
684685
if (g_clang_version_regex.Execute(producer, &matches))
685686
m_producer_version.tryParse(matches[1]);
686687
m_producer = eProducerClang;

lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ TEST(DWARFUnitTest, MissingSentinel) {
8585
EXPECT_EQ(die_first->GetSibling(), nullptr);
8686
}
8787

88-
TEST(DWARFUnitTest, Producer) {
88+
TEST(DWARFUnitTest, ClangProducer) {
8989
const char *yamldata = R"(
9090
--- !ELF
9191
FileHeader:
@@ -104,16 +104,13 @@ TEST(DWARFUnitTest, Producer) {
104104
Attributes:
105105
- Attribute: DW_AT_producer
106106
Form: DW_FORM_strp
107-
- Attribute: DW_AT_language
108-
Form: DW_FORM_data2
109107
debug_info:
110108
- Version: 4
111109
AddrSize: 8
112110
Entries:
113111
- AbbrCode: 0x1
114112
Values:
115113
- Value: 0x0
116-
- Value: 0xC
117114
- AbbrCode: 0x0
118115
)";
119116

@@ -123,3 +120,38 @@ TEST(DWARFUnitTest, Producer) {
123120
EXPECT_EQ(unit->GetProducer(), eProducerClang);
124121
EXPECT_EQ(unit->GetProducerVersion(), llvm::VersionTuple(1300, 0, 29, 3));
125122
}
123+
124+
TEST(DWARFUnitTest, LLVMGCCProducer) {
125+
const char *yamldata = R"(
126+
--- !ELF
127+
FileHeader:
128+
Class: ELFCLASS64
129+
Data: ELFDATA2LSB
130+
Type: ET_EXEC
131+
Machine: EM_386
132+
DWARF:
133+
debug_str:
134+
- 'i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)'
135+
debug_abbrev:
136+
- Table:
137+
- Code: 0x00000001
138+
Tag: DW_TAG_compile_unit
139+
Children: DW_CHILDREN_yes
140+
Attributes:
141+
- Attribute: DW_AT_producer
142+
Form: DW_FORM_strp
143+
debug_info:
144+
- Version: 4
145+
AddrSize: 8
146+
Entries:
147+
- AbbrCode: 0x1
148+
Values:
149+
- Value: 0x0
150+
- AbbrCode: 0x0
151+
)";
152+
153+
YAMLModuleTester t(yamldata);
154+
DWARFUnit *unit = t.GetDwarfUnit();
155+
ASSERT_TRUE((bool)unit);
156+
EXPECT_EQ(unit->GetProducer(), eProducerLLVMGCC);
157+
}

0 commit comments

Comments
 (0)