Re: [Lldb-commits] [PATCH] D14542: [lldb] Fix name lookup in ClangASTContext

2015-11-11 Thread Eugene Leviant via lldb-commits
evgeny777 updated this revision to Diff 39893.
evgeny777 added a comment.

Added test case


http://reviews.llvm.org/D14542

Files:
  packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py
  packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp
  source/Symbol/ClangASTContext.cpp

Index: source/Symbol/ClangASTContext.cpp
===
--- source/Symbol/ClangASTContext.cpp
+++ source/Symbol/ClangASTContext.cpp
@@ -9186,6 +9186,8 @@
 
 for (auto it = search_queue.find(decl_context); it != search_queue.end(); it++)
 {
+if (searched.find(it->second) != searched.end())
+continue;
 searched.insert(it->second);
 symbol_file->ParseDeclsForContext(CompilerDeclContext(this, it->second));
 
Index: packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp
===
--- packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp
+++ packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp
@@ -72,9 +72,31 @@
 }
 }
 
+namespace ns1 {
+int value = 100;
+}
+
+namespace ns2 {
+int value = 200;
+}
+
 #include 
+void test_namespace_scopes() {
+do {
+using namespace ns1;
+printf("ns1::value = %d\n", value); // Evaluate ns1::value
+} while(0);
+
+do {
+using namespace ns2;
+printf("ns2::value = %d\n", value); // Evaluate ns2::value
+} while(0);
+}
+
 int Foo::myfunc(int a)
 {
+test_namespace_scopes();
+
 ::my_uint_t anon_uint = 0;
 A::uint_t a_uint = 1;
 B::uint_t b_uint = 2;
Index: packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py
===
--- packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py
+++ packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py
@@ -26,23 +26,37 @@
 # And the line number to break at.
 self.line_break = line_number('main.cpp',
 '// Set break point at this line.')
+# Break inside do {} while and evaluate value
+self.line_break_ns1 = line_number('main.cpp', '// Evaluate ns1::value')
+self.line_break_ns2 = line_number('main.cpp', '// Evaluate ns2::value')
+
+def runToBkpt(self, command):
+self.runCmd(command, RUN_SUCCEEDED)
+# The stop reason of the thread should be breakpoint.
+self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+substrs = ['stopped',
+   'stop reason = breakpoint'])
 
 # rdar://problem/8668674
 @expectedFailureWindows("llvm.org/pr24764")
 def test_with_run_command(self):
 """Test that anonymous and named namespace variables display correctly."""
 self.build()
 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
 
+lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line_break_ns1, num_expected_locations=1, loc_exact=True)
+lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line_break_ns2, num_expected_locations=1, loc_exact=True)
 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line_break, num_expected_locations=1, loc_exact=True)
 
-self.runCmd("run", RUN_SUCCEEDED)
-
-# The stop reason of the thread should be breakpoint.
-self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
-substrs = ['stopped',
-   'stop reason = breakpoint'])
-
+self.runToBkpt("run")
+# Evaluate ns1::value
+self.expect("expression -- value", startstr = "(int) $0 = 100")
+
+self.runToBkpt("continue")
+# Evaluate ns2::value
+self.expect("expression -- value", startstr = "(int) $1 = 200")
+
+self.runToBkpt("continue")
 # On Mac OS X, gcc 4.2 emits the wrong debug info with respect to types.
 slist = ['(int) a = 12', 'anon_uint', 'a_uint', 'b_uint', 'y_uint']
 if self.platformIsDarwin() and self.getCompiler() in ['clang', 'llvm-gcc']:
@@ -83,8 +97,8 @@
 # test/namespace: 'expression -- i+j' not working
 # This has been fixed.
 self.expect("expression -- i + j",
-startstr = "(int) $0 = 7")
-# (int) $0 = 7
+startstr = "(int) $2 = 7")
+# (int) $2 = 7
 
 self.runCmd("expression -- i")
 self.runCmd("expression -- j")
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


Re: [Lldb-commits] [PATCH] D14536: Add empty symbols to symtab for skipped symbols

2015-11-11 Thread Greg Clayton via lldb-commits
clayborg requested changes to this revision.
clayborg added a comment.
This revision now requires changes to proceed.

Symbols are the #1 most expensive item memory wise in LLDB right now. We remove 
many symbols in Mach-O and we set the m_uid of each symbol to the original 
symbol table index. There is a binary search for a symbol by lldb::user_id_t 
that is efficient:

Symbol *
Symtab::FindSymbolByID (lldb::user_id_t symbol_uid) const
{

  Mutex::Locker locker (m_mutex);
  
  Symbol *symbol = (Symbol*)::bsearch (_uid, 
   _symbols[0], 
   m_symbols.size(), 
   sizeof(m_symbols[0]),
   CompareSymbolID);
  return symbol;

}

So just make sure to make your symbols have the correct lldb::user_id_t (the 
original symbol table index) and don't add empty useless symbols.


http://reviews.llvm.org/D14536



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


Re: [Lldb-commits] [PATCH] D14542: [lldb] Fix name lookup in ClangASTContext

2015-11-11 Thread Dawn Perchik via lldb-commits
dawn added a subscriber: dawn.
dawn accepted this revision.
dawn added a reviewer: dawn.
dawn added a comment.

