[Lldb-commits] [PATCH] D25392: Remove TimeValue usage from FileSpec.h

2016-11-01 Thread Pavel Labath via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285702: Remove TimeValue usage from FileSpec.h (authored by 
labath).

Changed prior to commit:
  https://reviews.llvm.org/D25392?vs=76573=76576#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25392

Files:
  lldb/trunk/include/lldb/Core/Module.h
  lldb/trunk/include/lldb/Core/ModuleSpec.h
  lldb/trunk/include/lldb/Core/SourceManager.h
  lldb/trunk/include/lldb/Host/FileSpec.h
  lldb/trunk/include/lldb/Host/FileSystem.h
  lldb/trunk/include/lldb/Host/TimeValue.h
  lldb/trunk/include/lldb/Interpreter/OptionValueFileSpec.h
  lldb/trunk/source/Core/Module.cpp
  lldb/trunk/source/Core/ModuleList.cpp
  lldb/trunk/source/Core/SourceManager.cpp
  lldb/trunk/source/Host/common/FileSpec.cpp
  lldb/trunk/source/Host/common/FileSystem.cpp
  lldb/trunk/source/Interpreter/OptionValueFileSpec.cpp
  lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
  
lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
  lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  lldb/trunk/unittests/Host/CMakeLists.txt
  lldb/trunk/unittests/Host/FileSystemTest.cpp

Index: lldb/trunk/unittests/Host/FileSystemTest.cpp
===
--- lldb/trunk/unittests/Host/FileSystemTest.cpp
+++ lldb/trunk/unittests/Host/FileSystemTest.cpp
@@ -0,0 +1,32 @@
+//===-- FileSystemTest.cpp --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Host/FileSystem.h"
+
+extern const char *TestMainArgv0;
+
+using namespace lldb_private;
+
+TEST(FileSystemTest, FileAndDirectoryComponents) {
+  using namespace std::chrono;
+
+  const bool resolve = true;
+#ifdef _WIN32
+  FileSpec fs1("C:\\FILE\\THAT\\DOES\\NOT\\EXIST.TXT", !resolve);
+#else
+  FileSpec fs1("/file/that/does/not/exist.txt", !resolve);
+#endif
+  FileSpec fs2(TestMainArgv0, resolve);
+
+  EXPECT_EQ(system_clock::time_point(), FileSystem::GetModificationTime(fs1));
+  EXPECT_LT(system_clock::time_point() + hours(24 * 365 * 20),
+FileSystem::GetModificationTime(fs2));
+}
Index: lldb/trunk/unittests/Host/CMakeLists.txt
===
--- lldb/trunk/unittests/Host/CMakeLists.txt
+++ lldb/trunk/unittests/Host/CMakeLists.txt
@@ -1,5 +1,6 @@
 add_lldb_unittest(HostTests
   FileSpecTest.cpp
+  FileSystemTest.cpp
   SocketAddressTest.cpp
   SocketTest.cpp
   SymbolsTest.cpp
Index: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
===
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -7,6 +7,8 @@
 //
 //===--===//
 
+#include "DynamicLoaderDarwin.h"
+
 #include "lldb/Breakpoint/StoppointCallbackContext.h"
 #include "lldb/Core/DataBuffer.h"
 #include "lldb/Core/DataBufferHeap.h"
@@ -18,6 +20,7 @@
 #include "lldb/Core/Section.h"
 #include "lldb/Core/State.h"
 #include "lldb/Expression/DiagnosticManager.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/ObjectFile.h"
@@ -30,8 +33,6 @@
 #include "lldb/Target/ThreadPlanCallFunction.h"
 #include "lldb/Target/ThreadPlanRunToAddress.h"
 
-#include "DynamicLoaderDarwin.h"
-
 //#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
 #ifdef ENABLE_DEBUG_PRINTF
 #include 
@@ -114,7 +115,7 @@
 // No UUID, we must rely upon the cached module modification
 // time and the modification time of the file on disk
 if (module_sp->GetModificationTime() !=
-module_sp->GetFileSpec().GetModificationTime())
+FileSystem::GetModificationTime(module_sp->GetFileSpec()))
   module_sp.reset();
   }
 
Index: lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
===
--- lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -34,6 +34,7 @@
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/Timer.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Symbol/ObjectFile.h"
 
 using namespace lldb;
