Re: [Lldb-commits] [PATCH] D21221: Fix for PrintStackTraces

2016-07-06 Thread Ravitheja Addepally via lldb-commits
ravitheja updated this revision to Diff 62831.
ravitheja added a comment.

Removing other files.


http://reviews.llvm.org/D21221

Files:
  packages/Python/lldbsuite/test/functionalities/unwind/ehframe/
  packages/Python/lldbsuite/test/functionalities/unwind/ehframe/Makefile
  
packages/Python/lldbsuite/test/functionalities/unwind/ehframe/TestEhFrameUnwind.py
  packages/Python/lldbsuite/test/functionalities/unwind/ehframe/main.c

Index: packages/Python/lldbsuite/test/functionalities/unwind/ehframe/main.c
===
--- /dev/null
+++ packages/Python/lldbsuite/test/functionalities/unwind/ehframe/main.c
@@ -0,0 +1,20 @@
+void func() {
+   __asm__ (
+   "pushq $0x10;"
+   ".cfi_def_cfa_offset 16;"
+   "jmp label;"
+   "movq $0x48, %rax;"
+"label: subq $0x38, %rax;"
+   "movq $0x48, %rcx;"
+   "movq $0x48, %rdx;"
+   "movq $0x48, %rax;"
+   "popq %rax;"
+   );
+
+}
+
+
+int main(int argc, char const *argv[])
+{
+   func();
+}
\ No newline at end of file
Index: 
packages/Python/lldbsuite/test/functionalities/unwind/ehframe/TestEhFrameUnwind.py
===
--- /dev/null
+++ 
packages/Python/lldbsuite/test/functionalities/unwind/ehframe/TestEhFrameUnwind.py
@@ -0,0 +1,51 @@
+"""
+Test that we can backtrace correctly from Non ABI functions on the stack
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class EHFrameBasedUnwind(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+
+   
+@skipUnlessPlatform(['linux'])
+@skipIf(archs=["aarch64", "arm", "i386", "i686"])
+def test (self):
+"""Test that we can backtrace correctly from Non ABI  functions on the 
stack"""
+self.build()
+self.setTearDownCleanup()
+
+exe = os.path.join(os.getcwd(), "a.out")
+target = self.dbg.CreateTarget(exe)
+
+self.assertTrue(target, VALID_TARGET)
+
+lldbutil.run_break_set_by_symbol (self, "func")
+
+process = target.LaunchSimple (["abc", "xyz"], None, 
self.get_process_working_directory())
+
+if not process:
+self.fail("SBTarget.Launch() failed")
+
+if process.GetState() != lldb.eStateStopped:
+self.fail("Process should be in the 'stopped' state, "
+  "instead the actual state is: '%s'" %
+  lldbutil.state_type_to_str(process.GetState()))
+
+stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
+self.expect(stacktraces, exe=False,
+substrs = ['(int)argc=3'])
+
+self.runCmd("thread step-inst")
+
+stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
+self.expect(stacktraces, exe=False,
+substrs = ['(int)argc=3'])
Index: packages/Python/lldbsuite/test/functionalities/unwind/ehframe/Makefile
===
--- /dev/null
+++ packages/Python/lldbsuite/test/functionalities/unwind/ehframe/Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c
+
+CFLAGS ?= -g -fomit-frame-pointer
+
+include $(LEVEL)/Makefile.rules


Index: packages/Python/lldbsuite/test/functionalities/unwind/ehframe/main.c
===
--- /dev/null
+++ packages/Python/lldbsuite/test/functionalities/unwind/ehframe/main.c
@@ -0,0 +1,20 @@
+void func() {
+	__asm__ (
+		"pushq $0x10;"
+		".cfi_def_cfa_offset 16;"
+		"jmp label;"
+		"movq $0x48, %rax;"
+"label: subq $0x38, %rax;"
+		"movq $0x48, %rcx;"
+		"movq $0x48, %rdx;"
+		"movq $0x48, %rax;"
+		"popq %rax;"
+	);
+
+}
+
+
+int main(int argc, char const *argv[])
+{
+	func();
+}
\ No newline at end of file
Index: packages/Python/lldbsuite/test/functionalities/unwind/ehframe/TestEhFrameUnwind.py
===
--- /dev/null
+++ packages/Python/lldbsuite/test/functionalities/unwind/ehframe/TestEhFrameUnwind.py
@@ -0,0 +1,51 @@
+"""
+Test that we can backtrace correctly from Non ABI functions on the stack
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class EHFrameBasedUnwind(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+
+	
+@skipUnlessPlatform(['linux'])
+@skipIf(archs=["aarch64", "arm", "i386", "i686"])
+def test (self):
+"""Test that we can backtrace correctly from Non ABI  functions on the stack"""
+self.build()
+self.setTearDownCleanup()
+
+exe = os.path.join(os.getcwd(), "a.out")
+target = self.dbg.CreateTarget(exe)

Re: [Lldb-commits] [PATCH] D21984: Add data formatter for libstdc++ shared_ptr and weak_ptr

2016-07-06 Thread Tamas Berghammer via lldb-commits
tberghammer added inline comments.


Comment at: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:665
@@ +664,3 @@
+
+stl_summary_flags.SetDontShowChildren(true);
+AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibStdcppSmartPointerSummaryProvider,

granata.enrico wrote:
> tberghammer wrote:
> > granata.enrico wrote:
> > > Is there any reason to hide the children for a type that you provide 
> > > synthetic children for?
> > Without hiding the children the content of the shard_ptr will be displayed 
> > 2 times. Once in the first line as part of the summary and then 2nd time as 
> > a children. I think it is cleaner if we display the value only once but it 
> > can make it more difficult to access to the content of the shared pointer.
> > 
> > If you think displaying the children is better then I am happy with that 
> > option too.
> > 
> > The 2 possible output for a type Foo:
> > 
> > ```
> > (std::shared_ptr) f = Foo @ 0x00606118 {
> >   _M_ptr = 0x00606118
> > }
> > ```
> > ```
> > (std::shared_ptr) f = Foo @ 0x00606118
> > ```
> > 
> > The 2 possible output for an std::string:
> > ```
> > (std::shared_ptr, 
> > std::allocator > >) s = "123456" {
> >   _M_ptr = "123456"
> > }
> > ```
> > ```
> > (std::shared_ptr, 
> > std::allocator > >) s = "123456"
> > ```
> Oh, I see. Yeah, I had to solve a similar problem for Swift Optionals.
> 
> Essentially, you're discovering that for shared_ptr, T can have 
> combinations of values, summaries, synthetic values, ...
> 
> Unfortunately right now there is no automated formatter for the concept of a 
> box that handles all those intricacies automatically for you. It would be 
> a nice thing to add, but it's probably beyond the scope of your change
> 
> Feel free to pick your favorite solution for now, and I'll try to get to a 
> universal box formatter at some point.
I decided to remove it to be in sync with the libc++ shared_ptr/weak_ptr 
summary provider but having a formatter for box would be nice but I am not 
sure what should be the exact semantic of it. If you won't beat me with it I 
might take a look in the future but don't know when I will have time for it.


http://reviews.llvm.org/D21984



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


[Lldb-commits] [lldb] r274617 - Add data formatter for libstdc++ shared_ptr and weak_ptr

2016-07-06 Thread Tamas Berghammer via lldb-commits
Author: tberghammer
Date: Wed Jul  6 04:50:00 2016
New Revision: 274617

URL: http://llvm.org/viewvc/llvm-project?rev=274617&view=rev
Log:
Add data formatter for libstdc++ shared_ptr and weak_ptr

Differential revision: http://reviews.llvm.org/D21984

Added:

lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/

lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile

lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py

lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/main.cpp
Modified:
lldb/trunk/include/lldb/DataFormatters/VectorIterator.h
lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcpp.h

Modified: lldb/trunk/include/lldb/DataFormatters/VectorIterator.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/VectorIterator.h?rev=274617&r1=274616&r2=274617&view=diff
==
--- lldb/trunk/include/lldb/DataFormatters/VectorIterator.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/VectorIterator.h Wed Jul  6 04:50:00 
2016
@@ -38,9 +38,7 @@ namespace lldb_private {
 
 size_t
 GetIndexOfChildWithName(const ConstString &name) override;
-
-~VectorIteratorSyntheticFrontEnd() override;
-
+
 private:
 ExecutionContextRef m_exe_ctx_ref;
 ConstString m_item_name;

Added: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile?rev=274617&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile
 (added)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile
 Wed Jul  6 04:50:00 2016
@@ -0,0 +1,15 @@
+LEVEL = ../../../../../make
+
+CXX_SOURCES := main.cpp
+
+CXXFLAGS := -O0
+USE_LIBSTDCPP := 1
+
+# clang-3.5+ outputs FullDebugInfo by default for Darwin/FreeBSD
+# targets.  Other targets do not, which causes this test to fail.
+# This flag enables FullDebugInfo for all targets.
+ifneq (,$(findstring clang,$(CC)))
+  CFLAGS_EXTRAS += -fno-limit-debug-info
+endif
+
+include $(LEVEL)/Makefile.rules

Added: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py?rev=274617&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py
 (added)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py
 Wed Jul  6 04:50:00 2016
@@ -0,0 +1,45 @@
+"""
+Test lldb data formatter subsystem.
+"""
+
+from __future__ import print_function
+
+import os, time
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class StdSmartPtrDataFormatterTestCase(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+
+@skipIfFreeBSD
+@skipIfWindows # libstdcpp not ported to Windows
+def test_with_run_command(self):
+self.build()
+self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_source_regexp (self, "Set break point at 
this line.")
+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.expect("frame variable nsp", substrs = ['nsp = nullptr'])
+self.expect("frame variable isp", substrs = ['isp = 123'])
+self.expect("frame variable ssp", substrs = ['ssp = "foobar"'])
+
+self.expect("frame variable nwp", substrs = ['nwp = nullptr'])
+self.expect("frame variable iwp", substrs = ['iwp = 123'])
+self.expect("frame variable swp", substrs = ['swp = "foobar"'

Re: [Lldb-commits] [PATCH] D21984: Add data formatter for libstdc++ shared_ptr and weak_ptr

2016-07-06 Thread Tamas Berghammer via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL274617: Add data formatter for libstdc++ shared_ptr and 
weak_ptr (authored by tberghammer).

Changed prior to commit:
  http://reviews.llvm.org/D21984?vs=62730&id=62838#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D21984

Files:
  lldb/trunk/include/lldb/DataFormatters/VectorIterator.h
  
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile
  
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py
  
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/main.cpp
  lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
  lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcpp.h

Index: lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -652,8 +652,22 @@
  "size=${svar%#}")));
 
 AddCXXSynthetic(cpp_category_sp, lldb_private::formatters::LibStdcppVectorIteratorSyntheticFrontEndCreator, "std::vector iterator synthetic children", ConstString("^__gnu_cxx::__normal_iterator<.+>$"), stl_synth_flags, true);
-
+
 AddCXXSynthetic(cpp_category_sp, lldb_private::formatters::LibstdcppMapIteratorSyntheticFrontEndCreator, "std::map iterator synthetic children", ConstString("^std::_Rb_tree_iterator<.+>$"), stl_synth_flags, true);
+
+AddCXXSynthetic(cpp_category_sp, lldb_private::formatters::LibStdcppSharedPtrSyntheticFrontEndCreator,
+"std::shared_ptr synthetic children", ConstString("^std::shared_ptr<.+>(( )?&)?$"), stl_synth_flags,
+true);
+AddCXXSynthetic(cpp_category_sp, lldb_private::formatters::LibStdcppSharedPtrSyntheticFrontEndCreator,
+"std::weak_ptr synthetic children", ConstString("^std::weak_ptr<.+>(( )?&)?$"), stl_synth_flags,
+true);
+
+AddCXXSummary(cpp_category_sp, lldb_private::formatters::LibStdcppSmartPointerSummaryProvider,
+  "libstdc++ std::shared_ptr summary provider", ConstString("^std::shared_ptr<.+>(( )?&)?$"),
+  stl_summary_flags, true);
+AddCXXSummary(cpp_category_sp, lldb_private::formatters::LibStdcppSmartPointerSummaryProvider,
+  "libstdc++ std::weak_ptr summary provider", ConstString("^std::weak_ptr<.+>(( )?&)?$"),
+  stl_summary_flags, true);
 #endif
 }
 
Index: lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcpp.h
===
--- lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcpp.h
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcpp.h
@@ -24,9 +24,14 @@
 bool
 LibStdcppWStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // libcstdc++ c++11 std::wstring
 
+bool
+LibStdcppSmartPointerSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options); // libstdc++ std::shared_ptr<> and std::weak_ptr<>
+
 SyntheticChildrenFrontEnd* LibstdcppMapIteratorSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP);