Patch is correct - without it we loop through the same decl context again.  
I've tested it locally - there are no new regressions.


http://reviews.llvm.org/D14542



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


Re: [Lldb-commits] [PATCH] D14549: Use uniqueness of C++ fully-qualified names to resolve conflicts

2015-11-11 Thread Greg Clayton via lldb-commits
clayborg accepted this revision.
clayborg added a comment.
This revision is now accepted and ready to land.

Looks good!


http://reviews.llvm.org/D14549



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


[Lldb-commits] [lldb] r252765 - Add a `PythonModule` class, and a root-level method for resolving names.

2015-11-11 Thread Zachary Turner via lldb-commits
Author: zturner
Date: Wed Nov 11 11:59:49 2015
New Revision: 252765

URL: http://llvm.org/viewvc/llvm-project?rev=252765=rev
Log:
Add a `PythonModule` class, and a root-level method for resolving names.

Modified:
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
lldb/trunk/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp

Modified: 
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp?rev=252765=252764=252765=diff
==
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp 
(original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp 
Wed Nov 11 11:59:49 2015
@@ -67,6 +67,8 @@ PythonObject::GetObjectType() const
 if (!IsAllocated())
 return PyObjectType::None;
 
+if (PythonModule::Check(m_py_obj))
+return PyObjectType::Module;
 if (PythonList::Check(m_py_obj))
 return PyObjectType::List;
 if (PythonDictionary::Check(m_py_obj))
@@ -81,7 +83,7 @@ PythonObject::GetObjectType() const
 }
 
 PythonString
-PythonObject::Repr()
+PythonObject::Repr() const
 {
 if (!m_py_obj)
 return PythonString();
@@ -92,7 +94,7 @@ PythonObject::Repr()
 }
 
 PythonString
-PythonObject::Str()
+PythonObject::Str() const
 {
 if (!m_py_obj)
 return PythonString();
@@ -102,6 +104,43 @@ PythonObject::Str()
 return PythonString(PyRefType::Owned, str);
 }
 
+PythonObject
+PythonObject::ResolveNameGlobal(llvm::StringRef name)
+{
+return PythonModule::MainModule().ResolveName(name);
+}
+
+PythonObject
+PythonObject::ResolveName(llvm::StringRef name) const
+{
+// Resolve the name in the context of the specified object.  If,
+// for example, `this` refers to a PyModule, then this will look for
+// `name` in this module.  If `this` refers to a PyType, then it will
+// resolve `name` as an attribute of that type.  If `this` refers to
+// an instance of an object, then it will resolve `name` as the value
+// of the specified field.
+//
+// This function handles dotted names so that, for example, if `m_py_obj`
+// refers to the `sys` module, and `name` == "path.append", then it
+// will find the function `sys.path.append`.
+
+size_t dot_pos = name.find_first_of('.');
+if (dot_pos == llvm::StringRef::npos)
+{
+// No dots in the name, we should be able to find the value immediately
+// as an attribute of `use_object`.
+return GetAttributeValue(name);
+}
+
+// Look up the first piece of the name, and resolve the rest as a child of 
that.
+PythonObject parent = ResolveName(name.substr(0, dot_pos));
+if (!parent.IsAllocated())
+return PythonObject();
+
+// Tail recursion.. should be optimized by the compiler
+return parent.ResolveName(name.substr(dot_pos + 1));
+}
+
 bool
 PythonObject::HasAttribute(llvm::StringRef attr) const
 {
@@ -605,6 +644,62 @@ PythonDictionary::CreateStructuredDictio
 return result;
 }
 
