Commit fc1e8551 authored by Jonas Devlieghere's avatar Jonas Devlieghere
Browse files

[lldb/Plugin] Rename MainThreadCheckerRuntime for consistency with plugin (NFC)

Renames MainThreadCheckerRuntime to
InstrumentationRuntimeMainThreadChecker to be consistent with the
directory structure and plugin name.
parent 623c3c4c
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@
#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
#include "Plugins/Instruction/PPC64/EmulateInstructionPPC64.h"
#include "Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.h"
#include "Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.h"
#include "Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.h"
#include "Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.h"
#include "Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.h"
#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
@@ -225,7 +225,7 @@ llvm::Error SystemInitializerFull::Initialize() {
  InstrumentationRuntimeASan::Initialize();
  InstrumentationRuntimeTSan::Initialize();
  InstrumentationRuntimeUBSan::Initialize();
  MainThreadCheckerRuntime::Initialize();
  InstrumentationRuntimeMainThreadChecker::Initialize();

  SymbolVendorELF::Initialize();
  breakpad::SymbolFileBreakpad::Initialize();
@@ -319,7 +319,8 @@ void SystemInitializerFull::Terminate() {
  InstrumentationRuntimeASan::Terminate();
  InstrumentationRuntimeTSan::Terminate();
  InstrumentationRuntimeUBSan::Terminate();
  MainThreadCheckerRuntime::Terminate();
  InstrumentationRuntimeMainThreadChecker::Terminate();

  wasm::SymbolVendorWasm::Terminate();
  SymbolVendorELF::Terminate();
  breakpad::SymbolFileBreakpad::Terminate();
+1 −1
Original line number Diff line number Diff line
add_lldb_library(lldbPluginInstrumentationRuntimeMainThreadChecker PLUGIN
  MainThreadCheckerRuntime.cpp
  InstrumentationRuntimeMainThreadChecker.cpp

  LINK_LIBS
    lldbBreakpoint
+34 −27
Original line number Diff line number Diff line
//===-- MainThreadCheckerRuntime.cpp ----------------------------*- C++ -*-===//
//===-- InstrumentationRuntimeMainThreadChecker.cpp -------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,9 @@
//
//===----------------------------------------------------------------------===//

#include "MainThreadCheckerRuntime.h"
#include "InstrumentationRuntimeMainThreadChecker.h"

#include "Plugins/Process/Utility/HistoryThread.h"
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
@@ -22,47 +23,52 @@
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/RegularExpression.h"
#include "Plugins/Process/Utility/HistoryThread.h"

#include <memory>

using namespace lldb;
using namespace lldb_private;

MainThreadCheckerRuntime::~MainThreadCheckerRuntime() {
InstrumentationRuntimeMainThreadChecker::
    ~InstrumentationRuntimeMainThreadChecker() {
  Deactivate();
}

lldb::InstrumentationRuntimeSP
MainThreadCheckerRuntime::CreateInstance(const lldb::ProcessSP &process_sp) {
  return InstrumentationRuntimeSP(new MainThreadCheckerRuntime(process_sp));
InstrumentationRuntimeMainThreadChecker::CreateInstance(
    const lldb::ProcessSP &process_sp) {
  return InstrumentationRuntimeSP(
      new InstrumentationRuntimeMainThreadChecker(process_sp));
}

void MainThreadCheckerRuntime::Initialize() {
void InstrumentationRuntimeMainThreadChecker::Initialize() {
  PluginManager::RegisterPlugin(
      GetPluginNameStatic(), "MainThreadChecker instrumentation runtime plugin.",
      CreateInstance, GetTypeStatic);
      GetPluginNameStatic(),
      "MainThreadChecker instrumentation runtime plugin.", CreateInstance,
      GetTypeStatic);
}

void MainThreadCheckerRuntime::Terminate() {
void InstrumentationRuntimeMainThreadChecker::Terminate() {
  PluginManager::UnregisterPlugin(CreateInstance);
}

lldb_private::ConstString MainThreadCheckerRuntime::GetPluginNameStatic() {
lldb_private::ConstString
InstrumentationRuntimeMainThreadChecker::GetPluginNameStatic() {
  return ConstString("MainThreadChecker");
}

lldb::InstrumentationRuntimeType MainThreadCheckerRuntime::GetTypeStatic() {
lldb::InstrumentationRuntimeType
InstrumentationRuntimeMainThreadChecker::GetTypeStatic() {
  return eInstrumentationRuntimeTypeMainThreadChecker;
}

const RegularExpression &
MainThreadCheckerRuntime::GetPatternForRuntimeLibrary() {
InstrumentationRuntimeMainThreadChecker::GetPatternForRuntimeLibrary() {
  static RegularExpression regex(llvm::StringRef("libMainThreadChecker.dylib"));
  return regex;
}

bool MainThreadCheckerRuntime::CheckIfRuntimeIsValid(
bool InstrumentationRuntimeMainThreadChecker::CheckIfRuntimeIsValid(
    const lldb::ModuleSP module_sp) {
  static ConstString test_sym("__main_thread_checker_on_report");
  const Symbol *symbol =
@@ -71,7 +77,8 @@ bool MainThreadCheckerRuntime::CheckIfRuntimeIsValid(
}

StructuredData::ObjectSP
MainThreadCheckerRuntime::RetrieveReportData(ExecutionContextRef exe_ctx_ref) {
InstrumentationRuntimeMainThreadChecker::RetrieveReportData(
    ExecutionContextRef exe_ctx_ref) {
  ProcessSP process_sp = GetProcessSP();
  if (!process_sp)
    return StructuredData::ObjectSP();
@@ -148,15 +155,15 @@ MainThreadCheckerRuntime::RetrieveReportData(ExecutionContextRef exe_ctx_ref) {
  return dict_sp;
}

bool MainThreadCheckerRuntime::NotifyBreakpointHit(
bool InstrumentationRuntimeMainThreadChecker::NotifyBreakpointHit(
    void *baton, StoppointCallbackContext *context, user_id_t break_id,
    user_id_t break_loc_id) {
  assert(baton && "null baton");
  if (!baton)
    return false; ///< false => resume execution.

  MainThreadCheckerRuntime *const instance =
      static_cast<MainThreadCheckerRuntime *>(baton);
  InstrumentationRuntimeMainThreadChecker *const instance =
      static_cast<InstrumentationRuntimeMainThreadChecker *>(baton);

  ProcessSP process_sp = instance->GetProcessSP();
  ThreadSP thread_sp = context->exe_ctx_ref.GetThreadSP();
@@ -184,7 +191,7 @@ bool MainThreadCheckerRuntime::NotifyBreakpointHit(
  return false;
}

void MainThreadCheckerRuntime::Activate() {
void InstrumentationRuntimeMainThreadChecker::Activate() {
  if (IsActive())
    return;

@@ -215,15 +222,15 @@ void MainThreadCheckerRuntime::Activate() {
          .CreateBreakpoint(symbol_address, /*internal=*/true,
                            /*hardware=*/false)
          .get();
  breakpoint->SetCallback(MainThreadCheckerRuntime::NotifyBreakpointHit, this,
                          true);
  breakpoint->SetCallback(
      InstrumentationRuntimeMainThreadChecker::NotifyBreakpointHit, this, true);
  breakpoint->SetBreakpointKind("main-thread-checker-report");
  SetBreakpointID(breakpoint->GetID());

  SetActive(true);
}

void MainThreadCheckerRuntime::Deactivate() {
void InstrumentationRuntimeMainThreadChecker::Deactivate() {
  SetActive(false);

  auto BID = GetBreakpointID();
@@ -237,7 +244,7 @@ void MainThreadCheckerRuntime::Deactivate() {
}

lldb::ThreadCollectionSP
MainThreadCheckerRuntime::GetBacktracesFromExtendedStopInfo(
InstrumentationRuntimeMainThreadChecker::GetBacktracesFromExtendedStopInfo(
    StructuredData::ObjectSP info) {
  ThreadCollectionSP threads;
  threads = std::make_shared<ThreadCollection>();
+68 −0
Original line number Diff line number Diff line
//===-- InstrumentationRuntimeMainThreadChecker.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 liblldb_MainThreadCheckerRuntime_h_
#define liblldb_MainThreadCheckerRuntime_h_

#include "lldb/Target/ABI.h"
#include "lldb/Target/InstrumentationRuntime.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/lldb-private.h"

namespace lldb_private {

class InstrumentationRuntimeMainThreadChecker
    : public lldb_private::InstrumentationRuntime {
public:
  ~InstrumentationRuntimeMainThreadChecker() override;

  static lldb::InstrumentationRuntimeSP
  CreateInstance(const lldb::ProcessSP &process_sp);

  static void Initialize();

  static void Terminate();

  static lldb_private::ConstString GetPluginNameStatic();

  static lldb::InstrumentationRuntimeType GetTypeStatic();

  lldb_private::ConstString GetPluginName() override {
    return GetPluginNameStatic();
  }

  virtual lldb::InstrumentationRuntimeType GetType() { return GetTypeStatic(); }

  uint32_t GetPluginVersion() override { return 1; }

  lldb::ThreadCollectionSP
  GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) override;

private:
  InstrumentationRuntimeMainThreadChecker(const lldb::ProcessSP &process_sp)
      : lldb_private::InstrumentationRuntime(process_sp) {}

  const RegularExpression &GetPatternForRuntimeLibrary() override;

  bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) override;

  void Activate() override;

  void Deactivate();

  static bool NotifyBreakpointHit(void *baton,
                                  StoppointCallbackContext *context,
                                  lldb::user_id_t break_id,
                                  lldb::user_id_t break_loc_id);

  StructuredData::ObjectSP RetrieveReportData(ExecutionContextRef exe_ctx_ref);
};

} // namespace lldb_private

#endif // liblldb_MainThreadCheckerRuntime_h_
+0 −67
Original line number Diff line number Diff line
//===-- MainThreadCheckerRuntime.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 liblldb_MainThreadCheckerRuntime_h_
#define liblldb_MainThreadCheckerRuntime_h_

#include "lldb/Target/ABI.h"
#include "lldb/Target/InstrumentationRuntime.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/lldb-private.h"

namespace lldb_private {
  
  class MainThreadCheckerRuntime : public lldb_private::InstrumentationRuntime {
  public:
    ~MainThreadCheckerRuntime() override;
    
    static lldb::InstrumentationRuntimeSP
    CreateInstance(const lldb::ProcessSP &process_sp);
    
    static void Initialize();
    
    static void Terminate();
    
    static lldb_private::ConstString GetPluginNameStatic();
    
    static lldb::InstrumentationRuntimeType GetTypeStatic();
    
    lldb_private::ConstString GetPluginName() override {
      return GetPluginNameStatic();
    }
    
    virtual lldb::InstrumentationRuntimeType GetType() { return GetTypeStatic(); }
    
    uint32_t GetPluginVersion() override { return 1; }
    
    lldb::ThreadCollectionSP
    GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) override;
    
  private:
    MainThreadCheckerRuntime(const lldb::ProcessSP &process_sp)
    : lldb_private::InstrumentationRuntime(process_sp) {}
    
    const RegularExpression &GetPatternForRuntimeLibrary() override;
    
    bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) override;
    
    void Activate() override;
    
    void Deactivate();
    
    static bool NotifyBreakpointHit(void *baton,
                                    StoppointCallbackContext *context,
                                    lldb::user_id_t break_id,
                                    lldb::user_id_t break_loc_id);
    
    StructuredData::ObjectSP RetrieveReportData(ExecutionContextRef exe_ctx_ref);
  };
  
} // namespace lldb_private

#endif // liblldb_MainThreadCheckerRuntime_h_
Loading