[Lldb-commits] [lldb] 3ffeb0e - [lldb-dap] Report the language of compile units (#235995)

via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 30 02:58:14 PDT 2026


Author: Nathan Fusselman
Date: 2026-10-30T09:58:09Z
New Revision: 3ffeb0eab773701ecbadcf78acaa42cd5bc380c8

URL: https://github.com/llvm/llvm-project/commit/3ffeb0eab773701ecbadcf78acaa42cd5bc380c8
DIFF: https://github.com/llvm/llvm-project/commit/3ffeb0eab773701ecbadcf78acaa42cd5bc380c8.diff

LOG: [lldb-dap] Report the language of compile units (#235995)

Add language to the CompileUnit type in the compileUnits response, with
its version where known, for example c11 or c++17. Clients can use it
instead of guessing a frame's language from its file extension. It is
omitted when the language is unknown.

rdar://190656790

Added: 
    

Modified: 
    lldb/docs/resources/lldbdap-extensions.md
    lldb/packages/Python/lldbsuite/test/tools/lldb_dap/types.py
    lldb/test/API/tools/lldb-dap/stackTrace/Makefile
    lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py
    lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
    lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp
    lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
    lldb/unittests/DAP/ProtocolRequestsTest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/docs/resources/lldbdap-extensions.md b/lldb/docs/resources/lldbdap-extensions.md
index d0670fcfac413e..4ccee9309aefa0 100644
--- a/lldb/docs/resources/lldbdap-extensions.md
+++ b/lldb/docs/resources/lldbdap-extensions.md
@@ -79,6 +79,12 @@ interface CompileUnit {
    * The path of the compile unit.
    */
   compileUnitPath: string;
+
+  /**
+   * The language of the compile unit, with its version where known, for
+   * example `c11` or `c++17`. Omitted if the language is unknown.
+   */
+  language?: string;
 }
 ```
 

diff  --git a/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/types.py b/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/types.py
index a0e98a75dce087..75cfcd28f54612 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/types.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/types.py
@@ -783,6 +783,7 @@ class Thread:
 class CompileUnit:
     id: int
     compileUnitPath: str
+    language: Optional[str] = None
 
 
 @dataclass(frozen=True)

diff  --git a/lldb/test/API/tools/lldb-dap/stackTrace/Makefile b/lldb/test/API/tools/lldb-dap/stackTrace/Makefile
index 118f0aa59ef6f5..b4355d52aa7fb8 100644
--- a/lldb/test/API/tools/lldb-dap/stackTrace/Makefile
+++ b/lldb/test/API/tools/lldb-dap/stackTrace/Makefile
@@ -1,3 +1,4 @@
 C_SOURCES := main.c other.c
+CFLAGS_EXTRAS := -std=c11
 
 include Makefile.rules

diff  --git a/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py b/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py
index ba134ee41b7d4e..92e9e5ba254f9e 100644
--- a/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py
+++ b/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py
@@ -345,7 +345,9 @@ def test_stack_frame_compile_unit_id(self) -> None:
             if frame.compileUnitId == compile_unit_id:
                 self.assertEqual(frame.source.name, "main.c")
 
-        expected = CompileUnit(id=compile_unit_id, compileUnitPath=source)
+        expected = CompileUnit(
+            id=compile_unit_id, compileUnitPath=source, language="c11"
+        )
 
         response = session.send_request(CompileUnitsArgs(moduleId=module_id)).result()
         all_units = response.body.compileUnits

diff  --git a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
index 3397c6995bc61c..365bcba4a6ca35 100644
--- a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
@@ -12,13 +12,13 @@
 #include "RequestHandler.h"
 #include "lldb/API/SBCompileUnit.h"
 #include "lldb/API/SBFileSpec.h"
+#include "lldb/API/SBLanguageRuntime.h"
 #include "lldb/Host/PosixApi.h" // Adds PATH_MAX for windows
 
 using namespace lldb_dap;
 using namespace lldb_dap::protocol;
 
-static std::optional<CompileUnit>
-CreateCompileUnit(const lldb::SBCompileUnit &unit) {
+static std::optional<CompileUnit> CreateCompileUnit(lldb::SBCompileUnit unit) {
   const lldb::SBFileSpec file_spec = unit.GetFileSpec();
   if (!file_spec.IsValid())
     return std::nullopt;
@@ -30,6 +30,12 @@ CreateCompileUnit(const lldb::SBCompileUnit &unit) {
   CompileUnit result;
   result.id = unit.GetIDInModule();
   result.compileUnitPath = std::string(path_buffer.data(), path_size);
+  if (const lldb::LanguageType language = unit.GetLanguage();
+      language != lldb::eLanguageTypeUnknown) {
+    if (const char *name =
+            lldb::SBLanguageRuntime::GetNameForLanguageType(language))
+      result.language = name;
+  }
   return result;
 }
 

diff  --git a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp
index 335b18986f8b86..e765c5e647e778 100644
--- a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp
+++ b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp
@@ -1172,6 +1172,8 @@ json::Value toJSON(const ExceptionDetails &ED) {
 
 llvm::json::Value toJSON(const CompileUnit &CU) {
   json::Object result{{"id", CU.id}, {"compileUnitPath", CU.compileUnitPath}};
+  if (CU.language)
+    result.insert({"language", *CU.language});
   return result;
 }
 

diff  --git a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
index 0a4af8bd364a8d..8da03217400806 100644
--- a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
+++ b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
@@ -1049,6 +1049,10 @@ struct CompileUnit {
 
   /// Path of compile unit.
   String compileUnitPath;
+
+  /// The language of the compile unit, with its version where known, for
+  /// example `c11` or `c++17`.
+  std::optional<String> language;
 };
 llvm::json::Value toJSON(const CompileUnit &);
 

diff  --git a/lldb/unittests/DAP/ProtocolRequestsTest.cpp b/lldb/unittests/DAP/ProtocolRequestsTest.cpp
index f0a71d25f21ddf..1aaed363c43691 100644
--- a/lldb/unittests/DAP/ProtocolRequestsTest.cpp
+++ b/lldb/unittests/DAP/ProtocolRequestsTest.cpp
@@ -274,14 +274,15 @@ TEST(ProtocolRequestsTest, CompileUnitsArguments) {
 
 TEST(ProtocolRequestsTest, CompileUnitsResponseBody) {
   CompileUnitsResponseBody body;
-  body.compileUnits = {{1, "main.cpp"}, {2, "util.cpp"}};
+  body.compileUnits = {{1, "main.cpp", "c++"}, {2, "util.cpp", std::nullopt}};
 
   // Check required keys.
   Expected<json::Value> expected = parse(R"({
     "compileUnits": [
       {
         "id": 1,
-        "compileUnitPath": "main.cpp"
+        "compileUnitPath": "main.cpp",
+        "language": "c++"
       },
       {
         "id": 2,


        


More information about the lldb-commits mailing list