[Lldb-commits] [lldb] r342185 - Add a "scripted" breakpoint type to lldb.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 13 14:35:33 PDT 2018


Author: jingham
Date: Thu Sep 13 14:35:32 2018
New Revision: 342185

URL: http://llvm.org/viewvc/llvm-project?rev=342185&view=rev
Log:
Add a "scripted" breakpoint type to lldb.

This change allows you to write a new breakpoint type where the
logic for setting breakpoints is determined by a Python callback
written using the SB API's.

Differential Revision: https://reviews.llvm.org/D51830

Modified:
    lldb/trunk/include/lldb/API/SBAddress.h
    lldb/trunk/include/lldb/API/SBBreakpoint.h
    lldb/trunk/include/lldb/API/SBStructuredData.h
    lldb/trunk/include/lldb/API/SBSymbolContext.h
    lldb/trunk/include/lldb/API/SBTarget.h
    lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/include/lldb/lldb-defines.h
    lldb/trunk/include/lldb/lldb-enumerations.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py
    lldb/trunk/scripts/Python/python-swigsafecast.swig
    lldb/trunk/scripts/Python/python-wrapper.swig
    lldb/trunk/scripts/interface/SBBreakpoint.i
    lldb/trunk/scripts/interface/SBStructuredData.i
    lldb/trunk/scripts/interface/SBTarget.i
    lldb/trunk/source/API/SBBreakpoint.cpp
    lldb/trunk/source/API/SBStructuredData.cpp
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/API/SystemInitializerFull.cpp
    lldb/trunk/source/Breakpoint/BreakpointResolver.cpp
    lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
    lldb/trunk/source/Core/SearchFilter.cpp
    lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
    lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/API/SBAddress.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBAddress.h?rev=342185&r1=342184&r2=342185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBAddress.h (original)
+++ lldb/trunk/include/lldb/API/SBAddress.h Thu Sep 13 14:35:32 2018
@@ -82,6 +82,7 @@ public:
 
 protected:
   friend class SBBlock;
+  friend class SBBreakpoint;
   friend class SBBreakpointLocation;
   friend class SBFrame;
   friend class SBFunction;

Modified: lldb/trunk/include/lldb/API/SBBreakpoint.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBBreakpoint.h?rev=342185&r1=342184&r2=342185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBBreakpoint.h (original)
+++ lldb/trunk/include/lldb/API/SBBreakpoint.h Thu Sep 13 14:35:32 2018
@@ -23,6 +23,8 @@ public:
 
   SBBreakpoint(const lldb::SBBreakpoint &rhs);
 
+  SBBreakpoint(const lldb::BreakpointSP &bp_sp);
+
   ~SBBreakpoint();
 
   const lldb::SBBreakpoint &operator=(const lldb::SBBreakpoint &rhs);
@@ -127,14 +129,16 @@ public:
   static uint32_t
   GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event_sp);
 
+  // Can only be called from a ScriptedBreakpointResolver...
+  SBError
+  AddLocation(SBAddress &address);
+  
 private:
   friend class SBBreakpointList;
   friend class SBBreakpointLocation;
   friend class SBBreakpointName;
   friend class SBTarget;
 
-  SBBreakpoint(const lldb::BreakpointSP &bp_sp);
-
   lldb::BreakpointSP GetSP() const;
 
   lldb::BreakpointWP m_opaque_wp;

Modified: lldb/trunk/include/lldb/API/SBStructuredData.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStructuredData.h?rev=342185&r1=342184&r2=342185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBStructuredData.h (original)
+++ lldb/trunk/include/lldb/API/SBStructuredData.h Thu Sep 13 14:35:32 2018
@@ -22,6 +22,8 @@ public:
   SBStructuredData(const lldb::SBStructuredData &rhs);
 
   SBStructuredData(const lldb::EventSP &event_sp);
+  
+  SBStructuredData(lldb_private::StructuredDataImpl *impl);
 
   ~SBStructuredData();
 
