Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 9 additions & 3 deletions lldb/include/lldb/lldb-private-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,24 @@ struct RegisterSet {
/// A type-erased pair of llvm::dwarf::SourceLanguageName and version.
struct SourceLanguage {
SourceLanguage() = default;
SourceLanguage(lldb::LanguageType language_type);
explicit SourceLanguage(lldb::LanguageType language_type);

SourceLanguage(uint16_t name, uint32_t version)
: name(name), version(version) {}
SourceLanguage(std::optional<std::pair<uint16_t, uint32_t>> name_vers)

explicit SourceLanguage(
std::optional<std::pair<uint16_t, uint32_t>> name_vers)
: name(name_vers ? name_vers->first : 0),
version(name_vers ? name_vers->second : 0) {}
operator bool() const { return name > 0; }

explicit operator bool() const { return name > 0; }

lldb::LanguageType AsLanguageType() const;
llvm::StringRef GetDescription() const;
bool IsC() const;
bool IsObjC() const;
bool IsCPlusPlus() const;
bool IsSwift() const;
Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, the Is... accessors made sense for merged languages like ObjC++, but Swift only has one dialect, so we could just compare the LNAME?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea makes sense!

uint16_t name = 0;
uint32_t version = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/BreakpointLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ bool BreakpointLocation::ConditionSaysStop(ExecutionContext &exe_ctx,
}

m_user_expression_sp.reset(GetTarget().GetUserExpressionForLanguage(
condition.GetText(), llvm::StringRef(), language,
condition.GetText(), llvm::StringRef(), SourceLanguage{language},
Expression::eResultTypeAny, EvaluateExpressionOptions(), nullptr,
error));
if (error.Fail()) {
Expand Down
12 changes: 6 additions & 6 deletions lldb/source/Commands/CommandObjectDWIMPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
StackFrame *frame = m_exe_ctx.GetFramePtr();

// Either the language was explicitly specified, or we check the frame.
lldb::LanguageType language = m_expr_options.language;
if (language == lldb::eLanguageTypeUnknown && frame)
language = frame->GuessLanguage().AsLanguageType();
SourceLanguage language{m_expr_options.language};
if (!language && frame)
language = frame->GuessLanguage();

// Add a hint if object description was requested, but no description
// function was implemented.
Expand All @@ -119,8 +119,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
"^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");

if (GetDebugger().GetShowDontUsePoHint() && target_ptr &&
(language == lldb::eLanguageTypeSwift ||
language == lldb::eLanguageTypeObjC) &&
(language.IsSwift() || language.IsObjC()) &&
std::regex_match(output.data(), swift_class_regex)) {

result.AppendNote(
Expand Down Expand Up @@ -193,7 +192,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,

// Second, try `expr` as a persistent variable.
if (expr.starts_with("$"))
if (auto *state = target.GetPersistentExpressionStateForLanguage(language))
if (auto *state = target.GetPersistentExpressionStateForLanguage(
language.AsLanguageType()))
if (auto var_sp = state->GetVariable(expr))
if (auto valobj_sp = var_sp->GetValueObject()) {
dump_val_object(*valobj_sp);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Expression/UserExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
// language in the target's properties if specified, else default to the
// langage for the frame.
if (!language) {
if (target->GetLanguage() != lldb::eLanguageTypeUnknown)
if (target->GetLanguage())
language = target->GetLanguage();
else if (StackFrame *frame = exe_ctx.GetFramePtr())
language = frame->GetLanguage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ lldb_private::Status ClangExpressionParser::DoPrepareForExecution(
LLDB_LOGF(log, "%s - Current expression language is %s\n", __FUNCTION__,
lang.GetDescription().data());
lldb::ProcessSP process_sp = exe_ctx.GetProcessSP();
if (process_sp && lang != lldb::eLanguageTypeUnknown) {
if (process_sp && lang) {
auto runtime = process_sp->GetLanguageRuntime(lang.AsLanguageType());
if (runtime)
runtime->GetIRPasses(custom_passes);
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Target/Language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,7 @@ bool SourceLanguage::IsObjC() const {
bool SourceLanguage::IsCPlusPlus() const {
return name == llvm::dwarf::DW_LNAME_C_plus_plus;
}

bool SourceLanguage::IsSwift() const {
return name == llvm::dwarf::DW_LNAME_Swift;
}
6 changes: 3 additions & 3 deletions lldb/source/Target/StackFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,18 +1344,18 @@ const char *StackFrame::GetDisplayFunctionName() {
SourceLanguage StackFrame::GetLanguage() {
CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
if (cu)
return cu->GetLanguage();
return SourceLanguage{cu->GetLanguage()};
return {};
}

SourceLanguage StackFrame::GuessLanguage() {
SourceLanguage lang_type = GetLanguage();

if (lang_type == eLanguageTypeUnknown) {
if (!lang_type) {
SymbolContext sc =
GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol);
if (sc.function)
lang_type = LanguageType(sc.function->GetMangled().GuessLanguage());
lang_type = SourceLanguage(sc.function->GetMangled().GuessLanguage());
else if (sc.symbol)
lang_type = SourceLanguage(sc.symbol->GetMangled().GuessLanguage());
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4945,7 +4945,7 @@ void TargetProperties::SetStandardErrorPath(llvm::StringRef path) {

SourceLanguage TargetProperties::GetLanguage() const {
const uint32_t idx = ePropertyLanguage;
return {GetPropertyAtIndexAs<LanguageType>(idx, {})};
return SourceLanguage{GetPropertyAtIndexAs<LanguageType>(idx, {})};
}

llvm::StringRef TargetProperties::GetExpressionPrefixContents() {
Expand Down
Loading