+PythonModule::PythonModule() : PythonObject()
+{
+}
+
+PythonModule::PythonModule(PyRefType type, PyObject *py_obj)
+{
+Reset(type, py_obj); // Use "Reset()" to ensure that py_obj is a module
+}
+
+PythonModule::PythonModule(const PythonModule ) : PythonObject(dict)
+{
+}
+
+PythonModule::~PythonModule()
+{
+}
+
+PythonModule
+PythonModule::MainModule()
+{
+return PythonModule(PyRefType::Borrowed, PyImport_AddModule("__main__"));
+}
+
+bool
+PythonModule::Check(PyObject *py_obj)
+{
+if (!py_obj)
+return false;
+
+return PyModule_Check(py_obj);
+}
+
+void
+PythonModule::Reset(PyRefType type, PyObject *py_obj)
+{
+// Grab the desired reference type so that if we end up rejecting
+// `py_obj` it still gets decremented if necessary.
+PythonObject result(type, py_obj);
+
+if (!PythonModule::Check(py_obj))
+{
+PythonObject::Reset();
+return;
+}
+
+// Calling PythonObject::Reset(const PythonObject&) will lead to stack 
overflow since it calls
+// back into the virtual implementation.
+PythonObject::Reset(PyRefType::Borrowed, result.get());
+}
+
+PythonDictionary
+PythonModule::GetDictionary() const
+{
+return PythonDictionary(PyRefType::Borrowed, PyModule_GetDict(m_py_obj));
+}
+
 PythonFile::PythonFile()
 : PythonObject()
 {

Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h?rev=252765=252764=252765=diff
==
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h 
(original)
+++ 

[Lldb-commits] [lldb] r252764 - Symlink the `six` module during swig generation.

2015-11-11 Thread Zachary Turner via lldb-commits
Author: zturner
Date: Wed Nov 11 11:59:34 2015
New Revision: 252764

URL: http://llvm.org/viewvc/llvm-project?rev=252764=rev
Log:
Symlink the `six` module during swig generation.

Modified:
lldb/trunk/scripts/CMakeLists.txt
lldb/trunk/scripts/Python/finishSwigPythonLLDB.py

Modified: lldb/trunk/scripts/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/CMakeLists.txt?rev=252764=252763=252764=diff
==
--- lldb/trunk/scripts/CMakeLists.txt (original)
+++ lldb/trunk/scripts/CMakeLists.txt Wed Nov 11 11:59:34 2015
@@ -12,6 +12,7 @@ set(SWIG_HEADERS
 find_package(SWIG REQUIRED)
 add_custom_command(
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lldb.py
   DEPENDS ${SWIG_SOURCES}
   DEPENDS ${SWIG_INTERFACES}
   DEPENDS ${SWIG_HEADERS}

Modified: lldb/trunk/scripts/Python/finishSwigPythonLLDB.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/finishSwigPythonLLDB.py?rev=252764=252763=252764=diff
==
--- lldb/trunk/scripts/Python/finishSwigPythonLLDB.py (original)
+++ lldb/trunk/scripts/Python/finishSwigPythonLLDB.py Wed Nov 11 11:59:34 2015
@@ -267,6 +267,37 @@ def make_symlink_other_platforms(vstrSrc
 
 return (bOk, strErrMsg)
 
+def make_symlink_native(vDictArgs, strSrc, strTarget):
+eOSType = utilsOsType.determine_os_type()
+bDbg = "-d" in vDictArgs
+bOk = True
+strErrMsg = ""
+
+target_filename = os.path.basename(strTarget)
+if eOSType == utilsOsType.EnumOsType.Unknown:
+bOk = False
+strErrMsg = strErrMsgOsTypeUnknown
+elif eOSType == utilsOsType.EnumOsType.Windows:
+if os.path.isfile(strTarget):
+if bDbg:
+print((strMsgSymlinkExists % target_filename))
+return (bOk, strErrMsg)
+if bDbg:
+print((strMsgSymlinkMk % (target_filename, strSrc, strTarget)))
+bOk, strErrMsg = make_symlink_windows(strSrc,
+  strTarget)
+else:
+if os.path.islink(strTarget):
+if bDbg:
+print((strMsgSymlinkExists % target_filename))
+return (bOk, strErrMsg)
+if bDbg:
+print((strMsgSymlinkMk % (target_filename, strSrc, strTarget)))
+bOk, strErrMsg = make_symlink_other_platforms(strSrc,
+  strTarget)
+
+return (bOk, strErrMsg)
+
 #++---
 # Details:  Make the symbolic link.
 # Args: vDictArgs   - (R) Program input parameters.
@@ -303,29 +334,16 @@ def make_symlink(vDictArgs, vstrFramewor
 strBuildDir = os.path.join("..", "..", "..", "..")
 strSrc = os.path.normcase(os.path.join(strBuildDir, vstrSrcFile))
 
-if eOSType == utilsOsType.EnumOsType.Unknown:
-bOk = False
-strErrMsg = strErrMsgOsTypeUnknown
-elif eOSType == utilsOsType.EnumOsType.Windows:
-if os.path.isfile(strTarget):
-if bDbg:
-print((strMsgSymlinkExists % vstrTargetFile))
-return (bOk, strErrMsg)
-if bDbg:
-print((strMsgSymlinkMk % (vstrTargetFile, strSrc, strTarget)))
-bOk, strErrMsg = make_symlink_windows(strSrc,
-  strTarget)
-else:
-if os.path.islink(strTarget):
-if bDbg:
-print((strMsgSymlinkExists % vstrTargetFile))
-return (bOk, strErrMsg)
-if bDbg:
-print((strMsgSymlinkMk % (vstrTargetFile, strSrc, strTarget)))
-bOk, strErrMsg = make_symlink_other_platforms(strSrc,
-  strTarget)
+return make_symlink_native(vDictArgs, strSrc, strTarget)
 
-return (bOk, strErrMsg)
+def make_symlink_six(vDictArgs, vstrFrameworkPythonDir):
+dbg = utilsDebug.CDebugFnVerbose("Python script make_symlink_six()")
+site_packages_dir = os.path.dirname(vstrFrameworkPythonDir)
+six_module_filename = "six.py"
+src_file = os.path.join(vDictArgs['--srcRoot'], "third_party", "Python", 
"module", "six", six_module_filename)
+src_file = os.path.normpath(src_file)
+target = os.path.join(site_packages_dir, six_module_filename)
+return make_symlink_native(vDictArgs, src_file, target)
 
 #++---
 # Details:  Make the symbolic that the script bridge for Python will need in
@@ -454,6 +472,9 @@ def create_symlinks(vDictArgs, vstrFrame
   vstrFrameworkPythonDir,
   strLibLldbFileName)
 
+if bOk:
+bOk, strErrMsg = make_symlink_six(vDictArgs, vstrFrameworkPythonDir)
+
 # Make symlink 

[Lldb-commits] [lldb] r252767 - Python 3 - Use six in our embedded Python glue code.

2015-11-11 Thread Zachary Turner via lldb-commits
Author: zturner
Date: Wed Nov 11 11:59:57 2015
New Revision: 252767

URL: http://llvm.org/viewvc/llvm-project?rev=252767=rev
Log:
Python 3 - Use six in our embedded Python glue code.

Modified:
lldb/trunk/scripts/interface/SBData.i
lldb/trunk/scripts/lldb.swig

Modified: lldb/trunk/scripts/interface/SBData.i
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBData.i?rev=252767=252766=252767=diff
==
--- lldb/trunk/scripts/interface/SBData.i (original)
+++ lldb/trunk/scripts/interface/SBData.i Wed Nov 11 11:59:57 2015
@@ -146,7 +146,7 @@ public:
 for x in range(*key.indices(self.__len__())):
 list.append(self.__getitem__(x))
 return list
-if not (isinstance(key,(int,long))):
+if not (isinstance(key,six.integer_types)):
 raise TypeError('must be int')
 key = key * self.item_size # SBData uses byte-based indexes, 
but we want to use itemsize-based indexes here
 error = SBError()

Modified: lldb/trunk/scripts/lldb.swig
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/lldb.swig?rev=252767=252766=252767=diff
==
--- lldb/trunk/scripts/lldb.swig (original)
+++ lldb/trunk/scripts/lldb.swig Wed Nov 11 11:59:57 2015
@@ -41,6 +41,8 @@ o SBLineEntry: Specifies an association
 import uuid
 import re
 import os
+
+import six
 %}
 %include "./Python/python-typemaps.swig"
 


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


[Lldb-commits] [PATCH] Avoid Python "UnboundedLocalError: local variable 'strErrMsgProgFail' referenced before assignment"

2015-11-11 Thread Stephan Bergmann via lldb-commits
An attempt at building lldb from recent trunk source failed for me with 
a Python error



UnboundedLocalError: local variable 'strErrMsgProgFail' referenced before 
assignment


in tools/lldb/scripts/Python/buildSwigPython.py.  I have not much of an 
idea about Python, but from 
 
it looks like there is "global strErrMsgProgFail" missing, and the 
attached lldb-buildSwigPython.patch indeed fixed the problem for me.


(I have no commit rights, so would ask for this to get pushed by 
somebody if acceptable.)
Index: scripts/Python/buildSwigPython.py
===
--- scripts/Python/buildSwigPython.py	(revision 252713)
+++ scripts/Python/buildSwigPython.py	(working copy)
@@ -640,6 +640,7 @@
 strMsg = ""
 
 if not "--swigExecutable" in vDictArgs:
+global strErrMsgProgFail
 strErrMsgProgFail += strErrMsgSwigParamsMissing
 return (-100, strErrMsgProgFail)
 
@@ -769,6 +770,7 @@
 if bOk:
 return (0, strMsg)
 else:
+global strErrMsgProgFail
 strErrMsgProgFail += strMsg
 return (-100, strErrMsgProgFail)
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


Re: [Lldb-commits] [PATCH] D14542: [lldb] Fix name lookup in ClangASTContext

2015-11-11 Thread Tamas Berghammer via lldb-commits
tberghammer accepted this revision.
tberghammer added a comment.
This revision is now accepted and ready to land.

Te test case looks good to me. Thanks for adding it.

For the actual code change I don' know enough about this area to say anything 
so please wait for a feedback from Greg.


http://reviews.llvm.org/D14542



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


Re: [Lldb-commits] [PATCH] D14226: Fix to solve Bug 23139 & Bug 23560

2015-11-11 Thread Jason Molenda via lldb-commits
jasonmolenda accepted this revision.
jasonmolenda added a comment.
This revision is now accepted and ready to land.

Hi Abhishek, I apologize for the long delay in reviewing this one, I needed to 
find a solid 30-45 minute block to review the changes and the current state of 
the unwinder code before I really understood what is going on here.

I think this change looks good, please commit it when you have a chance.



Comment at: source/Plugins/Process/Utility/UnwindLLDB.cpp:320
@@ +319,3 @@
+
+// This function is called for First Frame only.
+if (m_frames.size() != 1)

I would do this with an assert instead of a conditional check.  This method is 
only called from UnwindLLDB::AddFirstFrame().  AddFirstFrame starts by ensuring 
that m_frames is empty.  It constructs a Cursor object for the first stack 
frame, pushes it to m_frames.  And then it calls 
UpdateUnwindPlanForFirstFrameIfInvalid().

A conditional makes it look like this is a possible valid arrangement. Instead, 
what we're checking here is a basic assumption of the state of the object when 
this method should be called.  I think it's an appropriate space to use an 
assert.  If the code were to ever change around this method (or this method was 
called from another part of the code), we'd need it to crash immediately 
because the code would no longer be correct.


http://reviews.llvm.org/D14226



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


[Lldb-commits] [lldb] r252831 - [test] Fix comment.

2015-11-11 Thread Dawn Perchik via lldb-commits
Author: dperchik
Date: Wed Nov 11 18:43:22 2015
New Revision: 252831

URL: http://llvm.org/viewvc/llvm-project?rev=252831=rev
Log:
[test] Fix comment.

Modified:

lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py?rev=252831=252830=252831=diff
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
 Wed Nov 11 18:43:22 2015
@@ -56,7 +56,7 @@ class ExprOptionsTestCase(TestBase):
 
 # test --language on C++ expression using the SB API's
 
-# Make sure we can evaluate 'ns::func'.
+# Make sure we can evaluate a C++11 expression.
 val = frame.EvaluateExpression('foo != nullptr')
 self.assertTrue(val.IsValid())
 self.assertTrue(val.GetError().Success())


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


[Lldb-commits] [lldb] r252787 - Create `PythonTuple` and `PythonCallable` wrapper classes.

2015-11-11 Thread Zachary Turner via lldb-commits
Author: zturner
Date: Wed Nov 11 13:42:27 2015
New Revision: 252787

URL: http://llvm.org/viewvc/llvm-project?rev=252787=rev
Log:
Create `PythonTuple` and `PythonCallable` wrapper classes.

This adds PythonTuple and PythonCallable classes to PythonDataObjects.
Additionally, unit tests are provided that exercise this functionality,
including invoking manipulating and checking for validity of tuples,
and invoking and checking for validity of callables using a variety
of different syntaxes.

The goal here is to eventually replace the code in python-wrapper.swig
that directly uses the Python C API to deal with callables and name
resolution with this code that can be more easily tested and debugged.

Modified:
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
lldb/trunk/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp

Modified: 
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp?rev=252787=252786=252787=diff
==
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp 
(original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp 
Wed Nov 11 13:42:27 2015
@@ -71,6 +71,8 @@ PythonObject::GetObjectType() const
 return PyObjectType::Module;
 if (PythonList::Check(m_py_obj))
 return PyObjectType::List;
+if (PythonTuple::Check(m_py_obj))
+return PyObjectType::Tuple;
 if (PythonDictionary::Check(m_py_obj))
 return PyObjectType::Dictionary;
 if (PythonString::Check(m_py_obj))
@@ -79,6 +81,8 @@ PythonObject::GetObjectType() const
 return PyObjectType::Integer;
 if (PythonFile::Check(m_py_obj))
 return PyObjectType::File;
+if (PythonCallable::Check(m_py_obj))
+return PyObjectType::Callable;
 return PyObjectType::Unknown;
 }
 
@@ -105,9 +109,20 @@ PythonObject::Str() const
 }
 
 PythonObject
-PythonObject::ResolveNameGlobal(llvm::StringRef name)
+PythonObject::ResolveNameWithDictionary(llvm::StringRef name, PythonDictionary 
dict)
 {
-return PythonModule::MainModule().ResolveName(name);
+size_t dot_pos = name.find_first_of('.');
+llvm::StringRef piece = name.substr(0, dot_pos);
+PythonObject result = dict.GetItemForKey(PythonString(piece));
+if (dot_pos == llvm::StringRef::npos)
+{
+// There was no dot, we're done.
+return result;
+}
+
+// There was a dot.  The remaining portion of the name should be looked up 
in
+// the context of the object that was found in the dictionary.
+return result.ResolveName(name.substr(dot_pos + 1));
 }
 
 PythonObject
@@ -128,7 +143,7 @@ PythonObject::ResolveName(llvm::StringRe
 if (dot_pos == llvm::StringRef::npos)
 {
 // No dots in the name, we should be able to find the value immediately
-// as an attribute of `use_object`.
+// as an attribute of `m_py_obj`.
 return GetAttributeValue(name);
 }
 
@@ -545,6 +560,132 @@ PythonList::CreateStructuredArray() cons
 }
 
 //--
+// PythonTuple
+//--
+
+PythonTuple::PythonTuple(PyInitialValue value)
+: PythonObject()
+{
+if (value == PyInitialValue::Empty)
+Reset(PyRefType::Owned, PyTuple_New(0));
+}
+
+PythonTuple::PythonTuple(int tuple_size)
+: PythonObject()
+{
+Reset(PyRefType::Owned, PyTuple_New(tuple_size));
+}
+
+PythonTuple::PythonTuple(PyRefType type, PyObject *py_obj)
+: PythonObject()
+{
+Reset(type, py_obj); // Use "Reset()" to ensure that py_obj is a tuple
+}
+
+PythonTuple::PythonTuple(const PythonTuple )
+: PythonObject(tuple)
+{
+}
+
+PythonTuple::PythonTuple(std::initializer_list objects)
+{
+m_py_obj = PyTuple_New(objects.size());
+
+uint32_t idx = 0;
+for (auto object : objects)
+{
+if (object.IsValid())
+SetItemAtIndex(idx, object);
+idx++;
+}
+}
+
+PythonTuple::PythonTuple(std::initializer_list objects)
+{
+m_py_obj = PyTuple_New(objects.size());
+
+uint32_t idx = 0;
+for (auto py_object : objects)
+{
+PythonObject object(PyRefType::Borrowed, py_object);
+if (object.IsValid())
+SetItemAtIndex(idx, object);
+idx++;
+}
+}
+
+PythonTuple::~PythonTuple()
+{
+}
+
+bool
+PythonTuple::Check(PyObject *py_obj)
+{
+if (!py_obj)
+return false;
+return PyTuple_Check(py_obj);
+}
+
+void
+PythonTuple::Reset(PyRefType type, PyObject *py_obj)
+{
+// Grab the desired reference type so that if we end up rejecting
+// `py_obj` it still gets decremented if necessary.
+PythonObject 

[Lldb-commits] [lldb] r252788 - Convert python-wrapper.swig to use PythonDataObjects.

2015-11-11 Thread Zachary Turner via lldb-commits
Author: zturner
Date: Wed Nov 11 13:42:35 2015
New Revision: 252788

URL: http://llvm.org/viewvc/llvm-project?rev=252788=rev
Log:
Convert python-wrapper.swig to use PythonDataObjects.

This only begins to port python-wrapper.swig over.  Since this
code can be pretty hairy, I plan to do this incrementally over a
series of patches, each time removing or converting more code
over to the PythonDataObjects code.

Modified:
lldb/trunk/scripts/Python/python-wrapper.swig

Modified: lldb/trunk/scripts/Python/python-wrapper.swig
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=252788=252787=252788=diff
==
--- lldb/trunk/scripts/Python/python-wrapper.swig (original)
+++ lldb/trunk/scripts/Python/python-wrapper.swig Wed Nov 11 13:42:35 2015
@@ -26,77 +26,11 @@ private:
 bool m_print;
 };
 
-// TODO(zturner): This should be part of a `PythonModule` class in
-// PythonDataObjects.hm and it should return a `PythonObject`
 static PyObject*
-ResolvePythonName(const char* name,
-  PyObject* pmodule)
+FindSessionDictionary(const char *dict_name)
 {
 using namespace lldb_private;
-if (!name)
-return pmodule;
-
-PyErr_Cleaner pyerr_cleanup(true);  // show Python errors
-
-PythonDictionary main_dict(PyInitialValue::Invalid);
-
-if (!pmodule)
-{
-pmodule = PyImport_AddModule ("__main__");
-if (!pmodule)
-return nullptr;
-}
-
-if (PyType_Check(pmodule))
-main_dict.Reset(PyRefType::Borrowed, 
((PyTypeObject*)pmodule)->tp_dict);
-else if (PythonDictionary::Check(pmodule))
-main_dict.Reset(PyRefType::Borrowed, pmodule);
-else
-main_dict.Reset(PyRefType::Borrowed, PyModule_GetDict (pmodule));
-if (!main_dict.IsValid())
-return nullptr;
-
-const char* dot_pos = ::strchr(name, '.');
-
-PythonObject dest_object;
-Py_ssize_t pos = 0;
-
-if (!dot_pos)
-{
-PyObject *py_key;
-PyObject *py_value;
-// TODO(zturner): This should be conveniently wrapped by 
`PythonDictionary`.
-while (PyDict_Next(main_dict.get(), , _key, _value))
-{
-PythonObject key(PyRefType::Borrowed, py_key);
-auto key_string = key.AsType();
-if (!key_string.IsAllocated())
-continue;
-
-std::string str(key_string.GetString().str());
-if (strcmp(str.c_str(), name) == 0)
-{
-dest_object.Reset(PyRefType::Borrowed, py_value);
-break;
-}
-}
-return dest_object.release();
-}
-else
-{
-size_t len = dot_pos - name;
-std::string piece(name,len);
-PyObject *resolved_object = ResolvePythonName(piece.c_str(), 
main_dict.get());
-if (!resolved_object || resolved_object == Py_None)
-return nullptr;
-return ResolvePythonName(dot_pos+1,resolved_object); // tail 
recursion.. should be optimized by the compiler
-}
-}
-
-static PyObject*
-FindSessionDictionary(const char *session_dictionary_name)
-{
-return ResolvePythonName(session_dictionary_name, NULL);
+return PythonModule::MainModule().ResolveName(dict_name).release();
 }
 
 // TODO(zturner): This entire class should be moved to PythonDataObjects.h
@@ -191,18 +125,25 @@ public:
 return PyCallable();
 if ( (python_function_name[0] == 0) || (session_dictionary_name[0] == 
0) )
 return PyCallable();
-return FindWithFunctionName(python_function_name,FindSessionDictionary 
(session_dictionary_name));
+
+using namespace lldb_private;
+auto dict = 
PythonModule::MainModule().ResolveName(session_dictionary_name).AsType();
+return FindWithFunctionName(python_function_name, dict.get());
 }
 
 static PyCallable
 FindWithFunctionName (const char *python_function_name,
-  PyObject *session_dict)
+  PyObject *py_session_dict)
 {
-if (!python_function_name || !session_dict)
+if (!python_function_name || !py_session_dict)
 return PyCallable();
 if ( (python_function_name[0] == 0))
 return PyCallable();
-return PyCallable(ResolvePythonName (python_function_name, 
session_dict));
+
+using namespace lldb_private;
+PythonDictionary session_dict(PyRefType::Borrowed, py_session_dict);
+PythonCallable result = 
PythonObject::ResolveNameWithDictionary(python_function_name, 
session_dict).AsType();
+return PyCallable(result.release());
 }
 
 static PyCallable
@@ -213,6 +154,7 @@ public:
 return PyCallable();
 if (!python_function_name || (python_function_name[0] == 0))
 return PyCallable();
+
 return PyCallable(PyObject_GetAttrString(self, python_function_name));
 }
 

[Lldb-commits] [lldb] r252803 - Remove `FindSessionDictionary` and rely on PythonDataObjects.

2015-11-11 Thread Zachary Turner via lldb-commits
Author: zturner
Date: Wed Nov 11 15:07:29 2015
New Revision: 252803

URL: http://llvm.org/viewvc/llvm-project?rev=252803=rev
Log:
Remove `FindSessionDictionary` and rely on PythonDataObjects.

This had been relegated to a simple forwarding function, so just
delete it in preparation of migrating all of these functions out
of python-wrapper.swig.

Modified:
lldb/trunk/scripts/Python/python-wrapper.swig

Modified: lldb/trunk/scripts/Python/python-wrapper.swig
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=252803=252802=252803=diff
==
--- lldb/trunk/scripts/Python/python-wrapper.swig (original)
+++ lldb/trunk/scripts/Python/python-wrapper.swig Wed Nov 11 15:07:29 2015
@@ -26,13 +26,6 @@ private:
 bool m_print;
 };
 
-static PyObject*
-FindSessionDictionary(const char *dict_name)
-{
-using namespace lldb_private;
-return PythonModule::MainModule().ResolveName(dict_name).release();
-}
-
 // TODO(zturner): This entire class should be moved to PythonDataObjects.h
 // and properly abstracted and unit-tested.
 class PyCallable
