Author: Walter Erquinigo Date: 2024-07-04T10:05:01-04:00 New Revision: 94a067a306fecceac913cc6d9bfdcd49464358ec
URL: https://github.com/llvm/llvm-project/commit/94a067a306fecceac913cc6d9bfdcd49464358ec DIFF: https://github.com/llvm/llvm-project/commit/94a067a306fecceac913cc6d9bfdcd49464358ec.diff LOG: [LLDB] Support exception breakpoints for plugin-provided languages (#97675) CommandObjectBreakpoint has a harcoded list of languages for which exception breakpoints can be enabled. I'm making this a bit more generic so that my Mojo plugin can get this feature. Basically, I'm adding a new overridable method `Language::SupportsExceptionBreakpoints` that can be used by language plugins to determine whether they support this feature or not. This method is used in addition to the hardcoded list and, as an example, I'm using it for the ObjC language support. Another route is simply to avoid doing the check that it's being done right now and simply try to the create the exception breakpoint for whatever language that is not in the hardcoded list. I'm happy to do that if the reviewers think it's a good idea. As a note, the other possible place for adding this `SupportsExceptionBreakpoints` method is in `LanguageRuntime`. However, accessing it requires having a process, which is not always the case when invoking the `breakpoint set -E` command. The process might not be alive yet, so `Language` is a good second place for this. And as a final note, I don't want to make this `SupportsExceptionBreakpoints` complicated. I'm keeping it as simple as possible because it can easily evolve as it's not part of the public API. Added: Modified: lldb/include/lldb/Target/Language.h lldb/source/Commands/CommandObjectBreakpoint.cpp lldb/source/Plugins/Language/ObjC/ObjCLanguage.h Removed: ################################################################################ diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h index ff7c60bf68bfc9..2d6e5a40a0c0e4 100644 --- a/lldb/include/lldb/Target/Language.h +++ b/lldb/include/lldb/Target/Language.h @@ -363,6 +363,10 @@ class Language : public PluginInterface { return false; } + /// Returns true if this Language supports exception breakpoints via a + /// corresponding LanguageRuntime plugin. + virtual bool SupportsExceptionBreakpoints() const { return false; } + protected: // Classes that inherit from Language can see and modify these diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp index cd4c7790f447e1..a5fe9273fac76d 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.cpp +++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp @@ -308,9 +308,6 @@ class CommandObjectBreakpointSet : public CommandObjectParsed { case eLanguageTypeC_plus_plus_14: m_exception_language = eLanguageTypeC_plus_plus; break; - case eLanguageTypeObjC: - m_exception_language = eLanguageTypeObjC; - break; case eLanguageTypeObjC_plus_plus: error_context = "Set exception breakpoints separately for c++ and objective-c"; @@ -319,6 +316,12 @@ class CommandObjectBreakpointSet : public CommandObjectParsed { error_context = "Unknown language type for exception breakpoint"; break; default: + if (Language *languagePlugin = Language::FindPlugin(language)) { + if (languagePlugin->SupportsExceptionBreakpoints()) { + m_exception_language = language; + break; + } + } error_context = "Unsupported language type for exception breakpoint"; } if (!error_context.empty()) diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h index a50f4b036108d7..a61d0f128370d4 100644 --- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h +++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h @@ -194,6 +194,8 @@ class ObjCLanguage : public Language { llvm::StringRef GetInstanceVariableName() override { return "self"; } + bool SupportsExceptionBreakpoints() const override { return true; } + // PluginInterface protocol llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } }; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits