Skip to content

[lldb] Allow languages to filter breakpoints set by line #83908

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

Merged
merged 7 commits into from
Mar 14, 2024
Merged
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
20 changes: 20 additions & 0 deletions lldb/include/lldb/Target/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@

namespace lldb_private {

class LanguageProperties : public Properties {
public:
LanguageProperties();

static llvm::StringRef GetSettingName();

bool GetEnableFilterForLineBreakpoints() const;
};

class Language : public PluginInterface {
public:
class TypeScavenger {
Expand Down Expand Up @@ -324,6 +333,8 @@ class Language : public PluginInterface {
static LanguageSet GetLanguagesSupportingTypeSystemsForExpressions();
static LanguageSet GetLanguagesSupportingREPLs();

static LanguageProperties &GetGlobalLanguageProperties();

// Given a mangled function name, calculates some alternative manglings since
// the compiler mangling may not line up with the symbol we are expecting.
virtual std::vector<ConstString>
Expand All @@ -339,6 +350,15 @@ class Language : public PluginInterface {

virtual llvm::StringRef GetInstanceVariableName() { return {}; }

/// Returns true if this SymbolContext should be ignored when setting
/// breakpoints by line (number or regex). Helpful for languages that create
/// artificial functions without meaningful user code associated with them
/// (e.g. code that gets expanded in late compilation stages, like by
/// CoroSplitter).
virtual bool IgnoreForLineBreakpoints(const SymbolContext &) const {
return false;
}

protected:
// Classes that inherit from Language can see and modify these

Expand Down
12 changes: 10 additions & 2 deletions lldb/source/Breakpoint/BreakpointResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
Expand Down Expand Up @@ -203,8 +204,15 @@ void BreakpointResolver::SetSCMatchesByLine(
SearchFilter &filter, SymbolContextList &sc_list, bool skip_prologue,
llvm::StringRef log_ident, uint32_t line, std::optional<uint16_t> column) {
llvm::SmallVector<SymbolContext, 16> all_scs;
for (uint32_t i = 0; i < sc_list.GetSize(); ++i)
all_scs.push_back(sc_list[i]);

for (const auto &sc : sc_list) {
if (Language::GetGlobalLanguageProperties()
.GetEnableFilterForLineBreakpoints())
if (Language *lang = Language::FindPlugin(sc.GetLanguage());
lang && lang->IgnoreForLineBreakpoints(sc))
continue;
all_scs.push_back(sc);
}

while (all_scs.size()) {
uint32_t closest_line = UINT32_MAX;
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,9 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
m_collection_sp->AppendProperty(
"symbols", "Symbol lookup and cache settings.", true,
ModuleList::GetGlobalModuleListProperties().GetValueProperties());
m_collection_sp->AppendProperty(
LanguageProperties::GetSettingName(), "Language settings.", true,
Language::GetGlobalLanguageProperties().GetValueProperties());
if (m_command_interpreter_up) {
m_collection_sp->AppendProperty(
"interpreter",
Expand Down
30 changes: 30 additions & 0 deletions lldb/source/Target/Language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "lldb/Target/Language.h"

#include "lldb/Core/PluginManager.h"
#include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/TypeList.h"
#include "lldb/Target/Target.h"
Expand All @@ -27,6 +28,35 @@ using namespace lldb_private::formatters;
typedef std::unique_ptr<Language> LanguageUP;
typedef std::map<lldb::LanguageType, LanguageUP> LanguagesMap;

#define LLDB_PROPERTIES_language
#include "TargetProperties.inc"

enum {
#define LLDB_PROPERTIES_language
#include "TargetPropertiesEnum.inc"
};

LanguageProperties &Language::GetGlobalLanguageProperties() {
static LanguageProperties g_settings;
return g_settings;
}

llvm::StringRef LanguageProperties::GetSettingName() {
static constexpr llvm::StringLiteral g_setting_name("language");
return g_setting_name;
}

LanguageProperties::LanguageProperties() {
m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
m_collection_sp->Initialize(g_language_properties);
}

bool LanguageProperties::GetEnableFilterForLineBreakpoints() const {
const uint32_t idx = ePropertyEnableFilterForLineBreakpoints;
return GetPropertyAtIndexAs<bool>(
idx, g_language_properties[idx].default_uint_value != 0);
}

static LanguagesMap &GetLanguagesMap() {
static LanguagesMap *g_map = nullptr;
static llvm::once_flag g_initialize;
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Target/TargetProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,9 @@ let Definition = "thread" in {
DefaultUnsignedValue<600000>,
Desc<"Maximum number of frames to backtrace.">;
}

let Definition = "language" in {
def EnableFilterForLineBreakpoints: Property<"enable-filter-for-line-breakpoints", "Boolean">,
DefaultTrue,
Desc<"If true, allow Language plugins to filter locations when setting breakpoints by line number or regex.">;
}