@@ -191,30 +184,27 @@ LLDBSwigPythonBreakpointCallbackFunction
 const lldb::BreakpointLocationSP& bp_loc_sp
 )
 {
+using namespace lldb_private;
 lldb::SBFrame sb_frame (frame_sp);
 lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
 
 bool stop_at_breakpoint = true;
 
-{
-PyErr_Cleaner py_err_cleaner(true);
-
-PyCallable pfunc = 
PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+PyErr_Cleaner py_err_cleaner(true);
+PythonDictionary dict = 
PythonModule::MainModule().ResolveName(session_dictionary_name).AsType();
 
-if (!pfunc)
-return stop_at_breakpoint;
+PyCallable pfunc = 
PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-PyObject* session_dict = NULL;
-PyObject* pvalue = NULL;
-pvalue = pfunc(sb_frame, sb_bp_loc, session_dict = 
FindSessionDictionary(session_dictionary_name));
+if (!pfunc)
+return stop_at_breakpoint;
 
-Py_XINCREF (session_dict);
+PyObject* pvalue = NULL;
+pvalue = pfunc(sb_frame, sb_bp_loc, dict.get());
 
-if (pvalue == Py_False)
-stop_at_breakpoint = false;
+if (pvalue == Py_False)
+stop_at_breakpoint = false;
 
-Py_XDECREF (pvalue);
-}
+Py_XDECREF (pvalue);
 
 return stop_at_breakpoint;
 }
