[Lldb-commits] [PATCH] D13617: Fix ref-counting of Python objects

2019-10-07 Thread Zachary Turner via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Revision".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf8b22f8fea18: Fix ref counting of Python objects. (authored 
by zturner).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D13617?vs=37018=223601#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D13617

Files:
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
  lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp

Index: lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
===
--- lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
+++ lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
@@ -23,19 +23,75 @@
 SetUp() override
 {
 HostInfoBase::Initialize();
-// ScriptInterpreterPython::Initialize() depends on things like HostInfo being initialized
-// so it can compute the python directory etc, so we need to do this after
-// SystemInitializerCommon::Initialize().
+// ScriptInterpreterPython::Initialize() depends on HostInfo being
+// initializedso it can compute the python directory etc.
 ScriptInterpreterPython::Initialize();
+
+// Although we don't care about concurrency for the purposes of running
+// this test suite, Python requires the GIL to be locked even for
+// deallocating memory, which can happen when you call Py_DECREF or
+// Py_INCREF.  So acquire the GIL for the entire duration of this
+// test suite.
+m_gil_state = PyGILState_Ensure();
 }
 
 void
 TearDown() override
 {
+PyGILState_Release(m_gil_state);
+
 ScriptInterpreterPython::Terminate();
 }
+
+  private:
+PyGILState_STATE m_gil_state;
 };
 
+TEST_F(PythonDataObjectsTest, TestOwnedReferences)
+{
+// After creating a new object, the refcount should be 1
+PyObject *obj = PyLong_FromLong(3);
+EXPECT_EQ(1, obj->ob_refcnt);
+
+// If we take an owned reference, the refcount should still be 1
+PythonObject owned_long(PyRefType::Owned, obj);
+EXPECT_EQ(1, owned_long.get()->ob_refcnt);
+
+// Take another reference and verify that the refcount increases
+PythonObject strong_ref(owned_long);
+EXPECT_EQ(2, strong_ref.get()->ob_refcnt);
+
+// If we reset the first one, the refcount should be 1 again.
+owned_long.Reset();
+EXPECT_EQ(1, strong_ref.get()->ob_refcnt);
+}
+
+TEST_F(PythonDataObjectsTest, TestResetting)
+{
+PythonDictionary dict(PyInitialValue::Empty);
+
+PyObject *new_dict = PyDict_New();
+dict.Reset(PyRefType::Owned, new_dict);
+EXPECT_EQ(new_dict, dict.get());
+
+dict.Reset(PyRefType::Owned, nullptr);
+EXPECT_EQ(nullptr, dict.get());
+
+dict.Reset(PyRefType::Owned, PyDict_New());
+EXPECT_NE(nullptr, dict.get());
+dict.Reset();
+EXPECT_EQ(nullptr, dict.get());
+}
+
+TEST_F(PythonDataObjectsTest, TestBorrowedReferences)
+{
+PythonInteger long_value(PyRefType::Owned, PyLong_FromLong(3));
+EXPECT_EQ(1, long_value.get()->ob_refcnt);
+
+PythonInteger borrowed_long(PyRefType::Borrowed, long_value.get());
+EXPECT_EQ(2, borrowed_long.get()->ob_refcnt);
+}
+
 TEST_F(PythonDataObjectsTest, TestPythonInteger)
 {
 // Test that integers behave correctly when wrapped by a PythonInteger.
@@ -45,7 +101,7 @@
 // Note that PyInt doesn't exist in Python 3.x, so this is only for 2.x
 PyObject *py_int = PyInt_FromLong(12);
 EXPECT_TRUE(PythonInteger::Check(py_int));
-PythonInteger python_int(py_int);
+PythonInteger python_int(PyRefType::Owned, py_int);
 
 EXPECT_EQ(PyObjectType::Integer, python_int.GetObjectType());
 EXPECT_EQ(12, python_int.GetInteger());
@@ -54,7 +110,7 @@
 // Verify that `PythonInt` works correctly when given a PyLong object.
 PyObject *py_long = PyLong_FromLong(12);
 EXPECT_TRUE(PythonInteger::Check(py_long));
-PythonInteger python_long(py_long);
+PythonInteger python_long(PyRefType::Owned, py_long);
 EXPECT_EQ(PyObjectType::Integer, python_long.GetObjectType());
 
 // Verify that you can reset the value and that it is reflected properly.
@@ -74,7 +130,7 @@
 // Note that PyString doesn't exist in Python 3.x, so this is only for 2.x
 PyObject *py_string = PyString_FromString(test_string);
 EXPECT_TRUE(PythonString::Check(py_string));
-PythonString python_string(py_string);
+PythonString python_string(PyRefType::Owned, py_string);
 
 EXPECT_EQ(PyObjectType::String, 

[Lldb-commits] [PATCH] D17492: Case sensitive path compare on Windows breaks breakpoints

2019-10-07 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG47c03462f52a: Some fixes for case insensitive paths on 
Windows. (authored by zturner).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D17492?vs=48871=223585#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D17492

Files:
  lldb/include/lldb/Core/ConstString.h
  lldb/include/lldb/Host/FileSpec.h
  
lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_case_sensitivity/Makefile
  
lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_case_sensitivity/TestBreakpointCaseSensitivity.py
  
lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_case_sensitivity/main.c
  lldb/source/Core/ConstString.cpp
  lldb/source/Core/FileSpecList.cpp
  lldb/source/Host/common/FileSpec.cpp

Index: lldb/source/Host/common/FileSpec.cpp
===
--- lldb/source/Host/common/FileSpec.cpp
+++ lldb/source/Host/common/FileSpec.cpp
@@ -396,60 +396,62 @@
 bool
 FileSpec::operator== (const FileSpec& rhs) const
 {
-if (m_filename == rhs.m_filename)
+// case sensitivity of equality test
+const bool case_sensitive = IsCaseSensitive() || rhs.IsCaseSensitive();
+
+if (!ConstString::Equals(m_filename, rhs.m_filename, case_sensitive))
+return false;
+
+if (ConstString::Equals(m_directory, rhs.m_directory, case_sensitive))
+return true;
+
+// TODO: determine if we want to keep this code in here.
+// The code below was added to handle a case where we were
+// trying to set a file and line breakpoint and one path
+// was resolved, and the other not and the directory was
+// in a mount point that resolved to a more complete path:
+// "/tmp/a.c" == "/private/tmp/a.c". I might end up pulling
+// this out...
+if (IsResolved() && rhs.IsResolved())
 {
-if (m_directory == rhs.m_directory)
-return true;
-
-// TODO: determine if we want to keep this code in here.
-// The code below was added to handle a case where we were
-// trying to set a file and line breakpoint and one path
-// was resolved, and the other not and the directory was
-// in a mount point that resolved to a more complete path:
-// "/tmp/a.c" == "/private/tmp/a.c". I might end up pulling
-// this out...
-if (IsResolved() && rhs.IsResolved())
-{
-// Both paths are resolved, no need to look further...
-return false;
-}
-
-FileSpec resolved_lhs(*this);
+// Both paths are resolved, no need to look further...
+return false;
+}
+
+FileSpec resolved_lhs(*this);
 
-// If "this" isn't resolved, resolve it
-if (!IsResolved())
+// If "this" isn't resolved, resolve it
+if (!IsResolved())
+{
+if (resolved_lhs.ResolvePath())
 {
-if (resolved_lhs.ResolvePath())
-{
-// This path wasn't resolved but now it is. Check if the resolved
-// directory is the same as our unresolved directory, and if so, 
-// we can mark this object as resolved to avoid more future resolves
-m_is_resolved = (m_directory == resolved_lhs.m_directory);
-}
-else
-return false;
+// This path wasn't resolved but now it is. Check if the resolved
+// directory is the same as our unresolved directory, and if so,
+// we can mark this object as resolved to avoid more future resolves
+m_is_resolved = (m_directory == resolved_lhs.m_directory);
 }
-
-FileSpec resolved_rhs(rhs);
-if (!rhs.IsResolved())
+else
+return false;
+}
+
+FileSpec resolved_rhs(rhs);
+if (!rhs.IsResolved())
+{
+if (resolved_rhs.ResolvePath())
 {
-if (resolved_rhs.ResolvePath())
-{
-// rhs's path wasn't resolved but now it is. Check if the resolved
-// directory is the same as rhs's unresolved directory, and if so, 
-// we can mark this object as resolved to avoid more future resolves
-rhs.m_is_resolved = (rhs.m_directory == resolved_rhs.m_directory);
-}
-else
-return false;
+// rhs's path wasn't resolved but now it is. Check if the resolved
+// directory is the same as rhs's unresolved directory, and if so,
+// we can mark this object as resolved to avoid more future resolves
+rhs.m_is_resolved = (rhs.m_directory == resolved_rhs.m_directory);
 }
-
-// If we reach this point in the code we were able to resolve both 

[Lldb-commits] [PATCH] D27780: Make OptionDefinition structure store a StringRef

2019-10-07 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG182b4652e542: [StringRef] Add enable-if to StringLiteral. 
(authored by zturner).
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D27780?vs=81625=223552#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D27780

Files:
  llvm/include/llvm/ADT/StringRef.h


Index: llvm/include/llvm/ADT/StringRef.h
===
--- llvm/include/llvm/ADT/StringRef.h
+++ llvm/include/llvm/ADT/StringRef.h
@@ -838,22 +838,21 @@
 
   /// A wrapper around a string literal that serves as a proxy for constructing
   /// global tables of StringRefs with the length computed at compile time.
-  /// Using this class with a non-literal char array is considered undefined
-  /// behavior.  To prevent this, it is recommended that StringLiteral *only*
-  /// be used in a constexpr context, as such:
+  /// In order to avoid the invocation of a global constructor, StringLiteral
+  /// should *only* be used in a constexpr context, as such:
   ///
   /// constexpr StringLiteral S("test");
   ///
-  /// Note: There is a subtle behavioral difference in the constructor of
-  /// StringRef and StringLiteral, as illustrated below:
-  ///
-  /// constexpr StringLiteral S("a\0b");  // S.size() == 3
-  /// StringRef S("a\0b");  // S.size() == 1
-  ///
   class StringLiteral : public StringRef {
   public:
 template 
-constexpr StringLiteral(const char ()[N]) : StringRef(Str, N - 1) {}
+constexpr StringLiteral(const char ()[N])
+#if __has_attribute(enable_if)
+__attribute((enable_if(__builtin_strlen(Str) == N - 1,
+   "invalid string literal")))
+#endif
+: StringRef(Str, N - 1) {
+}
   };
 
   /// @name StringRef Comparison Operators
@@ -865,9 +864,7 @@
   }
 
   LLVM_ATTRIBUTE_ALWAYS_INLINE
-  inline bool operator!=(StringRef LHS, StringRef RHS) {
-return !(LHS == RHS);
-  }
+  inline bool operator!=(StringRef LHS, StringRef RHS) { return !(LHS == RHS); 
}
 
   inline bool operator<(StringRef LHS, StringRef RHS) {
 return LHS.compare(RHS) == -1;


Index: llvm/include/llvm/ADT/StringRef.h
===
--- llvm/include/llvm/ADT/StringRef.h
+++ llvm/include/llvm/ADT/StringRef.h
@@ -838,22 +838,21 @@
 
   /// A wrapper around a string literal that serves as a proxy for constructing
   /// global tables of StringRefs with the length computed at compile time.
-  /// Using this class with a non-literal char array is considered undefined
-  /// behavior.  To prevent this, it is recommended that StringLiteral *only*
-  /// be used in a constexpr context, as such:
+  /// In order to avoid the invocation of a global constructor, StringLiteral
+  /// should *only* be used in a constexpr context, as such:
   ///
   /// constexpr StringLiteral S("test");
   ///
-  /// Note: There is a subtle behavioral difference in the constructor of
-  /// StringRef and StringLiteral, as illustrated below:
-  ///
-  /// constexpr StringLiteral S("a\0b");  // S.size() == 3
-  /// StringRef S("a\0b");  // S.size() == 1
-  ///
   class StringLiteral : public StringRef {
   public:
 template 
-constexpr StringLiteral(const char ()[N]) : StringRef(Str, N - 1) {}
+constexpr StringLiteral(const char ()[N])
+#if __has_attribute(enable_if)
+__attribute((enable_if(__builtin_strlen(Str) == N - 1,
+   "invalid string literal")))
+#endif
+: StringRef(Str, N - 1) {
+}
   };
 
   /// @name StringRef Comparison Operators
@@ -865,9 +864,7 @@
   }
 
   LLVM_ATTRIBUTE_ALWAYS_INLINE
-  inline bool operator!=(StringRef LHS, StringRef RHS) {
-return !(LHS == RHS);
-  }
+  inline bool operator!=(StringRef LHS, StringRef RHS) { return !(LHS == RHS); }
 
   inline bool operator<(StringRef LHS, StringRef RHS) {
 return LHS.compare(RHS) == -1;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D55574: Remove else statements after returns

2019-10-04 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: source/Commands/CommandObjectTarget.cpp:2569
+  }
+  StreamString strm;
+  module_spec.GetUUID().Dump();

aprantl wrote:
> Can you manually double-check this one?
For large complex cases like this, it might make sense to convert them to early 
returns first.  That makes the size of the if blocks smaller so less chance of 
messing up.



Comment at: source/Commands/CommandObjectTarget.cpp:2601-2607
+  } else {
+result.AppendError(
+"one or more executable image paths must be specified");
+result.SetStatus(eReturnStatusFailed);
+return false;
+  }
   } else {

Something is wrong with indentation here.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D55574



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


[Lldb-commits] [PATCH] D67168: [Windows] Add support of watchpoints to `ProcessWindows`

2019-09-04 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: 
lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp:82
 
-bool RegisterContextWindows::ClearHardwareBreakpoint(uint32_t hw_idx) {
-  return false;
-}
+  if (!size || size > 8 || size & (size - 1))
+return false;

amccarth wrote:
> Clever!  It took me a minute or two to figure out what the point of that was 
> checking.  Perhaps a comment to explain?
Isn't this equivalent to:

```
switch (size)
{
case 1:
case 2:
case 4:
case 8:
break;
default:
return false;
}
```

?  That definitely seems much clearer.

I'm also pretty sure that on x86 you can't add a 64-bit watch, So you'd have to 
do something different depending on the target bitness if you want this to be 
correct for x86.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D67168



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


[Lldb-commits] [PATCH] D60152: Fix and simplify PrepareCommandsForSourcing

2019-04-03 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: lldb/tools/driver/Driver.cpp:492-496
 #ifdef _WIN32
-  _close(fds[WRITE]);
-  fds[WRITE] = -1;
+  _close(fd);
 #else
-  close(fds[WRITE]);
-  fds[WRITE] = -1;
+  close(fd);
 #endif

labath wrote:
> amccarth wrote:
> > labath wrote:
> > > Do you think it would be possible to use 
> > > `llvm::Process::SafelyCloseFileDescriptor` here? It looks like that still 
> > > uses close (without the `_`) on windows, which we are trying hard to 
> > > avoid here, but I'm not sure why. I know close is technically deprecated 
> > > on windows, but AFAIK the only thing deprecated about it is the name, and 
> > > otherwise it works correctly.
> > > 
> > > (If that works, I'd even consider removing this function entirely, as the 
> > > only thing it does extra is clear the fd, but that does not seem 
> > > necessary since we're now calling it immediately before we return (and 
> > > the fds go out of scope anyway)).
> > I'm happy to use `llvm::sys::Process::SafelyCloseFileDescriptor` and delete 
> > my little wrapper.  I agree that resetting the df to -1 right before it 
> > goes out of scope isn't useful.  I'll update the patch momentarily.
> > 
> > If we're not that worried about the deprecated names on Windows, should I 
> > also just use `fdopen` and forget about wrapping that as well?
> > 
> > Either way, I'm going to keep the OpenPipe wrapper since the Windows 
> > version takes additional parameters.
> I think using the non-underscore fdopen is fine, but I am not a windows guy. 
> (The nice thing about SafelyCloseFileDescriptor is that it already provides 
> an abstraction and so we can add the underscore there centrally, should it 
> ever become necessary).
I dug into this a little bit to find out what the actual difference is, and 
there isn't a difference at all.  `close` and `_close`, `fdopen` and `_fdopen`, 
and all other pairs of underscore and non underscore names both resolve to the 
exact same symbol in the object file (it links in an object file that has a 
symbol for `close` that aliases it to `_close`.  So there is literally no 
difference.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60152



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


[Lldb-commits] [PATCH] D59911: Don't abort() in lldb_assert and document why.

2019-03-28 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D59911#1446942 , @jingham wrote:

> In D59911#1446745 , @davide wrote:
>
> > My (maybe unpopolar) opinion on the subject is that "soft assertions" are a 
> > way to cleanse your conscience of guilt, but they don't work really well in 
> > practice.
> >  When I started working on lldb, I was a fairly strong proponent of 
> > assertions everywhere. My view changed somewhat radically over the course 
> > of the past 18 months, and I would like to summarize some points here.
> >
> > 1. Vendors (some) ship a release or two of debuggers every 6 months. Even 
> > if you just look at open source, llvm gets released every 6 months and 
> > distributions downstream package just the release version. Not everybody 
> > runs gentoo or exherbo or compiles his toolchain from svn. For these people 
> > the debugger has just to work. Assertions are always compiled out in 
> > release mode so this is not an issue. I strongly agree that for internal 
> > interfaces they have to be used as liberally as possible, mostly because 
> > they catch bugs in development. llvm libraries tend to use assertions 
> > galore, and developers put them in "just in case", and I think this is 
> > really not something we should do in lldb.
> > 2. Errors have to be handled, properly. I don't think returning a default 
> > constructed object in case something goes bad is better than throwing an 
> > error. We now have rich/proper error handling in llvm to make sure the 
> > process blows up if the error is not checked. This is a good thing.
> > 3. The above points are IMHO the only two needed ways of handling 
> > invariants/invalid input. Anything else in the middle is just going to 
> > cause confusion to new and existing developer. Adrian (or anybody else), do 
> > you have any real example where something wasn't either a user error or a 
> > strong invariant that couldn't be violated? I personally didn't, hence I 
> > don't understand the need for "soft" assertions here.
>
>
> Here is a concrete example of the sort of thing I thought lldbassert was for. 
>   In DWARFExpression::AddressRangeForLocationListEntry if we come across a 
> LocationList format we don't understand, we do:
>
>   default:
> // Not supported entry type
> lldbassert(false && "Not supported location list type");
> return false;


IMO, this example should be changed to

  return llvm::make_error("Unsupported location list type");

and let someone higher up handle this.


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

https://reviews.llvm.org/D59911



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


[Lldb-commits] [PATCH] D59854: [Host] Add LibraryLoader abstraction around dlopen/LoadLibrary

2019-03-26 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D59854#1443906 , @jingham wrote:

> In D59854#1443904 , @JDevlieghere 
> wrote:
>
> > In D59854#1443891 , @jingham wrote:
> >
> > > It isn't safe to pass "data()" of a StringRef to dlsym.
> >
> >
> > Why?
>
>
> StringRef's aren't guaranteed to be NULL terminated.  Or rather, the Data 
> that gets returned by the data() method is just the raw pointer in the 
> StringRef, which isn't guaranteed to be NULL terminated.


While true, I don't think this is a good reason to make the interface accept a 
`const char*`, because that means that the interface is exposing an 
implementation detail.  Instead, the interface should accept a `StringRef`, and 
the implementation can pass `foo.str().c_str()`.  It might be slightly less 
efficient (almost to the point of minutia), but this isn't really performance 
sensitive code, as loading the library will dominate the call to malloc / 
memcpy.


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

https://reviews.llvm.org/D59854



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


[Lldb-commits] [PATCH] D59651: Move DebugRanges() function from SymbolFileDWARF to DWARFContext

2019-03-21 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: JDevlieghere, clayborg, labath, aprantl.

This should be the last non-dwo dependent piece to get over to `DWARFContext`.  
After this there will need to be some careful refactoring to get all knowledge 
of DWO-ness into the `DWARFContext`, ultimately culminating in probably 
deleting `SymbolFileDWARFDwo` and friends.  That's for later though, just 
trying to give a preview into where this is going.

Eventually the goal is that `SymbolFileDWARF` depends on the low level parser, 
but not the other way around, at which point we can start the //real// process 
of merging with LLVM's.


https://reviews.llvm.org/D59651

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -240,10 +240,6 @@
 
   const DWARFDebugInfo *DebugInfo() const;
 
-  DWARFDebugRangesBase *DebugRanges();
-
-  const DWARFDebugRangesBase *DebugRanges() const;
-
   static bool SupportedVersion(uint16_t version);
 
   DWARFDIE
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -633,27 +633,6 @@
   return NULL;
 }
 
-DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() {
-  if (m_ranges == NULL) {
-static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
-Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION,
-   static_cast(this));
-
-if (m_context.getOrLoadDebugRangesData())
-  m_ranges = llvm::make_unique();
-else if (m_context.getOrLoadDebugRnglistsData())
-  m_ranges = llvm::make_unique();
-
-if (m_ranges)
-  m_ranges->Extract(this, m_context);
-  }
-  return m_ranges.get();
-}
-
-const DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() const {
-  return m_ranges.get();
-}
-
 lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFUnit *dwarf_cu,
uint32_t cu_idx) {
   CompUnitSP cu_sp;
@@ -3269,7 +3248,8 @@
   case DW_AT_start_scope: {
 if (form_value.Form() == DW_FORM_sec_offset) {
   DWARFRangeList dwarf_scope_ranges;
-  const DWARFDebugRangesBase *debug_ranges = DebugRanges();
+  const DWARFDebugRangesBase *debug_ranges =
+  m_context.getOrLoadRangeInfo();
   debug_ranges->FindRanges(die.GetCU(),
form_value.Unsigned(),
dwarf_scope_ranges);
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -436,8 +436,8 @@
   const dw_offset_t cu_offset = GetOffset();
   if (die) {
 DWARFRangeList ranges;
-const size_t num_ranges =
-die->GetAttributeAddressRanges(dwarf, this, ranges, false);
+const size_t num_ranges = die->GetAttributeAddressRanges(
+dwarf, GetDWARFContext(), this, ranges, false);
 if (num_ranges > 0) {
   // This compile unit has DW_AT_ranges, assume this is correct if it is
   // present since clang no longer makes .debug_aranges by default and it
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
@@ -22,8 +22,7 @@
 public:
   virtual ~DWARFDebugRangesBase(){};
 
-  virtual void Extract(SymbolFileDWARF *dwarf2Data,
-   lldb_private::DWARFContext _context) = 0;
+  virtual void Extract(lldb_private::DWARFContext _context) = 0;
   virtual bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset,
   DWARFRangeList _list) const = 0;
   virtual uint64_t GetOffset(size_t Index) const = 0;
@@ -33,8 +32,7 @@
 public:
   DWARFDebugRanges();
 
-  void 

[Lldb-commits] [PATCH] D59611: Move the rest of the section loading over to DWARFContext

2019-03-21 Thread Zachary Turner via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Revision".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356682: Move the rest of the sections over to DWARFContext. 
(authored by zturner, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59611?vs=191575=191722#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59611

Files:
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h

Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
@@ -147,7 +147,7 @@
 }
 
 DWARFExpression::LocationListFormat
-SymbolFileDWARFDwo::GetLocationListFormat() const {
+SymbolFileDWARFDwo::GetLocationListFormat() {
   return DWARFExpression::SplitDwarfLocationList;
 }
 
Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -54,6 +54,7 @@
 #include "AppleDWARFIndex.h"
 #include "DWARFASTParser.h"
 #include "DWARFASTParserClang.h"
+#include "DWARFContext.h"
 #include "DWARFDebugAbbrev.h"
 #include "DWARFDebugAranges.h"
 #include "DWARFDebugInfo.h"
@@ -357,11 +358,8 @@
   // contain the .o file index/ID
   m_debug_map_module_wp(), m_debug_map_symfile(NULL),
   m_context(*objfile->GetModule()), m_data_debug_abbrev(),
-  m_data_debug_frame(), m_data_debug_info(), m_data_debug_line(),
-  m_data_debug_macro(), m_data_debug_loc(), m_data_debug_ranges(),
-  m_data_debug_rnglists(), m_data_debug_str(), m_data_apple_names(),
-  m_data_apple_types(), m_data_apple_namespaces(), m_abbr(), m_info(),
-  m_line(), m_fetched_external_modules(false),
+  m_data_debug_info(), m_data_debug_str(), m_abbr(), m_info(), m_line(),
+  m_fetched_external_modules(false),
   m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), m_ranges(),
   m_unique_ast_type_map() {}
 
@@ -561,52 +559,10 @@
   return GetCachedSectionData(eSectionTypeDWARFDebugAddr, m_data_debug_addr);
 }
 
-const DWARFDataExtractor ::get_debug_frame_data() {
-  return GetCachedSectionData(eSectionTypeDWARFDebugFrame, m_data_debug_frame);
-}
-
 const DWARFDataExtractor ::get_debug_info_data() {
   return GetCachedSectionData(eSectionTypeDWARFDebugInfo, m_data_debug_info);
 }
 
-const DWARFDataExtractor ::get_debug_line_data() {
-  return GetCachedSectionData(eSectionTypeDWARFDebugLine, m_data_debug_line);
-}
-
-const DWARFDataExtractor ::get_debug_line_str_data() {
- return GetCachedSectionData(eSectionTypeDWARFDebugLineStr, m_data_debug_line_str);
-}
-
-const DWARFDataExtractor ::get_debug_macro_data() {
-  return GetCachedSectionData(eSectionTypeDWARFDebugMacro, m_data_debug_macro);
-}
-
-const DWARFDataExtractor ::DebugLocData() {
-  const DWARFDataExtractor  = get_debug_loc_data();
-  if (debugLocData.GetByteSize() > 0)
-return debugLocData;
-  return get_debug_loclists_data();
-}
-
-const DWARFDataExtractor ::get_debug_loc_data() {
-  return GetCachedSectionData(eSectionTypeDWARFDebugLoc, m_data_debug_loc);
-}
-
-const DWARFDataExtractor ::get_debug_loclists_data() {
-  return GetCachedSectionData(eSectionTypeDWARFDebugLocLists,
-  m_data_debug_loclists);
-}
-
-const DWARFDataExtractor ::get_debug_ranges_data() {
-  return GetCachedSectionData(eSectionTypeDWARFDebugRanges,
-  m_data_debug_ranges);
-}
-
-const DWARFDataExtractor ::get_debug_rnglists_data() {
-  

[Lldb-commits] [PATCH] D59611: Move the rest of the section loading over to DWARFContext

2019-03-21 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D59611#1437044 , @clayborg wrote:

> Use reference to DWARFContext instead of pointers? Apply to entire patch and 
> good to go


Done.  Since you conditionally LGTM'ed it based on that and I made that change 
I'll go ahead and submit


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

https://reviews.llvm.org/D59611



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


[Lldb-commits] [PATCH] D59611: Move the rest of the section loading over to DWARFContext

2019-03-20 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: clayborg, JDevlieghere, labath, aprantl.
Herald added a subscriber: jdoerfert.

This gets all of the remaining sections except those that are DWO-dependent.  
That will be a bit harder to do since we'll somehow have to get knowledge of 
DWO-ness into the `DWARFContext`.

This is mostly mechanical now after D59562 .


https://reviews.llvm.org/D59611

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
@@ -26,7 +26,7 @@
   GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) override;
 
   lldb_private::DWARFExpression::LocationListFormat
-  GetLocationListFormat() const override;
+  GetLocationListFormat() override;
 
   size_t GetObjCMethodDIEOffsets(lldb_private::ConstString class_name,
  DIEArray _die_offsets) override;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
@@ -147,7 +147,7 @@
 }
 
 DWARFExpression::LocationListFormat
-SymbolFileDWARFDwo::GetLocationListFormat() const {
+SymbolFileDWARFDwo::GetLocationListFormat() {
   return DWARFExpression::SplitDwarfLocationList;
 }
 
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -228,23 +228,9 @@
 
   virtual const lldb_private::DWARFDataExtractor _debug_abbrev_data();
   virtual const lldb_private::DWARFDataExtractor _debug_addr_data();
-  const lldb_private::DWARFDataExtractor _debug_frame_data();
   virtual const lldb_private::DWARFDataExtractor _debug_info_data();
-  const lldb_private::DWARFDataExtractor _debug_line_data();
-  const lldb_private::DWARFDataExtractor _debug_line_str_data();
-  const lldb_private::DWARFDataExtractor _debug_macro_data();
-  const lldb_private::DWARFDataExtractor _debug_loc_data();
-  const lldb_private::DWARFDataExtractor _debug_loclists_data();
-  const lldb_private::DWARFDataExtractor _debug_ranges_data();
-  const lldb_private::DWARFDataExtractor _debug_rnglists_data();
   virtual const lldb_private::DWARFDataExtractor _debug_str_data();
   virtual const lldb_private::DWARFDataExtractor _debug_str_offsets_data();
-  const lldb_private::DWARFDataExtractor _debug_types_data();
-  const lldb_private::DWARFDataExtractor _apple_names_data();
-  const lldb_private::DWARFDataExtractor _apple_types_data();
-  const lldb_private::DWARFDataExtractor _apple_namespaces_data();
-  const lldb_private::DWARFDataExtractor _apple_objc_data();
-  const lldb_private::DWARFDataExtractor _gnu_debugaltlink();
 
   DWARFDebugAbbrev *DebugAbbrev();
 
@@ -258,8 +244,6 @@
 
   const DWARFDebugRangesBase *DebugRanges() const;
 
-  const lldb_private::DWARFDataExtractor ();
-
   static bool SupportedVersion(uint16_t version);
 
   DWARFDIE
@@ -285,7 +269,7 @@
 uint32_t cu_idx);
 
   virtual lldb_private::DWARFExpression::LocationListFormat
-  GetLocationListFormat() const;
+  GetLocationListFormat();
 
   lldb::ModuleSP GetDWOModule(lldb_private::ConstString name);
 
@@ -302,6 +286,7 @@
   virtual std::unique_ptr
   GetDwoSymbolFileForCompileUnit(DWARFUnit _cu,
  const DWARFDebugInfoEntry _die);
+  lldb_private::DWARFContext *GetDWARFContext();
 
   // For regular SymbolFileDWARF instances the method returns nullptr,
   // for the instances of the subclass SymbolFileDWARFDwo
@@ -462,23 +447,9 @@
 
   DWARFDataSegment m_data_debug_abbrev;
   DWARFDataSegment 

[Lldb-commits] [PATCH] D59562: [SymbolFileDWARF] Introduce DWARFContext

2019-03-20 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356612: Introduce DWARFContext. (authored by zturner, 
committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59562?vs=191510=191572#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59562

Files:
  lldb/trunk/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFContext.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp

Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
@@ -19,6 +19,10 @@
 #include "lldb/lldb-private.h"
 #include "llvm/Support/Error.h"
 
+namespace lldb_private {
+class DWARFContext;
+}
+
 typedef std::multimap
 CStringToDIEMap;
 typedef CStringToDIEMap::iterator CStringToDIEMapIter;
@@ -32,7 +36,7 @@
   const dw_offset_t next_offset,
   const uint32_t depth, void *userData);
 
-  DWARFDebugInfo();
+  explicit DWARFDebugInfo(lldb_private::DWARFContext );
   void SetDwarfData(SymbolFileDWARF *dwarf2Data);
 
   size_t GetNumCompileUnits();
@@ -62,6 +66,7 @@
   // Member variables
   //--
   SymbolFileDWARF *m_dwarf2Data;
+  lldb_private::DWARFContext _context;
   CompileUnitColl m_compile_units;
   std::unique_ptr
   m_cu_aranges_up; // A quick address to compile unit table
Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -355,12 +355,13 @@
   << 32), // Used by SymbolFileDWARFDebugMap to
   // when this class parses .o files to
   // contain the .o file index/ID
-  m_debug_map_module_wp(), m_debug_map_symfile(NULL), m_data_debug_abbrev(),
-  m_data_debug_aranges(), m_data_debug_frame(), m_data_debug_info(),
-  m_data_debug_line(), m_data_debug_macro(), m_data_debug_loc(),
-  m_data_debug_ranges(), m_data_debug_rnglists(), m_data_debug_str(),
-  m_data_apple_names(), m_data_apple_types(), m_data_apple_namespaces(),
-  m_abbr(), m_info(), m_line(), m_fetched_external_modules(false),
+  m_debug_map_module_wp(), m_debug_map_symfile(NULL),
+  m_context(*objfile->GetModule()), m_data_debug_abbrev(),
+  m_data_debug_frame(), m_data_debug_info(), m_data_debug_line(),
+  m_data_debug_macro(), m_data_debug_loc(), m_data_debug_ranges(),
+  m_data_debug_rnglists(), m_data_debug_str(), m_data_apple_names(),
+  m_data_apple_types(), m_data_apple_namespaces(), m_abbr(), m_info(),
+  m_line(), m_fetched_external_modules(false),
   m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), m_ranges(),
   m_unique_ast_type_map() {}
 
@@ -394,15 +395,6 @@
 
 void SymbolFileDWARF::InitializeObject() {
   Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
-  ModuleSP module_sp(m_obj_file->GetModule());
-  if (module_sp) {
-const SectionList *section_list = module_sp->GetSectionList();
-Section *section =
-section_list->FindSectionByName(GetDWARFMachOSegmentName()).get();
-
-if (section)
-  m_obj_file->ReadSectionData(section, m_dwarf_data);
-  }
 
   if (!GetGlobalPluginProperties()->IgnoreFileIndexes()) {
 DWARFDataExtractor apple_names, apple_namespaces, apple_types, apple_objc;
@@ -549,19 +541,15 @@
   DWARFDataExtractor ) {
   ModuleSP module_sp(m_obj_file->GetModule());
   const SectionList *section_list = module_sp->GetSectionList();
-  if (section_list) {
-SectionSP section_sp(section_list->FindSectionByType(sect_type, true));
-if (section_sp) {
-  // See if we memory mapped the DWARF segment?
-  if (m_dwarf_data.GetByteSize()) {
-data.SetData(m_dwarf_data, section_sp->GetOffset(),
- section_sp->GetFileSize());
-  } else {
-if (m_obj_file->ReadSectionData(section_sp.get(), data) == 0)
-  data.Clear();
-  }
-}
-  }
+  if (!section_list)
+return;
+
+  SectionSP 

[Lldb-commits] [PATCH] D59562: [SymbolFileDWARF] Introduce DWARFContext

2019-03-20 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked an inline comment as done.
zturner added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:552
+  data.Clear();
+  m_obj_file->ReadSectionData(section_sp.get(), data);
 }

clayborg wrote:
> clayborg wrote:
> > ```
> > if (m_obj_file->ReadSectionData(section_sp.get(), data) == 0)
> >   data.Clear();
> > ```
> What do you think about this one? This is my last nit
I did see that one, but I was having trouble figuring out how the behavior is 
different from what I already wrote.  The only way I could see it being 
different is if `ReadSectionData` would actually write data there even when it 
failed.  That would be strange though, do you know if it can happen?

The way I wrote it, it clears first, and then if the function fails / returns 
0, I would expect it to be unchanged.

Happy to change it if there's actually a difference I'm overlooking, but if 
they're the same then I think the branchless version is slightly easier to read.


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

https://reviews.llvm.org/D59562



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


[Lldb-commits] [PATCH] D59562: [SymbolFileDWARF] Introduce DWARFContext

2019-03-20 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked 2 inline comments as done.
zturner added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp:50
+
+const DWARFDataExtractor *DWARFContext::getOrLoadArangesData() {
+  return LoadOrGetSection(m_module, m_dwarf_data, 
eSectionTypeDWARFDebugAranges,

clayborg wrote:
> rename to "getArangesData()"? Would it be better to return an 
> Optional?
I actually prefer to keep the name as `getOrLoad`.  `get` functions often sound 
like they don't modify anything, but this way it's clear that lazy evaluation 
will occur, which might be important to the caller for some reason or another.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp:24
+  // forward.
+  extractor.emplace();
+

clayborg wrote:
> clayborg wrote:
> > Don't we want to put an empty DWARFDataExtractor in here? Maybe this code 
> > should be:
> > 
> > ```
> > const SectionList *section_list = module.GetSectionList();
> >   if (!section_list)
> > return nullptr;
> > 
> >   auto section_sp = section_list->FindSectionByType(section_type, true);
> >   if (!section_sp)
> > return nullptr;
> > 
> >   extractor.emplace();
> >   if (section_sp->GetSectionData(*extractor) == 0)
> > extractor = llvm::None;
> >   return extractor.getPointer();
> > ```
> Or use a local DWARFDataExtractor and move it into "extractor" if we succeed?
> 
> ```
> DWARFDataExtractor data;
> if (section_sp->GetSectionData(data) > 0)
> extractor = std::move(data);
> ```
The suggested code here has a bug.  If you say 

```
extractor = llvm::None;
return extractor.getPointer();
```

it will assert, because there is no pointer, it's uninitialized.  When i write 
`extractor.emplace();` it initializes it with a default constructed 
`DataExtractor`, the idea being that if we try this function and it fails for 
any reason, we should not try the function again, because it already failed 
once, and so we should just "cache" the fact that it failed and immediately 
return.  By having a default constructed `DataExtractor` and changing the fast 
path exit condition to also return null in the case where the size is 0, we 
ensure that we only ever do work once, regardless of whether that work fails or 
succeeds.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp:40
+
+const DWARFDataExtractor *DWARFContext::getOrLoadArangesData() {
+  return LoadOrGetSection(m_module, eSectionTypeDWARFDebugAranges,

clayborg wrote:
> Why do we care about "getOrLoadArangesData()"? What not just 
> "getArangesData()"?
I like to emphasize in the name that the function might do work.  People are 
trained to think of `get` functions as read-only, but it's not the case here 
and so the idea is to make sure that nobody can misinterpret the behavior.


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

https://reviews.llvm.org/D59562



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


[Lldb-commits] [PATCH] D59562: [SymbolFileDWARF] Introduce DWARFContext

2019-03-20 Thread Zachary Turner via Phabricator via lldb-commits
zturner updated this revision to Diff 191510.
zturner marked an inline comment as done.
zturner added a comment.

Updated based on suggestions, including removal of the `m_dwarf_data` member 
variable which holds the contents of the `__DWARF` segment on MachO.


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

https://reviews.llvm.org/D59562

Files:
  lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
@@ -33,12 +33,6 @@
   if (section_list) {
 SectionSP section_sp(section_list->FindSectionByType(sect_type, true));
 if (section_sp) {
-  // See if we memory mapped the DWARF segment?
-  if (m_dwarf_data.GetByteSize()) {
-data.SetData(m_dwarf_data, section_sp->GetOffset(),
- section_sp->GetFileSize());
-return;
-  }
 
   if (m_obj_file->ReadSectionData(section_sp.get(), data) != 0)
 return;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -30,6 +30,7 @@
 #include "lldb/Utility/RangeMap.h"
 #include "lldb/lldb-private.h"
 
+#include "DWARFContext.h"
 #include "DWARFDataExtractor.h"
 #include "DWARFDefines.h"
 #include "DWARFIndex.h"
@@ -227,7 +228,6 @@
 
   virtual const lldb_private::DWARFDataExtractor _debug_abbrev_data();
   virtual const lldb_private::DWARFDataExtractor _debug_addr_data();
-  const lldb_private::DWARFDataExtractor _debug_aranges_data();
   const lldb_private::DWARFDataExtractor _debug_frame_data();
   virtual const lldb_private::DWARFDataExtractor _debug_info_data();
   const lldb_private::DWARFDataExtractor _debug_line_data();
@@ -458,11 +458,10 @@
   llvm::once_flag m_dwp_symfile_once_flag;
   std::unique_ptr m_dwp_symfile;
 
-  lldb_private::DWARFDataExtractor m_dwarf_data;
+  lldb_private::DWARFContext m_context;
 
   DWARFDataSegment m_data_debug_abbrev;
   DWARFDataSegment m_data_debug_addr;
-  DWARFDataSegment m_data_debug_aranges;
   DWARFDataSegment m_data_debug_frame;
   DWARFDataSegment m_data_debug_info;
   DWARFDataSegment m_data_debug_line;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -355,12 +355,13 @@
   << 32), // Used by SymbolFileDWARFDebugMap to
   // when this class parses .o files to
   // contain the .o file index/ID
-  m_debug_map_module_wp(), m_debug_map_symfile(NULL), m_data_debug_abbrev(),
-  m_data_debug_aranges(), m_data_debug_frame(), m_data_debug_info(),
-  m_data_debug_line(), m_data_debug_macro(), m_data_debug_loc(),
-  m_data_debug_ranges(), m_data_debug_rnglists(), m_data_debug_str(),
-  m_data_apple_names(), m_data_apple_types(), m_data_apple_namespaces(),
-  m_abbr(), m_info(), m_line(), m_fetched_external_modules(false),
+  m_debug_map_module_wp(), m_debug_map_symfile(NULL),
+  m_context(*objfile->GetModule()), m_data_debug_abbrev(),
+  m_data_debug_frame(), m_data_debug_info(), m_data_debug_line(),
+  m_data_debug_macro(), m_data_debug_loc(), m_data_debug_ranges(),
+  m_data_debug_rnglists(), m_data_debug_str(), m_data_apple_names(),
+  m_data_apple_types(), m_data_apple_namespaces(), m_abbr(), m_info(),
+  m_line(), m_fetched_external_modules(false),
   m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), m_ranges(),
   m_unique_ast_type_map() {}
 
@@ -394,15 +395,6 @@
 
 void SymbolFileDWARF::InitializeObject() {
   Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
-  ModuleSP module_sp(m_obj_file->GetModule());
-  if (module_sp) {
-const SectionList *section_list = module_sp->GetSectionList();
-Section *section =
-section_list->FindSectionByName(GetDWARFMachOSegmentName()).get();
-
-if (section)
-  m_obj_file->ReadSectionData(section, m_dwarf_data);
-  }
 
   if (!GetGlobalPluginProperties()->IgnoreFileIndexes()) {
 DWARFDataExtractor apple_names, apple_namespaces, apple_types, 

[Lldb-commits] [PATCH] D59562: [SymbolFileDWARF] Introduce DWARFContext

2019-03-20 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked 5 inline comments as done.
zturner added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp:17
+static const DWARFDataExtractor *LoadOrGetSection(
+Module , const llvm::Optional 
_dwarf_data,
+SectionType section_type, llvm::Optional ) {

clayborg wrote:
> is "mapped_dwarf_data" actually the entire file mmap'ed? If so rename this to 
> "mapped_file_data"?
It's the contents of the `__DWARF` segment on MachO, unless my reading of the 
old code is wrong.

In the old code, `SymbolFileDWARF` would try to read this segment, and if it 
existed set it to `SymbolFileDWARF::m_dwarf_data`.  Then, the 
`ReadCachedSectionData` function would first check if this member had data in 
it, and if so read the data from there instead of from the ObjectFile.

In this modified version of the patch, I call `SetDwarfData` with the contents 
of this section, then pass it through to this function so that we can perform 
the same logic.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp:40
+
+  module.GetObjectFile()->ReadSectionData(section_sp.get(), *extractor);
+  return extractor.getPointer();

clayborg wrote:
> Use:
> 
> ```
>   lldb::offset_t Section::GetSectionData(DataExtractor );
> ```
> We might want to make the ObjectFile::ReadSectionData private so people don't 
> use it and add a doxygen comment to use the above API in Section?
Yes, I like that better.  Thanks for pointing it out.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp:46-49
+void DWARFContext::SetDwarfData(const DWARFDataExtractor ) {
+  m_dwarf_data = dwarf;
+}
+

clayborg wrote:
> Again, is this the entire file that is mapped?
As mentioned elsewhere, this is the contents of `__DWARF`, which I didn't 
understand the purpose of, so I was hesitant to make any drastic changes.  
Perhaps you could clarify the significance of it now though and perhaps suggest 
an alternative approach to what we're doing here.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h:28
+
+  void SetDwarfData(const DWARFDataExtractor );
+

labath wrote:
> clayborg wrote:
> > labath wrote:
> > > Don't want to block progress here over this, but I just wanted to say 
> > > that my impression was that this DwarfData business was a relict from the 
> > > time when we re not mmapping the input object files. These days, we 
> > > always mmap the input, and so I don't believe that should be necessary 
> > > because ObjectFileMachO will automatically perform the DataBuffer slicing 
> > > that you're doing here manually as a part of ReadSectionData.
> > > 
> > > Maybe one of the Apple folks could check whether this is really needed, 
> > > because if it isn't, it will make your job easier here, as well as 
> > > produce an API that is more similar to its llvm counterpart.
> > We don't always mmap. We mmap if the file is local. We read the entire file 
> > if the file is on a network drive. If we don't do this and we mmap a NFS 
> > file, and that mount goes away, we crash the next time we access a page 
> > that hasn't been paged in. So we don't know if stuff is actually mmap'ed or 
> > not.
> Yeah, I wasn't being fully correct here, but this distinction does not really 
> matter here. Even if we don't mmap, we will end up with a full image of the 
> file in memory, so anybody can slice any chunk of that file as he sees fit. 
> Since ObjectFileMachO::ReadSectionData already implements this slicing, 
> there's no advantage in slicing manually here.
The parameter here represents the content of the `__DWARF` data segment on 
MachO.  I don't really know what this is for or the implications of removing 
it, so for now I left it identical to the original code with NFC, and planned 
on addressing this in the future.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h:70
   SymbolFileDWARF *m_dwarf2Data;
+  lldb_private::DWARFContext *m_dwarf_context;
   CompileUnitColl m_compile_units;

clayborg wrote:
> Be nice if this can be a reference and be set in the ctor
Fair enough, I kept it as a pointer for parity with `SymbolFileDWARF* 
m_dwarf2Data`, but a reference is definitely better.


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

https://reviews.llvm.org/D59562



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


[Lldb-commits] [PATCH] D59562: [SymbolFileDWARF] Introduce DWARFContext

2019-03-19 Thread Zachary Turner via Phabricator via lldb-commits
zturner updated this revision to Diff 191421.
zturner added a comment.

I went ahead and just removed the const `get` version entirely, while changing 
the other function name to `getOrLoad` as you suggested.  I have another patch 
while I'll upload after this one that converts all of the rest of the functions 
(except for the virtual ones required for DWO support), and the const version 
of the function was literally never needed, except in one place that was itself 
dead code.  So, in the spirit of YAGNI, it's gone until it demonstrates a need.


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

https://reviews.llvm.org/D59562

Files:
  lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -30,6 +30,7 @@
 #include "lldb/Utility/RangeMap.h"
 #include "lldb/lldb-private.h"
 
+#include "DWARFContext.h"
 #include "DWARFDataExtractor.h"
 #include "DWARFDefines.h"
 #include "DWARFIndex.h"
@@ -227,7 +228,6 @@
 
   virtual const lldb_private::DWARFDataExtractor _debug_abbrev_data();
   virtual const lldb_private::DWARFDataExtractor _debug_addr_data();
-  const lldb_private::DWARFDataExtractor _debug_aranges_data();
   const lldb_private::DWARFDataExtractor _debug_frame_data();
   virtual const lldb_private::DWARFDataExtractor _debug_info_data();
   const lldb_private::DWARFDataExtractor _debug_line_data();
@@ -458,11 +458,11 @@
   llvm::once_flag m_dwp_symfile_once_flag;
   std::unique_ptr m_dwp_symfile;
 
+  lldb_private::DWARFContext m_dwarf_context;
   lldb_private::DWARFDataExtractor m_dwarf_data;
 
   DWARFDataSegment m_data_debug_abbrev;
   DWARFDataSegment m_data_debug_addr;
-  DWARFDataSegment m_data_debug_aranges;
   DWARFDataSegment m_data_debug_frame;
   DWARFDataSegment m_data_debug_info;
   DWARFDataSegment m_data_debug_line;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -355,12 +355,13 @@
   << 32), // Used by SymbolFileDWARFDebugMap to
   // when this class parses .o files to
   // contain the .o file index/ID
-  m_debug_map_module_wp(), m_debug_map_symfile(NULL), m_data_debug_abbrev(),
-  m_data_debug_aranges(), m_data_debug_frame(), m_data_debug_info(),
-  m_data_debug_line(), m_data_debug_macro(), m_data_debug_loc(),
-  m_data_debug_ranges(), m_data_debug_rnglists(), m_data_debug_str(),
-  m_data_apple_names(), m_data_apple_types(), m_data_apple_namespaces(),
-  m_abbr(), m_info(), m_line(), m_fetched_external_modules(false),
+  m_debug_map_module_wp(), m_debug_map_symfile(NULL),
+  m_dwarf_context(*objfile->GetModule()), m_data_debug_abbrev(),
+  m_data_debug_frame(), m_data_debug_info(), m_data_debug_line(),
+  m_data_debug_macro(), m_data_debug_loc(), m_data_debug_ranges(),
+  m_data_debug_rnglists(), m_data_debug_str(), m_data_apple_names(),
+  m_data_apple_types(), m_data_apple_namespaces(), m_abbr(), m_info(),
+  m_line(), m_fetched_external_modules(false),
   m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), m_ranges(),
   m_unique_ast_type_map() {}
 
@@ -400,8 +401,10 @@
 Section *section =
 section_list->FindSectionByName(GetDWARFMachOSegmentName()).get();
 
-if (section)
+if (section) {
   m_obj_file->ReadSectionData(section, m_dwarf_data);
+  m_dwarf_context.SetDwarfData(m_dwarf_data);
+}
   }
 
   if (!GetGlobalPluginProperties()->IgnoreFileIndexes()) {
@@ -573,11 +576,6 @@
   return GetCachedSectionData(eSectionTypeDWARFDebugAddr, m_data_debug_addr);
 }
 
-const DWARFDataExtractor ::get_debug_aranges_data() {
-  return GetCachedSectionData(eSectionTypeDWARFDebugAranges,
-  m_data_debug_aranges);
-}
-
 const DWARFDataExtractor ::get_debug_frame_data() {
   return GetCachedSectionData(eSectionTypeDWARFDebugFrame, m_data_debug_frame);
 }
@@ -692,7 +690,7 @@
 if (get_debug_info_data().GetByteSize() > 0) {
   m_info.reset(new DWARFDebugInfo());
   if (m_info) {
-m_info->SetDwarfData(this);
+m_info->SetDwarfData(this, _dwarf_context);
   }
 }
   }
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h

[Lldb-commits] [PATCH] D59562: [SymbolFileDWARF] Introduce DWARFContext

2019-03-19 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked an inline comment as done.
zturner added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h:30
+
+  const DWARFDataExtractor *maybeLoadArangesData();
+

JDevlieghere wrote:
> Why do we need these two methods? I presume it's because one does work and 
> the other doesn't? If I understand the code correctly, `LoadOrGetSection` 
> will initialize the optional, so could you just check the optional to 
> determine where we should try to do work or not?
It's because one of them is `const` and a const version of the function cannot 
do any work.  It's possible we won't ever need this, and we'll always want a 
"get or create" function, but i can imagine scenarios where we have a const 
reference or const pointer.

This is always a problem with these lazy type interfaces, because in that case 
should you actually use `const_cast` or should you just fail and return 
nullptr?  It's a tough call.  I chose to explicitly embed into the name whether 
the function was doing work (e.g. `maybeLoad`) versus being purely a getter 
that will never do work (e.g. `get`).


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

https://reviews.llvm.org/D59562



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


[Lldb-commits] [PATCH] D59562: [SymbolFileDWARF] Introduce DWARFContext

2019-03-19 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: JDevlieghere, aprantl, clayborg.
Herald added subscribers: jdoerfert, mgorny.

LLVM's DWARF parsing library has a class called `DWARFContext` which holds all 
of the various DWARF data sections and lots of other information.  LLDB's on 
the other hand stores all of this directly in `SymbolFileDWARF` / 
`SymbolFileDWARFDwo` and passes this interface around through the parsing 
library.  Obviously this is incompatible with a world where the low level 
interface does not depend on the high level interface, so we need to move 
towards a model similar to LLVM's - i.e. all of the context needed for low 
level parsing should be in a single class, and that class gets passed around.

This patch is a small incremental step towards achieving this.  The interface 
and internals deviate from LLVM's for technical reasons, but the high level 
idea is the same.  The goal is, eventually, to remove all occurrences of 
`SymbolFileDWARF` from the low level parsing code.

For now I've chosen a very simple section - the `.debug_aranges` section to 
move into `DWARFContext` while leaving everything else unchanged.  In the short 
term this is a bit confusing because now the information you need might come 
from either of 2 different locations.  But it's a huge refactor to do this all 
at once and runs a much higher risk of breaking things.  So I think it would be 
wise to do this in very small pieces.

TL;DR - No functional change


https://reviews.llvm.org/D59562

Files:
  lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -30,6 +30,7 @@
 #include "lldb/Utility/RangeMap.h"
 #include "lldb/lldb-private.h"
 
+#include "DWARFContext.h"
 #include "DWARFDataExtractor.h"
 #include "DWARFDefines.h"
 #include "DWARFIndex.h"
@@ -227,7 +228,6 @@
 
   virtual const lldb_private::DWARFDataExtractor _debug_abbrev_data();
   virtual const lldb_private::DWARFDataExtractor _debug_addr_data();
-  const lldb_private::DWARFDataExtractor _debug_aranges_data();
   const lldb_private::DWARFDataExtractor _debug_frame_data();
   virtual const lldb_private::DWARFDataExtractor _debug_info_data();
   const lldb_private::DWARFDataExtractor _debug_line_data();
@@ -458,11 +458,11 @@
   llvm::once_flag m_dwp_symfile_once_flag;
   std::unique_ptr m_dwp_symfile;
 
+  lldb_private::DWARFContext m_dwarf_context;
   lldb_private::DWARFDataExtractor m_dwarf_data;
 
   DWARFDataSegment m_data_debug_abbrev;
   DWARFDataSegment m_data_debug_addr;
-  DWARFDataSegment m_data_debug_aranges;
   DWARFDataSegment m_data_debug_frame;
   DWARFDataSegment m_data_debug_info;
   DWARFDataSegment m_data_debug_line;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -355,12 +355,13 @@
   << 32), // Used by SymbolFileDWARFDebugMap to
   // when this class parses .o files to
   // contain the .o file index/ID
-  m_debug_map_module_wp(), m_debug_map_symfile(NULL), m_data_debug_abbrev(),
-  m_data_debug_aranges(), m_data_debug_frame(), m_data_debug_info(),
-  m_data_debug_line(), m_data_debug_macro(), m_data_debug_loc(),
-  m_data_debug_ranges(), m_data_debug_rnglists(), m_data_debug_str(),
-  m_data_apple_names(), m_data_apple_types(), m_data_apple_namespaces(),
-  m_abbr(), m_info(), m_line(), m_fetched_external_modules(false),
+  m_debug_map_module_wp(), m_debug_map_symfile(NULL),
+  m_dwarf_context(*objfile->GetModule()), m_data_debug_abbrev(),
+  m_data_debug_frame(), m_data_debug_info(), m_data_debug_line(),
+  m_data_debug_macro(), m_data_debug_loc(), m_data_debug_ranges(),
+  m_data_debug_rnglists(), m_data_debug_str(), m_data_apple_names(),
+  m_data_apple_types(), m_data_apple_namespaces(), m_abbr(), m_info(),
+  m_line(), m_fetched_external_modules(false),
   m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), m_ranges(),
   m_unique_ast_type_map() {}
 
@@ -400,8 +401,10 @@
 Section *section =
 section_list->FindSectionByName(GetDWARFMachOSegmentName()).get();
 
-if (section)
+if (section) {
   m_obj_file->ReadSectionData(section, 

[Lldb-commits] [PATCH] D59276: Delete dead code

2019-03-19 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB356490: Delete dead code. (authored by zturner, committed 
by ).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D59276?vs=190350=191356#toc

Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D59276

Files:
  source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
  source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugLine.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugMacinfo.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugMacinfo.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugMacinfoEntry.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugMacinfoEntry.h
  source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDefines.h
  source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
  source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h

Index: source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp
@@ -74,289 +74,6 @@
 }
 
 //--
-// DumpStateToFile
-//--
-static void DumpStateToFile(dw_offset_t offset,
-const DWARFDebugLine::State ,
-void *userData) {
-  Log *log = (Log *)userData;
-  if (state.row == DWARFDebugLine::State::StartParsingLineTable) {
-// If the row is zero we are being called with the prologue only
-state.prologue->Dump(log);
-log->PutCString("AddressLine   Column File");
-log->PutCString("-- -- -- --");
-  } else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) {
-// Done parsing line table
-  } else {
-log->Printf("0x%16.16" PRIx64 " %6u %6u %6u%s\n", state.address, state.line,
-state.column, state.file, state.end_sequence ? " END" : "");
-  }
-}
-
-//--
-// DWARFDebugLine::DumpLineTableRows
-//--
-bool DWARFDebugLine::DumpLineTableRows(Log *log, SymbolFileDWARF *dwarf2Data,
-   dw_offset_t debug_line_offset) {
-  const DWARFDataExtractor _line_data = dwarf2Data->get_debug_line_data();
-
-  if (debug_line_offset == DW_INVALID_OFFSET) {
-// Dump line table to a single file only
-debug_line_offset = 0;
-while (debug_line_data.ValidOffset(debug_line_offset))
-  debug_line_offset =
-  DumpStatementTable(log, debug_line_data, debug_line_offset);
-  } else {
-// Dump line table to a single file only
-DumpStatementTable(log, debug_line_data, debug_line_offset);
-  }
-  return false;
-}
-
-//--
-// DWARFDebugLine::DumpStatementTable
-//--
-dw_offset_t
-DWARFDebugLine::DumpStatementTable(Log *log,
-   const DWARFDataExtractor _line_data,
-   const dw_offset_t debug_line_offset) {
-  if (debug_line_data.ValidOffset(debug_line_offset)) {
-lldb::offset_t offset = debug_line_offset;
-log->Printf("--"
-"\n"
-"debug_line[0x%8.8x]\n"
-"--"
-"\n",
-debug_line_offset);
-
-if (ParseStatementTable(debug_line_data, , DumpStateToFile, log, nullptr))
-  return offset;
-else
-  return debug_line_offset + 1; // Skip to next byte in .debug_line section
-  }
-
-  return DW_INVALID_OFFSET;
-}
-
-//--
-// DumpOpcodes
-//--
-bool DWARFDebugLine::DumpOpcodes(Log *log, SymbolFileDWARF *dwarf2Data,

[Lldb-commits] [PATCH] D59291: [Object] Add basic minidump support

2019-03-19 Thread Zachary Turner via Phabricator via lldb-commits
zturner accepted this revision.
zturner added a comment.

This LGTM, but let's give it a day to see if anyone else chimes in with 
comments.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59291



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


[Lldb-commits] [PATCH] D59498: [DWARF] Remove a couple of log statements

2019-03-19 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB356469: Remove a couple of log statements. (authored by 
zturner, committed by ).
Herald added a subscriber: abidh.
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D59498?vs=191118=191331#toc

Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D59498

Files:
  source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
@@ -13,13 +13,11 @@
 
 #include 
 
-#include "lldb/Utility/Log.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/Timer.h"
 
 #include "DWARFUnit.h"
 #include "DWARFDebugInfo.h"
-#include "LogChannelDWARF.h"
 #include "SymbolFileDWARF.h"
 
 using namespace lldb;
@@ -118,30 +116,8 @@
   Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION,
  static_cast(this));
 
-  Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
-  size_t orig_arange_size = 0;
-  if (log) {
-orig_arange_size = m_aranges.GetSize();
-log->Printf("DWARFDebugAranges::Sort(minimize = %u) with %" PRIu64
-" entries",
-minimize, (uint64_t)orig_arange_size);
-  }
-
   m_aranges.Sort();
   m_aranges.CombineConsecutiveEntriesWithEqualData();
-
-  if (log) {
-if (minimize) {
-  const size_t new_arange_size = m_aranges.GetSize();
-  const size_t delta = orig_arange_size - new_arange_size;
-  log->Printf("DWARFDebugAranges::Sort() %" PRIu64
-  " entries after minimizing (%" PRIu64
-  " entries combined for %" PRIu64 " bytes saved)",
-  (uint64_t)new_arange_size, (uint64_t)delta,
-  (uint64_t)delta * sizeof(Range));
-}
-Dump(log);
-  }
 }
 
 //--
Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
@@ -22,7 +22,6 @@
 #include "DWARFDebugInfo.h"
 #include "DWARFDebugInfoEntry.h"
 #include "DWARFFormValue.h"
-#include "LogChannelDWARF.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -48,17 +47,10 @@
 
   assert(m_dwarf2Data);
 
-  Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
-
   m_cu_aranges_up = llvm::make_unique();
   const DWARFDataExtractor _aranges_data =
   m_dwarf2Data->get_debug_aranges_data();
   if (debug_aranges_data.GetByteSize() > 0) {
-if (log)
-  log->Printf(
-  "DWARFDebugInfo::GetCompileUnitAranges() for \"%s\" from "
-  ".debug_aranges",
-  m_dwarf2Data->GetObjectFile()->GetFileSpec().GetPath().c_str());
 llvm::Error error = m_cu_aranges_up->extract(debug_aranges_data);
 if (error)
   return std::move(error);
@@ -74,22 +66,13 @@
 
   // Manually build arange data for everything that wasn't in the
   // .debug_aranges table.
-  bool printed = false;
   const size_t num_compile_units = GetNumCompileUnits();
   for (size_t idx = 0; idx < num_compile_units; ++idx) {
 DWARFUnit *cu = GetCompileUnitAtIndex(idx);
 
 dw_offset_t offset = cu->GetOffset();
-if (cus_with_data.find(offset) == cus_with_data.end()) {
-  if (log) {
-if (!printed)
-  log->Printf(
-  "DWARFDebugInfo::GetCompileUnitAranges() for \"%s\" by parsing",
-  m_dwarf2Data->GetObjectFile()->GetFileSpec().GetPath().c_str());
-printed = true;
-  }
+if (cus_with_data.find(offset) == cus_with_data.end())
   cu->BuildAddressRangeTable(m_dwarf2Data, m_cu_aranges_up.get());
-}
   }
 
   const bool minimize = true;
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -165,15 +165,6 @@
 
   DWARFDebugInfoEntry die;
   // Keep a flat array of the DIE for binary lookup by DIE offset
-  Log *log(
-  LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_LOOKUPS));
-  if (log) {
-m_dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
-log,
-"DWARFUnit::ExtractDIEsIfNeeded () for compile unit at "
-".debug_info[0x%8.8x]",
-GetOffset());
-  }
 
   uint32_t depth = 0;
   // We are in our compile unit, parse starting at the offset we were told to
@@ -834,15 +825,6 @@
 const DWARFDebugAranges ::GetFunctionAranges() {
   if (m_func_aranges_up 

[Lldb-commits] [PATCH] D59498: [DWARF] Remove a couple of log statements

2019-03-18 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked 4 inline comments as done.
zturner added a comment.

In all cases, I think the question worth asking is not "could it be used for 
X", but rather "how often is it actually used for X".  Otherwise, it's just 
technical debt IMO.  There's a lot of things that are possible in theory, but 
unless it exhibits value in practice, YAGNI.




Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp:121-144
-  Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
-  size_t orig_arange_size = 0;
-  if (log) {
-orig_arange_size = m_aranges.GetSize();
-log->Printf("DWARFDebugAranges::Sort(minimize = %u) with %" PRIu64
-" entries",
-minimize, (uint64_t)orig_arange_size);

clayborg wrote:
> These two seem useful. They are only when logging .debug_aranges with 
> DWARF_LOG_DEBUG_ARANGES. What is left if we remove this?
What useful information does it tell you though?  That the function was called? 
 That's the part that doesn't seem useful.  It gives you some information about 
bytes saved and entries combined, which could arguably be useful, but are you 
aware of any situations where anyone actually looked at this log statement?  
One option is moving it up to a higher level if so, but I think it's worth 
seriously asking why you would want to know this, and if you did want to know 
it, why running LLDB in a debugger and/or adding some temporary logging to 
diagnose a specific problem wouldn't be sufficient.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp:93
-}
   }
 

clayborg wrote:
> All above logs seem useful. Sometimes we don't get a .debug_aranges section 
> which means we must parse the address ranges manually. When we are logging 
> .debug_aranges, it is handy to know where the info came from (.debug_aranges, 
> or manual index).
In that case, we can move the log up to a much higher level, and print one log 
all the way up in `SymbolFileDWARF` that says "aranges not present, using range 
info from manual index".  It doesn't need to be in the low level parsing code



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp:168-176
-  Log *log(
-  LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_LOOKUPS));
-  if (log) {
-m_dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
-log,
-"DWARFUnit::ExtractDIEsIfNeeded () for compile unit at "
-".debug_info[0x%8.8x]",

clayborg wrote:
> It is nice to know when we parse all DIEs for a compile unit. This helps us 
> to verify that our lazy DWARF parsing is working. When we have good 
> accelerator tables, like the Apple ones or DWARF 5 ones, then we will only 
> parse the DIEs in a compile unit when we need to. Seems like we need one when 
> it starts and one when it ends so we could see timestamp times...
This function already has this at the beginning:

```
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
  static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
  Timer scoped_timer(func_cat, "%8.8x: DWARFUnit::ExtractDIEsIfNeeded()", 
m_offset);
```

if timing information is needed.  There are also other options, like running a 
profiler or function tracer.  For verifying that the lazy parsing is working, 
we should just have tests, not log statements that require someone to manually 
inspect.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp:837-844
-Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
-
-if (log) {
-  m_dwarf->GetObjectFile()->GetModule()->LogMessage(
-  log,
-  "DWARFUnit::GetFunctionAranges() for compile unit at "
-  ".debug_info[0x%8.8x]",

clayborg wrote:
> This seems useful as it tells us when we manually index a compile unit for 
> all function address ranges which can be expensive.
This information could be stored at a higher level, it doesn't have to be here.


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

https://reviews.llvm.org/D59498



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


[Lldb-commits] [PATCH] D59498: [DWARF] Remove a couple of log statements

2019-03-18 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: JDevlieghere, aprantl.
Herald added a subscriber: jdoerfert.

I don't find these specific log statements particularly high value, as they 
appear more just like simple function tracing calls (i.e. they log low level 
implementation details, not high level program flow) so I'm removing them from 
the low level DWARF parsing libraries.

I'm prepared to be convinced that we actually should do something other than 
outright delete them, but I did look at each one specifically as well as the 
surrounding context before deciding that they were probably ok to delete.

My reasoning for deleting these is that they are all on the success codepath 
and have a very limited number of call-sites (in most cases actually just 1), 
so in most cases a previous log statement would necessarily be followed by the 
deleted log statement, so therefore it doesn't actually add much (if any) 
diagnostic value.


https://reviews.llvm.org/D59498

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -165,15 +165,6 @@
 
   DWARFDebugInfoEntry die;
   // Keep a flat array of the DIE for binary lookup by DIE offset
-  Log *log(
-  LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_LOOKUPS));
-  if (log) {
-m_dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
-log,
-"DWARFUnit::ExtractDIEsIfNeeded () for compile unit at "
-".debug_info[0x%8.8x]",
-GetOffset());
-  }
 
   uint32_t depth = 0;
   // We are in our compile unit, parse starting at the offset we were told to
@@ -834,15 +825,6 @@
 const DWARFDebugAranges ::GetFunctionAranges() {
   if (m_func_aranges_up == NULL) {
 m_func_aranges_up.reset(new DWARFDebugAranges());
-Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
-
-if (log) {
-  m_dwarf->GetObjectFile()->GetModule()->LogMessage(
-  log,
-  "DWARFUnit::GetFunctionAranges() for compile unit at "
-  ".debug_info[0x%8.8x]",
-  GetOffset());
-}
 const DWARFDebugInfoEntry *die = DIEPtr();
 if (die)
   die->BuildFunctionAddressRangeTable(m_dwarf, this,
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
@@ -22,7 +22,6 @@
 #include "DWARFDebugInfo.h"
 #include "DWARFDebugInfoEntry.h"
 #include "DWARFFormValue.h"
-#include "LogChannelDWARF.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -48,17 +47,10 @@
 
   assert(m_dwarf2Data);
 
-  Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
-
   m_cu_aranges_up = llvm::make_unique();
   const DWARFDataExtractor _aranges_data =
   m_dwarf2Data->get_debug_aranges_data();
   if (debug_aranges_data.GetByteSize() > 0) {
-if (log)
-  log->Printf(
-  "DWARFDebugInfo::GetCompileUnitAranges() for \"%s\" from "
-  ".debug_aranges",
-  m_dwarf2Data->GetObjectFile()->GetFileSpec().GetPath().c_str());
 llvm::Error error = m_cu_aranges_up->extract(debug_aranges_data);
 if (error)
   return std::move(error);
@@ -74,22 +66,13 @@
 
   // Manually build arange data for everything that wasn't in the
   // .debug_aranges table.
-  bool printed = false;
   const size_t num_compile_units = GetNumCompileUnits();
   for (size_t idx = 0; idx < num_compile_units; ++idx) {
 DWARFUnit *cu = GetCompileUnitAtIndex(idx);
 
 dw_offset_t offset = cu->GetOffset();
-if (cus_with_data.find(offset) == cus_with_data.end()) {
-  if (log) {
-if (!printed)
-  log->Printf(
-  "DWARFDebugInfo::GetCompileUnitAranges() for \"%s\" by parsing",
-  m_dwarf2Data->GetObjectFile()->GetFileSpec().GetPath().c_str());
-printed = true;
-  }
+if (cus_with_data.find(offset) == cus_with_data.end())
   cu->BuildAddressRangeTable(m_dwarf2Data, m_cu_aranges_up.get());
-}
   }
 
   const bool minimize = true;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
@@ -13,13 +13,11 @@
 
 #include 
 
-#include "lldb/Utility/Log.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/Timer.h"
 
 #include "DWARFUnit.h"
 #include "DWARFDebugInfo.h"
-#include "LogChannelDWARF.h"
 #include "SymbolFileDWARF.h"
 
 using namespace lldb;
@@ -118,30 +116,8 

[Lldb-commits] [PATCH] D59430: Update DwarfDebugInfoEntry to use llvm::Error and llvm::Expected

2019-03-18 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

ping


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

https://reviews.llvm.org/D59430



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


[Lldb-commits] [PATCH] D59276: Delete dead code

2019-03-18 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

ping


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

https://reviews.llvm.org/D59276



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


[Lldb-commits] [PATCH] D59433: Fix UUID decoding from minidump files.

2019-03-15 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

"MinidumpNew" is a little bit vague.  What's "new" about it?  Is there a way we 
could come up with a better name?

As an aside, since there's no interactivity in these tests, they seem like a 
good candidate for lit/Minidump, with 1 file for each test.  Something like:

  ; zero-uuid-modules.test
  ; RUN: lldb -core %S/Inputs/linux-arm-zero-uuids.dmp -S %p | FileCheck %s
  
  target modules list
  
  ; CHECK: [  0] -----  
  /tmp/a
  ; CHECK: [  1] -----  
  /tmp/b

Let's see what Pavel thinks though.


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

https://reviews.llvm.org/D59433



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


[Lldb-commits] [PATCH] D59427: [lldb] [API] Split SBRegistry into smaller files

2019-03-15 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

Or better yet, make it a static method on each SB class.  E.g. 
`SBTarget::InitializeReproducerRegistry();` etc, one for each class.

Random thought, but this all seems like a very high maintenance strategy, 
having to manually update this registry when methods are added or removed.  Did 
you ever consider auto-generating them by parsing the SWIG?


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D59427



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


[Lldb-commits] [PATCH] D59430: Update DwarfDebugInfoEntry to use llvm::Error and llvm::Expected

2019-03-15 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked 3 inline comments as done.
zturner added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp:218
+  assert(offset < cu->GetNextCompileUnitOffset() &&
+ debug_info_data.ValidOffset(offset));
 

aprantl wrote:
> Should this be a lldb_assert() followed by `return make_error` instead?
I think it's reasonable to treat this as an internal consistency check, where 
the pre-condition of this function is "offset must be a valid offset".  Similar 
to indexing an array out of bounds, your `operator[]` implementation would 
assert that the index you passed is within range.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp:1170
   const dw_offset_t die_offset, Stream ) {
-  if (dwarf2Data == NULL) {
-s.PutCString("NULL");
-return false;
-  }
+  assert(dwarf2Data);
 

aprantl wrote:
> Instead of passing a pointer and asserting, wouldn't it be better to pass a 
> `SymbolFileDWARF &`?
Yes, but I was trying to keep the change set minimal, and doing so would 
propagate that change many levels up the callstack until we reach 
`SymbolFileDwarf`, at which point we would change all calls to pass `*this` 
instead of `this`.  That's a reasonable change, but should probably be done 
separately to keep logically separate changes separate.

Note that, long term, we just won't even pass a `SymbolFileDWARF` to this 
function at all, because if the point is to decouple the high and low level 
interfaces, then the low-level interface can't know about the high level 
interface.


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

https://reviews.llvm.org/D59430



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


[Lldb-commits] [PATCH] D59430: Update DwarfDebugInfoEntry to use llvm::Error and llvm::Expected

2019-03-15 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: clayborg, aprantl, labath.
Herald added a subscriber: jdoerfert.

This hits the next batch of classes and adds better error handling and recovery 
to them.  After this, the only remaining case is the line table stuff, at which 
point we should be able to get all logging out of the low level DWARF parsing 
entirely.


https://reviews.llvm.org/D59430

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -723,18 +723,25 @@
 }
 
 DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() {
-  if (m_ranges == NULL) {
-static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
-Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION,
-   static_cast(this));
+  if (m_ranges)
+return m_ranges.get();
+
+  static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
+  Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION,
+ static_cast(this));
 
-if (get_debug_ranges_data().GetByteSize() > 0)
-  m_ranges.reset(new DWARFDebugRanges());
-else if (get_debug_rnglists_data().GetByteSize() > 0)
-  m_ranges.reset(new DWARFDebugRngLists());
+  if (get_debug_ranges_data().GetByteSize() > 0)
+m_ranges = llvm::make_unique();
+  else if (get_debug_rnglists_data().GetByteSize() > 0)
+m_ranges = llvm::make_unique();
+  else
+return nullptr;
 
-if (m_ranges)
-  m_ranges->Extract(this);
+  auto error = m_ranges->extract(this);
+  if (error) {
+Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
+LLDB_LOG_ERROR(log, std::move(error),
+   "Unable to get debug range information: {0}");
   }
   return m_ranges.get();
 }
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
@@ -12,13 +12,15 @@
 #include "DWARFDIE.h"
 #include "SymbolFileDWARF.h"
 
+#include "llvm/Support/Error.h"
+
 #include 
 
 class DWARFDebugRangesBase {
 public:
   virtual ~DWARFDebugRangesBase(){};
 
-  virtual void Extract(SymbolFileDWARF *dwarf2Data) = 0;
+  virtual llvm::Error extract(SymbolFileDWARF *dwarf2Data) = 0;
   virtual bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset,
   DWARFRangeList _list) const = 0;
   virtual uint64_t GetOffset(size_t Index) const = 0;
@@ -28,7 +30,7 @@
 public:
   DWARFDebugRanges();
 
-  void Extract(SymbolFileDWARF *dwarf2Data) override;
+  llvm::Error extract(SymbolFileDWARF *dwarf2Data) override;
   bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset,
   DWARFRangeList _list) const override;
   uint64_t GetOffset(size_t Index) const override;
@@ -38,8 +40,9 @@
lldb::offset_t *offset_ptr, dw_addr_t cu_base_addr);
 
 protected:
-  bool Extract(SymbolFileDWARF *dwarf2Data, lldb::offset_t *offset_ptr,
-   DWARFRangeList _list);
+  llvm::Error extractOne(SymbolFileDWARF *dwarf2Data,
+ lldb::offset_t *offset_ptr,
+ DWARFRangeList _list);
 
   typedef std::map range_map;
   typedef range_map::iterator range_map_iterator;
@@ -56,7 +59,7 @@
   };
 
 public:
-  void Extract(SymbolFileDWARF *dwarf2Data) override;
+  llvm::Error extract(SymbolFileDWARF *dwarf2Data) override;
   bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset,
   DWARFRangeList _list) const override;
   uint64_t GetOffset(size_t Index) const override;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
@@ -10,6 +10,7 @@
 #include "DWARFUnit.h"
 #include "SymbolFileDWARF.h"
 #include "lldb/Utility/Stream.h"
+#include "llvm/Object/Error.h"
 #include 
 
 using namespace lldb_private;
@@ -29,23 +30,33 @@
 
 DWARFDebugRanges::DWARFDebugRanges() : m_range_map() {}
 