-
+
 SyntheticChildrenFrontEnd* LibStdcppVectorIteratorSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP);
+
+SyntheticChildrenFrontEnd* LibStdcppSharedPtrSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP);
 } // namespace formatters
 } // namespace lldb_private
 
Index: lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
===
--- lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
@@ -28,12 +28,24 @@
 using namespace lldb_private;
 using namespace lldb_private::formatters;
 
+namespace
+{
+
 class LibstdcppMapIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd
 {
-public:
-LibstdcppMapIteratorSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp);
+/*
+ (std::_Rb_tree_iterator, std::allocator > > >) ibeg = {
+ (_Base_ptr) _M_node = 0x000100103910 {
+ (std::_Rb_tree_color) _M_color = _S_black
+ (std::_Rb_tree_node_base::_Base_ptr) _M_parent = 0x0001001038c0
+ (std::_Rb_tree_node_base::_Base_ptr) _M_left = 0x
+ (std::_Rb_tree_node_base::_Base_ptr) _M_right = 0x
+ }
+ }
+ */
 
-~LibstdcppMapIteratorSyntheticFrontEnd() override = default;

Re: [Lldb-commits] [PATCH] D21751: Implement GetMemoryRegions() for Linux and Mac OSX core files.

2016-07-06 Thread Howard Hellyer via lldb-commits
hhellyer updated this revision to Diff 62839.
hhellyer added a comment.

Updated patch to export IsMapped in the C++ and Python APIs.
Updated the test case to verify all the regions returned in the list are mapped.


http://reviews.llvm.org/D21751

Files:
  include/lldb/API/SBMemoryRegionInfo.h
  include/lldb/Core/RangeMap.h
  include/lldb/Target/MemoryRegionInfo.h
  include/lldb/Target/Process.h
  
packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/TestLinuxCore.py
  scripts/interface/SBMemoryRegionInfo.i
  source/API/SBMemoryRegionInfo.cpp
  source/Plugins/Process/Linux/NativeProcessLinux.cpp
  source/Plugins/Process/elf-core/ProcessElfCore.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  source/Plugins/Process/mach-core/ProcessMachCore.cpp
  source/Target/Process.cpp

Index: source/Target/Process.cpp
===
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -6609,3 +6609,36 @@
 
 return retval;
 }
+
+Error
+Process::GetMemoryRegions (std::vector& region_list)
+{
+
+Error error;
+
+lldb::addr_t range_base = 0;
+lldb::addr_t range_end = 0;
+
+region_list.clear();
+do
+{
+lldb::MemoryRegionInfoSP region_info( new lldb_private::MemoryRegionInfo() );
+error = GetMemoryRegionInfo (range_end, *region_info);
+// GetMemoryRegionInfo should only return an error if it is unimplemented.
+if (error.Fail())
+{
+region_list.clear();
+break;
+}
+
+range_base = region_info->GetRange().GetRangeBase();
+range_end = region_info->GetRange().GetRangeEnd();
+if( region_info->GetMapped() == MemoryRegionInfo::eYes )
+{
+region_list.push_back(region_info);
+}
+} while (range_end != LLDB_INVALID_ADDRESS);
+
+return error;
+
+}
Index: source/Plugins/Process/mach-core/ProcessMachCore.cpp
===
--- source/Plugins/Process/mach-core/ProcessMachCore.cpp
+++ source/Plugins/Process/mach-core/ProcessMachCore.cpp
@@ -581,19 +581,27 @@
: MemoryRegionInfo::eNo);
 region_info.SetExecutable(permissions.Test(ePermissionsExecutable) ? MemoryRegionInfo::eYes
: MemoryRegionInfo::eNo);
+region_info.SetMapped(MemoryRegionInfo::eYes);
 }
 else if (load_addr < permission_entry->GetRangeBase())
 {
 region_info.GetRange().SetRangeBase(load_addr);
 region_info.GetRange().SetRangeEnd(permission_entry->GetRangeBase());
 region_info.SetReadable(MemoryRegionInfo::eNo);
 region_info.SetWritable(MemoryRegionInfo::eNo);
 region_info.SetExecutable(MemoryRegionInfo::eNo);
+region_info.SetMapped(MemoryRegionInfo::eNo);
 }
 return Error();
 }
 
-return Error("invalid address");
+region_info.GetRange().SetRangeBase(load_addr);
+region_info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
+region_info.SetReadable(MemoryRegionInfo::eNo);
+region_info.SetWritable(MemoryRegionInfo::eNo);
+region_info.SetExecutable(MemoryRegionInfo::eNo);
+region_info.SetMapped(MemoryRegionInfo::eNo);
+return Error();
 }
 
 void
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -2427,13 +2427,16 @@
 region_info.SetExecutable (MemoryRegionInfo::eYes);
 else
 region_info.SetExecutable (MemoryRegionInfo::eNo);
+
+region_info.SetMapped(MemoryRegionInfo::eYes);
 }
 else
 {
 // The reported region does not contain this address -- we're looking at an unmapped page
 region_info.SetReadable (MemoryRegionInfo::eNo);
 region_info.SetWritable (MemoryRegionInfo::eNo);
 region_info.SetExecutable (MemoryRegionInfo::eNo);
+region_info.SetMapped(MemoryRegionInfo::eNo);
 }
 }
 else if (name.compare ("error") == 0)
@@ -2453,6 +2456,7 @@
 region_info.SetReadable (MemoryRegionInfo::eNo);
 region_info.SetWritable (MemoryRegionInfo::eNo);
 region_info.SetExecutable (MemoryRegionInfo::eNo);
+region_info.SetMapped(MemoryRegionInfo::eNo);
 }
 }
 else
Index: source/Plugins/Process/elf-core/ProcessElfCore.cpp
==

[Lldb-commits] [PATCH] D22039: [LLGS] Log more precise errors during inferior launch

2016-07-06 Thread Pavel Labath via lldb-commits
labath created this revision.
labath added a reviewer: tberghammer.
labath added a subscriber: lldb-commits.
Herald added subscribers: danalbert, tberghammer.

We are seeing infrequent failures to launch the inferior process on android. 
The failing call
seems to be execve(). This adds more logging to see the actual error reported 
by the call.

http://reviews.llvm.org/D22039

Files:
  source/Plugins/Process/Linux/NativeProcessLinux.cpp
  source/Plugins/Process/Linux/NativeProcessLinux.h

Index: source/Plugins/Process/Linux/NativeProcessLinux.h
===
--- source/Plugins/Process/Linux/NativeProcessLinux.h
+++ source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -202,6 +202,9 @@
 ::pid_t
 Attach(lldb::pid_t pid, Error &error);
 
+static void
+ChildFunc(const LaunchArgs &args) LLVM_ATTRIBUTE_NORETURN;
+
 static Error
 SetDefaultPtraceOpts(const lldb::pid_t);
 
Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp
===
--- source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -130,6 +130,35 @@
 return Error("failed to retrieve a valid architecture from the exe module");
 }
 
+// Used to notify the parent about which part of the launch sequence failed.
+enum LaunchCallSpecifier {
+ePtraceFailed,
+eDupStdinFailed,
+eDupStdoutFailed,
+eDupStderrFailed,
+eChdirFailed,
+eExecFailed,
+eSetGidFailed,
+eSetSigMaskFailed,
+eLaunchCallMax = eSetSigMaskFailed
+};
+
+static uint8_t LLVM_ATTRIBUTE_NORETURN ExitChildAbnormally(LaunchCallSpecifier spec)
+{
+static_assert(eLaunchCallMax < 0x8, "Have more launch calls than we are able to represent");
+// This may truncate the topmost bits of the errno because the exit code is only 8 bits wide.
+// However, it should still give us a pretty good indication of what went wrong. (And the
+// most common errors have small numbers anyway).
+_exit(unsigned(spec) | (errno << 3));
+}
+
+// The second member is the errno (or its 5 lowermost bits anyway).
+inline std::pair
+DecodeChildExitCode(int exit_code)
+{
+return std::make_pair(LaunchCallSpecifier(exit_code & 0x7), exit_code >> 3);
+}
+
 void
 DisplayBytes (StreamString &s, void *bytes, uint32_t count)
 {
@@ -453,136 +482,118 @@
 Attach(pid, error);
 }
 
+void NativeProcessLinux::ChildFunc(const LaunchArgs &args)
+{
+// Start tracing this child that is about to exec.
+if(ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1)
+ExitChildAbnormally(ePtraceFailed);
+
+// Do not inherit setgid powers.
+if (setgid(getgid()) != 0)
+ExitChildAbnormally(eSetGidFailed);
+
+// Attempt to have our own process group.
+if (setpgid(0, 0) != 0)
+{
+// FIXME log that this failed. This is common.
+// Don't allow this to prevent an inferior exec.
+}
+
+// Dup file descriptors if needed.
+if (args.m_stdin_file_spec)
+if (!DupDescriptor(args.m_stdin_file_spec, STDIN_FILENO, O_RDONLY))
+ExitChildAbnormally(eDupStdinFailed);
+
+if (args.m_stdout_file_spec)
+if (!DupDescriptor(args.m_stdout_file_spec, STDOUT_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
+ExitChildAbnormally(eDupStdoutFailed);
+
+if (args.m_stderr_file_spec)
+if (!DupDescriptor(args.m_stderr_file_spec, STDERR_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
+ExitChildAbnormally(eDupStderrFailed);
+
+// Close everything besides stdin, stdout, and stderr that has no file
+// action to avoid leaking
+for (int fd = 3; fd < sysconf(_SC_OPEN_MAX); ++fd)
+if (!args.m_launch_info.GetFileActionForFD(fd))
+close(fd);
+
+// Change working directory
+if (args.m_working_dir && 0 != ::chdir(args.m_working_dir.GetCString()))
+ExitChildAbnormally(eChdirFailed);
+
+// Disable ASLR if requested.
+if (args.m_launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR))
+{
+const int old_personality = personality(LLDB_PERSONALITY_GET_CURRENT_SETTINGS);
+if (old_personality == -1)
+{
+// Can't retrieve Linux personality.  Cannot disable ASLR.
+}
+else
+{
+const int new_personality = personality(ADDR_NO_RANDOMIZE | old_personality);
+if (new_personality == -1)
+{
+// Disabling ASLR failed.
+}
+else
+{
+// Disabling ASLR succeeded.
+}
+}
+}
+
+// Clear the signal mask to prevent the child from being affected by
+// any masking done by the parent.
+sigset_t set;
+if (sigemptyset(&set) != 0 || pthread_sigmask(SIG_SETMASK, &set, nullptr) != 0)
+ExitChildAbnormally(eSetSigMaskFailed);
+
+// Propagate the environment if o

Re: [Lldb-commits] [PATCH] D22039: [LLGS] Log more precise errors during inferior launch

2016-07-06 Thread Pavel Labath via lldb-commits
labath updated this revision to Diff 62842.
labath added a comment.

run clang-format over the patch


http://reviews.llvm.org/D22039

Files:
  source/Plugins/Process/Linux/NativeProcessLinux.cpp
  source/Plugins/Process/Linux/NativeProcessLinux.h

Index: source/Plugins/Process/Linux/NativeProcessLinux.h
===
--- source/Plugins/Process/Linux/NativeProcessLinux.h
+++ source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -202,6 +202,9 @@
 ::pid_t
 Attach(lldb::pid_t pid, Error &error);
 
+static void
+ChildFunc(const LaunchArgs &args) LLVM_ATTRIBUTE_NORETURN;
+
 static Error
 SetDefaultPtraceOpts(const lldb::pid_t);
 
Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp
===
--- source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -130,6 +130,37 @@
 return Error("failed to retrieve a valid architecture from the exe module");
 }
 
+// Used to notify the parent about which part of the launch sequence failed.
+enum LaunchCallSpecifier
+{
+ePtraceFailed,
+eDupStdinFailed,
+eDupStdoutFailed,
+eDupStderrFailed,
+eChdirFailed,
+eExecFailed,
+eSetGidFailed,
+eSetSigMaskFailed,
+eLaunchCallMax = eSetSigMaskFailed
+};
+
+static uint8_t LLVM_ATTRIBUTE_NORETURN
+ExitChildAbnormally(LaunchCallSpecifier spec)
+{
+static_assert(eLaunchCallMax < 0x8, "Have more launch calls than we are able to represent");
+// This may truncate the topmost bits of the errno because the exit code is only 8 bits wide.
+// However, it should still give us a pretty good indication of what went wrong. (And the
+// most common errors have small numbers anyway).
+_exit(unsigned(spec) | (errno << 3));
+}
+
+// The second member is the errno (or its 5 lowermost bits anyway).
+inline std::pair
+DecodeChildExitCode(int exit_code)
+{
+return std::make_pair(LaunchCallSpecifier(exit_code & 0x7), exit_code >> 3);
+}
+
 void
 DisplayBytes (StreamString &s, void *bytes, uint32_t count)
 {
@@ -453,136 +484,119 @@
 Attach(pid, error);
 }
 
+void
+NativeProcessLinux::ChildFunc(const LaunchArgs &args)
+{
+// Start tracing this child that is about to exec.
+if (ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1)
+ExitChildAbnormally(ePtraceFailed);
+
+// Do not inherit setgid powers.
+if (setgid(getgid()) != 0)
+ExitChildAbnormally(eSetGidFailed);
+
+// Attempt to have our own process group.
+if (setpgid(0, 0) != 0)
+{
+// FIXME log that this failed. This is common.
+// Don't allow this to prevent an inferior exec.
+}
+
+// Dup file descriptors if needed.
+if (args.m_stdin_file_spec)
+if (!DupDescriptor(args.m_stdin_file_spec, STDIN_FILENO, O_RDONLY))
+ExitChildAbnormally(eDupStdinFailed);
+
+if (args.m_stdout_file_spec)
+if (!DupDescriptor(args.m_stdout_file_spec, STDOUT_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
+ExitChildAbnormally(eDupStdoutFailed);
+
+if (args.m_stderr_file_spec)
+if (!DupDescriptor(args.m_stderr_file_spec, STDERR_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
+ExitChildAbnormally(eDupStderrFailed);
+
+// Close everything besides stdin, stdout, and stderr that has no file
+// action to avoid leaking
+for (int fd = 3; fd < sysconf(_SC_OPEN_MAX); ++fd)
+if (!args.m_launch_info.GetFileActionForFD(fd))
+close(fd);
+
+// Change working directory
+if (args.m_working_dir && 0 != ::chdir(args.m_working_dir.GetCString()))
+ExitChildAbnormally(eChdirFailed);
+
+// Disable ASLR if requested.
+if (args.m_launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR))
+{
+const int old_personality = personality(LLDB_PERSONALITY_GET_CURRENT_SETTINGS);
+if (old_personality == -1)
+{
+// Can't retrieve Linux personality.  Cannot disable ASLR.
+}
+else
+{
+const int new_personality = personality(ADDR_NO_RANDOMIZE | old_personality);
+if (new_personality == -1)
+{
+// Disabling ASLR failed.
+}
+else
+{
+// Disabling ASLR succeeded.
+}
+}
+}
+
+// Clear the signal mask to prevent the child from being affected by
+// any masking done by the parent.
+sigset_t set;
+if (sigemptyset(&set) != 0 || pthread_sigmask(SIG_SETMASK, &set, nullptr) != 0)
+ExitChildAbnormally(eSetSigMaskFailed);
+
+// Propagate the environment if one is not supplied.
+const char **envp = args.m_envp;
+if (envp == NULL || envp[0] == NULL)
+envp = const_cast(environ);
+
+// Execute.  We should never return...
+execve(args.m_argv[0], const_cast(args.m_argv), const

[Lldb-commits] [lldb] r274621 - In AddressSanitizer and ThreadSanitizer, let's explicitly set the language of the expression we're evaluating.

2016-07-06 Thread Kuba Brecka via lldb-commits
Author: kuba.brecka
Date: Wed Jul  6 06:46:20 2016
New Revision: 274621

URL: http://llvm.org/viewvc/llvm-project?rev=274621&view=rev
Log:
In AddressSanitizer and ThreadSanitizer, let's explicitly set the language of 
the expression we're evaluating.


Modified:

lldb/trunk/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp

lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
lldb/trunk/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp

Modified: 
lldb/trunk/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp?rev=274621&r1=274620&r2=274621&view=diff
==
--- 
lldb/trunk/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp
 (original)
+++ 
lldb/trunk/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp
 Wed Jul  6 06:46:20 2016
@@ -188,6 +188,7 @@ AddressSanitizerRuntime::RetrieveReportD
 options.SetTimeoutUsec(RETRIEVE_REPORT_DATA_FUNCTION_TIMEOUT_USEC);
 options.SetPrefix(address_sanitizer_retrieve_report_data_prefix);
 options.SetAutoApplyFixIts(false);
+options.SetLanguage(eLanguageTypeObjC_plus_plus);
 
 ValueObjectSP return_value_sp;
 ExecutionContext exe_ctx;

Modified: 
lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp?rev=274621&r1=274620&r2=274621&view=diff
==
--- 
lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
 (original)
+++ 
lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
 Wed Jul  6 06:46:20 2016
@@ -361,6 +361,8 @@ ThreadSanitizerRuntime::RetrieveReportDa
 options.SetIgnoreBreakpoints(true);
 options.SetTimeoutUsec(RETRIEVE_REPORT_DATA_FUNCTION_TIMEOUT_USEC);
 options.SetPrefix(thread_sanitizer_retrieve_report_data_prefix);
+options.SetAutoApplyFixIts(false);
+options.SetLanguage(eLanguageTypeObjC_plus_plus);
 
 ValueObjectSP main_value;
 ExecutionContext exe_ctx;

Modified: lldb/trunk/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp?rev=274621&r1=274620&r2=274621&view=diff
==
--- lldb/trunk/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp 
(original)
+++ lldb/trunk/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp Wed Jul  
6 06:46:20 2016
@@ -186,6 +186,8 @@ MemoryHistoryASan::GetHistoryThreads(lld
 options.SetIgnoreBreakpoints(true);
 options.SetTimeoutUsec(GET_STACK_FUNCTION_TIMEOUT_USEC);
 options.SetPrefix(memory_history_asan_command_prefix);
+options.SetAutoApplyFixIts(false);
+options.SetLanguage(eLanguageTypeObjC_plus_plus);
 
 ExpressionResults expr_result = UserExpression::Evaluate (exe_ctx,
   options,


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


Re: [Lldb-commits] [PATCH] D22039: [LLGS] Log more precise errors during inferior launch

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

Looks good. You might want to print the errno a bit better but I am fine with 
the current implementation as well.


http://reviews.llvm.org/D22039



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


Re: [Lldb-commits] [PATCH] D22029: Fix ADB client disconnect issues

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

Looks good


http://reviews.llvm.org/D22029



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


[Lldb-commits] [PATCH] D22040: Add oat symbolization support for odex files

2016-07-06 Thread Tamas Berghammer via lldb-commits
tberghammer created this revision.
tberghammer added reviewers: labath, ovyalov.
tberghammer added a subscriber: lldb-commits.
Herald added subscribers: srhines, danalbert, tberghammer.

Add oat symbolization support for odex files

http://reviews.llvm.org/D22040

Files:
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  source/Plugins/Platform/Android/PlatformAndroid.cpp

Index: source/Plugins/Platform/Android/PlatformAndroid.cpp
===
--- source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -317,8 +317,9 @@
  const FileSpec& dst_file_spec)
 {
 // For oat file we can try to fetch additional debug info from the device
-if (module_sp->GetFileSpec().GetFileNameExtension() != ConstString("oat"))
-return Error("Symbol file downloading only supported for oat files");
+ConstString extension = module_sp->GetFileSpec().GetFileNameExtension();
+if (extension != ConstString("oat") && extension != ConstString("odex"))
+return Error("Symbol file downloading only supported for oat and odex 
files");
 
 // If we have no information about the platform file we can't execute 
oatdump
 if (!module_sp->GetPlatformFileSpec())
Index: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2184,15 +2184,16 @@
 static ConstString bss_section_name(".bss");
 static ConstString opd_section_name(".opd");// For ppc64
 
-// On Android the oatdata and the oatexec symbols in the oat files covers 
the full .text
-// section what causes issues with displaying unusable symbol name to the 
user and very slow
-// unwinding speed because the instruction emulation based unwind plans 
try to emulate all
+// On Android the oatdata and the oatexec symbols in the oat and odex 
files covers the full
+// .text section what causes issues with displaying unusable symbol name 
to the user and very
+// slow unwinding speed because the instruction emulation based unwind 
plans try to emulate all
 // instructions in these symbols. Don't add these symbols to the symbol 
list as they have no
 // use for the debugger and they are causing a lot of trouble.
 // Filtering can't be restricted to Android because this special object 
file don't contain the
 // note section specifying the environment to Android but the custom 
extension and file name
 // makes it highly unlikely that this will collide with anything else.
-bool skip_oatdata_oatexec = m_file.GetFileNameExtension() == 
ConstString("oat");
+ConstString file_extension = m_file.GetFileNameExtension();
+bool skip_oatdata_oatexec = file_extension == ConstString("oat") || 
file_extension == ConstString("odex");
 
 ArchSpec arch;
 GetArchitecture(arch);


Index: source/Plugins/Platform/Android/PlatformAndroid.cpp
===
--- source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -317,8 +317,9 @@
  const FileSpec& dst_file_spec)
 {
 // For oat file we can try to fetch additional debug info from the device
-if (module_sp->GetFileSpec().GetFileNameExtension() != ConstString("oat"))
-return Error("Symbol file downloading only supported for oat files");
+ConstString extension = module_sp->GetFileSpec().GetFileNameExtension();
+if (extension != ConstString("oat") && extension != ConstString("odex"))
+return Error("Symbol file downloading only supported for oat and odex files");
 
 // If we have no information about the platform file we can't execute oatdump
 if (!module_sp->GetPlatformFileSpec())
Index: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2184,15 +2184,16 @@
 static ConstString bss_section_name(".bss");
 static ConstString opd_section_name(".opd");// For ppc64
 
-// On Android the oatdata and the oatexec symbols in the oat files covers the full .text
-// section what causes issues with displaying unusable symbol name to the user and very slow
-// unwinding speed because the instruction emulation based unwind plans try to emulate all
+// On Android the oatdata and the oatexec symbols in the oat and odex files covers the full
+// .text section what causes issues with displaying unusable symbol name to the user and very
+// slow unwinding speed because the instruction emulation based unwind plans try to emulate all
 // instructions in these symbols. Don't add these symbols

[Lldb-commits] [lldb] r274624 - [LLGS] Log more precise errors during inferior launch

2016-07-06 Thread Pavel Labath via lldb-commits
Author: labath
Date: Wed Jul  6 08:18:50 2016
New Revision: 274624

URL: http://llvm.org/viewvc/llvm-project?rev=274624&view=rev
Log:
[LLGS] Log more precise errors during inferior launch

Summary:
We are seeing infrequent failures to launch the inferior process on android. 
The failing call
seems to be execve(). This adds more logging to see the actual error reported 
by the call.

Reviewers: tberghammer

Subscribers: tberghammer, lldb-commits, danalbert

Differential Revision: http://reviews.llvm.org/D22039

Modified:
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=274624&r1=274623&r2=274624&view=diff
==
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Wed Jul  6 
08:18:50 2016
@@ -130,6 +130,37 @@ ResolveProcessArchitecture(lldb::pid_t p
 return Error("failed to retrieve a valid architecture from the exe 
module");
 }
 
+// Used to notify the parent about which part of the launch sequence failed.
+enum LaunchCallSpecifier
+{
+ePtraceFailed,
+eDupStdinFailed,
+eDupStdoutFailed,
+eDupStderrFailed,
+eChdirFailed,
+eExecFailed,
+eSetGidFailed,
+eSetSigMaskFailed,
+eLaunchCallMax = eSetSigMaskFailed
+};
+
+static uint8_t LLVM_ATTRIBUTE_NORETURN
+ExitChildAbnormally(LaunchCallSpecifier spec)
+{
+static_assert(eLaunchCallMax < 0x8, "Have more launch calls than we are 
able to represent");
+// This may truncate the topmost bits of the errno because the exit code 
is only 8 bits wide.
+// However, it should still give us a pretty good indication of what went 
wrong. (And the
+// most common errors have small numbers anyway).
+_exit(unsigned(spec) | (errno << 3));
+}
+
+// The second member is the errno (or its 5 lowermost bits anyway).
+inline std::pair
+DecodeChildExitCode(int exit_code)
+{
+return std::make_pair(LaunchCallSpecifier(exit_code & 0x7), exit_code >> 
3);
+}
+
 void
 DisplayBytes (StreamString &s, void *bytes, uint32_t count)
 {
@@ -453,24 +484,97 @@ NativeProcessLinux::AttachToInferior (Ma
 Attach(pid, error);
 }
 
+void
+NativeProcessLinux::ChildFunc(const LaunchArgs &args)
+{
+// Start tracing this child that is about to exec.
+if (ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1)
+ExitChildAbnormally(ePtraceFailed);
+
+// Do not inherit setgid powers.
+if (setgid(getgid()) != 0)
+ExitChildAbnormally(eSetGidFailed);
+
+// Attempt to have our own process group.
+if (setpgid(0, 0) != 0)
+{
+// FIXME log that this failed. This is common.
+// Don't allow this to prevent an inferior exec.
+}
+
+// Dup file descriptors if needed.
+if (args.m_stdin_file_spec)
+if (!DupDescriptor(args.m_stdin_file_spec, STDIN_FILENO, O_RDONLY))
+ExitChildAbnormally(eDupStdinFailed);
+
+if (args.m_stdout_file_spec)
+if (!DupDescriptor(args.m_stdout_file_spec, STDOUT_FILENO, O_WRONLY | 
O_CREAT | O_TRUNC))
+ExitChildAbnormally(eDupStdoutFailed);
+
+if (args.m_stderr_file_spec)
+if (!DupDescriptor(args.m_stderr_file_spec, STDERR_FILENO, O_WRONLY | 
O_CREAT | O_TRUNC))
+ExitChildAbnormally(eDupStderrFailed);
+
+// Close everything besides stdin, stdout, and stderr that has no file
+// action to avoid leaking
+for (int fd = 3; fd < sysconf(_SC_OPEN_MAX); ++fd)
+if (!args.m_launch_info.GetFileActionForFD(fd))
+close(fd);
+
+// Change working directory
+if (args.m_working_dir && 0 != ::chdir(args.m_working_dir.GetCString()))
+ExitChildAbnormally(eChdirFailed);
+
+// Disable ASLR if requested.
+if (args.m_launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR))
+{
+const int old_personality = 
personality(LLDB_PERSONALITY_GET_CURRENT_SETTINGS);
+if (old_personality == -1)
+{
+// Can't retrieve Linux personality.  Cannot disable ASLR.
+}
+else
+{
+const int new_personality = personality(ADDR_NO_RANDOMIZE | 
old_personality);
+if (new_personality == -1)
+{
+// Disabling ASLR failed.
+}
+else
+{
+// Disabling ASLR succeeded.
+}
+}
+}
+
+// Clear the signal mask to prevent the child from being affected by
+// any masking done by the parent.
+sigset_t set;
+if (sigemptyset(&set) != 0 || pthread_sigmask(SIG_SETMASK, &set, nullptr) 
!= 0)
+ExitChildAbnormally(eSetSigMaskFailed);
+
+// Propagate the environment 

Re: [Lldb-commits] [PATCH] D22039: [LLGS] Log more precise errors during inferior launch

2016-07-06 Thread Pavel Labath via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL274624: [LLGS] Log more precise errors during inferior 
launch (authored by labath).

Changed prior to commit:
  http://reviews.llvm.org/D22039?vs=62842&id=62854#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D22039

Files:
  lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h

Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
===
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -202,6 +202,9 @@
 ::pid_t
 Attach(lldb::pid_t pid, Error &error);
 
+static void
+ChildFunc(const LaunchArgs &args) LLVM_ATTRIBUTE_NORETURN;
+
 static Error
 SetDefaultPtraceOpts(const lldb::pid_t);
 
Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
===
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -130,6 +130,37 @@
 return Error("failed to retrieve a valid architecture from the exe module");
 }
 
+// Used to notify the parent about which part of the launch sequence failed.
+enum LaunchCallSpecifier
+{
+ePtraceFailed,
+eDupStdinFailed,
+eDupStdoutFailed,
+eDupStderrFailed,
+eChdirFailed,
+eExecFailed,
+eSetGidFailed,
+eSetSigMaskFailed,
+eLaunchCallMax = eSetSigMaskFailed
+};
+
+static uint8_t LLVM_ATTRIBUTE_NORETURN
+ExitChildAbnormally(LaunchCallSpecifier spec)
+{
+static_assert(eLaunchCallMax < 0x8, "Have more launch calls than we are able to represent");
+// This may truncate the topmost bits of the errno because the exit code is only 8 bits wide.
+// However, it should still give us a pretty good indication of what went wrong. (And the
+// most common errors have small numbers anyway).
+_exit(unsigned(spec) | (errno << 3));
+}
+
+// The second member is the errno (or its 5 lowermost bits anyway).
+inline std::pair
+DecodeChildExitCode(int exit_code)
+{
+return std::make_pair(LaunchCallSpecifier(exit_code & 0x7), exit_code >> 3);
+}
+
 void
 DisplayBytes (StreamString &s, void *bytes, uint32_t count)
 {
@@ -453,136 +484,119 @@
 Attach(pid, error);
 }
 
+void
+NativeProcessLinux::ChildFunc(const LaunchArgs &args)
+{
+// Start tracing this child that is about to exec.
+if (ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1)
+ExitChildAbnormally(ePtraceFailed);
+
+// Do not inherit setgid powers.
+if (setgid(getgid()) != 0)
+ExitChildAbnormally(eSetGidFailed);
+
+// Attempt to have our own process group.
+if (setpgid(0, 0) != 0)
+{
+// FIXME log that this failed. This is common.
+// Don't allow this to prevent an inferior exec.
+}
+
+// Dup file descriptors if needed.
+if (args.m_stdin_file_spec)
+if (!DupDescriptor(args.m_stdin_file_spec, STDIN_FILENO, O_RDONLY))
+ExitChildAbnormally(eDupStdinFailed);
+
+if (args.m_stdout_file_spec)
+if (!DupDescriptor(args.m_stdout_file_spec, STDOUT_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
+ExitChildAbnormally(eDupStdoutFailed);
+
+if (args.m_stderr_file_spec)
+if (!DupDescriptor(args.m_stderr_file_spec, STDERR_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
+ExitChildAbnormally(eDupStderrFailed);
+
+// Close everything besides stdin, stdout, and stderr that has no file
+// action to avoid leaking
+for (int fd = 3; fd < sysconf(_SC_OPEN_MAX); ++fd)
+if (!args.m_launch_info.GetFileActionForFD(fd))
+close(fd);
+
+// Change working directory
+if (args.m_working_dir && 0 != ::chdir(args.m_working_dir.GetCString()))
+ExitChildAbnormally(eChdirFailed);
+
+// Disable ASLR if requested.
+if (args.m_launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR))
+{
+const int old_personality = personality(LLDB_PERSONALITY_GET_CURRENT_SETTINGS);
+if (old_personality == -1)
+{
+// Can't retrieve Linux personality.  Cannot disable ASLR.
+}
+else
+{
+const int new_personality = personality(ADDR_NO_RANDOMIZE | old_personality);
+if (new_personality == -1)
+{
+// Disabling ASLR failed.
+}
+else
+{
+// Disabling ASLR succeeded.
+}
+}
+}
+
+// Clear the signal mask to prevent the child from being affected by
+// any masking done by the parent.
+sigset_t set;
+if (sigemptyset(&set) != 0 || pthread_sigmask(SIG_SETMASK, &set, nullptr) != 0)
+ExitChildAbnormally(eSetSigMaskFailed);
+
+// Pro

Re: [Lldb-commits] [PATCH] D22040: Add oat symbolization support for odex files

2016-07-06 Thread Oleksiy Vyalov via lldb-commits
ovyalov accepted this revision.
ovyalov added a comment.
This revision is now accepted and ready to land.

LGTM


http://reviews.llvm.org/D22040



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


Re: [Lldb-commits] [PATCH] D22040: Add oat symbolization support for odex files

2016-07-06 Thread Pavel Labath via lldb-commits
labath added a comment.

What is the performance implication of this?


http://reviews.llvm.org/D22040



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


[Lldb-commits] [lldb] r274635 - Add oat symbolization support for odex files

2016-07-06 Thread Tamas Berghammer via lldb-commits
Author: tberghammer
Date: Wed Jul  6 11:40:09 2016
New Revision: 274635

URL: http://llvm.org/viewvc/llvm-project?rev=274635&view=rev
Log:
Add oat symbolization support for odex files

Differential revision: http://reviews.llvm.org/D22040

Modified:
lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=274635&r1=274634&r2=274635&view=diff
==
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Wed Jul  6 
11:40:09 2016
@@ -2184,15 +2184,16 @@ ObjectFileELF::ParseSymbols (Symtab *sym
 static ConstString bss_section_name(".bss");
 static ConstString opd_section_name(".opd");// For ppc64
 
-// On Android the oatdata and the oatexec symbols in the oat files covers 
the full .text
-// section what causes issues with displaying unusable symbol name to the 
user and very slow
-// unwinding speed because the instruction emulation based unwind plans 
try to emulate all
+// On Android the oatdata and the oatexec symbols in the oat and odex 
files covers the full
+// .text section what causes issues with displaying unusable symbol name 
to the user and very
+// slow unwinding speed because the instruction emulation based unwind 
plans try to emulate all
 // instructions in these symbols. Don't add these symbols to the symbol 
list as they have no
 // use for the debugger and they are causing a lot of trouble.
 // Filtering can't be restricted to Android because this special object 
file don't contain the
 // note section specifying the environment to Android but the custom 
extension and file name
 // makes it highly unlikely that this will collide with anything else.
-bool skip_oatdata_oatexec = m_file.GetFileNameExtension() == 
ConstString("oat");
+ConstString file_extension = m_file.GetFileNameExtension();
+bool skip_oatdata_oatexec = file_extension == ConstString("oat") || 
file_extension == ConstString("odex");
 
 ArchSpec arch;
 GetArchitecture(arch);

Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp?rev=274635&r1=274634&r2=274635&view=diff
==
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp Wed Jul  6 
11:40:09 2016
@@ -317,8 +317,9 @@ PlatformAndroid::DownloadSymbolFile (con
  const FileSpec& dst_file_spec)
 {
 // For oat file we can try to fetch additional debug info from the device
-if (module_sp->GetFileSpec().GetFileNameExtension() != ConstString("oat"))
-return Error("Symbol file downloading only supported for oat files");
+ConstString extension = module_sp->GetFileSpec().GetFileNameExtension();
+if (extension != ConstString("oat") && extension != ConstString("odex"))
+return Error("Symbol file downloading only supported for oat and odex 
files");
 
 // If we have no information about the platform file we can't execute 
oatdump
 if (!module_sp->GetPlatformFileSpec())


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


Re: [Lldb-commits] [PATCH] D22040: Add oat symbolization support for odex files

2016-07-06 Thread Tamas Berghammer via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL274635: Add oat symbolization support for odex files 
(authored by tberghammer).

Changed prior to commit:
  http://reviews.llvm.org/D22040?vs=62851&id=62895#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D22040

Files:
  lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp

Index: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2184,15 +2184,16 @@
 static ConstString bss_section_name(".bss");
 static ConstString opd_section_name(".opd");// For ppc64
 
-// On Android the oatdata and the oatexec symbols in the oat files covers 
the full .text
-// section what causes issues with displaying unusable symbol name to the 
user and very slow
-// unwinding speed because the instruction emulation based unwind plans 
try to emulate all
+// On Android the oatdata and the oatexec symbols in the oat and odex 
files covers the full
+// .text section what causes issues with displaying unusable symbol name 
to the user and very
+// slow unwinding speed because the instruction emulation based unwind 
plans try to emulate all
 // instructions in these symbols. Don't add these symbols to the symbol 
list as they have no
 // use for the debugger and they are causing a lot of trouble.
 // Filtering can't be restricted to Android because this special object 
file don't contain the
 // note section specifying the environment to Android but the custom 
extension and file name
 // makes it highly unlikely that this will collide with anything else.
-bool skip_oatdata_oatexec = m_file.GetFileNameExtension() == 
ConstString("oat");
+ConstString file_extension = m_file.GetFileNameExtension();
+bool skip_oatdata_oatexec = file_extension == ConstString("oat") || 
file_extension == ConstString("odex");
 
 ArchSpec arch;
 GetArchitecture(arch);
Index: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
===
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -317,8 +317,9 @@
  const FileSpec& dst_file_spec)
 {
 // For oat file we can try to fetch additional debug info from the device
-if (module_sp->GetFileSpec().GetFileNameExtension() != ConstString("oat"))
-return Error("Symbol file downloading only supported for oat files");
+ConstString extension = module_sp->GetFileSpec().GetFileNameExtension();
+if (extension != ConstString("oat") && extension != ConstString("odex"))
+return Error("Symbol file downloading only supported for oat and odex 
files");
 
 // If we have no information about the platform file we can't execute 
oatdump
 if (!module_sp->GetPlatformFileSpec())


Index: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2184,15 +2184,16 @@
 static ConstString bss_section_name(".bss");
 static ConstString opd_section_name(".opd");// For ppc64
 
-// On Android the oatdata and the oatexec symbols in the oat files covers the full .text
-// section what causes issues with displaying unusable symbol name to the user and very slow
-// unwinding speed because the instruction emulation based unwind plans try to emulate all
+// On Android the oatdata and the oatexec symbols in the oat and odex files covers the full
+// .text section what causes issues with displaying unusable symbol name to the user and very
+// slow unwinding speed because the instruction emulation based unwind plans try to emulate all
 // instructions in these symbols. Don't add these symbols to the symbol list as they have no
 // use for the debugger and they are causing a lot of trouble.
 // Filtering can't be restricted to Android because this special object file don't contain the
 // note section specifying the environment to Android but the custom extension and file name
 // makes it highly unlikely that this will collide with anything else.
-bool skip_oatdata_oatexec = m_file.GetFileNameExtension() == ConstString("oat");
+ConstString file_extension = m_file.GetFileNameExtension();
+bool skip_oatdata_oatexec = file_extension == ConstString("oat") || file_extension == ConstString("odex");
 
 ArchSpec arch;
 GetArchitecture(arch);
Index: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
==

[Lldb-commits] [PATCH] D22052: Respect `ANDROID_SERIAL` environment variable used by ADB

2016-07-06 Thread Luke Drummond via lldb-commits
ldrumm created this revision.
ldrumm added reviewers: tberghammer, ovyalov.
ldrumm added a subscriber: lldb-commits.
ldrumm set the repository for this revision to rL LLVM.
Herald added subscribers: srhines, danalbert, tberghammer.

Respect `ANDROID_SERIAL` environment variable used by ADB

When multiple Android devices are attached, the default behaviour of ADB
is to resolve a device number based on the presence of ANDROID_SERIAL if
the serial number is not explicitly passed by the `-s` parameter. This patch
emulates that behaviour in lldb's ADB platform connector


Repository:
  rL LLVM

http://reviews.llvm.org/D22052

Files:
  source/Plugins/Platform/Android/AdbClient.cpp

Index: source/Plugins/Platform/Android/AdbClient.cpp
===
--- source/Plugins/Platform/Android/AdbClient.cpp
+++ source/Plugins/Platform/Android/AdbClient.cpp
@@ -24,6 +24,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -66,10 +67,15 @@
 if (device_id.empty())
 {
 if (connect_devices.size() != 1)
-return Error("Expected a single connected device, got instead %" 
PRIu64,
-static_cast(connect_devices.size()));
-
-adb.SetDeviceID(connect_devices.front());
+{
+if (const char *android_serial = std::getenv("ANDROID_SERIAL"))
+adb.SetDeviceID(android_serial);
+else
+return Error("Expected a single connected device, got instead 
%" PRIu64,
+ static_cast(connect_devices.size()));
+}
+else
+adb.SetDeviceID(connect_devices.front());
 }
 else
 {


Index: source/Plugins/Platform/Android/AdbClient.cpp
===
--- source/Plugins/Platform/Android/AdbClient.cpp
+++ source/Plugins/Platform/Android/AdbClient.cpp
@@ -24,6 +24,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -66,10 +67,15 @@
 if (device_id.empty())
 {
 if (connect_devices.size() != 1)
-return Error("Expected a single connected device, got instead %" PRIu64,
-static_cast(connect_devices.size()));
-
-adb.SetDeviceID(connect_devices.front());
+{
+if (const char *android_serial = std::getenv("ANDROID_SERIAL"))
+adb.SetDeviceID(android_serial);
+else
+return Error("Expected a single connected device, got instead %" PRIu64,
+ static_cast(connect_devices.size()));
+}
+else
+adb.SetDeviceID(connect_devices.front());
 }
 else
 {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] r274638 - Fix ADB client disconnect issues.

2016-07-06 Thread Oleksiy Vyalov via lldb-commits
Author: ovyalov
Date: Wed Jul  6 12:02:42 2016
New Revision: 274638

URL: http://llvm.org/viewvc/llvm-project?rev=274638&view=rev
Log:
Fix ADB client disconnect issues.

http://reviews.llvm.org/D22029


Modified:
lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
lldb/trunk/source/Plugins/Platform/Android/AdbClient.h
lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h

Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp?rev=274638&r1=274637&r2=274638&view=diff
==
--- lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp Wed Jul  6 
12:02:42 2016
@@ -225,10 +225,10 @@ AdbClient::DeletePortForwarding (const u
 }
 
 Error
-AdbClient::SendMessage (const std::string &packet)
+AdbClient::SendMessage (const std::string &packet, const bool reconnect)
 {
 Error error;
-if (!m_conn || !m_conn->IsConnected())
+if (!m_conn || reconnect)
 {
 error = Connect ();
 if (error.Fail ())
@@ -364,7 +364,7 @@ AdbClient::StartSync ()
 Error
 AdbClient::Sync ()
 {
-auto error = SendMessage ("sync:");
+auto error = SendMessage ("sync:", false);
 if (error.Fail ())
 return error;
 
@@ -380,9 +380,13 @@ AdbClient::ReadAllBytes (void *buffer, s
 Error
 AdbClient::Shell (const char* command, uint32_t timeout_ms, std::string* 
output)
 {
+auto error = SwitchDeviceTransport ();
+if (error.Fail ())
+return Error ("Failed to switch to device transport: %s", 
error.AsCString ());
+
 StreamString adb_command;
 adb_command.Printf("shell:%s", command);
-auto error = SendMessage (adb_command.GetData());
+error = SendMessage (adb_command.GetData(), false);
 if (error.Fail ())
 return error;
 
@@ -412,7 +416,7 @@ AdbClient::GetSyncService (Error &error)
 }
 
 Error
-AdbClient::SyncService::PullFile (const FileSpec &remote_file, const FileSpec 
&local_file)
+AdbClient::SyncService::internalPullFile (const FileSpec &remote_file, const 
FileSpec &local_file)
 {
 const auto local_file_path = local_file.GetPath ();
 llvm::FileRemover local_file_remover (local_file_path.c_str ());
@@ -442,7 +446,7 @@ AdbClient::SyncService::PullFile (const
 }
 
 Error
-AdbClient::SyncService::PushFile (const FileSpec &local_file, const FileSpec 
&remote_file)
+AdbClient::SyncService::internalPushFile (const FileSpec &local_file, const 
FileSpec &remote_file)
 {
 const auto local_file_path (local_file.GetPath ());
 std::ifstream src (local_file_path.c_str(), std::ios::in | 
std::ios::binary);
@@ -492,7 +496,7 @@ AdbClient::SyncService::PushFile (const
 }
 
 Error
-AdbClient::SyncService::Stat (const FileSpec &remote_file, uint32_t &mode, 
uint32_t &size, uint32_t &mtime)
+AdbClient::SyncService::internalStat (const FileSpec &remote_file, uint32_t 
&mode, uint32_t &size, uint32_t &mtime)
 {
 const std::string remote_file_path (remote_file.GetPath (false));
 auto error = SendSyncRequest (kSTAT, remote_file_path.length (), 
remote_file_path.c_str ());
@@ -523,11 +527,54 @@ AdbClient::SyncService::Stat (const File
 return Error ();
 }
 
+Error
+AdbClient::SyncService::PullFile (const FileSpec &remote_file, const FileSpec 
&local_file)
+{
+return executeCommand ([this, &remote_file, &local_file]() {
+return internalPullFile (remote_file, local_file);
+});
+}
+
+Error
+AdbClient::SyncService::PushFile (const FileSpec &local_file, const FileSpec 
&remote_file)
+{
+return executeCommand ([this, &local_file, &remote_file]() {
+return internalPushFile (local_file, remote_file);
+});
+}
+
+Error
+AdbClient::SyncService::Stat (const FileSpec &remote_file, uint32_t &mode, 
uint32_t &size, uint32_t &mtime)
+{
+return executeCommand ([this, &remote_file, &mode, &size, &mtime]() {
+return internalStat (remote_file, mode, size, mtime);
+});
+}
+
+bool
+AdbClient::SyncService::IsConnected () const
+{
+return m_conn && m_conn->IsConnected ();
+}
+
 AdbClient::SyncService::SyncService(std::unique_ptr &&conn):
 m_conn(std::move(conn))
 {
 }
 
+Error
+AdbClient::SyncService::executeCommand (const std::function &cmd)
+{
+if (!m_conn)
+return Error ("SyncService is disconnected");
+
+const auto error = cmd ();
+if (error.Fail ())
+m_conn.reset ();
+
+return error;
+}
+
 AdbClient::SyncService::~SyncService () {}
 
 Error

Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.h?rev=274638&r1=274637&r2=274638&view=diff
==
--- lldb/trunk/source/Plugins/Platform

Re: [Lldb-commits] [PATCH] D22029: Fix ADB client disconnect issues

2016-07-06 Thread Oleksiy Vyalov via lldb-commits
ovyalov closed this revision.
ovyalov added a comment.

Files:

  /lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
  /lldb/trunk/source/Plugins/Platform/Android/AdbClient.h
  /lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
  /lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h

Users:

  ovyalov (Author)

http://reviews.llvm.org/rL274638


http://reviews.llvm.org/D22029



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


Re: [Lldb-commits] [PATCH] D21751: Implement GetMemoryRegions() for Linux and Mac OSX core files.

2016-07-06 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/D21751



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


[Lldb-commits] [PATCH] D22060: [expression evaluation] Prevent invalid function declarations ending up in clang AST

2016-07-06 Thread Luke Drummond via lldb-commits
ldrumm created this revision.
ldrumm added reviewers: spyffe, jingham.
ldrumm added a subscriber: lldb-commits.

Due to the way the lldb override for 
`clang::ExternalASTSource::FindExternalGlobalVisibleDeclsByName` callback was 
searching for functions, it was possible for invalid declarations to end up in 
the list of function declarations passed back to the clang AST, which 
subsequently caused clang to complain about ambiguous lookups. The logic used 
to prune duplicate function declarations based on lexical distance was ignoring 
the error status returned for invalid declarations which meant that they ended 
up in the list of resolved declarations passed back to clang.

http://reviews.llvm.org/D22060

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

Index: source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===
--- source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -1430,7 +1430,14 @@
   &fdi.m_name,
   
&fdi.m_copied_type);
 }
-fdi_cache.emplace_back(fdi);
+if (fdi.m_decl_lvl == LLDB_INVALID_DECL_LEVEL)
+{
+if (log)
+log->Printf("INVALID_DECL_LEVEL for function 
declaration '%s'",
+fdi.m_name.GetCString());
+}
+else
+fdi_cache.emplace_back(fdi);
 }
 
 // Loop through the functions in our cache looking for 
matching types,


Index: source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===
--- source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -1430,7 +1430,14 @@
   &fdi.m_name,
   &fdi.m_copied_type);
 }
-fdi_cache.emplace_back(fdi);
+if (fdi.m_decl_lvl == LLDB_INVALID_DECL_LEVEL)
+{
+if (log)
+log->Printf("INVALID_DECL_LEVEL for function declaration '%s'",
+fdi.m_name.GetCString());
+}
+else
+fdi_cache.emplace_back(fdi);
 }
 
 // Loop through the functions in our cache looking for matching types,
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


Re: [Lldb-commits] [PATCH] D22060: [expression evaluation] Prevent invalid function declarations ending up in clang AST

2016-07-06 Thread Jim Ingham via lldb-commits
jingham added a comment.

Shouldn't it be the job of the subsequent filtering loop to sort this out?  The 
debugger should be able to call functions from a given frame, even if that 
function is not actually visible from the current frame.  So I don't think you 
want to reject such functions from the candidate list.  You just want to make 
sure that if there IS one visible, it should override the ones that aren't 
visible.


http://reviews.llvm.org/D22060



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


[Lldb-commits] [lldb] r274683 - Because of our lifetime rules w.r.t. ValueObjects and ClusterManagers, synthetic children caching is a tricky area:

2016-07-06 Thread Enrico Granata via lldb-commits
Author: enrico
Date: Wed Jul  6 16:24:28 2016
New Revision: 274683

URL: http://llvm.org/viewvc/llvm-project?rev=274683&view=rev
Log:
Because of our lifetime rules w.r.t. ValueObjects and ClusterManagers, 
synthetic children caching is a tricky area:
- if a synthetic child comes from the same hierarchy as its parent object, then 
it can't be cached by SharedPointer inside the synthetic provider, or it will 
cause a reference loop;
- but, if a synthetic child is made from whole cloth (e.g. from an expression, 
a memory region, ...), then it better be cached by SharedPointer, or it will be 
cleared out and cause an assert() to fail if used at a later point

For most cases of self-rooted synthetic children, we have a flag we set 
"IsSyntheticChildrenGenerated", but we were not using it to track caching. So, 
what ended up happening is each provider would set up its own cache, and if it 
got it wrong, a hard to diagnose crash would ensue

This patch fixes that by centralizing caching in ValueObjectSynthetic - if a 
provider returns a self-rooted child (as per the flag), then it gets cached 
centrally by the ValueObject itself
This cache is used only for lifetime management and not later retrieval of 
child values - a different cache handles that (because we might have a mix of 
self-rooted and properly nested child values for the same parent, we can't 
trivially use this lifetime cache for retrieval)

Fixes rdar://26480007


Added:
lldb/trunk/include/lldb/Core/ThreadSafeSTLVector.h
Modified:
lldb/trunk/include/lldb/API/SBValue.h
lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h
lldb/trunk/include/lldb/Utility/SharedCluster.h
lldb/trunk/lldb.xcodeproj/project.pbxproj
lldb/trunk/scripts/interface/SBValue.i
lldb/trunk/source/API/SBValue.cpp
lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
lldb/trunk/source/Plugins/Language/ObjC/NSArray.cpp
lldb/trunk/source/Plugins/Language/ObjC/NSError.cpp
lldb/trunk/source/Plugins/Language/ObjC/NSException.cpp

Modified: lldb/trunk/include/lldb/API/SBValue.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValue.h?rev=274683&r1=274682&r2=274683&view=diff
==
--- lldb/trunk/include/lldb/API/SBValue.h (original)
+++ lldb/trunk/include/lldb/API/SBValue.h Wed Jul  6 16:24:28 2016
@@ -125,6 +125,12 @@ public:
 
 bool
 IsSynthetic ();
+
+bool
+IsSyntheticChildrenGenerated ();
+
+void
+SetSyntheticChildrenGenerated (bool);
 
 const char *
 GetLocation ();

Added: lldb/trunk/include/lldb/Core/ThreadSafeSTLVector.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ThreadSafeSTLVector.h?rev=274683&view=auto
==
--- lldb/trunk/include/lldb/Core/ThreadSafeSTLVector.h (added)
+++ lldb/trunk/include/lldb/Core/ThreadSafeSTLVector.h Wed Jul  6 16:24:28 2016
@@ -0,0 +1,99 @@
+//===-- ThreadSafeSTLVector.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_ThreadSafeSTLVector_h_
+#define liblldb_ThreadSafeSTLVector_h_
+
+// C Includes
+// C++ Includes
+#include 
+#include 
+
+// Other libraries and framework includes
+// Project includes
+#include "lldb/lldb-defines.h"
+
+namespace lldb_private {
+
+template 
+class ThreadSafeSTLVector
+{
+public:
+typedef std::vector<_Object> collection;
+typedef typename collection::iterator iterator;
+typedef typename collection::const_iterator const_iterator;
+//--
+// Constructors and Destructors
+//--
+ThreadSafeSTLVector() : m_collection(), m_mutex() {}
+
+~ThreadSafeSTLVector() = default;
+
+bool
+IsEmpty() const
+{
+std::lock_guard guard(m_mutex);
+return m_collection.empty();
+}
+
+void
+Clear()
+{
+std::lock_guard guard(m_mutex);
+return m_collection.clear();
+}
+
+size_t
+GetCount()
+{
+std::lock_guard guard(m_mutex);
+return m_collection.size();
+ 

Re: [Lldb-commits] [PATCH] D22052: Respect `ANDROID_SERIAL` environment variable used by ADB

2016-07-06 Thread Oleksiy Vyalov via lldb-commits
ovyalov added inline comments.


Comment at: source/Plugins/Platform/Android/AdbClient.cpp:71
@@ +70,3 @@
+{
+if (const char *android_serial = std::getenv("ANDROID_SERIAL"))
+adb.SetDeviceID(android_serial);

Could you check whether serial number coming from ANDROID_SERIAL is within 
connect_devices?


Repository:
  rL LLVM

http://reviews.llvm.org/D22052



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


[Lldb-commits] [lldb] r274697 - Fix the installation of the vector data formatters in order to restore functionality

2016-07-06 Thread Enrico Granata via lldb-commits
Author: enrico
Date: Wed Jul  6 17:35:34 2016
New Revision: 274697

URL: http://llvm.org/viewvc/llvm-project?rev=274697&view=rev
Log:
Fix the installation of the vector data formatters in order to restore 
functionality


Modified:
lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp?rev=274697&r1=274696&r2=274697&view=diff
==
--- lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
(original)
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp Wed Jul  
6 17:35:34 2016
@@ -523,6 +523,7 @@ LoadLibCxxFormatters (lldb::TypeCategory
 SyntheticChildren::Flags stl_synth_flags;
 
stl_synth_flags.SetCascades(true).SetSkipPointers(false).SetSkipReferences(false);
 
+AddCXXSynthetic(cpp_category_sp, 
lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEndCreator, "libc++ 
std::vector synthetic children", 
ConstString("^std::__(ndk)?1::vector 
>$"), stl_synth_flags, true);
 AddCXXSynthetic(cpp_category_sp, 
lldb_private::formatters::LibcxxStdVectorSyntheticFrontEndCreator, "libc++ 
std::vector synthetic children", ConstString("^std::__(ndk)?1::vector<.+>(( 
)?&)?$"), stl_synth_flags, true);
 AddCXXSynthetic(cpp_category_sp, 
lldb_private::formatters::LibcxxStdListSyntheticFrontEndCreator, "libc++ 
std::list synthetic children", ConstString("^std::__(ndk)?1::list<.+>(( 
)?&)?$"), stl_synth_flags, true);
 AddCXXSynthetic(cpp_category_sp, 
lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator, "libc++ 
std::map synthetic children", ConstString("^std::__(ndk)?1::map<.+> >(( 
)?&)?$"), stl_synth_flags, true);
@@ -543,14 +544,11 @@ LoadLibCxxFormatters (lldb::TypeCategory
 AddCXXSynthetic(cpp_category_sp, 
lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEndCreator, "weak_ptr 
synthetic children", ConstString("^(std::__(ndk)?1::)weak_ptr<.+>(( )?&)?$"), 
stl_synth_flags, true);
 
 
stl_summary_flags.SetDontShowChildren(false);stl_summary_flags.SetSkipPointers(false);
-AddCXXSynthetic(cpp_category_sp, 
lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEndCreator, "libc++ 
std::vector synthetic children", 
ConstString("^std::__(ndk)?1::vector 
>$"), stl_synth_flags);
-
+AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ 
std::vector summary provider", ConstString("std::__(ndk)?1::vector >"), stl_summary_flags, true);
 AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::vector 
summary provider", ConstString("^std::__(ndk)?1::vector<.+>(( )?&)?$"), 
stl_summary_flags, true);
 AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::list 
summary provider", ConstString("^std::__(ndk)?1::list<.+>(( )?&)?$"), 
stl_summary_flags, true);
 AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::map 
summary provider", ConstString("^std::__(ndk)?1::map<.+>(( )?&)?$"), 
stl_summary_flags, true);
 AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::deque 
summary provider", ConstString("^std::__(ndk)?1::deque<.+>(( )?&)?$"), 
stl_summary_flags, true);
-AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ 
std::vector summary provider", 
ConstString("std::__(ndk)?1::vector >"), 
stl_summary_flags);
-AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ 
std::vector summary provider", ConstString("std::__(ndk)?1::vector >"), stl_summary_flags);
 AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::set 
summary provider", ConstString("^std::__(ndk)?1::set<.+>(( )?&)?$"), 
stl_summary_flags, true);
 AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::multiset 
summary provider", ConstString("^std::__(ndk)?1::multiset<.+>(( )?&)?$"), 
stl_summary_flags, true);
 AddCXXSummary(cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::multimap 
summary provider", ConstString("^std::__(ndk)?1::multimap<.+>(( )?&)?$"), 
stl_summary_flags, true);


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


[Lldb-commits] [lldb] r274700 - Enhance FuncUnwinders::GetUnwindPlanAtNonCallSite to detect when we

2016-07-06 Thread Jason Molenda via lldb-commits
Author: jmolenda
Date: Wed Jul  6 18:06:19 2016
New Revision: 274700

URL: http://llvm.org/viewvc/llvm-project?rev=274700&view=rev
Log:
Enhance FuncUnwinders::GetUnwindPlanAtNonCallSite to detect when we
may be in a function that is non-ABI conformant, and the eh_frame
instructions correctly describe how to unwind out of this function,
but the assembly parsing / arch default unwind plans would be 
incorrect.

This is to address a problem that Ravitheja Addepally reported in
http://reviews.llvm.org/D21221 - I wanted to try handling the problem
with this approach which I think may be more generally helpful, 
Ravitheja tested it and said it solves the problem on Linux/FreeBSD.
Ravi has a test case in http://reviews.llvm.org/D21221 that will
be committed separately.

Thanks for all the help on this one, Ravi.

Modified:
lldb/trunk/include/lldb/Symbol/FuncUnwinders.h
lldb/trunk/source/Symbol/FuncUnwinders.cpp

Modified: lldb/trunk/include/lldb/Symbol/FuncUnwinders.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/FuncUnwinders.h?rev=274700&r1=274699&r2=274700&view=diff
==
--- lldb/trunk/include/lldb/Symbol/FuncUnwinders.h (original)
+++ lldb/trunk/include/lldb/Symbol/FuncUnwinders.h Wed Jul  6 18:06:19 2016
@@ -116,6 +116,14 @@ private:
 lldb::UnwindAssemblySP
 GetUnwindAssemblyProfiler (Target& target);
 
+// Do a simplistic comparison for the register restore rule for getting 
+// the caller's pc value on two UnwindPlans -- returns LazyBoolYes if
+// they have the same unwind rule for the pc, LazyBoolNo if they do not
+// have the same unwind rule for the pc, and LazyBoolCalculate if it was
+// unable to determine this for some reason.
+lldb_private::LazyBool 
+CompareUnwindPlansForIdenticalInitialPCLocation (Thread& thread, const 
lldb::UnwindPlanSP &a, const lldb::UnwindPlanSP &b);
+
 UnwindTable& m_unwind_table;
 AddressRange m_range;
 

Modified: lldb/trunk/source/Symbol/FuncUnwinders.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/FuncUnwinders.cpp?rev=274700&r1=274699&r2=274700&view=diff
==
--- lldb/trunk/source/Symbol/FuncUnwinders.cpp (original)
+++ lldb/trunk/source/Symbol/FuncUnwinders.cpp Wed Jul  6 18:06:19 2016
@@ -22,6 +22,7 @@
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/UnwindAssembly.h"
+#include "lldb/Utility/RegisterNumber.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -228,16 +229,81 @@ FuncUnwinders::GetAssemblyUnwindPlan (Ta
 return m_unwind_plan_assembly_sp;
 }
 
+// This method compares the pc unwind rule in the first row of two UnwindPlans.
+// If they have the same way of getting the pc value (e.g. "CFA - 8" + "CFA is 
sp"), 
+// then it will return LazyBoolTrue.
+LazyBool
+FuncUnwinders::CompareUnwindPlansForIdenticalInitialPCLocation (Thread& 
thread, const UnwindPlanSP &a, const UnwindPlanSP &b)
+{
+LazyBool plans_are_identical = eLazyBoolCalculate;
+
+RegisterNumber pc_reg (thread, eRegisterKindGeneric, 
LLDB_REGNUM_GENERIC_PC);
+uint32_t pc_reg_lldb_regnum = pc_reg.GetAsKind (eRegisterKindLLDB);
+
+if (a.get() && b.get())
+{
+UnwindPlan::RowSP a_first_row = a->GetRowAtIndex (0);
+UnwindPlan::RowSP b_first_row = b->GetRowAtIndex (0);
+
+if (a_first_row.get() && b_first_row.get())
+{
+UnwindPlan::Row::RegisterLocation a_pc_regloc;
+UnwindPlan::Row::RegisterLocation b_pc_regloc;
+
+a_first_row->GetRegisterInfo (pc_reg_lldb_regnum, a_pc_regloc);
+b_first_row->GetRegisterInfo (pc_reg_lldb_regnum, b_pc_regloc);
+
+plans_are_identical = eLazyBoolYes;
+
+if (a_first_row->GetCFAValue() != b_first_row->GetCFAValue())
+{
+plans_are_identical = eLazyBoolNo;
+}
+if (a_pc_regloc != b_pc_regloc)
+{
+plans_are_identical = eLazyBoolNo;
+}
+}
+}
+return plans_are_identical;
+}
 
 UnwindPlanSP
 FuncUnwinders::GetUnwindPlanAtNonCallSite (Target& target, Thread& thread, int 
current_offset)
 {
-UnwindPlanSP non_call_site_unwindplan_sp = GetEHFrameAugmentedUnwindPlan 
(target, thread, current_offset);
-if (non_call_site_unwindplan_sp.get() == nullptr)
+UnwindPlanSP eh_frame_sp = GetEHFrameUnwindPlan (target, current_offset);
+UnwindPlanSP arch_default_at_entry_sp = 
GetUnwindPlanArchitectureDefaultAtFunctionEntry (thread);
+UnwindPlanSP arch_default_sp = GetUnwindPlanArchitectureDefault (thread);
+UnwindPlanSP assembly_sp = GetAssemblyUnwindPlan (target, thread, 
current_offset);
+
+// This point of this code is to detect when a function is using a 
non-standard ABI, and the eh_frame
+// correctly describes that alternate ABI.  This

Re: [Lldb-commits] [PATCH] D21221: Fix for PrintStackTraces

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

Ravitheja and I had some discussions over email about a possible alternate 
approach to this issue - I've committed that approach as r274700 after testing 
help from Ravi.  This patchset is tracking the very nice test case that was 
written to replicate the problem, thanks for doing that Ravitheja!


http://reviews.llvm.org/D21221



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


[Lldb-commits] [lldb] r274701 - LLDB reads incorrect memory ranges when displaying bitfields when reading bits from file memory.

2016-07-06 Thread Greg Clayton via lldb-commits
Author: gclayton
Date: Wed Jul  6 18:11:13 2016
New Revision: 274701

URL: http://llvm.org/viewvc/llvm-project?rev=274701&view=rev
Log:
LLDB reads incorrect memory ranges when displaying bitfields when reading bits 
from file memory. 

Bitfields were not correctly describing their offsets within the integer that 
they are contained within. If we had a bitfield like:

struct MyStruct {
  uint32_t a:8;
  uint32_t b:8;
};

ClangASTContext::GetChildCompilerTypeAtIndex would say that child a and b had 
the following values in their respective ValueObjectChild objects:

name byte-size bit-size bit-offset byte-offset-from-parent
 =  == ===
"a"  4 80  0
"b"  4 80  1

So if we had a "MyStruct" at address 0x1000, we would end up reading 4 bytes 
from 0x1000 for "a", and 4 bytes from 0x1001 for "b". The fix for this is to 
fix the "child_byte_offset" and "child_bitfield_bit_offset" values returned by 
ClangASTContext::GetChildCompilerTypeAtIndex() so that now the table looks like:

name byte-size bit-size bit-offset byte-offset-from-parent
 =  == ===
"a"  4 80  0
"b"  4 88  0

Then we don't run into a problem when reading data from a file's section info 
using "target variable" before running. It will also stop us from not being 
able to display a bitfield values if the bitfield is in the last bit of memory 
before an unmapped region. (Like if address 0x1004 was unmapped and unreadable 
in the example above, if we tried to read 4 bytes from 0x1001, the memory read 
would fail and we wouldn't be able to display "b").

 


Modified:
lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=274701&r1=274700&r2=274701&view=diff
==
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Wed Jul  6 18:11:13 2016
@@ -6274,12 +6274,20 @@ ClangASTContext::GetChildCompilerTypeAtI
 CompilerType field_clang_type (getASTContext(), 
field->getType());
 assert(field_idx < record_layout.getFieldCount());
 child_byte_size = field_clang_type.GetByteSize(exe_ctx 
? exe_ctx->GetBestExecutionContextScope() : NULL);
+const uint32_t child_bit_size = child_byte_size * 8;
 
 // Figure out the field offset within the current 
struct/union/class type
 bit_offset = record_layout.getFieldOffset (field_idx);
-child_byte_offset = bit_offset / 8;
 if (ClangASTContext::FieldIsBitfield (getASTContext(), 
*field, child_bitfield_bit_size))
-child_bitfield_bit_offset = bit_offset % 8;
+{
+child_bitfield_bit_offset = bit_offset % 
child_bit_size;
+const uint32_t child_bit_offset = bit_offset - 
child_bitfield_bit_offset;
+child_byte_offset =  child_bit_offset / 8;
+}
+else
+{
+child_byte_offset = bit_offset / 8;
+}
 
 return field_clang_type;
 }


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


[Lldb-commits] [lldb] r274703 - "frame variable" and "target variable" shouldn't allow us to get the address of bitfields.

2016-07-06 Thread Greg Clayton via lldb-commits
Author: gclayton
Date: Wed Jul  6 18:16:24 2016
New Revision: 274703

URL: http://llvm.org/viewvc/llvm-project?rev=274703&view=rev
Log:
"frame variable" and "target variable" shouldn't allow us to get the address of 
bitfields.

"frame variable" and "target variable" are trying to emulate the expression 
parser when doing things like:

(lldb) frame variable &my_struct.my_bitfield

And since the expression parser doesn't allow this, we shouldn't allow "frame 
variable" or "target variable" to succeed.

 


Modified:
lldb/trunk/source/Core/ValueObject.cpp

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=274703&r1=274702&r2=274703&view=diff
==
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Wed Jul  6 18:16:24 2016
@@ -834,20 +834,20 @@ ValueObject::CreateChildAtIndex (size_t
 
 ExecutionContext exe_ctx (GetExecutionContextRef());
 
-child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex 
(&exe_ctx,
-  idx,
-  
transparent_pointers,
-  
omit_empty_base_classes,
-  
ignore_array_bounds,
-  
child_name_str,
-  
child_byte_size,
-  
child_byte_offset,
-  
child_bitfield_bit_size,
-  
child_bitfield_bit_offset,
-  
child_is_base_class,
-  
child_is_deref_of_parent,
-  this,
-  
language_flags);
+child_compiler_type = 
GetCompilerType().GetChildCompilerTypeAtIndex(&exe_ctx,
+idx,
+
transparent_pointers,
+
omit_empty_base_classes,
+
ignore_array_bounds,
+
child_name_str,
+
child_byte_size,
+
child_byte_offset,
+
child_bitfield_bit_size,
+
child_bitfield_bit_offset,
+
child_is_base_class,
+
child_is_deref_of_parent,
+this,
+
language_flags);
 if (child_compiler_type)
 {
 if (synthetic_index)
@@ -1789,6 +1789,10 @@ ValueObject::DumpPrintableRepresentation
 addr_t
 ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType 
*address_type)
 {
+// Can't take address of a bitfield
+if (IsBitfield())
+return LLDB_INVALID_ADDRESS;
+
 if (!UpdateValueIfNeeded(false))
 return LLDB_INVALID_ADDRESS;
 


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


[Lldb-commits] [lldb] r274718 - Add support to debugserver for some new ways to interact with dyld

2016-07-06 Thread Jason Molenda via lldb-commits
Author: jmolenda
Date: Wed Jul  6 20:09:23 2016
New Revision: 274718

URL: http://llvm.org/viewvc/llvm-project?rev=274718&view=rev
Log:
Add support to debugserver for some new ways to interact with dyld
to find the solibs loaded in a process.  Support two new ways of
sending the jGetLoadedDynamicLibrariesInfos packet to debugserver
and add a new jGetSharedCacheInfo packet.  Update the documentation
for these packets as well.  The changes to lldb to use these will
be a separate commit.

 


Modified:
lldb/trunk/docs/lldb-gdb-remote.txt
lldb/trunk/tools/debugserver/source/DNB.cpp
lldb/trunk/tools/debugserver/source/DNB.h
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm
lldb/trunk/tools/debugserver/source/RNBRemote.cpp
lldb/trunk/tools/debugserver/source/RNBRemote.h

Modified: lldb/trunk/docs/lldb-gdb-remote.txt
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/docs/lldb-gdb-remote.txt?rev=274718&r1=274717&r2=274718&view=diff
==
--- lldb/trunk/docs/lldb-gdb-remote.txt (original)
+++ lldb/trunk/docs/lldb-gdb-remote.txt Wed Jul  6 20:09:23 2016
@@ -1508,6 +1508,28 @@ for this region.
 //  This packet asks the remote debug stub to send the details about libraries
 //  being added/removed from the process as a performance optimization.
 //
+//  There are three ways this packet can be used.  All three return a 
dictionary of
+//  binary images formatted the same way.
+//
+//  On MacOS X 10.11, iOS 9, tvOS 9, watchOS 2 and earlier, the packet is used 
like
+//   
jGetLoadedDynamicLibrariesInfos:{"image_count":1,"image_list_address":140734800075128}
+//  where the image_list_address is an array of {void* load_addr, void* 
mod_date, void* pathname}
+//  in the inferior process memory (and image_count is the number of elements 
in this array).
+//  lldb is using information from the dyld_all_image_infos structure to make 
these requests to
+//  debugserver.  This use is not supported on macOS 10.12, iOS 10, tvOS 10, 
watchOS 3 or newer.
+//
+//  On macOS 10.12, iOS 10, tvOS 10, watchOS 3 and newer, there are two calls. 
 One requests information
+//  on all shared libraries:
+//   jGetLoadedDynamicLibrariesInfos:{"fetch_all_solibs":true}
+//  And the second requests information about a list of shared libraries, 
given their load addresses:
+//   
jGetLoadedDynamicLibrariesInfos:{"solib_addresses":[8382824135,3258302053,830202858503]}
+//
+//  The second call is both a performance optimization (instead of having lldb 
read the mach-o header/load commands
+//  out of memory with generic read packets) but also adds additional 
information in the form of the 
+//  filename of the shared libraries (which is not available in the mach-o 
header/load commands.)
+//  
+//  An example using the Mac OS X 10.11 style call:
+//
 //  LLDB SENDS: 
jGetLoadedDynamicLibrariesInfos:{"image_count":1,"image_list_address":140734800075128}
 //  STUB REPLIES: 
${"images":[{"load_address":4294967296,"mod_date":0,"pathname":"/tmp/a.out","uuid":"02CF262C-ED6F-3965-9E14-63538B465CFF","mach_header":{"magic":4277009103,"cputype":16777223,"cpusubtype":18446744071562067971,"filetype":2},"segments":{"name":"__PAGEZERO","vmaddr":0,"vmsize":4294967296,"fileoff":0,"filesize":0,"maxprot":0},{"name":"__TEXT","vmaddr":4294967296,"vmsize":4096,"fileoff":0,"filesize":4096,"maxprot":7},{"name":"__LINKEDIT","vmaddr":4294971392,"vmsize":4096,"fileoff":4096,"filesize":152,"maxprot":7}}]}#00
 //
@@ -1562,26 +1584,12 @@ for this region.
 // quite a bit to provide all the information that the DynamicLoaderMacOSX
 // would need to work correctly on this platform.
 //
-// On Mac OS X / iOS, when libraries are added or removed, a stub
-// function is called which lldb puts a breakpoint on.  The arguments
-// to the stub function include the number of libraries being added
-// or removed and the address where the list of libraries can be
-// found.  The information at this address is the load address of the
-// library, the filename, and the mod date of the library if available.
-// DynamicLoaderMacOSX then parses the load commands in the Mach-O header
-// at the load address before it can decide what action to take.
-//
-// The purpose of this packet is to eliminate all of the memory reads needed
-// to read the Mach-O header and load commands for these libraries.
-// On a typical GUI app, there can be a couple hundred shared libraries 
-// which results in megabytes of read packets.  That same information can
-// be returned in a couple hundred kilobytes in JSON format from the remote
-// debugserver.
-//
-//
 // PRIORITY TO IMPLEMENT
-//  Low.  If this packet is absent, lldb will read the Mach-O headers/load
-//  commands out of memory.
+//  On Mac OS X 10.11, iOS 9, tvOS 9, watchOS 2 and older: Low.  If this 
packet is absent, 
+//  lldb will read the Mach-O headers/load commands ou

[Lldb-commits] [PATCH] D22081: Use shell cat command as a workaround if ADB stat cannot lookup a file

2016-07-06 Thread Oleksiy Vyalov via lldb-commits
ovyalov created this revision.
ovyalov added reviewers: tberghammer, labath.
ovyalov added a subscriber: lldb-commits.
Herald added subscribers: danalbert, tberghammer.

adbd may fail to access a file due security constraints - in such case 
sync:stat command returns file's mode as 0. If it's the case - use shell cat a 
workaround then.

http://reviews.llvm.org/D22081

Files:
  source/Plugins/Platform/Android/AdbClient.cpp
  source/Plugins/Platform/Android/AdbClient.h
  source/Plugins/Platform/Android/PlatformAndroid.cpp

Index: source/Plugins/Platform/Android/PlatformAndroid.cpp
===
--- source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -230,6 +230,22 @@
 if (error.Fail ())
 return error;
 
+uint32_t mode = 0, size = 0, mtime = 0;
+error = sync_service->Stat (source_spec, mode, size, mtime);
+if (error.Fail ())
+return error;
+
+if (mode == 0)
+{
+// mode == 0 can signify that adbd cannot access the file
+// due security constraints - try "cat ..." as a fallback. 
+AdbClient adb(m_device_id);
+char cmd[PATH_MAX];
+snprintf (cmd, sizeof (cmd), "cat '%s'", source_spec.GetCString (false));
+
+return adb.ShellToFile(cmd, 6 /* ms */, destination);
+}
+
 return sync_service->PullFile (source_spec, destination);
 }
 
Index: source/Plugins/Platform/Android/AdbClient.h
===
--- source/Plugins/Platform/Android/AdbClient.h
+++ source/Plugins/Platform/Android/AdbClient.h
@@ -119,6 +119,9 @@
 Error
 Shell (const char* command, uint32_t timeout_ms, std::string* output);
 
+Error
+ShellToFile (const char* command, uint32_t timeout_ms, const FileSpec &output_file_spec);
+
 std::unique_ptr
 GetSyncService (Error &error);
 
@@ -157,6 +160,9 @@
 StartSync ();
 
 Error
+internalShell (const char* command, uint32_t timeout_ms, std::vector &output_buf);
+
+Error
 ReadAllBytes (void *buffer, size_t size);
 
 std::string m_device_id;
Index: source/Plugins/Platform/Android/AdbClient.cpp
===
--- source/Plugins/Platform/Android/AdbClient.cpp
+++ source/Plugins/Platform/Android/AdbClient.cpp
@@ -378,8 +378,10 @@
 }
 
 Error
-AdbClient::Shell (const char* command, uint32_t timeout_ms, std::string* output)
+AdbClient::internalShell (const char* command, uint32_t timeout_ms, std::vector &output_buf)
 {
+output_buf.clear ();
+
 auto error = SwitchDeviceTransport ();
 if (error.Fail ())
 return Error ("Failed to switch to device transport: %s", error.AsCString ());
@@ -394,16 +396,39 @@
 if (error.Fail ())
 return error;
 
-std::vector in_buffer;
-error = ReadMessageStream (in_buffer, timeout_ms);
-if (error.Fail())
+return ReadMessageStream (output_buf, timeout_ms);
+}
+
+Error
+AdbClient::Shell (const char* command, uint32_t timeout_ms, std::string* output)
+{
+std::vector output_buffer;
+auto error = internalShell (command, timeout_ms, output_buffer);
+if (error.Fail ())
 return error;
 
 if (output)
-output->assign(in_buffer.begin(), in_buffer.end());
+output->assign(output_buffer.begin(), output_buffer.end());
 return error;
 }
 
+Error
+AdbClient::ShellToFile (const char* command, uint32_t timeout_ms, const FileSpec &output_file_spec)
+{
+std::vector output_buffer;
+auto error = internalShell (command, timeout_ms, output_buffer);
+if (error.Fail ())
+return error;
+
+const auto output_filename = output_file_spec.GetPath ();
+std::ofstream dst (output_filename, std::ios::out | std::ios::binary);
+if (!dst.is_open ())
+return Error ("Unable to open local file %s", output_filename.c_str());
+
+dst.write (&output_buffer[0], output_buffer.size ());
+return Error ();
+}
+
 std::unique_ptr
 AdbClient::GetSyncService (Error &error)
 {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] r274725 - debugserver will now report the minimum version load command

2016-07-06 Thread Jason Molenda via lldb-commits
Author: jmolenda
Date: Wed Jul  6 22:12:01 2016
New Revision: 274725

URL: http://llvm.org/viewvc/llvm-project?rev=274725&view=rev
Log:
debugserver will now report the minimum version load command
os name and version # from the mach-o binary as it scans the
header/load commands from memory and sends the details back
in the jGetLoadedDynamicLibrariesInfos response.  lldb isn't
using these fields yet but I have a suspicion I'm going to 
need them soon.

 

Modified:
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h?rev=274725&r1=274724&r2=274725&view=diff
==
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h Wed Jul  6 
22:12:01 2016
@@ -69,6 +69,8 @@ public:
 struct mach_header_64 mach_header;
 std::vector segments;
 uuid_t uuid;
+std::string min_version_os_name;
+std::string min_version_os_version;
 };
 
 struct binary_image_information

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm?rev=274725&r1=274724&r2=274725&view=diff
==
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm Wed Jul  6 
22:12:01 2016
@@ -631,6 +631,44 @@ MachProcess::GetMachOInformationFromMemo
 if (ReadMemory (load_cmds_p, sizeof (struct uuid_command), 
&uuidcmd) == sizeof (struct uuid_command))
 uuid_copy (inf.uuid, uuidcmd.uuid);
 }
+if (lc.cmd == LC_VERSION_MIN_IPHONEOS || lc.cmd == 
LC_VERSION_MIN_MACOSX 
+|| lc.cmd == LC_VERSION_MIN_WATCHOS || lc.cmd == 
LC_VERSION_MIN_TVOS)
+{
+struct version_min_command vers_cmd;
+if (ReadMemory (load_cmds_p, sizeof (struct version_min_command), 
&vers_cmd) != sizeof (struct version_min_command))
+{
+return false;
+}
+switch (lc.cmd)
+{
+case LC_VERSION_MIN_IPHONEOS:
+inf.min_version_os_name = "iphoneos";
+break;
+case LC_VERSION_MIN_MACOSX:
+inf.min_version_os_name = "macosx";
+break;
+case LC_VERSION_MIN_TVOS:
+inf.min_version_os_name = "tvos";
+break;
+case LC_VERSION_MIN_WATCHOS:
+inf.min_version_os_name = "watchos";
+break;
+default:
+return false;
+}
+uint32_t  = vers_cmd.sdk >> 16;
+uint32_t yy = (vers_cmd.sdk >> 8) & 0xffu;
+uint32_t zz = vers_cmd.sdk & 0xffu;
+inf.min_version_os_version = "";
+inf.min_version_os_version += std::to_string();
+inf.min_version_os_version += ".";
+inf.min_version_os_version += std::to_string(yy);
+if (zz != 0)
+{
+inf.min_version_os_version += ".";
+inf.min_version_os_version += std::to_string(zz);
+}
+}
 load_cmds_p += lc.cmdsize;
 }
 return true;
@@ -657,6 +695,13 @@ MachProcess::FormatDynamicLibrariesIntoJ
 uuid_unparse_upper (image_infos[i].macho_info.uuid, uuidstr);
 image_info_dict_sp->AddStringItem ("uuid", uuidstr);
 
+if (image_infos[i].macho_info.min_version_os_name.empty() == false
+&& image_infos[i].macho_info.min_version_os_version.empty() == 
false)
+{
+image_info_dict_sp->AddStringItem ("min_version_os_name", 
image_infos[i].macho_info.min_version_os_name);
+image_info_dict_sp->AddStringItem ("min_version_os_sdk", 
image_infos[i].macho_info.min_version_os_version);
+}
+
 JSONGenerator::DictionarySP mach_header_dict_sp (new 
JSONGenerator::Dictionary());
 mach_header_dict_sp->AddIntegerItem ("magic", 
image_infos[i].macho_info.mach_header.magic);
 mach_header_dict_sp->AddIntegerItem ("cputype", (uint32_t) 
image_infos[i].macho_info.mach_header.cputype);


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