@@ -231,30 +221,28 @@ LLDBSwigPythonWatchpointCallbackFunction
 const lldb::WatchpointSP& wp_sp
 )
 {
+using namespace lldb_private;
 lldb::SBFrame sb_frame (frame_sp);
 lldb::SBWatchpoint sb_wp(wp_sp);
 
 bool stop_at_watchpoint = true;
 
-{
-PyErr_Cleaner py_err_cleaner(true);
+PyErr_Cleaner py_err_cleaner(true);
 
-PyCallable pfunc = 
PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+PythonDictionary dict = 
PythonModule::MainModule().ResolveName(session_dictionary_name).AsType();
 
-if (!pfunc)
-return stop_at_watchpoint;
+PyCallable pfunc = 
PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-PyObject* session_dict = NULL;
-PyObject* pvalue = NULL;
-pvalue = pfunc(sb_frame, sb_wp, session_dict = 
FindSessionDictionary(session_dictionary_name));
+if (!pfunc)
+return stop_at_watchpoint;
 
-Py_XINCREF (session_dict);
+PyObject* pvalue = NULL;
+pvalue = pfunc(sb_frame, sb_wp, dict.get());
 
-if (pvalue == Py_False)
-stop_at_watchpoint = false;
+if (pvalue == Py_False)
+stop_at_watchpoint = false;
 
-Py_XDECREF (pvalue);
-}
+Py_XDECREF (pvalue);
 
 return stop_at_watchpoint;
 }
