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

2018-06-19 Thread Kuba (Brecka) Mracek via Phabricator via lldb-commits
kubamracek updated this revision to Diff 152017.
kubamracek added a comment.

Fixing up test (it was using the "-t" flag).
Removing a leftover printf().


https://reviews.llvm.org/D44603

Files:
  include/lldb/API/SBVariablesOptions.h
  include/lldb/Interpreter/OptionGroupVariable.h
  include/lldb/Interpreter/ScriptInterpreter.h
  include/lldb/Target/StackFrame.h
  include/lldb/Target/StackFrameRecognizer.h
  include/lldb/lldb-forward.h
  lldb.xcodeproj/project.pbxproj
  packages/Python/lldbsuite/test/functionalities/frame-recognizer/Makefile
  
packages/Python/lldbsuite/test/functionalities/frame-recognizer/TestFrameRecognizer.py
  packages/Python/lldbsuite/test/functionalities/frame-recognizer/main.m
  packages/Python/lldbsuite/test/functionalities/frame-recognizer/recognizer.py
  scripts/Python/python-wrapper.swig
  scripts/interface/SBVariablesOptions.i
  source/API/SBFrame.cpp
  source/API/SBVariablesOptions.cpp
  source/API/SystemInitializerFull.cpp
  source/Commands/CommandObjectFrame.cpp
  source/Interpreter/OptionGroupVariable.cpp
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
  source/Target/CMakeLists.txt
  source/Target/StackFrame.cpp
  source/Target/StackFrameRecognizer.cpp
  www/python-reference.html

Index: www/python-reference.html
===
--- www/python-reference.html
+++ www/python-reference.html
@@ -738,11 +738,64 @@
 # We do have a symbol, print some info for the symbol
 print symbol
 
-
-
+
+
+
+
+
+Writing LLDB frame recognizers in Python
+
+
+Frame recognizers allow retrieving information about special frames based on
+ABI, arguments or other special properties of that frame, even without source
+code or debug info. Currently, they can extract function arguments that would
+otherwise be unaccesible.
+
+Adding a custom frame recognizer is possible by implementing a Python class
+and using the 'frame recognizer add' command. The Python class should have a
+'get_recognized_arguments' method and it will receive an argument of type
+lldb.SBFrame representing the current frame that we are trying to recognize.
+The method should return a (possibly empty) list of lldb.SBValue objects that
+represent the recognized arguments.
+
+An example of a recognizer that retrieves the file descriptor values from libc
+functions 'read', 'write' and 'close' follows:
+
+  class LibcFdRecognizer(object):
+def get_recognized_arguments(self, frame):
+  if frame.name in ["read", "write", "close"]:
+fd = frame.EvaluateExpression("$arg1").unsigned
+value = lldb.target.CreateValueFromExpression("fd", "(int)%d" % fd)
+return [value]
+  return []
+
+
+The file containing this implementation can be imported via 'command script
+import' and then we can register this recognizer with 'frame recognizer add'.
+It's important to restrict the recognizer to the libc library (which is
+libsystem_kernel.dylib on macOS):
+
+(lldb) command script import .../fd_recognizer.py
+(lldb) frame recognizer add -l fd_recognizer.LibcFdRecognizer -n read -m libsystem_kernel.dylib
+
+
+When the program is stopped at the beginning of the 'read' function in libc, we
+can view the recognizer arguments in 'frame variable':
+
+(lldb) b read
+(lldb) r
+Process 1234 stopped
+* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.3
+frame #0: 0x7fff06013ca0 libsystem_kernel.dylib`read
+(lldb) frame variable
+(int) fd = 3
+
 
-  	
-	
+
+
+
+
+
 
 
 
Index: source/Target/StackFrameRecognizer.cpp
===
--- source/Target/StackFrameRecognizer.cpp
+++ source/Target/StackFrameRecognizer.cpp
@@ -0,0 +1,182 @@
+//===-- StackFrameRecognizer.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+// C Includes
+// C++ Includes
+#include 
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Module.h"
+#include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/StackFrameRecognizer.h"
+#include "lldb/Utility/RegularExpression.h"
+
+using namespace 

[Lldb-commits] [PATCH] D48295: [WIP] Implement new ReturnMIStatus method of CMICmdBase class.

2018-06-19 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

Ok, then let's continue this way.




Comment at: tools/lldb-mi/MICmdBase.h:89
+  [] { return MIstatus::failure; },
+  const lldb::SBError error = lldb::SBError());
   template  T *GetOption(const CMIUtilString );

If you move the error argument to the front, you can use the default error 
handler in the function below. In fact, I'm not even sure what it would mean to 
call this function without an error. I guess the error argument should probably 
not have a default value at all.



Comment at: tools/lldb-mi/MICmdCmdExec.cpp:242
   const CMIUtilString 
(CMIDriver::Instance().GetErrorDescription());
-  SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
- m_cmdData.strMiCmd.c_str(),
- rErrMsg.c_str()));
+  this->SetError(CMIUtilString::Format(
+  MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),

If you add a second variant (or a wrapper) that takes a bool instead of an 
SBError, you could use that one here, since it's basically the same pattern, 
just not with an SBError.


https://reviews.llvm.org/D48295



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


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

2018-06-19 Thread Kuba (Brecka) Mracek via Phabricator via lldb-commits
kubamracek updated this revision to Diff 152004.
kubamracek added a comment.

Switched on showing recognized args by default in "frame variable". Switched 
"-t" to mean "omit" instead of "include".
Added documentation and an example into "help frame recognizer add" and into 
python-reference.html.


https://reviews.llvm.org/D44603

Files:
  include/lldb/API/SBVariablesOptions.h
  include/lldb/Interpreter/OptionGroupVariable.h
  include/lldb/Interpreter/ScriptInterpreter.h
  include/lldb/Target/StackFrame.h
  include/lldb/Target/StackFrameRecognizer.h
  include/lldb/lldb-forward.h
  lldb.xcodeproj/project.pbxproj
  packages/Python/lldbsuite/test/functionalities/frame-recognizer/Makefile
  
packages/Python/lldbsuite/test/functionalities/frame-recognizer/TestFrameRecognizer.py
  packages/Python/lldbsuite/test/functionalities/frame-recognizer/main.m
  packages/Python/lldbsuite/test/functionalities/frame-recognizer/recognizer.py
  scripts/Python/python-wrapper.swig
  scripts/interface/SBVariablesOptions.i
  source/API/SBFrame.cpp
  source/API/SBVariablesOptions.cpp
  source/API/SystemInitializerFull.cpp
  source/Commands/CommandObjectFrame.cpp
  source/Interpreter/OptionGroupVariable.cpp
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
  source/Target/CMakeLists.txt
  source/Target/StackFrame.cpp
  source/Target/StackFrameRecognizer.cpp
  www/python-reference.html

Index: www/python-reference.html
===
--- www/python-reference.html
+++ www/python-reference.html
@@ -738,11 +738,64 @@
 # We do have a symbol, print some info for the symbol
 print symbol
 
-
-
+
+
+
+
+
+Writing LLDB frame recognizers in Python
+
+
+Frame recognizers allow retrieving information about special frames based on
+ABI, arguments or other special properties of that frame, even without source
+code or debug info. Currently, they can extract function arguments that would
+otherwise be unaccesible.
+
+Adding a custom frame recognizer is possible by implementing a Python class
+and using the 'frame recognizer add' command. The Python class should have a
+'get_recognized_arguments' method and it will receive an argument of type
+lldb.SBFrame representing the current frame that we are trying to recognize.
+The method should return a (possibly empty) list of lldb.SBValue objects that
+represent the recognized arguments.
+
+An example of a recognizer that retrieves the file descriptor values from libc
+functions 'read', 'write' and 'close' follows:
+
+  class LibcFdRecognizer(object):
+def get_recognized_arguments(self, frame):
+  if frame.name in ["read", "write", "close"]:
+fd = frame.EvaluateExpression("$arg1").unsigned
+value = lldb.target.CreateValueFromExpression("fd", "(int)%d" % fd)
+return [value]
+  return []
+
+
+The file containing this implementation can be imported via 'command script
+import' and then we can register this recognizer with 'frame recognizer add'.
+It's important to restrict the recognizer to the libc library (which is
+libsystem_kernel.dylib on macOS):
+
+(lldb) command script import .../fd_recognizer.py
+(lldb) frame recognizer add -l fd_recognizer.LibcFdRecognizer -n read -m libsystem_kernel.dylib
+
 
-  	
-	
+When the program is stopped at the beginning of the 'read' function in libc, we
+can view the recognizer arguments in 'frame variable':
+
+(lldb) b read
+(lldb) r
+Process 1234 stopped
+* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.3
+frame #0: 0x7fff06013ca0 libsystem_kernel.dylib`read
+(lldb) frame variable
+(int) fd = 3
+
+
+
+
+
+
+
 
 
 
Index: source/Target/StackFrameRecognizer.cpp
===
--- /dev/null
+++ source/Target/StackFrameRecognizer.cpp
@@ -0,0 +1,183 @@
+//===-- StackFrameRecognizer.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+// C Includes
+// C++ Includes
+#include 
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Module.h"
+#include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Symbol/Symbol.h"
+#include 

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

2018-06-19 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

This code looks fine to me.  The docs are a little thin.

You don't say how to make a recognizer anywhere except in the test example.  
There should probably be an example in the long help for 
CommandObjectFrameRecognizerAdd.  Look for instance at the help for "breakpoint 
command add" which tells you the signature of the Python function you need to 
add and gives an example.  You should also add a section to 
www/python-reference.html since that's where people go to see "how can I extend 
lldb using the Python interface."


https://reviews.llvm.org/D44603



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


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

2018-06-19 Thread Kuba (Brecka) Mracek via Phabricator via lldb-commits
kubamracek updated this revision to Diff 151991.
kubamracek added a comment.

Rebasing to current master.


https://reviews.llvm.org/D44603

Files:
  include/lldb/API/SBVariablesOptions.h
  include/lldb/Interpreter/OptionGroupVariable.h
  include/lldb/Interpreter/ScriptInterpreter.h
  include/lldb/Target/StackFrame.h
  include/lldb/Target/StackFrameRecognizer.h
  include/lldb/lldb-forward.h
  lldb.xcodeproj/project.pbxproj
  packages/Python/lldbsuite/test/functionalities/frame-recognizer/Makefile
  
packages/Python/lldbsuite/test/functionalities/frame-recognizer/TestFrameRecognizer.py
  packages/Python/lldbsuite/test/functionalities/frame-recognizer/main.m
  packages/Python/lldbsuite/test/functionalities/frame-recognizer/recognizer.py
  scripts/Python/python-wrapper.swig
  scripts/interface/SBVariablesOptions.i
  source/API/SBFrame.cpp
  source/API/SBVariablesOptions.cpp
  source/API/SystemInitializerFull.cpp
  source/Commands/CommandObjectFrame.cpp
  source/Interpreter/OptionGroupVariable.cpp
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
  source/Target/CMakeLists.txt
  source/Target/StackFrame.cpp
  source/Target/StackFrameRecognizer.cpp

Index: source/Target/StackFrameRecognizer.cpp
===
--- /dev/null
+++ source/Target/StackFrameRecognizer.cpp
@@ -0,0 +1,183 @@
+//===-- StackFrameRecognizer.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+// C Includes
+// C++ Includes
+#include 
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Module.h"
+#include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/StackFrameRecognizer.h"
+#include "lldb/Utility/RegularExpression.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+class ScriptedRecognizedStackFrame : public RecognizedStackFrame {
+public:
+  ScriptedRecognizedStackFrame(ValueObjectListSP args) {
+m_arguments = args;
+  }
+};
+
+ScriptedStackFrameRecognizer::ScriptedStackFrameRecognizer(
+ScriptInterpreter *interpreter, const char *pclass)
+: m_interpreter(interpreter), m_python_class(pclass) {
+  m_python_object_sp =
+  m_interpreter->CreateFrameRecognizer(m_python_class.c_str());
+}
+
+RecognizedStackFrameSP
+ScriptedStackFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame) {
+  if (!m_python_object_sp || !m_interpreter)
+return RecognizedStackFrameSP();
+
+  ValueObjectListSP args =
+  m_interpreter->GetRecognizedArguments(m_python_object_sp, frame);
+
+  return RecognizedStackFrameSP(new ScriptedRecognizedStackFrame(args));
+}
+
+class StackFrameRecognizerManagerImpl {
+public:
+  void AddRecognizer(StackFrameRecognizerSP recognizer, ConstString ,
+ ConstString , bool first_instruction_only) {
+m_recognizers.push_front({recognizer, false, module, RegularExpressionSP(),
+  symbol, RegularExpressionSP(),
+  first_instruction_only});
+  }
+
+  void AddRecognizer(StackFrameRecognizerSP recognizer,
+ RegularExpressionSP module, RegularExpressionSP symbol,
+ bool first_instruction_only) {
+m_recognizers.push_front({recognizer, true, ConstString(), module,
+  ConstString(), symbol, first_instruction_only});
+  }
+
+  void ForEach(
+  std::function const ) {
+for (auto entry : m_recognizers) {
+  if (entry.is_regexp) {
+callback(entry.recognizer->GetName(), entry.module_regexp->GetText(),
+ entry.symbol_regexp->GetText(), true);
+  } else {
+callback(entry.recognizer->GetName(), entry.module.GetCString(),
+ entry.symbol.GetCString(), false);
+  }
+}
+  }
+
+  bool Delete(std::string recognizer_name) {
+size_t previous_size = m_recognizers.size();
+m_recognizers.erase(
+std::remove_if(m_recognizers.begin(), m_recognizers.end(),
+   [recognizer_name](RegisteredEntry entry) {
+ printf("%s\n", entry.recognizer->GetName().c_str());
+ return entry.recognizer->GetName() == recognizer_name;
+   }),
+m_recognizers.end());
+return previous_size != m_recognizers.size();
+  }
+
+  void RemoveAllRecognizers() {
+m_recognizers.clear();
+  }
+
+  RecognizedStackFrameSP RecognizeFrame(StackFrameSP frame) {
+const SymbolContext  =
+frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+ConstString function_name = 

[Lldb-commits] [PATCH] D48295: [WIP] Implement new ReturnMIStatus method of CMICmdBase class.

2018-06-19 Thread Alexander Polyakov via Phabricator via lldb-commits
apolyakov added a comment.

>   bool handleSBError(SBError error, std::function 
> convert) {
> if (error.Success())
>   return false;
>   
> SetError(convert(error));
> return error_handler();
>   }
>   
>   ...
>   bool CMICmdCmdExecContinue::Execute() {
> if 
> (handleSBError(CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue(),
>  [](SBError error){
>   return CMIUtilString::Format(
>  MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
>  this->m_cmdData.strMiCmd.c_str(),
>  rErrMsg.c_str());'
>  }) 
>   return MIstatus::failure;
>   
> // potentially run other SBAPI commands...
> return MIstatus::success;
>   };
>   

In this case, it's not clear how to pass `error_handler` to 
`handleSBError(...)`. Moreover, user may want to specify action for success 
case which isn't presented in your example.

About using more than one SB API command: it's possible even in my patch, just 
use `ReturnMIStatus` like:

  if (!ReturnMIStatus(success_handler, error_handler, error))
return MIstatus::failure;
  
  // do other stuff
  ...
  return MIstatus::success;


https://reviews.llvm.org/D48295



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


[Lldb-commits] [PATCH] D48339: Refactor ClangUserExpression::Parse [NFC]

2018-06-19 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor created this revision.

This patch splits out functionality from the `Parse` method into different 
methods.
This benefits the code completion work (which should reuse those methods) and 
makes the
code a bit more readable.

Note that this patch is as minimal as possible. Some of the code in the new 
methods definitely
needs more refactoring.


https://reviews.llvm.org/D48339

Files:
  source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  source/Plugins/ExpressionParser/Clang/ClangUserExpression.h

Index: source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
===
--- source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
+++ source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
@@ -174,6 +174,13 @@
 lldb::addr_t struct_address,
 DiagnosticManager _manager) override;
 
+  llvm::Optional GetLanguageForExpr(
+  DiagnosticManager _manager, ExecutionContext _ctx);
+  bool SetupPersistentState(DiagnosticManager _manager,
+   ExecutionContext _ctx);
+  bool PrepareForParsing(DiagnosticManager _manager,
+ ExecutionContext _ctx);
+
   ClangUserExpressionHelper m_type_system_helper;
 
   class ResultDelegate : public Materializer::PersistentVariableDelegate {
Index: source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
===
--- source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -322,17 +322,8 @@
 };
 } // namespace
 
-bool ClangUserExpression::Parse(DiagnosticManager _manager,
-ExecutionContext _ctx,
-lldb_private::ExecutionPolicy execution_policy,
-bool keep_result_in_memory,
-bool generate_debug_info) {
-  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
-
-  Status err;
-
-  InstallContext(exe_ctx);
-
+bool ClangUserExpression::SetupPersistentState(DiagnosticManager _manager,
+ ExecutionContext _ctx) {
   if (Target *target = exe_ctx.GetTargetPtr()) {
 if (PersistentExpressionState *persistent_state =
 target->GetPersistentExpressionStateForLanguage(
@@ -349,35 +340,24 @@
  "error: couldn't start parsing (no target)");
 return false;
   }
+  return true;
+}
 
-  ScanContext(exe_ctx, err);
-
-  if (!err.Success()) {
-diagnostic_manager.PutString(eDiagnosticSeverityWarning, err.AsCString());
-  }
-
-  
-  // Generate the expression
-  //
-
-  ApplyObjcCastHack(m_expr_text);
-
-  std::string prefix = m_expr_prefix;
-
+static void SetupDeclVendor(ExecutionContext _ctx, Target *target) {
   if (ClangModulesDeclVendor *decl_vendor =
-  m_target->GetClangModulesDeclVendor()) {
+  target->GetClangModulesDeclVendor()) {
 const ClangModulesDeclVendor::ModuleVector _imported_modules =
 llvm::cast(
-m_target->GetPersistentExpressionStateForLanguage(
+target->GetPersistentExpressionStateForLanguage(
 lldb::eLanguageTypeC))
 ->GetHandLoadedClangModules();
 ClangModulesDeclVendor::ModuleVector modules_for_macros;
 
 for (ClangModulesDeclVendor::ModuleID module : hand_imported_modules) {
   modules_for_macros.push_back(module);
 }
 
-if (m_target->GetEnableAutoImportClangModules()) {
+if (target->GetEnableAutoImportClangModules()) {
   if (StackFrame *frame = exe_ctx.GetFramePtr()) {
 if (Block *block = frame->GetFrameBlock()) {
   SymbolContext sc;
@@ -394,8 +374,13 @@
   }
 }
   }
+}
+
+llvm::Optional ClangUserExpression::GetLanguageForExpr(
+DiagnosticManager _manager, ExecutionContext _ctx) {
+  lldb::LanguageType lang_type = lldb::LanguageType::eLanguageTypeUnknown;
 
-  lldb::LanguageType lang_type = lldb::eLanguageTypeUnknown;
+  std::string prefix = m_expr_prefix;
 
   if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) {
 m_transformed_text = m_expr_text;
@@ -415,9 +400,50 @@
   exe_ctx)) {
   diagnostic_manager.PutString(eDiagnosticSeverityError,
"couldn't construct expression body");
-  return false;
+  return llvm::Optional();
 }
   }
+  return lang_type;
+}
+
+bool ClangUserExpression::PrepareForParsing(
+DiagnosticManager _manager, ExecutionContext _ctx) {
+  InstallContext(exe_ctx);
+
+  if (!SetupPersistentState(diagnostic_manager, exe_ctx))
+return false;
+
+  Status err;
+  ScanContext(exe_ctx, err);
+
+  if (!err.Success()) {
+diagnostic_manager.PutString(eDiagnosticSeverityWarning, err.AsCString());
+  }
+
+  
+  // 

[Lldb-commits] [PATCH] D48302: Search for kext variants is searching from parent directory when it should not be

2018-06-19 Thread Phabricator via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL335079: Correct the pathname that 
PlatformDarwinKernel::ExamineKextForMatchingUUID (authored by jmolenda, 
committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48302?vs=151809=151981#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48302

Files:
  lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
  lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h


Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
===
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
@@ -780,10 +780,10 @@
 }
 
 std::vector
-PlatformDarwinKernel::SearchForExecutablesRecursively(const ConstString ) {
+PlatformDarwinKernel::SearchForExecutablesRecursively(const std::string ) {
   std::vector executables;
   std::error_code EC;
-  for (llvm::sys::fs::recursive_directory_iterator it(dir.GetStringRef(), EC),
+  for (llvm::sys::fs::recursive_directory_iterator it(dir.c_str(), EC),
end;
it != end && !EC; it.increment(EC)) {
 auto status = it->status();
@@ -800,7 +800,7 @@
 const FileSpec _bundle_path, const lldb_private::UUID ,
 const ArchSpec , ModuleSP _module_sp) {
   for (const auto _file :
-   SearchForExecutablesRecursively(kext_bundle_path.GetDirectory())) {
+   SearchForExecutablesRecursively(kext_bundle_path.GetPath())) {
 if (exe_file.Exists()) {
   ModuleSpec exe_spec(exe_file);
   exe_spec.GetUUID() = uuid;
Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
===
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
@@ -128,7 +128,7 @@
   bool recurse);
 
   static std::vector
-  SearchForExecutablesRecursively(const lldb_private::ConstString );
+  SearchForExecutablesRecursively(const std::string );
 
   static void AddKextToMap(PlatformDarwinKernel *thisp,
const lldb_private::FileSpec _spec);


Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
===
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
@@ -780,10 +780,10 @@
 }
 
 std::vector
-PlatformDarwinKernel::SearchForExecutablesRecursively(const ConstString ) {
+PlatformDarwinKernel::SearchForExecutablesRecursively(const std::string ) {
   std::vector executables;
   std::error_code EC;
-  for (llvm::sys::fs::recursive_directory_iterator it(dir.GetStringRef(), EC),
+  for (llvm::sys::fs::recursive_directory_iterator it(dir.c_str(), EC),
end;
it != end && !EC; it.increment(EC)) {
 auto status = it->status();
@@ -800,7 +800,7 @@
 const FileSpec _bundle_path, const lldb_private::UUID ,
 const ArchSpec , ModuleSP _module_sp) {
   for (const auto _file :
-   SearchForExecutablesRecursively(kext_bundle_path.GetDirectory())) {
+   SearchForExecutablesRecursively(kext_bundle_path.GetPath())) {
 if (exe_file.Exists()) {
   ModuleSpec exe_spec(exe_file);
   exe_spec.GetUUID() = uuid;
Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
===
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
@@ -128,7 +128,7 @@
   bool recurse);
 
   static std::vector
-  SearchForExecutablesRecursively(const lldb_private::ConstString );
+  SearchForExecutablesRecursively(const std::string );
 
   static void AddKextToMap(PlatformDarwinKernel *thisp,
const lldb_private::FileSpec _spec);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] r335079 - Correct the pathname that PlatformDarwinKernel::ExamineKextForMatchingUUID

2018-06-19 Thread Jason Molenda via lldb-commits
Author: jmolenda
Date: Tue Jun 19 14:39:10 2018
New Revision: 335079

URL: http://llvm.org/viewvc/llvm-project?rev=335079=rev
Log:
Correct the pathname that PlatformDarwinKernel::ExamineKextForMatchingUUID
passes to the recursive search function so we only recursively
search the kext bundle directory, instead of its parent directory.

 

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

Modified:
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp?rev=335079=335078=335079=diff
==
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp 
(original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp Tue Jun 
19 14:39:10 2018
@@ -780,10 +780,10 @@ Status PlatformDarwinKernel::GetSharedMo
 }
 
 std::vector
-PlatformDarwinKernel::SearchForExecutablesRecursively(const ConstString ) {
+PlatformDarwinKernel::SearchForExecutablesRecursively(const std::string ) {
   std::vector executables;
   std::error_code EC;
-  for (llvm::sys::fs::recursive_directory_iterator it(dir.GetStringRef(), EC),
+  for (llvm::sys::fs::recursive_directory_iterator it(dir.c_str(), EC),
end;
it != end && !EC; it.increment(EC)) {
 auto status = it->status();
@@ -800,7 +800,7 @@ Status PlatformDarwinKernel::ExamineKext
 const FileSpec _bundle_path, const lldb_private::UUID ,
 const ArchSpec , ModuleSP _module_sp) {
   for (const auto _file :
-   SearchForExecutablesRecursively(kext_bundle_path.GetDirectory())) {
+   SearchForExecutablesRecursively(kext_bundle_path.GetPath())) {
 if (exe_file.Exists()) {
   ModuleSpec exe_spec(exe_file);
   exe_spec.GetUUID() = uuid;

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h?rev=335079=335078=335079=diff
==
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h Tue Jun 19 
14:39:10 2018
@@ -128,7 +128,7 @@ protected:
   bool recurse);
 
   static std::vector
-  SearchForExecutablesRecursively(const lldb_private::ConstString );
+  SearchForExecutablesRecursively(const std::string );
 
   static void AddKextToMap(PlatformDarwinKernel *thisp,
const lldb_private::FileSpec _spec);


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


[Lldb-commits] [PATCH] D48337: Refactor OnExit utility class in ClangUserExpression

2018-06-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

How is this class different from `lldb_private::CleanUp`? Shouldn't we just 
delete it and replace all uses with the pre-existing class?


Repository:
  rL LLVM

https://reviews.llvm.org/D48337



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


[Lldb-commits] [PATCH] D48337: Refactor OnExit utility class in ClangUserExpression

2018-06-19 Thread Raphael Isemann 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 rL335078: Refactor OnExit utility class in ClangUserExpression 
(authored by teemperor, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48337?vs=151978=151980#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48337

Files:
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp


Index: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
===
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -307,6 +307,21 @@
 #undef OBJC_CAST_HACK_FROM
 }
 
+namespace {
+// Utility guard that calls a callback when going out of scope.
+class OnExit {
+public:
+  typedef std::function Callback;
+
+  OnExit(Callback const ) : m_callback(callback) {}
+
+  ~OnExit() { m_callback(); }
+
+private:
+  Callback m_callback;
+};
+} // namespace
+
 bool ClangUserExpression::Parse(DiagnosticManager _manager,
 ExecutionContext _ctx,
 lldb_private::ExecutionPolicy execution_policy,
@@ -426,28 +441,12 @@
 
   ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
 
-  class OnExit {
-  public:
-typedef std::function Callback;
-
-OnExit(Callback const ) : m_callback(callback) {}
-
-~OnExit() { m_callback(); }
-
-  private:
-Callback m_callback;
-  };
-
   OnExit on_exit([this]() { ResetDeclMap(); });
 
   if (!DeclMap()->WillParse(exe_ctx, m_materializer_ap.get())) {
 diagnostic_manager.PutString(
 eDiagnosticSeverityError,
 "current process state is unsuitable for expression parsing");
-
-ResetDeclMap(); // We are being careful here in the case of breakpoint
-// conditions.
-
 return false;
   }
 
@@ -484,10 +483,6 @@
   fixed_expression.substr(fixed_start, fixed_end - fixed_start);
   }
 }
-
-ResetDeclMap(); // We are being careful here in the case of breakpoint
-// conditions.
-
 return false;
   }
 
@@ -565,10 +560,6 @@
 }
   }
 
-  ResetDeclMap(); // Make this go away since we don't need any of its state
-  // after parsing.  This also gets rid of any
-  // ClangASTImporter::Minions.
-
   if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS)
 m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
   return true;


Index: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
===
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -307,6 +307,21 @@
 #undef OBJC_CAST_HACK_FROM
 }
 
+namespace {
+// Utility guard that calls a callback when going out of scope.
+class OnExit {
+public:
+  typedef std::function Callback;
+
+  OnExit(Callback const ) : m_callback(callback) {}
+
+  ~OnExit() { m_callback(); }
+
+private:
+  Callback m_callback;
+};
+} // namespace
+
 bool ClangUserExpression::Parse(DiagnosticManager _manager,
 ExecutionContext _ctx,
 lldb_private::ExecutionPolicy execution_policy,
@@ -426,28 +441,12 @@
 
   ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
 
-  class OnExit {
-  public:
-typedef std::function Callback;
-
-OnExit(Callback const ) : m_callback(callback) {}
-
-~OnExit() { m_callback(); }
-
-  private:
-Callback m_callback;
-  };
-
   OnExit on_exit([this]() { ResetDeclMap(); });
 
   if (!DeclMap()->WillParse(exe_ctx, m_materializer_ap.get())) {
 diagnostic_manager.PutString(
 eDiagnosticSeverityError,
 "current process state is unsuitable for expression parsing");
-
-ResetDeclMap(); // We are being careful here in the case of breakpoint
-// conditions.
-
 return false;
   }
 
@@ -484,10 +483,6 @@
   fixed_expression.substr(fixed_start, fixed_end - fixed_start);
   }
 }
-
-ResetDeclMap(); // We are being careful here in the case of breakpoint
-// conditions.
-
 return false;
   }
 
@@ -565,10 +560,6 @@
 }
   }
 
-  ResetDeclMap(); // Make this go away since we don't need any of its state
-  // after parsing.  This also gets rid of any
-  // ClangASTImporter::Minions.
-
   if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS)
 m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
   return true;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org

[Lldb-commits] [lldb] r335078 - Refactor OnExit utility class in ClangUserExpression

2018-06-19 Thread Raphael Isemann via lldb-commits
Author: teemperor
Date: Tue Jun 19 14:25:59 2018
New Revision: 335078

URL: http://llvm.org/viewvc/llvm-project?rev=335078=rev
Log:
Refactor OnExit utility class in ClangUserExpression

Summary:
OnExit ensures we call `ResetDeclMap` before this method ends. However,
we also have a few manual calls to ResetDeclMap in there that are actually 
unnecessary
because of this (calling the method multiple times has no effect). This patch 
also moves
the class out of the method that we can reuse it for the upcoming method that 
handles
parsing for completion.

Subscribers: lldb-commits

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

Modified:
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp

Modified: 
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp?rev=335078=335077=335078=diff
==
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp 
(original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp 
Tue Jun 19 14:25:59 2018
@@ -307,6 +307,21 @@ static void ApplyObjcCastHack(std::strin
 #undef OBJC_CAST_HACK_FROM
 }
 
+namespace {
+// Utility guard that calls a callback when going out of scope.
+class OnExit {
+public:
+  typedef std::function Callback;
+
+  OnExit(Callback const ) : m_callback(callback) {}
+
+  ~OnExit() { m_callback(); }
+
+private:
+  Callback m_callback;
+};
+} // namespace
+
 bool ClangUserExpression::Parse(DiagnosticManager _manager,
 ExecutionContext _ctx,
 lldb_private::ExecutionPolicy execution_policy,
@@ -426,28 +441,12 @@ bool ClangUserExpression::Parse(Diagnost
 
   ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
 
-  class OnExit {
-  public:
-typedef std::function Callback;
-
-OnExit(Callback const ) : m_callback(callback) {}
-
-~OnExit() { m_callback(); }
-
-  private:
-Callback m_callback;
-  };
-
   OnExit on_exit([this]() { ResetDeclMap(); });
 
   if (!DeclMap()->WillParse(exe_ctx, m_materializer_ap.get())) {
 diagnostic_manager.PutString(
 eDiagnosticSeverityError,
 "current process state is unsuitable for expression parsing");
-
-ResetDeclMap(); // We are being careful here in the case of breakpoint
-// conditions.
-
 return false;
   }
 
@@ -484,10 +483,6 @@ bool ClangUserExpression::Parse(Diagnost
   fixed_expression.substr(fixed_start, fixed_end - fixed_start);
   }
 }
-
-ResetDeclMap(); // We are being careful here in the case of breakpoint
-// conditions.
-
 return false;
   }
 
@@ -565,10 +560,6 @@ bool ClangUserExpression::Parse(Diagnost
 }
   }
 
-  ResetDeclMap(); // Make this go away since we don't need any of its state
-  // after parsing.  This also gets rid of any
-  // ClangASTImporter::Minions.
-
   if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS)
 m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
   return true;


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


[Lldb-commits] [PATCH] D48337: Refactor OnExit utility class in ClangUserExpression

2018-06-19 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor created this revision.

OnExit ensures we call `ResetDeclMap` before this method ends. However,
we also have a few manual calls to ResetDeclMap in there that are actually 
unnecessary
because of this (calling the method multiple times has no effect). This patch 
also moves
the class out of the method that we can reuse it for the upcoming method that 
handles
parsing for completion.


https://reviews.llvm.org/D48337

Files:
  source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp


Index: source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
===
--- source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -307,6 +307,21 @@
 #undef OBJC_CAST_HACK_FROM
 }
 
+namespace {
+// Utility guard that calls a callback when going out of scope.
+class OnExit {
+public:
+  typedef std::function Callback;
+
+  OnExit(Callback const ) : m_callback(callback) {}
+
+  ~OnExit() { m_callback(); }
+
+private:
+  Callback m_callback;
+};
+} // namespace
+
 bool ClangUserExpression::Parse(DiagnosticManager _manager,
 ExecutionContext _ctx,
 lldb_private::ExecutionPolicy execution_policy,
@@ -426,28 +441,12 @@
 
   ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
 
-  class OnExit {
-  public:
-typedef std::function Callback;
-
-OnExit(Callback const ) : m_callback(callback) {}
-
-~OnExit() { m_callback(); }
-
-  private:
-Callback m_callback;
-  };
-
   OnExit on_exit([this]() { ResetDeclMap(); });
 
   if (!DeclMap()->WillParse(exe_ctx, m_materializer_ap.get())) {
 diagnostic_manager.PutString(
 eDiagnosticSeverityError,
 "current process state is unsuitable for expression parsing");
-
-ResetDeclMap(); // We are being careful here in the case of breakpoint
-// conditions.
-
 return false;
   }
 
@@ -484,10 +483,6 @@
   fixed_expression.substr(fixed_start, fixed_end - fixed_start);
   }
 }
-
-ResetDeclMap(); // We are being careful here in the case of breakpoint
-// conditions.
-
 return false;
   }
 
@@ -565,10 +560,6 @@
 }
   }
 
-  ResetDeclMap(); // Make this go away since we don't need any of its state
-  // after parsing.  This also gets rid of any
-  // ClangASTImporter::Minions.
-
   if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS)
 m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
   return true;


Index: source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
===
--- source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -307,6 +307,21 @@
 #undef OBJC_CAST_HACK_FROM
 }
 
+namespace {
+// Utility guard that calls a callback when going out of scope.
+class OnExit {
+public:
+  typedef std::function Callback;
+
+  OnExit(Callback const ) : m_callback(callback) {}
+
+  ~OnExit() { m_callback(); }
+
+private:
+  Callback m_callback;
+};
+} // namespace
+
 bool ClangUserExpression::Parse(DiagnosticManager _manager,
 ExecutionContext _ctx,
 lldb_private::ExecutionPolicy execution_policy,
@@ -426,28 +441,12 @@
 
   ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
 
-  class OnExit {
-  public:
-typedef std::function Callback;
-
-OnExit(Callback const ) : m_callback(callback) {}
-
-~OnExit() { m_callback(); }
-
-  private:
-Callback m_callback;
-  };
-
   OnExit on_exit([this]() { ResetDeclMap(); });
 
   if (!DeclMap()->WillParse(exe_ctx, m_materializer_ap.get())) {
 diagnostic_manager.PutString(
 eDiagnosticSeverityError,
 "current process state is unsuitable for expression parsing");
-
-ResetDeclMap(); // We are being careful here in the case of breakpoint
-// conditions.
-
 return false;
   }
 
@@ -484,10 +483,6 @@
   fixed_expression.substr(fixed_start, fixed_end - fixed_start);
   }
 }
-
-ResetDeclMap(); // We are being careful here in the case of breakpoint
-// conditions.
-
 return false;
   }
 
@@ -565,10 +560,6 @@
 }
   }
 
-  ResetDeclMap(); // Make this go away since we don't need any of its state
-  // after parsing.  This also gets rid of any
-  // ClangASTImporter::Minions.
-
   if (process && m_jit_start_addr != LLDB_INVALID_ADDRESS)
 m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
   return true;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D48295: [WIP] Implement new ReturnMIStatus method of CMICmdBase class.

2018-06-19 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

I think I misread your patch. Now the naming of success_handler makes much more 
sense, too.

What do you think about defining a function that takes an SBError result, and a 
function that converts this error into a string? This would allow chaining more 
than one SBAPI command in one lldb-mi command implementation. I'm not sure how 
common this is, though.

  bool handleSBError(SBError error, std::function 
convert) {
if (error.Success())
  return false;
  
SetError(convert(error));
return error_handler();
  }
  
  ...
  bool CMICmdCmdExecContinue::Execute() {
if 
(handleSBError(CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue(), 
[](SBError error){
  return CMIUtilString::Format(
 MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
 this->m_cmdData.strMiCmd.c_str(),
 rErrMsg.c_str());'
 }) 
  return MIstatus::failure;
  
// potentially run other SBAPI commands...
return MIstatus::success;
  };


https://reviews.llvm.org/D48295



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


[Lldb-commits] [PATCH] D48303: Don't take the address of an xvalue when printing an expr result

2018-06-19 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor updated this revision to Diff 151967.
teemperor added a comment.

- Generalized test case a bit more and no longer checking only for 0.


https://reviews.llvm.org/D48303

Files:
  packages/Python/lldbsuite/test/expression_command/xvalue/Makefile
  packages/Python/lldbsuite/test/expression_command/xvalue/TestXValuePrinting.py
  packages/Python/lldbsuite/test/expression_command/xvalue/main.cpp
  source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp


Index: source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
===
--- source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
+++ source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
@@ -292,9 +292,8 @@
   //
   //   - During dematerialization, $0 is ignored.
 
-  bool is_lvalue = (last_expr->getValueKind() == VK_LValue ||
-last_expr->getValueKind() == VK_XValue) &&
-   (last_expr->getObjectKind() == OK_Ordinary);
+  bool is_lvalue = last_expr->getValueKind() == VK_LValue &&
+   last_expr->getObjectKind() == OK_Ordinary;
 
   QualType expr_qual_type = last_expr->getType();
   const clang::Type *expr_type = expr_qual_type.getTypePtr();
Index: packages/Python/lldbsuite/test/expression_command/xvalue/main.cpp
===
--- /dev/null
+++ packages/Python/lldbsuite/test/expression_command/xvalue/main.cpp
@@ -0,0 +1,14 @@
+#include 
+
+struct Tmp
+{
+  int data = 1234;
+};
+
+Tmp foo() { return Tmp(); }
+
+int main(int argc, char const *argv[])
+{
+  int something = foo().data;
+  return 0; // Break here
+}
Index: 
packages/Python/lldbsuite/test/expression_command/xvalue/TestXValuePrinting.py
===
--- /dev/null
+++ 
packages/Python/lldbsuite/test/expression_command/xvalue/TestXValuePrinting.py
@@ -0,0 +1,37 @@
+from __future__ import print_function
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ExprXValuePrintingTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+
+self.main_source = "main.cpp"
+self.main_source_spec = lldb.SBFileSpec(self.main_source)
+
+def do_test(self, dictionary=None):
+"""Printing an xvalue should work."""
+self.build(dictionary=dictionary)
+
+(target, process, thread, bkpt) = 
lldbutil.run_to_source_breakpoint(self, 
+  '// Break here', 
self.main_source_spec)
+frame = thread.GetFrameAtIndex(0)
+
+value = frame.EvaluateExpression("foo().data")
+self.assertTrue(value.IsValid())
+self.assertTrue(value.GetError().Success())
+self.assertEqual(value.GetValueAsSigned(), 1234)
+
+@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")
+def test(self):
+self.do_test()
+
Index: packages/Python/lldbsuite/test/expression_command/xvalue/Makefile
===
--- /dev/null
+++ packages/Python/lldbsuite/test/expression_command/xvalue/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules


Index: source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
===
--- source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
+++ source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
@@ -292,9 +292,8 @@
   //
   //   - During dematerialization, $0 is ignored.
 
-  bool is_lvalue = (last_expr->getValueKind() == VK_LValue ||
-last_expr->getValueKind() == VK_XValue) &&
-   (last_expr->getObjectKind() == OK_Ordinary);
+  bool is_lvalue = last_expr->getValueKind() == VK_LValue &&
+   last_expr->getObjectKind() == OK_Ordinary;
 
   QualType expr_qual_type = last_expr->getType();
   const clang::Type *expr_type = expr_qual_type.getTypePtr();
Index: packages/Python/lldbsuite/test/expression_command/xvalue/main.cpp
===
--- /dev/null
+++ packages/Python/lldbsuite/test/expression_command/xvalue/main.cpp
@@ -0,0 +1,14 @@
+#include 
+
+struct Tmp
+{
+  int data = 1234;
+};
+
+Tmp foo() { return Tmp(); }
+
+int main(int argc, char const *argv[])
+{
+  int something = foo().data;
+  return 0; // Break here
+}
Index: packages/Python/lldbsuite/test/expression_command/xvalue/TestXValuePrinting.py
===
--- /dev/null
+++ packages/Python/lldbsuite/test/expression_command/xvalue/TestXValuePrinting.py
@@ -0,0 +1,37 @@
+from __future__ import print_function
+
+
+import lldb
+from 

[Lldb-commits] [PATCH] D48295: [WIP] Implement new ReturnMIStatus method of CMICmdBase class.

2018-06-19 Thread Alexander Polyakov via Phabricator via lldb-commits
apolyakov added a comment.

Sorry, but I still don't understand you. In my thoughts, user specify actions 
for success and/or error cases. Success case means that out SBError objects' 
status is success(`sb_error.Success() == true`). Error case means similar 
except SBError object has fail status. So if SBError has success status we 
should call `success_handler`, specified by user. I don't see similar logic in 
your pseudo code. Could you please explain your idea more exactly?


https://reviews.llvm.org/D48295



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


[Lldb-commits] [lldb] r335060 - Scalar: Use llvm integer conversion functions

2018-06-19 Thread Pavel Labath via lldb-commits
Author: labath
Date: Tue Jun 19 10:24:03 2018
New Revision: 335060

URL: http://llvm.org/viewvc/llvm-project?rev=335060=rev
Log:
Scalar: Use llvm integer conversion functions

StringConvert was the only non-Utility dependency of this class. Getting
rid of it means it will be easy to move this class to a lower layer.

While I was in there, I also added a couple of unit tests for the Scalar
string conversion function.

Modified:
lldb/trunk/source/Core/Scalar.cpp
lldb/trunk/unittests/Core/CMakeLists.txt
lldb/trunk/unittests/Core/ScalarTest.cpp

Modified: lldb/trunk/source/Core/Scalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Scalar.cpp?rev=335060=335059=335060=diff
==
--- lldb/trunk/source/Core/Scalar.cpp (original)
+++ lldb/trunk/source/Core/Scalar.cpp Tue Jun 19 10:24:03 2018
@@ -9,7 +9,6 @@
 
 #include "lldb/Core/Scalar.h"
 
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Utility/DataExtractor.h"
 #include "lldb/Utility/Endian.h"
 #include "lldb/Utility/Status.h"
@@ -2254,17 +2253,15 @@ Status Scalar::SetValueFromCString(const
 error.SetErrorString("Invalid c-string value string.");
 return error;
   }
-  bool success = false;
   switch (encoding) {
   case eEncodingInvalid:
 error.SetErrorString("Invalid encoding.");
 break;
 
   case eEncodingUint:
-if (byte_size <= sizeof(unsigned long long)) {
-  uint64_t uval64 =
-  StringConvert::ToUInt64(value_str, UINT64_MAX, 0, );
-  if (!success)
+if (byte_size <= sizeof(uint64_t)) {
+  uint64_t uval64;
+  if (!llvm::to_integer(value_str, uval64))
 error.SetErrorStringWithFormat(
 "'%s' is not a valid unsigned integer string value", value_str);
   else if (!UIntValueIsValidForSize(uval64, byte_size))
@@ -2300,10 +2297,9 @@ Status Scalar::SetValueFromCString(const
 break;
 
   case eEncodingSint:
-if (byte_size <= sizeof(long long)) {
-  uint64_t sval64 =
-  StringConvert::ToSInt64(value_str, INT64_MAX, 0, );
-  if (!success)
+if (byte_size <= sizeof(int64_t)) {
+  int64_t sval64;
+  if (!llvm::to_integer(value_str, sval64))
 error.SetErrorStringWithFormat(
 "'%s' is not a valid signed integer string value", value_str);
   else if (!SIntValueIsValidForSize(sval64, byte_size))

Modified: lldb/trunk/unittests/Core/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/CMakeLists.txt?rev=335060=335059=335060=diff
==
--- lldb/trunk/unittests/Core/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Core/CMakeLists.txt Tue Jun 19 10:24:03 2018
@@ -9,6 +9,7 @@ add_lldb_unittest(LLDBCoreTests
   LINK_LIBS
 lldbCore
 lldbHost
+LLVMTestingSupport
   LINK_COMPONENTS
 Support
   )

Modified: lldb/trunk/unittests/Core/ScalarTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/ScalarTest.cpp?rev=335060=335059=335060=diff
==
--- lldb/trunk/unittests/Core/ScalarTest.cpp (original)
+++ lldb/trunk/unittests/Core/ScalarTest.cpp Tue Jun 19 10:24:03 2018
@@ -14,8 +14,10 @@
 #include "lldb/Utility/Endian.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StreamString.h"
+#include "llvm/Testing/Support/Error.h"
 
 using namespace lldb_private;
+using namespace llvm;
 
 TEST(ScalarTest, RightShiftOperator) {
   int a = 0x1000;
@@ -185,3 +187,34 @@ TEST(ScalarTest, Promotion) {
 }
   }
 }
+
+TEST(ScalarTest, SetValueFromCString) {
+  Scalar a;
+
+  EXPECT_THAT_ERROR(
+  a.SetValueFromCString("1234567890123", lldb::eEncodingUint, 8).ToError(),
+  Succeeded());
+  EXPECT_EQ(1234567890123ull, a);
+
+  EXPECT_THAT_ERROR(
+  a.SetValueFromCString("-1234567890123", lldb::eEncodingSint, 
8).ToError(),
+  Succeeded());
+  EXPECT_EQ(-1234567890123ll, a);
+
+  EXPECT_THAT_ERROR(
+  a.SetValueFromCString("asdf", lldb::eEncodingSint, 8).ToError(),
+  Failed());
+  EXPECT_THAT_ERROR(
+  a.SetValueFromCString("asdf", lldb::eEncodingUint, 8).ToError(),
+  Failed());
+  EXPECT_THAT_ERROR(
+  a.SetValueFromCString("1234567890123", lldb::eEncodingUint, 4).ToError(),
+  Failed());
+  EXPECT_THAT_ERROR(a.SetValueFromCString("123456789012345678901234567890",
+  lldb::eEncodingUint, 8)
+.ToError(),
+Failed());
+  EXPECT_THAT_ERROR(
+  a.SetValueFromCString("-123", lldb::eEncodingUint, 8).ToError(),
+  Failed());
+}


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


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

2018-06-19 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

I think ultimately we should make this presentation of variables as symmetrical 
with locals as we can or it's going to confuse users.

I don't think it is necessary for the first version.  The first uses, I would 
imagine, are to make available some variables in situations where none existed 
before - mostly digging info out of frames with no debug info - so it's 
strictly better than what was there before already...


https://reviews.llvm.org/D44603



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


Re: [Lldb-commits] [lldb] r334642 - [lit] Split test_set_working_dir TestProcessLaunch into two tests and fix it on Windows

2018-06-19 Thread Stella Stamenova via lldb-commits
Hey Greg,

I would be hesitant to make any big changes at the moment since it's my 
understanding that Zachary is working on a change that would impact all 
platforms (specifically for process launching).

That said, I've been looking at some of the other failing tests on Windows and 
I can compare notes with the implementation in ds2 to see if some of their 
windows changes can help with the issues that LLDB has. By the way, I did 
notice going through the ds2 sources that they have some TODOs in the windows 
code for some of the same features that are currently missing or not working 
correctly in LLDB (such as Wow64, floating point registers, etc.), so their 
implementation is not complete either.

Thank you,
-Stella

-Original Message-
From: Greg Clayton  
Sent: Wednesday, June 13, 2018 1:10 PM
To: Stella Stamenova 
Cc: lldb-commits@lists.llvm.org
Subject: Re: [Lldb-commits] [lldb] r334642 - [lit] Split test_set_working_dir 
TestProcessLaunch into two tests and fix it on Windows

I like seeing the windows debugger plug-in getting fixes.

LLDB currently encourages everyone to add native debugging support to 
lldb-server. Then you get remote debugging support for free. It seems like you 
are putting in some time on the windows fixes, so I thought I would pass this 
along. The ProcessGDBRemote is the most tested protocol in LLDB currently so I 
am guessing things might be easier in the long run if you go that route.

FYI: ds2 is an open source GDB server that actually already supports windows:

https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ffacebook%2Fds2=02%7C01%7Cstilis%40microsoft.com%7C6ac25ad6ce7941c2c79608d5d169abc1%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C1%7C636645174145470302=HcSScsDUTELddsNkvDA4cdAqimL1gn9D3KmH9B6mAng%3D=0

It is a separate GDB remote server that was not built using any LLDB sources.

It would be interesting to possibly port the windows changes over into LLDB's 
lldb-server.

Let me know what you think,

Greg Clayton


> On Jun 13, 2018, at 12:02 PM, Stella Stamenova via lldb-commits 
>  wrote:
> 
> Author: stella.stamenova
> Date: Wed Jun 13 12:02:44 2018
> New Revision: 334642
> 
> URL: 
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.o
> rg%2Fviewvc%2Fllvm-project%3Frev%3D334642%26view%3Drev=02%7C01%7C
> stilis%40microsoft.com%7C6ac25ad6ce7941c2c79608d5d169abc1%7C72f988bf86
> f141af91ab2d7cd011db47%7C1%7C1%7C636645174145470302=UtY53Z8TR6kp
> g6sPmO9vVqoM%2F%2BVNXI7QYHjBg9AspYg%3D=0
> Log:
> [lit] Split test_set_working_dir TestProcessLaunch into two tests and 
> fix it on Windows
> 
> Summary:
> test_set_working_dir was testing two scenario: failure to set the working dir 
> because of a non existent directory and succeeding to set the working 
> directory. Since the negative case fails on both Linux and Windows, the 
> positive case was never tested. I split the test into two which allows us to 
> always run both the negative and positive cases. The positive case now 
> succeeds on Linux and the negative case still fails.
> During the investigation, it turned out that lldbtest.py will try to execute 
> a process launch command up to 3 times if the command failed. This means that 
> we could be covering up intermittent failures by running any test that does 
> process launch multiple times without ever realizing it. I've changed the 
> counter to 1 (though it can still be overwritten with the environment 
> variable).
> This change also fixes both the positive and negative cases on Windows. There 
> were a few issues:
> 1) In ProcessLauncherWindows::LaunchProcess, the error was not retrieved 
> until CloseHandle was possibly called. Since CloseHandle is also a system 
> API, its success would overwrite any existing error that could be retrieved 
> using GetLastError. So by the time the error was retrieved, it was now a 
> success.
> 2) In DebuggerThread::StopDebugging TerminateProcess was called on the 
> process handle regardless of whether it was a valid handle. This was causing 
> the process to crash when the handle was LLDB_INVALID_PROCESS (0x).
> 3) In ProcessWindows::DoLaunch we need to check that the working directory 
> exists before launching the process to have the same behavior as other 
> platforms which first check the directory and then launch process. This way 
> we also control the exact error string.
> 
> Reviewers: labath, zturner, asmith, jingham
> 
> Reviewed By: labath
> 
> Subscribers: llvm-commits
> 
> Differential Revision: 
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Frevie
> ws.llvm.org%2FD48050=02%7C01%7Cstilis%40microsoft.com%7C6ac25ad6c
> e7941c2c79608d5d169abc1%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C1%7C6
> 36645174145470302=5PJhjuRZ%2BKpipw0vuSaW5pEm2C3jZ688QhXYJeqKIOQ%
> 3D=0
> 
> Modified:
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/TestProcessLaunch.py
>lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
> 

[Lldb-commits] [PATCH] D48303: Don't take the address of an xvalue when printing an expr result

2018-06-19 Thread Frederic Riss via Phabricator via lldb-commits
friss added inline comments.



Comment at: 
packages/Python/lldbsuite/test/expression_command/xvalue/TestXValuePrinting.py:32
+self.assertTrue(value.GetError().Success())
+self.assertEqual(value.GetValueAsUnsigned(), 0)
+

Could you use a different value than 0? Getting a random zero from memory seems 
to easy. It would be better to test a real string.


https://reviews.llvm.org/D48303



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


[Lldb-commits] [PATCH] D48295: [WIP] Implement new ReturnMIStatus method of CMICmdBase class.

2018-06-19 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

In https://reviews.llvm.org/D48295#1136692, @apolyakov wrote:

> I don't completely understand what you mean. First of all, what do you mean 
> when talking about success_handlers? 'cause if you mean success_handler from 
> `Execute` function, then I should say that it doesn't have to set an error, 
> it might be any. Secondly, `status` in your example is a function, how can it 
> has a `takeError` method?


`status` is meant to be a `bool`. I think `success_handler` was a bad name. It 
should probably be called `action` or `command` something similar. It would be 
the actual implementation of the command, such as lambda that is assigned to 
`success_handler` in your patch.


https://reviews.llvm.org/D48295



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


[Lldb-commits] [PATCH] D48295: [WIP] Implement new ReturnMIStatus method of CMICmdBase class.

2018-06-19 Thread Alexander Polyakov via Phabricator via lldb-commits
apolyakov added a comment.

In https://reviews.llvm.org/D48295#1136663, @aprantl wrote:

> In this design the success_handlers return an exit status *and* set a string 
> error. We could unify this by having the handler return an llvm::Error 
> (https://llvm.org/doxygen/classllvm_1_1Error.html). When it is successful, it 
> returns Error::success, otherwise it returns 
> `llvm::make_error("message", 
> llvm::inconvertibleErrorCode)`. In ReturnMIStatus we do something like
>
>   auto status = handler(...)
>   bool exit_status =  MIstatus::success;
>   handleAllErrors(status.takeError(), [&](const StringError ) {
> his->SetError(error.getMessage();
> exit_status =  error_handler();
>   });
>   return exit_status;
>


I don't completely understand what you mean. First of all, what do you mean 
when talking about success_handlers? 'cause if you mean success_handler from 
`Execute` function, then I should say that it doesn't have to set an error, it 
might be any. Secondly, `status` in your example is a function, how can it has 
a `takeError` method?


https://reviews.llvm.org/D48295



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


[Lldb-commits] [PATCH] D48295: [WIP] Implement new ReturnMIStatus method of CMICmdBase class.

2018-06-19 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

In this design the success_handlers return an exit status *and* set a string 
error. We could unify this by having the handler return an llvm::Error 
(https://llvm.org/doxygen/classllvm_1_1Error.html). When it is successful, it 
returns Error::success, otherwise it returns 
`llvm::make_error("message", llvm::inconvertibleErrorCode)`. 
In ReturnMIStatus we do something like

  auto status = handler(...)
  bool exit_status =  MIstatus::success;
  handleAllErrors(status.takeError(), [&](const StringError ) {
his->SetError(error.getMessage();
exit_status =  error_handler();
  });
  return exit_status;


https://reviews.llvm.org/D48295



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


[Lldb-commits] [PATCH] D48215: Remove dependency from Host to python

2018-06-19 Thread Pavel Labath via Phabricator via lldb-commits
labath updated this revision to Diff 151922.
labath added a comment.

Rebase this patch on trunk. Now this patch is simply about moving GetPythonDir
from Host module to ScriptInterpreterPython.


https://reviews.llvm.org/D48215

Files:
  include/lldb/Host/macosx/HostInfoMacOSX.h
  include/lldb/Host/posix/HostInfoPosix.h
  include/lldb/Host/windows/HostInfoWindows.h
  source/API/SBHostOS.cpp
  source/Host/CMakeLists.txt
  source/Host/common/HostInfoBase.cpp
  source/Host/macosx/objcxx/HostInfoMacOSX.mm
  source/Host/posix/HostInfoPosix.cpp
  source/Host/windows/HostInfoWindows.cpp
  source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h

Index: source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
===
--- source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
+++ source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
@@ -445,6 +445,8 @@
 
   static const char *GetPluginDescriptionStatic();
 
+  static FileSpec GetPythonDir();
+
   //--
   // PluginInterface protocol
   //--
@@ -509,6 +511,10 @@
 
   static void AddToSysPath(AddLocation location, std::string path);
 
+  static void ComputePythonDirForApple(llvm::SmallVectorImpl );
+  static void ComputePythonDirForPosix(llvm::SmallVectorImpl );
+  static void ComputePythonDirForWindows(llvm::SmallVectorImpl );
+
   bool EnterSession(uint16_t on_entry_flags, FILE *in, FILE *out, FILE *err);
 
   void LeaveSession();
Index: source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -347,6 +347,71 @@
   return "Embedded Python interpreter";
 }
 
+void ScriptInterpreterPython::ComputePythonDirForApple(
+llvm::SmallVectorImpl ) {
+  auto style = llvm::sys::path::Style::posix;
+
+  llvm::StringRef path_ref(path.begin(), path.size());
+  auto rbegin = llvm::sys::path::rbegin(path_ref, style);
+  auto rend = llvm::sys::path::rend(path_ref);
+  auto framework = std::find(rbegin, rend, "LLDB.framework");
+  if (framework == rend) {
+ComputePythonDirForPosix(path);
+return;
+  }
+  path.resize(framework - rend);
+  llvm::sys::path::append(path, style, "LLDB.framework", "Resources", "Python");
+}
+
+void ScriptInterpreterPython::ComputePythonDirForPosix(
+llvm::SmallVectorImpl ) {
+  auto style = llvm::sys::path::Style::posix;
+#if defined(LLDB_PYTHON_RELATIVE_LIBDIR)
+  // Build the path by backing out of the lib dir, then building with whatever
+  // the real python interpreter uses.  (e.g. lib for most, lib64 on RHEL
+  // x86_64).
+  llvm::sys::path::remove_filename(path, style);
+  llvm::sys::path::append(path, style, LLDB_PYTHON_RELATIVE_LIBDIR);
+#else
+  llvm::sys::path::append(path, style,
+  "python" + llvm::Twine(PY_MAJOR_VERSION) + "." +
+  llvm::Twine(PY_MINOR_VERSION),
+  "site-packages");
+#endif
+}
+
+void ScriptInterpreterPython::ComputePythonDirForWindows(
+llvm::SmallVectorImpl ) {
+  auto style = llvm::sys::path::Style::windows;
+  llvm::sys::path::remove_filename(path, style);
+  llvm::sys::path::append(path, style, "lib", "site-packages");
+
+  // This will be injected directly through FileSpec.GetDirectory().SetString(),
+  // so we need to normalize manually.
+  std::replace(path.begin(), path.end(), '\\', '/');
+}
+
+FileSpec ScriptInterpreterPython::GetPythonDir() {
+  static FileSpec g_spec = []() {
+FileSpec spec = HostInfo::GetShlibDir();
+if (!spec)
+  return FileSpec();
+llvm::SmallString<64> path;
+spec.GetPath(path);
+
+#if defined(__APPLE__)
+ComputePythonDirForApple(path);
+#elif defined(_WIN32)
+ComputePythonDirForWindows(path);
+#else
+ComputePythonDirForPosix(path);
+#endif
+spec.GetDirectory().SetString(path);
+return spec;
+  }();
+  return g_spec;
+}
+
 lldb_private::ConstString ScriptInterpreterPython::GetPluginName() {
   return GetPluginNameStatic();
 }
@@ -3098,7 +3163,7 @@
   // that use a backslash as the path separator, this will result in executing
   // python code containing paths with unescaped backslashes.  But Python also
   // accepts forward slashes, so to make life easier we just use that.
-  if (FileSpec file_spec = HostInfo::GetPythonDir())
+  if (FileSpec file_spec = GetPythonDir())
 AddToSysPath(AddLocation::Beginning, file_spec.GetPath(false));
   if (FileSpec file_spec = HostInfo::GetShlibDir())
 AddToSysPath(AddLocation::Beginning, file_spec.GetPath(false));
Index: 

[Lldb-commits] [PATCH] D48272: Replace HostInfo::GetLLDBPath with specific functions

2018-06-19 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL335052: Replace HostInfo::GetLLDBPath with specific 
functions (authored by labath, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D48272

Files:
  lldb/trunk/include/lldb/Host/HostInfoBase.h
  lldb/trunk/source/API/SBHostOS.cpp
  lldb/trunk/source/Core/Debugger.cpp
  lldb/trunk/source/Core/PluginManager.cpp
  lldb/trunk/source/Expression/REPL.cpp
  lldb/trunk/source/Host/common/Host.cpp
  lldb/trunk/source/Host/common/HostInfoBase.cpp
  lldb/trunk/source/Host/macosx/objcxx/Host.mm
  lldb/trunk/source/Host/macosx/objcxx/HostInfoMacOSX.mm
  lldb/trunk/source/Host/posix/HostInfoPosix.cpp
  lldb/trunk/source/Host/posix/PipePosix.cpp
  lldb/trunk/source/Host/windows/Host.cpp
  lldb/trunk/source/Host/windows/HostInfoWindows.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
  lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
  lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
  
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
  lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/trunk/unittests/Target/ModuleCacheTest.cpp

Index: lldb/trunk/unittests/Target/ModuleCacheTest.cpp
===
--- lldb/trunk/unittests/Target/ModuleCacheTest.cpp
+++ lldb/trunk/unittests/Target/ModuleCacheTest.cpp
@@ -68,8 +68,7 @@
   HostInfo::Initialize();
   ObjectFileELF::Initialize();
 
-  FileSpec tmpdir_spec;
-  HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir, s_cache_dir);
+  s_cache_dir = HostInfo::GetProcessTempDir();
   s_test_executable = GetInputFilePath(module_name);
 }
 
Index: lldb/trunk/source/API/SBHostOS.cpp
===
--- lldb/trunk/source/API/SBHostOS.cpp
+++ lldb/trunk/source/API/SBHostOS.cpp
@@ -32,24 +32,43 @@
 }
 
 SBFileSpec SBHostOS::GetLLDBPythonPath() {
-  SBFileSpec sb_lldb_python_filespec;
-  FileSpec lldb_python_spec;
-  if (HostInfo::GetLLDBPath(ePathTypePythonDir, lldb_python_spec)) {
-sb_lldb_python_filespec.SetFileSpec(lldb_python_spec);
-  }
-  return sb_lldb_python_filespec;
+  return GetLLDBPath(ePathTypePythonDir);
 }
 
 SBFileSpec SBHostOS::GetLLDBPath(lldb::PathType path_type) {
-  SBFileSpec sb_fspec;
   FileSpec fspec;
-  bool Success = true;
-  if (path_type == ePathTypeClangDir)
+  switch (path_type) {
+  case ePathTypeLLDBShlibDir:
+fspec = HostInfo::GetShlibDir();
+break;
+  case ePathTypeSupportExecutableDir:
+fspec = HostInfo::GetSupportExeDir();
+break;
+  case ePathTypeHeaderDir:
+fspec = HostInfo::GetHeaderDir();
+break;
+  case ePathTypePythonDir:
+fspec = HostInfo::GetPythonDir();
+break;
+  case ePathTypeLLDBSystemPlugins:
+fspec = HostInfo::GetSystemPluginDir();
+break;
+  case ePathTypeLLDBUserPlugins:
+fspec = HostInfo::GetUserPluginDir();
+break;
+  case ePathTypeLLDBTempSystemDir:
+fspec = HostInfo::GetProcessTempDir();
+break;
+  case ePathTypeGlobalLLDBTempSystemDir:
+fspec = HostInfo::GetGlobalTempDir();
+break;
+  case ePathTypeClangDir:
 fspec = GetClangResourceDir();
-  else
-Success = HostInfo::GetLLDBPath(path_type, fspec);
-  if (Success)
-sb_fspec.SetFileSpec(fspec);
+break;
+  }
+
+  SBFileSpec sb_fspec;
+  sb_fspec.SetFileSpec(fspec);
   return sb_fspec;
 }
 
Index: lldb/trunk/source/Core/PluginManager.cpp
===
--- lldb/trunk/source/Core/PluginManager.cpp
+++ lldb/trunk/source/Core/PluginManager.cpp
@@ -157,19 +157,18 @@
 
 void PluginManager::Initialize() {
 #if 1
-  FileSpec dir_spec;
   const bool find_directories = true;
   const bool find_files = true;
   const bool find_other = true;
   char dir_path[PATH_MAX];
-  if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec)) {
+  if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
   FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
find_other, LoadPluginCallback, nullptr);
 }
   }
 
-  if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec)) {
+  if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
   FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
find_other, LoadPluginCallback, nullptr);
Index: lldb/trunk/source/Core/Debugger.cpp
===
--- lldb/trunk/source/Core/Debugger.cpp
+++ 

[Lldb-commits] [lldb] r335052 - Replace HostInfo::GetLLDBPath with specific functions

2018-06-19 Thread Pavel Labath via lldb-commits
Author: labath
Date: Tue Jun 19 08:09:07 2018
New Revision: 335052

URL: http://llvm.org/viewvc/llvm-project?rev=335052=rev
Log:
Replace HostInfo::GetLLDBPath with specific functions

Summary:
Instead of a function taking an enum value determining which path to
return, we now have a suite of functions, each returning a single path
kind. This makes it easy to move the python-path function into a
specific plugin in a follow-up commit.

All the users of GetLLDBPath were converted to call specific functions
instead. Most of them were hard-coding the enum value anyway, so this
conversion was simple. The only exception was SBHostOS, which I've
changed to use a switch on the incoming enum value.

Reviewers: clayborg, zturner

Subscribers: lldb-commits

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

Modified:
lldb/trunk/include/lldb/Host/HostInfoBase.h
lldb/trunk/source/API/SBHostOS.cpp
lldb/trunk/source/Core/Debugger.cpp
lldb/trunk/source/Core/PluginManager.cpp
lldb/trunk/source/Expression/REPL.cpp
lldb/trunk/source/Host/common/Host.cpp
lldb/trunk/source/Host/common/HostInfoBase.cpp
lldb/trunk/source/Host/macosx/objcxx/Host.mm
lldb/trunk/source/Host/macosx/objcxx/HostInfoMacOSX.mm
lldb/trunk/source/Host/posix/HostInfoPosix.cpp
lldb/trunk/source/Host/posix/PipePosix.cpp
lldb/trunk/source/Host/windows/Host.cpp
lldb/trunk/source/Host/windows/HostInfoWindows.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp

lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
lldb/trunk/unittests/Target/ModuleCacheTest.cpp

Modified: lldb/trunk/include/lldb/Host/HostInfoBase.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostInfoBase.h?rev=335052=335051=335052=diff
==
--- lldb/trunk/include/lldb/Host/HostInfoBase.h (original)
+++ lldb/trunk/include/lldb/Host/HostInfoBase.h Tue Jun 19 08:09:07 2018
@@ -63,25 +63,39 @@ public:
 
   static llvm::Optional 
ParseArchitectureKind(llvm::StringRef kind);
 
-  //--
-  /// Find a resource files that are related to LLDB.
-  ///
-  /// Operating systems have different ways of storing shared
-  /// libraries and related resources. This function abstracts the
-  /// access to these paths.
-  ///
-  /// @param[in] path_type
-  /// The type of LLDB resource path you are looking for. If the
-  /// enumeration ends with "Dir", then only the \a file_spec's
-  /// directory member gets filled in.
-  ///
-  /// @param[in] file_spec
-  /// A file spec that gets filled in with the appropriate path.
-  ///
-  /// @return
-  /// \b true if \a resource_path was resolved, \a false otherwise.
-  //--
-  static bool GetLLDBPath(lldb::PathType type, FileSpec _spec);
+  /// Returns the directory containing the lldb shared library. Only the
+  /// directory member of the FileSpec is filled in.
+  static FileSpec GetShlibDir();
+
+  /// Returns the directory containing the support executables (debugserver,
+  /// ...). Only the directory member of the FileSpec is filled in.
+  static FileSpec GetSupportExeDir();
+
+  /// Returns the directory containing the lldb headers. Only the directory
+  /// member of the FileSpec is filled in.
+  static FileSpec GetHeaderDir();
+
+  /// Returns the directory containing the python modules. Only the directory
+  /// member of the FileSpec is filled in.
+  static FileSpec GetPythonDir();
+
+  /// Returns the directory containing the system plugins. Only the directory
+  /// member of the FileSpec is filled in.
+  static FileSpec GetSystemPluginDir();
+
+  /// Returns the directory containing the user plugins. Only the directory
+  /// member of the FileSpec is filled in.
+  static FileSpec GetUserPluginDir();
+
+  /// Returns the proces temporary directory. This directory will be cleaned up
+  /// when this process exits. Only the directory member of the FileSpec is
+  /// filled in.
+  static FileSpec GetProcessTempDir();
+
+  /// Returns the global temporary directory. This directory will **not** be
+  /// cleaned up when this process exits. Only the directory member of the
+  /// FileSpec is filled in.
+  static FileSpec GetGlobalTempDir();
 
   //---
   /// If the triple does not specify the vendor, os, and environment parts, we

