[Lldb-commits] [PATCH] D44055: [lldb] Fix "requires global constructor" warning in g_range_specifiers

2018-03-03 Thread Davide Italiano via Phabricator via lldb-commits
davide accepted this revision.
davide added a comment.
This revision is now accepted and ready to land.

LGTM with Pavel's suggestion implemented.


https://reviews.llvm.org/D44055



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


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

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

Thanks for the high-level feedback! I'll split the patch and we can discuss 
further.


https://reviews.llvm.org/D43886



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


[Lldb-commits] [PATCH] D44058: [lldb] Fix "code unreachable" warning in DNBArchImplX86_64::SetRegisterValue

2018-03-03 Thread Davide Italiano via Phabricator via lldb-commits
davide added a comment.

This seems scary. We really need a test case for this.


https://reviews.llvm.org/D44058



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


[Lldb-commits] [PATCH] D44058: [lldb] Fix "code unreachable" warning in DNBArchImplX86_64::SetRegisterValue

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

In https://reviews.llvm.org/D44058#1026646, @davide wrote:

> This seems scary. We really need a test case for this.


Agreed, but I don't know this code, so I'm not able to come up with a test for 
this.


https://reviews.llvm.org/D44058



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


[Lldb-commits] [PATCH] D44072: [lldb] Retrieve currently handled Obj-C exception via __cxa_current_exception_type

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

This builds on https://reviews.llvm.org/D43884 and 
https://reviews.llvm.org/D43886 and extends LLDB support of Obj-C exceptions to 
also look for a "current exception" for a thread in the C++ exception handling 
runtime metadata (via call to `__cxa_current_exception_type`). We also 
construct an actual historical SBThread/ThreadSP that contains frames from the 
backtrace in the Obj-C exception object.

The high level goal this achieves is that when we're already crashed (because 
an unhandled exception occurred), we can still access the exception object and 
retrieve the backtrace from the throw point. In Obj-C, this is particularly 
useful because a catch+rethrow in very common and in those cases you currently 
don't have any access to the throw point backtrace.

This is WIP, as the patch is missing doc-comments, error handling, but I'm 
looking for early comments to the approach.


https://reviews.llvm.org/D44072

Files:
  include/lldb/Target/SystemRuntime.h
  packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
  packages/Python/lldbsuite/test/lang/objc/exceptions/main.m
  scripts/interface/SBThread.i
  source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
  source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
  source/Target/Thread.cpp

Index: source/Target/Thread.cpp
===
--- source/Target/Thread.cpp
+++ source/Target/Thread.cpp
@@ -2212,17 +2212,37 @@
 
 ValueObjectSP Thread::GetCurrentException() {
   StackFrameSP frame_sp(GetStackFrameAtIndex(0));
-  if (!frame_sp) return ValueObjectSP();
-
-  RecognizedStackFrameSP recognized_frame(frame_sp->GetRecognizedFrame());
-  if (!recognized_frame) return ValueObjectSP();
+  if (frame_sp) {
+RecognizedStackFrameSP recognized_frame(frame_sp->GetRecognizedFrame());
+if (recognized_frame && recognized_frame->IsThrowingObjCException()) {
+  ValueObjectSP exception_from_recognizer =
+  recognized_frame->GetObjCExceptionObject();
+  if (exception_from_recognizer) {
+return exception_from_recognizer;
+  }
+}
+  }
 
-  if (!recognized_frame->IsThrowingObjCException()) return ValueObjectSP();
+  SystemRuntime *runtime = GetProcess()->GetSystemRuntime();
+  if (runtime) {
+ValueObjectSP exception_from_runtime =
+runtime->GetExceptionObjectForThread(shared_from_this());
+if (exception_from_runtime) {
+  return exception_from_runtime;
+}
+  }
 
-  return recognized_frame->GetObjCExceptionObject();
+  return ValueObjectSP();
 }
 
 ThreadSP Thread::GetCurrentExceptionBacktrace() {
-  // TODO
-  return ThreadSP();
+  ValueObjectSP exception = GetCurrentException();
+  if (!exception)
+return ThreadSP();
+
+  SystemRuntime *runtime = GetProcess()->GetSystemRuntime();
+  if (!runtime)
+return ThreadSP();
+
+  return runtime->GetBacktraceThreadFromException(exception);
 }
Index: source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
===
--- source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
+++ source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
@@ -103,6 +103,12 @@
   void AddThreadExtendedInfoPacketHints(
   lldb_private::StructuredData::ObjectSP dict) override;
 
+  virtual lldb::ValueObjectSP
+  GetExceptionObjectForThread(lldb::ThreadSP thread_sp) override;
+
+  virtual lldb::ThreadSP
+  GetBacktraceThreadFromException(lldb::ValueObjectSP thread_sp) override;
+
   bool SafeToCallFunctionsOnThisThread(lldb::ThreadSP thread_sp) override;
 
   //--
Index: source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
+++ source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
@@ -13,6 +13,9 @@
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Section.h"
+#include "lldb/DataFormatters/FormattersHelpers.h"
+#include "lldb/Expression/DiagnosticManager.h"
+#include "lldb/Expression/FunctionCaller.h"
 #include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/SymbolContext.h"
@@ -224,6 +227,116 @@
   }
 }
 
+ValueObjectSP
+SystemRuntimeMacOSX::GetExceptionObjectForThread(ThreadSP thread_sp) {
+  ClangASTContext *clang_ast_context =
+  m_process->GetTarget().GetScratchClangASTContext();
+  CompilerType voidstar =
+  clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
+
+  DiagnosticManager diagnostics;
+  ExecutionContext exe_ctx;
+  EvaluateExpressionOptions options;
+
+  options.SetUnwindOnError(true);
+  options.SetIgnoreBreakpoints(true);
+  options.SetStopOthers(true);
+  options.SetTimeout(std::chrono::milliseconds(500));
+  options.

[Lldb-commits] [PATCH] D44055: [lldb] Fix "requires global constructor" warning in g_range_specifiers

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

BTW, to appease older versions of gcc you will need to write the initializer as 
`= {{"-"}, {"to"}, ...}` (i.e. add extra {} around the strings).


https://reviews.llvm.org/D44055



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


[Lldb-commits] [PATCH] D42955: Make Module::GetSectionList output consistent

2018-03-03 Thread Pavel Labath via Phabricator via lldb-commits
labath abandoned this revision.
labath added a comment.

I don't think this approach is good while ObjectFileMachO is messing with 
sections of other object files. At this point I think, I've actually learned 
enough about MachO to understand what the code is doing there, so I'm going to 
see if I can make it do what I want.


https://reviews.llvm.org/D42955



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


[Lldb-commits] [lldb] r326667 - ObjectFileMachO: use early return to remove one nesting level from CreateSections()

2018-03-03 Thread Pavel Labath via lldb-commits
Author: labath
Date: Sat Mar  3 14:07:47 2018
New Revision: 326667

URL: http://llvm.org/viewvc/llvm-project?rev=326667&view=rev
Log:
ObjectFileMachO: use early return to remove one nesting level from 
CreateSections()

NFCI

Modified:
lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=326667&r1=32&r2=326667&view=diff
==
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Sat Mar  3 
14:07:47 2018
@@ -1350,575 +1350,556 @@ bool ObjectFileMachO::IsStripped() {
 }
 
 void ObjectFileMachO::CreateSections(SectionList &unified_section_list) {
-  if (!m_sections_ap.get()) {
-m_sections_ap.reset(new SectionList());
+  if (m_sections_ap)
+return;
 
-const bool is_dsym = (m_header.filetype == MH_DSYM);
-lldb::user_id_t segID = 0;
-lldb::user_id_t sectID = 0;
-lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-uint32_t i;
-const bool is_core = GetType() == eTypeCoreFile;
-// bool dump_sections = false;
-ModuleSP module_sp(GetModule());
-// First look up any LC_ENCRYPTION_INFO load commands
-typedef RangeArray EncryptedFileRanges;
-EncryptedFileRanges encrypted_file_ranges;
-encryption_info_command encryption_cmd;
-for (i = 0; i < m_header.ncmds; ++i) {
-  const lldb::offset_t load_cmd_offset = offset;
-  if (m_data.GetU32(&offset, &encryption_cmd, 2) == NULL)
-break;
-
-  // LC_ENCRYPTION_INFO and LC_ENCRYPTION_INFO_64 have the same sizes for
-  // the 3 fields we care about, so treat them the same.
-  if (encryption_cmd.cmd == LC_ENCRYPTION_INFO ||
-  encryption_cmd.cmd == LC_ENCRYPTION_INFO_64) {
-if (m_data.GetU32(&offset, &encryption_cmd.cryptoff, 3)) {
-  if (encryption_cmd.cryptid != 0) {
-EncryptedFileRanges::Entry entry;
-entry.SetRangeBase(encryption_cmd.cryptoff);
-entry.SetByteSize(encryption_cmd.cryptsize);
-encrypted_file_ranges.Append(entry);
-  }
+  m_sections_ap.reset(new SectionList());
+
+  const bool is_dsym = (m_header.filetype == MH_DSYM);
+  lldb::user_id_t segID = 0;
+  lldb::user_id_t sectID = 0;
+  lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+  uint32_t i;
+  const bool is_core = GetType() == eTypeCoreFile;
+  // bool dump_sections = false;
+  ModuleSP module_sp(GetModule());
+  // First look up any LC_ENCRYPTION_INFO load commands
+  typedef RangeArray EncryptedFileRanges;
+  EncryptedFileRanges encrypted_file_ranges;
+  encryption_info_command encryption_cmd;
+  for (i = 0; i < m_header.ncmds; ++i) {
+const lldb::offset_t load_cmd_offset = offset;
+if (m_data.GetU32(&offset, &encryption_cmd, 2) == NULL)
+  break;
+
+// LC_ENCRYPTION_INFO and LC_ENCRYPTION_INFO_64 have the same sizes for
+// the 3 fields we care about, so treat them the same.
+if (encryption_cmd.cmd == LC_ENCRYPTION_INFO ||
+encryption_cmd.cmd == LC_ENCRYPTION_INFO_64) {
+  if (m_data.GetU32(&offset, &encryption_cmd.cryptoff, 3)) {
+if (encryption_cmd.cryptid != 0) {
+  EncryptedFileRanges::Entry entry;
+  entry.SetRangeBase(encryption_cmd.cryptoff);
+  entry.SetByteSize(encryption_cmd.cryptsize);
+  encrypted_file_ranges.Append(entry);
 }
   }
-  offset = load_cmd_offset + encryption_cmd.cmdsize;
 }
+offset = load_cmd_offset + encryption_cmd.cmdsize;
+  }
 
-bool section_file_addresses_changed = false;
+  bool section_file_addresses_changed = false;
 
-offset = MachHeaderSizeFromMagic(m_header.magic);
+  offset = MachHeaderSizeFromMagic(m_header.magic);
 
-struct segment_command_64 load_cmd;
-for (i = 0; i < m_header.ncmds; ++i) {
-  const lldb::offset_t load_cmd_offset = offset;
-  if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
-break;
-
-  if (load_cmd.cmd == LC_SEGMENT || load_cmd.cmd == LC_SEGMENT_64) {
-if (m_data.GetU8(&offset, (uint8_t *)load_cmd.segname, 16)) {
-  bool add_section = true;
-  bool add_to_unified = true;
-  ConstString const_segname(load_cmd.segname,
-std::min(strlen(load_cmd.segname),
- 
sizeof(load_cmd.segname)));
-
-  SectionSP unified_section_sp(
-  unified_section_list.FindSectionByName(const_segname));
-  if (is_dsym && unified_section_sp) {
-if (const_segname == GetSegmentNameLINKEDIT()) {
-  // We need to keep the __LINKEDIT segment private to this object
-  // file only
-  add_to_unified = fal

[Lldb-commits] [PATCH] D44073: [lldb] Refactor ObjC/NSException.cpp (cleanup, avoid code duplication). NFC.

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

- Refactor reading of NSException fields into ExtractFields method to avoid 
code duplication.
- Remove "m_child_ptr" field, as it's not used anywhere.
- Clang-format.


https://reviews.llvm.org/D44073

Files:
  source/Plugins/Language/ObjC/NSException.cpp

Index: source/Plugins/Language/ObjC/NSException.cpp
===
--- source/Plugins/Language/ObjC/NSException.cpp
+++ source/Plugins/Language/ObjC/NSException.cpp
@@ -33,52 +33,70 @@
 using namespace lldb_private;
 using namespace lldb_private::formatters;
 
-bool lldb_private::formatters::NSException_SummaryProvider(
-ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+static bool ExtractFields(ValueObject &valobj, ValueObjectSP *name_sp,
+  ValueObjectSP *reason_sp,
+  ValueObjectSP *userinfo_sp) {
   ProcessSP process_sp(valobj.GetProcessSP());
   if (!process_sp)
 return false;
 
-  lldb::addr_t ptr_value = LLDB_INVALID_ADDRESS;
+  lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
 
   CompilerType valobj_type(valobj.GetCompilerType());
   Flags type_flags(valobj_type.GetTypeInfo());
   if (type_flags.AllClear(eTypeHasValue)) {
 if (valobj.IsBaseClass() && valobj.GetParent())
-  ptr_value = valobj.GetParent()->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
-  } else
-ptr_value = valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
+  ptr = valobj.GetParent()->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
+  } else {
+ptr = valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
+  }
 
-  if (ptr_value == LLDB_INVALID_ADDRESS)
+  if (ptr == LLDB_INVALID_ADDRESS)
 return false;
   size_t ptr_size = process_sp->GetAddressByteSize();
-  lldb::addr_t name_location = ptr_value + 1 * ptr_size;
-  lldb::addr_t reason_location = ptr_value + 2 * ptr_size;
 
   Status error;
-  lldb::addr_t name = process_sp->ReadPointerFromMemory(name_location, error);
+  auto name = process_sp->ReadPointerFromMemory(ptr + 1 * ptr_size, error);
   if (error.Fail() || name == LLDB_INVALID_ADDRESS)
 return false;
-
-  lldb::addr_t reason =
-  process_sp->ReadPointerFromMemory(reason_location, error);
+  auto reason = process_sp->ReadPointerFromMemory(ptr + 2 * ptr_size, error);
   if (error.Fail() || reason == LLDB_INVALID_ADDRESS)
 return false;
+  auto userinfo = process_sp->ReadPointerFromMemory(ptr + 3 * ptr_size, error);
+  if (error.Fail() || userinfo == LLDB_INVALID_ADDRESS)
+return false;
 
   InferiorSizedWord name_isw(name, *process_sp);
   InferiorSizedWord reason_isw(reason, *process_sp);
+  InferiorSizedWord userinfo_isw(userinfo, *process_sp);
 
   CompilerType voidstar = process_sp->GetTarget()
   .GetScratchClangASTContext()
   ->GetBasicType(lldb::eBasicTypeVoid)
   .GetPointerType();
 
-  ValueObjectSP name_sp = ValueObject::CreateValueObjectFromData(
-  "name_str", name_isw.GetAsData(process_sp->GetByteOrder()),
-  valobj.GetExecutionContextRef(), voidstar);
-  ValueObjectSP reason_sp = ValueObject::CreateValueObjectFromData(
-  "reason_str", reason_isw.GetAsData(process_sp->GetByteOrder()),
-  valobj.GetExecutionContextRef(), voidstar);
+  if (name_sp)
+*name_sp = ValueObject::CreateValueObjectFromData(
+"name", name_isw.GetAsData(process_sp->GetByteOrder()),
+valobj.GetExecutionContextRef(), voidstar);
+  if (reason_sp)
+*reason_sp = ValueObject::CreateValueObjectFromData(
+"reason", reason_isw.GetAsData(process_sp->GetByteOrder()),
+valobj.GetExecutionContextRef(), voidstar);
+  if (userinfo_sp)
+*userinfo_sp = ValueObject::CreateValueObjectFromData(
+"userInfo", userinfo_isw.GetAsData(process_sp->GetByteOrder()),
+valobj.GetExecutionContextRef(), voidstar);
+
+  return true;
+}
+
+bool lldb_private::formatters::NSException_SummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  lldb::ValueObjectSP name_sp;
+  lldb::ValueObjectSP reason_sp;
+  if (!ExtractFields(valobj, &name_sp, &reason_sp, nullptr))
+return false;
 
   if (!name_sp || !reason_sp)
 return false;
@@ -101,63 +119,24 @@
   : SyntheticChildrenFrontEnd(*valobj_sp) {}
 
   ~NSExceptionSyntheticFrontEnd() override = default;
-  // no need to delete m_child_ptr - it's kept alive by the cluster manager on
-  // our behalf
 
   size_t CalculateNumChildren() override {
-if (m_child_ptr)
-  return 1;
-if (m_child_sp)
-  return 1;
-return 0;
+return 1;
   }
 
   lldb::ValueObjectSP GetChildAtIndex(size_t idx) override {
-if (idx != 0)
-  return lldb::ValueObjectSP();
-
-if (m_child_ptr)
-  return m_child_ptr->GetSP();
-return m_child_sp;
+switch (idx) {
+  case 0: return m_userinfo_sp;
+}
+return 

[Lldb-commits] [PATCH] D43884: [lldb] Extract more fields from NSException values

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

The NFC refactoring part of this is at https://reviews.llvm.org/D44073.


https://reviews.llvm.org/D43884



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


[Lldb-commits] [PATCH] D44074: ObjectFileMachO: split CreateSections mega-function into more manageable chunks

2018-03-03 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: clayborg, davide.

In an effort to understand the function's operation, I've split it into logical
pieces. Parsing of a single segment is moved to a separate function (and the
parsing state that is carried from one segment to another is explicitly
captured in the SegmentParsingContext object). I've also extracted some pieces
of code which were already standalone (validation of the segment load command,
determining the section type, determining segment permissions) into
separate functions.

Parsing of a single section within the segment should probably also be a
separate function, but I've left that for a separate patch.

This patch is intended to be NFC.


https://reviews.llvm.org/D44074

Files:
  source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h

Index: source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
===
--- source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
+++ source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
@@ -185,6 +185,29 @@
 
   size_t ParseSymtab();
 
+  typedef lldb_private::RangeArray EncryptedFileRanges;
+  EncryptedFileRanges GetEncryptedFileRanges();
+
+  struct SegmentParsingContext {
+const EncryptedFileRanges EncryptedRanges;
+lldb_private::SectionList &UnifiedList;
+uint32_t NextSegmentIdx = 0;
+uint32_t NextSectionIdx = 0;
+bool FileAddressesChanged = false;
+
+SegmentParsingContext(EncryptedFileRanges EncryptedRanges,
+  lldb_private::SectionList &UnifiedList)
+: EncryptedRanges(std::move(EncryptedRanges)),
+  UnifiedList(UnifiedList) {}
+  };
+  void ProcessDysymtabCommand(const llvm::MachO::load_command &load_cmd,
+  lldb::offset_t offset);
+  void ProcessSegmentCommand(const llvm::MachO::load_command &load_cmd,
+ lldb::offset_t offset, uint32_t cmd_idx,
+ SegmentParsingContext &context);
+  void SanitizeSegmentCommand(llvm::MachO::segment_command_64 &seg_cmd,
+  uint32_t cmd_idx);
+
   llvm::MachO::mach_header m_header;
   static const lldb_private::ConstString &GetSegmentNameTEXT();
   static const lldb_private::ConstString &GetSegmentNameDATA();
Index: source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1349,25 +1349,12 @@
   return false;
 }
 
-void ObjectFileMachO::CreateSections(SectionList &unified_section_list) {
-  if (m_sections_ap)
-return;
-
-  m_sections_ap.reset(new SectionList());
-
-  const bool is_dsym = (m_header.filetype == MH_DSYM);
-  lldb::user_id_t segID = 0;
-  lldb::user_id_t sectID = 0;
+ObjectFileMachO::EncryptedFileRanges ObjectFileMachO::GetEncryptedFileRanges() {
+  EncryptedFileRanges result;
   lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-  uint32_t i;
-  const bool is_core = GetType() == eTypeCoreFile;
-  // bool dump_sections = false;
-  ModuleSP module_sp(GetModule());
-  // First look up any LC_ENCRYPTION_INFO load commands
-  typedef RangeArray EncryptedFileRanges;
-  EncryptedFileRanges encrypted_file_ranges;
+
   encryption_info_command encryption_cmd;
-  for (i = 0; i < m_header.ncmds; ++i) {
+  for (uint32_t i = 0; i < m_header.ncmds; ++i) {
 const lldb::offset_t load_cmd_offset = offset;
 if (m_data.GetU32(&offset, &encryption_cmd, 2) == NULL)
   break;
@@ -1381,526 +1368,523 @@
   EncryptedFileRanges::Entry entry;
   entry.SetRangeBase(encryption_cmd.cryptoff);
   entry.SetByteSize(encryption_cmd.cryptsize);
-  encrypted_file_ranges.Append(entry);
+  result.Append(entry);
 }
   }
 }
 offset = load_cmd_offset + encryption_cmd.cmdsize;
   }
 
-  bool section_file_addresses_changed = false;
+  return result;
+}
 
-  offset = MachHeaderSizeFromMagic(m_header.magic);
+void ObjectFileMachO::SanitizeSegmentCommand(segment_command_64 &seg_cmd,
+ uint32_t cmd_idx) {
+  if (m_length == 0 || seg_cmd.filesize == 0)
+return;
 
-  struct segment_command_64 load_cmd;
-  for (i = 0; i < m_header.ncmds; ++i) {
-const lldb::offset_t load_cmd_offset = offset;
-if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
+  if (seg_cmd.fileoff > m_length) {
+// We have a load command that says it extends past the end of the file.
+// This is likely a corrupt file.  We don't have any way to return an error
+// condition here (this method was likely invoked from something like
+// ObjectFile::GetSectionList()), so we just null out the section contents,
+// and dump a message to stdout.  The most common case here is core file
+// debugging with a truncated file.
+con

[Lldb-commits] [PATCH] D44015: Fix std unique pointer not printing.

2018-03-03 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp:65-76
   ValueObjectSP tuple_sp =
   valobj_sp->GetChildMemberWithName(ConstString("_M_t"), true);
+
+  ValueObjectSP tuple_sp_child  =
+  tuple_sp->GetChildMemberWithName(ConstString("_M_t"), true);
+
+  /* if there is a _M_t child, the pointers are found in the

This is somewhat nitpicky, but I think we should rename the tuple_sp variable, 
as in your case, it will not actually hold a tuple (it is some unique_ptr_impl 
object, IIRC). So, it should have some neutral name, and once you have the 
actual tuple object, then call it a "tuple". Feel free to move this code into a 
GetTuple() function or something...

Also, we prefer c++-style comments (//).


https://reviews.llvm.org/D44015



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


[Lldb-commits] [lldb] r326671 - llgs-tests: use the auto-parsing form of SendMessage for sending the continue packets

2018-03-03 Thread Pavel Labath via lldb-commits
Author: labath
Date: Sat Mar  3 18:12:18 2018
New Revision: 326671

URL: http://llvm.org/viewvc/llvm-project?rev=326671&view=rev
Log:
llgs-tests: use the auto-parsing form of SendMessage for sending the continue 
packets

Modified:
lldb/trunk/unittests/tools/lldb-server/tests/MessageObjects.h
lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp

Modified: lldb/trunk/unittests/tools/lldb-server/tests/MessageObjects.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/tools/lldb-server/tests/MessageObjects.h?rev=326671&r1=326670&r2=326671&view=diff
==
--- lldb/trunk/unittests/tools/lldb-server/tests/MessageObjects.h (original)
+++ lldb/trunk/unittests/tools/lldb-server/tests/MessageObjects.h Sat Mar  3 
18:12:18 2018
@@ -90,7 +90,7 @@ parseRegisterValue(const lldb_private::R
llvm::StringRef HexValue, llvm::support::endianness Endian,
bool ZeroPad = false);
 
-class StopReply {
+class StopReply : public Parser> {
 public:
   StopReply() = default;
   virtual ~StopReply() = default;

Modified: lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp?rev=326671&r1=326670&r2=326671&view=diff
==
--- lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp (original)
+++ lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp Sat Mar  3 
18:12:18 2018
@@ -235,23 +235,20 @@ Error TestClient::queryProcess() {
 Error TestClient::Continue(StringRef message) {
   assert(m_process_info.hasValue());
 
-  std::string response;
-  if (Error E = SendMessage(message, response))
-return E;
-  auto creation = StopReply::create(response, m_process_info->GetEndian(),
-m_register_infos);
-  if (Error E = creation.takeError())
-return E;
+  auto StopReplyOr = SendMessage(
+  message, m_process_info->GetEndian(), m_register_infos);
+  if (!StopReplyOr)
+return StopReplyOr.takeError();
 
-  m_stop_reply = std::move(*creation);
+  m_stop_reply = std::move(*StopReplyOr);
   if (!isa(m_stop_reply)) {
 StringExtractorGDBRemote R;
 PacketResult result = ReadPacket(R, GetPacketTimeout(), false);
 if (result != PacketResult::ErrorDisconnected) {
   return make_error(
-  formatv("Expected connection close after receiving {0}. Got {1}/{2} "
+  formatv("Expected connection close after sending {0}. Got {1}/{2} "
   "instead.",
-  response, result, R.GetStringRef())
+  message, result, R.GetStringRef())
   .str(),
   inconvertibleErrorCode());
 }


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


[Lldb-commits] [PATCH] D43884: [lldb] Extract more fields from NSException values

2018-03-03 Thread Kuba (Brecka) Mracek via Phabricator via lldb-commits
kubamracek updated this revision to Diff 136933.

https://reviews.llvm.org/D43884

Files:
  packages/Python/lldbsuite/test/lang/objc/exceptions/Makefile
  packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
  packages/Python/lldbsuite/test/lang/objc/exceptions/main.m
  source/Plugins/Language/ObjC/NSException.cpp

Index: source/Plugins/Language/ObjC/NSException.cpp
===
--- source/Plugins/Language/ObjC/NSException.cpp
+++ source/Plugins/Language/ObjC/NSException.cpp
@@ -34,8 +34,8 @@
 using namespace lldb_private::formatters;
 
 static bool ExtractFields(ValueObject &valobj, ValueObjectSP *name_sp,
-  ValueObjectSP *reason_sp,
-  ValueObjectSP *userinfo_sp) {
+  ValueObjectSP *reason_sp, ValueObjectSP *userinfo_sp,
+  ValueObjectSP *reserved_sp) {
   ProcessSP process_sp(valobj.GetProcessSP());
   if (!process_sp)
 return false;
@@ -65,10 +65,14 @@
   auto userinfo = process_sp->ReadPointerFromMemory(ptr + 3 * ptr_size, error);
   if (error.Fail() || userinfo == LLDB_INVALID_ADDRESS)
 return false;
+  auto reserved = process_sp->ReadPointerFromMemory(ptr + 4 * ptr_size, error);
+  if (error.Fail() || reserved == LLDB_INVALID_ADDRESS)
+return false;
 
   InferiorSizedWord name_isw(name, *process_sp);
   InferiorSizedWord reason_isw(reason, *process_sp);
   InferiorSizedWord userinfo_isw(userinfo, *process_sp);
+  InferiorSizedWord reserved_isw(reserved, *process_sp);
 
   CompilerType voidstar = process_sp->GetTarget()
   .GetScratchClangASTContext()
@@ -87,15 +91,19 @@
 *userinfo_sp = ValueObject::CreateValueObjectFromData(
 "userInfo", userinfo_isw.GetAsData(process_sp->GetByteOrder()),
 valobj.GetExecutionContextRef(), voidstar);
+  if (reserved_sp)
+*reserved_sp = ValueObject::CreateValueObjectFromData(
+"reserved", reserved_isw.GetAsData(process_sp->GetByteOrder()),
+valobj.GetExecutionContextRef(), voidstar);
 
   return true;
 }
 
 bool lldb_private::formatters::NSException_SummaryProvider(
 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
   lldb::ValueObjectSP name_sp;
   lldb::ValueObjectSP reason_sp;
-  if (!ExtractFields(valobj, &name_sp, &reason_sp, nullptr))
+  if (!ExtractFields(valobj, &name_sp, &reason_sp, nullptr, nullptr))
 return false;
 
   if (!name_sp || !reason_sp)
@@ -121,35 +129,51 @@
   ~NSExceptionSyntheticFrontEnd() override = default;
 
   size_t CalculateNumChildren() override {
-return 1;
+return 4;
   }
 
   lldb::ValueObjectSP GetChildAtIndex(size_t idx) override {
 switch (idx) {
-  case 0: return m_userinfo_sp;
+  case 0: return m_name_sp;
+  case 1: return m_reason_sp;
+  case 2: return m_userinfo_sp;
+  case 3: return m_reserved_sp;
 }
 return lldb::ValueObjectSP();
   }
 
   bool Update() override {
+m_name_sp.reset();
+m_reason_sp.reset();
 m_userinfo_sp.reset();
-if (!ExtractFields(m_backend, nullptr, nullptr, &m_userinfo_sp)) {
+m_reserved_sp.reset();
+
+if (!ExtractFields(m_backend, &m_name_sp, &m_reason_sp, &m_userinfo_sp,
+   &m_reserved_sp)) {
   return false;
 }
 return true;
   }
 
   bool MightHaveChildren() override { return true; }
 
   size_t GetIndexOfChildWithName(const ConstString &name) override {
+static ConstString g___name("name");
+static ConstString g___reason("reason");
 static ConstString g___userInfo("userInfo");
-if (name == g___userInfo)
-  return 0;
+static ConstString g___reserved("reserved");
+if (name == g___name) return 0;
+if (name == g___reason) return 1;
+if (name == g___userInfo) return 2;
+if (name == g___reserved) return 3;
 return UINT32_MAX;
   }
 
 private:
+  ValueObjectSP m_name_sp;
+  ValueObjectSP m_reason_sp;
   ValueObjectSP m_userinfo_sp;
+  ValueObjectSP m_reserved_sp;
 };
 
 SyntheticChildrenFrontEnd *
Index: packages/Python/lldbsuite/test/lang/objc/exceptions/main.m
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/objc/exceptions/main.m
@@ -0,0 +1,36 @@
+//===-- main.m *- ObjC -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#import 
+
+void foo()
+{
+NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"some_value", @"some_key", nil];
+@throw [[NSException alloc] initWithName:@"ThrownException" reason:@"SomeReason" userInfo:info];
+}
+
+int main (int argc, const char * argv[])
+{
+NSAutoreleasePool *pool = [[NSAutoreleasePoo

[Lldb-commits] [PATCH] D43884: [lldb] Extract more fields from NSException values

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

I simplified what this patch is doing by removing the other independent parts. 
I extended the test to be testing both CLI text output and SB APIs (which also 
means it cannot be moved to a lit test).


https://reviews.llvm.org/D43884



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