@@ -364,6 +352,7 @@ LLDBSwigPythonCreateSyntheticProvider
 const lldb::ValueObjectSP& valobj_sp
 )
 {
+using namespace lldb_private;
 PyObject* retval = NULL;
 
 if (python_class_name == NULL || python_class_name[0] == '\0' || 
!session_dictionary_name)
@@ -378,24 +367,19 @@ LLDBSwigPythonCreateSyntheticProvider
 if (ValObj_PyObj == NULL)
 Py_RETURN_NONE;
 
-{
-PyErr_Cleaner py_err_cleaner(true);
+PyErr_Cleaner py_err_cleaner(true);
 
-PyCallable pfunc = 
PyCallable::FindWithFunctionName(python_class_name,session_dictionary_name);
+PythonDictionary dict = 
PythonModule::MainModule().ResolveName(session_dictionary_name).AsType();
+PyCallable pfunc = 
PyCallable::FindWithFunctionName(python_class_name,dict.get());
 
-if (!pfunc)
-return retval;
+if (!pfunc)
+return retval;
 
-Py_INCREF(ValObj_PyObj);
+Py_INCREF(ValObj_PyObj);
 
-PyObject* session_dict = NULL;
-session_dict = FindSessionDictionary(session_dictionary_name);
-retval = pfunc(sb_value, session_dict);
+retval = pfunc(sb_value, dict.get());
 
-

[Lldb-commits] [PATCH] D14591: Implement register context for mini dump debugging

2015-11-11 Thread Adrian McCarthy via lldb-commits
amccarth created this revision.
amccarth added a reviewer: zturner.
amccarth added a subscriber: lldb-commits.

The old RegisterContextWinMiniDump stub is replaced with x86 and x64 
implementations that derive from the common windows register contexts.

ProcessWindowsMiniDump grabs the WinAPI CONTEXT for each thread and stashes it 
in the thread object when building the thread list.  The threads create the 
register context, stuffing in the saved CONTEXT.

New test ensures we can see the stack and registers for the (single) frame in 
the fizzbuzz minidump.  (No variables or function names, since that inferior 
doesn't have DWARF information.)

You might also notice that I remove the thread names for MiniDump threads.  
Thread names are unavailable when port-mortem debugging Windows apps (since 
naming the thread requires having the debugger catch a special exception raised 
while the inferior is running).

http://reviews.llvm.org/D14591

Files:
  
packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py
  source/Plugins/Process/Windows/Common/RegisterContextWindows.h
  source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp
  source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.h
  source/Plugins/Process/Windows/Live/x86/RegisterContextWindowsLive_x86.cpp
  source/Plugins/Process/Windows/Live/x86/RegisterContextWindowsLive_x86.h
  source/Plugins/Process/Windows/MiniDump/CMakeLists.txt
  source/Plugins/Process/Windows/MiniDump/ProcessWinMiniDump.cpp
  source/Plugins/Process/Windows/MiniDump/RegisterContextWindowsMiniDump.cpp
  source/Plugins/Process/Windows/MiniDump/RegisterContextWindowsMiniDump.h
  source/Plugins/Process/Windows/MiniDump/ThreadWinMiniDump.cpp
  source/Plugins/Process/Windows/MiniDump/ThreadWinMiniDump.h
  
source/Plugins/Process/Windows/MiniDump/x64/RegisterContextWindowsMiniDump_x64.cpp
  
source/Plugins/Process/Windows/MiniDump/x64/RegisterContextWindowsMiniDump_x64.h
  
source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.cpp
  
source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.h

Index: source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.h
===
--- /dev/null
+++ source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.h
@@ -0,0 +1,36 @@
+//===-- RegisterContextWindowsMiniDump_x86.h *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef liblldb_RegisterContextWindowsMiniDump_x86_H_
+#define liblldb_RegisterContextWindowsMiniDump_x86_H_
+
+#include "lldb/lldb-forward.h"
+#include "../../Common/x86/RegisterContextWindows_x86.h"
+
+namespace lldb_private
+{
+
+class Thread;
+
+class RegisterContextWindowsMiniDump_x86 : public RegisterContextWindows_x86
+{
+  public:
+RegisterContextWindowsMiniDump_x86(Thread , uint32_t concrete_frame_idx, const CONTEXT *context);
+
+virtual ~RegisterContextWindowsMiniDump_x86();
+
+bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue _value) override;
+
+  protected:
+bool CacheAllRegisterValues() override;
+};
+
+}
+
+#endif // #ifndef liblldb_RegisterContextWindowsMiniDump_x86_H_
Index: source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.cpp
===
--- /dev/null
+++ source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.cpp
@@ -0,0 +1,47 @@
+//===-- RegisterContextWindowsMiniDump_x86.cpp --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "lldb/lldb-private-types.h"
+#include "lldb/Host/windows/windows.h"
+
+#include "RegisterContextWindowsMiniDump_x86.h"
+
+using namespace lldb;
+
+namespace lldb_private
+{
+
+RegisterContextWindowsMiniDump_x86::RegisterContextWindowsMiniDump_x86(Thread , uint32_t concrete_frame_idx, const CONTEXT *context)
+: RegisterContextWindows_x86(thread, concrete_frame_idx)
+{
+if (context)
+{
+m_context = *context;
+m_context_stale = false;
+}
+}
+
+RegisterContextWindowsMiniDump_x86::~RegisterContextWindowsMiniDump_x86()
+{
+}
+
+bool
+RegisterContextWindowsMiniDump_x86::WriteRegister(const RegisterInfo * /* reg_info */, const RegisterValue & /* reg_value */)
+{
+return false;
+}
+
+bool
+RegisterContextWindowsMiniDump_x86::CacheAllRegisterValues()
+{
+// Since this is post-mortem debugging, we either have the 

[Lldb-commits] LLVM buildmaster will be restarted tonight

2015-11-11 Thread Galina Kistanova via lldb-commits
Hello everyone,

LLVM buildmaster will be updated restarted after 7 PM Pacific time today.

Thanks

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