[Lldb-commits] [lldb] r295694 - Fix spelling mistake.

2017-02-20 Thread Jason Molenda via lldb-commits
Author: jmolenda
Date: Mon Feb 20 23:09:26 2017
New Revision: 295694

URL: http://llvm.org/viewvc/llvm-project?rev=295694=rev
Log:
Fix spelling mistake.

Modified:
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp

Modified: 
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp?rev=295694=295693=295694=diff
==
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp 
(original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp 
Mon Feb 20 23:09:26 2017
@@ -609,7 +609,7 @@ bool ClangUserExpression::AddArguments(E
 
 if (!object_ptr_error.Success()) {
   exe_ctx.GetTargetRef().GetDebugger().GetAsyncOutputStream()->Printf(
-  "warning: `%s' is not accessible (subsituting 0)\n",
+  "warning: `%s' is not accessible (substituting 0)\n",
   object_name.AsCString());
   object_ptr = 0;
 }


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


[Lldb-commits] [PATCH] D29669: Hardware breakpoints implementation for Arm/AArch64 targets

2017-02-20 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

LGTM, but Pavel should give the ok as well.


https://reviews.llvm.org/D29669



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


[Lldb-commits] [PATCH] D27126: Merge Linux and FreeBSD arm register contexts

2017-02-20 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

Just found this lying on the bottom of my stack. Ed, if you don't object, I'd 
like to check in it. I think it is quite a safe change, so we probably don't 
need to do too much testing.


https://reviews.llvm.org/D27126



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


[Lldb-commits] [PATCH] D30172: Replace WINLOG_*** macros with LLDB_LOG

2017-02-20 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.

The main difference here is that in the WINLOG macros you can specify
log categories per call, whereas here you have to go the usual lldb
route of getting a Log* variable first. While this means you have to
write at least two statements, it usually means that each statement will
fit on a single line, whereas fitting the WINLOG invocation on a single
line was almost impossible. So the total size of code does not increase
even in functions with a single log statement, and functions with more
logging get shorter.

The downside here is reduced flexibility in specifying the log
categories, which a couple of functions used quite heavily (e.g.
RefreshStateAfterStop). For these I chose a single category used most
prominently and put everything into that, although a solution with
multiple log variables is definitely possible.


https://reviews.llvm.org/D30172

Files:
  source/Plugins/Process/Windows/Common/DebuggerThread.cpp
  source/Plugins/Process/Windows/Common/ProcessWindows.cpp
  source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp
  source/Plugins/Process/Windows/Common/ProcessWindowsLog.h
  source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp
  source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp

Index: source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp
===
--- source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp
+++ source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp
@@ -203,7 +203,8 @@
 return ReadRegisterHelper(CONTEXT_CONTROL, "EFLAGS", m_context.EFlags,
   reg_value);
   default:
-WINWARN_IFALL(WINDOWS_LOG_REGISTERS, "Requested unknown register %u", reg);
+Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
+LLDB_LOG(log, "Requested unknown register {0}", reg);
 break;
   }
   return false;
@@ -219,62 +220,52 @@
   if (!CacheAllRegisterValues())
 return false;
 
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
   uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
   switch (reg) {
   case lldb_eax_i386:
-WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EAX",
- reg_value.GetAsUInt32());
+LLDB_LOG(log, "Write value {0:x} to EAX", reg_value.GetAsUInt32());
 m_context.Eax = reg_value.GetAsUInt32();
 break;
   case lldb_ebx_i386:
-WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EBX",
- reg_value.GetAsUInt32());
+LLDB_LOG(log, "Write value {0:x} to EBX", reg_value.GetAsUInt32());
 m_context.Ebx = reg_value.GetAsUInt32();
 break;
   case lldb_ecx_i386:
-WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ECX",
- reg_value.GetAsUInt32());
+LLDB_LOG(log, "Write value {0:x} to ECX", reg_value.GetAsUInt32());
 m_context.Ecx = reg_value.GetAsUInt32();
 break;
   case lldb_edx_i386:
-WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EDX",
- reg_value.GetAsUInt32());
+LLDB_LOG(log, "Write value {0:x} to EDX", reg_value.GetAsUInt32());
 m_context.Edx = reg_value.GetAsUInt32();
 break;
   case lldb_edi_i386:
-WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EDI",
- reg_value.GetAsUInt32());
+LLDB_LOG(log, "Write value {0:x} to EDI", reg_value.GetAsUInt32());
 m_context.Edi = reg_value.GetAsUInt32();
 break;
   case lldb_esi_i386:
-WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ESI",
- reg_value.GetAsUInt32());
+LLDB_LOG(log, "Write value {0:x} to ESI", reg_value.GetAsUInt32());
 m_context.Esi = reg_value.GetAsUInt32();
 break;
   case lldb_ebp_i386:
-WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EBP",
- reg_value.GetAsUInt32());
+LLDB_LOG(log, "Write value {0:x} to EBP", reg_value.GetAsUInt32());
 m_context.Ebp = reg_value.GetAsUInt32();
 break;
   case lldb_esp_i386:
-WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ESP",
- reg_value.GetAsUInt32());
+LLDB_LOG(log, "Write value {0:x} to ESP", reg_value.GetAsUInt32());
 m_context.Esp = reg_value.GetAsUInt32();
 break;
   case lldb_eip_i386:
-WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EIP",
- reg_value.GetAsUInt32());
+LLDB_LOG(log, "Write value {0:x} to EIP", reg_value.GetAsUInt32());
 m_context.Eip = reg_value.GetAsUInt32();
 break;
   case lldb_eflags_i386:
-WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EFLAGS",
- reg_value.GetAsUInt32());
+LLDB_LOG(log, "Write value {0:x} to EFLAGS", reg_value.GetAsUInt32());
 m_context.EFlags = reg_value.GetAsUInt32();
 break;
   default:
-WINWARN_IFALL(WINDOWS_LOG_REGISTERS,
-  "Write value 0x%x to unknown register %u",
- 

[Lldb-commits] [PATCH] D30168: Log: Fix race in accessing the stream variable

2017-02-20 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.

The code was attempting to copy the shared pointer member in order to
guarantee atomicity, but this is not enough. Instead, protect the
pointer with a proper read-write mutex.

This bug was present here for a long time, but my recent refactors must
have altered the timings slightly, such that now this fails fairly often
when running the tests: the test runner runs the "log disable" command
just as the thread monitoring the lldb-server child is about to report
that the server has exited.

I add a test case for this. It's not possible to reproduce the race
deterministically in normal circumstances, but I have verified that
before the fix, the test failed when run under tsan, and was running
fine afterwards.


https://reviews.llvm.org/D30168

Files:
  include/lldb/Core/Log.h
  source/Core/Log.cpp
  unittests/Core/LogTest.cpp


Index: unittests/Core/LogTest.cpp
===
--- unittests/Core/LogTest.cpp
+++ unittests/Core/LogTest.cpp
@@ -13,6 +13,7 @@
 #include "lldb/Host/Host.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/Support/ManagedStatic.h"
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
@@ -26,6 +27,8 @@
 static Log::Channel test_channel(test_categories, default_flags);
 
 struct LogChannelTest : public ::testing::Test {
+  void TearDown() override { Log::DisableAllLogChannels(nullptr); }
+
   static void SetUpTestCase() {
 Log::Register("chan", test_channel);
   }
@@ -170,3 +173,26 @@
   EXPECT_FALSE(Log::ListChannelCategories("chanchan", str));
   EXPECT_EQ("Invalid log channel 'chanchan'.\n", str.GetString().str());
 }
+
+TEST_F(LogChannelTest, LogThread) {
+  // Test that we are able to concurrently write to a log channel and disable
+  // it.
+  std::string message;
+  std::shared_ptr stream_sp(
+  new llvm::raw_string_ostream(message));
+  StreamString err;
+  EXPECT_TRUE(Log::EnableLogChannel(stream_sp, 0, "chan", nullptr, err));
+
+  Log *log = test_channel.GetLogIfAll(FOO);
+
+  // Start logging on one thread. Concurrently, try disabling the log channel.
+  std::thread log_thread([log] { LLDB_LOG(log, "Hello World"); });
+  EXPECT_TRUE(Log::DisableLogChannel("chan", nullptr, err));
+  log_thread.join();
+
+  // The log thread either managed to write to the log in time, or it didn't. 
In
+  // either case, we should not trip any undefined behavior (run the test under
+  // TSAN to verify this).
+  EXPECT_TRUE(stream_sp->str() == "" || stream_sp->str() == "Hello World\n")
+  << "str(): " << stream_sp->str();
+}
Index: source/Core/Log.cpp
===
--- source/Core/Log.cpp
+++ source/Core/Log.cpp
@@ -400,7 +400,7 @@
 void Log::WriteMessage(const std::string ) {
   // Make a copy of our stream shared pointer in case someone disables our
   // log while we are logging and releases the stream
-  auto stream_sp = m_stream_sp;
+  auto stream_sp = GetStream();
   if (!stream_sp)
 return;
 
Index: include/lldb/Core/Log.h
===
--- include/lldb/Core/Log.h
+++ include/lldb/Core/Log.h
@@ -18,6 +18,7 @@
 
 // Other libraries and framework includes
 #include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/RWMutex.h"
 // C++ Includes
 #include 
 #include 
@@ -184,14 +185,22 @@
   bool GetVerbose() const;
 
   void SetStream(const std::shared_ptr _sp) {
+llvm::sys::ScopedWriter lock(m_stream_mutex);
 m_stream_sp = stream_sp;
   }
 
+  std::shared_ptr GetStream() {
+llvm::sys::ScopedReader lock(m_stream_mutex);
+return m_stream_sp;
+  }
+
 protected:
   //--
   // Member variables
   //--
+  llvm::sys::RWMutex m_stream_mutex; // Protects m_stream_sp
   std::shared_ptr m_stream_sp;
+
   Flags m_options;
   Flags m_mask_bits;
 


Index: unittests/Core/LogTest.cpp
===
--- unittests/Core/LogTest.cpp
+++ unittests/Core/LogTest.cpp
@@ -13,6 +13,7 @@
 #include "lldb/Host/Host.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/Support/ManagedStatic.h"
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
@@ -26,6 +27,8 @@
 static Log::Channel test_channel(test_categories, default_flags);
 
 struct LogChannelTest : public ::testing::Test {
+  void TearDown() override { Log::DisableAllLogChannels(nullptr); }
+
   static void SetUpTestCase() {
 Log::Register("chan", test_channel);
   }
@@ -170,3 +173,26 @@
   EXPECT_FALSE(Log::ListChannelCategories("chanchan", str));
   EXPECT_EQ("Invalid log channel 'chanchan'.\n", str.GetString().str());
 }
+
+TEST_F(LogChannelTest, LogThread) {
+  // Test that we are able to concurrently write to a log channel and disable
+  // it.
+  std::string message;
+  std::shared_ptr stream_sp(
+  new 

[Lldb-commits] [PATCH] D30094: Fix a couple of corner cases in NameMatches

2017-02-20 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL295651: Fix a couple of corner cases in NameMatches 
(authored by labath).

Changed prior to commit:
  https://reviews.llvm.org/D30094?vs=5=89102#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30094

Files:
  lldb/trunk/include/lldb/Target/Process.h
  lldb/trunk/include/lldb/Utility/NameMatches.h
  lldb/trunk/include/lldb/lldb-private-enumerations.h
  lldb/trunk/source/Commands/CommandObjectPlatform.cpp
  lldb/trunk/source/Commands/CommandObjectProcess.cpp
  lldb/trunk/source/Core/ArchSpec.cpp
  lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/trunk/source/Target/Process.cpp
  lldb/trunk/source/Utility/NameMatches.cpp
  lldb/trunk/source/Utility/RegularExpression.cpp
  lldb/trunk/unittests/Utility/CMakeLists.txt
  lldb/trunk/unittests/Utility/NameMatchesTest.cpp

Index: lldb/trunk/unittests/Utility/NameMatchesTest.cpp
===
--- lldb/trunk/unittests/Utility/NameMatchesTest.cpp
+++ lldb/trunk/unittests/Utility/NameMatchesTest.cpp
@@ -0,0 +1,58 @@
+//===-- NameMatchesTest.cpp -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "lldb/Utility/NameMatches.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+
+TEST(NameMatchesTest, Ignore) {
+  EXPECT_TRUE(NameMatches("foo", NameMatch::Ignore, "bar"));
+}
+
+TEST(NameMatchesTest, Equals) {
+  EXPECT_TRUE(NameMatches("foo", NameMatch::Equals, "foo"));
+  EXPECT_FALSE(NameMatches("foo", NameMatch::Equals, "bar"));
+}
+
+TEST(NameMatchesTest, Contains) {
+  EXPECT_TRUE(NameMatches("foobar", NameMatch::Contains, "foo"));
+  EXPECT_TRUE(NameMatches("foobar", NameMatch::Contains, "oob"));
+  EXPECT_TRUE(NameMatches("foobar", NameMatch::Contains, "bar"));
+  EXPECT_TRUE(NameMatches("foobar", NameMatch::Contains, "foobar"));
+  EXPECT_TRUE(NameMatches("", NameMatch::Contains, ""));
+  EXPECT_FALSE(NameMatches("", NameMatch::Contains, "foo"));
+  EXPECT_FALSE(NameMatches("foobar", NameMatch::Contains, "baz"));
+}
+
+TEST(NameMatchesTest, StartsWith) {
+  EXPECT_TRUE(NameMatches("foo", NameMatch::StartsWith, "f"));
+  EXPECT_TRUE(NameMatches("foo", NameMatch::StartsWith, ""));
+  EXPECT_TRUE(NameMatches("", NameMatch::StartsWith, ""));
+  EXPECT_FALSE(NameMatches("foo", NameMatch::StartsWith, "b"));
+  EXPECT_FALSE(NameMatches("", NameMatch::StartsWith, "b"));
+}
+
+TEST(NameMatchesTest, EndsWith) {
+  EXPECT_TRUE(NameMatches("foo", NameMatch::EndsWith, "o"));
+  EXPECT_TRUE(NameMatches("foo", NameMatch::EndsWith, ""));
+  EXPECT_TRUE(NameMatches("", NameMatch::EndsWith, ""));
+  EXPECT_FALSE(NameMatches("foo", NameMatch::EndsWith, "b"));
+  EXPECT_FALSE(NameMatches("", NameMatch::EndsWith, "b"));
+}
+
+TEST(NameMatchesTest, RegularExpression) {
+  EXPECT_TRUE(NameMatches("foobar", NameMatch::RegularExpression, "foo"));
+  EXPECT_TRUE(NameMatches("foobar", NameMatch::RegularExpression, "f[oa]o"));
+  EXPECT_TRUE(NameMatches("foo", NameMatch::RegularExpression, ""));
+  EXPECT_TRUE(NameMatches("", NameMatch::RegularExpression, ""));
+  EXPECT_FALSE(NameMatches("foo", NameMatch::RegularExpression, "b"));
+  EXPECT_FALSE(NameMatches("", NameMatch::RegularExpression, "b"));
+  EXPECT_FALSE(NameMatches("^a", NameMatch::RegularExpression, "^a"));
+}
Index: lldb/trunk/unittests/Utility/CMakeLists.txt
===
--- lldb/trunk/unittests/Utility/CMakeLists.txt
+++ lldb/trunk/unittests/Utility/CMakeLists.txt
@@ -1,6 +1,7 @@
 add_lldb_unittest(UtilityTests
   ConstStringTest.cpp
   ErrorTest.cpp
+  NameMatchesTest.cpp
   StringExtractorTest.cpp
   TaskPoolTest.cpp
   TimeoutTest.cpp
Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -360,16 +360,15 @@
 extractor.GetHexByteString(file);
 match_info.GetProcessInfo().GetExecutableFile().SetFile(file, false);
   } else if (key.equals("name_match")) {
-NameMatchType name_match =
-llvm::StringSwitch(value)
-.Case("equals", eNameMatchEquals)
-.Case("starts_with", eNameMatchStartsWith)
-.Case("ends_with", eNameMatchEndsWith)
-.Case("contains", eNameMatchContains)
-.Case("regex", eNameMatchRegularExpression)
-