@@ -452,7 +453,7 @@
   

[Lldb-commits] [PATCH] D25392: Remove TimeValue usage from FileSpec.h

2016-11-01 Thread Pavel Labath via lldb-commits
labath updated this revision to Diff 76573.
labath marked 2 inline comments as done.
labath added a comment.

- cleanup constructors
- use llvm's stat() implementation


https://reviews.llvm.org/D25392

Files:
  include/lldb/Core/Module.h
  include/lldb/Core/ModuleSpec.h
  include/lldb/Core/SourceManager.h
  include/lldb/Host/FileSpec.h
  include/lldb/Host/FileSystem.h
  include/lldb/Host/TimeValue.h
  include/lldb/Interpreter/OptionValueFileSpec.h
  source/Core/Module.cpp
  source/Core/ModuleList.cpp
  source/Core/SourceManager.cpp
  source/Host/common/FileSpec.cpp
  source/Host/common/FileSystem.cpp
  source/Interpreter/OptionValueFileSpec.cpp
  source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
  source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
  source/Plugins/Platform/Android/AdbClient.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  unittests/Host/CMakeLists.txt
  unittests/Host/FileSystemTest.cpp

Index: unittests/Host/FileSystemTest.cpp
===
--- /dev/null
+++ unittests/Host/FileSystemTest.cpp
@@ -0,0 +1,32 @@
+//===-- FileSystemTest.cpp --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Host/FileSystem.h"
+
+extern const char *TestMainArgv0;
+
+using namespace lldb_private;
+
+TEST(FileSystemTest, FileAndDirectoryComponents) {
+  using namespace std::chrono;
+
+  const bool resolve = true;
+#ifdef _WIN32
+  FileSpec fs1("C:\\FILE\\THAT\\DOES\\NOT\\EXIST.TXT", !resolve);
+#else
+  FileSpec fs1("/file/that/does/not/exist.txt", !resolve);
+#endif
+  FileSpec fs2(TestMainArgv0, resolve);
+
+  EXPECT_EQ(system_clock::time_point(), FileSystem::GetModificationTime(fs1));
+  EXPECT_LT(system_clock::time_point() + hours(24 * 365 * 20),
+FileSystem::GetModificationTime(fs2));
+}
Index: unittests/Host/CMakeLists.txt
===
--- unittests/Host/CMakeLists.txt
+++ unittests/Host/CMakeLists.txt
@@ -1,5 +1,6 @@
 add_lldb_unittest(HostTests
   FileSpecTest.cpp
+  FileSystemTest.cpp
   SocketAddressTest.cpp
   SocketTest.cpp
   SymbolsTest.cpp
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -14,6 +14,7 @@
 #include 
 
 #include "lldb/Core/RangeMap.h"
+#include "lldb/Host/TimeValue.h"
 #include "lldb/Symbol/SymbolFile.h"
 
 #include "UniqueDWARFASTType.h"
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -21,6 +21,7 @@
 #include "lldb/Core/RangeMap.h"
 #include "lldb/Core/RegularExpression.h"
 #include "lldb/Core/Section.h"
+#include "lldb/Host/FileSystem.h"
 
 //#define DEBUG_OSO_DMAP // DO NOT CHECKIN WITH THIS NOT COMMENTED OUT
 #if defined(DEBUG_OSO_DMAP)
@@ -424,7 +425,7 @@
   FileSpec oso_file(oso_path, false);
   ConstString oso_object;
   if (oso_file.Exists()) {
-TimeValue oso_mod_time(oso_file.GetModificationTime());
+TimeValue oso_mod_time(FileSystem::GetModificationTime(oso_file));
 if (oso_mod_time != comp_unit_info->oso_mod_time) {
   obj_file->GetModule()->ReportError(
   "debug map object file '%s' has changed (actual time is "
Index: source/Plugins/Platform/Android/AdbClient.cpp
===
--- source/Plugins/Platform/Android/AdbClient.cpp
+++ source/Plugins/Platform/Android/AdbClient.cpp
@@ -22,6 +22,7 @@
 #include "lldb/Core/StreamString.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
 #include "lldb/Host/FileSpec.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/PosixApi.h"
 
 #include 
@@ -475,8 +476,11 @@
 if (error.Fail())
   return Error("Failed to send file chunk: %s", error.AsCString());
   }
-  error = SendSyncRequest(kDONE, local_file.GetModificationTime().seconds(),
-  nullptr);
+  error = SendSyncRequest(
+  kDONE, std::chrono::duration_cast(
+ FileSystem::GetModificationTime(local_file).time_since_epoch())
+ .count(),
+  nullptr);
   if (error.Fail())
 return error;
 
Index: source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp

[Lldb-commits] [PATCH] D25392: Remove TimeValue usage from FileSpec.h

2016-11-01 Thread Pavel Labath via lldb-commits
labath added inline comments.



Comment at: include/lldb/Host/FileSystem.h:69-71
+  static std::chrono::time_point
+  GetModificationTime(const FileSpec _spec);

labath wrote:
> zturner wrote:
> > I wonder if it would be worth defining some typedefs in LLVM's `Chrono.h` 
> > that Mehdi is adding to make things like this less verbose.  For example:
> > 
> > ```
> > llvm::nanosecond_time_point
> > llvm::microsecond_time_point
> > llvm::nanosecond_duration
> > llvm::microsecond_duration
> > ```
> > 
> > Now, with all that aside, I'm not sure we actually need this function here 
> > (or many of the other functions for that matter).  LLVM has 
> > `llvm::support::fs::status()` which will return you a `file_status` object 
> > which contains the modification time.  I wonder if we should use that 
> > instead.  It currently uses an `llvm::TimeValue`, but the conversion to 
> > `chrono` could happen at that level presumably.
> That's a good point. I can check how easy it would be to do that. I'd like to 
> avoid refactoring the filesystem code just to get the time value conversion 
> done though.
I've changed this to use llvm::sys::fs::status() underneath (which now uses 
chrono). I am still keeping this function, as it has a somewhat different 
interface (takes FileSpec, returns an empty time point in case of an error), 
and I don't want to update all callers now.


https://reviews.llvm.org/D25392



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


Re: [Lldb-commits] [PATCH] D25392: Remove TimeValue usage from FileSpec.h

2016-10-08 Thread Zachary Turner via lldb-commits
Yea let's just duration_cast before calling to_time_t
On Sat, Oct 8, 2016 at 4:23 PM Pavel Labath  wrote:

> labath added inline comments.
>
>
> 
> Comment at: include/lldb/Host/TimeValue.h:37-38
>explicit TimeValue(uint32_t seconds, uint64_t nanos = 0);
> +  TimeValue(std::chrono::time_point +std::chrono::nanoseconds>
> +point)
> 
> labath wrote:
> > zturner wrote:
> > > Is there any reason to explicitly prefer a nanosecond clock here as
> opposed to `std::chrono::system_clock::duration`?  For any system which
> doesn't have nanosecond resolution, using a nanosecond clock is pointless,
> and if some theoretical system had finer resolution, then using a
> nanosecond clock would be limiting.  So how about just
> `std::chrono::time_point` and let the final
> argument be deduced?
> > If you let this argument be less precise you will get conversion errors
> if someone tries to pass in a time point which has higher precision
> (seconds are implicitly convertible to nanoseconds, but not the other way).
> And struct timespec already (theoretically) has nanosecond precision, so we
> would have to make an explicit choice to lose the precision  at some level.
> >
> > `chrono::system_clock::time_point` has the precision at which the host
> system clock hands out timestamps, but that doesn't mean it's impossible to
> get higher precision timestamps, particularly if we start dealing with
> remote systems.
> I've hit one more annoying issue `system_clock::to_time_t` will not accept
> a time point with precision greater than native system clock precision.
> Sort of makes sense, although it's pretty pointless since time_t has only
> second precision on all reasonable platforms. This means, if we use
> nanosecond precision everywhere, we would have to cast, or roll our own
> version of `to_time_t`. If we use native system clock precision, we lose
> the ability to represent nanoseconds in some cases (and there are
> filesystems storing timestamps with nanosecond precision), cannot represent
> `struct timespec` nor the current `TimeValue`s correctly, and our time
> functions would behave differently depending on the host os. I'd go with
> the first option as it seems to have less drawbacks.
>
> I'll try to come up with a coherent proposal on the llvm side. Since it
> seems we'll be putting these things there, I feel I should start by porting
> the usage in llvm anyway.
>
>
> https://reviews.llvm.org/D25392
>
>
>
>
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D25392: Remove TimeValue usage from FileSpec.h

2016-10-08 Thread Pavel Labath via lldb-commits
labath added inline comments.



Comment at: include/lldb/Host/TimeValue.h:37-38
   explicit TimeValue(uint32_t seconds, uint64_t nanos = 0);
+  TimeValue(std::chrono::time_point
+point)

labath wrote:
> zturner wrote:
> > Is there any reason to explicitly prefer a nanosecond clock here as opposed 
> > to `std::chrono::system_clock::duration`?  For any system which doesn't 
> > have nanosecond resolution, using a nanosecond clock is pointless, and if 
> > some theoretical system had finer resolution, then using a nanosecond clock 
> > would be limiting.  So how about just 
> > `std::chrono::time_point` and let the final 
> > argument be deduced?
> If you let this argument be less precise you will get conversion errors if 
> someone tries to pass in a time point which has higher precision (seconds are 
> implicitly convertible to nanoseconds, but not the other way). And struct 
> timespec already (theoretically) has nanosecond precision, so we would have 
> to make an explicit choice to lose the precision  at some level.
> 
> `chrono::system_clock::time_point` has the precision at which the host system 
> clock hands out timestamps, but that doesn't mean it's impossible to get 
> higher precision timestamps, particularly if we start dealing with remote 
> systems.
I've hit one more annoying issue `system_clock::to_time_t` will not accept a 
time point with precision greater than native system clock precision. Sort of 
makes sense, although it's pretty pointless since time_t has only second 
precision on all reasonable platforms. This means, if we use nanosecond 
precision everywhere, we would have to cast, or roll our own version of 
`to_time_t`. If we use native system clock precision, we lose the ability to 
represent nanoseconds in some cases (and there are filesystems storing 
timestamps with nanosecond precision), cannot represent `struct timespec` nor 
the current `TimeValue`s correctly, and our time functions would behave 
differently depending on the host os. I'd go with the first option as it seems 
to have less drawbacks.

I'll try to come up with a coherent proposal on the llvm side. Since it seems 
we'll be putting these things there, I feel I should start by porting the usage 
in llvm anyway.


https://reviews.llvm.org/D25392



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


[Lldb-commits] [PATCH] D25392: Remove TimeValue usage from FileSpec.h

2016-10-08 Thread Pavel Labath via lldb-commits
labath added inline comments.



Comment at: include/lldb/Host/FileSystem.h:69-71
+  static std::chrono::time_point
+  GetModificationTime(const FileSpec _spec);

zturner wrote:
> I wonder if it would be worth defining some typedefs in LLVM's `Chrono.h` 
> that Mehdi is adding to make things like this less verbose.  For example:
> 
> ```
> llvm::nanosecond_time_point
> llvm::microsecond_time_point
> llvm::nanosecond_duration
> llvm::microsecond_duration
> ```
> 
> Now, with all that aside, I'm not sure we actually need this function here 
> (or many of the other functions for that matter).  LLVM has 
> `llvm::support::fs::status()` which will return you a `file_status` object 
> which contains the modification time.  I wonder if we should use that 
> instead.  It currently uses an `llvm::TimeValue`, but the conversion to 
> `chrono` could happen at that level presumably.
That's a good point. I can check how easy it would be to do that. I'd like to 
avoid refactoring the filesystem code just to get the time value conversion 
done though.



Comment at: include/lldb/Host/TimeValue.h:37-38
   explicit TimeValue(uint32_t seconds, uint64_t nanos = 0);
+  TimeValue(std::chrono::time_point
+point)

zturner wrote:
> Is there any reason to explicitly prefer a nanosecond clock here as opposed 
> to `std::chrono::system_clock::duration`?  For any system which doesn't have 
> nanosecond resolution, using a nanosecond clock is pointless, and if some 
> theoretical system had finer resolution, then using a nanosecond clock would 
> be limiting.  So how about just 
> `std::chrono::time_point` and let the final 
> argument be deduced?
If you let this argument be less precise you will get conversion errors if 
someone tries to pass in a time point which has higher precision (seconds are 
implicitly convertible to nanoseconds, but not the other way). And struct 
timespec already (theoretically) has nanosecond precision, so we would have to 
make an explicit choice to lose the precision  at some level.

`chrono::system_clock::time_point` has the precision at which the host system 
clock hands out timestamps, but that doesn't mean it's impossible to get higher 
precision timestamps, particularly if we start dealing with remote systems.



Comment at: source/Core/Module.cpp:238-245
+: m_mutex(), m_mod_time(FileSystem::GetModificationTime(file_spec)),
+  m_arch(arch), m_uuid(), m_file(file_spec), m_platform_file(),
+  m_remote_install_file(), m_symfile_spec(), m_object_name(),
+  m_object_offset(object_offset), m_object_mod_time(), m_objfile_sp(),
+  m_symfile_ap(), m_type_system_map(), m_source_mappings(), 
m_sections_ap(),
+  m_did_load_objfile(false), m_did_load_symbol_vendor(false),
+  m_did_parse_uuid(false), m_file_has_changed(false),

zturner wrote:
> Whenever I touch code like this, I've been goign through and deleting all the 
> explicit constructor initializers and putting them in the header.  All the 
> ones of class type can just disappear, and the bools can be initialized 
> inline at the point of declaration.
sounds like a good idea.


https://reviews.llvm.org/D25392



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


[Lldb-commits] [PATCH] D25392: Remove TimeValue usage from FileSpec.h

2016-10-08 Thread Zachary Turner via lldb-commits
zturner added inline comments.



Comment at: include/lldb/Host/FileSystem.h:69-71
+  static std::chrono::time_point
+  GetModificationTime(const FileSpec _spec);

I wonder if it would be worth defining some typedefs in LLVM's `Chrono.h` that 
Mehdi is adding to make things like this less verbose.  For example:

```
llvm::nanosecond_time_point
llvm::microsecond_time_point
llvm::nanosecond_duration
llvm::microsecond_duration
```

Now, with all that aside, I'm not sure we actually need this function here (or 
many of the other functions for that matter).  LLVM has 
`llvm::support::fs::status()` which will return you a `file_status` object 
which contains the modification time.  I wonder if we should use that instead.  
It currently uses an `llvm::TimeValue`, but the conversion to `chrono` could 
happen at that level presumably.



Comment at: include/lldb/Host/TimeValue.h:37-38
   explicit TimeValue(uint32_t seconds, uint64_t nanos = 0);
+  TimeValue(std::chrono::time_point
+point)

Is there any reason to explicitly prefer a nanosecond clock here as opposed to 
`std::chrono::system_clock::duration`?  For any system which doesn't have 
nanosecond resolution, using a nanosecond clock is pointless, and if some 
theoretical system had finer resolution, then using a nanosecond clock would be 
limiting.  So how about just 
`std::chrono::time_point` and let the final argument 
be deduced?



Comment at: source/Core/Module.cpp:238-245
+: m_mutex(), m_mod_time(FileSystem::GetModificationTime(file_spec)),
+  m_arch(arch), m_uuid(), m_file(file_spec), m_platform_file(),
+  m_remote_install_file(), m_symfile_spec(), m_object_name(),
+  m_object_offset(object_offset), m_object_mod_time(), m_objfile_sp(),
+  m_symfile_ap(), m_type_system_map(), m_source_mappings(), 
m_sections_ap(),
+  m_did_load_objfile(false), m_did_load_symbol_vendor(false),
+  m_did_parse_uuid(false), m_file_has_changed(false),

Whenever I touch code like this, I've been goign through and deleting all the 
explicit constructor initializers and putting them in the header.  All the ones 
of class type can just disappear, and the bools can be initialized inline at 
the point of declaration.


https://reviews.llvm.org/D25392



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


[Lldb-commits] [PATCH] D25392: Remove TimeValue usage from FileSpec.h

2016-10-07 Thread Pavel Labath via lldb-commits
labath added a subscriber: mehdi_amini.
labath added inline comments.



Comment at: source/Host/common/FileSystem.cpp:103
+
+  return system_clock::from_time_t(file_stats.st_mtimespec.tv_sec) +
+ nanoseconds(file_stats.st_mtimespec.tv_nsec);

The conversion from `struct timespec` will probably be necessary in some other 
places as well.


https://reviews.llvm.org/D25392



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


[Lldb-commits] [PATCH] D25392: Remove TimeValue usage from FileSpec.h

2016-10-07 Thread Pavel Labath via lldb-commits
labath created this revision.
labath added reviewers: clayborg, zturner.
labath added a subscriber: lldb-commits.
Herald added subscribers: mgorny, beanz, danalbert, tberghammer.

The only usage there was in GetModificationTime(). I also took the opportunity
to move this function from FileSpec to the FileSystem class - since we are
using FileSpecs to also represent remote files for which we cannot (easily)
retrieve modification time, it makes sense to make the decision to get the
modification time more explicit.

The new function returns a std::duration::time_point. To aid the transition
from TimeValue, I have added a constructor to it which enables implicit
conversion from a time_point.


https://reviews.llvm.org/D25392

Files:
  include/lldb/Core/ModuleSpec.h
  include/lldb/Core/SourceManager.h
  include/lldb/Host/FileSpec.h
  include/lldb/Host/FileSystem.h
  include/lldb/Host/TimeValue.h
  include/lldb/Interpreter/OptionValueFileSpec.h
  source/Core/Module.cpp
  source/Core/ModuleList.cpp
  source/Core/SourceManager.cpp
  source/Host/common/FileSpec.cpp
  source/Host/common/FileSystem.cpp
  source/Interpreter/OptionValueFileSpec.cpp
  source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
  source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
  source/Plugins/Platform/Android/AdbClient.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  unittests/Host/CMakeLists.txt
  unittests/Host/FileSystemTest.cpp

Index: unittests/Host/FileSystemTest.cpp
===
--- /dev/null
+++ unittests/Host/FileSystemTest.cpp
@@ -0,0 +1,32 @@
+//===-- FileSystemTest.cpp --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Host/FileSystem.h"
+
+extern const char *TestMainArgv0;
+
+using namespace lldb_private;
+
+TEST(FileSystemTest, FileAndDirectoryComponents) {
+  using namespace std::chrono;
+
+  const bool resolve = true;
+#ifdef _WIN32
+  FileSpec fs1("C:\\FILE\\THAT\\DOES\\NOT\\EXIST.TXT", !resolve);
+#else
+  FileSpec fs1("/file/that/does/not/exist.txt", !resolve);
+#endif
+  FileSpec fs2(TestMainArgv0, resolve);
+
+  EXPECT_EQ(system_clock::time_point(), FileSystem::GetModificationTime(fs1));
+  EXPECT_LT(system_clock::time_point() + hours(24 * 365 * 20),
+FileSystem::GetModificationTime(fs2));
+}
Index: unittests/Host/CMakeLists.txt
===
--- unittests/Host/CMakeLists.txt
+++ unittests/Host/CMakeLists.txt
@@ -1,5 +1,6 @@
 add_lldb_unittest(HostTests
   FileSpecTest.cpp
+  FileSystemTest.cpp
   SocketAddressTest.cpp
   SocketTest.cpp
   SymbolsTest.cpp
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -14,6 +14,7 @@
 #include 
 
 #include "lldb/Core/RangeMap.h"
+#include "lldb/Host/TimeValue.h"
 #include "lldb/Symbol/SymbolFile.h"
 
 #include "UniqueDWARFASTType.h"
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -21,6 +21,7 @@
 #include "lldb/Core/RangeMap.h"
 #include "lldb/Core/RegularExpression.h"
 #include "lldb/Core/Section.h"
+#include "lldb/Host/FileSystem.h"
 
 //#define DEBUG_OSO_DMAP // DO NOT CHECKIN WITH THIS NOT COMMENTED OUT
 #if defined(DEBUG_OSO_DMAP)
@@ -424,7 +425,7 @@
   FileSpec oso_file(oso_path, false);
   ConstString oso_object;
   if (oso_file.Exists()) {
-TimeValue oso_mod_time(oso_file.GetModificationTime());
+TimeValue oso_mod_time(FileSystem::GetModificationTime(oso_file));
 if (oso_mod_time != comp_unit_info->oso_mod_time) {
   obj_file->GetModule()->ReportError(
   "debug map object file '%s' has changed (actual time is "
Index: source/Plugins/Platform/Android/AdbClient.cpp
===
--- source/Plugins/Platform/Android/AdbClient.cpp
+++ source/Plugins/Platform/Android/AdbClient.cpp
@@ -22,6 +22,7 @@
 #include "lldb/Core/StreamString.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
 #include "lldb/Host/FileSpec.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/PosixApi.h"
 
 #include 
@@ -475,8 +476,11 @@
 if (error.Fail())
   return Error("Failed to send file chunk: %s", error.AsCString());
   }