[Lldb-commits] [lldb] [lldb][Lanugage] Add Language::GetDisplayNameForLanguageType API (PR #161803)

via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 3 01:32:12 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

<details>
<summary>Changes</summary>

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 https://github.com/llvm/llvm-project/pull/161688

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


2 Files Affected:

- (modified) lldb/include/lldb/Target/Language.h (+7) 
- (modified) lldb/source/Target/Language.cpp (+4) 


``````````diff
diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h
index 3d0aa326d5a6d..48a7ac2cea42f 100644
--- a/lldb/include/lldb/Target/Language.h
+++ b/lldb/include/lldb/Target/Language.h
@@ -404,8 +404,15 @@ class Language : public PluginInterface {
   GetLanguageTypeFromString(const char *string) = delete;
   static lldb::LanguageType GetLanguageTypeFromString(llvm::StringRef string);
 
+  /// Returns the internal LLDB name for the specified language. When presenting
+  /// the language name to users, use \ref GetDisplayNameForLanguageType
+  /// instead.
   static const char *GetNameForLanguageType(lldb::LanguageType language);
 
+  /// Returns a user-friendly name for the specified language.
+  static llvm::StringRef
+  GetDisplayNameForLanguageType(lldb::LanguageType language);
+
   static void PrintAllLanguages(Stream &s, const char *prefix,
                                 const char *suffix);
 
diff --git a/lldb/source/Target/Language.cpp b/lldb/source/Target/Language.cpp
index 484d9badde397..f0fc48e18793b 100644
--- a/lldb/source/Target/Language.cpp
+++ b/lldb/source/Target/Language.cpp
@@ -270,6 +270,10 @@ const char *Language::GetNameForLanguageType(LanguageType language) {
     return language_names[eLanguageTypeUnknown].name;
 }
 
+llvm::StringRef Language::GetDisplayNameForLanguageType(LanguageType language) {
+  return SourceLanguage(language).GetDescription();
+}
+
 void Language::PrintSupportedLanguagesForExpressions(Stream &s,
                                                      llvm::StringRef prefix,
                                                      llvm::StringRef suffix) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/161803


More information about the lldb-commits mailing list