diff --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/CMakeLists.txt index bec694e43bd7b..befc5c9e9afc1 100644 --- a/lldb/bindings/CMakeLists.txt +++ b/lldb/bindings/CMakeLists.txt @@ -3,7 +3,7 @@ file(GLOB_RECURSE SWIG_SOURCES *.swig) file(GLOB SWIG_HEADERS ${LLDB_SOURCE_DIR}/include/lldb/API/*.h ${LLDB_SOURCE_DIR}/include/lldb/*.h - ${LLDB_BINARY_DIR}/include/lldb/API/SBLanguages.h + ${LLDB_BINARY_DIR}/include/lldb/SourceLanguageNames.h ) file(GLOB SWIG_PRIVATE_HEADERS ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig index c0dde905f986b..2420ea4aab843 100644 --- a/lldb/bindings/headers.swig +++ b/lldb/bindings/headers.swig @@ -39,7 +39,6 @@ #include "lldb/API/SBHostOS.h" #include "lldb/API/SBInstruction.h" #include "lldb/API/SBInstructionList.h" -#include "lldb/API/SBLanguages.h" #include "lldb/API/SBLanguageRuntime.h" #include "lldb/API/SBLaunchInfo.h" #include "lldb/API/SBLineEntry.h" diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig index 8a6fed95f0b72..e48e875367f7c 100644 --- a/lldb/bindings/interfaces.swig +++ b/lldb/bindings/interfaces.swig @@ -120,7 +120,6 @@ %include "lldb/API/SBHostOS.h" %include "lldb/API/SBInstruction.h" %include "lldb/API/SBInstructionList.h" -%include "lldb/API/SBLanguages.h" %include "lldb/API/SBLanguageRuntime.h" %include "lldb/API/SBLaunchInfo.h" %include "lldb/API/SBLineEntry.h" diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake index 471aeaaad3c0d..0daff8b3e07e2 100644 --- a/lldb/cmake/modules/LLDBFramework.cmake +++ b/lldb/cmake/modules/LLDBFramework.cmake @@ -71,7 +71,7 @@ endif() # At configuration time, collect headers for the framework bundle and copy them # into a staging directory. Later we can copy over the entire folder. file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) -set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/API/SBLanguages.h) +set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/SourceLanguageNames.h) file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h) list(REMOVE_ITEM root_public_headers ${root_private_headers}) diff --git a/lldb/include/lldb/API/LLDB.h b/lldb/include/lldb/API/LLDB.h index 40368e036e0e4..8884b21a40120 100644 --- a/lldb/include/lldb/API/LLDB.h +++ b/lldb/include/lldb/API/LLDB.h @@ -42,7 +42,6 @@ #include "lldb/API/SBInstruction.h" #include "lldb/API/SBInstructionList.h" #include "lldb/API/SBLanguageRuntime.h" -#include "lldb/API/SBLanguages.h" #include "lldb/API/SBLaunchInfo.h" #include "lldb/API/SBLineEntry.h" #include "lldb/API/SBListener.h" diff --git a/lldb/include/lldb/API/SBDefines.h b/lldb/include/lldb/API/SBDefines.h index 159a9ba799b18..3951fc17c4005 100644 --- a/lldb/include/lldb/API/SBDefines.h +++ b/lldb/include/lldb/API/SBDefines.h @@ -136,6 +136,8 @@ class LLDB_API SBWatchpoint; class LLDB_API SBWatchpointOptions; class LLDB_API SBUnixSignals; +typedef SourceLanguageName SBSourceLanguageName; + typedef bool (*SBBreakpointHitCallback)(void *baton, lldb::SBProcess &process, lldb::SBThread &thread, lldb::SBBreakpointLocation &location); diff --git a/lldb/include/lldb/API/SBExpressionOptions.h b/lldb/include/lldb/API/SBExpressionOptions.h index a9e929a4c0bd9..141dad8d9d9ab 100644 --- a/lldb/include/lldb/API/SBExpressionOptions.h +++ b/lldb/include/lldb/API/SBExpressionOptions.h @@ -10,7 +10,6 @@ #define LLDB_API_SBEXPRESSIONOPTIONS_H #include "lldb/API/SBDefines.h" -#include "lldb/API/SBLanguages.h" #include diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index e4848f19e64d6..abe3f35630ce7 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -324,7 +324,7 @@ class EvaluateExpressionOptions { /// Set the language using a pair of language code and version as /// defined by the DWARF 6 specification. /// WARNING: These codes may change until DWARF 6 is finalized. - void SetLanguage(uint16_t name, uint32_t version) { + void SetLanguage(lldb::SourceLanguageName name, uint32_t version) { m_language = SourceLanguage(name, version); } diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h index 938f6e3abe8f2..c2845491e16d8 100644 --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -12,6 +12,8 @@ #include #include +#include "lldb/SourceLanguageNames.h" + #ifndef SWIG // Macro to enable bitmask operations on an enum. Without this, Enum | Enum // gets promoted to an int, so you have to say Enum a = Enum(eFoo | eBar). If diff --git a/lldb/include/lldb/lldb-private-types.h b/lldb/include/lldb/lldb-private-types.h index b82a2b8aa0574..da7e5c430a7dd 100644 --- a/lldb/include/lldb/lldb-private-types.h +++ b/lldb/include/lldb/lldb-private-types.h @@ -103,18 +103,19 @@ struct RegisterSet { struct SourceLanguage { SourceLanguage() = default; SourceLanguage(lldb::LanguageType language_type); - SourceLanguage(uint16_t name, uint32_t version) + SourceLanguage(lldb::SourceLanguageName name, uint32_t version) : name(name), version(version) {} - SourceLanguage(std::optional> name_vers) - : name(name_vers ? name_vers->first : 0), + SourceLanguage( + std::optional> name_vers) + : name(name_vers ? std::optional(name_vers->first) : std::nullopt), version(name_vers ? name_vers->second : 0) {} - operator bool() const { return name > 0; } + operator bool() const { return name.has_value(); } lldb::LanguageType AsLanguageType() const; llvm::StringRef GetDescription() const; bool IsC() const; bool IsObjC() const; bool IsCPlusPlus() const; - uint16_t name = 0; + std::optional name; uint32_t version = 0; }; diff --git a/lldb/scripts/generate-sbapi-dwarf-enum.py b/lldb/scripts/generate-sbapi-dwarf-enum.py index 689c7f81bfda0..655717230e6b6 100755 --- a/lldb/scripts/generate-sbapi-dwarf-enum.py +++ b/lldb/scripts/generate-sbapi-dwarf-enum.py @@ -5,7 +5,7 @@ import os HEADER = """\ -//===-- SBLanguages.h -----------------------------------------*- C++ -*-===// +//===-- SourceLanguageNames.h -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -13,16 +13,16 @@ // //===----------------------------------------------------------------------===// -#ifndef LLDB_API_SBLANGUAGE_H -#define LLDB_API_SBLANGUAGE_H +#ifndef LLDB_SOURCELANGUAGENAMES_H +#define LLDB_SOURCELANGUAGENAMES_H #include namespace lldb { -/// Used by \\ref SBExpressionOptions. +/// This file is generated by `lldb/scripts/generate-sbapi-dwarf-enum.py`. /// These enumerations use the same language enumerations as the DWARF /// specification for ease of use and consistency. -enum SBSourceLanguageName : uint16_t { +enum SourceLanguageName { """ FOOTER = """\ diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index a32bc58507d8e..3105e06175979 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -20,24 +20,24 @@ if(LLDB_ENABLE_LUA) set(lldb_lua_wrapper ${lua_bindings_dir}/LLDBWrapLua.cpp) endif() -# Generate SBLanguages.h from Dwarf.def. -set(sb_languages_file - ${CMAKE_CURRENT_BINARY_DIR}/../../include/lldb/API/SBLanguages.h) -set(sb_languages_generator +# Generate SourceLanguageNames.h from Dwarf.def. +set(source_language_names_file + ${CMAKE_CURRENT_BINARY_DIR}/../../include/lldb/SourceLanguageNames.h) +set(source_language_names_generator ${LLDB_SOURCE_DIR}/scripts/generate-sbapi-dwarf-enum.py) add_custom_command( - COMMENT "Generating SBLanguages.h from Dwarf.def" + COMMENT "Generating SourceLanguageNames.h from Dwarf.def" COMMAND "${Python3_EXECUTABLE}" - ${sb_languages_generator} + ${source_language_names_generator} ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def - -o ${sb_languages_file} - OUTPUT ${sb_languages_file} + -o ${source_language_names_file} + OUTPUT ${source_language_names_file} DEPENDS ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def - ${sb_languages_generator} + ${source_language_names_generator} WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR} ) add_custom_target(lldb-sbapi-dwarf-enums - DEPENDS ${sb_languages_file}) + DEPENDS ${source_language_names_file}) set_target_properties(lldb-sbapi-dwarf-enums PROPERTIES FOLDER "LLDB/Tablegenning") add_lldb_library(liblldb SHARED ${option_framework} diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp index 30c44b974988d..a951fe43212cf 100644 --- a/lldb/source/API/SBFrame.cpp +++ b/lldb/source/API/SBFrame.cpp @@ -1027,7 +1027,7 @@ SBValue SBFrame::EvaluateExpression(const char *expr) { SourceLanguage language = target->GetLanguage(); if (!language) language = frame->GetLanguage(); - options.SetLanguage((SBSourceLanguageName)language.name, language.version); + options.SetLanguage(*language.name, language.version); return EvaluateExpression(expr, options); } else { Status error; @@ -1059,7 +1059,7 @@ SBFrame::EvaluateExpression(const char *expr, language = target->GetLanguage(); if (!language && frame) language = frame->GetLanguage(); - options.SetLanguage((SBSourceLanguageName)language.name, language.version); + options.SetLanguage(*language.name, language.version); return EvaluateExpression(expr, options); } @@ -1082,7 +1082,7 @@ SBValue SBFrame::EvaluateExpression(const char *expr, language = target->GetLanguage(); if (!language && frame) language = frame->GetLanguage(); - options.SetLanguage((SBSourceLanguageName)language.name, language.version); + options.SetLanguage(*language.name, language.version); return EvaluateExpression(expr, options); } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index 52d52826c946d..e12a100bbf7d6 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -71,14 +71,19 @@ ClangUserExpression::ClangUserExpression( m_type_system_helper(*m_target_wp.lock(), options.GetExecutionPolicy() == eExecutionPolicyTopLevel), m_result_delegate(exe_scope.CalculateTarget()), m_ctx_obj(ctx_obj) { - switch (m_language.name) { - case llvm::dwarf::DW_LNAME_C_plus_plus: + if (!m_language.name) { + m_allow_cxx = true; + m_allow_objc = true; + return; + } + switch (*m_language.name) { + case lldb::SourceLanguageName::eLanguageNameC_plus_plus: m_allow_cxx = true; break; - case llvm::dwarf::DW_LNAME_ObjC: + case lldb::SourceLanguageName::eLanguageNameObjC: m_allow_objc = true; break; - case llvm::dwarf::DW_LNAME_ObjC_plus_plus: + case lldb::SourceLanguageName::eLanguageNameObjC_plus_plus: default: m_allow_cxx = true; m_allow_objc = true; diff --git a/lldb/source/Target/Language.cpp b/lldb/source/Target/Language.cpp index d0bffe441f639..9c79f02f334f3 100644 --- a/lldb/source/Target/Language.cpp +++ b/lldb/source/Target/Language.cpp @@ -535,19 +535,22 @@ Language::Language() = default; Language::~Language() = default; SourceLanguage::SourceLanguage(lldb::LanguageType language_type) { - auto lname = - llvm::dwarf::toDW_LNAME((llvm::dwarf::SourceLanguage)language_type); + auto lname = llvm::dwarf::toDW_LNAME( + static_cast(language_type)); if (!lname) return; - name = lname->first; + name.emplace(static_cast(lname->first)); version = lname->second; } lldb::LanguageType SourceLanguage::AsLanguageType() const { - if (auto lang = llvm::dwarf::toDW_LANG((llvm::dwarf::SourceLanguageName)name, - version)) - return (lldb::LanguageType)*lang; - return lldb::eLanguageTypeUnknown; + if (!name) + return lldb::eLanguageTypeUnknown; + auto lang = llvm::dwarf::toDW_LANG( + static_cast(*name), version); + if (!lang) + return lldb::eLanguageTypeUnknown; + return static_cast(*lang); } llvm::StringRef SourceLanguage::GetDescription() const { @@ -555,7 +558,7 @@ llvm::StringRef SourceLanguage::GetDescription() const { if (type) return Language::GetNameForLanguageType(type); return llvm::dwarf::LanguageDescription( - (llvm::dwarf::SourceLanguageName)name); + static_cast(name ? *name : 0)); } bool SourceLanguage::IsC() const { return name == llvm::dwarf::DW_LNAME_C; } diff --git a/llvm/utils/gn/secondary/lldb/include/lldb/API/BUILD.gn b/llvm/utils/gn/secondary/lldb/include/lldb/BUILD.gn similarity index 72% rename from llvm/utils/gn/secondary/lldb/include/lldb/API/BUILD.gn rename to llvm/utils/gn/secondary/lldb/include/lldb/BUILD.gn index 2fe295d136569..d8df32761f89e 100644 --- a/llvm/utils/gn/secondary/lldb/include/lldb/API/BUILD.gn +++ b/llvm/utils/gn/secondary/lldb/include/lldb/BUILD.gn @@ -1,6 +1,6 @@ -action("SBLanguages") { +action("SourceLanguageNames") { script = "//lldb/scripts/generate-sbapi-dwarf-enum.py" - outputs = [ "$target_gen_dir/SBLanguages.h" ] + outputs = [ "$target_gen_dir/SourceLanguageNames.h" ] sources = [ "//llvm/include/llvm/BinaryFormat/Dwarf.def" ] args = [ rebase_path(sources[0], root_build_dir), diff --git a/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel b/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel index 3ed4f552290da..e4e12d4440603 100644 --- a/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel @@ -195,7 +195,7 @@ py_binary( genrule( name = "lldb-sbapi-dwarf-enums", srcs = ["//llvm:include/llvm/BinaryFormat/Dwarf.def"], - outs = ["include/lldb/API/SBLanguages.h"], + outs = ["include/lldb/SourceLanguageNames.h"], cmd = "$(location :generate-sbapi-dwarf-enum) $(location //llvm:include/llvm/BinaryFormat/Dwarf.def) --output $@", tools = [":generate-sbapi-dwarf-enum"], )