Skip to content

Commit 5744d94

Browse files
committed
[lldb] Move SBLanguages.h out of API tree
This patch moves `SBLanguages.h` out of the API tree. This file gets generated at build time using DWARF table-gen file and contains an enumeration of the DWARF supported source language names and there respective code/identifier. Since this is an enum, this shouldn't be part of the API tree but rather it should be included in the `lldb-enumeration` header. Also, that enum was used in internal methods in `lldb_private` by down-casting the enum value type to an `uint16_t`. This patch changes that by making those internal methods use the enum type. This should address the feedbacks from #111907. Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 774c953 commit 5744d94

File tree

17 files changed

+54
-45
lines changed

17 files changed

+54
-45
lines changed

lldb/bindings/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ file(GLOB_RECURSE SWIG_SOURCES *.swig)
33
file(GLOB SWIG_HEADERS
44
${LLDB_SOURCE_DIR}/include/lldb/API/*.h
55
${LLDB_SOURCE_DIR}/include/lldb/*.h
6-
${LLDB_BINARY_DIR}/include/lldb/API/SBLanguages.h
6+
${LLDB_BINARY_DIR}/include/lldb/SourceLanguageNames.h
77
)
88
file(GLOB SWIG_PRIVATE_HEADERS
99
${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h

lldb/bindings/headers.swig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "lldb/API/SBHostOS.h"
4040
#include "lldb/API/SBInstruction.h"
4141
#include "lldb/API/SBInstructionList.h"
42-
#include "lldb/API/SBLanguages.h"
4342
#include "lldb/API/SBLanguageRuntime.h"
4443
#include "lldb/API/SBLaunchInfo.h"
4544
#include "lldb/API/SBLineEntry.h"

lldb/bindings/interfaces.swig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
%include "lldb/API/SBHostOS.h"
121121
%include "lldb/API/SBInstruction.h"
122122
%include "lldb/API/SBInstructionList.h"
123-
%include "lldb/API/SBLanguages.h"
124123
%include "lldb/API/SBLanguageRuntime.h"
125124
%include "lldb/API/SBLaunchInfo.h"
126125
%include "lldb/API/SBLineEntry.h"

lldb/cmake/modules/LLDBFramework.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ endif()
7171
# At configuration time, collect headers for the framework bundle and copy them
7272
# into a staging directory. Later we can copy over the entire folder.
7373
file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h)
74-
set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/API/SBLanguages.h)
74+
set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/SourceLanguageNames.h)
7575
file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h)
7676
file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h)
7777
list(REMOVE_ITEM root_public_headers ${root_private_headers})

lldb/include/lldb/API/LLDB.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "lldb/API/SBInstruction.h"
4343
#include "lldb/API/SBInstructionList.h"
4444
#include "lldb/API/SBLanguageRuntime.h"
45-
#include "lldb/API/SBLanguages.h"
4645
#include "lldb/API/SBLaunchInfo.h"
4746
#include "lldb/API/SBLineEntry.h"
4847
#include "lldb/API/SBListener.h"

lldb/include/lldb/API/SBDefines.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class LLDB_API SBWatchpoint;
136136
class LLDB_API SBWatchpointOptions;
137137
class LLDB_API SBUnixSignals;
138138

139+
typedef SourceLanguageName SBSourceLanguageName;
140+
139141
typedef bool (*SBBreakpointHitCallback)(void *baton, lldb::SBProcess &process,
140142
lldb::SBThread &thread,
141143
lldb::SBBreakpointLocation &location);

lldb/include/lldb/API/SBExpressionOptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define LLDB_API_SBEXPRESSIONOPTIONS_H
1111

1212
#include "lldb/API/SBDefines.h"
13-
#include "lldb/API/SBLanguages.h"
1413

1514
#include <vector>
1615

lldb/include/lldb/Target/Target.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class EvaluateExpressionOptions {
324324
/// Set the language using a pair of language code and version as
325325
/// defined by the DWARF 6 specification.
326326
/// WARNING: These codes may change until DWARF 6 is finalized.
327-
void SetLanguage(uint16_t name, uint32_t version) {
327+
void SetLanguage(lldb::SourceLanguageName name, uint32_t version) {
328328
m_language = SourceLanguage(name, version);
329329
}
330330

lldb/include/lldb/lldb-enumerations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <cstdint>
1313
#include <type_traits>
1414

15+
#include "lldb/SourceLanguageNames.h"
16+
1517
#ifndef SWIG
1618
// Macro to enable bitmask operations on an enum. Without this, Enum | Enum
1719
// gets promoted to an int, so you have to say Enum a = Enum(eFoo | eBar). If

lldb/include/lldb/lldb-private-types.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,19 @@ struct RegisterSet {
103103
struct SourceLanguage {
104104
SourceLanguage() = default;
105105
SourceLanguage(lldb::LanguageType language_type);
106-
SourceLanguage(uint16_t name, uint32_t version)
106+
SourceLanguage(lldb::SourceLanguageName name, uint32_t version)
107107
: name(name), version(version) {}
108-
SourceLanguage(std::optional<std::pair<uint16_t, uint32_t>> name_vers)
109-
: name(name_vers ? name_vers->first : 0),
108+
SourceLanguage(
109+
std::optional<std::pair<lldb::SourceLanguageName, uint32_t>> name_vers)
110+
: name(name_vers ? std::optional(name_vers->first) : std::nullopt),
110111
version(name_vers ? name_vers->second : 0) {}
111-
operator bool() const { return name > 0; }
112+
operator bool() const { return name.has_value(); }
112113
lldb::LanguageType AsLanguageType() const;
113114
llvm::StringRef GetDescription() const;
114115
bool IsC() const;
115116
bool IsObjC() const;
116117
bool IsCPlusPlus() const;
117-
uint16_t name = 0;
118+
std::optional<lldb::SourceLanguageName> name;
118119
uint32_t version = 0;
119120
};
120121

lldb/scripts/generate-sbapi-dwarf-enum.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
import os
66

77
HEADER = """\
8-
//===-- SBLanguages.h -----------------------------------------*- C++ -*-===//
8+
//===-- SourceLanguageNames.h -----------------------------------*- C++ -*-===//
99
//
1010
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
1111
// See https://llvm.org/LICENSE.txt for license information.
1212
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1313
//
1414
//===----------------------------------------------------------------------===//
1515
16-
#ifndef LLDB_API_SBLANGUAGE_H
17-
#define LLDB_API_SBLANGUAGE_H
16+
#ifndef LLDB_SOURCELANGUAGENAMES_H
17+
#define LLDB_SOURCELANGUAGENAMES_H
1818
1919
#include <cstdint>
2020
2121
namespace lldb {
22-
/// Used by \\ref SBExpressionOptions.
22+
/// This file is generated by `lldb/scripts/generate-sbapi-dwarf-enum.py`.
2323
/// These enumerations use the same language enumerations as the DWARF
2424
/// specification for ease of use and consistency.
25-
enum SBSourceLanguageName : uint16_t {
25+
enum SourceLanguageName {
2626
"""
2727

2828
FOOTER = """\

lldb/source/API/CMakeLists.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ if(LLDB_ENABLE_LUA)
2020
set(lldb_lua_wrapper ${lua_bindings_dir}/LLDBWrapLua.cpp)
2121
endif()
2222

23-
# Generate SBLanguages.h from Dwarf.def.
24-
set(sb_languages_file
25-
${CMAKE_CURRENT_BINARY_DIR}/../../include/lldb/API/SBLanguages.h)
26-
set(sb_languages_generator
23+
# Generate SourceLanguageNames.h from Dwarf.def.
24+
set(source_language_names_file
25+
${CMAKE_CURRENT_BINARY_DIR}/../../include/lldb/SourceLanguageNames.h)
26+
set(source_language_names_generator
2727
${LLDB_SOURCE_DIR}/scripts/generate-sbapi-dwarf-enum.py)
2828
add_custom_command(
29-
COMMENT "Generating SBLanguages.h from Dwarf.def"
29+
COMMENT "Generating SourceLanguageNames.h from Dwarf.def"
3030
COMMAND "${Python3_EXECUTABLE}"
31-
${sb_languages_generator}
31+
${source_language_names_generator}
3232
${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def
33-
-o ${sb_languages_file}
34-
OUTPUT ${sb_languages_file}
33+
-o ${source_language_names_file}
34+
OUTPUT ${source_language_names_file}
3535
DEPENDS ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def
36-
${sb_languages_generator}
36+
${source_language_names_generator}
3737
WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR}
3838
)
3939
add_custom_target(lldb-sbapi-dwarf-enums
40-
DEPENDS ${sb_languages_file})
40+
DEPENDS ${source_language_names_file})
4141
set_target_properties(lldb-sbapi-dwarf-enums PROPERTIES FOLDER "LLDB/Tablegenning")
4242

4343
add_lldb_library(liblldb SHARED ${option_framework}

lldb/source/API/SBFrame.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ SBValue SBFrame::EvaluateExpression(const char *expr) {
10271027
SourceLanguage language = target->GetLanguage();
10281028
if (!language)
10291029
language = frame->GetLanguage();
1030-
options.SetLanguage((SBSourceLanguageName)language.name, language.version);
1030+
options.SetLanguage(*language.name, language.version);
10311031
return EvaluateExpression(expr, options);
10321032
} else {
10331033
Status error;
@@ -1059,7 +1059,7 @@ SBFrame::EvaluateExpression(const char *expr,
10591059
language = target->GetLanguage();
10601060
if (!language && frame)
10611061
language = frame->GetLanguage();
1062-
options.SetLanguage((SBSourceLanguageName)language.name, language.version);
1062+
options.SetLanguage(*language.name, language.version);
10631063
return EvaluateExpression(expr, options);
10641064
}
10651065

@@ -1082,7 +1082,7 @@ SBValue SBFrame::EvaluateExpression(const char *expr,
10821082
language = target->GetLanguage();
10831083
if (!language && frame)
10841084
language = frame->GetLanguage();
1085-
options.SetLanguage((SBSourceLanguageName)language.name, language.version);
1085+
options.SetLanguage(*language.name, language.version);
10861086
return EvaluateExpression(expr, options);
10871087
}
10881088

lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,19 @@ ClangUserExpression::ClangUserExpression(
7171
m_type_system_helper(*m_target_wp.lock(), options.GetExecutionPolicy() ==
7272
eExecutionPolicyTopLevel),
7373
m_result_delegate(exe_scope.CalculateTarget()), m_ctx_obj(ctx_obj) {
74-
switch (m_language.name) {
75-
case llvm::dwarf::DW_LNAME_C_plus_plus:
74+
if (!m_language.name) {
75+
m_allow_cxx = true;
76+
m_allow_objc = true;
77+
return;
78+
}
79+
switch (*m_language.name) {
80+
case lldb::SourceLanguageName::eLanguageNameC_plus_plus:
7681
m_allow_cxx = true;
7782
break;
78-
case llvm::dwarf::DW_LNAME_ObjC:
83+
case lldb::SourceLanguageName::eLanguageNameObjC:
7984
m_allow_objc = true;
8085
break;
81-
case llvm::dwarf::DW_LNAME_ObjC_plus_plus:
86+
case lldb::SourceLanguageName::eLanguageNameObjC_plus_plus:
8287
default:
8388
m_allow_cxx = true;
8489
m_allow_objc = true;

lldb/source/Target/Language.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -535,27 +535,30 @@ Language::Language() = default;
535535
Language::~Language() = default;
536536

537537
SourceLanguage::SourceLanguage(lldb::LanguageType language_type) {
538-
auto lname =
539-
llvm::dwarf::toDW_LNAME((llvm::dwarf::SourceLanguage)language_type);
538+
auto lname = llvm::dwarf::toDW_LNAME(
539+
static_cast<llvm::dwarf::SourceLanguage>(language_type));
540540
if (!lname)
541541
return;
542-
name = lname->first;
542+
name.emplace(static_cast<SourceLanguageName>(lname->first));
543543
version = lname->second;
544544
}
545545

546546
lldb::LanguageType SourceLanguage::AsLanguageType() const {
547-
if (auto lang = llvm::dwarf::toDW_LANG((llvm::dwarf::SourceLanguageName)name,
548-
version))
549-
return (lldb::LanguageType)*lang;
550-
return lldb::eLanguageTypeUnknown;
547+
if (!name)
548+
return lldb::eLanguageTypeUnknown;
549+
auto lang = llvm::dwarf::toDW_LANG(
550+
static_cast<llvm::dwarf::SourceLanguageName>(*name), version);
551+
if (!lang)
552+
return lldb::eLanguageTypeUnknown;
553+
return static_cast<lldb::LanguageType>(*lang);
551554
}
552555

553556
llvm::StringRef SourceLanguage::GetDescription() const {
554557
LanguageType type = AsLanguageType();
555558
if (type)
556559
return Language::GetNameForLanguageType(type);
557560
return llvm::dwarf::LanguageDescription(
558-
(llvm::dwarf::SourceLanguageName)name);
561+
static_cast<llvm::dwarf::SourceLanguageName>(name ? *name : 0));
559562
}
560563
bool SourceLanguage::IsC() const { return name == llvm::dwarf::DW_LNAME_C; }
561564

llvm/utils/gn/secondary/lldb/include/lldb/API/BUILD.gn renamed to llvm/utils/gn/secondary/lldb/include/lldb/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
action("SBLanguages") {
1+
action("SourceLanguageNames") {
22
script = "//lldb/scripts/generate-sbapi-dwarf-enum.py"
3-
outputs = [ "$target_gen_dir/SBLanguages.h" ]
3+
outputs = [ "$target_gen_dir/SourceLanguageNames.h" ]
44
sources = [ "//llvm/include/llvm/BinaryFormat/Dwarf.def" ]
55
args = [
66
rebase_path(sources[0], root_build_dir),

utils/bazel/llvm-project-overlay/lldb/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ py_binary(
195195
genrule(
196196
name = "lldb-sbapi-dwarf-enums",
197197
srcs = ["//llvm:include/llvm/BinaryFormat/Dwarf.def"],
198-
outs = ["include/lldb/API/SBLanguages.h"],
198+
outs = ["include/lldb/SourceLanguageNames.h"],
199199
cmd = "$(location :generate-sbapi-dwarf-enum) $(location //llvm:include/llvm/BinaryFormat/Dwarf.def) --output $@",
200200
tools = [":generate-sbapi-dwarf-enum"],
201201
)

0 commit comments

Comments
 (0)