Skip to content

Commit 11d1236

Browse files
Merge pull request #8658 from adrian-prantl/126783312-next
cherry-pick to next
2 parents ead278f + 63512c0 commit 11d1236

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+798
-175
lines changed

lldb/include/lldb/API/SBExpressionOptions.h

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

1212
#include "lldb/API/SBDefines.h"
13+
#include "lldb/API/SBLanguages.h"
1314

1415
#include <vector>
1516

@@ -67,6 +68,10 @@ class LLDB_API SBExpressionOptions {
6768
void SetTrapExceptions(bool trap_exceptions = true);
6869

6970
void SetLanguage(lldb::LanguageType language);
71+
/// Set the language using a pair of language code and version as
72+
/// defined by the DWARF 6 specification.
73+
/// WARNING: These codes may change until DWARF 6 is finalized.
74+
void SetLanguage(SBSourceLanguageName name, uint32_t version);
7075

7176
#ifndef SWIG
7277
void SetCancelCallback(lldb::ExpressionCancelCallback callback, void *baton);

lldb/include/lldb/Expression/Expression.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ class Expression {
4747
/// expression. Text() should contain the definition of this function.
4848
virtual const char *FunctionName() = 0;
4949

50-
/// Return the language that should be used when parsing. To use the
51-
/// default, return eLanguageTypeUnknown.
52-
virtual lldb::LanguageType Language() const {
53-
return lldb::eLanguageTypeUnknown;
54-
}
50+
/// Return the language that should be used when parsing.
51+
virtual SourceLanguage Language() const { return {}; }
5552

5653
/// Return the Materializer that the parser should use when registering
5754
/// external values.

lldb/include/lldb/Expression/LLVMUserExpression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class LLVMUserExpression : public UserExpression {
5252
};
5353

5454
LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
55-
llvm::StringRef prefix, lldb::LanguageType language,
55+
llvm::StringRef prefix, SourceLanguage language,
5656
ResultType desired_type,
5757
const EvaluateExpressionOptions &options);
5858
~LLVMUserExpression() override;

lldb/include/lldb/Expression/UserExpression.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class UserExpression : public Expression {
5656
/// If not eResultTypeAny, the type to use for the expression
5757
/// result.
5858
UserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
59-
llvm::StringRef prefix, lldb::LanguageType language,
59+
llvm::StringRef prefix, SourceLanguage language,
6060
ResultType desired_type,
6161
const EvaluateExpressionOptions &options);
6262

@@ -201,7 +201,7 @@ class UserExpression : public Expression {
201201
virtual bool IsParseCacheable() { return true; }
202202
/// Return the language that should be used when parsing. To use the
203203
/// default, return eLanguageTypeUnknown.
204-
lldb::LanguageType Language() const override { return m_language; }
204+
SourceLanguage Language() const override { return m_language; }
205205

206206
/// Return the desired result type of the function, or eResultTypeAny if
207207
/// indifferent.
@@ -314,19 +314,22 @@ class UserExpression : public Expression {
314314
lldb::ProcessSP &process_sp,
315315
lldb::StackFrameSP &frame_sp);
316316

317-
Address m_address; ///< The address the process is stopped in.
318-
std::string m_expr_text; ///< The text of the expression, as typed by the user
319-
std::string m_expr_prefix; ///< The text of the translation-level definitions,
320-
///as provided by the user
321-
std::string m_fixed_text; ///< The text of the expression with fix-its applied
322-
///- this won't be set if the fixed text doesn't
323-
///parse.
324-
lldb::LanguageType m_language; ///< The language to use when parsing
325-
///(eLanguageTypeUnknown means use defaults)
326-
ResultType m_desired_type; ///< The type to coerce the expression's result to.
327-
///If eResultTypeAny, inferred from the expression.
328-
EvaluateExpressionOptions
329-
m_options; ///< Additional options provided by the user.
317+
/// The address the process is stopped in.
318+
Address m_address;
319+
/// The text of the expression, as typed by the user.
320+
std::string m_expr_text;
321+
/// The text of the translation-level definitions, as provided by the user.
322+
std::string m_expr_prefix;
323+
/// The text of the expression with fix-its applied this won't be set if the
324+
/// fixed text doesn't parse.
325+
std::string m_fixed_text;
326+
/// The language to use when parsing (unknown means use defaults).
327+
SourceLanguage m_language;
328+
/// The type to coerce the expression's result to. If eResultTypeAny, inferred
329+
/// from the expression.
330+
ResultType m_desired_type;
331+
/// Additional options provided by the user.
332+
EvaluateExpressionOptions m_options;
330333
};
331334

332335
} // namespace lldb_private

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,10 @@ class TypeSystem : public PluginInterface,
517517
return IsPointerOrReferenceType(type, nullptr);
518518
}
519519