Modified: lldb/trunk/source/API/SBHostOS.cpp

[Lldb-commits] [lldb] r335051 - Make TestCommandScript.py NO_DEBUG_INFO_TESTCASE

2018-06-19 Thread Pavel Labath via lldb-commits
Author: labath
Date: Tue Jun 19 08:07:22 2018
New Revision: 335051

URL: http://llvm.org/viewvc/llvm-project?rev=335051=rev
Log:
Make TestCommandScript.py NO_DEBUG_INFO_TESTCASE

Modified:

lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/TestCommandScript.py

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/TestCommandScript.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/TestCommandScript.py?rev=335051=335050=335051=diff
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/TestCommandScript.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/TestCommandScript.py
 Tue Jun 19 08:07:22 2018
@@ -15,6 +15,7 @@ from lldbsuite.test.lldbtest import *
 class CmdPythonTestCase(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
+NO_DEBUG_INFO_TESTCASE = True
 
 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343")
 def test(self):


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


[Lldb-commits] [PATCH] D48272: Replace HostInfo::GetLLDBPath with specific functions

2018-06-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In https://reviews.llvm.org/D48272#1135373, @clayborg wrote:

> Looks good. My only question is do we not require people to only fill in the 
> directory portion of the FileSpec anymore for these functions? I am fine with 
> way since hopefully FileSpec::AppendPathComponent handles things correctly.


I'm not sure if anyone actually depends on this behavior, but there is a test 
which actually requires this (TestPaths.py). I did consider dropping this 
promise for the internal API and doing the fixup in the SB layer, but I chose 
not to go along with that for now. I believe AppendPathComponent et al. will 
mostly work for these kinds of FileSpecs, but they are definitely a less well 
tested path.


https://reviews.llvm.org/D48272



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


Re: [Lldb-commits] [lldb] r334978 - Fixed file completion for paths that start with '~'.

2018-06-19 Thread Pavel Labath via lldb-commits
A test?

It looks like it should be possible to test this in a similar way to
other CommandCompletion tests
(unittests/Interpreter/TestCompletion.cpp).
On Mon, 18 Jun 2018 at 21:16, Raphael Isemann via lldb-commits
 wrote:
>
> Author: teemperor
> Date: Mon Jun 18 13:11:38 2018
> New Revision: 334978
>
> URL: http://llvm.org/viewvc/llvm-project?rev=334978=rev
> Log:
> Fixed file completion for paths that start with '~'.
>
> We didn't add the remaining path behind the '~' to the completion string,
> causing it to just complete directories inside the user home directory. This
> patch just adds the directory of the remaining path if there is one.
>
> Fixes rdar://problem/40147002
>
> Modified:
> lldb/trunk/source/Commands/CommandCompletions.cpp
>
> Modified: lldb/trunk/source/Commands/CommandCompletions.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandCompletions.cpp?rev=334978=334977=334978=diff
> ==
> --- lldb/trunk/source/Commands/CommandCompletions.cpp (original)
> +++ lldb/trunk/source/Commands/CommandCompletions.cpp Mon Jun 18 13:11:38 2018
> @@ -164,6 +164,12 @@ static int DiskFilesOrDirectories(const
>  // search in the fully resolved directory, but CompletionBuffer keeps the
>  // unmodified form that the user typed.
>  Storage = Resolved;
> +llvm::StringRef RemainderDir = path::parent_path(Remainder.str());
> +if (!RemainderDir.empty()) {
> +  // Append the remaining path to the resolved directory.
> +  Storage.append(path::get_separator());
> +  Storage.append(RemainderDir);
> +}
>  SearchDir = Storage;
>} else {
>  SearchDir = path::parent_path(CompletionBuffer);
>
>
> ___
> lldb-commits mailing list
> lldb-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D48295: [WIP] Implement new ReturnMIStatus method of CMICmdBase class.

2018-06-19 Thread Alexander Polyakov via Phabricator via lldb-commits
apolyakov updated this revision to Diff 151906.
apolyakov added a comment.

Attached another realization of `CMICmdBase::ReturnMIStatus`. It uses lambda 
functions to get user defined actions.

It works, but, as you may see, I had to define `auto error_handler = ...` in 
`Execute` function since in C++ we can't do something like `return 
ReturnMIStatus(success_handler,, error)`.

Base on this, I see a few options:

1. keep it in current state;
2. use llvm::Optional instead of default arguments. We still will be needed to 
pass all three parameters, but in this case user could do following: `return 
ReturnMIStatus(success_handler, llvm::Optional::None, error)`.
3. go back to simple implementation of `ReturnMIStatus`:

  bool CMICmdBase::ReturnMIStatus(const SBError ) {
if (error.Success())
  return MIstatus::success;
  
SetError(error.GetCString());
return MIstatus::failure;
  }

4. discard this idea and keep duplicating code;


https://reviews.llvm.org/D48295

Files:
  tools/lldb-mi/MICmdBase.cpp
  tools/lldb-mi/MICmdBase.h
  tools/lldb-mi/MICmdCmdExec.cpp


Index: tools/lldb-mi/MICmdCmdExec.cpp
===
--- tools/lldb-mi/MICmdCmdExec.cpp
+++ tools/lldb-mi/MICmdCmdExec.cpp
@@ -235,21 +235,22 @@
 bool CMICmdCmdExecContinue::Execute() {
   lldb::SBError error =
   CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue();
- 
-  if (error.Success()) {
-// CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
+
+  auto success_handler = [this] {
 if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
   const CMIUtilString 
(CMIDriver::Instance().GetErrorDescription());
-  SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
- m_cmdData.strMiCmd.c_str(),
- rErrMsg.c_str()));
+  this->SetError(CMIUtilString::Format(
+  MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
+  this->m_cmdData.strMiCmd.c_str(),
+  rErrMsg.c_str()));
   return MIstatus::failure;
 }
 return MIstatus::success;
-  }
+  };
 
-  SetError(error.GetCString());
-  return MIstatus::failure;
+  auto error_handler = [] { return MIstatus::failure; };
+
+  return ReturnMIStatus(success_handler, error_handler, error); 
 }
 
 //++
Index: tools/lldb-mi/MICmdBase.h
===
--- tools/lldb-mi/MICmdBase.h
+++ tools/lldb-mi/MICmdBase.h
@@ -12,6 +12,8 @@
 // C Includes
 // C++ Includes
 // Other libraries and framework includes
+#include "lldb/API/SBError.h"
+
 // Project includes
 #include "MICmdArgSet.h"
 #include "MICmdData.h"
@@ -80,6 +82,11 @@
   // Methods:
 protected:
   void SetError(const CMIUtilString );
+  bool ReturnMIStatus(const std::function _handler =
+  [] { return MIstatus::success; },
+  const std::function _handler =
+  [] { return MIstatus::failure; },
+  const lldb::SBError error = lldb::SBError());
   template  T *GetOption(const CMIUtilString );
   bool ParseValidateCmdOptions();
 
Index: tools/lldb-mi/MICmdBase.cpp
===
--- tools/lldb-mi/MICmdBase.cpp
+++ tools/lldb-mi/MICmdBase.cpp
@@ -214,6 +214,25 @@
 
 //++
 
//
+// Details: Short cut function to check MI command's execute status and
+//  set an error in case of failure.
+// Type:Method.
+// Args:error - (R) Error description object.
+// Return:  bool.
+// Throws:  None.
+//--
+bool CMICmdBase::ReturnMIStatus(const std::function _handler,
+const std::function _handler,
+const lldb::SBError error) {
+  if (error.Success())
+return success_handler();
+
+  SetError(error.GetCString());
+  return error_handler();
+}
+
+//++
+//
 // Details: Ask a command to provide its unique identifier.
 // Type:Method.
 // Args:A unique identifier for this command class.


Index: tools/lldb-mi/MICmdCmdExec.cpp
===
--- tools/lldb-mi/MICmdCmdExec.cpp
+++ tools/lldb-mi/MICmdCmdExec.cpp
@@ -235,21 +235,22 @@
 bool CMICmdCmdExecContinue::Execute() {
   lldb::SBError error =
   CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue();
- 
-  if (error.Success()) {
-// CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
+
+  auto success_handler = [this] {
 if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
   const CMIUtilString (CMIDriver::Instance().GetErrorDescription());
-  SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
- 

[Lldb-commits] [PATCH] D48302: Search for kext variants is searching from parent directory when it should not be

2018-06-19 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.

Thanks Jason, good catch!


Repository:
  rL LLVM

https://reviews.llvm.org/D48302



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