-
Notifications
You must be signed in to change notification settings - Fork 15k
[lldb][Language] Simplify SourceLanguage::GetDescription #161804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Michael137
merged 6 commits into
llvm:main
from
Michael137:lldb/language-description-api
Oct 3, 2025
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
159ee47
[lldb][Language] Simplify SourceLanguage::GetDescription
Michael137 29d911d
fixup! handle non-standard languages
Michael137 bc4952c
fixup! add test
Michael137 d914c4b
fixup! add another test
Michael137 f341190
fixup! clean up switch statement
Michael137 3762551
fixup! llvm_unreachable -> std::optional
Michael137 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| //===-- LanguageTest.cpp --------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "lldb/Target/Language.h" | ||
| #include "lldb/lldb-enumerations.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| using namespace lldb_private; | ||
| using namespace lldb; | ||
|
|
||
| namespace { | ||
| class LanguageTest : public ::testing::Test {}; | ||
| } // namespace | ||
|
|
||
| TEST_F(LanguageTest, SourceLanguage_GetDescription) { | ||
| for (uint32_t i = 1; i < lldb::eNumLanguageTypes; ++i) { | ||
| // 0x29 is unassigned | ||
| if (i == 0x29) | ||
| continue; | ||
|
|
||
| auto lang_type = static_cast<lldb::LanguageType>(i); | ||
| if (lang_type == lldb::eLanguageTypeLastStandardLanguage) | ||
| continue; | ||
|
|
||
| SourceLanguage lang(lang_type); | ||
|
|
||
| // eLanguageTypeHIP is not implemented as a DW_LNAME because of a conflict. | ||
| if (lang_type == lldb::eLanguageTypeHIP) | ||
| EXPECT_FALSE(lang); | ||
| else | ||
| EXPECT_TRUE(lang); | ||
| } | ||
|
|
||
| EXPECT_EQ(SourceLanguage(eLanguageTypeC_plus_plus).GetDescription(), | ||
| "ISO C++"); | ||
| EXPECT_EQ(SourceLanguage(eLanguageTypeC_plus_plus_17).GetDescription(), | ||
| "ISO C++"); | ||
| EXPECT_EQ(SourceLanguage(eLanguageTypeC_plus_plus_20).GetDescription(), | ||
| "ISO C++"); | ||
|
|
||
| EXPECT_EQ(SourceLanguage(eLanguageTypeObjC).GetDescription(), "Objective C"); | ||
| EXPECT_EQ(SourceLanguage(eLanguageTypeMipsAssembler).GetDescription(), | ||
| "Assembly"); | ||
|
|
||
| auto next_vendor_language = | ||
| static_cast<lldb::LanguageType>(eLanguageTypeMipsAssembler + 1); | ||
| if (next_vendor_language < eNumLanguageTypes) | ||
| EXPECT_NE(SourceLanguage(next_vendor_language).GetDescription(), "Unknown"); | ||
|
|
||
| EXPECT_EQ(SourceLanguage(eLanguageTypeUnknown).GetDescription(), "Unknown"); | ||
| } | ||
|
|
||
| TEST_F(LanguageTest, SourceLanguage_AsLanguageType) { | ||
| EXPECT_EQ(SourceLanguage(eLanguageTypeC_plus_plus).AsLanguageType(), | ||
| eLanguageTypeC_plus_plus); | ||
| EXPECT_EQ(SourceLanguage(eLanguageTypeC_plus_plus_03).AsLanguageType(), | ||
| eLanguageTypeC_plus_plus_03); | ||
|
|
||
| // Vendor-specific language code. | ||
| EXPECT_EQ(SourceLanguage(eLanguageTypeMipsAssembler).AsLanguageType(), | ||
| eLanguageTypeAssembly); | ||
| EXPECT_EQ(SourceLanguage(eLanguageTypeUnknown).AsLanguageType(), | ||
| eLanguageTypeUnknown); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we cannot get here even if. we parse DWARF with e.g., a DW_LANG_user_low+n language attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise a fail-safe that doesn't crash might be more appropriate.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true if the debuggee was compiled with a compiler that emitted a vendor language that LLDB isn't aware of. That would hit this codepath. Let me relax this a bit