[Lldb-commits] [lldb] r307782 - [MainLoop] Fix possible use of an invalid iterator

2017-07-12 Thread Petr Pavlu via lldb-commits
Author: petr.pavlu
Date: Wed Jul 12 05:38:31 2017
New Revision: 307782

URL: http://llvm.org/viewvc/llvm-project?rev=307782&view=rev
Log:
[MainLoop] Fix possible use of an invalid iterator

Store file descriptors from loop.m_read_fds (if FORCE_PSELECT is
defined) and signals from loop.m_signals that need to be processed in
MainLoop::RunImpl::ProcessEvents() into a separate vector and then
iterate over this container to invoke the callbacks.

This prevents a problem where when the code iterated directly over
m_read_fds/m_signals, a callback invoked from within the loop could
modify these variables and invalidate the loop iterator. This would then
result in an assertion failure in llvm::DenseMapIterator::operator++().

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

Modified:
lldb/trunk/source/Host/common/MainLoop.cpp

Modified: lldb/trunk/source/Host/common/MainLoop.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/MainLoop.cpp?rev=307782&r1=307781&r2=307782&view=diff
==
--- lldb/trunk/source/Host/common/MainLoop.cpp (original)
+++ lldb/trunk/source/Host/common/MainLoop.cpp Wed Jul 12 05:38:31 2017
@@ -193,10 +193,16 @@ Status MainLoop::RunImpl::Poll() {
 
 void MainLoop::RunImpl::ProcessEvents() {
 #ifdef FORCE_PSELECT
-  for (const auto &fd : loop.m_read_fds) {
-if (!FD_ISSET(fd.first, &read_fd_set))
-  continue;
-IOObject::WaitableHandle handle = fd.first;
+  // Collect first all readable file descriptors into a separate vector and 
then
+  // iterate over it to invoke callbacks. Iterating directly over
+  // loop.m_read_fds is not possible because the callbacks can modify the
+  // container which could invalidate the iterator.
+  std::vector fds;
+  for (const auto &fd : loop.m_read_fds)
+if (FD_ISSET(fd.first, &read_fd_set))
+  fds.push_back(fd.first);
+
+  for (const auto &handle : fds) {
 #else
   for (const auto &fd : read_fds) {
 if ((fd.revents & POLLIN) == 0)
@@ -209,13 +215,16 @@ void MainLoop::RunImpl::ProcessEvents()
 loop.ProcessReadObject(handle);
   }
 
-  for (const auto &entry : loop.m_signals) {
+  std::vector signals;
+  for (const auto &entry : loop.m_signals)
+if (g_signal_flags[entry.first] != 0)
+  signals.push_back(entry.first);
+
+  for (const auto &signal : signals) {
 if (loop.m_terminate_request)
   return;
-if (g_signal_flags[entry.first] == 0)
-  continue; // No signal
-g_signal_flags[entry.first] = 0;
-loop.ProcessSignal(entry.first);
+g_signal_flags[signal] = 0;
+loop.ProcessSignal(signal);
   }
 }
 #endif


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


[Lldb-commits] [lldb] r315444 - Fix dumping of characters with non-standard sizes

2017-10-11 Thread Petr Pavlu via lldb-commits
Author: petr.pavlu
Date: Wed Oct 11 01:48:18 2017
New Revision: 315444

URL: http://llvm.org/viewvc/llvm-project?rev=315444&view=rev
Log:
Fix dumping of characters with non-standard sizes

* Prevent dumping of characters in DumpDataExtractor() with
  item_byte_size bigger than 8 bytes. This case is not supported by the
  code and results in a crash because the code calls
  DataExtractor::GetMaxU64Bitfield() -> GetMaxU64() that asserts for
  byte size > 8 bytes.
* Teach DataExtractor::GetMaxU64(), GetMaxU32(), GetMaxS64() and
  GetMaxU64_unchecked() how to handle byte sizes that are not a multiple
  of 2. This allows DumpDataExtractor() to dump characters and booleans
  with item_byte_size in the interval of [1, 8] bytes. Values that are
  not a multiple of 2 would previously result in a crash because they
  were not handled by GetMaxU64().

Modified:
lldb/trunk/include/lldb/Utility/DataExtractor.h
lldb/trunk/source/Core/DumpDataExtractor.cpp
lldb/trunk/source/Utility/DataExtractor.cpp
lldb/trunk/unittests/Core/DataExtractorTest.cpp

Modified: lldb/trunk/include/lldb/Utility/DataExtractor.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/DataExtractor.h?rev=315444&r1=315443&r2=315444&view=diff
==
--- lldb/trunk/include/lldb/Utility/DataExtractor.h (original)
+++ lldb/trunk/include/lldb/Utility/DataExtractor.h Wed Oct 11 01:48:18 2017
@@ -513,10 +513,8 @@ public:
   ///
   /// Extract a single integer value and update the offset pointed to
   /// by \a offset_ptr. The size of the extracted integer is specified
-  /// by the \a byte_size argument. \a byte_size should have a value
-  /// >= 1 and <= 4 since the return value is only 32 bits wide. Any
-  /// \a byte_size values less than 1 or greater than 4 will result in
-  /// nothing being extracted, and zero being returned.
+  /// by the \a byte_size argument. \a byte_size must have a value
+  /// >= 1 and <= 4 since the return value is only 32 bits wide.
   ///
   /// @param[in,out] offset_ptr
   /// A pointer to an offset within the data that will be advanced
@@ -539,11 +537,9 @@ public:
   ///
   /// Extract a single unsigned integer value and update the offset
   /// pointed to by \a offset_ptr. The size of the extracted integer
-  /// is specified by the \a byte_size argument. \a byte_size should
+  /// is specified by the \a byte_size argument. \a byte_size must
   /// have a value greater than or equal to one and less than or equal
-  /// to eight since the return value is 64 bits wide. Any
-  /// \a byte_size values less than 1 or greater than 8 will result in
-  /// nothing being extracted, and zero being returned.
+  /// to eight since the return value is 64 bits wide.
   ///
   /// @param[in,out] offset_ptr
   /// A pointer to an offset within the data that will be advanced
@@ -570,10 +566,9 @@ public:
   /// Extract a single signed integer value (sign extending if required)
   /// and update the offset pointed to by \a offset_ptr. The size of
   /// the extracted integer is specified by the \a byte_size argument.
-  /// \a byte_size should have a value greater than or equal to one
-  /// and less than or equal to eight since the return value is 64
-  /// bits wide. Any \a byte_size values less than 1 or greater than
-  /// 8 will result in nothing being extracted, and zero being returned.
+  /// \a byte_size must have a value greater than or equal to one and
+  /// less than or equal to eight since the return value is 64 bits
+  /// wide.
   ///
   /// @param[in,out] offset_ptr
   /// A pointer to an offset within the data that will be advanced
@@ -589,7 +584,7 @@ public:
   /// The sign extended signed integer value that was extracted,
   /// or zero on failure.
   //--
-  int64_t GetMaxS64(lldb::offset_t *offset_ptr, size_t size) const;
+  int64_t GetMaxS64(lldb::offset_t *offset_ptr, size_t byte_size) const;
 
   //--
   /// Extract an unsigned integer of size \a byte_size from \a
@@ -598,11 +593,9 @@ public:
   ///
   /// Extract a single unsigned integer value and update the offset
   /// pointed to by \a offset_ptr. The size of the extracted integer
-  /// is specified by the \a byte_size argument. \a byte_size should
+  /// is specified by the \a byte_size argument. \a byte_size must
   /// have a value greater than or equal to one and less than or equal
-  /// to 8 since the return value is 64 bits wide. Any
-  /// \a byte_size values less than 1 or greater than 8 will result in
-  /// nothing being extracted, and zero being returned.
+  /// to 8 since the return value is 64 bits wide.
   ///
   /// @param[in,out] offset_ptr
   /// A pointer to an offset within the data that will be advanced
@@ -641,10 +634,9 @@ public:
   /// Extract a single signed integer value (sign ext