@@ -41,7 +43,7 @@ public:
   /// Return the type of data in this data structure
   //------------------------------------------------------------------
   lldb::StructuredDataType GetType() const;
-
+  
   //------------------------------------------------------------------
   /// Return the size (i.e. number of elements) in this data structure
   /// if it is an array or dictionary type. For other types, 0 will be
@@ -50,6 +52,12 @@ public:
   size_t GetSize() const;
 
   //------------------------------------------------------------------
+  /// Fill keys with the keys in this object and return true if this data
+  /// structure is a dictionary.  Returns false otherwise.
+  //------------------------------------------------------------------
+   bool GetKeys(lldb::SBStringList &keys) const;
+  
+  //------------------------------------------------------------------
   /// Return the value corresponding to a key if this data structure
   /// is a dictionary type.
   //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/API/SBSymbolContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSymbolContext.h?rev=342185&r1=342184&r2=342185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBSymbolContext.h (original)
+++ lldb/trunk/include/lldb/API/SBSymbolContext.h Thu Sep 13 14:35:32 2018
@@ -26,6 +26,8 @@ public:
 
   SBSymbolContext(const lldb::SBSymbolContext &rhs);
 
+  SBSymbolContext(const lldb_private::SymbolContext *sc_ptr);
+
   ~SBSymbolContext();
 
   bool IsValid() const;
@@ -69,8 +71,6 @@ protected:
 
   lldb_private::SymbolContext *get() const;
 
-  SBSymbolContext(const lldb_private::SymbolContext *sc_ptr);
-
   void SetSymbolContext(const lldb_private::SymbolContext *sc_ptr);
 
 private:

Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=342185&r1=342184&r2=342185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Thu Sep 13 14:35:32 2018
@@ -662,6 +662,37 @@ public:
   lldb::SBBreakpoint BreakpointCreateByAddress(addr_t address);
 
   lldb::SBBreakpoint BreakpointCreateBySBAddress(SBAddress &address);
+  
+  //------------------------------------------------------------------
+  /// Create a breakpoint using a scripted resolver.
+  ///
+  /// @param[in] class_name
+  ///    This is the name of the class that implements a scripted resolver.
+  ///
+  /// @param[in] extra_args
+  ///    This is an SBStructuredData object that will get passed to the
+  ///    constructor of the class in class_name.  You can use this to 
+  ///    reuse the same class, parametrizing with entries from this 
+  ///    dictionary.
+  ///
+  /// @param module_list
+  ///    If this is non-empty, this will be used as the module filter in the 
+  ///    SearchFilter created for this breakpoint.
+  ///
+  /// @param file_list
+  ///    If this is non-empty, this will be used as the comp unit filter in the 
+  ///    SearchFilter created for this breakpoint.
+  ///
+  /// @return
+  ///     An SBBreakpoint that will set locations based on the logic in the
+  ///     resolver's search callback.
+  //------------------------------------------------------------------
+  lldb::SBBreakpoint BreakpointCreateFromScript(
+      const char *class_name,
+      SBStructuredData &extra_args,
+      const SBFileSpecList &module_list,
+      const SBFileSpecList &file_list,
+      bool request_hardware = false);
 
   //------------------------------------------------------------------
   /// Read breakpoints from source_file and return the newly created

Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h?rev=342185&r1=342184&r2=342185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h Thu Sep 13 14:35:32 2018
@@ -158,6 +158,7 @@ public:
     AddressResolver,      // This is an instance of BreakpointResolverAddress
     NameResolver,         // This is an instance of BreakpointResolverName
     FileRegexResolver,
+    PythonResolver,
     ExceptionResolver,
     LastKnownResolverType = ExceptionResolver,
     UnknownResolver
@@ -204,14 +205,19 @@ protected:
     ModuleName,
     NameMaskArray,
     Offset,
+    PythonClassName,
     RegexString,
