[Lldb-commits] [lldb] r335430 - [FileSpec] Refactor append and prepend implemenetations. NFC

2018-06-24 Thread Jonas Devlieghere via lldb-commits
Author: jdevlieghere
Date: Sun Jun 24 03:18:01 2018
New Revision: 335430

URL: http://llvm.org/viewvc/llvm-project?rev=335430&view=rev
Log:
[FileSpec] Refactor append and prepend implemenetations. NFC

Replaces custom implementations of append and prepend with calls to
llvm's path library. This is part of a series of patches (started in
D48084) to delegate common operations to llvm::sys::path.

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

Modified: lldb/trunk/source/Utility/FileSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/FileSpec.cpp?rev=335430&r1=335429&r2=335430&view=diff
==
--- lldb/trunk/source/Utility/FileSpec.cpp (original)
+++ lldb/trunk/source/Utility/FileSpec.cpp Sun Jun 24 03:18:01 2018
@@ -57,10 +57,6 @@ char GetPreferredPathSeparator(FileSpec:
   return GetPathSeparators(style)[0];
 }
 
-bool IsPathSeparator(char value, FileSpec::Style style) {
-  return value == '/' || (!PathStyleIsPosix(style) && value == '\\');
-}
-
 void Denormalize(llvm::SmallVectorImpl &path, FileSpec::Style style) {
   if (PathStyleIsPosix(style))
 return;
@@ -646,91 +642,28 @@ FileSpec::CopyByAppendingPathComponent(l
 }
 
 FileSpec FileSpec::CopyByRemovingLastPathComponent() const {
-  // CLEANUP: Use StringRef for string handling.
-  const bool resolve = false;
-  if (m_filename.IsEmpty() && m_directory.IsEmpty())
-return FileSpec("", resolve);
-  if (m_directory.IsEmpty())
-return FileSpec("", resolve);
-  if (m_filename.IsEmpty()) {
-const char *dir_cstr = m_directory.GetCString();
-const char *last_slash_ptr = ::strrchr(dir_cstr, '/');
-
-// check for obvious cases before doing the full thing
-if (!last_slash_ptr)
-  return FileSpec("", resolve);
-if (last_slash_ptr == dir_cstr)
-  return FileSpec("/", resolve);
-
-size_t last_slash_pos = last_slash_ptr - dir_cstr + 1;
-ConstString new_path(dir_cstr, last_slash_pos);
-return FileSpec(new_path.GetCString(), resolve);
-  } else
-return FileSpec(m_directory.GetCString(), resolve);
+  llvm::SmallString<64> current_path;
+  GetPath(current_path, false);
+  if (llvm::sys::path::has_parent_path(current_path, m_style))
+return FileSpec(llvm::sys::path::parent_path(current_path, m_style), false,
+m_style);
+  return *this;
 }
 
 ConstString FileSpec::GetLastPathComponent() const {
-  // CLEANUP: Use StringRef for string handling.
-  if (m_filename)
-return m_filename;
-  if (m_directory) {
-const char *dir_cstr = m_directory.GetCString();
-const char *last_slash_ptr = ::strrchr(dir_cstr, '/');
-if (last_slash_ptr == NULL)
-  return m_directory;
-if (last_slash_ptr == dir_cstr) {
-  if (last_slash_ptr[1] == 0)
-return ConstString(last_slash_ptr);
-  else
-return ConstString(last_slash_ptr + 1);
-}
-if (last_slash_ptr[1] != 0)
-  return ConstString(last_slash_ptr + 1);
-const char *penultimate_slash_ptr = last_slash_ptr;
-while (*penultimate_slash_ptr) {
-  --penultimate_slash_ptr;
-  if (penultimate_slash_ptr == dir_cstr)
-break;
-  if (*penultimate_slash_ptr == '/')
-break;
-}
-ConstString result(penultimate_slash_ptr + 1,
-   last_slash_ptr - penultimate_slash_ptr);
-return result;
-  }
-  return ConstString();
-}
-
-static std::string
-join_path_components(FileSpec::Style style,
- const std::vector components) {
-  std::string result;
-  for (size_t i = 0; i < components.size(); ++i) {
-if (components[i].empty())
-  continue;
-result += components[i];
-if (i != components.size() - 1 &&
-!IsPathSeparator(components[i].back(), style))
-  result += GetPreferredPathSeparator(style);
-  }
-
-  return result;
+  llvm::SmallString<64> current_path;
+  GetPath(current_path, false);
+  return ConstString(llvm::sys::path::filename(current_path, m_style));
 }
 
 void FileSpec::PrependPathComponent(llvm::StringRef component) {
-  if (component.empty())
-return;
-
-  const bool resolve = false;
-  if (m_filename.IsEmpty() && m_directory.IsEmpty()) {
-SetFile(component, resolve);
-return;
-  }
-
-  std::string result =
-  join_path_components(m_style, {component, m_directory.GetStringRef(),
- m_filename.GetStringRef()});
-  SetFile(result, resolve);
+  llvm::SmallString<64> new_path(component);
+  llvm::SmallString<64> current_path;
+  GetPath(current_path, false);
+  llvm::sys::path::append(new_path,
+  llvm::sys::path::begin(current_path, m_style),
+  llvm::sys::path::end(current_path), m_style);
+  SetFile(new_path, false, m_style);
 }
 
 void FileSpec::PrependPathComponent(const FileSpec &new_path) {
@@ -738,17 +671,10 @@ void FileSpec::PrependPathComponent(cons
 }
 
 void FileSpec::AppendPathComponent(llvm::StringRef

[Lldb-commits] [lldb] r335431 - Make testcase classnames unique

2018-06-24 Thread Jan Kratochvil via lldb-commits
Author: jankratochvil
Date: Sun Jun 24 03:36:44 2018
New Revision: 335431

URL: http://llvm.org/viewvc/llvm-project?rev=335431&view=rev
Log:
Make testcase classnames unique

Filenames with test results contain only the class name which makes it more
difficult to find it if the same class name is present in multiple *.py files.

packages/Python/lldbsuite/test/functionalities/step-avoids-no-debug/TestStepNoDebug.py
-class ReturnValueTestCase(TestBase):
+class StepAvoidsNoDebugTestCase(TestBase):
as ReturnValueTestCase is already present in:
packages/Python/lldbsuite/test/functionalities/return-value/TestReturnValue.py

packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py
-class CreateDuringStepTestCase(TestBase):
+class CrashDuringStepTestCase(TestBase):
as CreateDuringStepTestCase is already present in:
packages/Python/lldbsuite/test/functionalities/thread/create_during_step/TestCreateDuringStep.py

packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py
-class TestCStepping(TestBase):
+class StepUntilTestCase(TestBase):
as TestCStepping is already present in:
packages/Python/lldbsuite/test/lang/c/stepping/TestStepAndBreakpoints.py

Modified:

lldb/trunk/packages/Python/lldbsuite/test/functionalities/step-avoids-no-debug/TestStepNoDebug.py

lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py

lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/step-avoids-no-debug/TestStepNoDebug.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/step-avoids-no-debug/TestStepNoDebug.py?rev=335431&r1=335430&r2=335431&view=diff
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/step-avoids-no-debug/TestStepNoDebug.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/step-avoids-no-debug/TestStepNoDebug.py
 Sun Jun 24 03:36:44 2018
@@ -15,7 +15,7 @@ from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
 
 
-class ReturnValueTestCase(TestBase):
+class StepAvoidsNoDebugTestCase(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py?rev=335431&r1=335430&r2=335431&view=diff
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py
 Sun Jun 24 03:36:44 2018
@@ -12,7 +12,7 @@ from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
 
 
-class CreateDuringStepTestCase(TestBase):
+class CrashDuringStepTestCase(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py?rev=335431&r1=335430&r2=335431&view=diff
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py
 Sun Jun 24 03:36:44 2018
@@ -11,7 +11,7 @@ from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
 
 
-class TestCStepping(TestBase):
+class StepUntilTestCase(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 


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


[Lldb-commits] [lldb] r335432 - [FileSpec] Always normalize

2018-06-24 Thread Jonas Devlieghere via lldb-commits
Author: jdevlieghere
Date: Sun Jun 24 06:31:44 2018
New Revision: 335432

URL: http://llvm.org/viewvc/llvm-project?rev=335432&view=rev
Log:
[FileSpec] Always normalize

Removing redundant components from the path seems pretty harmless.
Rather than checking whether this is necessary and then actually doing
so, always invoke remove_dots to start with a normalized path.

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

Modified: lldb/trunk/source/Utility/FileSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/FileSpec.cpp?rev=335432&r1=335431&r2=335432&view=diff
==
--- lldb/trunk/source/Utility/FileSpec.cpp (original)
+++ lldb/trunk/source/Utility/FileSpec.cpp Sun Jun 24 06:31:44 2018
@@ -119,100 +119,6 @@ FileSpec::FileSpec(const FileSpec *rhs)
 //--
 FileSpec::~FileSpec() {}
 
-namespace {
-//--
-/// Safely get a character at the specified index.
-///
-/// @param[in] path
-/// A full, partial, or relative path to a file.
-///
-/// @param[in] i
-/// An index into path which may or may not be valid.
-///
-/// @return
-///   The character at index \a i if the index is valid, or 0 if
-///   the index is not valid.
-//--
-inline char safeCharAtIndex(const llvm::StringRef &path, size_t i) {
-  if (i < path.size())
-return path[i];
-  return 0;
-}
-
-//--
-/// Check if a path needs to be normalized.
-///
-/// Check if a path needs to be normalized. We currently consider a
-/// path to need normalization if any of the following are true
-///  - path contains "/./"
-///  - path contains "/../"
-///  - path contains "//"
-///  - path ends with "/"
-/// Paths that start with "./" or with "../" are not considered to
-/// need normalization since we aren't trying to resolve the path,
-/// we are just trying to remove redundant things from the path.
-///
-/// @param[in] path
-/// A full, partial, or relative path to a file.
-///
-/// @return
-///   Returns \b true if the path needs to be normalized.
-//--
-bool needsNormalization(const llvm::StringRef &path) {
-  if (path.empty())
-return false;
-  // We strip off leading "." values so these paths need to be normalized
-  if (path[0] == '.')
-return true;
-  for (auto i = path.find_first_of("\\/"); i != llvm::StringRef::npos;
-   i = path.find_first_of("\\/", i + 1)) {
-const auto next = safeCharAtIndex(path, i+1);
-switch (next) {
-  case 0:
-// path separator char at the end of the string which should be
-// stripped unless it is the one and only character
-return i > 0;
-  case '/':
-  case '\\':
-// two path separator chars in the middle of a path needs to be
-// normalized
-if (i > 0)
-  return true;
-++i;
-break;
-
-  case '.': {
-  const auto next_next = safeCharAtIndex(path, i+2);
-  switch (next_next) {
-default: break;
-case 0: return true; // ends with "/."
-case '/':
-case '\\':
-  return true; // contains "/./"
-case '.': {
-  const auto next_next_next = safeCharAtIndex(path, i+3);
-  switch (next_next_next) {
-default: break;
-case 0: return true; // ends with "/.."
-case '/':
-case '\\':
-  return true; // contains "/../"
-  }
-  break;
-}
-  }
-}
-break;
-
-  default:
-break;
-}
-  }
-  return false;
-}
-
-
-}
 //--
 // Assignment operator.
 //--
@@ -252,8 +158,7 @@ void FileSpec::SetFile(llvm::StringRef p
   }
 
   // Normalize the path by removing ".", ".." and other redundant components.
-  if (needsNormalization(resolved))
-llvm::sys::path::remove_dots(resolved, true, m_style);
+  llvm::sys::path::remove_dots(resolved, true, m_style);
 
   // Normalize back slashes to forward slashes
   if (m_style == Style::windows)
@@ -270,10 +175,10 @@ void FileSpec::SetFile(llvm::StringRef p
   // Split path into filename and directory. We rely on the underlying char
   // pointer to be nullptr when the components are empty.
   llvm::StringRef filename = llvm::sys::path::filename(resolved, m_style);
-  if(!filename.empty())
+  if (!filename.empty())
 m_filename.SetString(filename);
   llvm::StringRef directory = llvm::sys::path::parent_path(resolved, m_style);
-  if(!directory.empty())
+  if (!directory.empty())
 m_directory

[Lldb-commits] [PATCH] D48520: [lldb-mi] Re-implement a few MI commands.

2018-06-24 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

Nice. Since you are adding new lit-based tests for these commands, does that 
mean that the old python tests become redundant and could we remove them? IIRC 
the python tests don't set synchronous mode so they are prone to fail under 
load.


https://reviews.llvm.org/D48520



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


[Lldb-commits] [PATCH] D48520: [lldb-mi] Re-implement a few MI commands.

2018-06-24 Thread Alexander Polyakov via Phabricator via lldb-commits
apolyakov added a comment.

You are right about python tests. Let's remove them.


https://reviews.llvm.org/D48520



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