Skip to content

Commit 8a82d83

Browse files
Merge pull request #8657 from adrian-prantl/126783312-6.0
Add a new SBExpressionOptions::SetLanguage() API
2 parents 5dc3fbd + f8a1db3 commit 8a82d83

File tree

60 files changed

+819
-185
lines changed

Some content is hidden

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

60 files changed

+819
-185
lines changed

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(LLDB_INCLUDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include")
77

88
set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
99
set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
10+
set(LLDB_OBJ_DIR ${CMAKE_CURRENT_BINARY_DIR})
1011

1112
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
1213
message(FATAL_ERROR

lldb/cmake/modules/LLDBFramework.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +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)
7475
file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h)
7576
file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h)
7677
list(REMOVE_ITEM root_public_headers ${root_private_headers})
@@ -80,6 +81,7 @@ find_program(unifdef_EXECUTABLE unifdef)
8081
set(lldb_header_staging ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders)
8182
foreach(header
8283
${public_headers}
84+
${generated_public_headers}
8385
${root_public_headers})
8486

8587
get_filename_component(basename ${header} NAME)

lldb/include/lldb/API/LLDB.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "lldb/API/SBInstruction.h"
4141
#include "lldb/API/SBInstructionList.h"
4242
#include "lldb/API/SBLanguageRuntime.h"
43+
#include "lldb/API/SBLanguages.h"
4344
#include "lldb/API/SBLaunchInfo.h"
4445
#include "lldb/API/SBLineEntry.h"
4546
#include "lldb/API/SBListener.h"

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

@@ -196,7 +196,7 @@ class UserExpression : public Expression {
196196
virtual bool IsParseCacheable() { return true; }
197197
/// Return the language that should be used when parsing. To use the
198198
/// default, return eLanguageTypeUnknown.
199-
lldb::LanguageType Language() const override { return m_language; }
199+
SourceLanguage Language() const override { return m_language; }
200200

201201
/// Return the desired result type of the function, or eResultTypeAny if
202202
/// indifferent.
@@ -308,19 +308,22 @@ class UserExpression : public Expression {
308308
lldb::ProcessSP &process_sp,
309309
lldb::StackFrameSP &frame_sp);
310310

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

326329
} // namespace lldb_private

lldb/include/lldb/Symbol/TypeSystem.h

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

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

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
@@ -241,7 +241,7 @@ class TargetProperties : public Properties {
241241

242242
bool GetBreakpointsConsultPlatformAvoidList();
243243

244-
lldb::LanguageType GetLanguage() const;
244+
SourceLanguage GetLanguage() const;
245245

246246
llvm::StringRef GetExpressionPrefixContents();
247247

@@ -355,9 +355,18 @@ class EvaluateExpressionOptions {
355355
m_execution_policy = policy;
356356
}
357357

358-
lldb::LanguageType GetLanguage() const { return m_language; }
358+
SourceLanguage GetLanguage() const { return m_language; }
359359

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

362371
bool DoesCoerceToId() const { return m_coerce_to_id; }
363372

@@ -520,7 +529,7 @@ class EvaluateExpressionOptions {
520529

521530
private:
522531
ExecutionPolicy m_execution_policy = default_execution_policy;
523-
lldb::LanguageType m_language = lldb::eLanguageTypeUnknown;
532+
SourceLanguage m_language;
524533
std::string m_prefix;
525534
bool m_coerce_to_id = false;
526535
bool m_unwind_on_error = true;
@@ -1248,7 +1257,7 @@ class Target : public std::enable_shared_from_this<Target>,
12481257

12491258
UserExpression *
12501259
GetUserExpressionForLanguage(llvm::StringRef expr, llvm::StringRef prefix,
1251-
lldb::LanguageType language,
1260+
SourceLanguage language,
12521261
Expression::ResultType desired_type,
12531262
const EvaluateExpressionOptions &options,
12541263
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
@@ -94,6 +94,25 @@ struct RegisterSet {
9494
const uint32_t *registers;
9595
};
9696

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

lldb/packages/Python/lldbsuite/test/builders/builder.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ def getLLDBSwiftLibs(self):
175175
return ["SWIFT_LIBS_DIR={}".format(configuration.swift_libs_dir)]
176176
return []
177177

178+
def getLLDBObjRoot(self):
179+
return ["LLDB_OBJ_ROOT={}".format(configuration.lldb_obj_root)]
180+
178181
def _getDebugInfoArgs(self, debug_info):
179182
if debug_info is None:
180183
return []
@@ -216,6 +219,7 @@ def getBuildCommand(
216219
self.getModuleCacheSpec(),
217220
self.getLibCxxArgs(),
218221
self.getLLDBSwiftLibs(),
222+
self.getLLDBObjRoot(),
219223
self.getCmdLine(dictionary),
220224
]
221225
command = list(itertools.chain(*command_parts))

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

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

131131
# LLDB library directory.
132132
lldb_libs_dir = None
133+
lldb_obj_root = None
133134

134135
libcxx_include_dir = None
135136
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
@@ -429,6 +429,7 @@ def parseOptionsAndInitTestdirs():
429429
configuration.lldb_module_cache_dir = os.path.join(
430430
configuration.test_build_dir, "module-cache-lldb"
431431
)
432+
432433
if args.clang_module_cache_dir:
433434
configuration.clang_module_cache_dir = args.clang_module_cache_dir
434435
else:
@@ -441,6 +442,8 @@ def parseOptionsAndInitTestdirs():
441442

442443
if args.lldb_libs_dir:
443444
configuration.lldb_libs_dir = args.lldb_libs_dir
445+
if args.lldb_obj_root:
446+
configuration.lldb_obj_root = args.lldb_obj_root
444447

445448
if args.enabled_plugins:
446449
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
@@ -249,11 +249,17 @@ def create_parser():
249249
metavar="The lib directory inside the Swift build directory",
250250
help="The lib directory inside the Swift build directory.",
251251
)
252+
group.add_argument(
253+
"--lldb-obj-root",
254+
dest="lldb_obj_root",
255+
metavar="path",
256+
help="The path to the LLDB object files.",
257+
)
252258
group.add_argument(
253259
"--lldb-libs-dir",
254260
dest="lldb_libs_dir",
255261
metavar="path",
256-
help="The path to LLDB library directory (containing liblldb)",
262+
help="The path to LLDB library directory (containing liblldb).",
257263
)
258264
group.add_argument(
259265
"--enable-plugin",

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,23 +1465,25 @@ def buildDriver(self, sources, exe_name):
14651465
d = {
14661466
"CXX_SOURCES": sources,
14671467
"EXE": exe_name,
1468-
"CFLAGS_EXTRAS": "%s %s -I%s"
1468+
"CFLAGS_EXTRAS": "%s %s -I%s -I%s"
14691469
% (
14701470
stdflag,
14711471
stdlibflag,
14721472
os.path.join(os.environ["LLDB_SRC"], "include"),
1473+
os.path.join(configuration.lldb_obj_root, "include"),
14731474
),
14741475
"LD_EXTRAS": "-L%s -lliblldb" % lib_dir,
14751476
}
14761477
else:
14771478
d = {
14781479
"CXX_SOURCES": sources,
14791480
"EXE": exe_name,
1480-
"CFLAGS_EXTRAS": "%s %s -I%s"
1481+
"CFLAGS_EXTRAS": "%s %s -I%s -I%s"
14811482
% (
14821483
stdflag,
14831484
stdlibflag,
14841485
os.path.join(os.environ["LLDB_SRC"], "include"),
1486+
os.path.join(configuration.lldb_obj_root, "include"),
14851487
),
14861488
"LD_EXTRAS": "-L%s -llldb -Wl,-rpath,%s" % (lib_dir, lib_dir),
14871489
}
@@ -1500,7 +1502,8 @@ def buildLibrary(self, sources, lib_name):
15001502
d = {
15011503
"DYLIB_CXX_SOURCES": sources,
15021504
"DYLIB_NAME": lib_name,
1503-
"CFLAGS_EXTRAS": "%s -stdlib=libc++" % stdflag,
1505+
"CFLAGS_EXTRAS": "%s -stdlib=libc++ -I%s"
1506+
% (stdflag, os.path.join(configuration.lldb_obj_root, "include")),
15041507
"FRAMEWORK_INCLUDES": "-F%s" % self.framework_dir,
15051508
"LD_EXTRAS": "%s -Wl,-rpath,%s -dynamiclib"
15061509
% (self.lib_lldb, self.framework_dir),
@@ -1509,16 +1512,24 @@ def buildLibrary(self, sources, lib_name):
15091512
d = {
15101513
"DYLIB_CXX_SOURCES": sources,
15111514
"DYLIB_NAME": lib_name,
1512-
"CFLAGS_EXTRAS": "%s -I%s "
1513-
% (stdflag, os.path.join(os.environ["LLDB_SRC"], "include")),
1515+
"CFLAGS_EXTRAS": "%s -I%s -I%s"
1516+
% (
1517+
stdflag,
1518+
os.path.join(os.environ["LLDB_SRC"], "include"),
1519+
os.path.join(configuration.lldb_obj_root, "include"),
1520+
),
15141521
"LD_EXTRAS": "-shared -l%s\liblldb.lib" % lib_dir,
15151522
}
15161523
else:
15171524
d = {
15181525
"DYLIB_CXX_SOURCES": sources,
15191526
"DYLIB_NAME": lib_name,
1520-
"CFLAGS_EXTRAS": "%s -I%s -fPIC"
1521-
% (stdflag, os.path.join(os.environ["LLDB_SRC"], "include")),
1527+
"CFLAGS_EXTRAS": "%s -I%s -I%s -fPIC"
1528+
% (
1529+
stdflag,
1530+
os.path.join(os.environ["LLDB_SRC"], "include"),
1531+
os.path.join(configuration.lldb_obj_root, "include"),
1532+
),
15221533
"LD_EXTRAS": "-shared -L%s -llldb -Wl,-rpath,%s" % (lib_dir, lib_dir),
15231534
}
15241535
if self.TraceOn():

0 commit comments

Comments
 (0)