520-
virtual UserExpression *
521-
GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix,
522-
lldb::LanguageType language,
523-
Expression::ResultType desired_type,
524-
const EvaluateExpressionOptions &options,
525-
ValueObject *ctx_obj) {
520+
virtual UserExpression *GetUserExpression(
521+
llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language,
522+
Expression::ResultType desired_type,
523+
const EvaluateExpressionOptions &options, ValueObject *ctx_obj) {
526524
return nullptr;
527525
}
528526

lldb/include/lldb/Target/StackFrame.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
//===-- StackFrame.h --------------------------------------------*- C++ -*-===//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -446,13 +447,12 @@ class StackFrame : public ExecutionContextScope,
446447
/// Query this frame to determine what the default language should be when
447448
/// parsing expressions given the execution context.
448449
///
449-
/// \return
450-
/// The language of the frame if known, else lldb::eLanguageTypeUnknown.
451-
lldb::LanguageType GetLanguage();
450+
/// \return The language of the frame if known.
451+
SourceLanguage GetLanguage();
452452

453-
// similar to GetLanguage(), but is allowed to take a potentially incorrect
454-
// guess if exact information is not available
455-
lldb::LanguageType GuessLanguage();
453+
/// Similar to GetLanguage(), but is allowed to take a potentially incorrect
454+
/// guess if exact information is not available.
455+
SourceLanguage GuessLanguage();
456456

457457
/// Attempt to econstruct the ValueObject for a given raw address touched by
458458
/// the current instruction. The ExpressionPath should indicate how to get

lldb/include/lldb/Target/Target.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class TargetProperties : public Properties {
243243

244244
bool GetBreakpointsConsultPlatformAvoidList();
245245

246-
lldb::LanguageType GetLanguage() const;
246+
SourceLanguage GetLanguage() const;
247247

248248
llvm::StringRef GetExpressionPrefixContents();
249249

@@ -359,9 +359,18 @@ class EvaluateExpressionOptions {
359359
m_execution_policy = policy;
360360
}
361361

362-
lldb::LanguageType GetLanguage() const { return m_language; }
362+
SourceLanguage GetLanguage() const { return m_language; }
363363

364-
void SetLanguage(lldb::LanguageType language) { m_language = language; }
364+
void SetLanguage(lldb::LanguageType language_type) {
365+
m_language = SourceLanguage(language_type);
366+
}
367+
368+
/// Set the language using a pair of language code and version as
369+
/// defined by the DWARF 6 specification.
370+
/// WARNING: These codes may change until DWARF 6 is finalized.
371+
void SetLanguage(uint16_t name, uint32_t version) {
372+
m_language = SourceLanguage(name, version);
373+
}
365374

366375
bool DoesCoerceToId() const { return m_coerce_to_id; }
367376

@@ -524,7 +533,7 @@ class EvaluateExpressionOptions {
524533

525534
private:
526535
ExecutionPolicy m_execution_policy = default_execution_policy;
527-
lldb::LanguageType m_language = lldb::eLanguageTypeUnknown;
536+
SourceLanguage m_language;
528537
std::string m_prefix;
529538
bool m_coerce_to_id = false;
530539
bool m_unwind_on_error = true;
@@ -1255,7 +1264,7 @@ class Target : public std::enable_shared_from_this<Target>,
12551264

12561265
UserExpression *
12571266
GetUserExpressionForLanguage(llvm::StringRef expr, llvm::StringRef prefix,
1258-
lldb::LanguageType language,
1267+
SourceLanguage language,
12591268
Expression::ResultType desired_type,
12601269
const EvaluateExpressionOptions &options,
12611270
ValueObject *ctx_obj, Status &error);

lldb/include/lldb/Target/ThreadPlanCallFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class ThreadPlanCallFunction : public ThreadPlan {
9797

9898
virtual void SetStopOthers(bool new_value) override;
9999

100-
lldb::LanguageType GetExpressionLanguage() { return m_expression_language; }
100+
SourceLanguage GetExpressionLanguage() { return m_expression_language; }
101101

102102
bool HitErrorBackstop() { return m_hit_error_backstop; }
103103

@@ -148,7 +148,7 @@ class ThreadPlanCallFunction : public ThreadPlan {
148148
bool m_should_clear_cxx_exception_bp;
149149
lldb::addr_t m_stop_address; // This is the address we stopped at. Also set
150150
// in DoTakedown;
151-
lldb::LanguageType
151+
SourceLanguage
152152
m_expression_language; // Set from the incoming ExpressionOptions.
153153
lldb::BreakpointSP m_error_backstop_bp_sp;
154154
bool m_hit_error_backstop;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ struct RegisterSet {
9696
const uint32_t *registers;
9797
};
9898

99+
/// A type-erased pair of llvm::dwarf::SourceLanguageName and version.
100+
struct SourceLanguage {
101+
SourceLanguage() = default;
102+
SourceLanguage(lldb::LanguageType language_type);
103+
SourceLanguage(uint16_t name, uint32_t version)
104+
: name(name), version(version) {}
105+
SourceLanguage(std::optional<std::pair<uint16_t, uint32_t>> name_vers)
106+
: name(name_vers ? name_vers->first : 0),
107+
version(name_vers ? name_vers->second : 0) {}
108+
operator bool() const { return name > 0; }
109+
lldb::LanguageType AsLanguageType() const;
110+
llvm::StringRef GetDescription() const;
111+
bool IsC() const;
112+
bool IsObjC() const;
113+
bool IsCPlusPlus() const;
114+
uint16_t name = 0;
115+
uint32_t version = 0;
116+
};
117+
99118
struct OptionEnumValueElement {
100119
int64_t value;
101120
const char *string_value;

lldb/packages/Python/lldbsuite/test/configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127

128128
# LLDB library directory.
129129
lldb_libs_dir = None
130+
lldb_obj_root = None
130131

131132
libcxx_include_dir = None
132133
libcxx_include_target_dir = None

lldb/packages/Python/lldbsuite/test/dotest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ def parseOptionsAndInitTestdirs():
426426
configuration.lldb_module_cache_dir = os.path.join(
427427
configuration.test_build_dir, "module-cache-lldb"
428428
)
429+
429430
if args.clang_module_cache_dir:
430431
configuration.clang_module_cache_dir = args.clang_module_cache_dir
431432
else:
@@ -438,6 +439,8 @@ def parseOptionsAndInitTestdirs():
438439

439440
if args.lldb_libs_dir:
440441
configuration.lldb_libs_dir = args.lldb_libs_dir
442+
if args.lldb_obj_root:
443+
configuration.lldb_obj_root = args.lldb_obj_root
441444

442445
if args.enabled_plugins:
443446
configuration.enabled_plugins = args.enabled_plugins

lldb/packages/Python/lldbsuite/test/dotest_args.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,17 @@ def create_parser():
247247
metavar="The lib directory inside the Swift build directory",
248248
help="The lib directory inside the Swift build directory.",
249249
)
250+
group.add_argument(
251+
"--lldb-obj-root",
252+
dest="lldb_obj_root",
253+
metavar="path",
254+
help="The path to the LLDB object files.",
255+
)
250256
group.add_argument(
251257
"--lldb-libs-dir",
252258
dest="lldb_libs_dir",
253259
metavar="path",
254-
help="The path to LLDB library directory (containing liblldb)",
260+
help="The path to LLDB library directory (containing liblldb).",
255261
)
256262
group.add_argument(
257263
"--enable-plugin",

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,23 +1480,25 @@ def buildDriver(self, sources, exe_name):
14801480
d = {
14811481
"CXX_SOURCES": sources,
14821482
"EXE": exe_name,
1483-
"CFLAGS_EXTRAS": "%s %s -I%s"
1483+
"CFLAGS_EXTRAS": "%s %s -I%s -I%s"
14841484
% (
14851485
stdflag,
14861486
stdlibflag,
14871487
os.path.join(os.environ["LLDB_SRC"], "include"),
1488+
os.path.join(configuration.lldb_obj_root, "include"),
14881489
),
14891490
"LD_EXTRAS": "-L%s -lliblldb" % lib_dir,
14901491
}
14911492
else:
14921493
d = {
14931494
"CXX_SOURCES": sources,
14941495
"EXE": exe_name,
1495-
"CFLAGS_EXTRAS": "%s %s -I%s"
1496+
"CFLAGS_EXTRAS": "%s %s -I%s -I%s"
14961497
% (
14971498
stdflag,
14981499
stdlibflag,
14991500
os.path.join(os.environ["LLDB_SRC"], "include"),
1501+
os.path.join(configuration.lldb_obj_root, "include"),
15001502
),
15011503
"LD_EXTRAS": "-L%s -llldb -Wl,-rpath,%s" % (lib_dir, lib_dir),
15021504
}
@@ -1515,7 +1517,8 @@ def buildLibrary(self, sources, lib_name):
15151517
d = {
15161518
"DYLIB_CXX_SOURCES": sources,
15171519
"DYLIB_NAME": lib_name,
1518-
"CFLAGS_EXTRAS": "%s -stdlib=libc++" % stdflag,
1520+
"CFLAGS_EXTRAS": "%s -stdlib=libc++ -I%s"
1521+
% (stdflag, os.path.join(configuration.lldb_obj_root, "include")),
15191522
"FRAMEWORK_INCLUDES": "-F%s" % self.framework_dir,
15201523
"LD_EXTRAS": "%s -Wl,-rpath,%s -dynamiclib"
15211524
% (self.lib_lldb, self.framework_dir),
@@ -1524,16 +1527,24 @@ def buildLibrary(self, sources, lib_name):
15241527
d = {
15251528
"DYLIB_CXX_SOURCES": sources,
15261529
"DYLIB_NAME": lib_name,
1527-
"CFLAGS_EXTRAS": "%s -I%s "
1528-
% (stdflag, os.path.join(os.environ["LLDB_SRC"], "include")),
1530+
"CFLAGS_EXTRAS": "%s -I%s -I%s"
1531+
% (
1532+
stdflag,
1533+
os.path.join(os.environ["LLDB_SRC"], "include"),
1534+
os.path.join(configuration.lldb_obj_root, "include"),
1535+
),
15291536
"LD_EXTRAS": "-shared -l%s\liblldb.lib" % lib_dir,
15301537
}
15311538
else:
15321539
d = {
15331540
"DYLIB_CXX_SOURCES": sources,
15341541
"DYLIB_NAME": lib_name,
1535-
"CFLAGS_EXTRAS": "%s -I%s -fPIC"
1536-
% (stdflag, os.path.join(os.environ["LLDB_SRC"], "include")),
1542+
"CFLAGS_EXTRAS": "%s -I%s -I%s -fPIC"
1543+
% (
1544+
stdflag,
1545+
os.path.join(os.environ["LLDB_SRC"], "include"),
1546+
os.path.join(configuration.lldb_obj_root, "include"),
1547+
),
15371548
"LD_EXTRAS": "-shared -L%s -llldb -Wl,-rpath,%s" % (lib_dir, lib_dir),
15381549
}
15391550
if self.TraceOn():

lldb/source/API/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ if(LLDB_ENABLE_LUA)
3030
set(lldb_lua_wrapper ${lua_bindings_dir}/LLDBWrapLua.cpp)
3131
endif()
3232

33+
lldb_tablegen(../../include/lldb/API/SBLanguages.h -gen-lldb-sbapi-dwarf-enum
34+
SOURCE ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def
35+
TARGET lldb-sbapi-dwarf-enums)
36+
3337
add_lldb_library(liblldb SHARED ${option_framework}
3438
SBAddress.cpp
3539
SBAttachInfo.cpp
@@ -110,6 +114,9 @@ add_lldb_library(liblldb SHARED ${option_framework}
110114
${lldb_python_wrapper}
111115
${lldb_lua_wrapper}
112116

117+
DEPENDS
118+
lldb-sbapi-dwarf-enums
119+
113120
LINK_LIBS
114121
lldbBreakpoint
115122
lldbCore

lldb/source/API/SBExpressionOptions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ void SBExpressionOptions::SetLanguage(lldb::LanguageType language) {
156156
m_opaque_up->SetLanguage(language);
157157
}
158158

159+
void SBExpressionOptions::SetLanguage(SBSourceLanguageName name,
160+
uint32_t version) {
161+
LLDB_INSTRUMENT_VA(this, name, version);
162+
163+
m_opaque_up->SetLanguage(name, version);
164+
}
165+
159166
void SBExpressionOptions::SetCancelCallback(
160167
lldb::ExpressionCancelCallback callback, void *baton) {
161168
LLDB_INSTRUMENT_VA(this, callback, baton);

0 commit comments

Comments
 (0)