Skip to content

[lldb] Move SBLanguages.h out of API tree #111929

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lldb/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lldb/bindings/headers.swig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion lldb/bindings/interfaces.swig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lldb/cmake/modules/LLDBFramework.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
1 change: 0 additions & 1 deletion lldb/include/lldb/API/LLDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class LLDB_API SBWatchpoint;
class LLDB_API SBWatchpointOptions;
class LLDB_API SBUnixSignals;

typedef SourceLanguageName SBSourceLanguageName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure a typedef is enough here. It ends up being little more than syntactic sugar, the final symbol will still contain SourceLanguageName instead of SBSourceLanguageName. To verify this, you can perform a build with this patch and search for SBExpressionOptions::SetLanguage and make sure it still retains the SBSourceLanguageName symbol.


typedef bool (*SBBreakpointHitCallback)(void *baton, lldb::SBProcess &process,
lldb::SBThread &thread,
lldb::SBBreakpointLocation &location);
Expand Down
1 change: 0 additions & 1 deletion lldb/include/lldb/API/SBExpressionOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define LLDB_API_SBEXPRESSIONOPTIONS_H

#include "lldb/API/SBDefines.h"
#include "lldb/API/SBLanguages.h"

#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <cstdint>
#include <type_traits>

#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
Expand Down
11 changes: 6 additions & 5 deletions lldb/include/lldb/lldb-private-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<uint16_t, uint32_t>> name_vers)
: name(name_vers ? name_vers->first : 0),
SourceLanguage(
std::optional<std::pair<lldb::SourceLanguageName, uint32_t>> 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<lldb::SourceLanguageName> name;
uint32_t version = 0;
};

Expand Down
10 changes: 5 additions & 5 deletions lldb/scripts/generate-sbapi-dwarf-enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
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.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_API_SBLANGUAGE_H
#define LLDB_API_SBLANGUAGE_H
#ifndef LLDB_SOURCELANGUAGENAMES_H
#define LLDB_SOURCELANGUAGENAMES_H

#include <cstdint>

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 = """\
Expand Down
20 changes: 10 additions & 10 deletions lldb/source/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/API/SBFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 11 additions & 8 deletions lldb/source/Target/Language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,27 +535,30 @@ 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<llvm::dwarf::SourceLanguage>(language_type));
if (!lname)
return;
name = lname->first;
name.emplace(static_cast<SourceLanguageName>(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<llvm::dwarf::SourceLanguageName>(*name), version);
if (!lang)
return lldb::eLanguageTypeUnknown;
return static_cast<lldb::LanguageType>(*lang);
}

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 ? *name : 0));
}
bool SourceLanguage::IsC() const { return name == llvm::dwarf::DW_LNAME_C; }

Expand Down
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
2 changes: 1 addition & 1 deletion utils/bazel/llvm-project-overlay/lldb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
Expand Down
Loading