[Lldb-commits] [lldb] 34d4c8a - [lldb] Have LanguageRuntime and SystemRuntime share a base class (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 24 16:28:44 PDT 2020


Author: Jonas Devlieghere
Date: 2020-07-24T16:28:34-07:00
New Revision: 34d4c8a53e569b1b83a0672015a19f8ca9bb3c35

URL: https://github.com/llvm/llvm-project/commit/34d4c8a53e569b1b83a0672015a19f8ca9bb3c35
DIFF: https://github.com/llvm/llvm-project/commit/34d4c8a53e569b1b83a0672015a19f8ca9bb3c35.diff

LOG: [lldb] Have LanguageRuntime and SystemRuntime share a base class (NFC)

LangaugeRuntime and SystemRuntime now both inherit from Runtime.

Added: 
    lldb/include/lldb/Target/Runtime.h

Modified: 
    lldb/include/lldb/Target/LanguageRuntime.h
    lldb/include/lldb/Target/SystemRuntime.h
    lldb/source/Target/LanguageRuntime.cpp
    lldb/source/Target/SystemRuntime.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/LanguageRuntime.h b/lldb/include/lldb/Target/LanguageRuntime.h
index b0b9b919911a..da3cb9702392 100644
--- a/lldb/include/lldb/Target/LanguageRuntime.h
+++ b/lldb/include/lldb/Target/LanguageRuntime.h
@@ -18,6 +18,7 @@
 #include "lldb/Expression/LLVMUserExpression.h"
 #include "lldb/Symbol/DeclVendor.h"
 #include "lldb/Target/ExecutionContextScope.h"
+#include "lldb/Target/Runtime.h"
 #include "lldb/lldb-private.h"
 #include "lldb/lldb-public.h"
 
@@ -56,7 +57,7 @@ class ExceptionSearchFilter : public SearchFilter {
   void UpdateModuleListIfNeeded();
 };
 
-class LanguageRuntime : public PluginInterface {
+class LanguageRuntime : public Runtime, public PluginInterface {
 public:
   ~LanguageRuntime() override;
 
@@ -127,10 +128,6 @@ class LanguageRuntime : public PluginInterface {
     return lldb::ThreadSP();
   }
 
-  Process *GetProcess() { return m_process; }
-
-  Target &GetTargetRef() { return m_process->GetTarget(); }
-
   virtual DeclVendor *GetDeclVendor() { return nullptr; }
 
   virtual lldb::BreakpointResolverSP
@@ -159,7 +156,7 @@ class LanguageRuntime : public PluginInterface {
     return llvm::None;
   }
 
-  virtual void ModulesDidLoad(const ModuleList &module_list) {}
+  virtual void ModulesDidLoad(const ModuleList &module_list) override {}
 
   // Called by ClangExpressionParser::PrepareForExecution to query for any
   // custom LLVM IR passes that need to be run before an expression is
@@ -179,10 +176,7 @@ class LanguageRuntime : public PluginInterface {
   static char ID;
 
 protected:
-  // Classes that inherit from LanguageRuntime can see and modify these
-
   LanguageRuntime(Process *process);
-  Process *m_process;
 
 private:
   LanguageRuntime(const LanguageRuntime &) = delete;

diff  --git a/lldb/include/lldb/Target/Runtime.h b/lldb/include/lldb/Target/Runtime.h
new file mode 100644
index 000000000000..06f0b610e40b
--- /dev/null
+++ b/lldb/include/lldb/Target/Runtime.h
@@ -0,0 +1,33 @@
+//===-- Runtime.h -----------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_TARGET_RUNTIME_H
+#define LLDB_TARGET_RUNTIME_H
+
+#include "lldb/Target/Process.h"
+
+namespace lldb_private {
+class Runtime {
+public:
+  Runtime(Process *process) : m_process(process) {}
+  virtual ~Runtime() = default;
+  Runtime(const Runtime &) = delete;
+  const Runtime &operator=(const Runtime &) = delete;
+
+  Process *GetProcess() { return m_process; }
+  Target &GetTargetRef() { return m_process->GetTarget(); }
+
+  /// Called when modules have been loaded in the process.
+  virtual void ModulesDidLoad(const ModuleList &module_list) = 0;
+
+protected:
+  Process *m_process;
+};
+} // namespace lldb_private
+
+#endif // LLDB_TARGET_RUNTIME_H

diff  --git a/lldb/include/lldb/Target/SystemRuntime.h b/lldb/include/lldb/Target/SystemRuntime.h
index 4f07d7ab52e5..0ec0793e95f9 100644
--- a/lldb/include/lldb/Target/SystemRuntime.h
+++ b/lldb/include/lldb/Target/SystemRuntime.h
@@ -15,6 +15,7 @@
 #include "lldb/Core/PluginInterface.h"
 #include "lldb/Target/QueueItem.h"
 #include "lldb/Target/QueueList.h"
+#include "lldb/Target/Runtime.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/lldb-private.h"
@@ -39,7 +40,7 @@ namespace lldb_private {
 /// can be asked to provide that information.
 ///
 
-class SystemRuntime : public PluginInterface {
+class SystemRuntime : public Runtime, public PluginInterface {
 public:
   /// Find a system runtime plugin for a given process.
   ///
@@ -52,7 +53,7 @@ class SystemRuntime : public PluginInterface {
   static SystemRuntime *FindPlugin(Process *process);
 
   /// Construct with a process.
-  SystemRuntime(lldb_private::Process *process);
+  SystemRuntime(Process *process);
 
   /// Destructor.
   ///
@@ -76,7 +77,7 @@ class SystemRuntime : public PluginInterface {
   ///
   /// Allow the SystemRuntime plugin to enable logging features in the system
   /// runtime libraries.
-  virtual void ModulesDidLoad(lldb_private::ModuleList &module_list);
+  virtual void ModulesDidLoad(const ModuleList &module_list) override;
 
   /// Called before detaching from a process.
   ///
@@ -294,9 +295,6 @@ class SystemRuntime : public PluginInterface {
   }
 
 protected:
-  // Member variables.
-  Process *m_process;
-
   std::vector<ConstString> m_types;
 
 private:

diff  --git a/lldb/source/Target/LanguageRuntime.cpp b/lldb/source/Target/LanguageRuntime.cpp
index f8143839bb64..0bbb9660f741 100644
--- a/lldb/source/Target/LanguageRuntime.cpp
+++ b/lldb/source/Target/LanguageRuntime.cpp
@@ -214,7 +214,7 @@ LanguageRuntime *LanguageRuntime::FindPlugin(Process *process,
   return nullptr;
 }
 
-LanguageRuntime::LanguageRuntime(Process *process) : m_process(process) {}
+LanguageRuntime::LanguageRuntime(Process *process) : Runtime(process) {}
 
 LanguageRuntime::~LanguageRuntime() = default;
 

diff  --git a/lldb/source/Target/SystemRuntime.cpp b/lldb/source/Target/SystemRuntime.cpp
index cd3d8ba2c7b0..6d8a2ef55225 100644
--- a/lldb/source/Target/SystemRuntime.cpp
+++ b/lldb/source/Target/SystemRuntime.cpp
@@ -27,9 +27,7 @@ SystemRuntime *SystemRuntime::FindPlugin(Process *process) {
   return nullptr;
 }
 
-// SystemRuntime constructor
-SystemRuntime::SystemRuntime(Process *process)
-    : m_process(process), m_types() {}
+SystemRuntime::SystemRuntime(Process *process) : Runtime(process), m_types() {}
 
 SystemRuntime::~SystemRuntime() = default;
 
@@ -39,7 +37,7 @@ void SystemRuntime::DidLaunch() {}
 
 void SystemRuntime::Detach() {}
 
-void SystemRuntime::ModulesDidLoad(ModuleList &module_list) {}
+void SystemRuntime::ModulesDidLoad(const ModuleList &module_list) {}
 
 const std::vector<ConstString> &SystemRuntime::GetExtendedBacktraceTypes() {
   return m_types;


        


More information about the lldb-commits mailing list