+    ScriptArgs,
     SectionName,
+    SearchDepth,
     SkipPrologue,
     SymbolNameArray,
     LastOptionName
   };
   static const char
       *g_option_names[static_cast<uint32_t>(OptionNames::LastOptionName)];
+  
+  virtual void NotifyBreakpointSet() {};
 
 public:
   static const char *GetKey(OptionNames enum_value) {

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=342185&r1=342184&r2=342185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Thu Sep 13 14:35:32 2018
@@ -19,6 +19,7 @@
 #include "lldb/Breakpoint/BreakpointOptions.h"
 #include "lldb/Core/Broadcaster.h"
 #include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/SearchFilter.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StructuredData.h"
 
@@ -234,6 +235,26 @@ public:
     return lldb::eStateStepping;
   }
 
+  virtual StructuredData::GenericSP
+  CreateScriptedBreakpointResolver(const char *class_name,
+                                   StructuredDataImpl *args_data,
+                                   lldb::BreakpointSP &bkpt_sp) {
+    return StructuredData::GenericSP();
+  }
+  
+  virtual bool
+  ScriptedBreakpointResolverSearchCallback(StructuredData::GenericSP implementor_sp,
+                                           SymbolContext *sym_ctx)
+  {
+    return false;
+  }
+
+  virtual lldb::SearchDepth
+  ScriptedBreakpointResolverSearchDepth(StructuredData::GenericSP implementor_sp)
+  {
+    return lldb::eSearchDepthModule;
+  }
+
   virtual StructuredData::ObjectSP
   LoadPluginModule(const FileSpec &file_spec, lldb_private::Status &error) {
     return StructuredData::ObjectSP();

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=342185&r1=342184&r2=342185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Thu Sep 13 14:35:32 2018
@@ -617,6 +617,15 @@ public:
                             Args *additional_args = nullptr,
                             Status *additional_args_error = nullptr);
 
+  lldb::BreakpointSP
+  CreateScriptedBreakpoint(const llvm::StringRef class_name,
+                           const FileSpecList *containingModules,
+                           const FileSpecList *containingSourceFiles,
+                           bool internal,
+                           bool request_hardware,
+                           StructuredData::ObjectSP extra_args_sp,
+                           Status *creation_error = nullptr);
+
   // This is the same as the func_name breakpoint except that you can specify a
   // vector of names.  This is cheaper than a regular expression breakpoint in
   // the case where you just want to set a breakpoint on a set of names you

Modified: lldb/trunk/include/lldb/lldb-defines.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-defines.h?rev=342185&r1=342184&r2=342185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-defines.h (original)
+++ lldb/trunk/include/lldb/lldb-defines.h Thu Sep 13 14:35:32 2018
@@ -135,6 +135,7 @@
 #define LLDB_OPT_SET_8 (1U << 7)
 #define LLDB_OPT_SET_9 (1U << 8)
 #define LLDB_OPT_SET_10 (1U << 9)
+#define LLDB_OPT_SET_11 (1U << 10)
 #define LLDB_OPT_SET_FROM_TO(A, B)                                             \
   (((1U << (B)) - 1) ^ (((1U << (A)) - 1) >> 1))
 

Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=342185&r1=342184&r2=342185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Thu Sep 13 14:35:32 2018
@@ -258,13 +258,14 @@ enum ExpressionResults {
 };
 
 enum SearchDepth {
-    eSearchDepthTarget = 0,
+    eSearchDepthInvalid = 0,
+    eSearchDepthTarget,
     eSearchDepthModule,
     eSearchDepthCompUnit,
     eSearchDepthFunction,
     eSearchDepthBlock,
     eSearchDepthAddress,
-    kNumSearchDepthKinds = eSearchDepthAddress
+    kLastSearchDepthKind = eSearchDepthAddress
 };
 
 //----------------------------------------------------------------------




More information about the lldb-commits mailing list