[Lldb-commits] [lldb] r319504 - Add lldb-test.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 30 16:52:52 PST 2017


Author: zturner
Date: Thu Nov 30 16:52:51 2017
New Revision: 319504

URL: http://llvm.org/viewvc/llvm-project?rev=319504&view=rev
Log:
Add lldb-test.

This is basically a proof-of-concept and starting point for having a
testing-centric tool in LLDB.  I'm sure this leaves a lot of room to be
desired, but this at least allows us to have something to build on.

Right now there is only one command, the `module-sections` command, and I
created this command not because it was particularly special, but
because it addressed an immediate use case and was extremely simple.

Run the tool as `lldb-test module-sections <path-to-object>`.

Feel free to add testing related stuff to your heart's content after
this goes in.  Implementing the commands themselves takes some work, but
once they're there they can be reused without writing any code and
result in very easy to use and maintain tests.

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

Added:
    lldb/trunk/tools/lldb-test/
    lldb/trunk/tools/lldb-test/CMakeLists.txt
    lldb/trunk/tools/lldb-test/FormatUtil.cpp
    lldb/trunk/tools/lldb-test/FormatUtil.h
    lldb/trunk/tools/lldb-test/SystemInitializerTest.cpp
    lldb/trunk/tools/lldb-test/SystemInitializerTest.h
    lldb/trunk/tools/lldb-test/lldb-test.cpp
Modified:
    lldb/trunk/tools/CMakeLists.txt

Modified: lldb/trunk/tools/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/CMakeLists.txt?rev=319504&r1=319503&r2=319504&view=diff
==============================================================================
--- lldb/trunk/tools/CMakeLists.txt (original)
+++ lldb/trunk/tools/CMakeLists.txt Thu Nov 30 16:52:51 2017
@@ -9,3 +9,4 @@ if (LLDB_CAN_USE_LLDB_SERVER)
   add_subdirectory(lldb-server)
 endif()
 add_subdirectory(intel-features)
+add_subdirectory(lldb-test)

Added: lldb/trunk/tools/lldb-test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/CMakeLists.txt?rev=319504&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-test/CMakeLists.txt (added)
+++ lldb/trunk/tools/lldb-test/CMakeLists.txt Thu Nov 30 16:52:51 2017
@@ -0,0 +1,27 @@
+get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
+
+add_lldb_tool(lldb-test
+  FormatUtil.cpp
+  lldb-test.cpp
+  SystemInitializerTest.cpp
+
+  LINK_LIBS
+    lldbBase
+    lldbBreakpoint
+    lldbCore
+    lldbDataFormatters
+    lldbExpression
+    lldbHost
+    lldbInitialization
+    lldbInterpreter
+    lldbSymbol
+    lldbTarget
+    lldbUtility
+    ${LLDB_ALL_PLUGINS}
+    ${host_lib}
+
+  LINK_COMPONENTS
+    Support
+  )
+  
+include_directories(${LLDB_SOURCE_DIR}/source)

Added: lldb/trunk/tools/lldb-test/FormatUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/FormatUtil.cpp?rev=319504&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-test/FormatUtil.cpp (added)
+++ lldb/trunk/tools/lldb-test/FormatUtil.cpp Thu Nov 30 16:52:51 2017
@@ -0,0 +1,69 @@
+//===- FormatUtil.cpp ----------------------------------------- *- C++ --*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "FormatUtil.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/FormatVariadic.h"
+
+using namespace lldb_private;
+using namespace llvm;
+
+LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
+    : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {}
+
+void LinePrinter::Indent(uint32_t Amount) {
+  if (Amount == 0)
+    Amount = IndentSpaces;
+  CurrentIndent += Amount;
+}
+
+void LinePrinter::Unindent(uint32_t Amount) {
+  if (Amount == 0)
+    Amount = IndentSpaces;
+  CurrentIndent = std::max<int>(0, CurrentIndent - Amount);
+}
+
+void LinePrinter::NewLine() {
+  OS << "\n";
+  OS.indent(CurrentIndent);
+}
+
+void LinePrinter::print(const Twine &T) { OS << T; }
+
+void LinePrinter::printLine(const Twine &T) {
+  NewLine();
+  OS << T;
+}
+
+void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
+                               uint32_t StartOffset) {
+  NewLine();
+  OS << Label << " (";
+  if (!Data.empty()) {
+    OS << "\n";
+    OS << format_bytes_with_ascii(Data, StartOffset, 32, 4,
+                                  CurrentIndent + IndentSpaces, true);
+    NewLine();
+  }
+  OS << ")";
+}
+
+void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
+                               uint64_t Base, uint32_t StartOffset) {
+  NewLine();
+  OS << Label << " (";
+  if (!Data.empty()) {
+    OS << "\n";
+    Base += StartOffset;
+    OS << format_bytes_with_ascii(Data, Base, 32, 4,
+                                  CurrentIndent + IndentSpaces, true);
+    NewLine();
+  }
+  OS << ")";
+}

Added: lldb/trunk/tools/lldb-test/FormatUtil.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/FormatUtil.h?rev=319504&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-test/FormatUtil.h (added)
+++ lldb/trunk/tools/lldb-test/FormatUtil.h Thu Nov 30 16:52:51 2017
@@ -0,0 +1,75 @@
+//===- FormatUtil.h ------------------------------------------- *- C++ --*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLDBTEST_FORMATUTIL_H
+#define LLVM_TOOLS_LLDBTEST_FORMATUTIL_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <list>
+
+namespace lldb_private {
+
+class LinePrinter {
+  llvm::raw_ostream &OS;
+  int IndentSpaces;
+  int CurrentIndent;
+
+public:
+  LinePrinter(int Indent, llvm::raw_ostream &Stream);
+
+  void Indent(uint32_t Amount = 0);
+  void Unindent(uint32_t Amount = 0);
+  void NewLine();
+
+  void printLine(const llvm::Twine &T);
+  void print(const llvm::Twine &T);
+  template <typename... Ts> void formatLine(const char *Fmt, Ts &&... Items) {
+    printLine(llvm::formatv(Fmt, std::forward<Ts>(Items)...));
+  }
+  template <typename... Ts> void format(const char *Fmt, Ts &&... Items) {
+    print(llvm::formatv(Fmt, std::forward<Ts>(Items)...));
+  }
+
+  void formatBinary(llvm::StringRef Label, llvm::ArrayRef<uint8_t> Data,
+                    uint32_t StartOffset);
+  void formatBinary(llvm::StringRef Label, llvm::ArrayRef<uint8_t> Data,
+                    uint64_t BaseAddr, uint32_t StartOffset);
+
+  llvm::raw_ostream &getStream() { return OS; }
+  int getIndentLevel() const { return CurrentIndent; }
+};
+
+struct AutoIndent {
+  explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
+      : L(&L), Amount(Amount) {
+    L.Indent(Amount);
+  }
+  ~AutoIndent() {
+    if (L)
+      L->Unindent(Amount);
+  }
+
+  LinePrinter *L = nullptr;
+  uint32_t Amount = 0;
+};
+
+template <class T>
+inline llvm::raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
+  Printer.getStream() << Item;
+  return Printer.getStream();
+}
+
+} // namespace lldb_private
+
+#endif

Added: lldb/trunk/tools/lldb-test/SystemInitializerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/SystemInitializerTest.cpp?rev=319504&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-test/SystemInitializerTest.cpp (added)
+++ lldb/trunk/tools/lldb-test/SystemInitializerTest.cpp Thu Nov 30 16:52:51 2017
@@ -0,0 +1,345 @@
+//===-- SystemInitializerTest.cpp -------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "SystemInitializerTest.h"
+
+#include "lldb/Core/Debugger.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Initialization/SystemInitializerCommon.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/GoASTContext.h"
+#include "lldb/Symbol/JavaASTContext.h"
+#include "lldb/Symbol/OCamlASTContext.h"
+#include "lldb/Utility/Timer.h"
+
+#include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h"
+#include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h"
+#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
+#include "Plugins/ABI/SysV-arm/ABISysV_arm.h"
+#include "Plugins/ABI/SysV-arm64/ABISysV_arm64.h"
+#include "Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h"
+#include "Plugins/ABI/SysV-i386/ABISysV_i386.h"
+#include "Plugins/ABI/SysV-mips/ABISysV_mips.h"
+#include "Plugins/ABI/SysV-mips64/ABISysV_mips64.h"
+#include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h"
+#include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h"
+#include "Plugins/ABI/SysV-s390x/ABISysV_s390x.h"
+#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
+#include "Plugins/Architecture/Arm/ArchitectureArm.h"
+#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
+#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h"
+#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
+#include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
+#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
+#include "Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h"
+#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
+#include "Plugins/InstrumentationRuntime/ASan/ASanRuntime.h"
+#include "Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.h"
+#include "Plugins/InstrumentationRuntime/TSan/TSanRuntime.h"
+#include "Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.h"
+#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
+#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
+#include "Plugins/Language/Go/GoLanguage.h"
+#include "Plugins/Language/Java/JavaLanguage.h"
+#include "Plugins/Language/OCaml/OCamlLanguage.h"
+#include "Plugins/Language/ObjC/ObjCLanguage.h"
+#include "Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h"
+#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
+#include "Plugins/LanguageRuntime/Go/GoLanguageRuntime.h"
+#include "Plugins/LanguageRuntime/Java/JavaLanguageRuntime.h"
+#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h"
+#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
+#include "Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h"
+#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
+#include "Plugins/OperatingSystem/Go/OperatingSystemGo.h"
+#include "Plugins/Platform/Android/PlatformAndroid.h"
+#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
+#include "Plugins/Platform/Kalimba/PlatformKalimba.h"
+#include "Plugins/Platform/Linux/PlatformLinux.h"
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
+#include "Plugins/Platform/NetBSD/PlatformNetBSD.h"
+#include "Plugins/Platform/OpenBSD/PlatformOpenBSD.h"
+#include "Plugins/Platform/Windows/PlatformWindows.h"
+#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
+#include "Plugins/Process/elf-core/ProcessElfCore.h"
+#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
+#include "Plugins/Process/minidump/ProcessMinidump.h"
+#include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h"
+#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
+#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
+#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
+#include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h"
+#include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
+#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
+
+#if defined(__APPLE__)
+#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
+#include "Plugins/Platform/MacOSX/PlatformAppleTVSimulator.h"
+#include "Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.h"
+#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h"
+#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h"
+#include "Plugins/Process/MacOSX-Kernel/ProcessKDP.h"
+#include "Plugins/Process/mach-core/ProcessMachCore.h"
+#include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
+#endif
+#include "Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h"
+
+#if defined(__FreeBSD__)
+#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
+#endif
+
+#if defined(_WIN32)
+#include "Plugins/Process/Windows/Common/ProcessWindows.h"
+#include "lldb/Host/windows/windows.h"
+#endif
+
+#include "llvm/Support/TargetSelect.h"
+
+#include <string>
+
+using namespace lldb_private;
+
+SystemInitializerTest::SystemInitializerTest() {}
+
+SystemInitializerTest::~SystemInitializerTest() {}
+
+void SystemInitializerTest::Initialize() {
+  SystemInitializerCommon::Initialize();
+  ScriptInterpreterNone::Initialize();
+
+  OperatingSystemGo::Initialize();
+
+  platform_freebsd::PlatformFreeBSD::Initialize();
+  platform_linux::PlatformLinux::Initialize();
+  platform_netbsd::PlatformNetBSD::Initialize();
+  platform_openbsd::PlatformOpenBSD::Initialize();
+  PlatformWindows::Initialize();
+  PlatformKalimba::Initialize();
+  platform_android::PlatformAndroid::Initialize();
+  PlatformRemoteiOS::Initialize();
+  PlatformMacOSX::Initialize();
+#if defined(__APPLE__)
+  PlatformiOSSimulator::Initialize();
+  PlatformDarwinKernel::Initialize();
+#endif
+
+  // Initialize LLVM and Clang
+  llvm::InitializeAllTargets();
+  llvm::InitializeAllAsmPrinters();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllDisassemblers();
+
+  ClangASTContext::Initialize();
+  GoASTContext::Initialize();
+  JavaASTContext::Initialize();
+  OCamlASTContext::Initialize();
+
+  ABIMacOSX_i386::Initialize();
+  ABIMacOSX_arm::Initialize();
+  ABIMacOSX_arm64::Initialize();
+  ABISysV_arm::Initialize();
+  ABISysV_arm64::Initialize();
+  ABISysV_hexagon::Initialize();
+  ABISysV_i386::Initialize();
+  ABISysV_x86_64::Initialize();
+  ABISysV_ppc::Initialize();
+  ABISysV_ppc64::Initialize();
+  ABISysV_mips::Initialize();
+  ABISysV_mips64::Initialize();
+  ABISysV_s390x::Initialize();
+
+  ArchitectureArm::Initialize();
+
+  DisassemblerLLVMC::Initialize();
+
+  JITLoaderGDB::Initialize();
+  ProcessElfCore::Initialize();
+  minidump::ProcessMinidump::Initialize();
+  MemoryHistoryASan::Initialize();
+  AddressSanitizerRuntime::Initialize();
+  ThreadSanitizerRuntime::Initialize();
+  UndefinedBehaviorSanitizerRuntime::Initialize();
+  MainThreadCheckerRuntime::Initialize();
+
+  SymbolVendorELF::Initialize();
+  SymbolFileDWARF::Initialize();
+  SymbolFilePDB::Initialize();
+  SymbolFileSymtab::Initialize();
+  UnwindAssemblyInstEmulation::Initialize();
+  UnwindAssembly_x86::Initialize();
+  EmulateInstructionARM64::Initialize();
+  SymbolFileDWARFDebugMap::Initialize();
+  ItaniumABILanguageRuntime::Initialize();
+  AppleObjCRuntimeV2::Initialize();
+  AppleObjCRuntimeV1::Initialize();
+  SystemRuntimeMacOSX::Initialize();
+  RenderScriptRuntime::Initialize();
+  GoLanguageRuntime::Initialize();
+  JavaLanguageRuntime::Initialize();
+
+  CPlusPlusLanguage::Initialize();
+  GoLanguage::Initialize();
+  JavaLanguage::Initialize();
+  ObjCLanguage::Initialize();
+  ObjCPlusPlusLanguage::Initialize();
+  OCamlLanguage::Initialize();
+
+#if defined(_WIN32)
+  ProcessWindows::Initialize();
+#endif
+#if defined(__FreeBSD__)
+  ProcessFreeBSD::Initialize();
+#endif
+#if defined(__APPLE__)
+  SymbolVendorMacOSX::Initialize();
+  ProcessKDP::Initialize();
+  ProcessMachCore::Initialize();
+  PlatformAppleTVSimulator::Initialize();
+  PlatformAppleWatchSimulator::Initialize();
+  PlatformRemoteAppleTV::Initialize();
+  PlatformRemoteAppleWatch::Initialize();
+  DynamicLoaderDarwinKernel::Initialize();
+#endif
+
+  // This plugin is valid on any host that talks to a Darwin remote.
+  // It shouldn't be limited to __APPLE__.
+  StructuredDataDarwinLog::Initialize();
+
+  //----------------------------------------------------------------------
+  // Platform agnostic plugins
+  //----------------------------------------------------------------------
+  platform_gdb_server::PlatformRemoteGDBServer::Initialize();
+
+  process_gdb_remote::ProcessGDBRemote::Initialize();
+  DynamicLoaderMacOSXDYLD::Initialize();
+  DynamicLoaderMacOS::Initialize();
+  DynamicLoaderPOSIXDYLD::Initialize();
+  DynamicLoaderStatic::Initialize();
+  DynamicLoaderWindowsDYLD::Initialize();
+
+  // Scan for any system or user LLDB plug-ins
+  PluginManager::Initialize();
+
+  // The process settings need to know about installed plug-ins, so the Settings
+  // must be initialized
+  // AFTER PluginManager::Initialize is called.
+
+  Debugger::SettingsInitialize();
+}
+
+void SystemInitializerTest::Terminate() {
+  static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
+  Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
+
+  Debugger::SettingsTerminate();
+
+  // Terminate and unload and loaded system or user LLDB plug-ins
+  PluginManager::Terminate();
+
+  ClangASTContext::Terminate();
+  GoASTContext::Terminate();
+  JavaASTContext::Terminate();
+  OCamlASTContext::Terminate();
+
+  ABIMacOSX_i386::Terminate();
+  ABIMacOSX_arm::Terminate();
+  ABIMacOSX_arm64::Terminate();
+  ABISysV_arm::Terminate();
+  ABISysV_arm64::Terminate();
+  ABISysV_hexagon::Terminate();
+  ABISysV_i386::Terminate();
+  ABISysV_x86_64::Terminate();
+  ABISysV_ppc::Terminate();
+  ABISysV_ppc64::Terminate();
+  ABISysV_mips::Terminate();
+  ABISysV_mips64::Terminate();
+  ABISysV_s390x::Terminate();
+  DisassemblerLLVMC::Terminate();
+
+  JITLoaderGDB::Terminate();
+  ProcessElfCore::Terminate();
+  minidump::ProcessMinidump::Terminate();
+  MemoryHistoryASan::Terminate();
+  AddressSanitizerRuntime::Terminate();
+  ThreadSanitizerRuntime::Terminate();
+  UndefinedBehaviorSanitizerRuntime::Terminate();
+  MainThreadCheckerRuntime::Terminate();
+  SymbolVendorELF::Terminate();
+  SymbolFileDWARF::Terminate();
+  SymbolFilePDB::Terminate();
+  SymbolFileSymtab::Terminate();
+  UnwindAssembly_x86::Terminate();
+  UnwindAssemblyInstEmulation::Terminate();
+  EmulateInstructionARM64::Terminate();
+  SymbolFileDWARFDebugMap::Terminate();
+  ItaniumABILanguageRuntime::Terminate();
+  AppleObjCRuntimeV2::Terminate();
+  AppleObjCRuntimeV1::Terminate();
+  SystemRuntimeMacOSX::Terminate();
+  RenderScriptRuntime::Terminate();
+  JavaLanguageRuntime::Terminate();
+
+  CPlusPlusLanguage::Terminate();
+  GoLanguage::Terminate();
+  JavaLanguage::Terminate();
+  ObjCLanguage::Terminate();
+  ObjCPlusPlusLanguage::Terminate();
+  OCamlLanguage::Terminate();
+
+#if defined(__APPLE__)
+  DynamicLoaderDarwinKernel::Terminate();
+  ProcessMachCore::Terminate();
+  ProcessKDP::Terminate();
+  SymbolVendorMacOSX::Terminate();
+  PlatformAppleTVSimulator::Terminate();
+  PlatformAppleWatchSimulator::Terminate();
+  PlatformRemoteAppleTV::Terminate();
+  PlatformRemoteAppleWatch::Terminate();
+#endif
+
+#if defined(__FreeBSD__)
+  ProcessFreeBSD::Terminate();
+#endif
+  Debugger::SettingsTerminate();
+
+  platform_gdb_server::PlatformRemoteGDBServer::Terminate();
+  process_gdb_remote::ProcessGDBRemote::Terminate();
+  StructuredDataDarwinLog::Terminate();
+
+  DynamicLoaderMacOSXDYLD::Terminate();
+  DynamicLoaderMacOS::Terminate();
+  DynamicLoaderPOSIXDYLD::Terminate();
+  DynamicLoaderStatic::Terminate();
+  DynamicLoaderWindowsDYLD::Terminate();
+
+  OperatingSystemGo::Terminate();
+
+  platform_freebsd::PlatformFreeBSD::Terminate();
+  platform_linux::PlatformLinux::Terminate();
+  platform_netbsd::PlatformNetBSD::Terminate();
+  platform_openbsd::PlatformOpenBSD::Terminate();
+  PlatformWindows::Terminate();
+  PlatformKalimba::Terminate();
+  platform_android::PlatformAndroid::Terminate();
+  PlatformMacOSX::Terminate();
+  PlatformRemoteiOS::Terminate();
+#if defined(__APPLE__)
+  PlatformiOSSimulator::Terminate();
+  PlatformDarwinKernel::Terminate();
+#endif
+
+  // Now shutdown the common parts, in reverse order.
+  SystemInitializerCommon::Terminate();
+}

Added: lldb/trunk/tools/lldb-test/SystemInitializerTest.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/SystemInitializerTest.h?rev=319504&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-test/SystemInitializerTest.h (added)
+++ lldb/trunk/tools/lldb-test/SystemInitializerTest.h Thu Nov 30 16:52:51 2017
@@ -0,0 +1,35 @@
+//===-- SystemInitializerTest.h ---------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_API_SYSTEM_INITIALIZER_TEST_H
+#define LLDB_API_SYSTEM_INITIALIZER_TEST_H
+
+#include "lldb/Initialization/SystemInitializerCommon.h"
+
+namespace lldb_private {
+//------------------------------------------------------------------
+/// Initializes lldb.
+///
+/// This class is responsible for initializing all of lldb system
+/// services needed to use the full LLDB application.  This class is
+/// not intended to be used externally, but is instead used
+/// internally by SBDebugger to initialize the system.
+//------------------------------------------------------------------
+class SystemInitializerTest : public SystemInitializerCommon {
+public:
+  SystemInitializerTest();
+  ~SystemInitializerTest() override;
+
+  void Initialize() override;
+  void Terminate() override;
+};
+
+} // namespace lldb_private
+
+#endif // LLDB_API_SYSTEM_INITIALIZER_FULL_H

Added: lldb/trunk/tools/lldb-test/lldb-test.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/lldb-test.cpp?rev=319504&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-test/lldb-test.cpp (added)
+++ lldb/trunk/tools/lldb-test/lldb-test.cpp Thu Nov 30 16:52:51 2017
@@ -0,0 +1,98 @@
+//===- lldb-test.cpp ------------------------------------------ *- C++ --*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "FormatUtil.h"
+#include "SystemInitializerTest.h"
+
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Initialization/SystemLifetimeManager.h"
+#include "lldb/Utility/DataExtractor.h"
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Signals.h"
+#include <thread>
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace llvm;
+
+namespace opts {
+cl::SubCommand ModuleSubcommand("module-sections",
+                                "Display LLDB Module Information");
+
+namespace module {
+cl::opt<bool> SectionContents("contents",
+                              cl::desc("Dump each section's contents"),
+                              cl::sub(ModuleSubcommand));
+cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input files>"),
+                                     cl::OneOrMore, cl::sub(ModuleSubcommand));
+} // namespace module
+} // namespace opts
+
+static llvm::ManagedStatic<SystemLifetimeManager> DebuggerLifetime;
+
+static void dumpModules(Debugger &Dbg) {
+  LinePrinter Printer(4, llvm::outs());
+
+  for (const auto &File : opts::module::InputFilenames) {
+    ModuleSpec Spec{FileSpec(File, false)};
+    Spec.GetSymbolFileSpec().SetFile(File, false);
+
+    auto ModulePtr = std::make_shared<Module>(Spec);
+    SectionList *Sections = ModulePtr->GetSectionList();
+    if (!Sections) {
+      llvm::errs() << "Could not load sections for module " << File << "\n";
+      continue;
+    }
+
+    size_t Count = Sections->GetNumSections(0);
+    Printer.formatLine("Showing {0} sections", Count);
+    for (size_t I = 0; I < Count; ++I) {
+      AutoIndent Indent(Printer, 2);
+      auto S = Sections->GetSectionAtIndex(I);
+      assert(S);
+      Printer.formatLine("Index: {0}", I);
+      Printer.formatLine("Name: {0}", S->GetName().GetStringRef());
+      Printer.formatLine("Length: {0}", S->GetByteSize());
+
+      if (opts::module::SectionContents) {
+        DataExtractor Data;
+        S->GetSectionData(Data);
+        ArrayRef<uint8_t> Bytes = {Data.GetDataStart(), Data.GetDataEnd()};
+        Printer.formatBinary("Data: ", Bytes, 0);
+      }
+      Printer.NewLine();
+    }
+  }
+}
+
+int main(int argc, const char *argv[]) {
+  StringRef ToolName = argv[0];
+  sys::PrintStackTraceOnErrorSignal(ToolName);
+  PrettyStackTraceProgram X(argc, argv);
+  llvm_shutdown_obj Y;
+
+  cl::ParseCommandLineOptions(argc, argv, "LLDB Testing Utility\n");
+
+  DebuggerLifetime->Initialize(llvm::make_unique<SystemInitializerTest>(),
+                               nullptr);
+
+  auto Dbg = lldb_private::Debugger::CreateInstance();
+
+  if (opts::ModuleSubcommand)
+    dumpModules(*Dbg);
+
+  DebuggerLifetime->Terminate();
+  return 0;
+}




More information about the lldb-commits mailing list