Skip to content

Conversation

Michael137
Copy link
Member

@Michael137 Michael137 commented Oct 3, 2025

Currently we don't benefit from the user-friendly names that LanguageDescription returns because we would always use Language::GetNameForLanguageType. I'm not aware of a situation where GetDescription should prefer the non-human readable form of the name with. This patch removes the call to GetNameForLanguageType.

LanguageDescription already handles languages that it doesn't know about. For those it would return Unknown. The LLDB language types should all be available via DWARF. If there are languages that don't map cleanly between lldb::LanguageType and DW_LANG, then we should add explicit support for that in the SourceLanguage::SourceLanguage constructor.

Currently we don't benefit from the user-friendly names that `LanguageDescription` returns because we would always use `Language::GetNameForLanguageType`. I'm not aware of a situation where `GetDescription` should prefer the non-human readable form of the name with. This patch removes the call to `GetNameForLanguageType`.
@llvmbot
Copy link
Member

llvmbot commented Oct 3, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

Currently we don't benefit from the user-friendly names that LanguageDescription returns because we would always use Language::GetNameForLanguageType. I'm not aware of a situation where GetDescription should prefer the non-human readable form of the name with. This patch removes the call to GetNameForLanguageType.


Full diff: https://github.com/llvm/llvm-project/pull/161804.diff

1 Files Affected:

  • (modified) lldb/source/Target/Language.cpp (+1-4)
diff --git a/lldb/source/Target/Language.cpp b/lldb/source/Target/Language.cpp
index 484d9badde397..7ce85dd93f091 100644
--- a/lldb/source/Target/Language.cpp
+++ b/lldb/source/Target/Language.cpp
@@ -559,11 +559,8 @@ lldb::LanguageType SourceLanguage::AsLanguageType() const {
 }
 
 llvm::StringRef SourceLanguage::GetDescription() const {
-  LanguageType type = AsLanguageType();
-  if (type)
-    return Language::GetNameForLanguageType(type);
   return llvm::dwarf::LanguageDescription(
-      (llvm::dwarf::SourceLanguageName)name);
+      static_cast<llvm::dwarf::SourceLanguageName>(name));
 }
 bool SourceLanguage::IsC() const { return name == llvm::dwarf::DW_LNAME_C; }
 

@Michael137 Michael137 force-pushed the lldb/language-description-api branch from 89bda08 to 29d911d Compare October 3, 2025 09:22
Copy link

github-actions bot commented Oct 3, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@Michael137 Michael137 force-pushed the lldb/language-description-api branch from 65aceb1 to bc4952c Compare October 3, 2025 17:31
default: break;
}

llvm_unreachable("Unhandled language type");
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Member Author

@Michael137 Michael137 Oct 3, 2025

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

@Michael137 Michael137 merged commit 7f51a2a into llvm:main Oct 3, 2025
9 checks passed
@Michael137 Michael137 deleted the lldb/language-description-api branch October 3, 2025 22:15
Michael137 added a commit that referenced this pull request Oct 3, 2025
…1803)

The intention for this API is to be used when presenting language names
to the user, e.g., in expression evaluation diagnostics or LLDB errors.

Most uses of `GetNameForLanguageType` can be probably replaced with
`GetDisplayNameForLanguageType`, but that's out of scope of this PR.

This uses `llvm::dwarf::LanguageDescription` under the hood, so we would
lose the version numbers in the names. If we deem those to be important,
we could switch to an implementation that hardcodes a list of
user-friendly names with version numbers included.

The intention is to use it from
#161688

Depends on #161804
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 3, 2025
…pe API (#161803)

The intention for this API is to be used when presenting language names
to the user, e.g., in expression evaluation diagnostics or LLDB errors.

Most uses of `GetNameForLanguageType` can be probably replaced with
`GetDisplayNameForLanguageType`, but that's out of scope of this PR.

This uses `llvm::dwarf::LanguageDescription` under the hood, so we would
lose the version numbers in the names. If we deem those to be important,
we could switch to an implementation that hardcodes a list of
user-friendly names with version numbers included.

The intention is to use it from
llvm/llvm-project#161688

Depends on llvm/llvm-project#161804
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants