[Lldb-commits] [PATCH] D74903: [lldb][test] Add two wrapper functions to manage settings in test-suite

2020-02-21 Thread Tatyana Krasnukha via Phabricator via lldb-commits
tatyana-krasnukha added a comment.

I like this idea and ready to implement, but I'm not aware of the reasons why 
the current implementation was chosen. Suppose that initializing the Debugger 
for each test will slow down the test-suite significantly.


Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74903/new/

https://reviews.llvm.org/D74903



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


[Lldb-commits] [lldb] 0e5ed1b - [lldb][NFC] Split up ClangASTSource::FindExternalVisibleDecls

2020-02-21 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2020-02-21T09:47:52+01:00
New Revision: 0e5ed1b26264f7eee32b23c533371c18ce1cdec0

URL: 
https://github.com/llvm/llvm-project/commit/0e5ed1b26264f7eee32b23c533371c18ce1cdec0
DIFF: 
https://github.com/llvm/llvm-project/commit/0e5ed1b26264f7eee32b23c533371c18ce1cdec0.diff

LOG: [lldb][NFC] Split up ClangASTSource::FindExternalVisibleDecls

This function has two functions hidden inside it. Let's make
them proper functions.

Added: 


Modified: 
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h

Removed: 




diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 02b1f9bcd4a0..2395e3444d9d 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -750,100 +750,11 @@ void ClangASTSource::FindExternalVisibleDecls(
 
   if (!context.m_found.type) {
 // Try the modules next.
-
-do {
-  if (ClangModulesDeclVendor *modules_decl_vendor =
-  m_target->GetClangModulesDeclVendor()) {
-bool append = false;
-uint32_t max_matches = 1;
-std::vector decls;
-
-if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls))
-  break;
-
-if (log) {
-  LLDB_LOG(log,
-   "  CAS::FEVD[{0}] Matching entity found for \"{1}\" in "
-   "the modules",
-   current_id, name);
-}
-
-clang::NamedDecl *const decl_from_modules = decls[0];
-
-if (llvm::isa(decl_from_modules) ||
-llvm::isa(decl_from_modules) ||
-llvm::isa(decl_from_modules)) {
-  clang::Decl *copied_decl = CopyDecl(decl_from_modules);
-  clang::NamedDecl *copied_named_decl =
-  copied_decl ? dyn_cast(copied_decl) : nullptr;
-
-  if (!copied_named_decl) {
-LLDB_LOG(
-log,
-"  CAS::FEVD[{0}] - Couldn't export a type from the modules",
-current_id);
-
-break;
-  }
-
-  context.AddNamedDecl(copied_named_decl);
-
-  context.m_found.type = true;
-}
-  }
-} while (false);
+FindDeclInModules(context, name, current_id);
   }
 
   if (!context.m_found.type) {
-do {
-  // Couldn't find any types elsewhere.  Try the Objective-C runtime if
-  // one exists.
-
-  lldb::ProcessSP process(m_target->GetProcessSP());
-
-  if (!process)
-break;
-
-  ObjCLanguageRuntime *language_runtime(
-  ObjCLanguageRuntime::Get(*process));
-
-  if (!language_runtime)
-break;
-
-  DeclVendor *decl_vendor = language_runtime->GetDeclVendor();
-
-  if (!decl_vendor)
-break;
-
-  bool append = false;
-  uint32_t max_matches = 1;
-  std::vector decls;
-
-  auto *clang_decl_vendor = llvm::cast(decl_vendor);
-  if (!clang_decl_vendor->FindDecls(name, append, max_matches, decls))
-break;
-
-  if (log) {
-LLDB_LOG(
-log,
-"  CAS::FEVD[{0}] Matching type found for \"{0}\" in the runtime",
-current_id, name);
-  }
-
-  clang::Decl *copied_decl = CopyDecl(decls[0]);
-  clang::NamedDecl *copied_named_decl =
-  copied_decl ? dyn_cast(copied_decl) : nullptr;
-
-  if (!copied_named_decl) {
-LLDB_LOG(log,
- "  CAS::FEVD[{0}] - Couldn't export a type from the runtime",
- current_id);
-
-break;
-  }
-
-  context.AddNamedDecl(copied_named_decl);
-} while (false);
+FindDeclInObjCRuntime(context, name, current_id);
   }
 }
 
@@ -979,6 +890,100 @@ bool ClangASTSource::FindObjCMethodDeclsWithOrigin(
   return true;
 }
 
+void ClangASTSource::FindDeclInModules(NameSearchContext &context,
+   ConstString name, unsigned current_id) {
+  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+  ClangModulesDeclVendor *modules_decl_vendor =
+  m_target->GetClangModulesDeclVendor();
+  if (!modules_decl_vendor)
+return;
+
+  bool append = false;
+  uint32_t max_matches = 1;
+  std::vector decls;
+
+  if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls))
+return;
+
+  if (log) {
+LLDB_LOG(log,
+ "  CAS::FEVD[{0}] Matching entity found for \"{1}\" in "
+ "the modules",
+ current_id, name);
+  }
+
+  clang::NamedDecl *const decl_from_modules = decls[0];
+
+  if (llvm::isa(decl_from_modules) ||
+  llvm::isa(decl_from_modules) ||
+  llvm::isa(decl_from_modules)) {
+clang::Decl *copied_decl = CopyDecl(decl_from_modules);
+clang::NamedDecl *copied_named_decl =
+copied_de

[Lldb-commits] [PATCH] D74951: [lldb] Remove all the 'current_id' logging counters from the lookup code.

2020-02-21 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor created this revision.
teemperor added reviewers: labath, shafik, JDevlieghere.
Herald added subscribers: lldb-commits, abidh.
Herald added a project: LLDB.
teemperor retitled this revision from "[lldb] Remove all the`current_id`  
logging counters from the lookup code." to "[lldb] Remove all the 'current_id'  
logging counters from the lookup code.".

We have a lot of code in our lookup code to pass around `current_id` counters 
which end up in our logs like this:

  AOCTV::FT [234] Found XYZ

This patch removes all of this code because:

- I'm splitting up all humongous functions, so I need to write more and more 
boilerplate to pass around these ids.
- I never saw any similar counters in the LLDB/LLVM code base.
- They're essentially globals and the last thing we need in LLDB is even more 
global state.
- They're not really useful when readings logs. It doesn't help that there 
isn't just 1 or 2 counters, but 12 (!) unique counters. I always thought that 
if I see two identical counter values in those brackets it's the same lookup 
request, but it seems that's only true by accident (and you can't know which of 
the 12 counters is actually printed without reading the code). The only time I 
know I can trust the counters is when it's obvious from the log that it's the 
same counter like in the log below, but then why have the counters in the first 
place?

  LayoutRecordType[28] on (ASTContext*)0x7FFA1C840200 'scratch ASTContext' 
for (RecordDecl*)0x7FFA0AAE8CF0 [name = '__tree']
  LRT[28] returned:
  LRT[28]   Original = (RecordDecl*)%p
  LRT[28]   Size = %lld
  LRT[28]   Alignment = %lld
  LRT[28]   Fields:
  LRT[28] (FieldDecl*)0x7FFA1A13B1D0, Name = '__begin_node_', Offset = 
0 bits
  LRT[28] (FieldDecl*)0x7FFA1C08FD30, Name = '__pair1_', Offset = 64 
bits
  LRT[28] (FieldDecl*)0x7FFA1C061210, Name = '__pair3_', Offset = 128 
bits
  LRT[28]   Bases:


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D74951

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp

Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
@@ -30,17 +30,14 @@
 
   bool FindExternalVisibleDeclsByName(const clang::DeclContext *decl_ctx,
   clang::DeclarationName name) override {
-static unsigned int invocation_id = 0;
-unsigned int current_id = invocation_id++;
 
 Log *log(GetLogIfAllCategoriesSet(
 LIBLLDB_LOG_EXPRESSIONS)); // FIXME - a more appropriate log channel?
 
 if (log) {
   LLDB_LOGF(log,
-"AppleObjCExternalASTSource::FindExternalVisibleDeclsByName[%"
-"u] on (ASTContext*)%p Looking for %s in (%sDecl*)%p",
-current_id,
+"AppleObjCExternalASTSource::FindExternalVisibleDeclsByName"
+" on (ASTContext*)%p Looking for %s in (%sDecl*)%p",
 static_cast(&decl_ctx->getParentASTContext()),
 name.getAsString().c_str(), decl_ctx->getDeclKindName(),
 static_cast(decl_ctx));
@@ -70,44 +67,37 @@
   }
 
   void CompleteType(clang::TagDecl *tag_decl) override {
-static unsigned int invocation_id = 0;
-unsigned int current_id = invocation_id++;
 
 Log *log(GetLogIfAllCategoriesSet(
 LIBLLDB_LOG_EXPRESSIONS)); // FIXME - a more appropriate log channel?
 
 LLDB_LOGF(log,
-  "AppleObjCExternalASTSource::CompleteType[%u] on "
+  "AppleObjCExternalASTSource::CompleteType on "
   "(ASTContext*)%p Completing (TagDecl*)%p named %s",
-  current_id, static_cast(&tag_decl->getASTContext()),
+  static_cast(&tag_decl->getASTContext()),
   static_cast(tag_decl), tag_decl->getName().str().c_str());
 
-LLDB_LOG(log, "  AOEAS::CT[{0}] Before:\n{1}", current_id,
- ClangUtil::DumpDecl(tag_decl));
+LLDB_LOG(log, "  AOEAS::CT Before:\n{1}", ClangUtil::DumpDecl(tag_decl));
 
-LLDB_LOG(log, "  AOEAS::CT[{1}] After:{1}", current_id,
- ClangUtil::DumpDecl(tag_decl));
+LLDB_LOG(log, "  AOEAS::CT After:{1}", ClangUtil::DumpDecl(tag_decl));
 
 return;
   }
 
   void CompleteType(clang::ObjCInterfaceDecl *interface_decl) override {
-static unsigned int invocation_id = 0;
-unsigned int current_id = invocation_id++;
 
 Log *log(GetLogIfAllCategoriesSet(
 LIBLLDB_LOG_EXPRESSIONS)); // FIXME - a more appropria

[Lldb-commits] [PATCH] D73067: [lldb/CMake] Auto-generate the Initialize and Terminate calls for plugin

2020-02-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

In D73067#1884970 , @krytarowski wrote:

> Autogeneration of the code puts extra burden on us for tracking what is 
> defined where and for repackaging LLDB with custom build rules (we need plain 
> Makefile in the distribution). I presume the same problem is for gn users, 
> for FreeBSD etc.
>
> The NetBSD buildbot is now broken:
>
>FAILED: lib/liblldb.so.11.0.0git 
>: && /home/motus/netbsd8/netbsd8/wrappers/clang++ -fPIC -fPIC 
> -fvisibility-inlines-hidden -Werror=date-time 
> -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
> -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
> -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default 
> -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor 
> -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections 
> -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing 
> -Wno-deprecated-register -Wno-vla-extension -O3 -DNDEBUG  -Wl,-z,defs 
> -Wl,--color-diagnostics   -Wl,-O3 -Wl,--gc-sections  
> -Wl,--version-script,"/home/motus/netbsd8/netbsd8/build-stage2/tools/lldb/source/API/liblldb.exports"
>  -shared -Wl,-soname,liblldb.so.11git -o lib/liblldb.so.11.0.0git 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBAddress.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBAttachInfo.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBBlock.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBBreakpoint.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBBreakpointLocation.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBBreakpointName.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBBreakpointOptionCommon.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBBroadcaster.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBCommandInterpreter.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBCommandReturnObject.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBCommunication.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBCompileUnit.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBData.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBDebugger.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBDeclaration.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBError.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBEvent.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBExecutionContext.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBExpressionOptions.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBFileSpec.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBFile.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBFileSpecList.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBFrame.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBFunction.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBHostOS.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBInstruction.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBInstructionList.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBLanguageRuntime.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBLaunchInfo.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBLineEntry.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBListener.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBMemoryRegionInfo.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBMemoryRegionInfoList.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBModule.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBModuleSpec.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBPlatform.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBProcess.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBProcessInfo.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBQueue.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBQueueItem.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBReproducer.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBSection.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBSourceManager.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBStream.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBStringList.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBStructuredData.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBSymbol.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBSymbolContext.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBSymbolContextList.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBTarget.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBThread.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBThreadCollection.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBThreadPlan.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBTrace.cpp.o 
> tools/lldb/source/API/CMakeFiles/liblldb.dir/SBTraceOption

[Lldb-commits] [PATCH] D74957: [lldb] Disable auto fix-its when evaluating expressions in the test suite

2020-02-21 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor created this revision.
teemperor added reviewers: jingham, JDevlieghere.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Currently the test suite runs with enabled automatically applied Clang fix-its 
for expressions.
This is causing that sometimes incorrect expressions in tests are still 
evaluated even though they
are actually incorrect. Let's disable this feature in the test suite so that we 
know when expressions
are wrong and leave the fix-it testing to the dedicated tests for that feature.

Also updates the `lang/cpp/operators/` test as it seems Clang needs the 
`struct` keywords
before C and would otherwise fail without fixits.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D74957

Files:
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/test/API/lang/cpp/operators/main.cpp
  lldb/test/Shell/lit-lldb-init.in


Index: lldb/test/Shell/lit-lldb-init.in
===
--- lldb/test/Shell/lit-lldb-init.in
+++ lldb/test/Shell/lit-lldb-init.in
@@ -3,3 +3,4 @@
 settings set plugin.process.gdb-remote.packet-timeout 60
 settings set interpreter.echo-comment-commands false
 settings set symbols.clang-modules-cache-path "@LLDB_TEST_MODULE_CACHE_LLDB@"
+settings set target.auto-apply-fixits false
Index: lldb/test/API/lang/cpp/operators/main.cpp
===
--- lldb/test/API/lang/cpp/operators/main.cpp
+++ lldb/test/API/lang/cpp/operators/main.cpp
@@ -171,7 +171,7 @@
   //% self.expect("expr static_cast(c)", endstr=" 12\n")
   //% self.expect("expr c.operatorint()", endstr=" 13\n")
   //% self.expect("expr c.operatornew()", endstr=" 14\n")
-  //% self.expect("expr (new C)->custom_new", endstr=" true\n")
+  //% self.expect("expr (new struct C)->custom_new", endstr=" true\n")
   //% self.expect("expr (new struct C[1])->custom_new", endstr=" true\n")
   //% self.expect("expr delete c2; side_effect", endstr=" = 1\n")
   //% self.expect("expr delete[] c3; side_effect", endstr=" = 2\n")
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -692,6 +692,10 @@
 # differ in the debug info, which is not being hashed.
 "settings set symbols.enable-external-lookup false",
 
+# Disable fix-its by default so that incorrect expressions in 
tests don't
+# pass just because Clang thinks it has a fix-it.
+"settings set target.auto-apply-fixits false",
+
 # Testsuite runs in parallel and the host can have also other load.
 "settings set plugin.process.gdb-remote.packet-timeout 60",
 
@@ -2394,7 +2398,16 @@
 self.assertTrue(expr.strip() == expr, "Expression contains 
trailing/leading whitespace: '" + expr + "'")
 
 frame = self.frame()
-eval_result = frame.EvaluateExpression(expr)
+options = lldb.SBExpressionOptions()
+
+# Disable fix-its that tests don't pass by accident.
+options.SetAutoApplyFixIts(True)
+
+# Set the usual default options for normal expressions.
+options.SetIgnoreBreakpoints(True)
+options.SetLanguage(frame.GuessLanguage())
+
+eval_result = frame.EvaluateExpression(expr, options)
 
 if error_msg:
 self.assertFalse(eval_result.IsValid(), "Unexpected success with 
result: '" + str(eval_result) + "'")


Index: lldb/test/Shell/lit-lldb-init.in
===
--- lldb/test/Shell/lit-lldb-init.in
+++ lldb/test/Shell/lit-lldb-init.in
@@ -3,3 +3,4 @@
 settings set plugin.process.gdb-remote.packet-timeout 60
 settings set interpreter.echo-comment-commands false
 settings set symbols.clang-modules-cache-path "@LLDB_TEST_MODULE_CACHE_LLDB@"
+settings set target.auto-apply-fixits false
Index: lldb/test/API/lang/cpp/operators/main.cpp
===
--- lldb/test/API/lang/cpp/operators/main.cpp
+++ lldb/test/API/lang/cpp/operators/main.cpp
@@ -171,7 +171,7 @@
   //% self.expect("expr static_cast(c)", endstr=" 12\n")
   //% self.expect("expr c.operatorint()", endstr=" 13\n")
   //% self.expect("expr c.operatornew()", endstr=" 14\n")
-  //% self.expect("expr (new C)->custom_new", endstr=" true\n")
+  //% self.expect("expr (new struct C)->custom_new", endstr=" true\n")
   //% self.expect("expr (new struct C[1])->custom_new", endstr=" true\n")
   //% self.expect("expr delete c2; side_effect", endstr=" = 1\n")
   //% self.expect("expr delete[] c3; side_effect", endstr=" = 2\n")
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -692,6 +692,10 @@
 

[Lldb-commits] [PATCH] D74903: [lldb][test] Add two wrapper functions to manage settings in test-suite

2020-02-21 Thread Pavel Labath via Phabricator via lldb-commits
labath added a subscriber: jingham.
labath added a comment.

We (mostly me and @jingham) discussed that idea (very) briefly a couple of 
weeks ago, and my impression was that this (reinitializing SBDebugger for every 
test) would be a good way to go. There are just too many things that can leak 
from one session into another, and since none of the default bots run in the 
monolithic mode, I am frankly surprised that this mode is still even remotely 
usable.

One thing to be aware of is that SBDebuggers are not perfectly isolated either 
-- some settings will leak from one debugger into another and so one still has 
to be careful when setting those...


Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74903/new/

https://reviews.llvm.org/D74903



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


[Lldb-commits] [PATCH] D74657: [lldb/Plugins] Add ability to fetch crash information on crashed processes

2020-02-21 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D74657#1885361 , @JDevlieghere 
wrote:

> A few small nits inline, but this LGTM if Pavel is on board.


We're getting close, but I still see some room for improvement. :)




Comment at: lldb/bindings/interface/SBPlatform.i:195-198
+%feature("autodoc", "
+Returns the platform's process extended crash information.") 
GetExtendedCrashInformation;
+lldb::SBStructuredData
+GetExtendedCrashInformation (lldb::SBTarget& target);

If we keep the this way, then the user will have to remember to get the correct 
platform in order to ask it for the crash info. That's not the end of the 
world, but it might be better if this was a method on the SBTarget class, which 
would automatically consult the target's current platform.



Comment at: lldb/source/Commands/CommandObjectProcess.cpp:1288-1291
+  if (!crash_info_sp) {
+result.AppendError("Couldn't fetch the crash information");
+result.SetStatus(eReturnStatusFailed);
+return result.Succeeded();

So, this will print an error if we don't get a crash information for _any_ 
reason (process did not crash, platform does not support crash info, ...), is 
that right?

That seems overly aggressive. I think this should be more nuanced. Maybe if 
`FetchExtendedCrashInformation` returned `Expected`, then you 
could do something like
- if the result is an error => something really went wrong => print the error 
message
- nullptr => not an error, but we also didn't get anything => don't print 
anything
- an actual dictionary => hurray => print the crash info

Then the default implementation can return `nullptr`, and in `PlatformDarwin` 
you can precisely decide what treatment does a certain situation deserve (e.g. 
whether not being able to find the __crash_info section is an error or just 
"nothing").



Comment at: lldb/source/Commands/CommandObjectProcess.cpp:1294
+
+  crash_info_sp->Dump(strm);
+}

Should you maybe print some kind of a header to make it clear that what follows 
is the crash information?



Comment at: 
lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py:37
+self.expect('process status --verbose',
+patterns=["\"message\".*pointer being freed was not 
allocated"])
+

Besides the "positive" test, I think it would be also good to have some tests 
for the "negative" cases. E.g. a case where the process did not crash, or when 
we have not even launched it yet.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74657/new/

https://reviews.llvm.org/D74657



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


[Lldb-commits] [PATCH] D74951: [lldb] Remove all the 'current_id' logging counters from the lookup code.

2020-02-21 Thread Noel Grandin via Phabricator via lldb-commits
grandinj added a comment.

Just a drive-by suggestion: Logging the pointer value of the relevant root 
object in the callees would provide similar benefit to anyone needing to do log 
tracing


Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74951/new/

https://reviews.llvm.org/D74951



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


[Lldb-commits] [PATCH] D74957: [lldb] Disable auto fix-its when evaluating expressions in the test suite

2020-02-21 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM outside of my comments




Comment at: lldb/packages/Python/lldbsuite/test/lldbtest.py:2404
+# Disable fix-its that tests don't pass by accident.
+options.SetAutoApplyFixIts(True)
+

Should this be `False` or is the comment incorrect?



Comment at: lldb/test/API/lang/cpp/operators/main.cpp:174
   //% self.expect("expr c.operatornew()", endstr=" 14\n")
-  //% self.expect("expr (new C)->custom_new", endstr=" true\n")
+  //% self.expect("expr (new struct C)->custom_new", endstr=" true\n")
   //% self.expect("expr (new struct C[1])->custom_new", endstr=" true\n")

This is puzzling, I don't know why we need the `struct` for I don't see why an 
elborated type specifier is required here.


Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74957/new/

https://reviews.llvm.org/D74957



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


[Lldb-commits] [lldb] de8793b - [lldb/DWARF] Add support for type units in dwp files

2020-02-21 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2020-02-21T16:01:17+01:00
New Revision: de8793b9184ece0d24f46bc2d86711092848f938

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

LOG: [lldb/DWARF] Add support for type units in dwp files

all that was needed was to teach lldb's DWARF context about the
debug_tu_index section.

Added: 
lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s

Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
index 79601e3bad0d..37e28a09f3c4 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
@@ -45,6 +45,11 @@ const DWARFDataExtractor 
&DWARFContext::getOrLoadCuIndexData() {
   m_data_debug_cu_index);
 }
 
+const DWARFDataExtractor &DWARFContext::getOrLoadTuIndexData() {
+  return LoadOrGetSection(llvm::None, eSectionTypeDWARFDebugTuIndex,
+  m_data_debug_tu_index);
+}
+
 const DWARFDataExtractor &DWARFContext::getOrLoadAbbrevData() {
   return LoadOrGetSection(eSectionTypeDWARFDebugAbbrev,
   eSectionTypeDWARFDebugAbbrevDwo, 
m_data_debug_abbrev);
@@ -134,6 +139,7 @@ llvm::DWARFContext &DWARFContext::GetAsLLVM() {
 
 AddSection("debug_line_str", getOrLoadLineStrData());
 AddSection("debug_cu_index", getOrLoadCuIndexData());
+AddSection("debug_tu_index", getOrLoadTuIndexData());
 
 m_llvm_context = llvm::DWARFContext::create(section_map, addr_size);
   }

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h
index 8de5e9c8a5fb..92161a21d167 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h
@@ -42,6 +42,7 @@ class DWARFContext {
   SectionData m_data_debug_rnglists;
   SectionData m_data_debug_str;
   SectionData m_data_debug_str_offsets;
+  SectionData m_data_debug_tu_index;
   SectionData m_data_debug_types;
 
   const DWARFDataExtractor &
@@ -50,6 +51,7 @@ class DWARFContext {
SectionData &data);
 
   const DWARFDataExtractor &getOrLoadCuIndexData();
+  const DWARFDataExtractor &getOrLoadTuIndexData();
 
 public:
   explicit DWARFContext(SectionList *main_section_list,

diff  --git a/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s 
b/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s
new file mode 100644
index ..fd009381b452
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s
@@ -0,0 +1,211 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc --filetype=obj --triple x86_64-pc-linux %s -o %t --defsym MAIN=0
+# RUN: llvm-mc --filetype=obj --triple x86_64-pc-linux %s -o %t.dwp --defsym 
DWP=0
+# RUN: %lldb %t -o "type lookup ENUM0" -o "target variable A" -b | FileCheck %s
+
+# CHECK-LABEL: type lookup ENUM0
+# CHECK-NEXT: enum ENUM0 {
+# CHECK-NEXT:   case0
+# CHECK-NEXT: }
+
+# CHECK-LABEL: target variable A
+# CHECK: (ENUM0) A = case0
+# CHECK: (ENUM1) A = case0
+
+.ifdef MAIN
+.section.debug_abbrev,"",@progbits
+.byte   1   # Abbreviation Code
+.byte   17  # DW_TAG_compile_unit
+.byte   0   # DW_CHILDREN_no
+.ascii  "\260B" # DW_AT_GNU_dwo_name
+.byte   8   # DW_FORM_string
+.ascii  "\261B" # DW_AT_GNU_dwo_id
+.byte   7   # DW_FORM_data8
+.ascii  "\263B" # DW_AT_GNU_addr_base
+.byte   23  # DW_FORM_sec_offset
+.byte   0   # EOM(1)
+.byte   0   # EOM(2)
+.byte   0   # EOM(3)
+
+.irpc I,01
+.data
+A\I:
+.long 0
+
+.section.debug_info,"",@progbits
+.Lcu_begin\I:
+.long   .Ldebug_info_end\I-.Ldebug_info_start\I # Length of Unit
+.Ldebug_info_start\I:
+.short  4   # DWARF version number
+.long   .debug_abbrev   # Offset Into Abbrev. Section
+.byte   8   # Address Size (in bytes)
+.byte   1   # Abbrev [1] DW_TAG_compile_unit
+.asciz  "A.dwo" # DW_AT_GNU_dwo_name
+.quad   \I  # DW_AT_GNU_dwo_id
+.long   .debug_addr # DW_AT_GNU_addr_base
+.Ldebug_info_end\I:
+
+.section.debug_addr,"",@progbits
+.quad   A\I
+
+.endr
+.endif
+
+.ifdef DWP
+.irpc I,01
+.section   

[Lldb-commits] [PATCH] D74951: [lldb] Remove all the 'current_id' logging counters from the lookup code.

2020-02-21 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

I have struggled to understand the real use of those counters, they may have 
been helpful to someone at one point but the rationale is lost in the sands of 
time.

LGTM but lets see if someone else has an insight.


Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74951/new/

https://reviews.llvm.org/D74951



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


[Lldb-commits] [PATCH] D74957: [lldb] Disable auto fix-its when evaluating expressions in the test suite

2020-02-21 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor updated this revision to Diff 245846.
teemperor added a comment.

- Revert dummy change that set auto-apply fixits to true (thanks Shafik!)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74957/new/

https://reviews.llvm.org/D74957

Files:
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/test/API/lang/cpp/operators/main.cpp
  lldb/test/Shell/lit-lldb-init.in


Index: lldb/test/Shell/lit-lldb-init.in
===
--- lldb/test/Shell/lit-lldb-init.in
+++ lldb/test/Shell/lit-lldb-init.in
@@ -3,3 +3,4 @@
 settings set plugin.process.gdb-remote.packet-timeout 60
 settings set interpreter.echo-comment-commands false
 settings set symbols.clang-modules-cache-path "@LLDB_TEST_MODULE_CACHE_LLDB@"
+settings set target.auto-apply-fixits false
Index: lldb/test/API/lang/cpp/operators/main.cpp
===
--- lldb/test/API/lang/cpp/operators/main.cpp
+++ lldb/test/API/lang/cpp/operators/main.cpp
@@ -171,7 +171,7 @@
   //% self.expect("expr static_cast(c)", endstr=" 12\n")
   //% self.expect("expr c.operatorint()", endstr=" 13\n")
   //% self.expect("expr c.operatornew()", endstr=" 14\n")
-  //% self.expect("expr (new C)->custom_new", endstr=" true\n")
+  //% self.expect("expr (new struct C)->custom_new", endstr=" true\n")
   //% self.expect("expr (new struct C[1])->custom_new", endstr=" true\n")
   //% self.expect("expr delete c2; side_effect", endstr=" = 1\n")
   //% self.expect("expr delete[] c3; side_effect", endstr=" = 2\n")
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -692,6 +692,10 @@
 # differ in the debug info, which is not being hashed.
 "settings set symbols.enable-external-lookup false",
 
+# Disable fix-its by default so that incorrect expressions in 
tests don't
+# pass just because Clang thinks it has a fix-it.
+"settings set target.auto-apply-fixits false",
+
 # Testsuite runs in parallel and the host can have also other load.
 "settings set plugin.process.gdb-remote.packet-timeout 60",
 
@@ -2394,7 +2398,16 @@
 self.assertTrue(expr.strip() == expr, "Expression contains 
trailing/leading whitespace: '" + expr + "'")
 
 frame = self.frame()
-eval_result = frame.EvaluateExpression(expr)
+options = lldb.SBExpressionOptions()
+
+# Disable fix-its that tests don't pass by accident.
+options.SetAutoApplyFixIts(False)
+
+# Set the usual default options for normal expressions.
+options.SetIgnoreBreakpoints(True)
+options.SetLanguage(frame.GuessLanguage())
+
+eval_result = frame.EvaluateExpression(expr, options)
 
 if error_msg:
 self.assertFalse(eval_result.IsValid(), "Unexpected success with 
result: '" + str(eval_result) + "'")


Index: lldb/test/Shell/lit-lldb-init.in
===
--- lldb/test/Shell/lit-lldb-init.in
+++ lldb/test/Shell/lit-lldb-init.in
@@ -3,3 +3,4 @@
 settings set plugin.process.gdb-remote.packet-timeout 60
 settings set interpreter.echo-comment-commands false
 settings set symbols.clang-modules-cache-path "@LLDB_TEST_MODULE_CACHE_LLDB@"
+settings set target.auto-apply-fixits false
Index: lldb/test/API/lang/cpp/operators/main.cpp
===
--- lldb/test/API/lang/cpp/operators/main.cpp
+++ lldb/test/API/lang/cpp/operators/main.cpp
@@ -171,7 +171,7 @@
   //% self.expect("expr static_cast(c)", endstr=" 12\n")
   //% self.expect("expr c.operatorint()", endstr=" 13\n")
   //% self.expect("expr c.operatornew()", endstr=" 14\n")
-  //% self.expect("expr (new C)->custom_new", endstr=" true\n")
+  //% self.expect("expr (new struct C)->custom_new", endstr=" true\n")
   //% self.expect("expr (new struct C[1])->custom_new", endstr=" true\n")
   //% self.expect("expr delete c2; side_effect", endstr=" = 1\n")
   //% self.expect("expr delete[] c3; side_effect", endstr=" = 2\n")
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -692,6 +692,10 @@
 # differ in the debug info, which is not being hashed.
 "settings set symbols.enable-external-lookup false",
 
+# Disable fix-its by default so that incorrect expressions in tests don't
+# pass just because Clang thinks it has a fix-it.
+"settings set target.auto-apply-fixits false",
+
 # Testsuite runs in parallel and the host can have also other load.
 "settings set plugin.process.gdb-remote.packe

[Lldb-commits] [PATCH] D74957: [lldb] Disable auto fix-its when evaluating expressions in the test suite

2020-02-21 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor marked 3 inline comments as done.
teemperor added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/lldbtest.py:2404
+# Disable fix-its that tests don't pass by accident.
+options.SetAutoApplyFixIts(True)
+

shafik wrote:
> Should this be `False` or is the comment incorrect?
True (heh), I changed that to false as some tests were failing in very 
unexpected ways on my system with this patch and I wanted to double check that 
it's not the fixits. Forgot to change this line back afterwards :(



Comment at: lldb/test/API/lang/cpp/operators/main.cpp:174
   //% self.expect("expr c.operatornew()", endstr=" 14\n")
-  //% self.expect("expr (new C)->custom_new", endstr=" true\n")
+  //% self.expect("expr (new struct C)->custom_new", endstr=" true\n")
   //% self.expect("expr (new struct C[1])->custom_new", endstr=" true\n")

shafik wrote:
> This is puzzling, I don't know why we need the `struct` for I don't see why 
> an elborated type specifier is required here.
I remember I was confused about this when I wrote the line below as Clang 
forced me to add the 'struct' (as apparently there Clang wasn't smart enough 
for the automatic fixit). I didn't investigate back then as I already had 
enough on my plate but with some luck that's an easy fix (maybe we get some 
language option wrong?).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74957/new/

https://reviews.llvm.org/D74957



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


[Lldb-commits] [PATCH] D74964: [lldb/DWARF] Don't index dwp file multiple times

2020-02-21 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: clayborg, JDevlieghere, aprantl.
Herald added a subscriber: arphaman.
Herald added a project: LLDB.

When we added support for type units in dwo files, we changed the
"manual" dwarf index to index _all_ dwarf units in the dwo file instead
of just the split unit belonging to our skeleton unit. This was fine for
dwo files, as they contain only a single compile units and type units do
not have a split type unit which would point to them.

However, this does not work for dwp files because, these files do
contain multiple split compile units, and the current approach means
that each unit gets indexed multiple times (once for each split unit =>
n^2 complexity).

This patch teaches the manual dwarf index to treat dwp files specially.
Any type units in the dwp file added to the main list of compile units
and indexed with them in a single batch. Split compile units in dwp
files are still indexed as a part of their skeleton unit -- this is done
because we need the DW_AT_language attribute from the skeleton unit to
index them properly.

Handling of dwo files remains unchanged -- all units (type and skeleton)
are indexed when we reach the dwo file through the split unit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74964

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s

Index: lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s
===
--- lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s
+++ lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s
@@ -3,6 +3,7 @@
 # RUN: llvm-mc --filetype=obj --triple x86_64-pc-linux %s -o %t --defsym MAIN=0
 # RUN: llvm-mc --filetype=obj --triple x86_64-pc-linux %s -o %t.dwp --defsym DWP=0
 # RUN: %lldb %t -o "type lookup ENUM0" -o "target variable A" -b | FileCheck %s
+# RUN: lldb-test symbols %t | FileCheck %s --check-prefix=SYMBOLS
 
 # CHECK-LABEL: type lookup ENUM0
 # CHECK-NEXT: enum ENUM0 {
@@ -13,6 +14,19 @@
 # CHECK: (ENUM0) A = case0
 # CHECK: (ENUM1) A = case0
 
+# Make sure each entity is present in the index only once.
+# SYMBOLS:  Globals and statics:
+# SYMBOLS-NEXT: 3fff/INFO/0023 "A"
+# SYMBOLS-NEXT: 3fff/INFO/005a "A"
+# SYMBOLS-EMPTY:
+
+# SYMBOLS: Types:
+# SYMBOLS-NEXT: 3fff/TYPE/0018 "ENUM0"
+# SYMBOLS-NEXT: 3fff/TYPE/002d "int"
+# SYMBOLS-NEXT: 3fff/TYPE/0062 "int"
+# SYMBOLS-NEXT: 3fff/TYPE/004d "ENUM1"
+# SYMBOLS-EMPTY:
+
 .ifdef MAIN
 .section.debug_abbrev,"",@progbits
 .byte   1   # Abbreviation Code
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -292,6 +292,8 @@
 
   lldb_private::DWARFContext &GetDWARFContext() { return m_context; }
 
+  const std::shared_ptr &GetDwpSymbolFile();
+
   lldb_private::FileSpec GetFile(DWARFUnit &unit, size_t file_idx);
 
   static llvm::Expected
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -458,9 +458,9 @@
 LoadSectionData(eSectionTypeDWARFDebugNames, debug_names);
 if (debug_names.GetByteSize() > 0) {
   llvm::Expected> index_or =
-  DebugNamesDWARFIndex::Create(
-  *GetObjectFile()->GetModule(), debug_names,
-  m_context.getOrLoadStrData(), DebugInfo());
+  DebugNamesDWARFIndex::Create(*GetObjectFile()->GetModule(),
+   debug_names,
+   m_context.getOrLoadStrData(), *this);
   if (index_or) {
 m_index = std::move(*index_or);
 return;
@@ -470,8 +470,8 @@
 }
   }
 
-  m_index = std::make_unique(*GetObjectFile()->GetModule(),
-DebugInfo());
+  m_index =
+  std::make_unique(*GetObjectFile()->GetModule(), *this);
 }
 
 bool SymbolFileDWARF::SupportedVersion(uint16_t version) {
@@ -1555,9 +1555,8 @@
   if (!dwo_name)
 return nullptr;
 
-  FindDwpSymbolFile();
-  if (m_dwp_symfile)
-return m_dwp_symfile;
+  if (std::shared_ptr dwp_sp = GetDwpSymbolFile())
+return dwp_sp;
 
   FileSpec dwo_file(dwo_name);
   FileSystem::Instance().Resolve(dwo_file);
@@ -3876,7 +3875,7 @@
   return m_debug_map_symfile;
 }
 
-void SymbolFileDWAR

[Lldb-commits] [PATCH] D74798: [lldb-vscode] Use libOption with tablegen to parse command line options.

2020-02-21 Thread Ivan Hernandez via Phabricator via lldb-commits
ivanhernandez13 added a comment.

Thanks for the guidance!

When there are no additional concerns, would someone mind committing this 
change for me? I don't have commit access.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74798/new/

https://reviews.llvm.org/D74798



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


[Lldb-commits] [lldb] c47e0e2 - [lldb-vscode] Use libOption with tablegen to parse command line options.

2020-02-21 Thread Jonas Devlieghere via lldb-commits

Author: Ivan Hernandez
Date: 2020-02-21T08:15:06-08:00
New Revision: c47e0e2d37d32ec56c760f1a2c9740d69c370b57

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

LOG: [lldb-vscode] Use libOption with tablegen to parse command line options.

This change will bring lldb-vscode in line with how several other llvm
tools process command line arguments and make it easier to add future
options.

Differential revision: https://reviews.llvm.org/D74798

Added: 
lldb/test/Shell/VSCode/TestOptions.test
lldb/tools/lldb-vscode/Options.td

Modified: 
lldb/test/Shell/helper/toolchain.py
lldb/tools/lldb-vscode/CMakeLists.txt
lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 




diff  --git a/lldb/test/Shell/VSCode/TestOptions.test 
b/lldb/test/Shell/VSCode/TestOptions.test
new file mode 100644
index ..05588ecd9df6
--- /dev/null
+++ b/lldb/test/Shell/VSCode/TestOptions.test
@@ -0,0 +1,8 @@
+# RUN: lldb-vscode --help | FileCheck %s
+# CHECK: -g
+# CHECK: --help
+# CHECK: -h
+# CHECK: --port
+# CHECK: -p
+# CHECK: --wait-for-debugger
+

diff  --git a/lldb/test/Shell/helper/toolchain.py 
b/lldb/test/Shell/helper/toolchain.py
index a5ccfd8b8898..a4bd9f20feb1 100644
--- a/lldb/test/Shell/helper/toolchain.py
+++ b/lldb/test/Shell/helper/toolchain.py
@@ -62,6 +62,7 @@ def use_lldb_substitutions(config):
   unresolved='ignore'),
 'lldb-test',
 'lldb-instr',
+'lldb-vscode',
 ToolSubst('%build',
   command="'" + sys.executable + "'",
   extra_args=build_script_args)

diff  --git a/lldb/tools/lldb-vscode/CMakeLists.txt 
b/lldb/tools/lldb-vscode/CMakeLists.txt
index b527addb6ba9..edf0aaa78d97 100644
--- a/lldb/tools/lldb-vscode/CMakeLists.txt
+++ b/lldb/tools/lldb-vscode/CMakeLists.txt
@@ -20,6 +20,9 @@ endif()
 # We need to include the llvm components we depend on manually, as liblldb does
 # not re-export those.
 set(LLVM_LINK_COMPONENTS Support)
+set(LLVM_TARGET_DEFINITIONS Options.td)
+tablegen(LLVM Options.inc -gen-opt-parser-defs)
+add_public_tablegen_target(LLDBVSCodeOptionsTableGen)
 add_lldb_tool(lldb-vscode
   lldb-vscode.cpp
   BreakpointBase.cpp
@@ -37,6 +40,7 @@ add_lldb_tool(lldb-vscode
 ${extra_libs}
 
   LINK_COMPONENTS
+Option
 Support
   )
 

diff  --git a/lldb/tools/lldb-vscode/Options.td 
b/lldb/tools/lldb-vscode/Options.td
new file mode 100644
index ..87cfb5199b42
--- /dev/null
+++ b/lldb/tools/lldb-vscode/Options.td
@@ -0,0 +1,25 @@
+include "llvm/Option/OptParser.td"
+
+class F: Flag<["--", "-"], name>;
+class S: Separate<["--", "-"], name>;
+class R prefixes, string name>
+  : Option;
+
+def help: F<"help">,
+  HelpText<"Prints out the usage information for the LLDB VSCode tool.">;
+def: Flag<["-"], "h">,
+  Alias,
+  HelpText<"Alias for --help">;
+
+def wait_for_debugger: F<"wait-for-debugger">,
+  HelpText<"Pause the program at startup.">;
+def: Flag<["-"], "g">,
+  Alias,
+  HelpText<"Alias for --wait-for-debugger">;
+
+def port: Separate<["--", "-"], "port">,
+  MetaVarName<"">,
+  HelpText<"Communicate with the lldb-vscode tool over the defined port.">;
+def: Separate<["-"], "p">,
+  Alias,
+  HelpText<"Alias for --port">;

diff  --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp 
b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index 29aa2f4e55d9..080ef5b40c01 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -41,8 +41,12 @@
 #include 
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Option/Option.h"
 #include "llvm/Support/Errno.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
 #include "JSONUtils.h"
@@ -64,6 +68,33 @@ constexpr const char *dev_null_path = "/dev/null";
 using namespace lldb_vscode;
 
 namespace {
+enum ID {
+  OPT_INVALID = 0, // This is not an option ID.
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  
\
+   HELPTEXT, METAVAR, VALUES)  
\
+  OPT_##ID,
+#include "Options.inc"
+#undef OPTION
+};
+
+#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
+#include "Options.inc"
+#undef PREFIX
+
+static const llvm::opt::OptTable::Info InfoTable[] = {
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  
\
+   HELPTEXT, METAVAR, VALUES)  
\
+  {PREFIX,  NAME,  HELPTEXT,   
\
+   METAVAR, OPT_##ID,  llvm::opt::Option::KIND##Class, 
\
+   PARAM,   FLAGS, OPT_##GROUP,
\
+   OPT_##ALIAS, ALIASARGS, VALUE

[Lldb-commits] [PATCH] D74798: [lldb-vscode] Use libOption with tablegen to parse command line options.

2020-02-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

In D74798#1886477 , @ivanhernandez13 
wrote:

> Thanks for the guidance!
>
> When there are no additional concerns, would someone mind committing this 
> change for me? I don't have commit access.


Done!

  To github.com:llvm/llvm-project.git
 de0dda54d38..c47e0e2d37d  master -> master


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74798/new/

https://reviews.llvm.org/D74798



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


[Lldb-commits] [PATCH] D74798: [lldb-vscode] Use libOption with tablegen to parse command line options.

2020-02-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc47e0e2d37d3: [lldb-vscode] Use libOption with tablegen to 
parse command line options. (authored by ivanhernandez13, committed by 
JDevlieghere).

Changed prior to commit:
  https://reviews.llvm.org/D74798?vs=245523&id=245873#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74798/new/

https://reviews.llvm.org/D74798

Files:
  lldb/test/Shell/VSCode/TestOptions.test
  lldb/test/Shell/helper/toolchain.py
  lldb/tools/lldb-vscode/CMakeLists.txt
  lldb/tools/lldb-vscode/Options.td
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -41,8 +41,12 @@
 #include 
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Option/Option.h"
 #include "llvm/Support/Errno.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
 #include "JSONUtils.h"
@@ -64,6 +68,33 @@
 using namespace lldb_vscode;
 
 namespace {
+enum ID {
+  OPT_INVALID = 0, // This is not an option ID.
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, VALUES)  \
+  OPT_##ID,
+#include "Options.inc"
+#undef OPTION
+};
+
+#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
+#include "Options.inc"
+#undef PREFIX
+
+static const llvm::opt::OptTable::Info InfoTable[] = {
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+   HELPTEXT, METAVAR, VALUES)  \
+  {PREFIX,  NAME,  HELPTEXT,   \
+   METAVAR, OPT_##ID,  llvm::opt::Option::KIND##Class, \
+   PARAM,   FLAGS, OPT_##GROUP,\
+   OPT_##ALIAS, ALIASARGS, VALUES},
+#include "Options.inc"
+#undef OPTION
+};
+class LLDBVSCodeOptTable : public llvm::opt::OptTable {
+public:
+  LLDBVSCodeOptTable() : OptTable(InfoTable, true) {}
+};
 
 typedef void (*RequestCallback)(const llvm::json::Object &command);
 
@@ -2719,31 +2750,69 @@
 
 } // anonymous namespace
 
+static void printHelp(LLDBVSCodeOptTable &table, llvm::StringRef tool_name) {
+  std::string usage_str = tool_name.str() + "options";
+  table.PrintHelp(llvm::outs(), usage_str.c_str(), "LLDB VSCode", false);
+
+  std::string examples = R"___(
+EXAMPLES:
+  The debug adapter can be started in two modes.
+
+  Running lldb-vscode without any arguments will start communicating with the
+  parent over stdio. Passing a port number causes lldb-vscode to start listening
+  for connections on that port.
+
+lldb-vscode -p 
+
+  Passing --wait-for-debugger will pause the process at startup and wait for a
+  debugger to attach to the process.
+
+lldb-vscode -g
+  )___";
+  llvm::outs() << examples;
+}
+
 int main(int argc, char *argv[]) {
 
   // Initialize LLDB first before we do anything.
   lldb::SBDebugger::Initialize();
 
-  if (argc == 2) {
-const char *arg = argv[1];
+  int portno = -1;
+
+  LLDBVSCodeOptTable T;
+  unsigned MAI, MAC;
+  llvm::ArrayRef ArgsArr = llvm::makeArrayRef(argv + 1, argc);
+  llvm::opt::InputArgList input_args = T.ParseArgs(ArgsArr, MAI, MAC);
+
+  if (input_args.hasArg(OPT_help)) {
+printHelp(T, llvm::sys::path::filename(argv[0]));
+return 0;
+  }
+
+  if (auto *arg = input_args.getLastArg(OPT_port)) {
+auto optarg = arg->getValue();
+char *remainder;
+portno = strtol(optarg, &remainder, 0);
+if (remainder == optarg || *remainder != '\0') {
+  fprintf(stderr, "'%s' is not a valid port number.\n", optarg);
+  exit(1);
+}
+  }
+
 #if !defined(_WIN32)
-if (strcmp(arg, "-g") == 0) {
-  printf("Paused waiting for debugger to attach (pid = %i)...\n", getpid());
-  pause();
-} else {
-#else
-{
+  if (input_args.hasArg(OPT_wait_for_debugger)) {
+printf("Paused waiting for debugger to attach (pid = %i)...\n", getpid());
+pause();
+  }
 #endif
-  int portno = atoi(arg);
-  printf("Listening on port %i...\n", portno);
-  SOCKET socket_fd = AcceptConnection(portno);
-  if (socket_fd >= 0) {
-g_vsc.input.descriptor = StreamDescriptor::from_socket(socket_fd, true);
-g_vsc.output.descriptor =
-StreamDescriptor::from_socket(socket_fd, false);
-  } else {
-exit(1);
-  }
+  if (portno != -1) {
+printf("Listening on port %i...\n", portno);
+SOCKET socket_fd = AcceptConnection(portno);
+if (socket_fd >= 0) {
+  g_vsc.input.descriptor = StreamDescriptor::from_socket(socket_fd, true);
+  g_vsc.output.descriptor = StreamDescriptor::from_socket(socket_fd, f

[Lldb-commits] [lldb] 07d2cda - [lldb/cmake] Enable more verbose find_package output.

2020-02-21 Thread Matt Davis via lldb-commits

Author: Matt Davis
Date: 2020-02-21T10:37:02-08:00
New Revision: 07d2cdae11633139947f105888163adfd5646ce7

URL: 
https://github.com/llvm/llvm-project/commit/07d2cdae11633139947f105888163adfd5646ce7
DIFF: 
https://github.com/llvm/llvm-project/commit/07d2cdae11633139947f105888163adfd5646ce7.diff

LOG: [lldb/cmake] Enable more verbose find_package output.

Summary:
The purpose of this patch is to make identifying missing dependencies clearer 
to the user.
`find_package` will report if a package is not found, that output, combined 
with the exiting
status message, is clearer than not having the additional verbosity.

If the SWIG dependency is required {LLDB_ENABLE_PYTHON, LLDB_ENABLE_LUA}
and SWIG is not available, fail the configuration step.  Terminate the
configure early rather than later with a clear error message.

We could possibly modify:
`llvm-project/lldb/cmake/modules/FindPythonInterpAndLibs.cmake`
However, the patch here seems clear in my opinion.

Reviewers: aadsm, hhb, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: labath, jrm, mgorny, lldb-commits

Tags: #lldb

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

Added: 


Modified: 
lldb/cmake/modules/FindLuaAndSwig.cmake
lldb/cmake/modules/FindPythonInterpAndLibs.cmake

Removed: 




diff  --git a/lldb/cmake/modules/FindLuaAndSwig.cmake 
b/lldb/cmake/modules/FindLuaAndSwig.cmake
index 2e99933a7456..cc9083ce049a 100644
--- a/lldb/cmake/modules/FindLuaAndSwig.cmake
+++ b/lldb/cmake/modules/FindLuaAndSwig.cmake
@@ -7,9 +7,9 @@
 if(LUA_LIBRARIES AND LUA_INCLUDE_DIR AND SWIG_EXECUTABLE)
   set(LUAANDSWIG_FOUND TRUE)
 else()
-  find_package(SWIG 2.0 QUIET)
+  find_package(SWIG 2.0)
   if (SWIG_FOUND)
-find_package(Lua QUIET)
+find_package(Lua)
 if(LUA_FOUND AND SWIG_FOUND)
   mark_as_advanced(
 LUA_LIBRARIES

diff  --git a/lldb/cmake/modules/FindPythonInterpAndLibs.cmake 
b/lldb/cmake/modules/FindPythonInterpAndLibs.cmake
index 858622541015..5c047831a029 100644
--- a/lldb/cmake/modules/FindPythonInterpAndLibs.cmake
+++ b/lldb/cmake/modules/FindPythonInterpAndLibs.cmake
@@ -7,10 +7,10 @@
 if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS AND PYTHON_EXECUTABLE AND 
SWIG_EXECUTABLE)
   set(PYTHONINTERPANDLIBS_FOUND TRUE)
 else()
-  find_package(SWIG 2.0 QUIET)
+  find_package(SWIG 2.0)
   if (SWIG_FOUND)
 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
-  find_package(Python3 COMPONENTS Interpreter Development QUIET)
+  find_package(Python3 COMPONENTS Interpreter Development)
   if (Python3_FOUND AND Python3_Interpreter_FOUND)
 set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
 set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
@@ -22,8 +22,8 @@ else()
   SWIG_EXECUTABLE)
   endif()
 else()
-  find_package(PythonInterp QUIET)
-  find_package(PythonLibs QUIET)
+  find_package(PythonInterp)
+  find_package(PythonLibs)
   if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND)
 if (NOT CMAKE_CROSSCOMPILING)
   string(REPLACE "." ";" pythonlibs_version_list 
${PYTHONLIBS_VERSION_STRING})



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


[Lldb-commits] [PATCH] D74917: [lldb/cmake] Enable more verbose find_package output.

2020-02-21 Thread Matt Davis via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG07d2cdae1163: [lldb/cmake] Enable more verbose find_package 
output. (authored by mattd).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74917/new/

https://reviews.llvm.org/D74917

Files:
  lldb/cmake/modules/FindLuaAndSwig.cmake
  lldb/cmake/modules/FindPythonInterpAndLibs.cmake


Index: lldb/cmake/modules/FindPythonInterpAndLibs.cmake
===
--- lldb/cmake/modules/FindPythonInterpAndLibs.cmake
+++ lldb/cmake/modules/FindPythonInterpAndLibs.cmake
@@ -7,10 +7,10 @@
 if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS AND PYTHON_EXECUTABLE AND 
SWIG_EXECUTABLE)
   set(PYTHONINTERPANDLIBS_FOUND TRUE)
 else()
-  find_package(SWIG 2.0 QUIET)
+  find_package(SWIG 2.0)
   if (SWIG_FOUND)
 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
-  find_package(Python3 COMPONENTS Interpreter Development QUIET)
+  find_package(Python3 COMPONENTS Interpreter Development)
   if (Python3_FOUND AND Python3_Interpreter_FOUND)
 set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
 set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
@@ -22,8 +22,8 @@
   SWIG_EXECUTABLE)
   endif()
 else()
-  find_package(PythonInterp QUIET)
-  find_package(PythonLibs QUIET)
+  find_package(PythonInterp)
+  find_package(PythonLibs)
   if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND)
 if (NOT CMAKE_CROSSCOMPILING)
   string(REPLACE "." ";" pythonlibs_version_list 
${PYTHONLIBS_VERSION_STRING})
Index: lldb/cmake/modules/FindLuaAndSwig.cmake
===
--- lldb/cmake/modules/FindLuaAndSwig.cmake
+++ lldb/cmake/modules/FindLuaAndSwig.cmake
@@ -7,9 +7,9 @@
 if(LUA_LIBRARIES AND LUA_INCLUDE_DIR AND SWIG_EXECUTABLE)
   set(LUAANDSWIG_FOUND TRUE)
 else()
-  find_package(SWIG 2.0 QUIET)
+  find_package(SWIG 2.0)
   if (SWIG_FOUND)
-find_package(Lua QUIET)
+find_package(Lua)
 if(LUA_FOUND AND SWIG_FOUND)
   mark_as_advanced(
 LUA_LIBRARIES


Index: lldb/cmake/modules/FindPythonInterpAndLibs.cmake
===
--- lldb/cmake/modules/FindPythonInterpAndLibs.cmake
+++ lldb/cmake/modules/FindPythonInterpAndLibs.cmake
@@ -7,10 +7,10 @@
 if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS AND PYTHON_EXECUTABLE AND SWIG_EXECUTABLE)
   set(PYTHONINTERPANDLIBS_FOUND TRUE)
 else()
-  find_package(SWIG 2.0 QUIET)
+  find_package(SWIG 2.0)
   if (SWIG_FOUND)
 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
-  find_package(Python3 COMPONENTS Interpreter Development QUIET)
+  find_package(Python3 COMPONENTS Interpreter Development)
   if (Python3_FOUND AND Python3_Interpreter_FOUND)
 set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
 set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
@@ -22,8 +22,8 @@
   SWIG_EXECUTABLE)
   endif()
 else()
-  find_package(PythonInterp QUIET)
-  find_package(PythonLibs QUIET)
+  find_package(PythonInterp)
+  find_package(PythonLibs)
   if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND)
 if (NOT CMAKE_CROSSCOMPILING)
   string(REPLACE "." ";" pythonlibs_version_list ${PYTHONLIBS_VERSION_STRING})
Index: lldb/cmake/modules/FindLuaAndSwig.cmake
===
--- lldb/cmake/modules/FindLuaAndSwig.cmake
+++ lldb/cmake/modules/FindLuaAndSwig.cmake
@@ -7,9 +7,9 @@
 if(LUA_LIBRARIES AND LUA_INCLUDE_DIR AND SWIG_EXECUTABLE)
   set(LUAANDSWIG_FOUND TRUE)
 else()
-  find_package(SWIG 2.0 QUIET)
+  find_package(SWIG 2.0)
   if (SWIG_FOUND)
-find_package(Lua QUIET)
+find_package(Lua)
 if(LUA_FOUND AND SWIG_FOUND)
   mark_as_advanced(
 LUA_LIBRARIES
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D74657: [lldb/Plugins] Add ability to fetch crash information on crashed processes

2020-02-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 245939.
mib marked 6 inline comments as done.
mib edited the summary of this revision.
mib added a comment.

Addressed Pavel's comments.
Add "negative" tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74657/new/

https://reviews.llvm.org/D74657

Files:
  lldb/bindings/interface/SBPlatform.i
  lldb/bindings/interface/SBTarget.i
  lldb/include/lldb/API/SBPlatform.h
  lldb/include/lldb/API/SBStructuredData.h
  lldb/include/lldb/API/SBTarget.h
  lldb/include/lldb/Target/Platform.h
  lldb/include/lldb/Target/Process.h
  lldb/source/API/SBPlatform.cpp
  lldb/source/API/SBTarget.cpp
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Commands/Options.td
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/test/API/functionalities/process_crash_info/Makefile
  lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
  lldb/test/API/functionalities/process_crash_info/main.c

Index: lldb/test/API/functionalities/process_crash_info/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/process_crash_info/main.c
@@ -0,0 +1,7 @@
+#include 
+int main() {
+  int *var = malloc(sizeof(int));
+  free(var);
+  free(var);
+  return 0;
+}
Index: lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
===
--- /dev/null
+++ lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
@@ -0,0 +1,97 @@
+"""
+Test lldb process crash info.
+"""
+
+import os
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class PlatformProcessCrashInfoTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+TestBase.setUp(self)
+self.runCmd("settings set auto-confirm true")
+self.source = "main.c"
+self.line = 3
+
+def tearDown(self):
+self.runCmd("settings clear auto-confirm")
+TestBase.tearDown(self)
+
+@skipUnlessDarwin
+def test_cli(self):
+"""Test that `process status --verbose` fetches the extended crash
+information dictionnary from the command-line properly."""
+self.build()
+exe = self.getBuildArtifact("a.out")
+self.expect("file " + exe,
+patterns=["Current executable set to .*a.out"])
+
+self.expect('process launch',
+patterns=["Process .* launched: .*a.out"])
+
+self.expect('process status --verbose',
+patterns=["\"message\".*pointer being freed was not allocated"])
+
+
+@skipUnlessDarwin
+def test_api(self):
+"""Test that lldb can fetch a crashed process' extended crash information
+dictionnary from the api properly."""
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+target.LaunchSimple(None, None, os.getcwd())
+
+stream = lldb.SBStream()
+self.assertTrue(stream)
+
+crash_info = target.GetExtendedCrashInformation()
+
+error = crash_info.GetAsJSON(stream)
+
+self.assertTrue(error.Success())
+
+self.assertTrue(crash_info.IsValid())
+
+self.assertIn("pointer being freed was not allocated", stream.GetData())
+
+@skipUnlessDarwin
+def test_on_launch(self):
+"""Test that lldb doesn't fetch the extended crash information
+dictionnary from if the process wasn't launched yet."""
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+stream = lldb.SBStream()
+self.assertTrue(stream)
+
+crash_info = target.GetExtendedCrashInformation()
+
+error = crash_info.GetAsJSON(stream)
+self.assertFalse(error.Success())
+self.assertIn("No structured data.", error.GetCString())
+
+@skipUnlessDarwin
+def test_on_sane_process(self):
+"""Test that lldb doesn't fetch the extended crash information
+dictionnary from a 'sane' stopped process."""
+self.build()
+target, _, _, _ = lldbutil.run_to_line_breakpoint(self, lldb.SBFileSpec(self.source),
+self.line)
+
+stream = lldb.SBStream()
+self.assertTrue(stream)
+
+crash_info = target.GetExtendedCrashInformation()
+
+error = crash_info.GetAsJSON(stream)
+self.assertFalse(error.Success())
+self.assertIn("No structured data.", error.GetCString())
Index: lldb/test/API/functionalities/process_crash_info/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/process

[Lldb-commits] [PATCH] D74657: [lldb/Plugins] Add ability to fetch crash information on crashed processes

2020-02-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 245952.
mib added a comment.

Removed old revision artifacts
Renamed `test_on_launch` to `test_before_launch`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74657/new/

https://reviews.llvm.org/D74657

Files:
  lldb/bindings/interface/SBTarget.i
  lldb/include/lldb/API/SBTarget.h
  lldb/include/lldb/Target/Platform.h
  lldb/include/lldb/Target/Process.h
  lldb/source/API/SBTarget.cpp
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Commands/Options.td
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/test/API/functionalities/process_crash_info/Makefile
  lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
  lldb/test/API/functionalities/process_crash_info/main.c

Index: lldb/test/API/functionalities/process_crash_info/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/process_crash_info/main.c
@@ -0,0 +1,7 @@
+#include 
+int main() {
+  int *var = malloc(sizeof(int));
+  free(var);
+  free(var);
+  return 0;
+}
Index: lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
===
--- /dev/null
+++ lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
@@ -0,0 +1,97 @@
+"""
+Test lldb process crash info.
+"""
+
+import os
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class PlatformProcessCrashInfoTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+TestBase.setUp(self)
+self.runCmd("settings set auto-confirm true")
+self.source = "main.c"
+self.line = 3
+
+def tearDown(self):
+self.runCmd("settings clear auto-confirm")
+TestBase.tearDown(self)
+
+@skipUnlessDarwin
+def test_cli(self):
+"""Test that `process status --verbose` fetches the extended crash
+information dictionnary from the command-line properly."""
+self.build()
+exe = self.getBuildArtifact("a.out")
+self.expect("file " + exe,
+patterns=["Current executable set to .*a.out"])
+
+self.expect('process launch',
+patterns=["Process .* launched: .*a.out"])
+
+self.expect('process status --verbose',
+patterns=["\"message\".*pointer being freed was not allocated"])
+
+
+@skipUnlessDarwin
+def test_api(self):
+"""Test that lldb can fetch a crashed process' extended crash information
+dictionnary from the api properly."""
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+target.LaunchSimple(None, None, os.getcwd())
+
+stream = lldb.SBStream()
+self.assertTrue(stream)
+
+crash_info = target.GetExtendedCrashInformation()
+
+error = crash_info.GetAsJSON(stream)
+
+self.assertTrue(error.Success())
+
+self.assertTrue(crash_info.IsValid())
+
+self.assertIn("pointer being freed was not allocated", stream.GetData())
+
+@skipUnlessDarwin
+def test_before_launch(self):
+"""Test that lldb doesn't fetch the extended crash information
+dictionnary from if the process wasn't launched yet."""
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+stream = lldb.SBStream()
+self.assertTrue(stream)
+
+crash_info = target.GetExtendedCrashInformation()
+
+error = crash_info.GetAsJSON(stream)
+self.assertFalse(error.Success())
+self.assertIn("No structured data.", error.GetCString())
+
+@skipUnlessDarwin
+def test_on_sane_process(self):
+"""Test that lldb doesn't fetch the extended crash information
+dictionnary from a 'sane' stopped process."""
+self.build()
+target, _, _, _ = lldbutil.run_to_line_breakpoint(self, lldb.SBFileSpec(self.source),
+self.line)
+
+stream = lldb.SBStream()
+self.assertTrue(stream)
+
+crash_info = target.GetExtendedCrashInformation()
+
+error = crash_info.GetAsJSON(stream)
+self.assertFalse(error.Success())
+self.assertIn("No structured data.", error.GetCString())
Index: lldb/test/API/functionalities/process_crash_info/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/process_crash_info/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+
+include Makefile.rules
+
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
===

[Lldb-commits] [lldb] 0bb9062 - Allow customized relative PYTHONHOME

2020-02-21 Thread Haibo Huang via lldb-commits

Author: Haibo Huang
Date: 2020-02-21T12:49:10-08:00
New Revision: 0bb90628b5f7c170689d2d3f019af773772fc649

URL: 
https://github.com/llvm/llvm-project/commit/0bb90628b5f7c170689d2d3f019af773772fc649
DIFF: 
https://github.com/llvm/llvm-project/commit/0bb90628b5f7c170689d2d3f019af773772fc649.diff

LOG: Allow customized relative PYTHONHOME

Summary:
This change allows a hard coded relative PYTHONHOME setting. So that
python can easily be packaged together with lldb.

The change includes:
1. Extend LLDB_RELOCATABLE_PYTHON to all platforms. It defaults to ON
for platforms other than Windows, to keep the behavior compatible.
2. Allows to customize LLDB_PYTHON_HOME. But still defaults to
PYTHON_HOME.
3. LLDB_PYTHON_HOME can be a path relative to liblldb. If it is
relative, we will resolve it before send it to Py_DecodeLocale.

Subscribers: mgorny, lldb-commits

Tags: #lldb

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

Added: 


Modified: 
lldb/cmake/modules/LLDBConfig.cmake
lldb/include/lldb/Host/Config.h.cmake
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Removed: 




diff  --git a/lldb/cmake/modules/LLDBConfig.cmake 
b/lldb/cmake/modules/LLDBConfig.cmake
index fb4512a87998..6b10f73eff19 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -59,7 +59,6 @@ add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting 
support in LLDB" L
 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in 
LLDB" PythonInterpAndLibs PYTHONINTERPANDLIBS_FOUND)
 add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" 
LibXml2 LIBXML2_FOUND VERSION 2.8)
 
-option(LLDB_RELOCATABLE_PYTHON "Use the PYTHONHOME environment variable to 
locate Python." OFF)
 option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install 
a copy of it" OFF)
 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" 
ON)
 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
@@ -140,10 +139,20 @@ if (LLDB_ENABLE_LIBEDIT)
 endif()
 
 if (LLDB_ENABLE_PYTHON)
+  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+set(default_embed_python_home ON)
+  else()
+set(default_embed_python_home OFF)
+  endif()
+  option(LLDB_EMBED_PYTHON_HOME
+"Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment 
variable will be used to to locate Python."
+${default_embed_python_home})
+
   include_directories(${PYTHON_INCLUDE_DIRS})
-  if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND NOT 
LLDB_RELOCATABLE_PYTHON)
+  if (LLDB_EMBED_PYTHON_HOME)
 get_filename_component(PYTHON_HOME "${PYTHON_EXECUTABLE}" DIRECTORY)
-file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME)
+set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
+  "Path to use as PYTHONHOME in lldb. If a relative path is specified, it 
will be resolved at runtime relative to liblldb directory.")
   endif()
 endif()
 

diff  --git a/lldb/include/lldb/Host/Config.h.cmake 
b/lldb/include/lldb/Host/Config.h.cmake
index e9065ed04caa..42f4ca1a26c6 100644
--- a/lldb/include/lldb/Host/Config.h.cmake
+++ b/lldb/include/lldb/Host/Config.h.cmake
@@ -46,6 +46,8 @@
 
 #cmakedefine01 LLDB_ENABLE_PYTHON
 
+#cmakedefine01 LLDB_EMBED_PYTHON_HOME
+
 #cmakedefine LLDB_PYTHON_HOME "${LLDB_PYTHON_HOME}"
 
 #define LLDB_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}"

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 722af713ba43..f046bcfd18eb 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -277,14 +277,36 @@ struct InitializePythonRAII {
 
 private:
   void InitializePythonHome() {
-#if defined(LLDB_PYTHON_HOME)
+#if LLDB_EMBED_PYTHON_HOME
 #if PY_MAJOR_VERSION >= 3
-size_t size = 0;
-static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size);
+typedef const wchar_t* str_type;
 #else
-static char g_python_home[] = LLDB_PYTHON_HOME;
+typedef char* str_type;
 #endif
-Py_SetPythonHome(g_python_home);
+static str_type g_python_home = []() -> str_type {
+  const char *lldb_python_home = LLDB_PYTHON_HOME;
+  const char *absolute_python_home = nullptr;
+  llvm::SmallString<64> path;
+  if (llvm::sys::path::is_absolute(lldb_python_home)) {
+absolute_python_home = lldb_python_home;
+  } else {
+FileSpec spec = HostInfo::GetShlibDir();
+if (!spec)
+  return nullptr;
+spec.GetPath(path);
+llvm::sys::path::append(path, lldb_python_home);
+absolute_python_home = path.c_str();
+  }
+#if PY_MAJOR_VERSION >= 3
+  size_t size = 0;
+  return Py_DecodeLocale(absolute_python_home, &size);
+#else
+  

[Lldb-commits] [PATCH] D74727: Allow customized relative PYTHONHOME

2020-02-21 Thread Haibo Huang via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0bb90628b5f7: Allow customized relative PYTHONHOME (authored 
by hhb).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74727/new/

https://reviews.llvm.org/D74727

Files:
  lldb/cmake/modules/LLDBConfig.cmake
  lldb/include/lldb/Host/Config.h.cmake
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -277,14 +277,36 @@
 
 private:
   void InitializePythonHome() {
-#if defined(LLDB_PYTHON_HOME)
+#if LLDB_EMBED_PYTHON_HOME
 #if PY_MAJOR_VERSION >= 3
-size_t size = 0;
-static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size);
+typedef const wchar_t* str_type;
 #else
-static char g_python_home[] = LLDB_PYTHON_HOME;
+typedef char* str_type;
 #endif
-Py_SetPythonHome(g_python_home);
+static str_type g_python_home = []() -> str_type {
+  const char *lldb_python_home = LLDB_PYTHON_HOME;
+  const char *absolute_python_home = nullptr;
+  llvm::SmallString<64> path;
+  if (llvm::sys::path::is_absolute(lldb_python_home)) {
+absolute_python_home = lldb_python_home;
+  } else {
+FileSpec spec = HostInfo::GetShlibDir();
+if (!spec)
+  return nullptr;
+spec.GetPath(path);
+llvm::sys::path::append(path, lldb_python_home);
+absolute_python_home = path.c_str();
+  }
+#if PY_MAJOR_VERSION >= 3
+  size_t size = 0;
+  return Py_DecodeLocale(absolute_python_home, &size);
+#else
+  return strdup(absolute_python_home);
+#endif
+}();
+if (g_python_home != nullptr) {
+  Py_SetPythonHome(g_python_home);
+}
 #else
 #if defined(__APPLE__) && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7
 // For Darwin, the only Python version supported is the one shipped in the
Index: lldb/include/lldb/Host/Config.h.cmake
===
--- lldb/include/lldb/Host/Config.h.cmake
+++ lldb/include/lldb/Host/Config.h.cmake
@@ -46,6 +46,8 @@
 
 #cmakedefine01 LLDB_ENABLE_PYTHON
 
+#cmakedefine01 LLDB_EMBED_PYTHON_HOME
+
 #cmakedefine LLDB_PYTHON_HOME "${LLDB_PYTHON_HOME}"
 
 #define LLDB_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}"
Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -59,7 +59,6 @@
 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in 
LLDB" PythonInterpAndLibs PYTHONINTERPANDLIBS_FOUND)
 add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" 
LibXml2 LIBXML2_FOUND VERSION 2.8)
 
-option(LLDB_RELOCATABLE_PYTHON "Use the PYTHONHOME environment variable to 
locate Python." OFF)
 option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install 
a copy of it" OFF)
 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" 
ON)
 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
@@ -140,10 +139,20 @@
 endif()
 
 if (LLDB_ENABLE_PYTHON)
+  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+set(default_embed_python_home ON)
+  else()
+set(default_embed_python_home OFF)
+  endif()
+  option(LLDB_EMBED_PYTHON_HOME
+"Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment 
variable will be used to to locate Python."
+${default_embed_python_home})
+
   include_directories(${PYTHON_INCLUDE_DIRS})
-  if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND NOT 
LLDB_RELOCATABLE_PYTHON)
+  if (LLDB_EMBED_PYTHON_HOME)
 get_filename_component(PYTHON_HOME "${PYTHON_EXECUTABLE}" DIRECTORY)
-file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME)
+set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
+  "Path to use as PYTHONHOME in lldb. If a relative path is specified, it 
will be resolved at runtime relative to liblldb directory.")
   endif()
 endif()
 


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -277,14 +277,36 @@
 
 private:
   void InitializePythonHome() {
-#if defined(LLDB_PYTHON_HOME)
+#if LLDB_EMBED_PYTHON_HOME
 #if PY_MAJOR_VERSION >= 3
-size_t size = 0;
-static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size);
+typedef const wchar_t* str_type;
 #else
-static char g_python_home[] = LLDB_PYTHON_HOME;
+typedef char* str_type;
 #endif
-  

[Lldb-commits] [PATCH] D74727: Allow customized relative PYTHONHOME

2020-02-21 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

It looks like this broke the Windows LLDB Buildbot:

http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/14048/steps/build/logs/stdio


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74727/new/

https://reviews.llvm.org/D74727



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


[Lldb-commits] [PATCH] D74657: [lldb/Plugins] Add ability to fetch crash information on crashed processes

2020-02-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.

LGTM'ing for Pavel by proxy as discussed on IRC.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74657/new/

https://reviews.llvm.org/D74657



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


[Lldb-commits] [lldb] d7c403e - [lldb/Plugins] Add ability to fetch crash information on crashed processes

2020-02-21 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2020-02-21T22:44:36+01:00
New Revision: d7c403e64043281b9c5883e3e034da5ebaf4985a

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

LOG: [lldb/Plugins] Add ability to fetch crash information on crashed processes

Currently, in macOS, when a process crashes, lldb halts inside the
implementation disassembly without yielding any useful information.
The only way to get more information is to detach from the process, then wait
for ReportCrash to generate a report, find the report, then see what error
message was included in it. Instead of waiting for this to happen, lldb could
locate the error_string and make it available to the user.

This patch addresses this issue by enabling the user to fetch extended
crash information for crashed processes using `process status --verbose`.

Depending on the platform, this will try to gather different crash information
into an structured data dictionnary. This dictionnary is generic and extensible,
as it contains an array for each different type of crash information.

On Darwin Platforms, lldb will iterate over each of the target's images,
extract their `__crash_info` section and generated a StructuredData::Array
containing, in each entry, the module spec, its UUID, the crash messages
and the abort cause. The array will be inserted into the platform's
`m_extended_crash_info` dictionnary and `FetchExtendedCrashInformation` will
return its JSON representation like this:

```
{
  "crash-info annotations": [
{
  "abort-cause": 0,
  "image": "/usr/lib/system/libsystem_malloc.dylib",
  "message": "main(76483,0x1000cedc0) malloc: *** error for object 
0x1003040a0: pointer being freed was not allocated",
  "message2": "",
  "uuid": "5747D0C9-900D-3306-8D70-1E2EA4B7E821"
},
...
  ],
  ...
}
```

This crash information can also be fetched using the SB API or lldb-rpc protocol
using SBTarget::GetExtendedCrashInformation().

rdar://37736535

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

Signed-off-by: Med Ismail Bennani 

Added: 
lldb/test/API/functionalities/process_crash_info/Makefile
lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
lldb/test/API/functionalities/process_crash_info/main.c

Modified: 
lldb/bindings/interface/SBTarget.i
lldb/include/lldb/API/SBTarget.h
lldb/include/lldb/Target/Platform.h
lldb/include/lldb/Target/Process.h
lldb/source/API/SBTarget.cpp
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Commands/Options.td
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h

Removed: 




diff  --git a/lldb/bindings/interface/SBTarget.i 
b/lldb/bindings/interface/SBTarget.i
index 371bf5c35ebd..aec7ab94942a 100644
--- a/lldb/bindings/interface/SBTarget.i
+++ b/lldb/bindings/interface/SBTarget.i
@@ -949,6 +949,12 @@ public:
 void
 SetLaunchInfo (const lldb::SBLaunchInfo &launch_info);
 
+%feature("autodoc", "
+Returns the platform's process extended crash information.") 
GetExtendedCrashInformation;
+lldb::SBStructuredData
+GetExtendedCrashInformation ();
+
+
 void SetCollectingStats(bool v);
 
 bool GetCollectingStats();

diff  --git a/lldb/include/lldb/API/SBTarget.h 
b/lldb/include/lldb/API/SBTarget.h
index c950c12daf17..f95c89d9a47a 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -819,6 +819,8 @@ class LLDB_API SBTarget {
 
   void SetLaunchInfo(const lldb::SBLaunchInfo &launch_info);
 
+  SBStructuredData GetExtendedCrashInformation();
+
 protected:
   friend class SBAddress;
   friend class SBBlock;
@@ -829,6 +831,7 @@ class LLDB_API SBTarget {
   friend class SBFunction;
   friend class SBInstruction;
   friend class SBModule;
+  friend class SBPlatform;
   friend class SBProcess;
   friend class SBSection;
   friend class SBSourceManager;

diff  --git a/lldb/include/lldb/Target/Platform.h 
b/lldb/include/lldb/Target/Platform.h
index 2431f94644d1..79bbc130ef86 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -23,6 +23,7 @@
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/StructuredData.h"
 #include "lldb/Utility/Timeout.h"
 #include "lldb/Utility/UserIDResolver.h"
 #include "lldb/lldb-private-forward.h"
@@ -823,6 +824,26 @@ class Platform : public PluginInterface {
   virtual size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger,
lldb_private::Status &error);
 
+  /// Gather all of crash informations into a structured data dictionnary.
+  ///
+  /// If the platform have a crashed process 

[Lldb-commits] [lldb] 1f04d1b - [lldb/test] Move `platform process list` tests to its own directory (NFC)

2020-02-21 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2020-02-21T22:44:36+01:00
New Revision: 1f04d1b7069bf6c513526f36b8c7327c8dec6604

URL: 
https://github.com/llvm/llvm-project/commit/1f04d1b7069bf6c513526f36b8c7327c8dec6604
DIFF: 
https://github.com/llvm/llvm-project/commit/1f04d1b7069bf6c513526f36b8c7327c8dec6604.diff

LOG: [lldb/test] Move `platform process list` tests to its own directory (NFC)

Since the `platform process` commamnd has more tests now, this commits
separates each of the `platform process` subcommand's test in its own directory.

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

Signed-off-by: Med Ismail Bennani 

Added: 
lldb/test/API/commands/platform/process/list/Makefile
lldb/test/API/commands/platform/process/list/TestProcessList.py
lldb/test/API/commands/platform/process/list/main.cpp

Modified: 


Removed: 
lldb/test/API/commands/platform/process/Makefile
lldb/test/API/commands/platform/process/TestProcessList.py
lldb/test/API/commands/platform/process/main.cpp



diff  --git a/lldb/test/API/commands/platform/process/Makefile 
b/lldb/test/API/commands/platform/process/list/Makefile
similarity index 100%
rename from lldb/test/API/commands/platform/process/Makefile
rename to lldb/test/API/commands/platform/process/list/Makefile

diff  --git a/lldb/test/API/commands/platform/process/TestProcessList.py 
b/lldb/test/API/commands/platform/process/list/TestProcessList.py
similarity index 100%
rename from lldb/test/API/commands/platform/process/TestProcessList.py
rename to lldb/test/API/commands/platform/process/list/TestProcessList.py

diff  --git a/lldb/test/API/commands/platform/process/main.cpp 
b/lldb/test/API/commands/platform/process/list/main.cpp
similarity index 100%
rename from lldb/test/API/commands/platform/process/main.cpp
rename to lldb/test/API/commands/platform/process/list/main.cpp



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


[Lldb-commits] [PATCH] D74836: [lldb/test] Move `platform process list` tests to its own directory (NFC)

2020-02-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1f04d1b7069b: [lldb/test] Move `platform process list` tests 
to its own directory (NFC) (authored by mib).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74836/new/

https://reviews.llvm.org/D74836

Files:
  lldb/test/API/commands/platform/process/Makefile
  lldb/test/API/commands/platform/process/TestProcessList.py
  lldb/test/API/commands/platform/process/list/Makefile
  lldb/test/API/commands/platform/process/list/TestProcessList.py
  lldb/test/API/commands/platform/process/list/main.cpp
  lldb/test/API/commands/platform/process/main.cpp




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


[Lldb-commits] [PATCH] D74657: [lldb/Plugins] Add ability to fetch crash information on crashed processes

2020-02-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd7c403e64043: [lldb/Plugins] Add ability to fetch crash 
information on crashed processes (authored by mib).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74657/new/

https://reviews.llvm.org/D74657

Files:
  lldb/bindings/interface/SBTarget.i
  lldb/include/lldb/API/SBTarget.h
  lldb/include/lldb/Target/Platform.h
  lldb/include/lldb/Target/Process.h
  lldb/source/API/SBTarget.cpp
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Commands/Options.td
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/test/API/functionalities/process_crash_info/Makefile
  lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
  lldb/test/API/functionalities/process_crash_info/main.c

Index: lldb/test/API/functionalities/process_crash_info/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/process_crash_info/main.c
@@ -0,0 +1,7 @@
+#include 
+int main() {
+  int *var = malloc(sizeof(int));
+  free(var);
+  free(var);
+  return 0;
+}
Index: lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
===
--- /dev/null
+++ lldb/test/API/functionalities/process_crash_info/TestProcessCrashInfo.py
@@ -0,0 +1,97 @@
+"""
+Test lldb process crash info.
+"""
+
+import os
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class PlatformProcessCrashInfoTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+TestBase.setUp(self)
+self.runCmd("settings set auto-confirm true")
+self.source = "main.c"
+self.line = 3
+
+def tearDown(self):
+self.runCmd("settings clear auto-confirm")
+TestBase.tearDown(self)
+
+@skipUnlessDarwin
+def test_cli(self):
+"""Test that `process status --verbose` fetches the extended crash
+information dictionnary from the command-line properly."""
+self.build()
+exe = self.getBuildArtifact("a.out")
+self.expect("file " + exe,
+patterns=["Current executable set to .*a.out"])
+
+self.expect('process launch',
+patterns=["Process .* launched: .*a.out"])
+
+self.expect('process status --verbose',
+patterns=["\"message\".*pointer being freed was not allocated"])
+
+
+@skipUnlessDarwin
+def test_api(self):
+"""Test that lldb can fetch a crashed process' extended crash information
+dictionnary from the api properly."""
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+target.LaunchSimple(None, None, os.getcwd())
+
+stream = lldb.SBStream()
+self.assertTrue(stream)
+
+crash_info = target.GetExtendedCrashInformation()
+
+error = crash_info.GetAsJSON(stream)
+
+self.assertTrue(error.Success())
+
+self.assertTrue(crash_info.IsValid())
+
+self.assertIn("pointer being freed was not allocated", stream.GetData())
+
+@skipUnlessDarwin
+def test_before_launch(self):
+"""Test that lldb doesn't fetch the extended crash information
+dictionnary from if the process wasn't launched yet."""
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+stream = lldb.SBStream()
+self.assertTrue(stream)
+
+crash_info = target.GetExtendedCrashInformation()
+
+error = crash_info.GetAsJSON(stream)
+self.assertFalse(error.Success())
+self.assertIn("No structured data.", error.GetCString())
+
+@skipUnlessDarwin
+def test_on_sane_process(self):
+"""Test that lldb doesn't fetch the extended crash information
+dictionnary from a 'sane' stopped process."""
+self.build()
+target, _, _, _ = lldbutil.run_to_line_breakpoint(self, lldb.SBFileSpec(self.source),
+self.line)
+
+stream = lldb.SBStream()
+self.assertTrue(stream)
+
+crash_info = target.GetExtendedCrashInformation()
+
+error = crash_info.GetAsJSON(stream)
+self.assertFalse(error.Success())
+self.assertIn("No structured data.", error.GetCString())
Index: lldb/test/API/functionalities/process_crash_info/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/process_crash_info/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c

[Lldb-commits] [lldb] 215a311 - Revert "Allow customized relative PYTHONHOME"

2020-02-21 Thread Stella Stamenova via lldb-commits

Author: Stella Stamenova
Date: 2020-02-21T14:57:00-08:00
New Revision: 215a31115f89c851331a822e67aa4528ba5c21e6

URL: 
https://github.com/llvm/llvm-project/commit/215a31115f89c851331a822e67aa4528ba5c21e6
DIFF: 
https://github.com/llvm/llvm-project/commit/215a31115f89c851331a822e67aa4528ba5c21e6.diff

LOG: Revert "Allow customized relative PYTHONHOME"

This reverts commit 0bb90628b5f7c170689d2d3f019af773772fc649 since it is 
causing failures on the Windows LLDB buildbot:

http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/14048

Added: 


Modified: 
lldb/cmake/modules/LLDBConfig.cmake
lldb/include/lldb/Host/Config.h.cmake
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Removed: 




diff  --git a/lldb/cmake/modules/LLDBConfig.cmake 
b/lldb/cmake/modules/LLDBConfig.cmake
index 6b10f73eff19..fb4512a87998 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -59,6 +59,7 @@ add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting 
support in LLDB" L
 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in 
LLDB" PythonInterpAndLibs PYTHONINTERPANDLIBS_FOUND)
 add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" 
LibXml2 LIBXML2_FOUND VERSION 2.8)
 
+option(LLDB_RELOCATABLE_PYTHON "Use the PYTHONHOME environment variable to 
locate Python." OFF)
 option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install 
a copy of it" OFF)
 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" 
ON)
 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
@@ -139,20 +140,10 @@ if (LLDB_ENABLE_LIBEDIT)
 endif()
 
 if (LLDB_ENABLE_PYTHON)
-  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
-set(default_embed_python_home ON)
-  else()
-set(default_embed_python_home OFF)
-  endif()
-  option(LLDB_EMBED_PYTHON_HOME
-"Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment 
variable will be used to to locate Python."
-${default_embed_python_home})
-
   include_directories(${PYTHON_INCLUDE_DIRS})
-  if (LLDB_EMBED_PYTHON_HOME)
+  if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND NOT 
LLDB_RELOCATABLE_PYTHON)
 get_filename_component(PYTHON_HOME "${PYTHON_EXECUTABLE}" DIRECTORY)
-set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
-  "Path to use as PYTHONHOME in lldb. If a relative path is specified, it 
will be resolved at runtime relative to liblldb directory.")
+file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME)
   endif()
 endif()
 

diff  --git a/lldb/include/lldb/Host/Config.h.cmake 
b/lldb/include/lldb/Host/Config.h.cmake
index 42f4ca1a26c6..e9065ed04caa 100644
--- a/lldb/include/lldb/Host/Config.h.cmake
+++ b/lldb/include/lldb/Host/Config.h.cmake
@@ -46,8 +46,6 @@
 
 #cmakedefine01 LLDB_ENABLE_PYTHON
 
-#cmakedefine01 LLDB_EMBED_PYTHON_HOME
-
 #cmakedefine LLDB_PYTHON_HOME "${LLDB_PYTHON_HOME}"
 
 #define LLDB_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}"

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index f046bcfd18eb..722af713ba43 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -277,36 +277,14 @@ struct InitializePythonRAII {
 
 private:
   void InitializePythonHome() {
-#if LLDB_EMBED_PYTHON_HOME
+#if defined(LLDB_PYTHON_HOME)
 #if PY_MAJOR_VERSION >= 3
-typedef const wchar_t* str_type;
+size_t size = 0;
+static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size);
 #else
-typedef char* str_type;
+static char g_python_home[] = LLDB_PYTHON_HOME;
 #endif
-static str_type g_python_home = []() -> str_type {
-  const char *lldb_python_home = LLDB_PYTHON_HOME;
-  const char *absolute_python_home = nullptr;
-  llvm::SmallString<64> path;
-  if (llvm::sys::path::is_absolute(lldb_python_home)) {
-absolute_python_home = lldb_python_home;
-  } else {
-FileSpec spec = HostInfo::GetShlibDir();
-if (!spec)
-  return nullptr;
-spec.GetPath(path);
-llvm::sys::path::append(path, lldb_python_home);
-absolute_python_home = path.c_str();
-  }
-#if PY_MAJOR_VERSION >= 3
-  size_t size = 0;
-  return Py_DecodeLocale(absolute_python_home, &size);
-#else
-  return strdup(absolute_python_home);
-#endif
-}();
-if (g_python_home != nullptr) {
-  Py_SetPythonHome(g_python_home);
-}
+Py_SetPythonHome(g_python_home);
 #else
 #if defined(__APPLE__) && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7
 // For Darwin, the only Python version supported is the one shipped in the



___
lldb-commits mailing list

[Lldb-commits] [lldb] 8a0f0e2 - [lldb/test] Tweak libcxx string test on Apple+ARM devices

2020-02-21 Thread Vedant Kumar via lldb-commits

Author: Vedant Kumar
Date: 2020-02-21T15:54:38-08:00
New Revision: 8a0f0e2656abf76b771037c6543caf9a31744120

URL: 
https://github.com/llvm/llvm-project/commit/8a0f0e2656abf76b771037c6543caf9a31744120
DIFF: 
https://github.com/llvm/llvm-project/commit/8a0f0e2656abf76b771037c6543caf9a31744120.diff

LOG: [lldb/test] Tweak libcxx string test on Apple+ARM devices

On Apple platforms, is __arm__ isn't defined and we're not on Intel, we use an
alternate std::string layout. I.e., the libcxx string test fails on phones
because the hand-crafted "garbage" string structs are actually valid strings.

See:

```
  // _LIBCPP_ALTERNATE_STRING_LAYOUT is an old name for
  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility.
  #if (defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) &&  
 \
   (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)) ||  
 \
  defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
  #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  #endif
```

Disable inspection of the garbage structs on Apple+ARM devices.

Added: 


Modified: 

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
index 3753067113b1..c6f95d7e8593 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
@@ -116,7 +116,9 @@ def cleanup():
 '%s::allocator >) uchar = "a"'%(ns,ns,ns),
 ])
 
-if is_64_bit:
+# The test assumes that std::string is in its cap-size-data layout.
+is_alternate_layout = ('arm' in self.getArchitecture()) and 
self.platformIsDarwin()
+if is_64_bit and not is_alternate_layout:
 self.expect("frame variable garbage1", substrs=['garbage1 = 
Summary Unavailable'])
 self.expect("frame variable garbage2", substrs=['garbage2 = 
Summary Unavailable'])
 self.expect("frame variable garbage3", substrs=['garbage3 = 
Summary Unavailable'])



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


[Lldb-commits] [PATCH] D74998: Allow customized relative PYTHONHOME (Attemp 1)

2020-02-21 Thread Haibo Huang via Phabricator via lldb-commits
hhb created this revision.
Herald added subscribers: lldb-commits, mgorny.
Herald added a project: LLDB.

This is another attempt of 0bb90628b5f7c170689d2d3f019af773772fc649 
.

The difference is that g_python_home is not declared as const. Since
some versions of python do not expect that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74998

Files:
  lldb/cmake/modules/LLDBConfig.cmake
  lldb/include/lldb/Host/Config.h.cmake
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -277,14 +277,36 @@
 
 private:
   void InitializePythonHome() {
-#if defined(LLDB_PYTHON_HOME)
+#if LLDB_EMBED_PYTHON_HOME
 #if PY_MAJOR_VERSION >= 3
-size_t size = 0;
-static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size);
+typedef wchar_t* str_type;
 #else
-static char g_python_home[] = LLDB_PYTHON_HOME;
+typedef char* str_type;
 #endif
-Py_SetPythonHome(g_python_home);
+static str_type g_python_home = []() -> str_type {
+  const char *lldb_python_home = LLDB_PYTHON_HOME;
+  const char *absolute_python_home = nullptr;
+  llvm::SmallString<64> path;
+  if (llvm::sys::path::is_absolute(lldb_python_home)) {
+absolute_python_home = lldb_python_home;
+  } else {
+FileSpec spec = HostInfo::GetShlibDir();
+if (!spec)
+  return nullptr;
+spec.GetPath(path);
+llvm::sys::path::append(path, lldb_python_home);
+absolute_python_home = path.c_str();
+  }
+#if PY_MAJOR_VERSION >= 3
+  size_t size = 0;
+  return Py_DecodeLocale(absolute_python_home, &size);
+#else
+  return strdup(absolute_python_home);
+#endif
+}();
+if (g_python_home != nullptr) {
+  Py_SetPythonHome(g_python_home);
+}
 #else
 #if defined(__APPLE__) && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7
 // For Darwin, the only Python version supported is the one shipped in the
Index: lldb/include/lldb/Host/Config.h.cmake
===
--- lldb/include/lldb/Host/Config.h.cmake
+++ lldb/include/lldb/Host/Config.h.cmake
@@ -46,6 +46,8 @@
 
 #cmakedefine01 LLDB_ENABLE_PYTHON
 
+#cmakedefine01 LLDB_EMBED_PYTHON_HOME
+
 #cmakedefine LLDB_PYTHON_HOME "${LLDB_PYTHON_HOME}"
 
 #define LLDB_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}"
Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -59,7 +59,6 @@
 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in 
LLDB" PythonInterpAndLibs PYTHONINTERPANDLIBS_FOUND)
 add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" 
LibXml2 LIBXML2_FOUND VERSION 2.8)
 
-option(LLDB_RELOCATABLE_PYTHON "Use the PYTHONHOME environment variable to 
locate Python." OFF)
 option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install 
a copy of it" OFF)
 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" 
ON)
 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
@@ -140,10 +139,20 @@
 endif()
 
 if (LLDB_ENABLE_PYTHON)
+  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+set(default_embed_python_home ON)
+  else()
+set(default_embed_python_home OFF)
+  endif()
+  option(LLDB_EMBED_PYTHON_HOME
+"Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment 
variable will be used to to locate Python."
+${default_embed_python_home})
+
   include_directories(${PYTHON_INCLUDE_DIRS})
-  if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND NOT 
LLDB_RELOCATABLE_PYTHON)
+  if (LLDB_EMBED_PYTHON_HOME)
 get_filename_component(PYTHON_HOME "${PYTHON_EXECUTABLE}" DIRECTORY)
-file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME)
+set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
+  "Path to use as PYTHONHOME in lldb. If a relative path is specified, it 
will be resolved at runtime relative to liblldb directory.")
   endif()
 endif()
 


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -277,14 +277,36 @@
 
 private:
   void InitializePythonHome() {
-#if defined(LLDB_PYTHON_HOME)
+#if LLDB_EMBED_PYTHON_HOME
 #if PY_MAJOR_VERSION >= 3
-size_t size = 0;
-static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size);
+typedef 

Re: [Lldb-commits] [lldb] 8a0f0e2 - [lldb/test] Tweak libcxx string test on Apple+ARM devices

2020-02-21 Thread Davidino Italiano via lldb-commits


> On Feb 21, 2020, at 3:54 PM, Vedant Kumar via lldb-commits 
>  wrote:
> 
> 
> Author: Vedant Kumar
> Date: 2020-02-21T15:54:38-08:00
> New Revision: 8a0f0e2656abf76b771037c6543caf9a31744120
> 
> URL: 
> https://github.com/llvm/llvm-project/commit/8a0f0e2656abf76b771037c6543caf9a31744120
> DIFF: 
> https://github.com/llvm/llvm-project/commit/8a0f0e2656abf76b771037c6543caf9a31744120.diff
> 
> LOG: [lldb/test] Tweak libcxx string test on Apple+ARM devices
> 
> On Apple platforms, is __arm__ isn't defined and we're not on Intel, we use an
> alternate std::string layout. I.e., the libcxx string test fails on phones
> because the hand-crafted "garbage" string structs are actually valid strings.
> 
> See:
> 
> ```
>  // _LIBCPP_ALTERNATE_STRING_LAYOUT is an old name for
>  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility.
>  #if (defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && 
>   \
>   (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)) || 
>   \
>  defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
>  #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
>  #endif
> ```
> 
> Disable inspection of the garbage structs on Apple+ARM devices.
> 
> Added: 
> 
> 
> Modified: 
>
> lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
> 
> Removed: 
> 
> 

Thank you for the commit message. We (me in particular) historically have been 
bad at this but this is an example of something great for archeology.

> 
> 
> diff  --git 
> a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
>  
> b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
> index 3753067113b1..c6f95d7e8593 100644
> --- 
> a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
> +++ 
> b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
> @@ -116,7 +116,9 @@ def cleanup():
> '%s::allocator >) uchar = "a"'%(ns,ns,ns),
> ])
> 
> -if is_64_bit:
> +# The test assumes that std::string is in its cap-size-data layout.
> +is_alternate_layout = ('arm' in self.getArchitecture()) and 
> self.platformIsDarwin()
> +if is_64_bit and not is_alternate_layout:
> self.expect("frame variable garbage1", substrs=['garbage1 = 
> Summary Unavailable'])
> self.expect("frame variable garbage2", substrs=['garbage2 = 
> Summary Unavailable'])
> self.expect("frame variable garbage3", substrs=['garbage3 = 
> Summary Unavailable'])
> 
> 
> 
> ___
> lldb-commits mailing list
> lldb-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

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


[Lldb-commits] [lldb] 3ec3f62 - Allow customized relative PYTHONHOME (Attemp 1)

2020-02-21 Thread Haibo Huang via lldb-commits

Author: Haibo Huang
Date: 2020-02-21T16:25:30-08:00
New Revision: 3ec3f62f0a0b1ac13230922c91ffc988c1b1e8d5

URL: 
https://github.com/llvm/llvm-project/commit/3ec3f62f0a0b1ac13230922c91ffc988c1b1e8d5
DIFF: 
https://github.com/llvm/llvm-project/commit/3ec3f62f0a0b1ac13230922c91ffc988c1b1e8d5.diff

LOG: Allow customized relative PYTHONHOME (Attemp 1)

Summary:
This is another attempt of 0bb90628b5f7c170689d2d3f019af773772fc649.

The difference is that g_python_home is not declared as const. Since
some versions of python do not expect that.

Subscribers: mgorny, lldb-commits

Tags: #lldb

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

Added: 


Modified: 
lldb/cmake/modules/LLDBConfig.cmake
lldb/include/lldb/Host/Config.h.cmake
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Removed: 




diff  --git a/lldb/cmake/modules/LLDBConfig.cmake 
b/lldb/cmake/modules/LLDBConfig.cmake
index fb4512a87998..6b10f73eff19 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -59,7 +59,6 @@ add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting 
support in LLDB" L
 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in 
LLDB" PythonInterpAndLibs PYTHONINTERPANDLIBS_FOUND)
 add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" 
LibXml2 LIBXML2_FOUND VERSION 2.8)
 
-option(LLDB_RELOCATABLE_PYTHON "Use the PYTHONHOME environment variable to 
locate Python." OFF)
 option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install 
a copy of it" OFF)
 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" 
ON)
 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
@@ -140,10 +139,20 @@ if (LLDB_ENABLE_LIBEDIT)
 endif()
 
 if (LLDB_ENABLE_PYTHON)
+  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+set(default_embed_python_home ON)
+  else()
+set(default_embed_python_home OFF)
+  endif()
+  option(LLDB_EMBED_PYTHON_HOME
+"Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment 
variable will be used to to locate Python."
+${default_embed_python_home})
+
   include_directories(${PYTHON_INCLUDE_DIRS})
-  if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND NOT 
LLDB_RELOCATABLE_PYTHON)
+  if (LLDB_EMBED_PYTHON_HOME)
 get_filename_component(PYTHON_HOME "${PYTHON_EXECUTABLE}" DIRECTORY)
-file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME)
+set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
+  "Path to use as PYTHONHOME in lldb. If a relative path is specified, it 
will be resolved at runtime relative to liblldb directory.")
   endif()
 endif()
 

diff  --git a/lldb/include/lldb/Host/Config.h.cmake 
b/lldb/include/lldb/Host/Config.h.cmake
index e9065ed04caa..42f4ca1a26c6 100644
--- a/lldb/include/lldb/Host/Config.h.cmake
+++ b/lldb/include/lldb/Host/Config.h.cmake
@@ -46,6 +46,8 @@
 
 #cmakedefine01 LLDB_ENABLE_PYTHON
 
+#cmakedefine01 LLDB_EMBED_PYTHON_HOME
+
 #cmakedefine LLDB_PYTHON_HOME "${LLDB_PYTHON_HOME}"
 
 #define LLDB_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}"

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 722af713ba43..3e93ddbf18c8 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -277,14 +277,36 @@ struct InitializePythonRAII {
 
 private:
   void InitializePythonHome() {
-#if defined(LLDB_PYTHON_HOME)
+#if LLDB_EMBED_PYTHON_HOME
 #if PY_MAJOR_VERSION >= 3
-size_t size = 0;
-static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size);
+typedef wchar_t* str_type;
 #else
-static char g_python_home[] = LLDB_PYTHON_HOME;
+typedef char* str_type;
 #endif
-Py_SetPythonHome(g_python_home);
+static str_type g_python_home = []() -> str_type {
+  const char *lldb_python_home = LLDB_PYTHON_HOME;
+  const char *absolute_python_home = nullptr;
+  llvm::SmallString<64> path;
+  if (llvm::sys::path::is_absolute(lldb_python_home)) {
+absolute_python_home = lldb_python_home;
+  } else {
+FileSpec spec = HostInfo::GetShlibDir();
+if (!spec)
+  return nullptr;
+spec.GetPath(path);
+llvm::sys::path::append(path, lldb_python_home);
+absolute_python_home = path.c_str();
+  }
+#if PY_MAJOR_VERSION >= 3
+  size_t size = 0;
+  return Py_DecodeLocale(absolute_python_home, &size);
+#else
+  return strdup(absolute_python_home);
+#endif
+}();
+if (g_python_home != nullptr) {
+  Py_SetPythonHome(g_python_home);
+}
 #else
 #if defined(__APPLE__) && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7
 // For Darwin, the only Python version supported is the one shipp

[Lldb-commits] [PATCH] D74998: Allow customized relative PYTHONHOME (Attemp 1)

2020-02-21 Thread Haibo Huang via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3ec3f62f0a0b: Allow customized relative PYTHONHOME (Attemp 
1) (authored by hhb).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74998/new/

https://reviews.llvm.org/D74998

Files:
  lldb/cmake/modules/LLDBConfig.cmake
  lldb/include/lldb/Host/Config.h.cmake
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -277,14 +277,36 @@
 
 private:
   void InitializePythonHome() {
-#if defined(LLDB_PYTHON_HOME)
+#if LLDB_EMBED_PYTHON_HOME
 #if PY_MAJOR_VERSION >= 3
-size_t size = 0;
-static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size);
+typedef wchar_t* str_type;
 #else
-static char g_python_home[] = LLDB_PYTHON_HOME;
+typedef char* str_type;
 #endif
-Py_SetPythonHome(g_python_home);
+static str_type g_python_home = []() -> str_type {
+  const char *lldb_python_home = LLDB_PYTHON_HOME;
+  const char *absolute_python_home = nullptr;
+  llvm::SmallString<64> path;
+  if (llvm::sys::path::is_absolute(lldb_python_home)) {
+absolute_python_home = lldb_python_home;
+  } else {
+FileSpec spec = HostInfo::GetShlibDir();
+if (!spec)
+  return nullptr;
+spec.GetPath(path);
+llvm::sys::path::append(path, lldb_python_home);
+absolute_python_home = path.c_str();
+  }
+#if PY_MAJOR_VERSION >= 3
+  size_t size = 0;
+  return Py_DecodeLocale(absolute_python_home, &size);
+#else
+  return strdup(absolute_python_home);
+#endif
+}();
+if (g_python_home != nullptr) {
+  Py_SetPythonHome(g_python_home);
+}
 #else
 #if defined(__APPLE__) && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7
 // For Darwin, the only Python version supported is the one shipped in the
Index: lldb/include/lldb/Host/Config.h.cmake
===
--- lldb/include/lldb/Host/Config.h.cmake
+++ lldb/include/lldb/Host/Config.h.cmake
@@ -46,6 +46,8 @@
 
 #cmakedefine01 LLDB_ENABLE_PYTHON
 
+#cmakedefine01 LLDB_EMBED_PYTHON_HOME
+
 #cmakedefine LLDB_PYTHON_HOME "${LLDB_PYTHON_HOME}"
 
 #define LLDB_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}"
Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -59,7 +59,6 @@
 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in 
LLDB" PythonInterpAndLibs PYTHONINTERPANDLIBS_FOUND)
 add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" 
LibXml2 LIBXML2_FOUND VERSION 2.8)
 
-option(LLDB_RELOCATABLE_PYTHON "Use the PYTHONHOME environment variable to 
locate Python." OFF)
 option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install 
a copy of it" OFF)
 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" 
ON)
 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
@@ -140,10 +139,20 @@
 endif()
 
 if (LLDB_ENABLE_PYTHON)
+  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+set(default_embed_python_home ON)
+  else()
+set(default_embed_python_home OFF)
+  endif()
+  option(LLDB_EMBED_PYTHON_HOME
+"Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment 
variable will be used to to locate Python."
+${default_embed_python_home})
+
   include_directories(${PYTHON_INCLUDE_DIRS})
-  if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND NOT 
LLDB_RELOCATABLE_PYTHON)
+  if (LLDB_EMBED_PYTHON_HOME)
 get_filename_component(PYTHON_HOME "${PYTHON_EXECUTABLE}" DIRECTORY)
-file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME)
+set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
+  "Path to use as PYTHONHOME in lldb. If a relative path is specified, it 
will be resolved at runtime relative to liblldb directory.")
   endif()
 endif()
 


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -277,14 +277,36 @@
 
 private:
   void InitializePythonHome() {
-#if defined(LLDB_PYTHON_HOME)
+#if LLDB_EMBED_PYTHON_HOME
 #if PY_MAJOR_VERSION >= 3
-size_t size = 0;
-static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size);
+typedef wchar_t* str_type;
 #else
-static

[Lldb-commits] [PATCH] D74964: [lldb/DWARF] Don't index dwp file multiple times

2020-02-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

Seems straightforward.




Comment at: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h:66
 
   /// Non-null value means we haven't built the index yet.
+  SymbolFileDWARF *m_dwarf;

This seems inverted? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74964/new/

https://reviews.llvm.org/D74964



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


[Lldb-commits] [PATCH] D75004: Fix a race between lldb's packet timeout and killing the profile thread

2020-02-21 Thread Jim Ingham via Phabricator via lldb-commits
jingham created this revision.
jingham added a reviewer: clayborg.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The debugserver profile thread used to suspend itself between samples with
a usleep.  When you detach or kill, MachProcess::Clear would delay replying
to the incoming packet until pthread_join of the profile thread returned.
If you are unlucky or the suspend delay is long, it could take longer than
the packet timeout for pthread_join to return.  Then you would get an error
about detach not succeeding from lldb - even though in fact the detach was
successful...

  

I replaced the usleep with PThreadEvents entity.  Then we just call a timed
WaitForEventBits, and when debugserver wants to stop the profile thread, it
can set the event bit, and the sleep will exit immediately.

Note, you have to get fairly unlucky because when lldb times out a packet it
then sends a qEcho, and tries to get back in sync.  That adds some extra delay
which might give the detach a chance to succeed.  I've had occasional 
mysterious 
reports of Detach failing like this - only under Xcode which is currently the 
only client
I know of of the profiling info for years, but didn't get to chasing it down 
till now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75004

Files:
  lldb/test/API/macosx/profile_vrs_detach/Makefile
  lldb/test/API/macosx/profile_vrs_detach/TestDetachVrsProfile.py
  lldb/test/API/macosx/profile_vrs_detach/main.c
  lldb/tools/debugserver/source/MacOSX/MachProcess.h
  lldb/tools/debugserver/source/MacOSX/MachProcess.mm

Index: lldb/tools/debugserver/source/MacOSX/MachProcess.mm
===
--- lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -25,11 +25,13 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
 #include 
+#include 
 #include 
 
 #import 
@@ -485,6 +487,7 @@
   m_stdio_mutex(PTHREAD_MUTEX_RECURSIVE), m_stdout_data(),
   m_profile_enabled(false), m_profile_interval_usec(0), m_profile_thread(0),
   m_profile_data_mutex(PTHREAD_MUTEX_RECURSIVE), m_profile_data(),
+  m_profile_events(0, eMachProcessProfileCancel),
   m_thread_actions(), m_exception_messages(),
   m_exception_messages_mutex(PTHREAD_MUTEX_RECURSIVE), m_thread_list(),
   m_activities(), m_state(eStateUnloaded),
@@ -1294,10 +1297,7 @@
 m_exception_messages.clear();
   }
   m_activities.Clear();
-  if (m_profile_thread) {
-pthread_join(m_profile_thread, NULL);
-m_profile_thread = NULL;
-  }
+  StopProfileThread();
 }
 
 bool MachProcess::StartSTDIOThread() {
@@ -1316,11 +1316,19 @@
   if (m_profile_enabled && (m_profile_thread == NULL)) {
 StartProfileThread();
   } else if (!m_profile_enabled && m_profile_thread) {
-pthread_join(m_profile_thread, NULL);
-m_profile_thread = NULL;
+StopProfileThread();
   }
 }
 
+void MachProcess::StopProfileThread() {
+  if (m_profile_thread == NULL)
+return;
+  m_profile_events.SetEvents(eMachProcessProfileCancel);
+  pthread_join(m_profile_thread, NULL);
+  m_profile_thread = NULL;
+  m_profile_events.ResetEvents(eMachProcessProfileCancel);
+}
+
 bool MachProcess::StartProfileThread() {
   DNBLogThreadedIf(LOG_PROCESS, "MachProcess::%s ( )", __FUNCTION__);
   // Create the thread that profiles the inferior and reports back if enabled
@@ -2513,10 +2521,20 @@
   // Done. Get out of this thread.
   break;
 }
-
-// A simple way to set up the profile interval. We can also use select() or
-// dispatch timer source if necessary.
-usleep(proc->ProfileInterval());
+timespec ts;
+{
+  using namespace std::chrono;
+  std::chrono::microseconds dur(proc->ProfileInterval());
+  const auto dur_secs = duration_cast(dur);
+  const auto dur_usecs = dur % std::chrono::seconds(1);
+  DNBTimer::OffsetTimeOfDay(&ts, dur_secs.count(), 
+dur_usecs.count());
+}
+uint32_t bits_set = 
+proc->m_profile_events.WaitForSetEvents(eMachProcessProfileCancel, &ts);
+// If we got bits back, we were told to exit.  Do so.
+if (bits_set & eMachProcessProfileCancel)
+  break;
   }
   return NULL;
 }
Index: lldb/tools/debugserver/source/MacOSX/MachProcess.h
===
--- lldb/tools/debugserver/source/MacOSX/MachProcess.h
+++ lldb/tools/debugserver/source/MacOSX/MachProcess.h
@@ -338,9 +338,16 @@
 eMachProcessFlagsUsingFBS = (1 << 3), // only read via ProcessUsingFrontBoard()
 eMachProcessFlagsBoardCalculated = (1 << 4)
   };
+
+  enum {
+eMachProcessProfileNone = 0,
+eMachProcessProfileCancel = (1 << 0)
+  };
+
   void Clear(bool detaching = false);
   void ReplyToAllExceptions();
   void PrivateResume();
+  void StopProfileThread();
 
   uint32_t Flags() const { return m_flags; }
   nub_state_t DoSIGST

[Lldb-commits] [lldb] ebee131 - [lldb][test] Fix sh_type of .debug_cu_index and .debug_tu_index

2020-02-21 Thread Fangrui Song via lldb-commits

Author: Fangrui Song
Date: 2020-02-21T17:38:39-08:00
New Revision: ebee131259719fa9c06cd346e21ace3fa8ac0888

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

LOG: [lldb][test] Fix sh_type of .debug_cu_index and .debug_tu_index

They do not have the SHF_EXCLUDE flag.
After D73999, MC errors `changed section type for .debug_cu_index, expected: 
0x0`

Added: 


Modified: 
lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s
lldb/test/Shell/SymbolFile/DWARF/dwp.s

Removed: 




diff  --git a/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s 
b/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s
index fd009381b452..8680d27a3b42 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s
+++ b/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s
@@ -203,9 +203,9 @@ A\I:
 .endr
 .endmacro
 
-.section.debug_cu_index,"e",@progbits
+.section.debug_cu_index,"",@progbits
 index 1, .debug_info.dwo, .Lcu_begin, .Ldebug_info_end
 
-.section.debug_tu_index,"e",@progbits
+.section.debug_tu_index,"",@progbits
 index 2, .debug_types.dwo, .Ltu_begin, .Ltype_info_end
 .endif

diff  --git a/lldb/test/Shell/SymbolFile/DWARF/dwp.s 
b/lldb/test/Shell/SymbolFile/DWARF/dwp.s
index 730609412c36..659d7703daa9 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/dwp.s
+++ b/lldb/test/Shell/SymbolFile/DWARF/dwp.s
@@ -232,7 +232,7 @@ F\I:
 .Ldebug_info_end\I:
 .endr
 
-.section.debug_cu_index,"e",@progbits
+.section.debug_cu_index,"",@progbits
 .short  2   # DWARF version number
 .short  0   # Reserved
 .long   4   # Section count



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


[Lldb-commits] [PATCH] D75004: Fix a race between lldb's packet timeout and killing the profile thread

2020-02-21 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

Lots of change for something that might be fixed much easier:

Alt way: Why not just set m_profile_enabled to false in StopProfileThread() and 
let loop exit on next iteration? Code changes would be much smaller. All 
comments above are marked with "alt way:" for this solution




Comment at: lldb/test/API/macosx/profile_vrs_detach/TestDetachVrsProfile.py:27
+def test_profile_and_detach(self):
+"""There can be many tests in a test case - describe this test here."""
+self.build()

fix comment?



Comment at: lldb/tools/debugserver/source/MacOSX/MachProcess.h:341-346
+
+  enum {
+eMachProcessProfileNone = 0,
+eMachProcessProfileCancel = (1 << 0)
+  };
+

Alt way (see main comment): remove these lines



Comment at: lldb/tools/debugserver/source/MacOSX/MachProcess.h:385
   m_profile_data; // Profile data, must be protected by 
m_profile_data_mutex
-
+  PThreadEvent m_profile_events; // Used for the profile thread cancellable 
wait  
   DNBThreadResumeActions m_thread_actions; // The thread actions for the 
current

Alt way: remove



Comment at: lldb/tools/debugserver/source/MacOSX/MachProcess.mm:28
 #include 
+#include 
 #include 

remove



Comment at: lldb/tools/debugserver/source/MacOSX/MachProcess.mm:34
 #include 
+#include 
 #include 

remove



Comment at: lldb/tools/debugserver/source/MacOSX/MachProcess.mm:490
   m_profile_data_mutex(PTHREAD_MUTEX_RECURSIVE), m_profile_data(),
+  m_profile_events(0, eMachProcessProfileCancel),
   m_thread_actions(), m_exception_messages(),

alt way: remove



Comment at: lldb/tools/debugserver/source/MacOSX/MachProcess.mm:1326
+return;
+  m_profile_events.SetEvents(eMachProcessProfileCancel);
+  pthread_join(m_profile_thread, NULL);

alt way: 

```
m_profile_enabled = false;
```




Comment at: lldb/tools/debugserver/source/MacOSX/MachProcess.mm:1329
+  m_profile_thread = NULL;
+  m_profile_events.ResetEvents(eMachProcessProfileCancel);
+}

alt way: remove



Comment at: lldb/tools/debugserver/source/MacOSX/MachProcess.mm:2511-2538
   while (proc->IsProfilingEnabled()) {
 nub_state_t state = proc->GetState();
 if (state == eStateRunning) {
   std::string data =
   proc->Task().GetProfileData(proc->GetProfileScanType());
   if (!data.empty()) {
 proc->SignalAsyncProfileData(data.c_str());

Alt way: revert all changes here, when we call StopProfileThread, it will set 
m_profile_enabled = false and this loop will naturally exit.

Your way: Move the conversion of profile interval out of the loop?

```
 timespec ts;
 using namespace std::chrono;
 std::chrono::microseconds dur(proc->ProfileInterval());
 const auto dur_secs = duration_cast(dur);
 const auto dur_usecs = dur % std::chrono::seconds(1);
  while (proc->IsProfilingEnabled()) {
nub_state_t state = proc->GetState();
if (state == eStateRunning) {
  std::string data =
  proc->Task().GetProfileData(proc->GetProfileScanType());
  if (!data.empty()) {
proc->SignalAsyncProfileData(data.c_str());
  }
} else if ((state == eStateUnloaded) || (state == eStateDetached) ||
   (state == eStateUnloaded)) {
  // Done. Get out of this thread.
  break;
}
DNBTimer::OffsetTimeOfDay(&ts, dur_secs.count(), dur_usecs.count());
// Exit if requested.
if (proc->m_profile_events.WaitForSetEvents(eMachProcessProfileCancel, &ts))
  break;
  }
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75004/new/

https://reviews.llvm.org/D75004



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


[Lldb-commits] [lldb] e29065a - [lldb][test] Fix sh_flags and sh_entsize of .debug_str.dwo

2020-02-21 Thread Fangrui Song via lldb-commits

Author: Fangrui Song
Date: 2020-02-21T18:51:05-08:00
New Revision: e29065a105342a904871437d18a4e6fab09e5bc1

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

LOG: [lldb][test] Fix sh_flags and sh_entsize of .debug_str.dwo

sh_flags: SHF_MERGE | SHF_STRINGS | SHF_EXCLUDE
sh_entsize: 1

Incorrect sh_flags or sh_entsize is an error after the assembler change made by 
D73999.

Added: 


Modified: 
lldb/test/Shell/SymbolFile/DWARF/dwp.s

Removed: 




diff  --git a/lldb/test/Shell/SymbolFile/DWARF/dwp.s 
b/lldb/test/Shell/SymbolFile/DWARF/dwp.s
index 659d7703daa9..7987299197d9 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/dwp.s
+++ b/lldb/test/Shell/SymbolFile/DWARF/dwp.s
@@ -105,7 +105,7 @@ F\I:
 # This deliberately excludes compile unit 4 to check test the case of a missing
 # split unit.
 .irpc I,0123
-.section.debug_str.dwo,"e",@progbits
+.section.debug_str.dwo,"MSe",@progbits,1
 .Lstr\I:
 .byte   'I', 'N', 'T', '0'+\I, 0
 



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


[Lldb-commits] [PATCH] D75007: When unwinding out of a trap handler, fetch the saved pc even if there's a return address register defined

2020-02-21 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda created this revision.
jasonmolenda added a project: LLDB.
Herald added a subscriber: kristof.beyls.

On targets with a return address register (e.g. $lr on arm), when the unwinder 
is asked to fetch the caller's pc, we rewrite that to fetch the return address 
value.

However, when we're in a trap handler -- either from an interrupt or an async 
signal -- we will have a full register context for the frame that was 
interrupted/trapped.  The unwinder correctly allows you to fetch volatile 
registers when you're above a trap handler.  But we are still rewriting the 
"fetch the pc" request when the trap handler is asked to find the caller's 
saved pc.  This is incorrect, and results in lldb showing the wrong function 
that was interrupted/faulted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75007

Files:
  lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp


Index: lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
===
--- lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
+++ lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
@@ -1203,9 +1203,13 @@
   // If we're fetching the saved pc and this UnwindPlan defines a
   // ReturnAddress register (e.g. lr on arm), look for the return address
   // register number in the UnwindPlan's row.
+  // If this is a trap handler frame, we have access to the complete
+  // register context when the interrupt/async signal was received, so
+  // we need to fetch the actual saved $pc value.
   if (pc_regnum.IsValid() && pc_regnum == regnum &&
   m_full_unwind_plan_sp->GetReturnAddressRegister() !=
-  LLDB_INVALID_REGNUM) {
+  LLDB_INVALID_REGNUM &&
+  m_frame_type != eTrapHandlerFrame) {
 
 return_address_reg.init(
 m_thread, m_full_unwind_plan_sp->GetRegisterKind(),


Index: lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
===
--- lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
+++ lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
@@ -1203,9 +1203,13 @@
   // If we're fetching the saved pc and this UnwindPlan defines a
   // ReturnAddress register (e.g. lr on arm), look for the return address
   // register number in the UnwindPlan's row.
+  // If this is a trap handler frame, we have access to the complete
+  // register context when the interrupt/async signal was received, so
+  // we need to fetch the actual saved $pc value.
   if (pc_regnum.IsValid() && pc_regnum == regnum &&
   m_full_unwind_plan_sp->GetReturnAddressRegister() !=
-  LLDB_INVALID_REGNUM) {
+  LLDB_INVALID_REGNUM &&
+  m_frame_type != eTrapHandlerFrame) {
 
 return_address_reg.init(
 m_thread, m_full_unwind_plan_sp->GetRegisterKind(),
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits