[Lldb-commits] [PATCH] D40475: DWZ 10/11: DWZ test mode

2018-03-17 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil updated this revision to Diff 138813.

https://reviews.llvm.org/D40475

Files:
  packages/Python/lldbsuite/test/dotest.py
  packages/Python/lldbsuite/test/lldbinline.py
  packages/Python/lldbsuite/test/lldbtest.py
  packages/Python/lldbsuite/test/make/Makefile.rules
  packages/Python/lldbsuite/test/plugins/builder_base.py
  packages/Python/lldbsuite/test/test_categories.py
  unittests/SymbolFile/CMakeLists.txt
  unittests/SymbolFile/DWZ/CMakeLists.txt
  unittests/SymbolFile/DWZ/Inputs/dwztest.c
  unittests/SymbolFile/DWZ/Inputs/dwztest.debug
  unittests/SymbolFile/DWZ/Inputs/dwztest.debug.dwz
  unittests/SymbolFile/DWZ/Inputs/dwztest.out
  unittests/SymbolFile/DWZ/SymbolFileDWZTests.cpp

Index: unittests/SymbolFile/DWZ/SymbolFileDWZTests.cpp
===
--- /dev/null
+++ unittests/SymbolFile/DWZ/SymbolFileDWZTests.cpp
@@ -0,0 +1,89 @@
+//===-- SymbolFileDWZTests.cpp --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "TestingSupport/TestUtilities.h"
+
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/FileSpec.h"
+
+#if defined(_MSC_VER)
+#include "lldb/Host/windows/windows.h"
+#include 
+#endif
+
+#include 
+
+using namespace lldb_private;
+
+class SymbolFileDWZTests : public testing::Test {
+public:
+  void SetUp() override {
+// Initialize and TearDown the plugin every time, so we get a brand new
+// AST every time so that modifications to the AST from each test don't
+// leak into the next test.
+#if defined(_MSC_VER)
+::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
+#endif
+
+HostInfo::Initialize();
+SymbolFileDWARF::Initialize();
+ClangASTContext::Initialize();
+ObjectFileELF::Initialize();
+SymbolVendorELF::Initialize();
+
+m_dwztest_out = GetInputFilePath("dwztest.out");
+  }
+
+  void TearDown() override {
+SymbolVendorELF::Terminate();
+ObjectFileELF::Terminate();
+ClangASTContext::Terminate();
+SymbolFileDWARF::Terminate();
+HostInfo::Terminate();
+
+#if defined(_MSC_VER)
+::CoUninitialize();
+#endif
+  }
+
+protected:
+  std::string m_dwztest_out;
+};
+
+TEST_F(SymbolFileDWZTests, TestSimpleClassTypes) {
+  FileSpec fspec(m_dwztest_out.c_str(), false);
+  ArchSpec aspec("x86_64-pc-linux");
+  lldb::ModuleSP module = std::make_shared(fspec, aspec);
+
+  SymbolVendor *plugin = module->GetSymbolVendor();
+  EXPECT_NE(nullptr, plugin);
+  SymbolFile *symfile = plugin->GetSymbolFile();
+  EXPECT_NE(nullptr, symfile);
+  EXPECT_EQ(symfile->GetPluginName(), SymbolFileDWARF::GetPluginNameStatic());
+  SymbolContext sc;
+  llvm::DenseSet searched_files;
+  TypeMap results;
+  EXPECT_EQ(1u,
+  symfile->FindTypes(sc, ConstString("StructMovedToDWZCommonFile"), nullptr,
+  false, 0, searched_files, results));
+  EXPECT_EQ(1u, results.GetSize());
+  lldb::TypeSP udt_type = results.GetTypeAtIndex(0);
+  EXPECT_EQ(ConstString("StructMovedToDWZCommonFile"), udt_type->GetName());
+  CompilerType compiler_type = udt_type->GetForwardCompilerType();
+  EXPECT_TRUE(ClangASTContext::IsClassType(compiler_type.GetOpaqueQualType()));
+}
Index: unittests/SymbolFile/DWZ/Inputs/dwztest.c
===
--- /dev/null
+++ unittests/SymbolFile/DWZ/Inputs/dwztest.c
@@ -0,0 +1,9 @@
+// gcc -Wall -g -o dwztest.out dwztest.c; eu-strip --remove-comment -f dwztest.debug dwztest.out; cp -p dwztest.debug dwztest.debug.dup; dwz -m dwztest.debug.dwz dwztest.debug dwztest.debug.dup;rm dwztest.debug.dup; /usr/lib/rpm/sepdebugcrcfix . dwztest.out 
+
+struct StructMovedToDWZCommonFile {
+  int i1, i2, i3, i4, i5, i6, i7, i8, i9;
+} VarWithStructMovedToDWZCommonFile;
+static const int sizeof_StructMovedToDWZCommonFile = sizeof(struct StructMovedToDWZCommonFile);
+int main() {
+  return sizeof_StructMovedToDWZCommonFile;
+}
Index: unittests/SymbolFile/DWZ/CMakeLists.txt
===
--- /dev/null
+++ unittests/SymbolFile/DWZ/CMakeLists.txt
@@ -0,0 +1,21 @@
+add_lldb_unittest(SymbolFileDWZTests
+  SymbolFileDWZTests.cpp
+
+  LINK_LIBS
+lldbCore
+lldbHost
+lldbSymbol
+lldbPluginSymbolFileDWARF
+lldbUtilityHelpers
+lldbPluginObjectFileELF
+lldbPluginSymbolVendorELF
+  LINK_COMPONENTS
+Support
+  )
+
+set(test_inputs
+   dwztest.out
+   dwztest.debug
+   dwztest.debug

[Lldb-commits] [PATCH] D44603: [lldb] Introduce StackFrameRecognizer

2018-03-17 Thread Kuba (Brecka) Mracek via Phabricator via lldb-commits
kubamracek created this revision.
kubamracek added reviewers: jingham, jasonmolenda.
Herald added a subscriber: mgorny.

This is following on the discussion and goals of 
https://reviews.llvm.org/D43886. The patch introduces a concept of "frame 
recognizer" and "recognized frame". This should be an extensible mechanism that 
retrieves information about special frames based on ABI, arguments or other 
special properties of that frame, even without source code. A few examples 
where that could be useful could be 1) objc_exception_throw, where we'd like to 
get the current exception, 2) terminate_with_reason and extracting the current 
terminate string

This should address the comments from Jim from https://reviews.llvm.org/D43886: 
The results from the recognizer should be generic (we now return a 
ValueObjectList that represent recognized arguments), and the frame recognizers 
are extensible and we could create a Python interface for those and register 
Python-based recognizers via StackFrameRecognizerManager.


https://reviews.llvm.org/D44603

Files:
  include/lldb/Target/StackFrame.h
  include/lldb/Target/StackFrameRecognizer.h
  include/lldb/lldb-forward.h
  lldb.xcodeproj/project.pbxproj
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  
source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCStackFrameRecognizer.cpp
  
source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCStackFrameRecognizer.h
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/CMakeLists.txt
  source/Target/CMakeLists.txt
  source/Target/StackFrame.cpp
  source/Target/StackFrameRecognizer.cpp

Index: source/Target/StackFrameRecognizer.cpp
===
--- /dev/null
+++ source/Target/StackFrameRecognizer.cpp
@@ -0,0 +1,111 @@
+//===-- StackFrameRecognizer.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+// C Includes
+// C++ Includes
+#include 
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Module.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/StackFrameRecognizer.h"
+#include "lldb/Utility/RegularExpression.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+class StackFrameRecognizerManagerImpl {
+public:
+  void AddRecognizer(StackFrameRecognizerSP recognizer, ConstString &module,
+ ConstString &symbol, bool first_instruction_only) {
+m_recognizers.push_back({recognizer, module, RegularExpressionSP(), symbol,
+ RegularExpressionSP(), first_instruction_only});
+  }
+
+  void AddRecognizer(StackFrameRecognizerSP recognizer,
+ RegularExpressionSP module, RegularExpressionSP symbol,
+ bool first_instruction_only) {
+m_recognizers.push_back({recognizer, ConstString(), module, ConstString(),
+ symbol, first_instruction_only});
+  }
+
+  RecognizedStackFrameSP RecognizeFrame(StackFrameSP frame) {
+const SymbolContext &symctx =
+frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+ConstString function_name = symctx.GetFunctionName();
+ConstString module_name = symctx.module_sp->GetFileSpec().GetFilename();
+Address start_addr = symctx.symbol->GetAddress();
+Address current_addr = frame->GetFrameCodeAddress();
+
+for (auto entry : m_recognizers) {
+  if (entry.module)
+if (entry.module != module_name)
+  continue;
+
+  if (entry.module_regexp)
+if (!entry.module_regexp->Execute(module_name.GetStringRef()))
+  continue;
+
+  if (entry.symbol)
+if (entry.symbol != function_name)
+  continue;
+
+  if (entry.symbol_regexp)
+if (!entry.symbol_regexp->Execute(function_name.GetStringRef()))
+  continue;
+
+  if (entry.first_instruction_only)
+if (start_addr != current_addr)
+  continue;
+
+  auto recognized_frame = entry.recognizer->RecognizeFrame(frame);
+  if (recognized_frame)
+return recognized_frame;
+}
+return RecognizedStackFrameSP();
+  }
+
+private:
+  struct RegisteredEntry {
+StackFrameRecognizerSP recognizer;
+ConstString module;
+RegularExpressionSP module_regexp;
+ConstString symbol;
+RegularExpressionSP symbol_regexp;
+bool first_instruction_only;
+  };
+
+  std::vector m_recognizers;
+};
+
+StackFrameRecognizerManagerImpl &GetStackFrameRecognizerManagerImpl() {
+  static StackFrameRecognizerManagerImpl instance =
+  StackFrameRecognizerManagerImpl();
+  return instance;
+}
+
+void StackFrameRecognizerManager::AddRecognizer(
+StackFrameRecogniz

[Lldb-commits] [PATCH] D43886: [lldb] Add GetCurrentException and GetCurrentExceptionBacktrace APIs to SBThread

2018-03-17 Thread Kuba (Brecka) Mracek via Phabricator via lldb-commits
kubamracek added a comment.

Hi, I've moved the part that introduces the frame recognizers to 
https://reviews.llvm.org/D44603.


https://reviews.llvm.org/D43886



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits