[Lldb-commits] [PATCH] D46726: build: use cmake to find the libedit content

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

The patch looks quite nice, though I can't say I know much about how 
find_package modules are supposed to be written. I won't click accept yet to 
see if anyone with more cmake knowledge steps in to review. In the mean time, I 
have two nitty comments.




Comment at: cmake/modules/FindLibEdit.cmake:11-14
+#   libedit_FOUND - true if libedit was found
+#   libedit_INCLUDE_DIRS  - include search path
+#   libedit_LIBRARIES - libraries to link
+#   libedit_VERSION   - version number

Should we make the capitalization of these match the file name (LibEdit_FOUND) ?



Comment at: cmake/modules/FindLibEdit.cmake:53-54
+set(libedit_VERSION_STRING 
"${libedit_major_version}.${libedit_minor_version}")
+unset(libedit_major_version)
+unset(libedit_minor_version)
+  endif()

Do you really need to unset these? I would hope that this file is evaluated in 
a fresh context, and it won't pollute the callers namespace or anything..


https://reviews.llvm.org/D46726



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


[Lldb-commits] [PATCH] D32167: Add support for type units (.debug_types) to LLDB in a way that is compatible with DWARF 5

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

The thing here is that I don't see how can be done in a non-hacky way in 
DWARFDataExtractor while DWARFDataExtractor remains a (subclass of) 
DataExtractor. And it is a hack because as soon as you slide the extractor, a 
number of its functions become booby-trapped (explode as soon as you call them) 
or just return nonsensical results. And I'd like us to implement it in a way 
that it is not a hack, on any level.

I see several ways of achieving this (in decreasing order of intrusiveness):

1. do this in the DataExtractor class. This would require us to change (extend) 
the definition of the class. Right now, I would define this class as "a view of 
a range of bytes with a bunch of utility functions for accessing them". After 
this change it would become something like "a view of a range of bytes with a 
bunch of utility functions for accessing them, **where the accessor functions 
automatically apply a bias to all offsets**". That's precisely the kind of 
change you are making now, only the difference would be that we would state 
this up-front rather than doing it behind the DataExtractor's back and hoping 
it works. In practice, this would be as simple as adding another `offset_t 
m_bias;` field to the class and going through it's methods to make sure the do 
something reasonable with it. "Something reasonable" would generally mean 
"subtract it from the input offset", but there are a couple of functions that 
would need to do something different, (e.g.,  ValidOffset() would return true 
for values from `m_bias` to `m_bias + (m_end-m_start) -1` because those are the 
only valid offsets, etc.). This is my preferred solution because it provides 
with a consistent DataExtractor interface (and in terms of code churn, I don't 
think it's harder to implement than any of the other solutions). It's true that 
dwarf type units will probably be the only user of these "slid" extractors, but 
I don't think that matters as their functionality can be defined in a clear and 
self-consistent manner without any references to dwarf.

2. Add the `m_bias` field to the DWARFDataExtractor class, but stop the class 
from publicly inheriting from DataExtractor (it can inherit privately, or have 
it as a member). The result of this is the same as the first option - we get to 
go through the DataExtractor interface and make sure all its functions do 
something sensible. The difference is that we may not need to go through that 
all methods, only those that are used for dwarf parsing; and the sliding trick 
can then be kept dwarf-specific.

3. Keep DWARFDataExtractor as-is, and add a new SlidingDWARFExtractor class 
instead (which will then to the `m_bias` trick and so on); then convert all 
places that need this to use the new class instead. This is a variation on the 
second option. I don't see it as particularly interesting, as it the 
DWARFDataExtractor is already a very small class, but it would still provide us 
self-consistent APIs everywhere.

I can also see some kind of a solution involving a ConcatenatingDataExtractor, 
which would contain two or more DataExtractors as it's backing store and then 
pretend they represent one continuous address space from `0` to `sum(sizes)` 
(no sliding necessary). This would achieve what you wanted at a higher level. 
In a way it would be nicer because there would be a single canonical bytestream 
for each symbol file and you wouldn't have to ask each DIE for it's own 
extractor, but I expect it to be a bit harder to implement, and may have a 
runtime cost.

The next solution which does not require sliding is to modify your previous 
patch `D46606` and insert some kind of offset fixup code there. It seems that 
in every place you call the new `GetData()` function, you have an offset around 
(makes sense, as the reason you are calling GetData is because you want to 
parse something). We could modify that function to take a virtual (slid) offset 
as a parameter, and return an offset which is suitable for usage in the 
returned extractor. So, the usage would become something like 
`std::tie(extractor, real_offset) = die.GetData(virtual_offset);`. I'm not sure 
how nice this will end up in practice, but it's a possibility.

Let me know what you think of these. I'm open to other options as well. The 
thing I'd like avoid is an implementation that relies on putting objects in an 
invalid state or invoking undefined behavior.


https://reviews.llvm.org/D32167



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


[Lldb-commits] [lldb] r332088 - Remove custom path manipulation functions from FileSpec

2018-05-11 Thread Pavel Labath via lldb-commits
Author: labath
Date: Fri May 11 04:55:34 2018
New Revision: 332088

URL: http://llvm.org/viewvc/llvm-project?rev=332088&view=rev
Log:
Remove custom path manipulation functions from FileSpec

Summary:
now that llvm supports host-agnostic path manipulation functions (and
most of their kinks have been ironed out), we can remove our copies of
the path parsing functions in favour of the llvm ones.

This should be NFC except for the slight difference in handling of the
"//" path, which is now normalized to "/" (this only applies to the
literal "//" path; "//net" and friends still get to keep the two
slashes).

Reviewers: zturner, clayborg

Subscribers: lldb-commits

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

Modified:
lldb/trunk/source/Utility/FileSpec.cpp
lldb/trunk/unittests/Utility/FileSpecTest.cpp

Modified: lldb/trunk/source/Utility/FileSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/FileSpec.cpp?rev=332088&r1=332087&r2=332088&view=diff
==
--- lldb/trunk/source/Utility/FileSpec.cpp (original)
+++ lldb/trunk/source/Utility/FileSpec.cpp Fri May 11 04:55:34 2018
@@ -82,67 +82,6 @@ void Denormalize(llvm::SmallVectorImpl 0 && IsPathSeparator(str.back(), syntax))
-return str.size() - 1;
-
-  size_t pos = str.find_last_of(GetPathSeparators(syntax), str.size() - 1);
-
-  if (!PathSyntaxIsPosix(syntax) && pos == llvm::StringRef::npos)
-pos = str.find_last_of(':', str.size() - 2);
-
-  if (pos == llvm::StringRef::npos ||
-  (pos == 1 && IsPathSeparator(str[0], syntax)))
-return 0;
-
-  return pos + 1;
-}
-
-size_t RootDirStart(llvm::StringRef str, FileSpec::PathSyntax syntax) {
-  // case "c:/"
-  if (!PathSyntaxIsPosix(syntax) &&
-  (str.size() > 2 && str[1] == ':' && IsPathSeparator(str[2], syntax)))
-return 2;
-
-  // case "//"
-  if (str.size() == 2 && IsPathSeparator(str[0], syntax) && str[0] == str[1])
-return llvm::StringRef::npos;
-
-  // case "//net"
-  if (str.size() > 3 && IsPathSeparator(str[0], syntax) && str[0] == str[1] &&
-  !IsPathSeparator(str[2], syntax))
-return str.find_first_of(GetPathSeparators(syntax), 2);
-
-  // case "/"
-  if (str.size() > 0 && IsPathSeparator(str[0], syntax))
-return 0;
-
-  return llvm::StringRef::npos;
-}
-
-size_t ParentPathEnd(llvm::StringRef path, FileSpec::PathSyntax syntax) {
-  size_t end_pos = FilenamePos(path, syntax);
-
-  bool filename_was_sep =
-  path.size() > 0 && IsPathSeparator(path[end_pos], syntax);
-
-  // Skip separators except for root dir.
-  size_t root_dir_pos = RootDirStart(path.substr(0, end_pos), syntax);
-
-  while (end_pos > 0 && (end_pos - 1) != root_dir_pos &&
- IsPathSeparator(path[end_pos - 1], syntax))
---end_pos;
-
-  if (end_pos == 1 && root_dir_pos == 0 && filename_was_sep)
-return llvm::StringRef::npos;
-
-  return end_pos;
-}
-
 } // end anonymous namespace
 
 void FileSpec::Resolve(llvm::SmallVectorImpl &path) {
@@ -312,10 +251,6 @@ const FileSpec &FileSpec::operator=(cons
 //--
 void FileSpec::SetFile(llvm::StringRef pathname, bool resolve,
PathSyntax syntax) {
-  // CLEANUP: Use StringRef for string handling.  This function is kind of a
-  // mess and the unclear semantics of RootDirStart and ParentPathEnd make it
-  // very difficult to understand this function.  There's no reason this
-  // function should be particularly complicated or difficult to understand.
   m_filename.Clear();
   m_directory.Clear();
   m_is_resolved = false;
@@ -339,26 +274,11 @@ void FileSpec::SetFile(llvm::StringRef p
   if (m_syntax == FileSpec::ePathSyntaxWindows)
 std::replace(resolved.begin(), resolved.end(), '\\', '/');
 
-  llvm::StringRef resolve_path_ref(resolved.c_str());
-  size_t dir_end = ParentPathEnd(resolve_path_ref, m_syntax);
-  if (dir_end == 0) {
-m_filename.SetString(resolve_path_ref);
-return;
-  }
-
-  m_directory.SetString(resolve_path_ref.substr(0, dir_end));
-
-  size_t filename_begin = dir_end;
-  size_t root_dir_start = RootDirStart(resolve_path_ref, m_syntax);
-  while (filename_begin != llvm::StringRef::npos &&
- filename_begin < resolve_path_ref.size() &&
- filename_begin != root_dir_start &&
- IsPathSeparator(resolve_path_ref[filename_begin], m_syntax))
-++filename_begin;
-  m_filename.SetString((filename_begin == llvm::StringRef::npos ||
-filename_begin >= resolve_path_ref.size())
-   ? "."
-   : resolve_path_ref.substr(filename_begin));
+  auto style = LLVMPathSyntax(syntax);
+  m_filename.SetString(llvm::sys::path::filename(resolved, style));
+  llvm::StringRef dir = llvm::sys::path::parent_path(resolved, style);
+  if (!dir.empty())
+m_directory.SetString(dir);
 }
 
 void FileSpec::SetFile(llvm::StringRef path, bool resolve,

Modified:

[Lldb-commits] [PATCH] D46687: Remove custom path manipulation functions from FileSpec

2018-05-11 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332088: Remove custom path manipulation functions from 
FileSpec (authored by labath, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D46687

Files:
  lldb/trunk/source/Utility/FileSpec.cpp
  lldb/trunk/unittests/Utility/FileSpecTest.cpp

Index: lldb/trunk/unittests/Utility/FileSpecTest.cpp
===
--- lldb/trunk/unittests/Utility/FileSpecTest.cpp
+++ lldb/trunk/unittests/Utility/FileSpecTest.cpp
@@ -195,8 +195,7 @@
   {"/foo//bar/./baz", "/foo/bar/baz"},
   {"/./foo", "/foo"},
   {"/", "/"},
-  // TODO: fix llvm::sys::path::remove_dots() to return "//" below.
-  //{"//", "//"},
+  {"//", "/"},
   {"//net", "//net"},
   {"/..", "/"},
   {"/.", "/"},
@@ -212,6 +211,7 @@
   {"../../foo", "../../foo"},
   };
   for (auto test : posix_tests) {
+SCOPED_TRACE(llvm::Twine("test.first = ") + test.first);
 EXPECT_EQ(test.second,
   FileSpec(test.first, false, FileSpec::ePathSyntaxPosix)
   .GetPath());
@@ -224,8 +224,8 @@
   {R"(c:\bar\.)", R"(c:\bar)"},
   {R"(c:\.\bar)", R"(c:\bar)"},
   {R"(\)", R"(\)"},
-  //  {R"(\\)", R"(\\)"},
-  //  {R"(\\net)", R"(\\net)"},
+  {R"(\\)", R"(\)"},
+  {R"(\\net)", R"(\\net)"},
   {R"(c:\..)", R"(c:\)"},
   {R"(c:\.)", R"(c:\)"},
   // TODO: fix llvm::sys::path::remove_dots() to return "\" below.
Index: lldb/trunk/source/Utility/FileSpec.cpp
===
--- lldb/trunk/source/Utility/FileSpec.cpp
+++ lldb/trunk/source/Utility/FileSpec.cpp
@@ -82,67 +82,6 @@
 
   std::replace(path.begin(), path.end(), '/', '\\');
 }
-
-size_t FilenamePos(llvm::StringRef str, FileSpec::PathSyntax syntax) {
-  if (str.size() == 2 && IsPathSeparator(str[0], syntax) && str[0] == str[1])
-return 0;
-
-  if (str.size() > 0 && IsPathSeparator(str.back(), syntax))
-return str.size() - 1;
-
-  size_t pos = str.find_last_of(GetPathSeparators(syntax), str.size() - 1);
-
-  if (!PathSyntaxIsPosix(syntax) && pos == llvm::StringRef::npos)
-pos = str.find_last_of(':', str.size() - 2);
-
-  if (pos == llvm::StringRef::npos ||
-  (pos == 1 && IsPathSeparator(str[0], syntax)))
-return 0;
-
-  return pos + 1;
-}
-
-size_t RootDirStart(llvm::StringRef str, FileSpec::PathSyntax syntax) {
-  // case "c:/"
-  if (!PathSyntaxIsPosix(syntax) &&
-  (str.size() > 2 && str[1] == ':' && IsPathSeparator(str[2], syntax)))
-return 2;
-
-  // case "//"
-  if (str.size() == 2 && IsPathSeparator(str[0], syntax) && str[0] == str[1])
-return llvm::StringRef::npos;
-
-  // case "//net"
-  if (str.size() > 3 && IsPathSeparator(str[0], syntax) && str[0] == str[1] &&
-  !IsPathSeparator(str[2], syntax))
-return str.find_first_of(GetPathSeparators(syntax), 2);
-
-  // case "/"
-  if (str.size() > 0 && IsPathSeparator(str[0], syntax))
-return 0;
-
-  return llvm::StringRef::npos;
-}
-
-size_t ParentPathEnd(llvm::StringRef path, FileSpec::PathSyntax syntax) {
-  size_t end_pos = FilenamePos(path, syntax);
-
-  bool filename_was_sep =
-  path.size() > 0 && IsPathSeparator(path[end_pos], syntax);
-
-  // Skip separators except for root dir.
-  size_t root_dir_pos = RootDirStart(path.substr(0, end_pos), syntax);
-
-  while (end_pos > 0 && (end_pos - 1) != root_dir_pos &&
- IsPathSeparator(path[end_pos - 1], syntax))
---end_pos;
-
-  if (end_pos == 1 && root_dir_pos == 0 && filename_was_sep)
-return llvm::StringRef::npos;
-
-  return end_pos;
-}
-
 } // end anonymous namespace
 
 void FileSpec::Resolve(llvm::SmallVectorImpl &path) {
@@ -312,10 +251,6 @@
 //--
 void FileSpec::SetFile(llvm::StringRef pathname, bool resolve,
PathSyntax syntax) {
-  // CLEANUP: Use StringRef for string handling.  This function is kind of a
-  // mess and the unclear semantics of RootDirStart and ParentPathEnd make it
-  // very difficult to understand this function.  There's no reason this
-  // function should be particularly complicated or difficult to understand.
   m_filename.Clear();
   m_directory.Clear();
   m_is_resolved = false;
@@ -339,26 +274,11 @@
   if (m_syntax == FileSpec::ePathSyntaxWindows)
 std::replace(resolved.begin(), resolved.end(), '\\', '/');
 
-  llvm::StringRef resolve_path_ref(resolved.c_str());
-  size_t dir_end = ParentPathEnd(resolve_path_ref, m_syntax);
-  if (dir_end == 0) {
-m_filename.SetString(resolve_path_ref);
-return;
-  }
-
-  m_directory.SetString(resolve_path_ref.substr(0, dir_end));
-
-  size_t filename_begin = dir_end;
-  size_t root_dir_start = RootDirStart(resolve_path_ref, m_syntax);
-  while (filename_begin != llvm::StringRef::npos &&
- filename_begin < resolve_pat

[Lldb-commits] [PATCH] D46753: FileSpec: Remove PathSyntax enum and use llvm version instead

2018-05-11 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: zturner, clayborg.

The llvm version of the enum has the same enumerators, with stlightly
different names, so this is mostly just a search&replace exercise. One
concrete benefit of this is that we can remove the function for
converting between the two enums.

To avoid typing llvm::sys::path::Style::windows everywhere I import the
enum into the FileSpec class, so it can be referenced as
FileSpec::Style::windows.


https://reviews.llvm.org/D46753

Files:
  include/lldb/Utility/FileSpec.h
  source/Plugins/Platform/Android/PlatformAndroid.cpp
  source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  source/Utility/FileSpec.cpp
  unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
  unittests/Target/ModuleCacheTest.cpp
  unittests/Utility/FileSpecTest.cpp

Index: unittests/Utility/FileSpecTest.cpp
===
--- unittests/Utility/FileSpecTest.cpp
+++ unittests/Utility/FileSpecTest.cpp
@@ -14,123 +14,122 @@
 using namespace lldb_private;
 
 TEST(FileSpecTest, FileAndDirectoryComponents) {
-  FileSpec fs_posix("/foo/bar", false, FileSpec::ePathSyntaxPosix);
+  FileSpec fs_posix("/foo/bar", false, FileSpec::Style::posix);
   EXPECT_STREQ("/foo/bar", fs_posix.GetCString());
   EXPECT_STREQ("/foo", fs_posix.GetDirectory().GetCString());
   EXPECT_STREQ("bar", fs_posix.GetFilename().GetCString());
 
-  FileSpec fs_windows("F:\\bar", false, FileSpec::ePathSyntaxWindows);
+  FileSpec fs_windows("F:\\bar", false, FileSpec::Style::windows);
   EXPECT_STREQ("F:\\bar", fs_windows.GetCString());
   // EXPECT_STREQ("F:\\", fs_windows.GetDirectory().GetCString()); // It returns
   // "F:/"
   EXPECT_STREQ("bar", fs_windows.GetFilename().GetCString());
 
-  FileSpec fs_posix_root("/", false, FileSpec::ePathSyntaxPosix);
+  FileSpec fs_posix_root("/", false, FileSpec::Style::posix);
   EXPECT_STREQ("/", fs_posix_root.GetCString());
   EXPECT_EQ(nullptr, fs_posix_root.GetDirectory().GetCString());
   EXPECT_STREQ("/", fs_posix_root.GetFilename().GetCString());
 
-  FileSpec fs_windows_drive("F:", false, FileSpec::ePathSyntaxWindows);
+  FileSpec fs_windows_drive("F:", false, FileSpec::Style::windows);
   EXPECT_STREQ("F:", fs_windows_drive.GetCString());
   EXPECT_EQ(nullptr, fs_windows_drive.GetDirectory().GetCString());
   EXPECT_STREQ("F:", fs_windows_drive.GetFilename().GetCString());
 
-  FileSpec fs_windows_root("F:\\", false, FileSpec::ePathSyntaxWindows);
+  FileSpec fs_windows_root("F:\\", false, FileSpec::Style::windows);
   EXPECT_STREQ("F:\\", fs_windows_root.GetCString());
   EXPECT_STREQ("F:", fs_windows_root.GetDirectory().GetCString());
   // EXPECT_STREQ("\\", fs_windows_root.GetFilename().GetCString()); // It
   // returns "/"
 
-  FileSpec fs_posix_long("/foo/bar/baz", false, FileSpec::ePathSyntaxPosix);
+  FileSpec fs_posix_long("/foo/bar/baz", false, FileSpec::Style::posix);
   EXPECT_STREQ("/foo/bar/baz", fs_posix_long.GetCString());
   EXPECT_STREQ("/foo/bar", fs_posix_long.GetDirectory().GetCString());
   EXPECT_STREQ("baz", fs_posix_long.GetFilename().GetCString());
 
-  FileSpec fs_windows_long("F:\\bar\\baz", false, FileSpec::ePathSyntaxWindows);
+  FileSpec fs_windows_long("F:\\bar\\baz", false, FileSpec::Style::windows);
   EXPECT_STREQ("F:\\bar\\baz", fs_windows_long.GetCString());
   // EXPECT_STREQ("F:\\bar", fs_windows_long.GetDirectory().GetCString()); // It
   // returns "F:/bar"
   EXPECT_STREQ("baz", fs_windows_long.GetFilename().GetCString());
 
-  FileSpec fs_posix_trailing_slash("/foo/bar/", false,
-   FileSpec::ePathSyntaxPosix);
+  FileSpec fs_posix_trailing_slash("/foo/bar/", false, FileSpec::Style::posix);
   EXPECT_STREQ("/foo/bar", fs_posix_trailing_slash.GetCString());
   EXPECT_STREQ("/foo", fs_posix_trailing_slash.GetDirectory().GetCString());
   EXPECT_STREQ("bar", fs_posix_trailing_slash.GetFilename().GetCString());
 
   FileSpec fs_windows_trailing_slash("F:\\bar\\", false,
- FileSpec::ePathSyntaxWindows);
+ FileSpec::Style::windows);
   EXPECT_STREQ("F:\\bar", fs_windows_trailing_slash.GetCString());
   EXPECT_STREQ("bar", fs_windows_trailing_slash.GetFilename().GetCString());
 }
 
 TEST(FileSpecTest, AppendPathComponent) {
-  FileSpec fs_posix("/foo", false, FileSpec::ePathSyntaxPosix);
+  FileSpec fs_posix("/foo", false, FileSpec::Style::posix);
   fs_posix.AppendPathComponent("bar");
   EXPECT_STREQ("/foo/bar", fs_posix.GetCString());
   EXPECT_STREQ("/foo", fs_posix.GetDirectory().GetCString());
   EXPECT_STREQ("bar", fs_posix.GetFilename().GetCString());
 
-  FileSpec fs_posix_2("/foo", false, FileSpec::ePathSyntaxPosix);
+  FileSpec fs_posix_2("/foo", false, FileSpec::Style::posix);
   fs_posix_2.AppendPathComponent("//bar/baz");
   EXPECT_STREQ("/foo/bar/baz", fs_posix_2.GetCString());
   EXPECT_STREQ("/foo/bar", fs_posix_2.GetDirectory().GetCString()

[Lldb-commits] [PATCH] D46733: Add a lock to PlatformPOSIX::DoLoadImage

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

Much better.


https://reviews.llvm.org/D46733



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


[Lldb-commits] [PATCH] D46753: FileSpec: Remove PathSyntax enum and use llvm version instead

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

Fine to use llvm's enum as long as we don't export the style through the SB API


https://reviews.llvm.org/D46753



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


[Lldb-commits] [PATCH] D46736: HostInfoMacOSX: Share the clang resource directory with Swift.

2018-05-11 Thread Frederic Riss via Phabricator via lldb-commits
friss accepted this revision.
friss added inline comments.
This revision is now accepted and ready to land.



Comment at: source/Host/macosx/HostInfoMacOSX.mm:288
+  // Fall back to the Clang resource directory inside the framework.
+  raw_path.resize(rev_it - r_end);
   raw_path.append("/Resources/Clang");

As both branches above also resize, I think it would be clearer if this resize 
was in a final else above rather than on its own. Otherwise this LGTM


https://reviews.llvm.org/D46736



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


[Lldb-commits] [lldb] r332111 - HostInfoMacOSX: Share the clang resource directory with Swift.

2018-05-11 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Fri May 11 10:54:09 2018
New Revision: 332111

URL: http://llvm.org/viewvc/llvm-project?rev=332111&view=rev
Log:
HostInfoMacOSX: Share the clang resource directory with Swift.

Inside Xcode and in Xcode toolchains LLDB is always in lockstep
with the Swift compiler, so it can reuse its Clang resource
directory. This allows LLDB and the Swift compiler to share the
same Clang module cache.

rdar://problem/40039633

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

Modified:
lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h
lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
lldb/trunk/unittests/Host/CMakeLists.txt
lldb/trunk/unittests/Host/HostInfoTest.cpp

Modified: lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h?rev=332111&r1=332110&r2=332111&view=diff
==
--- lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h (original)
+++ lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h Fri May 11 10:54:09 
2018
@@ -38,6 +38,8 @@ protected:
   static bool ComputeHeaderDirectory(FileSpec &file_spec);
   static bool ComputePythonDirectory(FileSpec &file_spec);
   static bool ComputeClangDirectory(FileSpec &file_spec);
+  static bool ComputeClangDirectory(FileSpec &lldb_shlib_spec,
+FileSpec &file_spec, bool verify);
   static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
   static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
 };

Modified: lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm?rev=332111&r1=332110&r2=332111&view=diff
==
--- lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm (original)
+++ lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm Fri May 11 10:54:09 2018
@@ -19,6 +19,7 @@
 
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
 // C++ Includes
@@ -226,21 +227,67 @@ bool HostInfoMacOSX::ComputePythonDirect
 #endif
 }
 
+static bool VerifyClangPath(const llvm::Twine &clang_path) {
+  if (llvm::sys::fs::is_directory(clang_path))
+return true;
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+  if (log)
+log->Printf("HostInfoMacOSX::ComputeClangDirectory(): "
+"failed to stat clang resource directory at \"%s\"",
+clang_path.str().c_str());
+  return false;
+}
+
 bool HostInfoMacOSX::ComputeClangDirectory(FileSpec &file_spec) {
   FileSpec lldb_file_spec;
   if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
 return false;
+  return ComputeClangDirectory(lldb_file_spec, file_spec, true);
+}
 
-  std::string raw_path = lldb_file_spec.GetPath();
+bool HostInfoMacOSX::ComputeClangDirectory(FileSpec &lldb_shlib_spec,
+   FileSpec &file_spec, bool verify) {
+  std::string raw_path = lldb_shlib_spec.GetPath();
 
-  size_t framework_pos = raw_path.find("LLDB.framework");
-  if (framework_pos == std::string::npos)
+  auto rev_it = llvm::sys::path::rbegin(raw_path);
+  auto r_end = llvm::sys::path::rend(raw_path);
+
+  // Check for a Posix-style build of LLDB.
+  if (rev_it == r_end || *rev_it != "LLDB.framework")
 return HostInfoPosix::ComputeClangDirectory(file_spec);
-  
-  framework_pos += strlen("LLDB.framework");
-  raw_path.resize(framework_pos);
+
+  // Inside Xcode and in Xcode toolchains LLDB is always in lockstep
+  // with the Swift compiler, so it can reuse its Clang resource
+  // directory. This allows LLDB and the Swift compiler to share the
+  // same Clang module cache.
+  llvm::SmallString<256> clang_path;
+  const char *swift_clang_resource_dir = "usr/lib/swift/clang";
+  ++rev_it;
+  if (rev_it != r_end && *rev_it == "SharedFrameworks") {
+// This is the top-level LLDB in the Xcode.app bundle.
+raw_path.resize(rev_it - r_end);
+llvm::sys::path::append(clang_path, raw_path,
+"Developer/Toolchains/XcodeDefault.xctoolchain",
+swift_clang_resource_dir);
+if (!verify || VerifyClangPath(clang_path)) {
+  file_spec.SetFile(clang_path.c_str(), true);
+  return true;
+}
+  } else if (rev_it != r_end && *rev_it == "PrivateFrameworks" &&
+ ++rev_it != r_end && ++rev_it != r_end) {
+// This is LLDB inside an Xcode toolchain.
+raw_path.resize(rev_it - r_end);
+llvm::sys::path::append(clang_path, raw_path, swift_clang_resource_dir);
+if (!verify || VerifyClangPath(clang_path)) {
+  file_spec.SetFile(clang_path.c_str(), true);
+  return true;
+}
+  } else {
+raw_path.resize(rev_it - r_end);
+  }
+
+  // Fall back to the Clang resource directory

[Lldb-commits] [PATCH] D46736: HostInfoMacOSX: Share the clang resource directory with Swift.

2018-05-11 Thread Phabricator via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332111: HostInfoMacOSX: Share the clang resource directory 
with Swift. (authored by adrian, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46736?vs=146259&id=146363#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46736

Files:
  lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h
  lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
  lldb/trunk/unittests/Host/CMakeLists.txt
  lldb/trunk/unittests/Host/HostInfoTest.cpp

Index: lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h
===
--- lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h
+++ lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h
@@ -38,6 +38,8 @@
   static bool ComputeHeaderDirectory(FileSpec &file_spec);
   static bool ComputePythonDirectory(FileSpec &file_spec);
   static bool ComputeClangDirectory(FileSpec &file_spec);
+  static bool ComputeClangDirectory(FileSpec &lldb_shlib_spec,
+FileSpec &file_spec, bool verify);
   static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
   static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
 };
Index: lldb/trunk/unittests/Host/HostInfoTest.cpp
===
--- lldb/trunk/unittests/Host/HostInfoTest.cpp
+++ lldb/trunk/unittests/Host/HostInfoTest.cpp
@@ -8,7 +8,9 @@
 //===--===//
 
 #include "lldb/Host/HostInfo.h"
+#include "lldb/Host/macosx/HostInfoMacOSX.h"
 #include "lldb/lldb-defines.h"
+#include "TestingSupport/TestUtilities.h"
 #include "gtest/gtest.h"
 
 using namespace lldb_private;
@@ -43,3 +45,41 @@
   EXPECT_EQ(HostInfo::GetAugmentedArchSpec(LLDB_ARCH_DEFAULT).GetTriple(),
 HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple());
 }
+
+
+struct HostInfoMacOSXTest : public HostInfoMacOSX {
+  static std::string ComputeClangDir(std::string lldb_shlib_path,
+ bool verify = false) {
+FileSpec clang_dir;
+FileSpec lldb_shlib_spec(lldb_shlib_path, false);
+ComputeClangDirectory(lldb_shlib_spec, clang_dir, verify);
+return clang_dir.GetPath();
+  }
+};
+
+
+TEST_F(HostInfoTest, MacOSX) {
+  // This returns whatever the POSIX fallback returns.
+  std::string posix = "/usr/lib/liblldb.dylib";
+  EXPECT_FALSE(HostInfoMacOSXTest::ComputeClangDir(posix).empty());
+
+  std::string xcode =
+"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework";
+  std::string xcode_clang =
+"/Applications/Xcode.app/Contents/Developer/Toolchains/"
+"XcodeDefault.xctoolchain/usr/lib/swift/clang";
+  EXPECT_EQ(HostInfoMacOSXTest::ComputeClangDir(xcode), xcode_clang);
+
+  std::string toolchain =
+  "/Applications/Xcode.app/Contents/Developer/Toolchains/"
+  "Swift-4.1-development-snapshot.xctoolchain/System/Library/"
+  "PrivateFrameworks/LLDB.framework";
+  std::string toolchain_clang =
+  "/Applications/Xcode.app/Contents/Developer/Toolchains/"
+  "Swift-4.1-development-snapshot.xctoolchain/usr/lib/swift/clang";
+  EXPECT_EQ(HostInfoMacOSXTest::ComputeClangDir(toolchain), toolchain_clang);
+
+  // Test that a bogus path is detected.
+  EXPECT_NE(HostInfoMacOSXTest::ComputeClangDir(GetInputFilePath(xcode), true),
+HostInfoMacOSXTest::ComputeClangDir(GetInputFilePath(xcode)));
+}
Index: lldb/trunk/unittests/Host/CMakeLists.txt
===
--- lldb/trunk/unittests/Host/CMakeLists.txt
+++ lldb/trunk/unittests/Host/CMakeLists.txt
@@ -22,4 +22,5 @@
   LINK_LIBS
 lldbCore
 lldbHost
+lldbUtilityHelpers
   )
Index: lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
===
--- lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
+++ lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
@@ -19,6 +19,7 @@
 
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
 // C++ Includes
@@ -226,21 +227,67 @@
 #endif
 }
 
+static bool VerifyClangPath(const llvm::Twine &clang_path) {
+  if (llvm::sys::fs::is_directory(clang_path))
+return true;
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+  if (log)
+log->Printf("HostInfoMacOSX::ComputeClangDirectory(): "
+"failed to stat clang resource directory at \"%s\"",
+clang_path.str().c_str());
+  return false;
+}
+
 bool HostInfoMacOSX::ComputeClangDirectory(FileSpec &file_spec) {
   FileSpec lldb_file_spec;
   if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
 return false;
+  return ComputeClangDirectory(lldb_file_spec, file_spec, true);
+}
 
-  std::string raw_path = lldb_file_spec.GetPath(

[Lldb-commits] [lldb] r332115 - Add a lock to PlatformPOSIX::DoLoadImage

2018-05-11 Thread Frederic Riss via lldb-commits
Author: friss
Date: Fri May 11 11:21:11 2018
New Revision: 332115

URL: http://llvm.org/viewvc/llvm-project?rev=332115&view=rev
Log:
Add a lock to PlatformPOSIX::DoLoadImage

Summary:
Multiple threads could be calling into DoLoadImage concurrently,
only one should be allowed to create the UtilityFunction.

Reviewers: jingham

Subscribers: emaste, lldb-commits

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

Modified:
lldb/trunk/include/lldb/Target/Process.h
lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=332115&r1=332114&r2=332115&view=diff
==
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Fri May 11 11:21:11 2018
@@ -804,7 +804,7 @@ public:
   }
 
   //--
-  // FUTURE WORK: {Set,Get}LoadImageUtilityFunction are the first use we've
+  // FUTURE WORK: GetLoadImageUtilityFunction are the first use we've
   // had of having other plugins cache data in the Process.  This is handy for
   // long-living plugins - like the Platform - which manage interactions whose
   // lifetime is governed by the Process lifetime.  If we find we need to do
@@ -820,34 +820,23 @@ public:
   // We are postponing designing this till we have at least a second use case.
   //--
   //--
-  /// Set the cached UtilityFunction that assists in loading binary images
-  /// into the process.
-  ///
-  /// This UtilityFunction is maintained in the Process since the Platforms
-  /// don't track the lifespan of the Targets/Processes that use them.   But
-  /// it is not intended to be comprehended by the Process, it's up to the
-  /// Platform that set it to do it right.
-  ///
-  /// @param[in] utility_func_up
-  /// The incoming utility_function.  The process will manage the 
function's
-  /// lifetime.
-  ///
-  //--
-  void SetLoadImageUtilityFunction(std::unique_ptr 
-   utility_func_up);
-  
-  //--
   /// Get the cached UtilityFunction that assists in loading binary images
   /// into the process.
   ///
   /// @param[in] platform
   /// The platform fetching the UtilityFunction.
-  /// 
+  /// @param[in] factory
+  /// A function that will be called only once per-process in a
+  /// thread-safe way to create the UtilityFunction if it has not
+  /// been initialized yet.
+  ///
   /// @return
   /// The cached utility function or null if the platform is not the
   /// same as the target's platform.
   //--
-  UtilityFunction *GetLoadImageUtilityFunction(Platform *platform);
+  UtilityFunction *GetLoadImageUtilityFunction(
+  Platform *platform,
+  llvm::function_ref()> factory);
 
   //--
   /// Get the dynamic loader plug-in for this process.
@@ -3127,6 +3116,7 @@ protected:
   enum { eCanJITDontKnow = 0, eCanJITYes, eCanJITNo } m_can_jit;
   
   std::unique_ptr m_dlopen_utility_func_up;
+  std::once_flag m_dlopen_utility_func_flag_once;
 
   size_t RemoveBreakpointOpcodesFromBuffer(lldb::addr_t addr, size_t size,
uint8_t *buf) const;

Modified: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=332115&r1=332114&r2=332115&view=diff
==
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Fri May 11 
11:21:11 2018
@@ -929,10 +929,9 @@ Status PlatformPOSIX::EvaluateLibdlExpre
   return Status();
 }
 
-UtilityFunction *
-PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx, 
-Status &error)
-{
+std::unique_ptr
+PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx,
+Status &error) {
   // Remember to prepend this with the prefix from
   // GetLibdlFunctionDeclarations. The returned values are all in
   // __lldb_dlopen_result for consistency. The wrapper returns a void * but
@@ -982,7 +981,6 @@ PlatformPOSIX::MakeLoadImageUtilityFunct
   Value value;
   ValueList arguments;
   FunctionCaller *do_dlopen_functio

[Lldb-commits] [PATCH] D46733: Add a lock to PlatformPOSIX::DoLoadImage

2018-05-11 Thread Frederic Riss via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332115: Add a lock to PlatformPOSIX::DoLoadImage (authored 
by friss, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46733?vs=146268&id=146368#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46733

Files:
  lldb/trunk/include/lldb/Target/Process.h
  lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
  lldb/trunk/source/Target/Process.cpp

Index: lldb/trunk/source/Target/Process.cpp
===
--- lldb/trunk/source/Target/Process.cpp
+++ lldb/trunk/source/Target/Process.cpp
@@ -6164,14 +6164,12 @@
   return Status();
 }
 
-UtilityFunction *Process::GetLoadImageUtilityFunction(Platform *platform) {
+UtilityFunction *Process::GetLoadImageUtilityFunction(
+Platform *platform,
+llvm::function_ref()> factory) {
   if (platform != GetTarget().GetPlatform().get())
 return nullptr;
+  std::call_once(m_dlopen_utility_func_flag_once,
+ [&] { m_dlopen_utility_func_up = factory(); });
   return m_dlopen_utility_func_up.get();
 }
-
-void Process::SetLoadImageUtilityFunction(std::unique_ptr 
-  utility_func_up) {
-  m_dlopen_utility_func_up.swap(utility_func_up);
-}
-
Index: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -929,10 +929,9 @@
   return Status();
 }
 
-UtilityFunction *
-PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx, 
-Status &error)
-{
+std::unique_ptr
+PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx,
+Status &error) {
   // Remember to prepend this with the prefix from
   // GetLibdlFunctionDeclarations. The returned values are all in
   // __lldb_dlopen_result for consistency. The wrapper returns a void * but
@@ -982,7 +981,6 @@
   Value value;
   ValueList arguments;
   FunctionCaller *do_dlopen_function = nullptr;
-  UtilityFunction *dlopen_utility_func = nullptr;
 
   // Fetch the clang types we will need:
   ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext();
@@ -1015,9 +1013,7 @@
   }
   
   // We made a good utility function, so cache it in the process:
-  dlopen_utility_func = dlopen_utility_func_up.get();
-  process->SetLoadImageUtilityFunction(std::move(dlopen_utility_func_up));
-  return dlopen_utility_func;
+  return dlopen_utility_func_up;
 }
 
 uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process,
@@ -1038,18 +1034,16 @@
   thread_sp->CalculateExecutionContext(exe_ctx);
 
   Status utility_error;
-  
-  // The UtilityFunction is held in the Process.  Platforms don't track the
-  // lifespan of the Targets that use them, we can't put this in the Platform.
-  UtilityFunction *dlopen_utility_func 
-  = process->GetLoadImageUtilityFunction(this);
+  UtilityFunction *dlopen_utility_func;
   ValueList arguments;
   FunctionCaller *do_dlopen_function = nullptr;
-  
-  if (!dlopen_utility_func) {
-// Make the UtilityFunction:
-dlopen_utility_func = MakeLoadImageUtilityFunction(exe_ctx, error);
-  }
+
+  // The UtilityFunction is held in the Process.  Platforms don't track the
+  // lifespan of the Targets that use them, we can't put this in the Platform.
+  dlopen_utility_func = process->GetLoadImageUtilityFunction(
+  this, [&]() -> std::unique_ptr {
+return MakeLoadImageUtilityFunction(exe_ctx, error);
+  });
   // If we couldn't make it, the error will be in error, so we can exit here.
   if (!dlopen_utility_func)
 return LLDB_INVALID_IMAGE_TOKEN;
Index: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
===
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
@@ -199,10 +199,10 @@
   EvaluateLibdlExpression(lldb_private::Process *process, const char *expr_cstr,
   llvm::StringRef expr_prefix,
   lldb::ValueObjectSP &result_valobj_sp);
-  
-  lldb_private::UtilityFunction *
-  MakeLoadImageUtilityFunction(lldb_private::ExecutionContext &exe_ctx, 
-   lldb_private::Status &error); 
+
+  std::unique_ptr
+  MakeLoadImageUtilityFunction(lldb_private::ExecutionContext &exe_ctx,
+   lldb_private::Status &error);
 
   virtual
   llvm::StringRef GetLibdlFunctionDeclarations(lldb_private::Process *process);
Index: lldb/trunk/include/lldb/Target/Process.h
=

[Lldb-commits] [PATCH] D46726: build: use cmake to find the libedit content

2018-05-11 Thread Saleem Abdulrasool via Phabricator via lldb-commits
compnerd added inline comments.



Comment at: cmake/modules/FindLibEdit.cmake:11-14
+#   libedit_FOUND - true if libedit was found
+#   libedit_INCLUDE_DIRS  - include search path
+#   libedit_LIBRARIES - libraries to link
+#   libedit_VERSION   - version number

labath wrote:
> Should we make the capitalization of these match the file name 
> (LibEdit_FOUND) ?
*shrug* I'm not tied to that.  I found `LibEdit_FOUND` to be a bit jarring, 
which is why I went with `libedit_FOUND` which also mirror's the project's 
actual spelling (`libedit`).



Comment at: cmake/modules/FindLibEdit.cmake:53-54
+set(libedit_VERSION_STRING 
"${libedit_major_version}.${libedit_minor_version}")
+unset(libedit_major_version)
+unset(libedit_minor_version)
+  endif()

labath wrote:
> Do you really need to unset these? I would hope that this file is evaluated 
> in a fresh context, and it won't pollute the callers namespace or anything..
I'm pretty sure that they get evaluated in the global context :-(.


https://reviews.llvm.org/D46726



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


[Lldb-commits] [lldb] r332120 - Fix a regression in r332111. The LLDB.framework path component is not

2018-05-11 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Fri May 11 12:00:58 2018
New Revision: 332120

URL: http://llvm.org/viewvc/llvm-project?rev=332120&view=rev
Log:
Fix a regression in r332111. The LLDB.framework path component is not
usually the last component.

Modified:
lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
lldb/trunk/unittests/Host/HostInfoTest.cpp

Modified: lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm?rev=332120&r1=332119&r2=332120&view=diff
==
--- lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm (original)
+++ lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm Fri May 11 12:00:58 2018
@@ -253,7 +253,13 @@ bool HostInfoMacOSX::ComputeClangDirecto
   auto r_end = llvm::sys::path::rend(raw_path);
 
   // Check for a Posix-style build of LLDB.
-  if (rev_it == r_end || *rev_it != "LLDB.framework")
+  while (rev_it != r_end) {
+if (*rev_it == "LLDB.framework")
+  break;
+++rev_it;
+  }
+
+  if (rev_it == r_end)
 return HostInfoPosix::ComputeClangDirectory(file_spec);
 
   // Inside Xcode and in Xcode toolchains LLDB is always in lockstep

Modified: lldb/trunk/unittests/Host/HostInfoTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/HostInfoTest.cpp?rev=332120&r1=332119&r2=332120&view=diff
==
--- lldb/trunk/unittests/Host/HostInfoTest.cpp (original)
+++ lldb/trunk/unittests/Host/HostInfoTest.cpp Fri May 11 12:00:58 2018
@@ -63,8 +63,14 @@ TEST_F(HostInfoTest, MacOSX) {
   std::string posix = "/usr/lib/liblldb.dylib";
   EXPECT_FALSE(HostInfoMacOSXTest::ComputeClangDir(posix).empty());
 
+  std::string framework =
+"/SharedFrameworks/LLDB.framework";
+  std::string framework_clang =
+"/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang";
+  EXPECT_EQ(HostInfoMacOSXTest::ComputeClangDir(framework), framework_clang);
+
   std::string xcode =
-"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework";
+
"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A";
   std::string xcode_clang =
 "/Applications/Xcode.app/Contents/Developer/Toolchains/"
 "XcodeDefault.xctoolchain/usr/lib/swift/clang";


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


[Lldb-commits] [lldb] r332126 - Yet another follow-up to r332111. This also handles the case where an

2018-05-11 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Fri May 11 12:29:25 2018
New Revision: 332126

URL: http://llvm.org/viewvc/llvm-project?rev=332126&view=rev
Log:
Yet another follow-up to r332111. This also handles the case where an
LLDB.framework is built inside the LLDB build directory (but not
inside an Xcode installation).

Modified:
lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
lldb/trunk/unittests/Host/HostInfoTest.cpp

Modified: lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm?rev=332126&r1=332125&r2=332126&view=diff
==
--- lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm (original)
+++ lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm Fri May 11 12:29:25 2018
@@ -268,10 +268,11 @@ bool HostInfoMacOSX::ComputeClangDirecto
   // same Clang module cache.
   llvm::SmallString<256> clang_path;
   const char *swift_clang_resource_dir = "usr/lib/swift/clang";
-  ++rev_it;
-  if (rev_it != r_end && *rev_it == "SharedFrameworks") {
+  auto parent = std::next(rev_it);
+  if (parent != r_end && *parent == "SharedFrameworks") {
 // This is the top-level LLDB in the Xcode.app bundle.
-raw_path.resize(rev_it - r_end);
+// e.g., "Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A"
+raw_path.resize(parent - r_end);
 llvm::sys::path::append(clang_path, raw_path,
 "Developer/Toolchains/XcodeDefault.xctoolchain",
 swift_clang_resource_dir);
@@ -279,10 +280,14 @@ bool HostInfoMacOSX::ComputeClangDirecto
   file_spec.SetFile(clang_path.c_str(), true);
   return true;
 }
-  } else if (rev_it != r_end && *rev_it == "PrivateFrameworks" &&
- ++rev_it != r_end && ++rev_it != r_end) {
+  } else if (parent != r_end && *parent == "PrivateFrameworks" &&
+ std::distance(parent, r_end) > 2) {
 // This is LLDB inside an Xcode toolchain.
-raw_path.resize(rev_it - r_end);
+// e.g., "Xcode.app/Contents/Developer/Toolchains/" \
+//   "My.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework"
+++parent;
+++parent;
+raw_path.resize(parent - r_end);
 llvm::sys::path::append(clang_path, raw_path, swift_clang_resource_dir);
 if (!verify || VerifyClangPath(clang_path)) {
   file_spec.SetFile(clang_path.c_str(), true);
@@ -293,7 +298,7 @@ bool HostInfoMacOSX::ComputeClangDirecto
   }
 
   // Fall back to the Clang resource directory inside the framework.
-  raw_path.append("/Resources/Clang");
+  raw_path.append("LLDB.framework/Resources/Clang");
   file_spec.SetFile(raw_path.c_str(), true);
   return true;
 }

Modified: lldb/trunk/unittests/Host/HostInfoTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/HostInfoTest.cpp?rev=332126&r1=332125&r2=332126&view=diff
==
--- lldb/trunk/unittests/Host/HostInfoTest.cpp (original)
+++ lldb/trunk/unittests/Host/HostInfoTest.cpp Fri May 11 12:29:25 2018
@@ -63,11 +63,11 @@ TEST_F(HostInfoTest, MacOSX) {
   std::string posix = "/usr/lib/liblldb.dylib";
   EXPECT_FALSE(HostInfoMacOSXTest::ComputeClangDir(posix).empty());
 
-  std::string framework =
-"/SharedFrameworks/LLDB.framework";
-  std::string framework_clang =
-"/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang";
-  EXPECT_EQ(HostInfoMacOSXTest::ComputeClangDir(framework), framework_clang);
+  std::string build =
+"/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Versions/A";
+  std::string build_clang =
+"/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Resources/Clang";
+  EXPECT_EQ(HostInfoMacOSXTest::ComputeClangDir(build), build_clang);
 
   std::string xcode =
 
"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A";


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


[Lldb-commits] [PATCH] D32167: Add support for type units (.debug_types) to LLDB in a way that is compatible with DWARF 5

2018-05-11 Thread Paul Robinson via Phabricator via lldb-commits
probinson added a comment.

I haven't given Pavel's comments as much thought as they deserve, but here are 
some of mine.

It's a worthwhile point that a class ought to represent some useful and 
reasonably well defined abstraction.  DataExtractor has one, and 
DWARFDataExtractor builds on that (at least in the LLVM parser) by handling 
relocations; the most reasonable way to handle multiple buffers would be with 
multiple extractors, building on top of what's there rather than hacking the 
insides.

One aspect I am looking at is that the LLVM parser needs to handle .o files, 
which can have multiple .debug_types (in v4) or .debug_info (in v5) sections, 
because the units are broken up into COMDATs.  So, the dumper needs to be able 
to handle an arbitrary number of either kind of section, where LLDB needs at 
most one of each section.  One way of dealing with all this is to have a vector 
or deque of sections, each section has its DWARFDataExtractor and knows its own 
"base offset" which would be the sum of the sizes of the preceding sections.  I 
don't know how awkward it might be to turn this into a meta-extractor that hid 
details from consumers, but then I think it probably would not be all that hard 
to have consumers be aware that there can be multiple lumps of DWARF and get 
the offsets right on their own.


https://reviews.llvm.org/D32167



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


[Lldb-commits] [PATCH] D32167: Add support for type units (.debug_types) to LLDB in a way that is compatible with DWARF 5

2018-05-11 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

After reading Pavel's and Paul's comments, I will come up with a solution that 
allows multiple sections to be combined into one large section. That way it 
will be all legal and easy to extend. If we have just .debug_info, then we can 
use a base class that just calls directly through to DWARFDataExtractor. If we 
have more that one section that need to act as one section, I will make a new 
class that can put N sections together. I'll post a patch on its own that 
implements this with tests and we can iterate on that and make it work for all 
of our needs, then switch this patch over to use it. Sound good?


https://reviews.llvm.org/D32167



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


[Lldb-commits] [lldb] r332140 - Conditionally compile a Darwin-only test.

2018-05-11 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Fri May 11 14:05:32 2018
New Revision: 332140

URL: http://llvm.org/viewvc/llvm-project?rev=332140&view=rev
Log:
Conditionally compile a Darwin-only test.

Modified:
lldb/trunk/unittests/Host/HostInfoTest.cpp

Modified: lldb/trunk/unittests/Host/HostInfoTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/HostInfoTest.cpp?rev=332140&r1=332139&r2=332140&view=diff
==
--- lldb/trunk/unittests/Host/HostInfoTest.cpp (original)
+++ lldb/trunk/unittests/Host/HostInfoTest.cpp Fri May 11 14:05:32 2018
@@ -58,6 +58,7 @@ struct HostInfoMacOSXTest : public HostI
 };
 
 
+#ifdef __APPLE__
 TEST_F(HostInfoTest, MacOSX) {
   // This returns whatever the POSIX fallback returns.
   std::string posix = "/usr/lib/liblldb.dylib";
@@ -89,3 +90,4 @@ TEST_F(HostInfoTest, MacOSX) {
   EXPECT_NE(HostInfoMacOSXTest::ComputeClangDir(GetInputFilePath(xcode), true),
 HostInfoMacOSXTest::ComputeClangDir(GetInputFilePath(xcode)));
 }
+#endif


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


[Lldb-commits] [PATCH] D32167: Add support for type units (.debug_types) to LLDB in a way that is compatible with DWARF 5

2018-05-11 Thread Paul Robinson via Phabricator via lldb-commits
probinson added a comment.

Go for it.  It sounds like an abstraction that hides the multiple-section 
nature of the beast will particularly help LLDB; on the LLVM side the dumper 
will want to remain a bit more cognizant of the underlying sections.  But we 
can surely leverage ideas from each other, which will ultimately help with 
converging on the Grand Unified Parser.


https://reviews.llvm.org/D32167



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


[Lldb-commits] [PATCH] D46783: FileSpec objects that resolve to "." should have "." in m_filename and m_directory empty.

2018-05-11 Thread Greg Clayton via Phabricator via lldb-commits
clayborg created this revision.
clayborg added reviewers: labath, jingham, davide, zturner.

After switching to LLVM normalization, if we init FileSpec with "." we would 
end up with m_directory being NULL and m_filename being "".

This patch fixes this by allowing the path to be normalized and if it 
normalized to nothing, set it to m_filename.


https://reviews.llvm.org/D46783

Files:
  source/Utility/FileSpec.cpp
  unittests/Utility/FileSpecTest.cpp


Index: unittests/Utility/FileSpecTest.cpp
===
--- unittests/Utility/FileSpecTest.cpp
+++ unittests/Utility/FileSpecTest.cpp
@@ -201,9 +201,9 @@
   {"/..", "/"},
   {"/.", "/"},
   {"..", ".."},
-  {".", ""},
+  {".", "."},
   {"../..", "../.."},
-  {"foo/..", ""},
+  {"foo/..", "."},
   {"foo/../bar", "bar"},
   {"../foo/..", ".."},
   {"./foo", "foo"},
@@ -232,11 +232,11 @@
   {R"(\..)", R"(\..)"},
   //  {R"(c:..)", R"(c:..)"},
   {R"(..)", R"(..)"},
-  {R"(.)", R"()"},
+  {R"(.)", R"(.)"},
   // TODO: fix llvm::sys::path::remove_dots() to return "c:\" below.
   {R"(c:..\..)", R"(c:\..\..)"},
   {R"(..\..)", R"(..\..)"},
-  {R"(foo\..)", R"()"},
+  {R"(foo\..)", R"(.)"},
   {R"(foo\..\bar)", R"(bar)"},
   {R"(..\foo\..)", R"(..)"},
   {R"(.\foo)", R"(foo)"},
Index: source/Utility/FileSpec.cpp
===
--- source/Utility/FileSpec.cpp
+++ source/Utility/FileSpec.cpp
@@ -340,6 +340,13 @@
 std::replace(resolved.begin(), resolved.end(), '\\', '/');
 
   llvm::StringRef resolve_path_ref(resolved.c_str());
+  if (!pathname.empty() && resolve_path_ref.empty()) {
+// We have a non empty specified that resulted in an empty normalized path
+// so this resolved to the current working directory. Don't let m_directory
+// or m_filename be empty.
+m_filename.SetString(".");
+return;
+  }
   size_t dir_end = ParentPathEnd(resolve_path_ref, m_syntax);
   if (dir_end == 0) {
 m_filename.SetString(resolve_path_ref);


Index: unittests/Utility/FileSpecTest.cpp
===
--- unittests/Utility/FileSpecTest.cpp
+++ unittests/Utility/FileSpecTest.cpp
@@ -201,9 +201,9 @@
   {"/..", "/"},
   {"/.", "/"},
   {"..", ".."},
-  {".", ""},
+  {".", "."},
   {"../..", "../.."},
-  {"foo/..", ""},
+  {"foo/..", "."},
   {"foo/../bar", "bar"},
   {"../foo/..", ".."},
   {"./foo", "foo"},
@@ -232,11 +232,11 @@
   {R"(\..)", R"(\..)"},
   //  {R"(c:..)", R"(c:..)"},
   {R"(..)", R"(..)"},
-  {R"(.)", R"()"},
+  {R"(.)", R"(.)"},
   // TODO: fix llvm::sys::path::remove_dots() to return "c:\" below.
   {R"(c:..\..)", R"(c:\..\..)"},
   {R"(..\..)", R"(..\..)"},
-  {R"(foo\..)", R"()"},
+  {R"(foo\..)", R"(.)"},
   {R"(foo\..\bar)", R"(bar)"},
   {R"(..\foo\..)", R"(..)"},
   {R"(.\foo)", R"(foo)"},
Index: source/Utility/FileSpec.cpp
===
--- source/Utility/FileSpec.cpp
+++ source/Utility/FileSpec.cpp
@@ -340,6 +340,13 @@
 std::replace(resolved.begin(), resolved.end(), '\\', '/');
 
   llvm::StringRef resolve_path_ref(resolved.c_str());
+  if (!pathname.empty() && resolve_path_ref.empty()) {
+// We have a non empty specified that resulted in an empty normalized path
+// so this resolved to the current working directory. Don't let m_directory
+// or m_filename be empty.
+m_filename.SetString(".");
+return;
+  }
   size_t dir_end = ParentPathEnd(resolve_path_ref, m_syntax);
   if (dir_end == 0) {
 m_filename.SetString(resolve_path_ref);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D46783: FileSpec objects that resolve to "." should have "." in m_filename and m_directory empty.

2018-05-11 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

This patch is needed for some PathMappingList fixes I have coming up.


https://reviews.llvm.org/D46783



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


[Lldb-commits] [lldb] r332162 - [LLDB] Support GNU-style compressed debug sections (.zdebug)

2018-05-11 Thread Davide Italiano via lldb-commits
Author: davide
Date: Fri May 11 17:29:25 2018
New Revision: 332162

URL: http://llvm.org/viewvc/llvm-project?rev=332162&view=rev
Log:
[LLDB] Support GNU-style compressed debug sections (.zdebug)

Patch by Erik Welander!

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

Added:
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/

lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile

lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c
Modified:
lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Added: 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile?rev=332162&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile 
(added)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile 
Fri May 11 17:29:25 2018
@@ -0,0 +1,16 @@
+LEVEL := ../../make
+
+C_SOURCES := a.c
+
+all: compressed.out compressed.gnu.out
+
+compressed.out: a.out
+   $(OBJCOPY) --compress-debug-sections=zlib $< $@
+
+compressed.gnu.out: a.out
+   $(OBJCOPY) --compress-debug-sections=zlib-gnu $< $@
+
+include $(LEVEL)/Makefile.rules
+
+clean::
+   $(RM) -f a.o main compressed.out compressed.gnu.out

Added: 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py?rev=332162&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
 (added)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
 Fri May 11 17:29:25 2018
@@ -0,0 +1,46 @@
+""" Tests that compressed debug info sections are used. """
+import os
+import lldb
+import sys
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCompressedDebugInfo(TestBase):
+  mydir = TestBase.compute_mydir(__file__)
+
+  def setUp(self):
+TestBase.setUp(self)
+
+  @no_debug_info_test  # Prevent the genaration of the dwarf version of this 
test
+  @skipUnlessPlatform(["linux"])
+  def test_compressed_debug_info(self):
+"""Tests that the 'frame variable' works with compressed debug info."""
+
+self.build()
+process = lldbutil.run_to_source_breakpoint(
+self, "main", lldb.SBFileSpec("a.c"), exe_name="compressed.out")[1]
+
+# The process should be stopped at a breakpoint, and the z variable should
+# be in the top frame.
+self.assertTrue(process.GetState() == lldb.eStateStopped,
+STOPPED_DUE_TO_BREAKPOINT)
+frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
+self.assertTrue(frame.FindVariable("z").IsValid(), "z is not valid")
+
+  @no_debug_info_test  # Prevent the genaration of the dwarf version of this 
test
+  @skipUnlessPlatform(["linux"])
+  def test_compressed_debug_info_gnu(self):
+"""Tests that the 'frame variable' works with gnu-style compressed debug 
info."""
+
+self.build()
+process = lldbutil.run_to_source_breakpoint(
+self, "main", lldb.SBFileSpec("a.c"), exe_name="compressed.gnu.out")[1]
+
+# The process should be stopped at a breakpoint, and the z variable should
+# be in the top frame.
+self.assertTrue(process.GetState() == lldb.eStateStopped,
+STOPPED_DUE_TO_BREAKPOINT)
+frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
+self.assertTrue(frame.FindVariable("z").IsValid(), "z is not valid")

Added: lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c?rev=332162&view=auto
==
--- lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c 
(added)
+++ lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c 
Fri May 11 17:29:25 2018
@@ -0,0 +1,4 @@
+int main() {
+  int z = 2;
+  return z;
+}

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=332162&r1=332161&r2=332162&view=diff
==
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/Obj

[Lldb-commits] [PATCH] D45628: [LLDB] Support GNU-style compressed debug sections (.zdebug)

2018-05-11 Thread Davide Italiano 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 rL332162: [LLDB] Support GNU-style compressed debug sections 
(.zdebug) (authored by davide, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45628?vs=145939&id=146448#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45628

Files:
  lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile
  
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
  lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c
  lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Index: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1757,6 +1757,63 @@
   return 0;
 }
 
+static SectionType getSectionType(llvm::StringRef section_name) {
+  if (!section_name.startswith(".")) {
+return eSectionTypeOther;
+  }
+
+  // MISSING? .gnu_debugdata - "mini debuginfo / MiniDebugInfo" section,
+  // http://sourceware.org/gdb/onlinedocs/gdb/MiniDebugInfo.html
+  // MISSING? .debug-index -
+  // http://src.chromium.org/viewvc/chrome/trunk/src/build/gdb-add-index?pathrev=144644
+  return llvm::StringSwitch(section_name.drop_front(1))
+  .Case("text", eSectionTypeCode)
+  .Case("data", eSectionTypeData)
+  .Case("bss", eSectionTypeZeroFill)
+  .Case("tdata", eSectionTypeData)
+  .Case("tbss", eSectionTypeZeroFill)
+  // Abbreviations used in the .debug_info section
+  .Case("debug_abbrev", eSectionTypeDWARFDebugAbbrev)
+  .Case("debug_abbrev.dwo", eSectionTypeDWARFDebugAbbrev)
+  .Case("debug_addr", eSectionTypeDWARFDebugAddr)
+  // Lookup table for mapping addresses to compilation units
+  .Case("debug_aranges", eSectionTypeDWARFDebugAranges)
+  .Case("debug_cu_index", eSectionTypeDWARFDebugCuIndex)
+  // Call frame information
+  .Case("debug_frame", eSectionTypeDWARFDebugFrame)
+  // The core DWARF information section
+  .Case("debug_info", eSectionTypeDWARFDebugInfo)
+  .Case("debug_info.dwo", eSectionTypeDWARFDebugInfo)
+  // Line number information
+  .Case("debug_line", eSectionTypeDWARFDebugLine)
+  .Case("debug_line.dwo", eSectionTypeDWARFDebugLine)
+  // Location lists used in DW_AT_location attributes
+  .Case("debug_loc", eSectionTypeDWARFDebugLoc)
+  .Case("debug_loc.dwo", eSectionTypeDWARFDebugLoc)
+  // Macro information
+  .Case("debug_macinfo", eSectionTypeDWARFDebugMacInfo)
+  .Case("debug_macro", eSectionTypeDWARFDebugMacro)
+  .Case("debug_macro.dwo", eSectionTypeDWARFDebugMacro)
+  // Lookup table for mapping object and function names to compilation units
+  .Case("debug_pubnames", eSectionTypeDWARFDebugPubNames)
+  // Lookup table for mapping type names to compilation units
+  .Case("debug_pubtypes", eSectionTypeDWARFDebugPubTypes)
+  // Address ranges used in DW_AT_ranges attributes
+  .Case("debug_ranges", eSectionTypeDWARFDebugRanges)
+  // String table used in .debug_info
+  .Case("debug_str", eSectionTypeDWARFDebugStr)
+  .Case("debug_str.dwo", eSectionTypeDWARFDebugStr)
+  .Case("debug_str_offsets", eSectionTypeDWARFDebugStrOffsets)
+  .Case("debug_str_offsets.dwo", eSectionTypeDWARFDebugStrOffsets)
+  .Case("debug_types", eSectionTypeDWARFDebugTypes)
+  .Case("gnu_debugaltlink", eSectionTypeDWARFGNUDebugAltLink)
+  .Case("eh_frame", eSectionTypeEHFrame)
+  .Case("ARM.exidx", eSectionTypeARMexidx)
+  .Case("ARM.extab", eSectionTypeARMextab)
+  .Case("gosymtab", eSectionTypeGoSymtab)
+  .Default(eSectionTypeOther);
+}
+
 void ObjectFileELF::CreateSections(SectionList &unified_section_list) {
   if (!m_sections_ap.get() && ParseSectionHeaders()) {
 m_sections_ap.reset(new SectionList());
@@ -1771,137 +1828,14 @@
  I != m_section_headers.end(); ++I) {
   const ELFSectionHeaderInfo &header = *I;
 
-  ConstString &name = I->section_name;
+  llvm::StringRef section_name = I->section_name.GetStringRef();
   const uint64_t file_size =
   header.sh_type == SHT_NOBITS ? 0 : header.sh_size;
   const uint64_t vm_size = header.sh_flags & SHF_ALLOC ? header.sh_size : 0;
 
-  static ConstString g_sect_name_text(".text");
-  static ConstString g_sect_name_data(".data");
-  static ConstString g_sect_name_bss(".bss");
-  static ConstString g_sect_name_tdata(".tdata");
-  static ConstString g_sect_name_tbss(".tbss");
-  static ConstString g_sect_name_dwarf_debug_abbrev(".debug_abbrev");
-  static ConstString g_sect_name_dwarf_debug_addr(".debug_addr");
-  static ConstString g_sect_name_dwarf_debug_

[Lldb-commits] [lldb] r332163 - [LanguageRuntime/ObjC] Turn off ISA logging once and for all.

2018-05-11 Thread Davide Italiano via lldb-commits
Author: davide
Date: Fri May 11 17:33:12 2018
New Revision: 332163

URL: http://llvm.org/viewvc/llvm-project?rev=332163&view=rev
Log:
[LanguageRuntime/ObjC] Turn off ISA logging once and for all.

On behalf of Jim, who's out today.

Modified:

lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

Modified: 
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=332163&r1=332162&r2=332163&view=diff
==
--- 
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 (original)
+++ 
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 Fri May 11 17:33:12 2018
@@ -1437,6 +1437,8 @@ uint32_t AppleObjCRuntimeV2::ParseClassI
   //} __attribute__((__packed__));
 
   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES));
+  bool should_log = log && log->GetVerbose();
+
   uint32_t num_parsed = 0;
 
   // Iterate through all ClassInfo structures
@@ -1445,7 +1447,7 @@ uint32_t AppleObjCRuntimeV2::ParseClassI
 ObjCISA isa = data.GetPointer(&offset);
 
 if (isa == 0) {
-  if (log && log->GetVerbose())
+  if (should_log)
 log->Printf(
 "AppleObjCRuntimeV2 found NULL isa, ignoring this class info");
   continue;
@@ -1453,7 +1455,7 @@ uint32_t AppleObjCRuntimeV2::ParseClassI
 // Check if we already know about this ISA, if we do, the info will never
 // change, so we can just skip it.
 if (ISAIsCached(isa)) {
-  if (log)
+  if (should_log)
 log->Printf("AppleObjCRuntimeV2 found cached isa=0x%" PRIx64
 ", ignoring this class info",
 isa);
@@ -1464,14 +1466,14 @@ uint32_t AppleObjCRuntimeV2::ParseClassI
   ClassDescriptorSP descriptor_sp(new ClassDescriptorV2(*this, isa, NULL));
   AddClass(isa, descriptor_sp, name_hash);
   num_parsed++;
-  if (log)
+  if (should_log)
 log->Printf("AppleObjCRuntimeV2 added isa=0x%" PRIx64
 ", hash=0x%8.8x, name=%s",
 isa, name_hash,
 descriptor_sp->GetClassName().AsCString(""));
 }
   }
-  if (log)
+  if (should_log)
 log->Printf("AppleObjCRuntimeV2 parsed %" PRIu32 " class infos",
 num_parsed);
   return num_parsed;


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


Re: [Lldb-commits] [lldb] r332162 - [LLDB] Support GNU-style compressed debug sections (.zdebug)

2018-05-11 Thread Davide Italiano via lldb-commits
On Fri, May 11, 2018 at 5:29 PM, Davide Italiano via lldb-commits
 wrote:
> Author: davide
> Date: Fri May 11 17:29:25 2018
> New Revision: 332162
>
> URL: http://llvm.org/viewvc/llvm-project?rev=332162&view=rev
> Log:
> [LLDB] Support GNU-style compressed debug sections (.zdebug)
>
> Patch by Erik Welander!
>

Erik, I'm going to revert this because it broke the ubuntu 14.04 bot.
Please take a look and I'll recommit it for you once it's fixed.

Log:
http://lab.llvm.org:8011/builders/lldb-x86_64-ubuntu-14.04-cmake/builds/23184

Culprit:
```
Build Command Output:
objcopy: option '--compress-debug-sections' doesn't allow an argument
```
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] r332165 - Revert "[LLDB] Support GNU-style compressed debug sections (.zdebug)"

2018-05-11 Thread Davide Italiano via lldb-commits
Author: davide
Date: Fri May 11 18:25:48 2018
New Revision: 332165

URL: http://llvm.org/viewvc/llvm-project?rev=332165&view=rev
Log:
Revert "[LLDB] Support GNU-style compressed debug sections (.zdebug)"

This reverts commit r332162 as it breaks the bots (Ubuntu 14.04)
with the following message:

Build Command Output:
objcopy: option '--compress-debug-sections' doesn't allow an argument

Removed:

lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile

lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c
Modified:
lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Removed: 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile?rev=332164&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile 
(original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile 
(removed)
@@ -1,16 +0,0 @@
-LEVEL := ../../make
-
-C_SOURCES := a.c
-
-all: compressed.out compressed.gnu.out
-
-compressed.out: a.out
-   $(OBJCOPY) --compress-debug-sections=zlib $< $@
-
-compressed.gnu.out: a.out
-   $(OBJCOPY) --compress-debug-sections=zlib-gnu $< $@
-
-include $(LEVEL)/Makefile.rules
-
-clean::
-   $(RM) -f a.o main compressed.out compressed.gnu.out

Removed: 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py?rev=332164&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
 (removed)
@@ -1,46 +0,0 @@
-""" Tests that compressed debug info sections are used. """
-import os
-import lldb
-import sys
-from lldbsuite.test.decorators import *
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-
-
-class TestCompressedDebugInfo(TestBase):
-  mydir = TestBase.compute_mydir(__file__)
-
-  def setUp(self):
-TestBase.setUp(self)
-
-  @no_debug_info_test  # Prevent the genaration of the dwarf version of this 
test
-  @skipUnlessPlatform(["linux"])
-  def test_compressed_debug_info(self):
-"""Tests that the 'frame variable' works with compressed debug info."""
-
-self.build()
-process = lldbutil.run_to_source_breakpoint(
-self, "main", lldb.SBFileSpec("a.c"), exe_name="compressed.out")[1]
-
-# The process should be stopped at a breakpoint, and the z variable should
-# be in the top frame.
-self.assertTrue(process.GetState() == lldb.eStateStopped,
-STOPPED_DUE_TO_BREAKPOINT)
-frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
-self.assertTrue(frame.FindVariable("z").IsValid(), "z is not valid")
-
-  @no_debug_info_test  # Prevent the genaration of the dwarf version of this 
test
-  @skipUnlessPlatform(["linux"])
-  def test_compressed_debug_info_gnu(self):
-"""Tests that the 'frame variable' works with gnu-style compressed debug 
info."""
-
-self.build()
-process = lldbutil.run_to_source_breakpoint(
-self, "main", lldb.SBFileSpec("a.c"), exe_name="compressed.gnu.out")[1]
-
-# The process should be stopped at a breakpoint, and the z variable should
-# be in the top frame.
-self.assertTrue(process.GetState() == lldb.eStateStopped,
-STOPPED_DUE_TO_BREAKPOINT)
-frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
-self.assertTrue(frame.FindVariable("z").IsValid(), "z is not valid")

Removed: 
lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c?rev=332164&view=auto
==
--- lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c 
(original)
+++ lldb/trunk/packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c 
(removed)
@@ -1,4 +0,0 @@
-int main() {
-  int z = 2;
-  return z;
-}

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=332165&r1=332164&r2=332165&view=diff
==
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/Object

Re: [Lldb-commits] [lldb] r332162 - [LLDB] Support GNU-style compressed debug sections (.zdebug)

2018-05-11 Thread Davide Italiano via lldb-commits
On Fri, May 11, 2018 at 5:57 PM, Davide Italiano  wrote:
> On Fri, May 11, 2018 at 5:29 PM, Davide Italiano via lldb-commits
>  wrote:
>> Author: davide
>> Date: Fri May 11 17:29:25 2018
>> New Revision: 332162
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=332162&view=rev
>> Log:
>> [LLDB] Support GNU-style compressed debug sections (.zdebug)
>>
>> Patch by Erik Welander!
>>
>
> Erik, I'm going to revert this because it broke the ubuntu 14.04 bot.
> Please take a look and I'll recommit it for you once it's fixed.
>
> Log:
> http://lab.llvm.org:8011/builders/lldb-x86_64-ubuntu-14.04-cmake/builds/23184
>
> Culprit:
> ```
> Build Command Output:
> objcopy: option '--compress-debug-sections' doesn't allow an argument
> ```

Reverted in r332165.
Don't hesitate to ping me when you have a fix.

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