-void DWARFDebugRanges::Extract(SymbolFileDWARF *dwarf2Data) {
+llvm::Error DWARFDebugRanges::extract(SymbolFileDWARF *dwarf2Data) {
   DWARFRangeList range_list;
   lldb::offset_t offset = 0;
   dw_offset_t debug_ranges_offset = offset;
-  while (Extract(dwarf2Data, , range_list)) {
+
+  const DWARFDataExtractor _ranges_data =
+  

[Lldb-commits] [PATCH] D59381: Change CompileUnit and ARanges interfaces to propagate errors

2019-03-15 Thread Zachary Turner via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Revision".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356278: Return Error and Expected from more DWARF 
interfaces. (authored by zturner, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59381?vs=190700=190851#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59381

Files:
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
@@ -10,12 +10,14 @@
 #define SymbolFileDWARF_DWARFCompileUnit_h_
 
 #include "DWARFUnit.h"
+#include "llvm/Support/Error.h"
 
 class DWARFCompileUnit : public DWARFUnit {
 public:
-  static DWARFUnitSP Extract(SymbolFileDWARF *dwarf2Data,
- const lldb_private::DWARFDataExtractor _info,
- lldb::offset_t *offset_ptr);
+  static llvm::Expected
+  extract(SymbolFileDWARF *dwarf2Data,
+  const lldb_private::DWARFDataExtractor _info,
+  lldb::offset_t *offset_ptr);
   void Dump(lldb_private::Stream *s) const override;
 
   //--
Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
@@ -10,6 +10,7 @@
 
 #include "SymbolFileDWARF.h"
 #include "lldb/Utility/Stream.h"
+#include "llvm/Object/Error.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -17,50 +18,64 @@
 DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF *dwarf2Data)
 : DWARFUnit(dwarf2Data) {}
 
-DWARFUnitSP DWARFCompileUnit::Extract(SymbolFileDWARF *dwarf2Data,
-  const DWARFDataExtractor _info,
-  lldb::offset_t *offset_ptr) {
+llvm::Expected
+DWARFCompileUnit::extract(SymbolFileDWARF *dwarf2Data,
+  const DWARFDataExtractor _info,
+  lldb::offset_t *offset_ptr) {
+  assert(debug_info.ValidOffset(*offset_ptr));
+
   // std::make_shared would require the ctor to be public.
   std::shared_ptr cu_sp(new DWARFCompileUnit(dwarf2Data));
 
   cu_sp->m_offset = *offset_ptr;
 
-  if (debug_info.ValidOffset(*offset_ptr)) {
-dw_offset_t abbr_offset;
-const DWARFDebugAbbrev *abbr = dwarf2Data->DebugAbbrev();
-cu_sp->m_length = debug_info.GetDWARFInitialLength(offset_ptr);
-cu_sp->m_version = debug_info.GetU16(offset_ptr);
-
-if (cu_sp->m_version == 5) {
-  cu_sp->m_unit_type = debug_info.GetU8(offset_ptr);
-  cu_sp->m_addr_size = debug_info.GetU8(offset_ptr);
-  abbr_offset = debug_info.GetDWARFOffset(offset_ptr);
-
-  if (cu_sp->m_unit_type == llvm::dwarf::DW_UT_skeleton)
-cu_sp->m_dwo_id = debug_info.GetU64(offset_ptr);
-} else {
-  abbr_offset = debug_info.GetDWARFOffset(offset_ptr);
-  cu_sp->m_addr_size = debug_info.GetU8(offset_ptr);
-}
-
-bool length_OK =
-debug_info.ValidOffset(cu_sp->GetNextCompileUnitOffset() - 1);
-bool version_OK = SymbolFileDWARF::SupportedVersion(cu_sp->m_version);
-bool abbr_offset_OK =
-dwarf2Data->get_debug_abbrev_data().ValidOffset(abbr_offset);
-bool addr_size_OK = (cu_sp->m_addr_size == 4) || (cu_sp->m_addr_size == 8);
-
-if (length_OK && version_OK && addr_size_OK && abbr_offset_OK &&
-abbr != NULL) {
-  cu_sp->m_abbrevs = abbr->GetAbbreviationDeclarationSet(abbr_offset);
-  return cu_sp;
-}
-
-// reset the offset to where we tried to parse from if anything went wrong
-*offset_ptr = cu_sp->m_offset;
+  dw_offset_t abbr_offset;
+  const DWARFDebugAbbrev *abbr = dwarf2Data->DebugAbbrev();
+  if (!abbr)
+return llvm::make_error(
+"No debug_abbrev data");
+
+  cu_sp->m_length = debug_info.GetDWARFInitialLength(offset_ptr);
+  cu_sp->m_version = debug_info.GetU16(offset_ptr);
+
+  if (cu_sp->m_version == 5) {
+

[Lldb-commits] [PATCH] D59400: [lldb-vscode] Fix dangling pointer in request_evaluate.

2019-03-14 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

Another option would be to just assign it to a `std::string`, but this is fine 
too.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D59400



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


[Lldb-commits] [PATCH] D59381: Change CompileUnit and ARanges interfaces to propagate errors

2019-03-14 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked 2 inline comments as done.
zturner added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp:25
+  lldb::offset_t *offset_ptr) {
+  assert(debug_info.ValidOffset(*offset_ptr));
+

clayborg wrote:
> We have error checking now, use it instead of asserting? We are checking it 
> with the assert anyways, so might as well check and return an error?
The reason I changed this is because the logic is simpler if we assert, and I 
examined all call-sites and ensured that the value is already sanitized before 
we call this function.

In this case, the only actual call to this function is here:

```
while (debug_info_data.ValidOffset(offset)) {
llvm::Expected cu_sp =
DWARFCompileUnit::extract(m_dwarf2Data, debug_info_data, );
   ...
}
```

so we have already verified that the offset is valid before we even call the 
function.  In fact, that is the most natural way to parse compile units anyway, 
by running a loop until you're at the end of the data, so it would be hard to 
imagine someone could actually intend to call the function

Because of this, I'm considering the assert here to be an enforcement of 
internal consistency and not one of user input



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp:46
+llvm::Expected DWARFDebugInfo::GetCompileUnitAranges() {
+  assert(m_cu_aranges_up && m_dwarf2Data);
+

clayborg wrote:
> This logic is wrong. We cache the m_cu_arange_up. If it is NULL then we 
> build. If not, we return what we have. Maybe change this to:
> 
> ```
> if (m_cu_aranges_up)
>   return *m_cu_aranges_up;
> ```
Yes, you are right.  I'm at home today on my Windows box so I couldn't really 
run the test suite, but that certainly would have caught this.  Thanks for 
pointing it out!  I'll make sure to fix when I'm back at work before submitting.


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

https://reviews.llvm.org/D59381



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


[Lldb-commits] [PATCH] D59381: Change CompileUnit and ARanges interfaces to propagate errors

2019-03-14 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: clayborg, labath, aprantl.
Herald added a subscriber: jdoerfert.

This is a continuation of D59370  for compile 
units and aranges.


https://reviews.llvm.org/D59381

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1758,8 +1758,18 @@
 
 DWARFDebugInfo *debug_info = DebugInfo();
 if (debug_info) {
-  const dw_offset_t cu_offset =
-  debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
+  llvm::Expected aranges =
+  debug_info->GetCompileUnitAranges();
+  if (!aranges) {
+Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO |
+DWARF_LOG_DEBUG_ARANGES);
+LLDB_LOG_ERROR(log, aranges.takeError(),
+   "SymbolFileDWARF::ResolveSymbolContext failed to get cu "
+   "aranges.  {0}");
+return 0;
+  }
+
+  const dw_offset_t cu_offset = aranges->FindAddress(file_vm_addr);
   if (cu_offset == DW_INVALID_OFFSET) {
 // Global variables are not in the compile unit address ranges. The
 // only way to currently find global variables is to iterate over the
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
@@ -12,11 +12,12 @@
 #include 
 #include 
 
-#include "DWARFUnit.h"
 #include "DWARFDIE.h"
+#include "DWARFUnit.h"
 #include "SymbolFileDWARF.h"
 #include "lldb/Core/STLUtils.h"
 #include "lldb/lldb-private.h"
+#include "llvm/Support/Error.h"
 
 typedef std::multimap
 CStringToDIEMap;
@@ -50,7 +51,7 @@
 (1 << 2) // Show all parent DIEs when dumping single DIEs
   };
 
-  DWARFDebugAranges ();
+  llvm::Expected GetCompileUnitAranges();
 
 protected:
   static bool OffsetLessThanCompileUnitOffset(dw_offset_t offset,
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
@@ -42,69 +42,84 @@
   m_compile_units.clear();
 }
 
-DWARFDebugAranges ::GetCompileUnitAranges() {
-  if (m_cu_aranges_up == NULL && m_dwarf2Data) {
-Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
-
-m_cu_aranges_up.reset(new DWARFDebugAranges());
-const DWARFDataExtractor _aranges_data =
-m_dwarf2Data->get_debug_aranges_data();
-if (debug_aranges_data.GetByteSize() > 0) {
-  if (log)
-log->Printf(
-"DWARFDebugInfo::GetCompileUnitAranges() for \"%s\" from "
-".debug_aranges",
-m_dwarf2Data->GetObjectFile()->GetFileSpec().GetPath().c_str());
-  m_cu_aranges_up->Extract(debug_aranges_data);
-}
+llvm::Expected DWARFDebugInfo::GetCompileUnitAranges() {
+  assert(m_cu_aranges_up && m_dwarf2Data);
+
+  Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
+
+  m_cu_aranges_up = llvm::make_unique();
+  const DWARFDataExtractor _aranges_data =
+  m_dwarf2Data->get_debug_aranges_data();
+  if (debug_aranges_data.GetByteSize() > 0) {
+if (log)
+  log->Printf(
+  "DWARFDebugInfo::GetCompileUnitAranges() for \"%s\" from "
+  ".debug_aranges",
+  m_dwarf2Data->GetObjectFile()->GetFileSpec().GetPath().c_str());
+llvm::Error error = m_cu_aranges_up->extract(debug_aranges_data);
+if (!error)
+  return std::move(error);
+  }
 
-// Make a list of all CUs represented by the arange data in the file.
-std::set cus_with_data;
-for (size_t n = 0; n < m_cu_aranges_up->GetNumRanges(); n++) {
-  dw_offset_t offset = m_cu_aranges_up->OffsetAtIndex(n);
-  if (offset != DW_INVALID_OFFSET)
-cus_with_data.insert(offset);
-}
+  // Make a list of all CUs represented by the arange data in the file.
+  std::set cus_with_data;
+  for (size_t n = 0; n < m_cu_aranges_up->GetNumRanges(); n++) {
+dw_offset_t offset = m_cu_aranges_up->OffsetAtIndex(n);
+if (offset != DW_INVALID_OFFSET)
+  

[Lldb-commits] [PATCH] D59370: Return llvm::Error and llvm::Expected from some DWARF parsing functions

2019-03-14 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB356190: Return llvm::Error and llvm::Expected from DWARF 
parsing code. (authored by zturner, committed by ).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D59370?vs=190654=190698#toc

Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D59370

Files:
  source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  source/Plugins/SymbolFile/DWARF/DWARFDefines.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
@@ -35,8 +35,11 @@
   void Clear();
   dw_offset_t GetOffset() const { return m_offset; }
   void Dump(lldb_private::Stream *s) const;
-  bool Extract(const lldb_private::DWARFDataExtractor ,
-   lldb::offset_t *offset_ptr);
+
+  /// Extract all abbrev decls in a set.  Returns llvm::ErrorSuccess() on
+  /// success, and an appropriate llvm::Error object otherwise.
+  llvm::Error extract(const lldb_private::DWARFDataExtractor ,
+  lldb::offset_t *offset_ptr);
   // void Encode(BinaryStreamBuf& debug_abbrev_buf) const;
   dw_uleb128_t
   AppendAbbrevDeclSequential(const DWARFAbbreviationDeclaration );
@@ -64,7 +67,11 @@
   const DWARFAbbreviationDeclarationSet *
   GetAbbreviationDeclarationSet(dw_offset_t cu_abbr_offset) const;
   void Dump(lldb_private::Stream *s) const;
-  void Parse(const lldb_private::DWARFDataExtractor );
+
+  /// Extract all abbreviations for a particular compile unit.  Returns
+  /// llvm::ErrorSuccess() on success, and an appropriate llvm::Error object
+  /// otherwise.
+  llvm::Error parse(const lldb_private::DWARFDataExtractor );
   void GetUnsupportedForms(std::set _forms) const;
 
 protected:
Index: source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -11,6 +11,8 @@
 #include "lldb/Core/dwarf.h"
 #include "lldb/Utility/Stream.h"
 
+#include "llvm/Object/Error.h"
+
 #include "DWARFFormValue.h"
 
 using namespace lldb_private;
@@ -23,41 +25,48 @@
 : m_code(InvalidCode), m_tag(tag), m_has_children(has_children),
   m_attributes() {}
 
-bool DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor ,
-   lldb::offset_t *offset_ptr) {
-  return Extract(data, offset_ptr, data.GetULEB128(offset_ptr));
-}
+llvm::Expected
+DWARFAbbreviationDeclaration::extract(const DWARFDataExtractor ,
+  lldb::offset_t *offset_ptr) {
+  m_code = data.GetULEB128(offset_ptr);
+  if (m_code == 0)
+return DWARFEnumState::Complete;
 
-bool DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor ,
-   lldb::offset_t *offset_ptr,
-   dw_uleb128_t code) {
-  m_code = code;
   m_attributes.clear();
-  if (m_code) {
-m_tag = data.GetULEB128(offset_ptr);
-m_has_children = data.GetU8(offset_ptr);
-
-while (data.ValidOffset(*offset_ptr)) {
-  dw_attr_t attr = data.GetULEB128(offset_ptr);
-  dw_form_t form = data.GetULEB128(offset_ptr);
-  DWARFFormValue::ValueType val;
-
-  if (form == DW_FORM_implicit_const)
-val.value.sval = data.GetULEB128(offset_ptr);
-
-  if (attr && form)
-m_attributes.push_back(DWARFAttribute(attr, form, val));
-  else
-break;
-}
-
-return m_tag != 0;
-  } else {
-m_tag = 0;
-m_has_children = 0;
+  m_tag = data.GetULEB128(offset_ptr);
+  if (m_tag == DW_TAG_null) {
+// FIXME: According to the DWARF spec this may actually be malformed.
+// Should this return an error instead?
+return DWARFEnumState::Complete;
+  }
+
+  m_has_children = data.GetU8(offset_ptr);
+
+  while (data.ValidOffset(*offset_ptr)) {
+dw_attr_t attr = data.GetULEB128(offset_ptr);
+dw_form_t form = data.GetULEB128(offset_ptr);
+
+// This is the last attribute for this abbrev decl, but there may still be
+// more abbrev decls, so return MoreItems to indicate to the caller that
+// they should call this function again.
+if (!attr && !form)
+  return DWARFEnumState::MoreItems;
+
+if (!attr || !form)
+  return llvm::make_error(
+  "malformed abbreviation declaration attribute");
+
+DWARFFormValue::ValueType val;
+
+if (form == DW_FORM_implicit_const)
+

[Lldb-commits] [PATCH] D59291: [Object] Add basic minidump support

2019-03-14 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: include/llvm/Object/Minidump.h:77
+   ArrayRef Streams,
+   std::unordered_map StreamMap)
+  : Binary(ID_Minidump, Source), Header(Header), Streams(Streams),

jhenderson wrote:
> Are you deliberately making a copy of StreamMap? I would normally expect this 
> to be passed by some form of reference.
It's actually not making a copy.  This gives the caller the ability to write 
`std::move(StreamMap)`, which will actually *prevent* a copy.  If you change 
this to a reference, then in order to store it in the class by value a copy 
must be made.  By passing it by value in the constructor, you can prevent *any* 
copies from being made, because the caller can move it in at construction time 
(and indeed, this is what happens later on).


However, I would also ask why we're using `std::unordered_map<>` instead of 
`llvm::DenseMap<>`, which is generally more efficient.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59291



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


[Lldb-commits] [PATCH] D59370: Return llvm::Error and llvm::Expected from some DWARF parsing functions

2019-03-14 Thread Zachary Turner via Phabricator via lldb-commits
zturner updated this revision to Diff 190654.
zturner added a comment.

Fix half-written comment and add comments to other extraction function 
declarations.


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

https://reviews.llvm.org/D59370

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -660,14 +660,23 @@
 }
 
 DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() {
-  if (m_abbr == NULL) {
-const DWARFDataExtractor _abbrev_data = get_debug_abbrev_data();
-if (debug_abbrev_data.GetByteSize() > 0) {
-  m_abbr.reset(new DWARFDebugAbbrev());
-  if (m_abbr)
-m_abbr->Parse(debug_abbrev_data);
-}
+  if (m_abbr)
+return m_abbr.get();
+
+  const DWARFDataExtractor _abbrev_data = get_debug_abbrev_data();
+  if (debug_abbrev_data.GetByteSize() == 0)
+return nullptr;
+
+  auto abbr = llvm::make_unique();
+  llvm::Error error = abbr->parse(debug_abbrev_data);
+  if (error) {
+Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
+LLDB_LOG_ERROR(log, std::move(error),
+   "Unable to read .debug_abbrev section: {0}");
+return nullptr;
   }
+
+  m_abbr = std::move(abbr);
   return m_abbr.get();
 }
 
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
@@ -14,6 +14,8 @@
 
 namespace lldb_private {
 
+enum class DWARFEnumState { MoreItems, Complete };
+
 typedef uint32_t DRC_class; // Holds DRC_* class bitfields
 
 enum DW_TAG_Category {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
@@ -35,8 +35,11 @@
   void Clear();
   dw_offset_t GetOffset() const { return m_offset; }
   void Dump(lldb_private::Stream *s) const;
-  bool Extract(const lldb_private::DWARFDataExtractor ,
-   lldb::offset_t *offset_ptr);
+
+  /// Extract all abbrev decls in a set.  Returns llvm::ErrorSuccess() on
+  /// success, and an appropriate llvm::Error object otherwise.
+  llvm::Error extract(const lldb_private::DWARFDataExtractor ,
+  lldb::offset_t *offset_ptr);
   // void Encode(BinaryStreamBuf& debug_abbrev_buf) const;
   dw_uleb128_t
   AppendAbbrevDeclSequential(const DWARFAbbreviationDeclaration );
@@ -64,7 +67,11 @@
   const DWARFAbbreviationDeclarationSet *
   GetAbbreviationDeclarationSet(dw_offset_t cu_abbr_offset) const;
   void Dump(lldb_private::Stream *s) const;
-  void Parse(const lldb_private::DWARFDataExtractor );
+
+  /// Extract all abbreviations for a particular compile unit.  Returns
+  /// llvm::ErrorSuccess() on success, and an appropriate llvm::Error object
+  /// otherwise.
+  llvm::Error parse(const lldb_private::DWARFDataExtractor );
   void GetUnsupportedForms(std::set _forms) const;
 
 protected:
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
@@ -25,14 +25,22 @@
 //--
 // DWARFAbbreviationDeclarationSet::Extract()
 //--
-bool DWARFAbbreviationDeclarationSet::Extract(const DWARFDataExtractor ,
-  lldb::offset_t *offset_ptr) {
+llvm::Error
+DWARFAbbreviationDeclarationSet::extract(const DWARFDataExtractor ,
+ lldb::offset_t *offset_ptr) {
   const lldb::offset_t begin_offset = *offset_ptr;
   m_offset = begin_offset;
   Clear();
   DWARFAbbreviationDeclaration abbrevDeclaration;
   dw_uleb128_t prev_abbr_code = 0;
-  while (abbrevDeclaration.Extract(data, offset_ptr)) {
+  DWARFEnumState state = DWARFEnumState::MoreItems;
+  while (state == DWARFEnumState::MoreItems) {
+llvm::Expected es =
+abbrevDeclaration.extract(data, offset_ptr);
+if (!es)
+  return es.takeError();
+
+state = *es;
 m_decls.push_back(abbrevDeclaration);
 if (m_idx_offset == 0)
   m_idx_offset = 

[Lldb-commits] [PATCH] D59370: Return llvm::Error and llvm::Expected from some DWARF parsing functions

2019-03-14 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: labath, clayborg, aprantl, probinson.
Herald added a subscriber: jdoerfert.

The goal here is to improve our error handling and error recovery while parsing 
DWARF, while at the same time getting us closer to being able to merge LLDB's 
DWARF parser with LLVM's.  To this end, I've udpated several of the low-level 
parsing functions in LLDB to return `llvm::Error` and `llvm::Expected`.

For now, this only updates LLDB parsing functions and not LLVM.  In some ways, 
this actually gets us *farther* from parity with the two interfaces, because 
prior to this patch, at least the parsing interfaces were the same (i.e. they 
all just returned bools, and now with this patch they're diverging).  But, I 
chose to do this for two primary reasons.

1. LLDB has error logging code engrained deep within some of its parsing 
functions.  We don't want to lose this logging information, but obviously LLVM 
has no logging mechanism at all.  So if we're to merge the interfaces, we have 
to find a way to still allow LLDB to properly report parsing errors while not 
having the reporting code be inside of LLVM.

2. LLDB (and indeed, LLVM) overload the meaning of the `false` return value 
from all of these extraction functions to mean both "We reached the null entry 
at the end of a list of items, therefore everything was successful" as well as 
"something bad and unrecoverable happened during parsing".  So you would have a 
lot code that would do something like:

  while (foo.extract(...)) {
...
  }

But when the loop stops, why did it stop?  Did it stop because it finished 
parsing, or because there was an error?  Because of this, in some cases we 
don't always know whether it is ok to proceed, or how to proceed, but we were 
doing it anyway.

In this patch, I solve the second problem by introducing an enumeration called 
`DWARFEnumState` which has two values `MoreItems and `Complete`.  Both of these 
indicate success, but the latter indicates that we reached the null entry.  
Then, I return this value instead of bool, and convey parsing failure 
separately.

To solve the first problem (and convey parsing failure) these functions now 
return either `llvm::Error` or `llvm::Expected`.  Having this 
extra bit of information allows us to properly convey all 3 of us "error, bail 
out", "success, call this function again", and "success, don't call this 
function again".

In subsequent patches I plan to extend this pattern to the rest of the parsing 
interfaces, which will ultimately get all of the log statements and error 
reporting out of the low level parsing code and into the high level parsing 
code (e.g. `SymbolFileDWARF`, `DWARFASTParserClang`, etc).

Eventually, these same changes will have to be backported to LLVM's DWARF 
parser, but I feel like diverging in the short term is the quickest way to 
converge in the long term.


https://reviews.llvm.org/D59370

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -660,14 +660,23 @@
 }
 
 DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() {
-  if (m_abbr == NULL) {
-const DWARFDataExtractor _abbrev_data = get_debug_abbrev_data();
-if (debug_abbrev_data.GetByteSize() > 0) {
-  m_abbr.reset(new DWARFDebugAbbrev());
-  if (m_abbr)
-m_abbr->Parse(debug_abbrev_data);
-}
+  if (m_abbr)
+return m_abbr.get();
+
+  const DWARFDataExtractor _abbrev_data = get_debug_abbrev_data();
+  if (debug_abbrev_data.GetByteSize() == 0)
+return nullptr;
+
+  auto abbr = llvm::make_unique();
+  llvm::Error error = abbr->parse(debug_abbrev_data);
+  if (error) {
+Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
+LLDB_LOG_ERROR(log, std::move(error),
+   "Unable to read .debug_abbrev section: {0}");
+return nullptr;
   }
+
+  m_abbr = std::move(abbr);
   return m_abbr.get();
 }
 
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
@@ -14,6 +14,8 @@
 
 namespace lldb_private {
 
+enum class DWARFEnumState { MoreItems, Complete };
+
 typedef uint32_t DRC_class; // Holds DRC_* class bitfields
 
 enum DW_TAG_Category {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h

[Lldb-commits] [PATCH] D59276: Delete dead code

2019-03-12 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D59276#1426972 , @aprantl wrote:

> One one hand this seems fine to remove, but on the other hand — won't these 
> functions come in handy to compare and debug differences between the LLDB and 
> LLVM DWARF parsers, while we are switching over?


Maybe, but I'm not sure how useful it will actually be in practice to compare 
dump output that way.  I feel like if we successfully parse the DWARF using 
LLVM's parser, and no tests on either side regress in the process, then it is 
probably sufficient to say that things worked.

Can you imagine a scenario where the two outputs meaningfully differ but the 
test suites passed anyway?


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

https://reviews.llvm.org/D59276



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


[Lldb-commits] [PATCH] D59276: Delete dead code

2019-03-12 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: clayborg, aprantl.
Herald added subscribers: jdoerfert, mgorny.

Most of these are Dump functions that are never called, but there is one 
instance of entire unused classes (DWARFDebugMacinfo and 
DWARFDebugMacinfoEntry) which are also unreferenced in the codebase).


https://reviews.llvm.org/D59276

Files:
  lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugLine.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacinfo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacinfo.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacinfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacinfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h

Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
@@ -104,8 +104,6 @@
 
 bool Read(const lldb_private::DWARFDataExtractor ,
   lldb::offset_t *offset_ptr, DIEInfo _data) const;
-
-void Dump(lldb_private::Stream , const DIEInfo _data) const;
   };
 
   // A class for reading and using a saved hash table from a block of data
Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
@@ -304,49 +304,6 @@
   return true;
 }
 
-void DWARFMappedHash::Header::Dump(lldb_private::Stream ,
-   const DIEInfo _data) const {
-  const size_t num_atoms = header_data.atoms.size();
-  for (size_t i = 0; i < num_atoms; ++i) {
-if (i > 0)
-  strm.PutCString(", ");
-
-DWARFFormValue form_value(NULL, header_data.atoms[i].form);
-switch (header_data.atoms[i].type) {
-case eAtomTypeDIEOffset: // DIE offset, check form for encoding
-  strm.Printf("{0x%8.8x}", hash_data.offset);
-  break;
-
-case eAtomTypeTag: // DW_TAG value for the DIE
-{
-  const char *tag_cstr = lldb_private::DW_TAG_value_to_name(hash_data.tag);
-  if (tag_cstr)
-strm.PutCString(tag_cstr);
-  else
-strm.Printf("DW_TAG_(0x%4.4x)", hash_data.tag);
-} break;
-
-case eAtomTypeTypeFlags: // Flags from enum TypeFlags
-  strm.Printf("0x%2.2x", hash_data.type_flags);
-  if (hash_data.type_flags) {
-strm.PutCString(" (");
-if (hash_data.type_flags & eTypeFlagClassIsImplementation)
-  strm.PutCString(" implementation");
-strm.PutCString(" )");
-  }
-  break;
-
-case eAtomTypeQualNameHash: // Flags from enum TypeFlags
-  strm.Printf("0x%8.8x", hash_data.qualified_name_hash);
-  break;
-
-default:
-  strm.Printf("AtomType(0x%x)", header_data.atoms[i].type);
-  break;
-}
-  }
-}
-
 DWARFMappedHash::MemoryTable::MemoryTable(
 lldb_private::DWARFDataExtractor _data,
 const lldb_private::DWARFDataExtractor _table, const char *name)
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
@@ -45,8 +45,6 @@
 
 const char *DW_VIS_value_to_name(uint32_t val);
 
-const char *DW_VIRTUALITY_value_to_name(uint32_t val);
-
 const char *DW_LANG_value_to_name(uint32_t val);
 
 const char *DW_ID_value_to_name(uint32_t val);
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
@@ -411,17 +411,6 @@
   return llvmstr.data();
 }
 
-const char *DW_VIRTUALITY_value_to_name(uint32_t val) {
-  static char invalid[100];
-  llvm::StringRef llvmstr = llvm::dwarf::VirtualityString(val);
- 

[Lldb-commits] [PATCH] D59235: Remove Support for DWARF64

2019-03-12 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB355975: Remove support for DWARF64. (authored by zturner, 
committed by ).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D59235?vs=190173=190326#toc

Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D59235

Files:
  include/lldb/Core/dwarf.h
  source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
  source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: include/lldb/Core/dwarf.h
===
--- include/lldb/Core/dwarf.h
+++ include/lldb/Core/dwarf.h
@@ -27,15 +27,8 @@
 // any addresses in the compile units that get
 // parsed
 
-#ifdef DWARFUTILS_DWARF64
-#define DWARF_REF_ADDR_SIZE 8
-typedef uint64_t dw_offset_t; // Dwarf Debug Information Entry offset for any
-  // offset into the file
-#else
-#define DWARF_REF_ADDR_SIZE 4
 typedef uint32_t dw_offset_t; // Dwarf Debug Information Entry offset for any
   // offset into the file
-#endif
 
 /* Constants */
 #define DW_INVALID_OFFSET (~(dw_offset_t)0)
Index: source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
+++ source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
@@ -87,8 +87,7 @@
 lldb::offset_t *offset_ptr, const DWARFUnit *cu);
   static bool IsBlockForm(const dw_form_t form);
   static bool IsDataForm(const dw_form_t form);
-  static FixedFormSizes GetFixedFormSizesForAddressSize(uint8_t addr_size,
-bool is_dwarf64);
+  static FixedFormSizes GetFixedFormSizesForAddressSize(uint8_t addr_size);
   static int Compare(const DWARFFormValue , const DWARFFormValue );
   void Clear();
   static bool FormIsSupported(dw_form_t form);
Index: source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp
@@ -12,11 +12,7 @@
 
 uint64_t
 DWARFDataExtractor::GetDWARFInitialLength(lldb::offset_t *offset_ptr) const {
-  uint64_t length = GetU32(offset_ptr);
-  m_is_dwarf64 = (length == UINT32_MAX);
-  if (m_is_dwarf64)
-length = GetU64(offset_ptr);
-  return length;
+  return GetU32(offset_ptr);
 }
 
 dw_offset_t
Index: source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
@@ -260,9 +260,7 @@
   lldb::offset_t offset = 0;
 
   uint64_t length = data.GetU32();
-  bool isDwarf64 = (length == 0x);
-  if (isDwarf64)
-length = data.GetU64();
+  // FIXME: Handle DWARF64.
   lldb::offset_t end = offset + length;
 
   // Check version.
@@ -279,7 +277,7 @@
 
   uint32_t offsetsAmount = data.GetU32();
   for (uint32_t i = 0; i < offsetsAmount; ++i)
-Offsets.push_back(data.GetMaxU64(, isDwarf64 ? 8 : 4));
+Offsets.push_back(data.GetMaxU64(, 4));
 
   lldb::offset_t listOffset = offset;
   std::vector rangeList;
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -59,8 +59,7 @@
   // parse
   const DWARFDataExtractor  = GetData();
   DWARFFormValue::FixedFormSizes fixed_form_sizes =
-  DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
-  IsDWARF64());
+  DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize());
   if (offset < GetNextCompileUnitOffset() &&
   m_first_die.FastExtract(data, this, fixed_form_sizes, )) {
 AddUnitDIE(m_first_die);
@@ -185,8 +184,7 @@
   die_index_stack.push_back(0);
   bool prev_die_had_children = false;
   DWARFFormValue::FixedFormSizes fixed_form_sizes =
-  DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
-  IsDWARF64());
+  DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize());
   while (offset < next_cu_offset &&
  

[Lldb-commits] [PATCH] D59165: Remove DWARFDIECollection

2019-03-12 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB355974: Remove DWARFDIECollection. (authored by zturner, 
committed by ).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D59165?vs=189961=190325#toc

Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D59165

Files:
  source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
  source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDIE.h
  source/Plugins/SymbolFile/DWARF/DWARFDIECollection.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDIECollection.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -54,8 +54,7 @@
   ScopedExtractDIEs ExtractDIEsScoped();
 
   DWARFDIE LookupAddress(const dw_addr_t address);
-  size_t AppendDIEsWithTag(const dw_tag_t tag,
-   DWARFDIECollection _dies,
+  size_t AppendDIEsWithTag(const dw_tag_t tag, std::vector ,
uint32_t depth = UINT32_MAX) const;
   bool Verify(lldb_private::Stream *s) const;
   virtual void Dump(lldb_private::Stream *s) const = 0;
Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -18,7 +18,6 @@
 #include "lldb/Utility/Stream.h"
 
 #include "DWARFUnit.h"
-#include "DWARFDIECollection.h"
 #include "DWARFDebugAbbrev.h"
 #include "DWARFDebugAranges.h"
 #include "DWARFDebugInfo.h"
@@ -1381,11 +1380,11 @@
   }
 }
 
-void DWARFDebugInfoEntry::GetDeclContextDIEs(
-DWARFUnit *cu, DWARFDIECollection _context_dies) const {
+std::vector
+DWARFDebugInfoEntry::GetDeclContextDIEs(DWARFUnit *cu) const {
 
   DWARFDIE die(cu, const_cast(this));
-  die.GetDeclContextDIEs(decl_context_dies);
+  return die.GetDeclContextDIEs();
 }
 
 void DWARFDebugInfoEntry::GetDWARFDeclContext(
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -49,7 +49,6 @@
 class DWARFDebugLine;
 class DWARFDebugRangesBase;
 class DWARFDeclContext;
-class DWARFDIECollection;
 class DWARFFormValue;
 class SymbolFileDWARFDebugMap;
 class SymbolFileDWARFDwo;
Index: source/Plugins/SymbolFile/DWARF/CMakeLists.txt
===
--- source/Plugins/SymbolFile/DWARF/CMakeLists.txt
+++ source/Plugins/SymbolFile/DWARF/CMakeLists.txt
@@ -21,7 +21,6 @@
   DWARFDeclContext.cpp
   DWARFDefines.cpp
   DWARFDIE.cpp
-  DWARFDIECollection.cpp
   DWARFFormValue.cpp
   DWARFIndex.cpp
   DWARFUnit.cpp
Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFDIE.h
+++ source/Plugins/SymbolFile/DWARF/DWARFDIE.h
@@ -81,7 +81,7 @@
   //--
   // DeclContext related functions
   //--
-  void GetDeclContextDIEs(DWARFDIECollection _context_dies) const;
+  std::vector GetDeclContextDIEs() const;
 
   void GetDWARFDeclContext(DWARFDeclContext _decl_ctx) const;
 
Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
@@ -230,8 +230,7 @@
 return HasChildren() ? this + 1 : NULL;
   }
 
-  void GetDeclContextDIEs(DWARFUnit *cu,
-  DWARFDIECollection _context_dies) const;
+  std::vector GetDeclContextDIEs(DWARFUnit *cu) const;
 
   void GetDWARFDeclContext(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
DWARFDeclContext _decl_ctx) const;
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -17,7 +17,6 @@
 #include "lldb/Utility/StreamString.h"
 #include 

[Lldb-commits] [PATCH] D59164: [SymbolFileDWARF] Move ElaboratingDIEIterator into implementation file

2019-03-12 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB355973: Move ElaboratingDIEIterator into implementation 
file. (authored by zturner, committed by ).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D59164?vs=189959=190324#toc

Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D59164

Files:
  source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDIE.h

Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -17,20 +17,75 @@
 
 using namespace lldb_private;
 
-void DWARFDIE::ElaboratingDIEIterator::Next() {
-  assert(!m_worklist.empty() && "Incrementing end iterator?");
+namespace {
 
-  // Pop the current item from the list.
-  DWARFDIE die = m_worklist.back();
-  m_worklist.pop_back();
-
-  // And add back any items that elaborate it.
-  for (dw_attr_t attr : {DW_AT_specification, DW_AT_abstract_origin}) {
-if (DWARFDIE d = die.GetReferencedDIE(attr))
-  if (m_seen.insert(die.GetID()).second)
-m_worklist.push_back(d);
+/// Iterate through all DIEs elaborating (i.e. reachable by a chain of
+/// DW_AT_specification and DW_AT_abstract_origin attributes) a given DIE. For
+/// convenience, the starting die is included in the sequence as the first
+/// item.
+class ElaboratingDIEIterator
+: public std::iterator {
+
+  // The operating invariant is: top of m_worklist contains the "current" item
+  // and the rest of the list are items yet to be visited. An empty worklist
+  // means we've reached the end.
+  // Infinite recursion is prevented by maintaining a list of seen DIEs.
+  // Container sizes are optimized for the case of following DW_AT_specification
+  // and DW_AT_abstract_origin just once.
+  llvm::SmallVector m_worklist;
+  llvm::SmallSet m_seen;
+
+  void Next() {
+assert(!m_worklist.empty() && "Incrementing end iterator?");
+
+// Pop the current item from the list.
+DWARFDIE die = m_worklist.back();
+m_worklist.pop_back();
+
+// And add back any items that elaborate it.
+for (dw_attr_t attr : {DW_AT_specification, DW_AT_abstract_origin}) {
+  if (DWARFDIE d = die.GetReferencedDIE(attr))
+if (m_seen.insert(die.GetID()).second)
+  m_worklist.push_back(d);
+}
+  }
+
+public:
+  /// An iterator starting at die d.
+  explicit ElaboratingDIEIterator(DWARFDIE d) : m_worklist(1, d) {}
+
+  /// End marker
+  ElaboratingDIEIterator() {}
+
+  const DWARFDIE *() const { return m_worklist.back(); }
+  ElaboratingDIEIterator ++() {
+Next();
+return *this;
+  }
+  ElaboratingDIEIterator operator++(int) {
+ElaboratingDIEIterator I = *this;
+Next();
+return I;
   }
+
+  friend bool operator==(const ElaboratingDIEIterator ,
+ const ElaboratingDIEIterator ) {
+if (a.m_worklist.empty() || b.m_worklist.empty())
+  return a.m_worklist.empty() == b.m_worklist.empty();
+return a.m_worklist.back() == b.m_worklist.back();
+  }
+  friend bool operator!=(const ElaboratingDIEIterator ,
+ const ElaboratingDIEIterator ) {
+return !(a == b);
+  }
+};
+
+llvm::iterator_range
+elaborating_dies(const DWARFDIE ) {
+  return llvm::make_range(ElaboratingDIEIterator(die),
+  ElaboratingDIEIterator());
 }
+} // namespace
 
 DWARFDIE
 DWARFDIE::GetParent() const {
@@ -229,7 +284,7 @@
 }
 
 bool DWARFDIE::IsMethod() const {
-  for (DWARFDIE d: elaborating_dies())
+  for (DWARFDIE d : elaborating_dies(*this))
 if (d.GetParent().IsStructUnionOrClass())
   return true;
   return false;
Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFDIE.h
+++ source/Plugins/SymbolFile/DWARF/DWARFDIE.h
@@ -14,8 +14,6 @@
 
 class DWARFDIE : public DWARFBaseDIE {
 public:
-  class ElaboratingDIEIterator;
-
   using DWARFBaseDIE::DWARFBaseDIE;
 
   //--
@@ -33,8 +31,6 @@
   DWARFDIE
   GetContainingDWOModuleDIE() const;
 
-  inline llvm::iterator_range elaborating_dies() const;
-
   //--
   // Accessing information about a DIE
   //--
@@ -121,58 +117,4 @@
   lldb_private::CompilerDeclContext GetContainingDeclContext() const;
 };
 
-/// Iterate through all DIEs elaborating (i.e. reachable by a chain of
-/// DW_AT_specification and DW_AT_abstract_origin attributes) a given DIE. For
-/// convenience, the starting die is included in the sequence as the first
-/// item.
-class DWARFDIE::ElaboratingDIEIterator
-: public std::iterator {
-

[Lldb-commits] [PATCH] D59235: Remove Support for DWARF64

2019-03-12 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked an inline comment as done.
zturner added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp:170
 case DW_FORM_sec_offset:
   assert(m_cu);
+  m_value.value.uval = data.GetMaxU64(offset_ptr, 4);

jankratochvil wrote:
> Delete the assert?
Good catch.  I'll do this (and the other one) before submitting.


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

https://reviews.llvm.org/D59235



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


[Lldb-commits] [PATCH] D59235: Remove Support for DWARF64

2019-03-12 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked an inline comment as done.
zturner added a comment.

It seems like we're mostly in agreement on the direction of the patch, so if 
there's no outstanding comments I'll submit at the end of the day.




Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp:263
   uint64_t length = data.GetU32();
-  bool isDwarf64 = (length == 0x);
-  if (isDwarf64)

jankratochvil wrote:
> Here should be an error that DWARF64 is not supported.
How do we report that error?  This function doesn't return an error code, and 
neither does the function that calls it (I didn't look higher than that), and 
we don't build with exceptions.  We can assert, but we try to avoid asserts 
(although admittedly, we're going to crash anyway).  I can try to do more work 
to propagate errors up the stack, but at this point this whole file (and even 
most of the folder that the file is in) is in theory going to be going away 
soon as we converge on LLVM's DWARF parser, so it may make sense to just deal 
with the problem at that level.


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

https://reviews.llvm.org/D59235



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


[Lldb-commits] [PATCH] D59235: Remove Support for DWARF64

2019-03-11 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D59235#1425436 , @clayborg wrote:

> My main concern with the LLVM DWARF parser is all of the asserts in the code. 
> If you attempt to use a DWARFDIE without first checking it for validity, it 
> will crash on you instead of returning a good error or default value. That 
> makes me really nervous as we shouldn't just crash the debugger. The 
> switching over won't be too hard, just the fallout from the LLDB versions of 
> the class that do error checking and return good error/default values and 
> LLVM being very strict.


Sure, I'm prepared to deal all that appropriately.  I don't plan to regress 
LLDB's stability in the process.

That's why for now I'm just doing very small preliminary steps to get the two 
interfaces to be closer to each other and simplify the problem space.  We can 
worry about the asserts and all of that when we actually start moving pieces of 
LLDB to use LLVM's classes (which isn't in this patch).


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

https://reviews.llvm.org/D59235



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


[Lldb-commits] [PATCH] D59235: Remove Support for DWARF64

2019-03-11 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a subscriber: jankratochvil.
zturner added a comment.

In D59235#1425417 , @clayborg wrote:

> What part of parsing DWARF64 wasn't working? I think the SPARC compiler was 
> the only one producing DWARF64.


This patch originated from a thread on lldb-dev where I asked if anyone knows 
the status.  The first response was from @jankratochvil at Red Hat who gave 
this example:

  IMO there isn't as for example:
  lldb/source/Plugins/SymbolFile/DWARF/DIERef.cpp
  is using bits 32..63 for additional info (DWO file offset/index for example)
  while only bits 0..31 are used for DIE offset inside .debug_info section.

However, presumably this was identified from Jan simply looking at the code.  
There could be other such examples.

> Be a shame to lose the support.   What is the plan here after this patch?

Currently I'm doing some very preliminary investigation into merging LLVM and 
LLDB's DWARF parsers.  Initially, I started by updating LLVM's `DataExtractor` 
class to accept `size_t` offsets instead of `uint32_t`, however that quickly 
grew into a very large patch.

To answer your question: I think the plan would be to first standardize on a 
single DWARF parser, and then if / when we decide to support DWARF64, do it in 
one place (and importantly, make sure it has some corresponding test coverage).


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

https://reviews.llvm.org/D59235



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


[Lldb-commits] [PATCH] D59235: Remove Support for DWARF64

2019-03-11 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: clayborg, jasonmolenda, aprantl.
Herald added a subscriber: jdoerfert.

LLVM doesn't produce DWARF64, and neither does GCC.  LLDB's support for DWARF64 
is only partial, and if enabled appears to also not work.  It also appears to 
have no test coverage.  Removing this makes merging LLVM and LLDB's DWARF 
parsing implementations simpler.


https://reviews.llvm.org/D59235

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3253,8 +3253,7 @@
 // Retrieve the value as a data expression.
 DWARFFormValue::FixedFormSizes fixed_form_sizes =
 DWARFFormValue::GetFixedFormSizesForAddressSize(
-attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
-attributes.CompileUnitAtIndex(i)->IsDWARF64());
+attributes.CompileUnitAtIndex(i)->GetAddressByteSize());
 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
 uint32_t data_length =
 fixed_form_sizes.GetSize(form_value.Form());
@@ -3276,8 +3275,7 @@
   DWARFFormValue::FixedFormSizes fixed_form_sizes =
   DWARFFormValue::GetFixedFormSizesForAddressSize(
   attributes.CompileUnitAtIndex(i)
-  ->GetAddressByteSize(),
-  attributes.CompileUnitAtIndex(i)->IsDWARF64());
+  ->GetAddressByteSize());
   uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
   uint32_t data_length =
   fixed_form_sizes.GetSize(form_value.Form());
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -82,14 +82,13 @@
   //--
   /// Get the size in bytes of the length field in the header.
   ///
-  /// In DWARF32 this is just 4 bytes, and DWARF64 it is 12 where 4
-  /// are 0x followed by the actual 64 bit length.
+  /// In DWARF32 this is just 4 bytes
   ///
   /// \return
   /// Byte size of the compile unit header length field
   //--
-  size_t GetLengthByteSize() const { return IsDWARF64() ? 12 : 4; }
-  
+  size_t GetLengthByteSize() const { return 4; }
+
   bool ContainsDIEOffset(dw_offset_t die_offset) const {
 return die_offset >= GetFirstDIEOffset() &&
die_offset < GetNextCompileUnitOffset();
@@ -135,8 +134,6 @@
 
   static uint8_t GetAddressByteSize(const DWARFUnit *cu);
 
-  static bool IsDWARF64(const DWARFUnit *cu);
-
   static uint8_t GetDefaultAddressSize();
 
   void *GetUserData() const;
@@ -163,8 +160,6 @@
 
   lldb::LanguageType GetLanguageType();
 
-  bool IsDWARF64() const { return m_is_dwarf64; }
-
   bool GetIsOptimized();
 
   const lldb_private::FileSpec ();
@@ -213,7 +208,6 @@
   uint32_t m_producer_version_minor = 0;
   uint32_t m_producer_version_update = 0;
   lldb::LanguageType m_language_type = lldb::eLanguageTypeUnknown;
-  bool m_is_dwarf64 = false;
   lldb_private::LazyBool m_is_optimized = lldb_private::eLazyBoolCalculate;
   llvm::Optional m_comp_dir;
   dw_addr_t m_addr_base = 0;   // Value of DW_AT_addr_base
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -59,8 +59,7 @@
   // parse
   const DWARFDataExtractor  = GetData();
   DWARFFormValue::FixedFormSizes fixed_form_sizes =
-  DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
-  IsDWARF64());
+  DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize());
   if (offset < GetNextCompileUnitOffset() &&
   m_first_die.FastExtract(data, this, fixed_form_sizes, )) {
 

[Lldb-commits] [PATCH] D59217: Fix/unify SBType comparison

2019-03-11 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

SBType storing a pair of CompilerType and TypeSP seems like a very confusing 
interface and like it will be very easy to misuse or violate assumptions 
(perhaps even assumptions that nobody knows exists).  Why exactly is this 
necessary?

As far as I can tell, `SBType` uses `TypeImpl`, which supports having a 
`CompilerType`, a `TypeSP`, or both, but I cannot find any client of `TypeImpl` 
which actually depends on the `TypeSP` being set.  Perhaps we can just delete 
support for `TypeSP` from `TypeImpl` entirely.


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

https://reviews.llvm.org/D59217



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


[Lldb-commits] [PATCH] D59200: Fix a crasher in StackFrame::GetValueForVariableExpressionPath()

2019-03-11 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: source/Target/StackFrame.cpp:644-645
 if (error.Fail()) {
   error.SetErrorStringWithFormatv(
   "Failed to dereference sythetic value: %s", deref_error);
   return ValueObjectSP();

Not your code, but incidentally this looks wrong.  formatv uses python style 
format strings where you don't specify the type code but instead specify 
something like `{0}`.  So either the function is incorrectly named or the call 
is incorrect.



Comment at: source/Target/StackFrame.cpp:650-651
+if (!valobj_sp) {
+  error.SetErrorStringWithFormatv(
+  "Failed to dereference sythetic value");
+  return ValueObjectSP();

I think you can' just write this as `SetErrorString`, since there is no format 
happening.


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

https://reviews.llvm.org/D59200



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


[Lldb-commits] [PATCH] D59165: Remove DWARFDIECollection

2019-03-08 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: clayborg, aprantl.
Herald added subscribers: jdoerfert, mgorny.

  This is a very thin wrapper over a std::vector and does
  not seem to provide any real value over just using a container
  directly.


https://reviews.llvm.org/D59165

Files:
  lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIECollection.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -49,7 +49,6 @@
 class DWARFDebugLine;
 class DWARFDebugRangesBase;
 class DWARFDeclContext;
-class DWARFDIECollection;
 class DWARFFormValue;
 class SymbolFileDWARFDebugMap;
 class SymbolFileDWARFDwo;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -54,7 +54,6 @@
 #include "AppleDWARFIndex.h"
 #include "DWARFASTParser.h"
 #include "DWARFASTParserClang.h"
-#include "DWARFDIECollection.h"
 #include "DWARFDebugAbbrev.h"
 #include "DWARFDebugAranges.h"
 #include "DWARFDebugInfo.h"
@@ -861,22 +860,20 @@
 
 size_t SymbolFileDWARF::ParseFunctions(CompileUnit _unit) {
   ASSERT_MODULE_LOCK(this);
-  size_t functions_added = 0;
   DWARFUnit *dwarf_cu = GetDWARFCompileUnit(_unit);
-  if (dwarf_cu) {
-DWARFDIECollection function_dies;
-const size_t num_functions =
-dwarf_cu->AppendDIEsWithTag(DW_TAG_subprogram, function_dies);
-size_t func_idx;
-for (func_idx = 0; func_idx < num_functions; ++func_idx) {
-  DWARFDIE die = function_dies.GetDIEAtIndex(func_idx);
-  if (comp_unit.FindFunctionByUID(die.GetID()).get() == NULL) {
-if (ParseFunction(comp_unit, die))
-  ++functions_added;
-  }
-}
-// FixupTypes();
+  if (!dwarf_cu)
+return 0;
+
+  size_t functions_added = 0;
+  std::vector function_dies;
+  dwarf_cu->AppendDIEsWithTag(DW_TAG_subprogram, function_dies);
+  for (const DWARFDIE  : function_dies) {
+if (comp_unit.FindFunctionByUID(die.GetID()))
+  continue;
+if (ParseFunction(comp_unit, die))
+  ++functions_added;
   }
+  // FixupTypes();
   return functions_added;
 }
 
@@ -2807,8 +2804,8 @@
   if (die1 == die2)
 return true;
 
-  DWARFDIECollection decl_ctx_1;
-  DWARFDIECollection decl_ctx_2;
+  std::vector decl_ctx_1;
+  std::vector decl_ctx_2;
   // The declaration DIE stack is a stack of the declaration context DIEs all
   // the way back to the compile unit. If a type "T" is declared inside a class
   // "B", and class "B" is declared inside a class "A" and class "A" is in a
@@ -2824,11 +2821,11 @@
   // back to the compiler unit.
 
   // First lets grab the decl contexts for both DIEs
-  die1.GetDeclContextDIEs(decl_ctx_1);
-  die2.GetDeclContextDIEs(decl_ctx_2);
+  decl_ctx_1 = die1.GetDeclContextDIEs();
+  decl_ctx_2 = die2.GetDeclContextDIEs();
   // Make sure the context arrays have the same size, otherwise we are done
-  const size_t count1 = decl_ctx_1.Size();
-  const size_t count2 = decl_ctx_2.Size();
+  const size_t count1 = decl_ctx_1.size();
+  const size_t count2 = decl_ctx_2.size();
   if (count1 != count2)
 return false;
 
@@ -2838,8 +2835,8 @@
   DWARFDIE decl_ctx_die2;
   size_t i;
   for (i = 0; i < count1; i++) {
-decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex(i);
-decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex(i);
+decl_ctx_die1 = decl_ctx_1[i];
+decl_ctx_die2 = decl_ctx_2[i];
 if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag())
   return false;
   }
@@ -2849,7 +2846,7 @@
   // DW_TAG_compile_unit or DW_TAG_partial_unit. If it isn't then
   // something went wrong in the DWARFDIE::GetDeclContextDIEs()
   // function.
-  dw_tag_t cu_tag = decl_ctx_1.GetDIEAtIndex(count1 - 1).Tag();
+  dw_tag_t cu_tag = decl_ctx_1[count1 - 1].Tag();
   UNUSED_IF_ASSERT_DISABLED(cu_tag);
   assert(cu_tag == DW_TAG_compile_unit || cu_tag == DW_TAG_partial_unit);
 
@@ -2857,8 +2854,8 @@
   // Always skip the compile unit when comparing by only iterating up to "count
   // - 1". Here we 

[Lldb-commits] [PATCH] D59164: [SymbolFileDWARF] Move ElaboratingDIEIterator into implementation file

2019-03-08 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added a reviewer: clayborg.

  This is not used outside of the private implementation of the class,
  so hiding in the implementation file is a nice way of simplifying
  the external interface.


https://reviews.llvm.org/D59164

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h

Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
@@ -14,8 +14,6 @@
 
 class DWARFDIE : public DWARFBaseDIE {
 public:
-  class ElaboratingDIEIterator;
-
   using DWARFBaseDIE::DWARFBaseDIE;
 
   //--
@@ -33,8 +31,6 @@
   DWARFDIE
   GetContainingDWOModuleDIE() const;
 
-  inline llvm::iterator_range elaborating_dies() const;
-
   //--
   // Accessing information about a DIE
   //--
@@ -121,58 +117,4 @@
   lldb_private::CompilerDeclContext GetContainingDeclContext() const;
 };
 
-/// Iterate through all DIEs elaborating (i.e. reachable by a chain of
-/// DW_AT_specification and DW_AT_abstract_origin attributes) a given DIE. For
-/// convenience, the starting die is included in the sequence as the first
-/// item.
-class DWARFDIE::ElaboratingDIEIterator
-: public std::iterator {
-
-  // The operating invariant is: top of m_worklist contains the "current" item
-  // and the rest of the list are items yet to be visited. An empty worklist
-  // means we've reached the end.
-  // Infinite recursion is prevented by maintaining a list of seen DIEs.
-  // Container sizes are optimized for the case of following DW_AT_specification
-  // and DW_AT_abstract_origin just once.
-  llvm::SmallVector m_worklist;
-  llvm::SmallSet m_seen;
-
-  void Next();
-
-public:
-  /// An iterator starting at die d.
-  explicit ElaboratingDIEIterator(DWARFDIE d) : m_worklist(1, d) {}
-
-  /// End marker
-  ElaboratingDIEIterator() {}
-
-  const DWARFDIE *() const { return m_worklist.back(); }
-  ElaboratingDIEIterator ++() {
-Next();
-return *this;
-  }
-  ElaboratingDIEIterator operator++(int) {
-ElaboratingDIEIterator I = *this;
-Next();
-return I;
-  }
-
-  friend bool operator==(const ElaboratingDIEIterator ,
- const ElaboratingDIEIterator ) {
-if (a.m_worklist.empty() || b.m_worklist.empty())
-  return a.m_worklist.empty() == b.m_worklist.empty();
-return a.m_worklist.back() == b.m_worklist.back();
-  }
-  friend bool operator!=(const ElaboratingDIEIterator ,
- const ElaboratingDIEIterator ) {
-return !(a == b);
-  }
-};
-
-llvm::iterator_range
-DWARFDIE::elaborating_dies() const {
-  return llvm::make_range(ElaboratingDIEIterator(*this),
-  ElaboratingDIEIterator());
-}
-
 #endif // SymbolFileDWARF_DWARFDIE_h_
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -17,20 +17,75 @@
 
 using namespace lldb_private;
 
-void DWARFDIE::ElaboratingDIEIterator::Next() {
-  assert(!m_worklist.empty() && "Incrementing end iterator?");
-
-  // Pop the current item from the list.
-  DWARFDIE die = m_worklist.back();
-  m_worklist.pop_back();
-
-  // And add back any items that elaborate it.
-  for (dw_attr_t attr : {DW_AT_specification, DW_AT_abstract_origin}) {
-if (DWARFDIE d = die.GetReferencedDIE(attr))
-  if (m_seen.insert(die.GetID()).second)
-m_worklist.push_back(d);
+namespace {
+
+/// Iterate through all DIEs elaborating (i.e. reachable by a chain of
+/// DW_AT_specification and DW_AT_abstract_origin attributes) a given DIE. For
+/// convenience, the starting die is included in the sequence as the first
+/// item.
+class ElaboratingDIEIterator
+: public std::iterator {
+
+  // The operating invariant is: top of m_worklist contains the "current" item
+  // and the rest of the list are items yet to be visited. An empty worklist
+  // means we've reached the end.
+  // Infinite recursion is prevented by maintaining a list of seen DIEs.
+  // Container sizes are optimized for the case of following DW_AT_specification
+  // and DW_AT_abstract_origin just once.
+  llvm::SmallVector m_worklist;
+  llvm::SmallSet m_seen;
+
+  void Next() {
+assert(!m_worklist.empty() && "Incrementing end iterator?");
+
+// Pop the current item from the list.
+DWARFDIE die = m_worklist.back();
+m_worklist.pop_back();
+
+// And add back any items that elaborate it.
+for (dw_attr_t attr : {DW_AT_specification, DW_AT_abstract_origin}) {
+  if (DWARFDIE d = 

[Lldb-commits] [PATCH] D59158: Break cycle lldb/Commands [3->] lldb/Expression [1->] lldb/Commands

2019-03-08 Thread Zachary Turner via Phabricator via lldb-commits
zturner accepted this revision.
zturner added a comment.
This revision is now accepted and ready to land.

Ahh yea, sorry.  Got confused for a second :)


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

https://reviews.llvm.org/D59158



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


[Lldb-commits] [PATCH] D59158: Break cycle lldb/Commands [3->] lldb/Expression [1->] lldb/Commands

2019-03-08 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

Interesting, I had looked at fixing this one once before but I didn't realize 
we had a class named `EvaluateExpressionOptions` that contained just the right 
set of information, and it felt gross to invent a new one just for this purpose 
(It's a good thing I didn't too, since we already had another one).

Can you also update the CMake files?  You'll need to update 
`Expression/CMakeLists.txt` to not pull in `lldbTarget`.  I was going to say 
that you would also need to update `unittests/Expression/CMakeLists.txt`, but 
it's already not listed, so I guess it's just been relying on linking it 
transitively.

Do you have the ability to test the build with CMake?  If so, could you try 
`ninja ExpressionTests` and make sure everything still works after removing the 
link dependcy in `Expression/CMakeLists.txt`?


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

https://reviews.llvm.org/D59158



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


[Lldb-commits] [PATCH] D59158: Break cycle lldb/Commands [3->] lldb/Expression [1->] lldb/Commands

2019-03-08 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

I think maybe part of the problem is that this patch looks like actually 2 
things.  1) A move of the include files from `lldb/source/Commands` to 
`lldb/Include/lldb/Commands`, and 2) The dependency changes.  So it makes it 
hard to see what changes are actually needed for breaking the dependency.

Would it be possible to first move the header files as an independent change 
(which probably doesn't even need to be clang-formatted), and then after that 
fix the dependency issues?




Comment at: lldb/source/Expression/REPL.cpp:10
 #include "lldb/Expression/REPL.h"
+#include "lldb/Commands/CommandObjectExpression.h"
 #include "lldb/Core/Debugger.h"

AFAICT, this doesn't really appear to break the dependency does it?  Because 
right here, Expression will still cause a link dependency against Commands.  


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D59158



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


[Lldb-commits] [PATCH] D59158: Break cycle lldb/Commands [3->] lldb/Expression [1->] lldb/Commands

2019-03-08 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: lldb/include/lldb/Commands/CommandObjectBreakpoint.h:36
 
-  static void VerifyBreakpointOrLocationIDs(Args , Target *target,
-CommandReturnObject ,

I think the clang-format got messed up.  It appears to be formatting your 
entire tree instead of only the files that were changed in this patch.  Can you 
try to re-run clang-format only on the changed files?


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D59158



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


[Lldb-commits] [PATCH] D59114: [lldb-vscode] Don't hang indefinitely on invalid program

2019-03-07 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL355656: [lldb-vscode] Report an error if an invalid program 
is specified. (authored by zturner, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59114?vs=189788=189799#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59114

Files:
  lldb/trunk/source/Target/Process.cpp
  lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/trunk/source/Target/Process.cpp
===
--- lldb/trunk/source/Target/Process.cpp
+++ lldb/trunk/source/Target/Process.cpp
@@ -2519,108 +2519,112 @@
   m_process_input_reader.reset();
 
   Module *exe_module = GetTarget().GetExecutableModulePointer();
-  if (exe_module) {
-char local_exec_file_path[PATH_MAX];
-char platform_exec_file_path[PATH_MAX];
-exe_module->GetFileSpec().GetPath(local_exec_file_path,
-  sizeof(local_exec_file_path));
-exe_module->GetPlatformFileSpec().GetPath(platform_exec_file_path,
-  sizeof(platform_exec_file_path));
-if (FileSystem::Instance().Exists(exe_module->GetFileSpec())) {
-  // Install anything that might need to be installed prior to launching.
-  // For host systems, this will do nothing, but if we are connected to a
-  // remote platform it will install any needed binaries
-  error = GetTarget().Install(_info);
-  if (error.Fail())
-return error;
+  if (!exe_module) {
+error.SetErrorString("executable module does not exist");
+return error;
+  }
 
-  if (PrivateStateThreadIsValid())
-PausePrivateStateThread();
+  char local_exec_file_path[PATH_MAX];
+  char platform_exec_file_path[PATH_MAX];
+  exe_module->GetFileSpec().GetPath(local_exec_file_path,
+sizeof(local_exec_file_path));
+  exe_module->GetPlatformFileSpec().GetPath(platform_exec_file_path,
+sizeof(platform_exec_file_path));
+  if (FileSystem::Instance().Exists(exe_module->GetFileSpec())) {
+// Install anything that might need to be installed prior to launching.
+// For host systems, this will do nothing, but if we are connected to a
+// remote platform it will install any needed binaries
+error = GetTarget().Install(_info);
+if (error.Fail())
+  return error;
 
-  error = WillLaunch(exe_module);
-  if (error.Success()) {
-const bool restarted = false;
-SetPublicState(eStateLaunching, restarted);
-m_should_detach = false;
+if (PrivateStateThreadIsValid())
+  PausePrivateStateThread();
 
-if (m_public_run_lock.TrySetRunning()) {
-  // Now launch using these arguments.
-  error = DoLaunch(exe_module, launch_info);
-} else {
-  // This shouldn't happen
-  error.SetErrorString("failed to acquire process run lock");
-}
+error = WillLaunch(exe_module);
+if (error.Success()) {
+  const bool restarted = false;
+  SetPublicState(eStateLaunching, restarted);
+  m_should_detach = false;
 
-if (error.Fail()) {
-  if (GetID() != LLDB_INVALID_PROCESS_ID) {
-SetID(LLDB_INVALID_PROCESS_ID);
-const char *error_string = error.AsCString();
-if (error_string == nullptr)
-  error_string = "launch failed";
-SetExitStatus(-1, error_string);
-  }
-} else {
-  EventSP event_sp;
+  if (m_public_run_lock.TrySetRunning()) {
+// Now launch using these arguments.
+error = DoLaunch(exe_module, launch_info);
+  } else {
+// This shouldn't happen
+error.SetErrorString("failed to acquire process run lock");
+  }
 
-  // Now wait for the process to launch and return control to us, and then call
-  // DidLaunch:
-  StateType state = WaitForProcessStopPrivate(event_sp, seconds(10));
-
-  if (state == eStateInvalid || !event_sp) {
-// We were able to launch the process, but we failed to catch the
-// initial stop.
-error.SetErrorString("failed to catch stop after launch");
-SetExitStatus(0, "failed to catch stop after launch");
-Destroy(false);
-  } else if (state == eStateStopped || state == eStateCrashed) {
-DidLaunch();
-
-DynamicLoader *dyld = GetDynamicLoader();
-if (dyld)
-  dyld->DidLaunch();
-
-GetJITLoaders().DidLaunch();
-
-SystemRuntime *system_runtime = GetSystemRuntime();
-if (system_runtime)
-  system_runtime->DidLaunch();
-
-if (!m_os_up)
-  LoadOperatingSystemPlugin(false);
-
-

[Lldb-commits] [PATCH] D59114: [lldb-vscode] Don't hang indefinitely on invalid program

2019-03-07 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added a reviewer: clayborg.

When you configure your launch settings, if you pass a path to an invalid 
program, we would previously hand indefinitely.  This is because a combination 
of two bugs working together.  The first is that we did not attempt to detect 
when handling the request whether the file existed, and we would just pass it 
through to the `Process::Launch` method.  The second is that the 
`Process::Launch` method did not properly report an error in the case where the 
file does not exist.  It actually reported that the launch succeeded, which 
would then cause LLDB to wait on the broadcaster to receive some events, which 
would obviously never come.

Although fixing this in either place independently will get lldb-vscode working 
properly when an invalid executable is specified, I'm fixing it in both places 
because it seems like the right thing to do.  Note that for the first fix (the 
one in `lldb-vscode.cpp`) we were previously checking the value of 
`error.Fail()`, but the previous call did not actually communicate an error via 
an `SBError` return, instead it communicated an error via a null `SBModule` 
return.  So this condition is changed.


https://reviews.llvm.org/D59114

Files:
  lldb/source/Target/Process.cpp
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1227,20 +1227,23 @@
 
   // Grab the name of the program we need to debug and set it as the first
   // argument that will be passed to the program we will debug.
-  const auto program = GetString(arguments, "program");
+  llvm::StringRef program = GetString(arguments, "program");
   if (!program.empty()) {
 lldb::SBFileSpec program_fspec(program.data(), true /*resolve_path*/);
-
 g_vsc.launch_info.SetExecutableFile(program_fspec,
 true /*add_as_first_arg*/);
 const char *target_triple = nullptr;
 const char *uuid_cstr = nullptr;
 // Stand alone debug info file if different from executable
 const char *symfile = nullptr;
-g_vsc.target.AddModule(program.data(), target_triple, uuid_cstr, symfile);
-if (error.Fail()) {
+lldb::SBModule module = g_vsc.target.AddModule(
+program.data(), target_triple, uuid_cstr, symfile);
+if (!module.IsValid()) {
   response["success"] = llvm::json::Value(false);
-  EmplaceSafeString(response, "message", std::string(error.GetCString()));
+
+  EmplaceSafeString(
+  response, "message",
+  llvm::formatv("Could not load program '{0}'.", program).str());
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
   }
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -2519,108 +2519,112 @@
   m_process_input_reader.reset();
 
   Module *exe_module = GetTarget().GetExecutableModulePointer();
-  if (exe_module) {
-char local_exec_file_path[PATH_MAX];
-char platform_exec_file_path[PATH_MAX];
-exe_module->GetFileSpec().GetPath(local_exec_file_path,
-  sizeof(local_exec_file_path));
-exe_module->GetPlatformFileSpec().GetPath(platform_exec_file_path,
-  sizeof(platform_exec_file_path));
-if (FileSystem::Instance().Exists(exe_module->GetFileSpec())) {
-  // Install anything that might need to be installed prior to launching.
-  // For host systems, this will do nothing, but if we are connected to a
-  // remote platform it will install any needed binaries
-  error = GetTarget().Install(_info);
-  if (error.Fail())
-return error;
+  if (!exe_module) {
+error.SetErrorString("executable module does not exist");
+return error;
+  }
 
-  if (PrivateStateThreadIsValid())
-PausePrivateStateThread();
+  char local_exec_file_path[PATH_MAX];
+  char platform_exec_file_path[PATH_MAX];
+  exe_module->GetFileSpec().GetPath(local_exec_file_path,
+sizeof(local_exec_file_path));
+  exe_module->GetPlatformFileSpec().GetPath(platform_exec_file_path,
+sizeof(platform_exec_file_path));
+  if (FileSystem::Instance().Exists(exe_module->GetFileSpec())) {
+// Install anything that might need to be installed prior to launching.
+// For host systems, this will do nothing, but if we are connected to a
+// remote platform it will install any needed binaries
+error = GetTarget().Install(_info);
+if (error.Fail())
+  return error;
 
-  error = WillLaunch(exe_module);
-  if (error.Success()) {
-const bool restarted = false;
-SetPublicState(eStateLaunching, restarted);
-

[Lldb-commits] [PATCH] D59104: [lldb-vscode] Make server mode work on Windows

2019-03-07 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL355637: [lldb-vscode] Support running in server mode on 
Windows. (authored by zturner, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59104?vs=189759=189777#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59104

Files:
  lldb/trunk/tools/lldb-vscode/CMakeLists.txt
  lldb/trunk/tools/lldb-vscode/IOStream.cpp
  lldb/trunk/tools/lldb-vscode/IOStream.h
  lldb/trunk/tools/lldb-vscode/VSCode.cpp
  lldb/trunk/tools/lldb-vscode/VSCode.h
  lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp
  lldb/trunk/tools/lldb-vscode/package.json

Index: lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp
@@ -23,6 +23,7 @@
 #define NOMINMAX
 #include 
 #undef GetObject
+#include 
 #else
 #include 
 #include 
@@ -53,7 +54,6 @@
 constexpr const char *dev_null_path = "nul";
 
 #else
-typedef int SOCKET;
 constexpr const char *dev_null_path = "/dev/null";
 
 #endif
@@ -68,9 +68,9 @@
 
 enum VSCodeBroadcasterBits { eBroadcastBitStopEventThread = 1u << 0 };
 
-int AcceptConnection(int portno) {
+SOCKET AcceptConnection(int portno) {
   // Accept a socket connection from any host on "portno".
-  int newsockfd = -1;
+  SOCKET newsockfd = -1;
   struct sockaddr_in serv_addr, cli_addr;
   SOCKET sockfd = socket(AF_INET, SOCK_STREAM, 0);
   if (sockfd < 0) {
@@ -2635,23 +2635,19 @@
 #endif
   int portno = atoi(arg);
   printf("Listening on port %i...\n", portno);
-  int socket_fd = AcceptConnection(portno);
+  SOCKET socket_fd = AcceptConnection(portno);
   if (socket_fd >= 0) {
-// We must open two FILE objects, one for reading and one for writing
-// the FILE objects have a mutex in them that won't allow reading and
-// writing to the socket stream.
-g_vsc.in = fdopen(socket_fd, "r");
-g_vsc.out = fdopen(socket_fd, "w");
-if (g_vsc.in == nullptr || g_vsc.out == nullptr) {
-  if (g_vsc.log)
-*g_vsc.log << "fdopen failed (" << strerror(errno) << ")"
-   << std::endl;
-  exit(1);
-}
+g_vsc.input.descriptor = StreamDescriptor::from_socket(socket_fd, true);
+g_vsc.output.descriptor =
+StreamDescriptor::from_socket(socket_fd, false);
   } else {
 exit(1);
   }
 }
+  } else {
+g_vsc.input.descriptor = StreamDescriptor::from_file(fileno(stdin), false);
+g_vsc.output.descriptor =
+StreamDescriptor::from_file(fileno(stdout), false);
   }
   auto request_handlers = GetRequestHandlers();
   uint32_t packet_idx = 0;
Index: lldb/trunk/tools/lldb-vscode/CMakeLists.txt
===
--- lldb/trunk/tools/lldb-vscode/CMakeLists.txt
+++ lldb/trunk/tools/lldb-vscode/CMakeLists.txt
@@ -15,6 +15,7 @@
   BreakpointBase.cpp
   ExceptionBreakpoint.cpp
   FunctionBreakpoint.cpp
+  IOStream.cpp
   JSONUtils.cpp
   LLDBUtils.cpp
   SourceBreakpoint.cpp
Index: lldb/trunk/tools/lldb-vscode/IOStream.h
===
--- lldb/trunk/tools/lldb-vscode/IOStream.h
+++ lldb/trunk/tools/lldb-vscode/IOStream.h
@@ -0,0 +1,69 @@
+//===-- IOStream.h --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDBVSCODE_IOSTREAM_H_
+#define LLDBVSCODE_IOSTREAM_H_
+
+#if defined(_WIN32)
+// We need to #define NOMINMAX in order to skip `min()` and `max()` macro
+// definitions that conflict with other system headers.
+// We also need to #undef GetObject (which is defined to GetObjectW) because
+// the JSON code we use also has methods named `GetObject()` and we conflict
+// against these.
+#define NOMINMAX
+#include 
+#else
+typedef int SOCKET;
+#endif
+
+#include "llvm/ADT/StringRef.h"
+
+#include 
+#include 
+
+// Windows requires different system calls for dealing with sockets and other
+// types of files, so we can't simply have one code path that just uses read
+// and write everywhere.  So we need an abstraction in order to allow us to
+// treat them identically.
+namespace lldb_vscode {
+struct StreamDescriptor {
+  StreamDescriptor();
+  ~StreamDescriptor();
+  StreamDescriptor(StreamDescriptor &);
+
+  StreamDescriptor =(StreamDescriptor &);
+
+  static StreamDescriptor from_socket(SOCKET s, bool close);
+  static StreamDescriptor from_file(int fd, bool close);
+
+  bool 

[Lldb-commits] [PATCH] D59104: [lldb-vscode] Make server mode work on Windows

2019-03-07 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added a reviewer: clayborg.
Herald added a subscriber: mgorny.

For historical reasons, Windows unfortunately doesn't support using sockets in 
standard system calls like read/write, which means that they also can't be 
buffered with a `FILE*`.  This violates some fundamental assumptions of how 
lldb-vscode was written, so fixing it requires some replumbing of the guts.  I 
introduced an abstraction called `IOStream` which basically knows whether the 
descriptor is a socket or a non-socket, and then delegates to the appropriate 
underlying APIs accordingly.  This means calling `read/write` on `stdin/stdout` 
and calling `recv/send` on sockets.  Luckily this same strategy will also work 
on non-Windows platforms, so the abstractions needed aren't too egregious.


https://reviews.llvm.org/D59104

Files:
  lldb/tools/lldb-vscode/CMakeLists.txt
  lldb/tools/lldb-vscode/IOStream.cpp
  lldb/tools/lldb-vscode/IOStream.h
  lldb/tools/lldb-vscode/VSCode.cpp
  lldb/tools/lldb-vscode/VSCode.h
  lldb/tools/lldb-vscode/lldb-vscode.cpp
  lldb/tools/lldb-vscode/package.json

Index: lldb/tools/lldb-vscode/package.json
===
--- lldb/tools/lldb-vscode/package.json
+++ lldb/tools/lldb-vscode/package.json
@@ -56,6 +56,9 @@
 	]
 },
 "program": "./bin/lldb-vscode",
+"windows": {
+	"program": "./bin/lldb-vscode.exe"
+},
 "configurationAttributes": {
 	"launch": {
 		"required": [
Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -23,6 +23,7 @@
 #define NOMINMAX
 #include 
 #undef GetObject
+#include 
 #else
 #include 
 #include 
@@ -68,9 +69,9 @@
 
 enum VSCodeBroadcasterBits { eBroadcastBitStopEventThread = 1u << 0 };
 
-int AcceptConnection(int portno) {
+SOCKET AcceptConnection(int portno) {
   // Accept a socket connection from any host on "portno".
-  int newsockfd = -1;
+  SOCKET newsockfd = -1;
   struct sockaddr_in serv_addr, cli_addr;
   SOCKET sockfd = socket(AF_INET, SOCK_STREAM, 0);
   if (sockfd < 0) {
@@ -2635,23 +2636,19 @@
 #endif
   int portno = atoi(arg);
   printf("Listening on port %i...\n", portno);
-  int socket_fd = AcceptConnection(portno);
+  SOCKET socket_fd = AcceptConnection(portno);
   if (socket_fd >= 0) {
-// We must open two FILE objects, one for reading and one for writing
-// the FILE objects have a mutex in them that won't allow reading and
-// writing to the socket stream.
-g_vsc.in = fdopen(socket_fd, "r");
-g_vsc.out = fdopen(socket_fd, "w");
-if (g_vsc.in == nullptr || g_vsc.out == nullptr) {
-  if (g_vsc.log)
-*g_vsc.log << "fdopen failed (" << strerror(errno) << ")"
-   << std::endl;
-  exit(1);
-}
+g_vsc.input.descriptor = StreamDescriptor::from_socket(socket_fd, true);
+g_vsc.output.descriptor =
+StreamDescriptor::from_socket(socket_fd, false);
   } else {
 exit(1);
   }
 }
+  } else {
+g_vsc.input.descriptor = StreamDescriptor::from_file(fileno(stdin), false);
+g_vsc.output.descriptor =
+StreamDescriptor::from_file(fileno(stdout), false);
   }
   auto request_handlers = GetRequestHandlers();
   uint32_t packet_idx = 0;
Index: lldb/tools/lldb-vscode/VSCode.h
===
--- lldb/tools/lldb-vscode/VSCode.h
+++ lldb/tools/lldb-vscode/VSCode.h
@@ -19,6 +19,7 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
 
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBreakpoint.h"
@@ -43,6 +44,7 @@
 
 #include "ExceptionBreakpoint.h"
 #include "FunctionBreakpoint.h"
+#include "IOStream.h"
 #include "SourceBreakpoint.h"
 #include "SourceReference.h"
 
@@ -62,8 +64,8 @@
 enum class OutputType { Console, Stdout, Stderr, Telemetry };
 
 struct VSCode {
-  FILE *in;
-  FILE *out;
+  InputStream input;
+  OutputStream output;
   lldb::SBDebugger debugger;
   lldb::SBTarget target;
   lldb::SBAttachInfo attach_info;
@@ -94,8 +96,6 @@
   ~VSCode();
   VSCode(const VSCode ) = delete;
   void operator=(const VSCode ) = delete;
-  void CloseInputStream();
-  void CloseOutputStream();
   int64_t GetLineForPC(int64_t sourceReference, lldb::addr_t pc) const;
   ExceptionBreakpoint *GetExceptionBreakpoint(const std::string );
   ExceptionBreakpoint *GetExceptionBreakpoint(const lldb::break_id_t bp_id);
Index: lldb/tools/lldb-vscode/VSCode.cpp
===
--- lldb/tools/lldb-vscode/VSCode.cpp
+++ lldb/tools/lldb-vscode/VSCode.cpp
@@ -10,12 +10,15 @@
 #include 
 #include 
 
-#include "VSCode.h"
 #include "LLDBUtils.h"
+#include "VSCode.h"

[Lldb-commits] [PATCH] D59043: [lldb-vscode] Correctly propagate errors back to VS Code

2019-03-06 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added a reviewer: clayborg.

I tried installing this, and I couldn't get it working.  VS Code would launch 
the adapter and then it would get stuck waiting for something to happen.

Eventually, I tracked this down to the fact that it couldn't locate 
lldb-server, and I fixed this by symlinking lldb-server in the extension's bin 
directory.  However, it would have saved me a lot of time if VS Code had told 
me about this.  So then I started investigating why it didn't tell me about 
this, and it turns out that the reason is that in `FillResponse` we initialize 
the `success` field to `true`, and then when an error occurs, we use 
`try_emplace` to set it to `false`.  However, the semantics of this function 
are that if the value is already set, don't do anything, so ultimately this 
resulted in us sending back a response message saying we had succeeded even 
though we had failed.  So VS Code would think that we were fine and was just 
waiting on us to launch the process, even though we couldn't.

So, for the failure case, we shouldn't be using `try_emplace`, we should just 
clobber the old value.  After this, I've confirmed that if lldb-server is 
missing, VS Code reports an appropriate error message to me.


https://reviews.llvm.org/D59043

Files:
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -537,7 +537,7 @@
 const char *symfile = nullptr;
 g_vsc.target.AddModule(program.data(), target_triple, uuid_cstr, symfile);
 if (error.Fail()) {
-  response.try_emplace("success", false);
+  response["success"] = llvm::json::Value(false);
   EmplaceSafeString(response, "message", std::string(error.GetCString()));
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
   return;
@@ -589,7 +589,7 @@
   }
 
   if (error.Fail()) {
-response.try_emplace("success", false);
+response["success"] = llvm::json::Value(false);
 EmplaceSafeString(response, "message", std::string(error.GetCString()));
   }
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
@@ -832,7 +832,7 @@
 //   uint64_t exc_data = thread.GetStopReasonDataAtIndex(i);
 // }
   } else {
-response.try_emplace("success", false);
+response["success"] = llvm::json::Value(false);
   }
   response.try_emplace("body", std::move(body));
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
@@ -964,7 +964,7 @@
 if (value.GetError().Fail())
   value = frame.EvaluateExpression(expression.data());
 if (value.GetError().Fail()) {
-  response.try_emplace("success", false);
+  response["success"] = llvm::json::Value(false);
   const char *error_cstr = value.GetError().GetCString();
   if (error_cstr && error_cstr[0])
 EmplaceSafeString(response, "message", std::string(error_cstr));
@@ -1239,7 +1239,7 @@
 const char *symfile = nullptr;
 g_vsc.target.AddModule(program.data(), target_triple, uuid_cstr, symfile);
 if (error.Fail()) {
-  response.try_emplace("success", false);
+  response["success"] = llvm::json::Value(false);
   EmplaceSafeString(response, "message", std::string(error.GetCString()));
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
@@ -1277,7 +1277,7 @@
   g_vsc.debugger.SetAsync(false);
   g_vsc.target.Launch(g_vsc.launch_info, error);
   if (error.Fail()) {
-response.try_emplace("success", false);
+response["success"] = llvm::json::Value(false);
 EmplaceSafeString(response, "message", std::string(error.GetCString()));
   }
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
@@ -1339,7 +1339,7 @@
 g_vsc.focus_tid = thread.GetThreadID();
 thread.StepOver();
   } else {
-response.try_emplace("success", false);
+response["success"] = llvm::json::Value(false);
   }
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
@@ -1946,7 +1946,7 @@
   if (pos != g_vsc.source_map.end()) {
 EmplaceSafeString(body, "content", pos->second.content);
   } else {
-response.try_emplace("success", false);
+response["success"] = llvm::json::Value(false);
   }
   response.try_emplace("body", std::move(body));
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
@@ -2107,7 +2107,7 @@
 g_vsc.focus_tid = thread.GetThreadID();
 thread.StepInto();
   } else {
-response.try_emplace("success", false);
+response["success"] = llvm::json::Value(false);
   }
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
@@ -2161,7 +2161,7 @@
 g_vsc.focus_tid = thread.GetThreadID();
 thread.StepOut();
   } else {
-response.try_emplace("success", false);
+response["success"] = llvm::json::Value(false);
   }
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
@@ -2216,7 +2216,7 @@
 

[Lldb-commits] [PATCH] D58985: Fix core files for 32 bit architectures that are supported in ProcessELFCore.cpp

2019-03-05 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: source/Plugins/Process/elf-core/ThreadElfCore.cpp:276
+else
+  return sizeof(ELFLinuxPrStatus) - 10 * 4;
   }

subtracting 40 from the header size seems a bit magical to those not in the 
know (such as myself).  Could you do something like:

```
if (arch.GetAddressByteSize() == 8)
return sizeof(ELFLinuxPrStatus);

lldbassert(arch.GetAddressByteSize() == 4);
constexpr int kWhatever = 10;
return sizeof(ELFLinuxPrStatus) - kWhatever * arch.GetAddressByteSize();
```


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

https://reviews.llvm.org/D58985



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


[Lldb-commits] [PATCH] D58971: Move MemoryRegionInfo into the Utility module

2019-03-05 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

One idea for a new module name could be `AbstractProcess`, but I can't think of 
anything else better at the moment.


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

https://reviews.llvm.org/D58971



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


[Lldb-commits] [PATCH] D58972: Introduce the "Formats" module and move LinuxProcMaps parser to it

2019-03-05 Thread Zachary Turner via Phabricator via lldb-commits
zturner accepted this revision.
zturner added a comment.
This revision is now accepted and ready to land.

Great idea, this is a nice analogue to LLVM/BinaryFormat.

But, "Formats" is a little generic.  What about FileFormats or something?


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

https://reviews.llvm.org/D58972



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


[Lldb-commits] [PATCH] D58976: Introduce core2yaml tool

2019-03-05 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D58976#1418621 , @clayborg wrote:

> Strong ownership is needed for this class IMHO because it hands out pointers 
> to native data


I disagree here, see my previous comment.  Binaries grow large very quickly, 
and if we always copy data around when we want to hand out some internal 
pointer, memory usage would explode.  Luckily, the scenario that attempts to 
prevent is very rare.  Specifically, it only addresses the scenario where you 
open a file, parse a bunch of data, close the file, then still expect to be 
able to do something with the file's internal data structures.  I haven't ever 
seen this be a problem in practice, as the "natural" order is to open a file, 
process it, then close the file.  And in that case this is fine.

I don't mind having it be documented in the class header, but given that the 
pattern is fairly pervasive in LLVM (e.g. all of lib/Object works this way, 
among other things), I'm also fine with just letting it be implicitly 
understood.




Comment at: include/lldb/Formats/MinidumpParser.h:105
 private:
-  lldb::DataBufferSP m_data_sp;
+  llvm::ArrayRef m_data;
+  const MinidumpHeader *m_header;

clayborg wrote:
> I worry about this going stale when the owner of the data lets it go and we 
> crash now that we don't have strong ownership. If this is common in LLVM, 
> then we need to document this in the header file.
This is a fairly pervasive, as well as being an important optimization.  We 
don't want to be copying data around from binary files because the amount of 
data that ends up being copied could quickly spiral out of control since 
binaries get quite large.  The semantics are that the data is valid as long as 
the backing file remains opened.  Anyone using the class needs to be aware of 
this, and if they want a lifetime that is not tied to the life of the backing 
file (which is a fairly uncommon scenario), they need to explicitly copy any 
data they need to outlive the file.



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

https://reviews.llvm.org/D58976



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


[Lldb-commits] [PATCH] D58842: Move ProcessInstanceInfo and similar to Utility

2019-03-04 Thread Zachary Turner via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL355342: Move ProcessInfo from Host to Utility. (authored by 
zturner, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58842?vs=188950=189200#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58842

Files:
  lldb/trunk/include/lldb/Host/Host.h
  lldb/trunk/include/lldb/Host/ProcessInfo.h
  lldb/trunk/include/lldb/Host/ProcessLaunchInfo.h
  lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h
  lldb/trunk/include/lldb/Target/Platform.h
  lldb/trunk/include/lldb/Target/Process.h
  lldb/trunk/include/lldb/Utility/ProcessInfo.h
  lldb/trunk/include/lldb/module.modulemap
  lldb/trunk/source/API/SBProcess.cpp
  lldb/trunk/source/API/SBProcessInfo.cpp
  lldb/trunk/source/API/SBTarget.cpp
  lldb/trunk/source/Host/CMakeLists.txt
  lldb/trunk/source/Host/common/ProcessInfo.cpp
  lldb/trunk/source/Host/freebsd/Host.cpp
  lldb/trunk/source/Host/linux/Host.cpp
  lldb/trunk/source/Host/macosx/objcxx/Host.mm
  lldb/trunk/source/Host/netbsd/Host.cpp
  lldb/trunk/source/Host/openbsd/Host.cpp
  lldb/trunk/source/Host/posix/HostInfoPosix.cpp
  lldb/trunk/source/Host/windows/Host.cpp
  lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
  lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp
  lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
  lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
  lldb/trunk/source/Target/Process.cpp
  lldb/trunk/source/Utility/CMakeLists.txt
  lldb/trunk/source/Utility/ProcessInfo.cpp
  lldb/trunk/unittests/Host/CMakeLists.txt
  lldb/trunk/unittests/Host/ProcessInfoTest.cpp
  lldb/trunk/unittests/Utility/CMakeLists.txt
  lldb/trunk/unittests/Utility/ProcessInfoTest.cpp

Index: lldb/trunk/include/lldb/module.modulemap
===
--- lldb/trunk/include/lldb/module.modulemap
+++ lldb/trunk/include/lldb/module.modulemap
@@ -39,7 +39,6 @@
   module PipeBase { header "Host/PipeBase.h" export * }
   module Pipe { header "Host/Pipe.h" export * }
   module PosixApi { header "Host/PosixApi.h" export * }
-  module ProcessInfo { header "Host/ProcessInfo.h" export * }
   module ProcessLauncher { header "Host/ProcessLauncher.h" export * }
   module ProcessLaunchInfo { header "Host/ProcessLaunchInfo.h" export * }
   module ProcessRunLock { header "Host/ProcessRunLock.h" export * }
Index: lldb/trunk/include/lldb/Utility/ProcessInfo.h
===
--- lldb/trunk/include/lldb/Utility/ProcessInfo.h
+++ lldb/trunk/include/lldb/Utility/ProcessInfo.h
@@ -0,0 +1,251 @@
+//===-- ProcessInfo.h ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_UTILITY_PROCESSINFO_H
+#define LLDB_UTILITY_PROCESSINFO_H
+
+// LLDB headers
+#include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/Args.h"
+#include "lldb/Utility/Environment.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/NameMatches.h"
+
+#include 
+
+namespace lldb_private {
+
+class UserIDResolver;
+
+//--
+// ProcessInfo
+//
+// A base class for information for a process. This can be used to fill
+// out information for a process prior to launching it, or it can be used for
+// an instance of a process and can be filled in with the existing values for
+// that process.
+//--
+class ProcessInfo {
+public:
+  ProcessInfo();
+
+  ProcessInfo(const char *name, const ArchSpec , lldb::pid_t pid);
+
+  void Clear();
+
+  const char *GetName() const;
+
+  size_t GetNameLength() const;
+
+  FileSpec () { return m_executable; }
+
+  void SetExecutableFile(const FileSpec _file,
+ bool add_exe_file_as_first_arg);
+
+  const FileSpec () const { return m_executable; }
+
+  uint32_t GetUserID() const { return m_uid; }
+
+  uint32_t GetGroupID() const { return m_gid; }
+
+  bool UserIDIsValid() const { return m_uid != UINT32_MAX; }
+
+  bool GroupIDIsValid() const { return m_gid != UINT32_MAX; }
+
+  void SetUserID(uint32_t uid) { m_uid = uid; }
+
+  void SetGroupID(uint32_t gid) { m_gid = gid; }
+
+  ArchSpec () { return m_arch; }
+
+  

[Lldb-commits] [PATCH] D58838: Remove tautological #ifdefs

2019-03-01 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

Yea it would be nice if we could remove all of the `LLDB_CONFIGURATION_xxx` 
macros and just use either the LLVM ones or standard ones such as NDEBUG


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

https://reviews.llvm.org/D58838



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


[Lldb-commits] [PATCH] D58792: Add "operator bool" to SB APIs

2019-03-01 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

Out of curiosity, are there known, specific examples of users who rely on the 
exact mangling not changing?


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

https://reviews.llvm.org/D58792



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


[Lldb-commits] [PATCH] D58842: Move ProcessInstanceInfo and similar to Utility

2019-03-01 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D58842#1415526 , @labath wrote:

> Hmm.. I think I've thought of (or remembered, because I have been thinking 
> about Utility too) a reason why it might be better to keep these in Host. 
> ProcessLaunchInfo cannot be trivially moved to Utility (and indeed, in this 
> patch, you are keeping it in Host), because it contains some references to 
> Host-specific code (PTY stuff). Now, I am not convinced having the PTY class 
> be a member of ProcessLaunchInfo is a good thing, but assuming we don't want 
> to refactor that now, I think it might be better to keep Process(Launch)Info 
> and friends in the same package (i.e., in Host), at least until we have a 
> reason to do otherwise.


Well, the biggest difference between ProcessAttachInfo / ProcessLaunchInfo and 
the ones here is that those actually have some non-trivial functionality 
associated with them.  It might be possible to decouple that functionality from 
the descriptions themselves, but it didn't seem worth it to me.

I have a mild preference for putting them in Utility on the grounds that 
logically that's where they seem to make the most sense.  A Process could just 
as easily be running on a target as on the host, and we may want to pass this 
description around, and so favoring one or the other regarding to put them 
seemed a bit biased.  We do already have a process class in Host called 
HostProcess, and that's more what I envision a host-specific process looking 
like.  Low level methods that map directly to system calls to manipulate and 
query a process's state, etc.

As for D58167 , I mostly just had a drive-by 
passing comment, and it looked fine to me after that, but I guess I was waiting 
for someone else to click Accept since my comment was fairly minor.  But I'll 
go ahead and accept it anyway just to unblock


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

https://reviews.llvm.org/D58842



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


[Lldb-commits] [PATCH] D58842: Move ProcessInstanceInfo and similar to Utility

2019-03-01 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: jingham, labath, JDevlieghere.
Herald added subscribers: jdoerfert, mgorny, emaste.

There are set of classes in Target that describe the parameters of a process - 
e.g. it's PID, name, user id, and similar.  However, since it is a bare 
description of a process and contains no actual functionality, there's nothing 
specifically that makes this appropriate for being in Target -- it could just 
as well be describing a process on the host, or some hypothetical virtual 
process that doesn't even exist.

To cement this, I'm moving this class to Utility.  It's possible that we can 
find a better place for it in the future, but as it is neither Host specific 
nor Target specific, Utility seems like the most appropriate place for the time 
being.

After this there are only 2 remaining references to Target from Host, neither 
of which is terribly difficult to fix on its own and which I'll address in 
followups.


https://reviews.llvm.org/D58842

Files:
  lldb/include/lldb/Host/Host.h
  lldb/include/lldb/Host/ProcessInfo.h
  lldb/include/lldb/Host/ProcessLaunchInfo.h
  lldb/include/lldb/Target/Platform.h
  lldb/include/lldb/Target/Process.h
  lldb/include/lldb/Utility/ProcessInfo.h
  lldb/include/lldb/module.modulemap
  lldb/source/API/SBProcess.cpp
  lldb/source/API/SBProcessInfo.cpp
  lldb/source/API/SBTarget.cpp
  lldb/source/Commands/CommandObjectPlatform.cpp
  lldb/source/Host/CMakeLists.txt
  lldb/source/Host/common/ProcessInfo.cpp
  lldb/source/Host/freebsd/Host.cpp
  lldb/source/Host/linux/Host.cpp
  lldb/source/Host/netbsd/Host.cpp
  lldb/source/Host/openbsd/Host.cpp
  lldb/source/Host/windows/Host.cpp
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
  lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/ProcessInfo.cpp
  lldb/unittests/Host/CMakeLists.txt
  lldb/unittests/Host/ProcessInfoTest.cpp
  lldb/unittests/Utility/CMakeLists.txt
  lldb/unittests/Utility/ProcessInfoTest.cpp

Index: lldb/unittests/Utility/ProcessInfoTest.cpp
===
--- lldb/unittests/Utility/ProcessInfoTest.cpp
+++ lldb/unittests/Utility/ProcessInfoTest.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "lldb/Host/ProcessInfo.h"
+#include "lldb/Utility/ProcessInfo.h"
 #include "gtest/gtest.h"
 
 using namespace lldb_private;
Index: lldb/unittests/Utility/CMakeLists.txt
===
--- lldb/unittests/Utility/CMakeLists.txt
+++ lldb/unittests/Utility/CMakeLists.txt
@@ -18,6 +18,7 @@
   LogTest.cpp
   NameMatchesTest.cpp
   PredicateTest.cpp
+  ProcessInfoTest.cpp
   RegisterValueTest.cpp
   ReproducerTest.cpp
   ReproducerInstrumentationTest.cpp
Index: lldb/unittests/Host/CMakeLists.txt
===
--- lldb/unittests/Host/CMakeLists.txt
+++ lldb/unittests/Host/CMakeLists.txt
@@ -5,7 +5,6 @@
   HostTest.cpp
   MainLoopTest.cpp
   NativeProcessProtocolTest.cpp
-  ProcessInfoTest.cpp
   ProcessLaunchInfoTest.cpp
   SocketAddressTest.cpp
   SocketTest.cpp
Index: lldb/source/Utility/ProcessInfo.cpp
===
--- lldb/source/Utility/ProcessInfo.cpp
+++ lldb/source/Utility/ProcessInfo.cpp
@@ -1,4 +1,4 @@
-//===-- ProcessInfo.cpp -*- C++ -*-===//
+//===-- ProcessInstance.cpp -*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,14 @@
 //
 //===--===//
 
-#include "lldb/Host/ProcessInfo.h"
+#include "lldb/Utility/ProcessInfo.h"
 
-#include 
-
-#include "lldb/Host/PosixApi.h"
+#include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/Stream.h"
-
 #include "llvm/ADT/SmallString.h"
 
+#include 
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -72,13 +71,9 @@
   }
 }
 
-llvm::StringRef ProcessInfo::GetArg0() const {
-  return m_arg0;
-}
+llvm::StringRef ProcessInfo::GetArg0() const { return m_arg0; }
 
-void ProcessInfo::SetArg0(llvm::StringRef arg) {
-  m_arg0 = arg;
-}
+void ProcessInfo::SetArg0(llvm::StringRef arg) { m_arg0 = arg; }
 
 void ProcessInfo::SetArguments(char const **argv,
bool first_arg_is_executable) {
@@ -111,3 +106,86 @@
 }
   }
 }
+
+bool ProcessInstanceInfoMatch::NameMatches(const char 

[Lldb-commits] [PATCH] D58833: Fix embedded Python initialization according to changes in version 3.7

2019-03-01 Thread Zachary Turner via Phabricator via lldb-commits
zturner added reviewers: davide, stella.stamenova.
zturner added a comment.

Davide ran into this issue recently and tried to fix it, so I'm adding him here 
as a reviewer.  Also Stella is interested in Python 3 support as well, so 
adding her also.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D58833



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


[Lldb-commits] [PATCH] D58730: Rename Symbols.cpp from Host to Symbols/LocateSymbolFile.{h, cpp}

2019-02-27 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB355032: Move Host/Symbols.cpp to 
Symbols/LocateSymbolFile.cpp (authored by zturner, committed by ).
Herald added subscribers: abidh, krytarowski.
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D58730?vs=188587=188613#toc

Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D58730

Files:
  include/lldb/Host/Symbols.h
  include/lldb/Symbol/LocateSymbolFile.h
  include/lldb/module.modulemap
  source/Commands/CommandObjectTarget.cpp
  source/Core/ModuleList.cpp
  source/Host/CMakeLists.txt
  source/Host/common/Symbols.cpp
  source/Host/macosx/Symbols.cpp
  source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
  source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
  source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
  source/Symbol/CMakeLists.txt
  source/Symbol/LocateSymbolFile.cpp
  source/Symbol/LocateSymbolFileMacOSX.cpp
  unittests/Host/CMakeLists.txt
  unittests/Host/SymbolsTest.cpp
  unittests/Symbol/CMakeLists.txt
  unittests/Symbol/LocateSymbolFileTest.cpp

Index: include/lldb/module.modulemap
===
--- include/lldb/module.modulemap
+++ include/lldb/module.modulemap
@@ -48,7 +48,6 @@
   module SocketAddress { header "Host/SocketAddress.h" export * }
   module Socket { header "Host/Socket.h" export * }
   module StringConvert { textual header "Host/StringConvert.h" export * }
-  module Symbols { header "Host/Symbols.h" export * }
   module TaskPool { header "Host/TaskPool.h" export * }
   module Terminal { header "Host/Terminal.h" export * }
   module ThreadLauncher { header "Host/ThreadLauncher.h" export * }
Index: include/lldb/Symbol/LocateSymbolFile.h
===
--- include/lldb/Symbol/LocateSymbolFile.h
+++ include/lldb/Symbol/LocateSymbolFile.h
@@ -0,0 +1,61 @@
+//===-- Symbols.h ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef liblldb_Symbols_h_
+#define liblldb_Symbols_h_
+
+#include 
+
+#include "lldb/Utility/FileSpec.h"
+
+namespace lldb_private {
+
+class ArchSpec;
+class ModuleSpec;
+class UUID;
+
+class Symbols {
+public:
+  //--
+  // Locate the executable file given a module specification.
+  //
+  // Locating the file should happen only on the local computer or using the
+  // current computers global settings.
+  //--
+  static ModuleSpec LocateExecutableObjectFile(const ModuleSpec _spec);
+
+  //--
+  // Locate the symbol file given a module specification.
+  //
+  // Locating the file should happen only on the local computer or using the
+  // current computers global settings.
+  //--
+  static FileSpec LocateExecutableSymbolFile(const ModuleSpec _spec);
+
+  static FileSpec FindSymbolFileInBundle(const FileSpec _bundle_fspec,
+ const lldb_private::UUID *uuid,
+ const ArchSpec *arch);
+
+  //--
+  // Locate the object and symbol file given a module specification.
+  //
+  // Locating the file can try to download the file from a corporate build
+  // repository, or using any other means necessary to locate both the
+  // unstripped object file and the debug symbols. The force_lookup argument
+  // controls whether the external program is called unconditionally to find
+  // the symbol file, or if the user's settings are checked to see if they've
+  // enabled the external program before calling.
+  //
+  //--
+  static bool DownloadObjectAndSymbolFile(ModuleSpec _spec,
+  bool force_lookup = true);
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_Symbols_h_
Index: unittests/Host/CMakeLists.txt
===
--- unittests/Host/CMakeLists.txt
+++ unittests/Host/CMakeLists.txt
@@ -9,7 +9,6 @@
   ProcessLaunchInfoTest.cpp
   SocketAddressTest.cpp
   

[Lldb-commits] [PATCH] D58730: Rename Symbols.cpp from Host to Symbols/LocateSymbolFile.{h, cpp}

2019-02-27 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: labath, JDevlieghere, jingham.
Herald added subscribers: jdoerfert, MaskRay, arichardson, mgorny, emaste.
Herald added a reviewer: espindola.

After this change, there is only 1 remaining dependency in Host to Target.

While this change might seem like kind of a heavy hammer to solving the 
dependency problem, it makes more sense even conceptually to be in Symbols.  
While some of the specific places to search for symbol files might change 
depending on the Host, this is not inherently true in the same way that 
"accessing the file system" or "starting threads" is fundamentally dependent on 
the Host.

PDBs, for example, recently became a reality on non-Windows platforms, and it's 
theoretically possible that DSYMs could become a thing on non MacOSX platforms 
(maybe in a remote debugging scenario).  Other types of symbol files, such as 
DWO, DWP, etc have never been tied to any Host platform anyway.

So I think this change both makes sense logically, and also improves the 
layering.


https://reviews.llvm.org/D58730

Files:
  lldb/include/lldb/Host/Symbols.h
  lldb/include/lldb/Symbol/LocateSymbolFile.h
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Core/ModuleList.cpp
  lldb/source/Host/CMakeLists.txt
  lldb/source/Host/common/Symbols.cpp
  lldb/source/Host/macosx/Symbols.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
  lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
  lldb/source/Symbol/CMakeLists.txt
  lldb/source/Symbol/LocateSymbolFile.cpp
  lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
  lldb/unittests/Host/CMakeLists.txt
  lldb/unittests/Host/SymbolsTest.cpp
  lldb/unittests/Symbol/CMakeLists.txt
  lldb/unittests/Symbol/LocateSymbolFileTest.cpp

Index: lldb/unittests/Symbol/LocateSymbolFileTest.cpp
===
--- lldb/unittests/Symbol/LocateSymbolFileTest.cpp
+++ lldb/unittests/Symbol/LocateSymbolFileTest.cpp
@@ -11,7 +11,7 @@
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
-#include "lldb/Host/Symbols.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
 
 using namespace lldb_private;
 
Index: lldb/unittests/Symbol/CMakeLists.txt
===
--- lldb/unittests/Symbol/CMakeLists.txt
+++ lldb/unittests/Symbol/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_lldb_unittest(SymbolTests
+  LocateSymbolFileTest.cpp
   TestClangASTContext.cpp
   TestDWARFCallFrameInfo.cpp
   TestType.cpp
Index: lldb/unittests/Host/CMakeLists.txt
===
--- lldb/unittests/Host/CMakeLists.txt
+++ lldb/unittests/Host/CMakeLists.txt
@@ -9,7 +9,6 @@
   ProcessLaunchInfoTest.cpp
   SocketAddressTest.cpp
   SocketTest.cpp
-  SymbolsTest.cpp
   TaskPoolTest.cpp
 )
 
Index: lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
===
--- lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
+++ lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "lldb/Host/Symbols.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
 
 #include 
 #include 
@@ -54,7 +54,7 @@
   log->Printf("Spotlight lookup for .dSYM bundles is disabled.");
 return 0;
   }
-  
+
   return_module_spec = module_spec;
   return_module_spec.GetFileSpec().Clear();
   return_module_spec.GetSymbolFileSpec().Clear();
@@ -422,8 +422,8 @@
   source_path.RemoveLastPathComponent();
   source_path.RemoveLastPathComponent();
   module_spec.GetSourceMappingList().Append(
-ConstString(build_path.GetPath().c_str()),
-ConstString(source_path.GetPath().c_str()), true);
+  ConstString(build_path.GetPath().c_str()),
+  ConstString(source_path.GetPath().c_str()), true);
 }
   }
 }
@@ -434,7 +434,6 @@
   }
 }
 
-
 // If we have a DBGBuildSourcePath + DBGSourcePath pair, append them to the
 // source remappings list.
 
Index: lldb/source/Symbol/LocateSymbolFile.cpp
===
--- lldb/source/Symbol/LocateSymbolFile.cpp
+++ lldb/source/Symbol/LocateSymbolFile.cpp
@@ -6,7 +6,8 @@
 //
 //===--===//
 
-#include "lldb/Host/Symbols.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
+
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Host/FileSystem.h"
 #include 

[Lldb-commits] [PATCH] D58654: Move Config.h from Host to Utility

2019-02-27 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D58654#1411084 , @labath wrote:

> BTW, what's the reason that you have to have this split now? I understand its 
> attractiveness from a Zen perspective, but it seems to me that at the end of 
> the day, it doesn't have that much impact on the new code you're about to 
> write. It seems to me you could still enforce a clean layering on the new 
> code by just saying "only ever include stuff from Host or Utility". The fact 
> that Host transitively pulls in the kitchen sink is unfortunate, but I don't 
> think it should impact you much. And when we finally clean up Host (which is 
> something that we'll do eventually, and I hope not too far from now), then 
> the new code will magically stop depending on the whole world without any 
> extra effort.


I suppose that actually is fine.


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

https://reviews.llvm.org/D58654



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


[Lldb-commits] [PATCH] D58350: Insert random blocks of python code with swig instead of modify-python-lldb.py

2019-02-26 Thread Zachary Turner via Phabricator via lldb-commits
zturner accepted this revision.
zturner added a comment.

Also lgtm.  Don't call the commit message "Insert random blocks of python code" 
though.  Hopefully the code we're inserting is not actually random :)


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

https://reviews.llvm.org/D58350



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


[Lldb-commits] [PATCH] D58678: Improve step over performance by not stopping at branches that are function calls and stepping into and them out of each one

2019-02-26 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

> Since we are stepping over we can safely ignore these calls since they will 
> return to the next instruction

What if the call throws an exception?


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D58678



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


[Lldb-commits] [PATCH] D58654: Move Config.h from Host to Utility

2019-02-26 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D58654#1410817 , @JDevlieghere 
wrote:

> I'm not a fan of introducing another library for this. Without a clear 
> timeline of "fixing" Host it's basically as temporary as anything else in 
> software development. I also think it's confusing (e,g, new files should go 
> where?). If you really want a clean slate we should move everything in System 
> that doesn't depend on anything other than Utility until Host is empty, but 
> I'm sure everyone agrees that unrealistic and not worth the churn.
>
> For the record I also very much support a Host library instead of having 
> everything in Utility. That being said, I could see the config file being 
> special enough (in that everything depends on it) to be the exception.
>
> It seems like we could drop the dependencies on Core and Symbol by moving 
> Symbols somewhere else. How much work would there be left after Pavel's patch?


Moving Symbols somewhere else isn't exactly easy though.  There's a lot of 
interdependencies that are slightly different on every Host platform, so it 
creates a lot of breakage doing things this way.

FWIW, I actually wouldn't mind moving everything out of Host into System until 
Host is basically empty.  My next step after this patch was going to be to move 
MainLoop followed by Socket into System (those are my actual goals anyway).  In 
some ways, approaching the dependency problem from both directions this way is 
more effective than approaching it from only one side, as this way eventually 
Host becomes so small that you can just take whatever is left over and have it 
be subsumed by some other target (probably Core or Symbols).

All of that said, I'm not as sold that having a separate library just for Host 
is even terribly useful.  I'll go along with it if that's what everyone wants, 
but at the end of the day, this library (whether it be called Host, or System, 
or something else) will almost certainly depend on Utility, and Utility will 
almost certainly depend on it (for the same reason that Utility currently 
depends on llvm/Support).  This is why in LLVM/Support there are both non-Host 
specific things, such as `StringExtras.h`, and host specific things, such as 
`FileSystem.h`, `Thread.h`, etc.  I don't think that's actually so bad in 
practice.

So my vote is honestly still to just put this in Utility for consistency with 
LLVM, but I can agree with `System` or something as part of a transition if it 
gets us closer to being able to use these utility classes without a dependency 
on the whole debugger.


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

https://reviews.llvm.org/D58654



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


[Lldb-commits] [PATCH] D58167: Refactor user/group name resolving code

2019-02-26 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: include/lldb/Host/UserIDResolver.h:9
+
+#ifndef LLDB_HOST_USERIDRESOLVER_H
+#define LLDB_HOST_USERIDRESOLVER_H

I wonder if this class should actually be in Host.  While some specific 
implementation of it might be host-dependent, the interface itself is not.  I 
kind of envision at some point in the future having a target that contains all 
of our core interfaces that someone can include and re-implement small pieces 
of the debugger without having to bring in the entire thing.  This is also nice 
from a mocking / unittesting perspective.

So I think this would be better if it were in Utility (or some other top-level 
library such as Interfaces)


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

https://reviews.llvm.org/D58167



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


[Lldb-commits] [PATCH] D58654: Move Config.h from Host to Utility

2019-02-26 Thread Zachary Turner via Phabricator via lldb-commits
zturner updated this revision to Diff 188393.
zturner added a comment.

Moved to `System` instead of `Utility`


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

https://reviews.llvm.org/D58654

Files:
  lldb/cmake/XcodeHeaderGenerator/CMakeLists.txt
  lldb/cmake/modules/LLDBGenerateConfig.cmake
  lldb/include/lldb/Host/Config.h
  lldb/include/lldb/Host/Config.h.cmake
  lldb/include/lldb/Host/MainLoop.h
  lldb/include/lldb/Host/Terminal.h
  lldb/include/lldb/Host/linux/Uio.h
  lldb/include/lldb/System/lldb-config.h
  lldb/include/lldb/System/lldb-config.h.cmake
  lldb/include/lldb/Target/Process.h
  lldb/source/Host/common/File.cpp
  lldb/source/Host/common/HostInfoBase.cpp
  lldb/source/Host/common/ProcessLaunchInfo.cpp
  lldb/source/Host/common/PseudoTerminal.cpp
  lldb/source/Host/common/Socket.cpp
  lldb/source/Host/common/TCPSocket.cpp
  lldb/source/Host/common/Terminal.cpp
  lldb/source/Host/common/UDPSocket.cpp
  lldb/source/Host/linux/HostInfoLinux.cpp
  lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
  lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
  lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
  lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
  lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
  lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
  lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
  
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/unittests/Host/SocketTest.cpp

Index: lldb/unittests/Host/SocketTest.cpp
===
--- lldb/unittests/Host/SocketTest.cpp
+++ lldb/unittests/Host/SocketTest.cpp
@@ -12,10 +12,10 @@
 
 #include "gtest/gtest.h"
 
-#include "lldb/Host/Config.h"
 #include "lldb/Host/Socket.h"
 #include "lldb/Host/common/TCPSocket.h"
 #include "lldb/Host/common/UDPSocket.h"
+#include "lldb/System/lldb-config.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "lldb/Host/Config.h"
+#include "lldb/System/lldb-config.h"
 
 #include 
 #include 
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -19,11 +19,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Threading.h"
 
-#include "lldb/Host/Config.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
 #include "lldb/Host/FileAction.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
+#include "lldb/System/lldb-config.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/UnixSignals.h"
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -8,7 +8,7 @@
 
 #include 
 
-#include "lldb/Host/Config.h"
+#include "lldb/System/lldb-config.h"
 
 #include "GDBRemoteCommunicationServerLLGS.h"
 #include "lldb/Utility/StreamGDBRemote.h"
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -18,7 +18,6 @@
 #include 
 
 #include "lldb/Core/ModuleSpec.h"
-#include "lldb/Host/Config.h"
 #include "lldb/Host/File.h"
 #include "lldb/Host/FileAction.h"
 #include "lldb/Host/FileSystem.h"
@@ -27,6 +26,7 @@
 #include "lldb/Host/SafeMachO.h"
 #include "lldb/Interpreter/OptionArgParser.h"
 #include 

[Lldb-commits] [PATCH] D58654: Move Config.h from Host to Utility

2019-02-25 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D58654#1410080 , @jingham wrote:

> There aren't many more platforms (OpenVMS?) that are likely to show up and 
> need support for lldb, so maybe this is making too much of the matter.  But 
> having there be a well defined set of places where you need to look when 
> porting lldb to a new host platform seems a useful design to me.  The fact 
> that we weren't strict enough and allowed Host platform dependencies to creep 
> in where they don't belong doesn't argue we should just abandon trying to 
> keep the places where a port sockets into lldb regular.
>
> It's fine to have a staging area ("WillBeHost"?) to help pull out the classes 
> that it is simple to pull out of host.  But I'd rather not glom them all into 
> Utility, which is already becoming a little incoherent.


How about "System" then?  FTR, I'm also fine eventually renaming it back to 
Host once all the layering issues are addressed.  The important thing is that 
if it's really just a set of platform-specific abstractions, it shouldn't 
really depend on anything else (except perhaps Utility).

I guess one advantage to having them be together though is that often even the 
Utility code itself needs to make use of platform-specific abstractions.  You 
can already see this anywhere that lldb/Utility calls into llvm/Support to do 
things like read from the file system or start a thread (TBH, I'm actually not 
even sure it does any of those things, but it seems reasonable that it might 
want to).  So if we make a library called System, then it's possible that 
System ends up depending on Utility and Utility ends up depending on System.  
Despite all of mine (and others') push for proper layering, this is one area 
where I'm actually ok with it.  LLVM has the same issue here, where ADT and 
Support depend on each other and just linked together into one big .lib, 
despite being in separate folders.

But it's something to keep in mind.

Anyway, does that seem reasonable?  Put it in a new folder called `System`?


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

https://reviews.llvm.org/D58654



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


[Lldb-commits] [PATCH] D58654: Move Config.h from Host to Utility

2019-02-25 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D58654#1409974 , @jingham wrote:

> Utility is supposed to be a bunch of stand-alone utility files & headers that 
> we gather together for convenience's sake.
>
> Host is where we put all the code that is specific to one or another host, 
> and any support files that requires.  For instance, that's why PlatformLinux 
> and friends are there, and all the independent platform directories.  So it 
> is odd to move platform specific defines from Host to Utility.
>
> I don't care much about the name, but having this in Utility when it is 
> setting Host defines and we have a place clearly set out for host support 
> files doesn't seem right.


That is how Host started out, but I think that that distinction both a) hasn't 
played out the way we hoped for in practice, and b) isn't necessarily the right 
line to draw anyway.  We have quite a few ifdefs scattered around the codebase 
for different platforms that are not in Host in places where we couldn't easily 
(or cleanly) make the code fit into that separation model.  On the flip side, 
lots of stuff has crept into Host that isn't really host-specific, which is why 
the dependencies are so tangled up.

I think following the LLVM/Support model makes sense.  It's "Utility", plus 
what we would normally think of as "Host".  This is a lot cleaner than it 
sounds, and all of the ifdefs and platform specific defines end up only in 
private implementation files, with none exposed through headers.

To be honest, I don't mind if we call it something other than Host (for example 
it could be called System or something), but the practical issue with using 
Host today is that it still has a ways to go before it can be linked against 
without pulling in the rest of LLDB, and the changes needed to get there are 
not trivial, so it will take some more continued effort.

Regardless, in my mind Utility is exactly what you said, but that definition 
doesn't actually preclude Host-specific things.  In fact, putting Host-specific 
abstractions there solves a lot of problems.  Imagine, for example, someone 
wanted to create a debugging related tool that was not a full-fledged debugger. 
 They might want to use lots of functionality that is in Utility and Host, but 
not bring in everything else.  That's what Utility is to me.  It's a set of 
abstractions that are useful for creating debugging-related tooling that 
someone can use for that purpose.

I don't necessarily care if it's in Utility or some other newly created library 
we call something else, but we need some immediate way of using these 
abstractions without linking against the rest of LLDB so that we're not blocked 
on finishing the layering split.

One option would be to just keep growing Utility with these kinds of classes 
and abstractions until we decide that it's too big, at which point a separation 
would probably fall out naturally (FWIW, this is how LLVM/Support and LLVM/ADT 
evolved into what they are)


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

https://reviews.llvm.org/D58654



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


[Lldb-commits] [PATCH] D58654: Move Config.h from Host to Utility

2019-02-25 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: labath, jgorbe, JDevlieghere, davide.
Herald added subscribers: mgorny, emaste.

`Host/Config.h` is where we have platform specific preprocessor defines that 
are configured at CMake time.  Then, we can include this file 
`lldb/Host/Config.h` and read the value of defines.  This is basically 
identical to what llvm does with `llvm/Support/llvm-config.h`, the only 
fundamental differences being: a) LLDB configures it into `lldb/Host` where as 
the spiritual equivalent to `llvm/Support` is `lldb/Utility`, and b) LLDB calls 
it `Config.h` and LLVM calls it `llvm-config.h`.

This patch brings LLDB in line with LLVM here by configuring into 
`lldb/Utility/lldb-config.h`, in part for consistency and in part for more 
practical reasons.

The practical reasons are that I want to use `Socket.h` from a new tool / 
library without having to link all of LLDB such as Clang, Python, etc, and 
that's not currently possible with the current layering, as linking to Host 
will link to everything.

So this is a necessary first step.  `llvm/Support`'s model for handling 
platform specific differences is quite convenient both from a usability as well 
as a maintenance perspective, and I'd like to gradually move towards that 
whenever an opportunity / need arises.  So the immediate plan is to move 
`config.h` to Utility, and then start by moving pieces -- as necessary -- from 
Host to Utility until I can get `Socket` just by linking to `lldbUtility`.


https://reviews.llvm.org/D58654

Files:
  lldb/cmake/XcodeHeaderGenerator/CMakeLists.txt
  lldb/cmake/modules/LLDBGenerateConfig.cmake
  lldb/include/lldb/Host/Config.h
  lldb/include/lldb/Host/Config.h.cmake
  lldb/include/lldb/Host/MainLoop.h
  lldb/include/lldb/Host/Terminal.h
  lldb/include/lldb/Host/linux/Uio.h
  lldb/include/lldb/Target/Process.h
  lldb/include/lldb/Utility/lldb-config.h
  lldb/include/lldb/Utility/lldb-config.h.cmake
  lldb/source/Host/common/File.cpp
  lldb/source/Host/common/HostInfoBase.cpp
  lldb/source/Host/common/ProcessLaunchInfo.cpp
  lldb/source/Host/common/PseudoTerminal.cpp
  lldb/source/Host/common/Socket.cpp
  lldb/source/Host/common/TCPSocket.cpp
  lldb/source/Host/common/Terminal.cpp
  lldb/source/Host/common/UDPSocket.cpp
  lldb/source/Host/linux/HostInfoLinux.cpp
  lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
  lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
  lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
  lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
  lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
  lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
  lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
  
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/unittests/Host/SocketTest.cpp

Index: lldb/unittests/Host/SocketTest.cpp
===
--- lldb/unittests/Host/SocketTest.cpp
+++ lldb/unittests/Host/SocketTest.cpp
@@ -12,10 +12,10 @@
 
 #include "gtest/gtest.h"
 
-#include "lldb/Host/Config.h"
 #include "lldb/Host/Socket.h"
 #include "lldb/Host/common/TCPSocket.h"
 #include "lldb/Host/common/UDPSocket.h"
+#include "lldb/Utility/lldb-config.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "lldb/Host/Config.h"
+#include "lldb/Utility/lldb-config.h"
 
 #include 
 #include 
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -19,7 +19,6 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Threading.h"
 
-#include "lldb/Host/Config.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
 #include "lldb/Host/FileAction.h"
 #include 

[Lldb-commits] [PATCH] D57780: Don't include UnixSignals.h from Host

2019-02-15 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB354168: Dont include UnixSignals.h from Host. 
(authored by zturner, committed by ).
Herald added subscribers: abidh, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D57780?vs=185379=187071#toc

Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D57780

Files:
  include/lldb/Host/Host.h
  include/lldb/Host/Symbols.h
  include/lldb/Target/Platform.h
  include/lldb/Target/UnixSignals.h
  source/Host/common/Host.cpp
  source/Host/common/Symbols.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
  source/Target/Platform.cpp
  source/Target/UnixSignals.cpp
  unittests/Host/SymbolsTest.cpp

Index: unittests/Host/SymbolsTest.cpp
===
--- unittests/Host/SymbolsTest.cpp
+++ unittests/Host/SymbolsTest.cpp
@@ -12,6 +12,7 @@
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Host/Symbols.h"
+#include "lldb/Target/Target.h"
 
 using namespace lldb_private;
 
@@ -33,7 +34,9 @@
 SymbolsTest,
 TerminateLocateExecutableSymbolFileForUnknownExecutableAndUnknownSymbolFile) {
   ModuleSpec module_spec;
-  FileSpec symbol_file_spec = Symbols::LocateExecutableSymbolFile(module_spec);
+  FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
+  FileSpec symbol_file_spec =
+  Symbols::LocateExecutableSymbolFile(module_spec, search_paths);
   EXPECT_TRUE(symbol_file_spec.GetFilename().IsEmpty());
 }
 
@@ -43,6 +46,8 @@
   // using a GUID here because the symbol file shouldn't actually exist on disk
   module_spec.GetSymbolFileSpec().SetFile(
   "4A524676-B24B-4F4E-968A-551D465EBAF1.so", FileSpec::Style::native);
-  FileSpec symbol_file_spec = Symbols::LocateExecutableSymbolFile(module_spec);
+  FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
+  FileSpec symbol_file_spec =
+  Symbols::LocateExecutableSymbolFile(module_spec, search_paths);
   EXPECT_TRUE(symbol_file_spec.GetFilename().IsEmpty());
 }
Index: source/Target/UnixSignals.cpp
===
--- source/Target/UnixSignals.cpp
+++ source/Target/UnixSignals.cpp
@@ -11,6 +11,7 @@
 #include "Plugins/Process/Utility/LinuxSignals.h"
 #include "Plugins/Process/Utility/MipsLinuxSignals.h"
 #include "Plugins/Process/Utility/NetBSDSignals.h"
+#include "lldb/Host/HostInfo.h"
 #include "lldb/Host/StringConvert.h"
 #include "lldb/Utility/ArchSpec.h"
 
@@ -50,6 +51,12 @@
   }
 }
 
+lldb::UnixSignalsSP UnixSignals::CreateForHost() {
+  static lldb::UnixSignalsSP s_unix_signals_sp =
+  Create(HostInfo::GetArchitecture());
+  return s_unix_signals_sp;
+}
+
 //--
 // UnixSignals constructor
 //--
Index: source/Target/Platform.cpp
===
--- source/Target/Platform.cpp
+++ source/Target/Platform.cpp
@@ -1740,9 +1740,9 @@
   return s_default_unix_signals_sp;
 }
 
-const UnixSignalsSP ::GetUnixSignals() {
+UnixSignalsSP Platform::GetUnixSignals() {
   if (IsHost())
-return Host::GetUnixSignals();
+return UnixSignals::CreateForHost();
   return GetRemoteUnixSignals();
 }
 
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -49,6 +49,7 @@
 #include "lldb/Symbol/VariableList.h"
 
 #include "lldb/Target/Language.h"
+#include "lldb/Target/Target.h"
 
 #include "AppleDWARFIndex.h"
 #include "DWARFASTParser.h"
@@ -3836,7 +3837,10 @@
 module_spec.GetFileSpec() = m_obj_file->GetFileSpec();
 module_spec.GetSymbolFileSpec() =
 FileSpec(m_obj_file->GetFileSpec().GetPath() + ".dwp");
-FileSpec dwp_filespec = Symbols::LocateExecutableSymbolFile(module_spec);
+
+FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
+FileSpec dwp_filespec =
+Symbols::LocateExecutableSymbolFile(module_spec, search_paths);
 if (FileSystem::Instance().Exists(dwp_filespec)) {
   m_dwp_symfile = SymbolFileDWARFDwp::Create(GetObjectFile()->GetModule(),
  dwp_filespec);
Index: source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
===
--- source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
+++ source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
@@ -17,6 +17,7 @@
 #include "lldb/Host/Host.h"
 

[Lldb-commits] [PATCH] D58172: Embed swig version into lldb.py in a different way

2019-02-14 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

Long term, I wonder if we can just delete this entire `modify-python-lldb.py` 
script.  it seems like the entire purpose is to make sure that the SB methods 
support iteration, equality, and some other basic stuff, and it does this by 
inserting lines of python code into the actual `__init__.py` file.  It seems 
like we could just have the swig file say `%pythoncode%{import sb_iteration}`, 
then write a file called `sb_iteration.py` which we ship alongside the 
`__init__.py`, and have it dynamically add all of the things it needs at 
runtime.  Then, we don't even need a a post processing step at all, which seems 
like a definite improvement.

As for this particular change, another option is to just say:

  %pythoncode%{
swig_version = VERSION
  }

There's no real reason we have to do the parsing here, we could do it in our 
dotest.py decorators.  I don't have a strong preference on which is better 
though.


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

https://reviews.llvm.org/D58172



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


[Lldb-commits] [PATCH] D57840: Convert TestCommandRegex to lit (from expect)

2019-02-06 Thread Zachary Turner via Phabricator via lldb-commits
zturner accepted this revision.
zturner added a comment.
This revision is now accepted and ready to land.

Can you rename these two tests to `command-regex-delete.test` and 
`command-regex-unalias.test`?  Otherwise, lgtm


Repository:
  rL LLVM

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

https://reviews.llvm.org/D57840



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


[Lldb-commits] [PATCH] D57780: Don't include UnixSignals.h from Host

2019-02-05 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added a reviewer: labath.
Herald added a reviewer: jfb.

This file lives in Target, which makes sense since it is supposed to represent 
the various types of signals that can occur on any platform (since you might be 
remote debugging a platform with different signals than the host).

However, Host had a method called `GetUnixSignals` which just returned an 
instance of this class initialized for the Host's signals.  Rather than have 
this functionality in Host, we can just provide a static factory method on 
`UnixSignals` called `CreateForHost`.  This brings us one step closer to 
breaking the Target -> Host -> Target cycle.


https://reviews.llvm.org/D57780

Files:
  lldb/include/lldb/Host/Host.h
  lldb/include/lldb/Target/Platform.h
  lldb/include/lldb/Target/UnixSignals.h
  lldb/source/Host/common/Host.cpp
  
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Target/UnixSignals.cpp

Index: lldb/source/Target/UnixSignals.cpp
===
--- lldb/source/Target/UnixSignals.cpp
+++ lldb/source/Target/UnixSignals.cpp
@@ -11,6 +11,7 @@
 #include "Plugins/Process/Utility/LinuxSignals.h"
 #include "Plugins/Process/Utility/MipsLinuxSignals.h"
 #include "Plugins/Process/Utility/NetBSDSignals.h"
+#include "lldb/Host/HostInfo.h"
 #include "lldb/Host/StringConvert.h"
 #include "lldb/Utility/ArchSpec.h"
 
@@ -50,6 +51,12 @@
   }
 }
 
+lldb::UnixSignalsSP UnixSignals::CreateForHost() {
+  static lldb::UnixSignalsSP s_unix_signals_sp =
+  Create(HostInfo::GetArchitecture());
+  return s_unix_signals_sp;
+}
+
 //--
 // UnixSignals constructor
 //--
Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -1739,9 +1739,9 @@
   return s_default_unix_signals_sp;
 }
 
-const UnixSignalsSP ::GetUnixSignals() {
+UnixSignalsSP Platform::GetUnixSignals() {
   if (IsHost())
-return Host::GetUnixSignals();
+return UnixSignals::CreateForHost();
   return GetRemoteUnixSignals();
 }
 
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -398,7 +398,7 @@
 StringExtractorGDBRemote ) {
   StructuredData::Array signal_array;
 
-  const auto  = Host::GetUnixSignals();
+  lldb::UnixSignalsSP signals = UnixSignals::CreateForHost();
   for (auto signo = signals->GetFirstSignalNumber();
signo != LLDB_INVALID_SIGNAL_NUMBER;
signo = signals->GetNextSignalNumber(signo)) {
Index: lldb/source/Host/common/Host.cpp
===
--- lldb/source/Host/common/Host.cpp
+++ lldb/source/Host/common/Host.cpp
@@ -56,7 +56,6 @@
 #include "lldb/Host/ProcessLauncher.h"
 #include "lldb/Host/ThreadLauncher.h"
 #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
-#include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/DataBufferLLVM.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Log.h"
@@ -613,12 +612,6 @@
 
 #endif
 
-const UnixSignalsSP ::GetUnixSignals() {
-  static const auto s_unix_signals_sp =
-  UnixSignals::Create(HostInfo::GetArchitecture());
-  return s_unix_signals_sp;
-}
-
 std::unique_ptr Host::CreateDefaultConnection(llvm::StringRef url) {
 #if defined(_WIN32)
   if (url.startswith("file://"))
Index: lldb/include/lldb/Target/UnixSignals.h
===
--- lldb/include/lldb/Target/UnixSignals.h
+++ lldb/include/lldb/Target/UnixSignals.h
@@ -22,6 +22,7 @@
 class UnixSignals {
 public:
   static lldb::UnixSignalsSP Create(const ArchSpec );
+  static lldb::UnixSignalsSP CreateForHost();
 
   //--
   // Constructors and Destructors
Index: lldb/include/lldb/Target/Platform.h
===
--- lldb/include/lldb/Target/Platform.h
+++ lldb/include/lldb/Target/Platform.h
@@ -689,7 +689,7 @@
 
   virtual const lldb::UnixSignalsSP ();
 
-  const lldb::UnixSignalsSP ();
+  lldb::UnixSignalsSP GetUnixSignals();
 
   //--
   /// Locate a queue name given a thread's qaddr
Index: lldb/include/lldb/Host/Host.h
===
--- lldb/include/lldb/Host/Host.h
+++ lldb/include/lldb/Host/Host.h
@@ -196,8 +196,6 @@
 
   static bool GetProcessInfo(lldb::pid_t pid, 

[Lldb-commits] [PATCH] D56904: [NativePDB] Process virtual bases in the correct order

2019-02-04 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

In D56904#1383148 , @aleksandr.urakov 
wrote:

> Ping! What do you think about it?


Generally the change looks good, but I'm not sure why the compiler can't 
properly compile the source file.  I know it's something to do with the 
environment, but it's hard to say what.

One idea would be to add `-###` to the end of your command line when running 
the command manually, and then update the `build.py` script so that it also 
runs `-###` from the command line and prints the output.  Then maybe compare 
the two command lines and see if there's a difference.

Another idea would be to hack up the code in the `build.py` script that 
modifies the child process's environment.  Start with the child environment 
hardcoded to your terminal's environment, and then delete variables until the 
problem reproduces.  That should tell you what environment variable is causing 
the problem.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D56904



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


[Lldb-commits] [PATCH] D57552: Handle "." in target.source-map in PathMapListing::FindFiles

2019-02-01 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: source/Target/PathMappingList.cpp:204
FileSpec _spec) const {
   if (!m_pairs.empty()) {
+std::string orig_path = orig_spec.GetPath();

Can we put some early returns in here?

```
new_spec.Clear();

if (m_pairs.empty())
  return;
```



Comment at: source/Target/PathMappingList.cpp:207
+
+if (!orig_path.empty()) {
+  llvm::StringRef orig_ref(orig_path);

```
if (orig_path.empty())
  return;
```



Comment at: source/Target/PathMappingList.cpp:208
+if (!orig_path.empty()) {
+  llvm::StringRef orig_ref(orig_path);
+  bool orig_is_relative = orig_spec.IsRelative();

I think we can move this declaration inside of the for loop



Comment at: source/Target/PathMappingList.cpp:212
   const_iterator pos, end = m_pairs.end();
   for (pos = m_pairs.begin(); pos != end; ++pos) {
+llvm::StringRef prefix_ref = pos->first.GetStringRef();

How about 

```
for (const auto  : m_pairs) {
}
```



Comment at: source/Target/PathMappingList.cpp:232
+  llvm::StringRef orig_remaining = orig_ref;
+  if (orig_remaining.consume_front(prefix_ref)) {
 new_spec.SetFile(pos->second.GetCString(), 
FileSpec::Style::native);

After moving inside of the for loop, you can just write `if 
(orig_ref.consume_front(prefix_ref))`


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D57552



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


[Lldb-commits] [PATCH] D57213: [Scalar] Add support for 512-bits values.

2019-01-30 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: lldb/source/Utility/Scalar.cpp:168
+  swapped_words[6] = apint_words[1];
+  swapped_words[7] = apint_words[0];
+  apint_words = swapped_words;

davide wrote:
> davide wrote:
> > aprantl wrote:
> > > std::reverse perhaps?
> > We might want to change this everywhere.
> I updated the comment but I can't really easily use `std::swap` or 
> `std::reverse` because they operate on vectors and the unit of currency here 
> is an array.
> I thought about initializing a vector from the array we read and then call 
> `std::reverse` (and then covert back to a pointer), but that didn't seem 
> better than what we have now (or, at least, less ugly).
I'm confused why `std::swap(swapped_words[7], swapped_words[0]);` and similar 
for the other 4 doesn't work though.


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

https://reviews.llvm.org/D57213



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


[Lldb-commits] [PATCH] D55122: [PDB] Fix location retrieval for function local variables and arguments that are stored relative to VFRAME

2019-01-30 Thread Zachary Turner via Phabricator via lldb-commits
zturner accepted this revision.
zturner added a comment.
This revision is now accepted and ready to land.

This is really cool, thanks for doing this!




Comment at: source/Expression/DWARFExpression.cpp:3253
 
-  return false;
+  return true;
 }

Why do we change the return value here?



Comment at: source/Plugins/SymbolFile/NativePDB/CodeViewRegisterMapping.h:16
+
+uint32_t GetLLDBRegisterNumber(llvm::Triple::ArchType arch_type,
+   llvm::codeview::RegisterId register_id);

Can you put this function in the `lldb_private::npdb` namespace?



Comment at: 
source/Plugins/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpression.h:20
+
+bool TranslateFPOProgramToDWARFExpression(llvm::StringRef program,
+  llvm::StringRef register_name,

Can you put this function in the `lldb_private::npdb` namespace?


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D55122



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


[Lldb-commits] [PATCH] D57413: Fix some warnings with gcc on Linux

2019-01-29 Thread Zachary Turner via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB352557: Fix some warnings in building LLDB. (authored by 
zturner, committed by ).
Herald added a subscriber: abidh.

Changed prior to commit:
  https://reviews.llvm.org/D57413?vs=184163=184186#toc

Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D57413

Files:
  source/Commands/CommandObjectReproducer.cpp
  source/Plugins/Language/ObjC/Cocoa.cpp
  source/Plugins/Language/ObjC/NSArray.cpp
  source/Plugins/Language/ObjC/NSDictionary.cpp
  source/Plugins/Language/ObjC/NSSet.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1663,7 +1663,6 @@
 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
 
 DWARFFormValue type_die_form;
-int64_t first_index = 0;
 uint32_t byte_stride = 0;
 uint32_t bit_stride = 0;
 bool is_vector = false;
@@ -1733,7 +1732,6 @@
   if (element_type) {
 auto array_info = ParseChildArrayInfo(die);
 if (array_info) {
-  first_index = array_info->first_index;
   byte_stride = array_info->byte_stride;
   bit_stride = array_info->bit_stride;
 }
Index: source/Plugins/Language/ObjC/Cocoa.cpp
===
--- source/Plugins/Language/ObjC/Cocoa.cpp
+++ source/Plugins/Language/ObjC/Cocoa.cpp
@@ -754,7 +754,7 @@
 uint64_t fraction:52;  // unsigned
 uint64_t exponent:11;  // signed
 uint64_t sign:1;
-  };
+  } repr;
   uint64_t i;
   double d;
 } DoubleBits;
@@ -764,7 +764,7 @@
 uint64_t exponent:7;   // signed
 uint64_t sign:1;
 uint64_t unused:4;  // placeholder for pointer tag bits
-  };
+  } repr;
   uint64_t i;
 } TaggedDoubleBits;
 
@@ -786,10 +786,10 @@
 
   // Sign and fraction are represented exactly.
   // Exponent is encoded.
-  assert(encodedBits.unused == 0);
-  decodedBits.sign = encodedBits.sign;
-  decodedBits.fraction = encodedBits.fraction;
-  decodedBits.exponent = decodeExponent(encodedBits.exponent);
+  assert(encodedBits.repr.unused == 0);
+  decodedBits.repr.sign = encodedBits.repr.sign;
+  decodedBits.repr.fraction = encodedBits.repr.fraction;
+  decodedBits.repr.exponent = decodeExponent(encodedBits.repr.exponent);
 
   return decodedBits.d;
 }
Index: source/Plugins/Language/ObjC/NSArray.cpp
===
--- source/Plugins/Language/ObjC/NSArray.cpp
+++ source/Plugins/Language/ObjC/NSArray.cpp
@@ -171,13 +171,8 @@
 PtrType _data;
 uint32_t _offset;
 uint32_t _size;
-union {
-  PtrType _mutations;
-  struct {
-uint32_t _muts;
-uint32_t _used;
-  };
-};
+uint32_t _muts;
+uint32_t _used;
   };
 
   using NSArrayMSyntheticFrontEnd =
Index: source/Plugins/Language/ObjC/NSDictionary.cpp
===
--- source/Plugins/Language/ObjC/NSDictionary.cpp
+++ source/Plugins/Language/ObjC/NSDictionary.cpp
@@ -281,18 +281,11 @@
   
   struct DataDescriptor_32 {
 uint32_t _buffer;
-union {
-  struct {
-uint32_t _mutations;
-  };
-  struct {
-uint32_t _muts;
-uint32_t _used:25;
-uint32_t _kvo:1;
-uint32_t _szidx:6;
-  };
-};
-
+uint32_t _muts;
+uint32_t _used : 25;
+uint32_t _kvo : 1;
+uint32_t _szidx : 6;
+
 uint64_t GetSize() {
   return (_szidx) >= NSDictionaryNumSizeBuckets ?
   0 : NSDictionaryCapacities[_szidx];
@@ -301,18 +294,11 @@
   
   struct DataDescriptor_64 {
 uint64_t _buffer;
-union {
-  struct {
-uint64_t _mutations;
-  };
-  struct {
-uint32_t _muts;
-uint32_t _used:25;
-uint32_t _kvo:1;
-uint32_t _szidx:6;
-  };
-};
-
+uint32_t _muts;
+uint32_t _used : 25;
+uint32_t _kvo : 1;
+uint32_t _szidx : 6;
+
 uint64_t GetSize() {
   return (_szidx) >= NSDictionaryNumSizeBuckets ?
   0 : NSDictionaryCapacities[_szidx];
Index: source/Plugins/Language/ObjC/NSSet.cpp
===
--- source/Plugins/Language/ObjC/NSSet.cpp
+++ source/Plugins/Language/ObjC/NSSet.cpp
@@ -154,28 +154,18 @@
 uint32_t _cow;
 // __table storage
 uint32_t _objs_addr;
-union {
-  uint32_t _mutations;
-  struct {
-uint32_t _muts;
-uint32_t _used : 26;
-uint32_t _szidx : 6;
-  };
-};
+uint32_t _muts;
+uint32_t _used : 26;
+

[Lldb-commits] [PATCH] D57413: Fix some warnings with gcc on Linux

2019-01-29 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked an inline comment as done.
zturner added inline comments.



Comment at: lldb/source/Plugins/Language/ObjC/NSDictionary.cpp:304-314
-union {
-  struct {
-uint64_t _mutations;
-  };
-  struct {
-uint32_t _muts;
-uint32_t _used:25;

zturner wrote:
> jingham wrote:
> > I don't think this is right. The data formatter is reading a target side 
> > struct onto a host struct to read it in.  For instance, later on the code 
> > does:
> > 
> > m_data_64 = new DataDescriptor_64();
> > process_sp->ReadMemory(data_location, m_data_64, 
> > sizeof(DataDescriptor_64),
> >error);
> > 
> > So if you remove mutations you won't read in enough bytes and they won't be 
> > correctly aligned.
> > 
> > That's not safe if the host and target have different endian-ness, so this 
> > doesn't seem a great way to get this data into lldb.  It would be more 
> > correct to make a DataExtractor for this read, and then pull the fields out 
> > of it by size and type.  
> > 
> > But as it stands, you can't just delete these fields.
> That is indeed how I assumed this works, but if you look carefully, it's a 
> union of a) a 64-bit struct (struct with one uint64 member), and b) a struct 
> with a uint32 followed by another uint32 bitfield.  So also 64-bits.  So 
> deleting the first struct (which is never referenced) allows us to remove the 
> union entirely, and should have no impact on the size of the final struct.
Just to be sure, I added this:

```
  struct DataDescriptor_64 {
uint64_t _buffer;
uint32_t _muts;
uint32_t _used : 25;
uint32_t _kvo : 1;
uint32_t _szidx : 6;

uint64_t GetSize() {
  return (_szidx) >= NSDictionaryNumSizeBuckets ?
  0 : NSDictionaryCapacities[_szidx];
}
  };

  
  struct DataDescriptor_64_2 {
uint64_t _buffer;
union {
  struct {
uint64_t _mutations;
  };
  struct {
uint32_t _muts;
uint32_t _used : 25;
uint32_t _kvo : 1;
uint32_t _szidx : 6;
  };
};
  };

  static_assert(sizeof(DataDescriptor_64_2) == sizeof(DataDescriptor_64), 
"mismatched size!");

```

And the static assert passes.  I wouldn't want to leave that in the final code, 
but the point is that I it's still NFC even in the face of deleting the fields.


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

https://reviews.llvm.org/D57413



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


[Lldb-commits] [PATCH] D57413: Fix some warnings with gcc on Linux

2019-01-29 Thread Zachary Turner via Phabricator via lldb-commits
zturner marked an inline comment as done.
zturner added inline comments.



Comment at: lldb/source/Plugins/Language/ObjC/NSDictionary.cpp:304-314
-union {
-  struct {
-uint64_t _mutations;
-  };
-  struct {
-uint32_t _muts;
-uint32_t _used:25;

jingham wrote:
> I don't think this is right. The data formatter is reading a target side 
> struct onto a host struct to read it in.  For instance, later on the code 
> does:
> 
> m_data_64 = new DataDescriptor_64();
> process_sp->ReadMemory(data_location, m_data_64, 
> sizeof(DataDescriptor_64),
>error);
> 
> So if you remove mutations you won't read in enough bytes and they won't be 
> correctly aligned.
> 
> That's not safe if the host and target have different endian-ness, so this 
> doesn't seem a great way to get this data into lldb.  It would be more 
> correct to make a DataExtractor for this read, and then pull the fields out 
> of it by size and type.  
> 
> But as it stands, you can't just delete these fields.
That is indeed how I assumed this works, but if you look carefully, it's a 
union of a) a 64-bit struct (struct with one uint64 member), and b) a struct 
with a uint32 followed by another uint32 bitfield.  So also 64-bits.  So 
deleting the first struct (which is never referenced) allows us to remove the 
union entirely, and should have no impact on the size of the final struct.


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

https://reviews.llvm.org/D57413



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


[Lldb-commits] [PATCH] D57413: Fix some warnings with gcc on Linux

2019-01-29 Thread Zachary Turner via Phabricator via lldb-commits
zturner created this revision.
zturner added reviewers: davide, JDevlieghere, jingham.

Most of these are surrounding the ObjectiveC formatters.  They use a lot of 
unions containing unnamed structs, which are not ISO C++ compliant and which 
gcc warns about.  There are several other minor warnings like unused variables, 
etc.

The ObjectiveC ones look NFC to me, because they basically just delete some 
structure / union members that are never read, but I'm throwing this up here 
for review anyway just to be on the safe side.


https://reviews.llvm.org/D57413

Files:
  lldb/source/Commands/CommandObjectReproducer.cpp
  lldb/source/Plugins/Language/ObjC/Cocoa.cpp
  lldb/source/Plugins/Language/ObjC/NSArray.cpp
  lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
  lldb/source/Plugins/Language/ObjC/NSSet.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1663,7 +1663,6 @@
 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
 
 DWARFFormValue type_die_form;
-int64_t first_index = 0;
 uint32_t byte_stride = 0;
 uint32_t bit_stride = 0;
 bool is_vector = false;
@@ -1733,7 +1732,6 @@
   if (element_type) {
 auto array_info = ParseChildArrayInfo(die);
 if (array_info) {
-  first_index = array_info->first_index;
   byte_stride = array_info->byte_stride;
   bit_stride = array_info->bit_stride;
 }
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -1263,7 +1263,7 @@
 
 void GDBRemoteCommunication::SetHistoryStream(llvm::raw_ostream *strm) {
   m_history.SetStream(strm);
-};
+}
 
 llvm::Error
 GDBRemoteCommunication::ConnectLocally(GDBRemoteCommunication ,
Index: lldb/source/Plugins/Language/ObjC/NSSet.cpp
===
--- lldb/source/Plugins/Language/ObjC/NSSet.cpp
+++ lldb/source/Plugins/Language/ObjC/NSSet.cpp
@@ -154,28 +154,18 @@
 uint32_t _cow;
 // __table storage
 uint32_t _objs_addr;
-union {
-  uint32_t _mutations;
-  struct {
-uint32_t _muts;
-uint32_t _used : 26;
-uint32_t _szidx : 6;
-  };
-};
+uint32_t _muts;
+uint32_t _used : 26;
+uint32_t _szidx : 6;
   };
   
   struct DataDescriptor_64 {
 uint64_t _cow;
 // __Table storage
 uint64_t _objs_addr;
-union {
-  uint64_t _mutations;
-  struct {
-uint32_t _muts;
-uint32_t _used : 26;
-uint32_t _szidx : 6;
-  };
-};
+uint32_t _muts;
+uint32_t _used : 26;
+uint32_t _szidx : 6;
   };
   
   using NSSetMSyntheticFrontEnd =
Index: lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
===
--- lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
+++ lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
@@ -281,18 +281,11 @@
   
   struct DataDescriptor_32 {
 uint32_t _buffer;
-union {
-  struct {
-uint32_t _mutations;
-  };
-  struct {
-uint32_t _muts;
-uint32_t _used:25;
-uint32_t _kvo:1;
-uint32_t _szidx:6;
-  };
-};
-
+uint32_t _muts;
+uint32_t _used : 25;
+uint32_t _kvo : 1;
+uint32_t _szidx : 6;
+
 uint64_t GetSize() {
   return (_szidx) >= NSDictionaryNumSizeBuckets ?
   0 : NSDictionaryCapacities[_szidx];
@@ -301,18 +294,11 @@
   
   struct DataDescriptor_64 {
 uint64_t _buffer;
-union {
-  struct {
-uint64_t _mutations;
-  };
-  struct {
-uint32_t _muts;
-uint32_t _used:25;
-uint32_t _kvo:1;
-uint32_t _szidx:6;
-  };
-};
-
+uint32_t _muts;
+uint32_t _used : 25;
+uint32_t _kvo : 1;
+uint32_t _szidx : 6;
+
 uint64_t GetSize() {
   return (_szidx) >= NSDictionaryNumSizeBuckets ?
   0 : NSDictionaryCapacities[_szidx];
Index: lldb/source/Plugins/Language/ObjC/NSArray.cpp
===
--- lldb/source/Plugins/Language/ObjC/NSArray.cpp
+++ lldb/source/Plugins/Language/ObjC/NSArray.cpp
@@ -171,13 +171,8 @@
 PtrType _data;
 uint32_t _offset;
 uint32_t _size;
-union {
-  PtrType _mutations;
-  struct {
-uint32_t _muts;
-uint32_t _used;
-  };
-};
+uint32_t _muts;
+uint32_t _used;
   };
 
   using 

[Lldb-commits] [PATCH] D56602: Move FileAction, ProcessInfo and ProcessLaunchInfo from Target to Host

2019-01-29 Thread Zachary Turner via Phabricator via lldb-commits
zturner accepted this revision.
zturner added a comment.
This revision is now accepted and ready to land.

Seems I had forgotten about this.  It looks pretty good to me, and I'm glad 
we're very close to breaking this dependency.


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

https://reviews.llvm.org/D56602



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


[Lldb-commits] [PATCH] D56904: [NativePDB] Process virtual bases in the correct order

2019-01-28 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

Sorry, due to the way Phabricator re-orders feedback across files when sending 
the email notification, if you're reading my comments in email you have to read 
the previous email from the bottom up.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D56904



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


[Lldb-commits] [PATCH] D56904: [NativePDB] Process virtual bases in the correct order

2019-01-28 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

The above suggestion is admittedly minor, but since it's both a minor 
performance improvement **and** a minor readability/maintainability 
improvement, I think it's probably worth doing.




Comment at: lit/SymbolFile/NativePDB/tag-types.cpp:5
 // Test that we can display tag types.
 // RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s 
 // RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \

aleksandr.urakov wrote:
> Clang gives me an error about char16_t, char32_t etc., but if I use MSVC 
> here, then the test compiles ok.
Usually this means clang cannot find your CRT headers.  Can you run with 
-verbose?  That should give you some insight into the environment we are 
running clang with, and might be a clue why it can't find the headers.



Comment at: source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp:54
+llvm::codeview::TypeIndex ti, llvm::codeview::MemberAccess access,
+bool is_virtual, uint64_t vtable_idx) {
   PdbTypeSymId type_id(ti);

Then, change this function to not pass `is_virtual`, only pass 
`Optional`.  



Comment at: source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp:60-63
   std::unique_ptr base_spec =
   m_ast_builder.clang().CreateBaseClassSpecifier(
-  qt.getAsOpaquePtr(), TranslateMemberAccess(access), false,
+  qt.getAsOpaquePtr(), TranslateMemberAccess(access), is_virtual,
   udt_cvt.kind() == LF_CLASS);

`vtable_idx.hasValue();`



Comment at: source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp:68-71
+  if (is_virtual)
+m_vbases[vtable_idx] = std::move(base_spec);
+  else
+m_bases.push_back(std::move(base_spec));

`m_bases.push_back(std::make_pair(vtable_idx.getValueOr(0), 
std::move(base_spec)));`



Comment at: source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp:188
 void UdtRecordCompleter::complete() {
+  // Flush all virtual bases using the correct order.
+  for (auto  : m_vbases)

```
using vt = std::pair>>;
std::stable_sort(m_bases, [](const vt , const vt ) {
  return base1.first < base2.first;
  });
```



Comment at: source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h:52
   std::vector> m_bases;
+  std::map> m_vbases;
   ClangASTImporter::LayoutInfo m_layout;

I actually think it would be slightly better to use a `vector>` here.  
The reason is that a) it will probably be slightly more efficient, because # of 
vbases is usually quite small (often just 1) and the overhead of a map is a net 
performance loss for small numbers of items.  b) that people are often confused 
when seeing `map` instead of `DenseMap` and it might cause someone in the 
future to think they can change this to a `DenseMap` with no behavioral 
difference, even though the reason for using a map here is that it must be 
sorted.

How about just having this:

```
std::vector>> 
m_bases;
```

Comments on how to change the implementation below.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D56904



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


[Lldb-commits] [PATCH] D56126: [NativePDB] Add basic support of methods recostruction in AST

2019-01-28 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a comment.

Thanks for the reminder!


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

https://reviews.llvm.org/D56126



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


[Lldb-commits] [PATCH] D57213: [Scalar] Add support for 512-bits values.

2019-01-28 Thread Zachary Turner via Phabricator via lldb-commits
zturner added inline comments.



Comment at: lldb/source/Utility/Scalar.cpp:161
+if (endian::InlHostByteOrder() == eByteOrderBig) {
+  swapped_words[0] = apint_words[7];
+  swapped_words[1] = apint_words[6];

I'm confused.  You say it returns a pointer to an array of four `uint64_t` 
values, but here you're clearly swapping the order of //eight// `uint64_t` 
values.  Is the comment wrong?

Anyway, how about:

```
std::swap(apint_words[0], apint_words[7]);
std::swap(apint_words[1], apint_words[6]);
std::swap(apint_words[2], apint_words[5]);
std::swap(apint_words[3], apint_words[4]);
```


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

https://reviews.llvm.org/D57213



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


  1   2   3   4   5   6   7   8   >