[Lldb-commits] [PATCH] D18880: -thread-info in lldbmi does not conform to protocol. Should end with current thread id

2016-04-07 Thread Jackson Davis via lldb-commits
jacdavis created this revision.
jacdavis added reviewers: lldb-commits, abidh.

-thread-info in lldbmi does not conform to protocol. Should end with current 
thread id as described here:  
https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Thread-Commands.html#GDB_002fMI-Thread-Commands

When printing all threads, the current thread id should be printed afterwards. 

Example:
-thread-info
 ^done,threads=[
 {id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
frame={level="0",addr="0xe410",func="__kernel_vsyscall",
args=[]},state="running"},
 {id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
frame={level="0",addr="0x0804891f",func="foo",
args=[{name="i",value="10"}],
file="/tmp/a.c",fullname="/tmp/a.c",line="158"},
state="running"}],
 current-thread-id="1"
 (gdb)

http://reviews.llvm.org/D18880

Files:
  packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
  packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
  packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
  tools/lldb-mi/MICmdCmdThread.cpp
  tools/lldb-mi/MICmdCmdThread.h

Index: tools/lldb-mi/MICmdCmdThread.h
===
--- tools/lldb-mi/MICmdCmdThread.h
+++ tools/lldb-mi/MICmdCmdThread.h
@@ -60,4 +60,8 @@
 bool m_bThreadInvalid; // True = invalid, false = ok
 VecMIValueTuple_t m_vecMIValueTuple;
 const CMIUtilString m_constStrArgNamedThreadId;
+
+// mi value of current-thread-id if multiple threads are requested
+bool m_bHasCurrentThread;
+CMICmnMIValue m_miValueCurrThreadId;
 };
Index: tools/lldb-mi/MICmdCmdThread.cpp
===
--- tools/lldb-mi/MICmdCmdThread.cpp
+++ tools/lldb-mi/MICmdCmdThread.cpp
@@ -32,6 +32,7 @@
 : m_bSingleThread(false)
 , m_bThreadInvalid(true)
 , m_constStrArgNamedThreadId("thread-id")
+, m_bHasCurrentThread(false)
 {
 // Command factory matches this name with that received from the stdin stream
 m_strMiCmd = "thread-info";
@@ -123,6 +124,15 @@
 m_vecMIValueTuple.push_back(miTuple);
 }
 }
+
+// -thread-info with multiple threads ends with the current thread id if any
+if (thread.IsValid())
+{
+const CMIUtilString strId(CMIUtilString::Format("%d", thread.GetIndexID()));
+CMICmnMIValueConst miValueCurrThreadId(strId);
+m_miValueCurrThreadId = miValueCurrThreadId;
+m_bHasCurrentThread = true;
+}
 
 return MIstatus::success;
 }
@@ -179,7 +189,12 @@
 ++it;
 }
 
-const CMICmnMIValueResult miValueResult("threads", miValueList);
+CMICmnMIValueResult miValueResult("threads", miValueList);
+if (m_bHasCurrentThread)
+{
+CMIUtilString strCurrThreadId = "current-thread-id";
+miValueResult.Add(strCurrThreadId, m_miValueCurrThreadId);
+}
 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
 m_miResultRecord = miRecordResult;
 
Index: packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
===
--- packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
+++ packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
@@ -0,0 +1,19 @@
+#include 
+#include 
+#include 
+
+
+void* ThreadProc(void* arg)
+{
+int i = 0;
+i++; 
+return NULL;
+}
+
+int main()
+{
+pthread_t thread;
+pthread_create(&thread, NULL, ThreadProc, NULL);
+pthread_join(thread, NULL);
+return 0;
+}
Index: packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
===
--- packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
+++ packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
@@ -0,0 +1,39 @@
+"""
+Test lldb-mi -thread-info command.
+"""
+
+from __future__ import print_function
+
+import lldbmi_testcase
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class MiThreadInfoTestCase(lldbmi_testcase.MiTestCaseBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipIfWindows # pthreads not supported on Windows
+@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+def test_lldbmi_thread_info(self):
+"""Test that -thread-info prints thread info and the current-thread-id"""
+
+self.spawnLldbMi(args = None)
+
+# Load executable
+self.runCmd("-file-exec-and-symbols %s" % self.myexe)
+self.expect("\^done")
+
+self.runCmd("-break-insert ThreadProc")
+self.expect("\^done")
+
+# Run to the breakpoint
+

Re: [Lldb-commits] [PATCH] D18880: -thread-info in lldbmi does not conform to protocol. Should end with current thread id

2016-04-07 Thread Jackson Davis via lldb-commits
jacdavis updated this revision to Diff 52991.
jacdavis added a comment.

Updated to use C++ 11 threads. Clang-format tried to format the diff in the 
llvm style. Since this is all lldb code, is that actually what is expected? 
None of the braces matched etc


http://reviews.llvm.org/D18880

Files:
  packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
  packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
  packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
  tools/lldb-mi/MICmdCmdThread.cpp
  tools/lldb-mi/MICmdCmdThread.h

Index: tools/lldb-mi/MICmdCmdThread.h
===
--- tools/lldb-mi/MICmdCmdThread.h
+++ tools/lldb-mi/MICmdCmdThread.h
@@ -60,4 +60,8 @@
 bool m_bThreadInvalid; // True = invalid, false = ok
 VecMIValueTuple_t m_vecMIValueTuple;
 const CMIUtilString m_constStrArgNamedThreadId;
+
+// mi value of current-thread-id if multiple threads are requested
+bool m_bHasCurrentThread;
+CMICmnMIValue m_miValueCurrThreadId;
 };
Index: tools/lldb-mi/MICmdCmdThread.cpp
===
--- tools/lldb-mi/MICmdCmdThread.cpp
+++ tools/lldb-mi/MICmdCmdThread.cpp
@@ -29,9 +29,10 @@
 // Throws:  None.
 //--
 CMICmdCmdThreadInfo::CMICmdCmdThreadInfo()
-: m_bSingleThread(false)
-, m_bThreadInvalid(true)
-, m_constStrArgNamedThreadId("thread-id")
+: m_bSingleThread(false),
+  m_bThreadInvalid(true),
+  m_constStrArgNamedThreadId("thread-id"),
+  m_bHasCurrentThread(false)
 {
 // Command factory matches this name with that received from the stdin stream
 m_strMiCmd = "thread-info";
@@ -124,6 +125,15 @@
 }
 }
 
+// -thread-info with multiple threads ends with the current thread id if any
+if (thread.IsValid())
+{
+const CMIUtilString strId(CMIUtilString::Format("%d", thread.GetIndexID()));
+CMICmnMIValueConst miValueCurrThreadId(strId);
+m_miValueCurrThreadId = miValueCurrThreadId;
+m_bHasCurrentThread = true;
+}
+
 return MIstatus::success;
 }
 
@@ -179,7 +189,12 @@
 ++it;
 }
 
-const CMICmnMIValueResult miValueResult("threads", miValueList);
+CMICmnMIValueResult miValueResult("threads", miValueList);
+if (m_bHasCurrentThread)
+{
+CMIUtilString strCurrThreadId = "current-thread-id";
+miValueResult.Add(strCurrThreadId, m_miValueCurrThreadId);
+}
 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
 m_miResultRecord = miRecordResult;
 
Index: packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
===
--- packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
+++ packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
@@ -0,0 +1,21 @@
+#include 
+#include 
+#include 
+
+using namespace std;
+
+void
+ThreadProc()
+{
+int i = 0;
+i++;
+}
+
+int
+main()
+{
+thread t(ThreadProc);
+t.join();
+
+return 0;
+}
Index: packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
===
--- packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
+++ packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
@@ -0,0 +1,38 @@
+"""
+Test lldb-mi -thread-info command.
+"""
+
+from __future__ import print_function
+
+import lldbmi_testcase
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class MiThreadInfoTestCase(lldbmi_testcase.MiTestCaseBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+def test_lldbmi_thread_info(self):
+"""Test that -thread-info prints thread info and the current-thread-id"""
+
+self.spawnLldbMi(args = None)
+
+# Load executable
+self.runCmd("-file-exec-and-symbols %s" % self.myexe)
+self.expect("\^done")
+
+self.runCmd("-break-insert ThreadProc")
+self.expect("\^done")
+
+# Run to the breakpoint
+self.runCmd("-exec-run")
+self.expect("\^running")
+self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+self.runCmd("-thread-info")
+self.expect("\^done,threads=\[\{id=\"1\",(.*)\},\{id=\"2\",(.*)\],current-thread-id=\"2\"")
+
+self.runCmd("-gdb-quit")
+   
Index: packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
===
--- packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
+++ packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+

Re: [Lldb-commits] [PATCH] D18880: -thread-info in lldbmi does not conform to protocol. Should end with current thread id

2016-04-07 Thread Jackson Davis via lldb-commits
Great, thanks. I'll rerun in the morning. I realized I also left the pthread 
linker option on in the test.

Sent from my Windows Phone

From: Zachary Turner
Sent: ‎4/‎7/‎2016 6:21 PM
To: Jackson Davis; 
lldb-commits@lists.llvm.org; 
abidh@gmail.com
Cc: ztur...@google.com
Subject: Re: [PATCH] D18880: -thread-info in lldbmi does not conform to 
protocol. Should end with current thread id

zturner added a comment.

We have an lldb style file in llvm/tools/lldb, it should be picked up
automatically if you run it from the lldb directory. I'm not sure though if
it's based on the folder you're in when you run clang-format or by
searching up the tree from the target file until it finds a rule file


https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2freviews.llvm.org%2fD18880&data=01%7c01%7cJackson.Davis%40microsoft.com%7c27e96005c36b4333193508d35f4c11da%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=tEFmBcNdo%2b%2blWJ%2fjC7kUZ6%2b5EKY2txGgt6cAZLwX4Js%3d



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


Re: [Lldb-commits] [PATCH] D18880: -thread-info in lldbmi does not conform to protocol. Should end with current thread id

2016-04-08 Thread Jackson Davis via lldb-commits
jacdavis updated this revision to Diff 53028.
jacdavis added a comment.

Ran formatting tool with lldb format. pthread linker option is still required 
for C++11 threads so left it in. New test still disabled for windows.


http://reviews.llvm.org/D18880

Files:
  Makefile
  TestMiThreadInfo.py
  test_threadinfo.cpp

Index: test_threadinfo.cpp
===
--- test_threadinfo.cpp
+++ test_threadinfo.cpp
@@ -0,0 +1,21 @@
+#include 
+#include 
+#include 
+
+using namespace std;
+
+void
+ThreadProc()
+{
+int i = 0;
+i++;
+}
+
+int
+main()
+{
+thread t(ThreadProc);
+t.join();
+
+return 0;
+}
Index: TestMiThreadInfo.py
===
--- TestMiThreadInfo.py
+++ TestMiThreadInfo.py
@@ -0,0 +1,39 @@
+"""
+Test lldb-mi -thread-info command.
+"""
+
+from __future__ import print_function
+
+import lldbmi_testcase
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class MiThreadInfoTestCase(lldbmi_testcase.MiTestCaseBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipIfWindows # pthreads not supported on Windows
+@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread 
races
+def test_lldbmi_thread_info(self):
+"""Test that -thread-info prints thread info and the 
current-thread-id"""
+
+self.spawnLldbMi(args = None)
+
+# Load executable
+self.runCmd("-file-exec-and-symbols %s" % self.myexe)
+self.expect("\^done")
+
+self.runCmd("-break-insert ThreadProc")
+self.expect("\^done")
+
+# Run to the breakpoint
+self.runCmd("-exec-run")
+self.expect("\^running")
+self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+self.runCmd("-thread-info")
+
self.expect("\^done,threads=\[\{id=\"1\",(.*)\},\{id=\"2\",(.*)\],current-thread-id=\"2\"")
+
+self.runCmd("-gdb-quit")
+   
Index: Makefile
===
--- Makefile
+++ Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+
+LDFLAGS=-pthread
+
+CXX_SOURCES := test_threadinfo.cpp
+
+include $(LEVEL)/Makefile.rules


Index: test_threadinfo.cpp
===
--- test_threadinfo.cpp
+++ test_threadinfo.cpp
@@ -0,0 +1,21 @@
+#include 
+#include 
+#include 
+
+using namespace std;
+
+void
+ThreadProc()
+{
+int i = 0;
+i++;
+}
+
+int
+main()
+{
+thread t(ThreadProc);
+t.join();
+
+return 0;
+}
Index: TestMiThreadInfo.py
===
--- TestMiThreadInfo.py
+++ TestMiThreadInfo.py
@@ -0,0 +1,39 @@
+"""
+Test lldb-mi -thread-info command.
+"""
+
+from __future__ import print_function
+
+import lldbmi_testcase
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class MiThreadInfoTestCase(lldbmi_testcase.MiTestCaseBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipIfWindows # pthreads not supported on Windows
+@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+def test_lldbmi_thread_info(self):
+"""Test that -thread-info prints thread info and the current-thread-id"""
+
+self.spawnLldbMi(args = None)
+
+# Load executable
+self.runCmd("-file-exec-and-symbols %s" % self.myexe)
+self.expect("\^done")
+
+self.runCmd("-break-insert ThreadProc")
+self.expect("\^done")
+
+# Run to the breakpoint
+self.runCmd("-exec-run")
+self.expect("\^running")
+self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+self.runCmd("-thread-info")
+self.expect("\^done,threads=\[\{id=\"1\",(.*)\},\{id=\"2\",(.*)\],current-thread-id=\"2\"")
+
+self.runCmd("-gdb-quit")
+   
Index: Makefile
===
--- Makefile
+++ Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+
+LDFLAGS=-pthread
+
+CXX_SOURCES := test_threadinfo.cpp
+
+include $(LEVEL)/Makefile.rules
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


Re: [Lldb-commits] [PATCH] D18880: -thread-info in lldbmi does not conform to protocol. Should end with current thread id

2016-04-08 Thread Jackson Davis via lldb-commits
jacdavis updated this revision to Diff 53031.
jacdavis added a comment.

last diff missed lldb-mi changes


http://reviews.llvm.org/D18880

Files:
  packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
  packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
  packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
  tools/lldb-mi/MICmdCmdThread.cpp
  tools/lldb-mi/MICmdCmdThread.h

Index: tools/lldb-mi/MICmdCmdThread.h
===
--- tools/lldb-mi/MICmdCmdThread.h
+++ tools/lldb-mi/MICmdCmdThread.h
@@ -60,4 +60,8 @@
 bool m_bThreadInvalid; // True = invalid, false = ok
 VecMIValueTuple_t m_vecMIValueTuple;
 const CMIUtilString m_constStrArgNamedThreadId;
+
+// mi value of current-thread-id if multiple threads are requested
+bool m_bHasCurrentThread;
+CMICmnMIValue m_miValueCurrThreadId;
 };
Index: tools/lldb-mi/MICmdCmdThread.cpp
===
--- tools/lldb-mi/MICmdCmdThread.cpp
+++ tools/lldb-mi/MICmdCmdThread.cpp
@@ -29,9 +29,10 @@
 // Throws:  None.
 //--
 CMICmdCmdThreadInfo::CMICmdCmdThreadInfo()
-: m_bSingleThread(false)
-, m_bThreadInvalid(true)
-, m_constStrArgNamedThreadId("thread-id")
+: m_bSingleThread(false),
+  m_bThreadInvalid(true),
+  m_constStrArgNamedThreadId("thread-id"),
+  m_bHasCurrentThread(false)
 {
 // Command factory matches this name with that received from the stdin stream
 m_strMiCmd = "thread-info";
@@ -124,6 +125,15 @@
 }
 }
 
+// -thread-info with multiple threads ends with the current thread id if any
+if (thread.IsValid())
+{
+const CMIUtilString strId(CMIUtilString::Format("%d", thread.GetIndexID()));
+CMICmnMIValueConst miValueCurrThreadId(strId);
+m_miValueCurrThreadId = miValueCurrThreadId;
+m_bHasCurrentThread = true;
+}
+
 return MIstatus::success;
 }
 
@@ -179,7 +189,12 @@
 ++it;
 }
 
-const CMICmnMIValueResult miValueResult("threads", miValueList);
+CMICmnMIValueResult miValueResult("threads", miValueList);
+if (m_bHasCurrentThread)
+{
+CMIUtilString strCurrThreadId = "current-thread-id";
+miValueResult.Add(strCurrThreadId, m_miValueCurrThreadId);
+}
 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
 m_miResultRecord = miRecordResult;
 
Index: packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
===
--- packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
+++ packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
@@ -0,0 +1,21 @@
+#include 
+#include 
+#include 
+
+using namespace std;
+
+void
+ThreadProc()
+{
+int i = 0;
+i++;
+}
+
+int
+main()
+{
+thread t(ThreadProc);
+t.join();
+
+return 0;
+}
Index: packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
===
--- packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
+++ packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
@@ -0,0 +1,39 @@
+"""
+Test lldb-mi -thread-info command.
+"""
+
+from __future__ import print_function
+
+import lldbmi_testcase
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class MiThreadInfoTestCase(lldbmi_testcase.MiTestCaseBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipIfWindows # pthreads not supported on Windows
+@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+def test_lldbmi_thread_info(self):
+"""Test that -thread-info prints thread info and the current-thread-id"""
+
+self.spawnLldbMi(args = None)
+
+# Load executable
+self.runCmd("-file-exec-and-symbols %s" % self.myexe)
+self.expect("\^done")
+
+self.runCmd("-break-insert ThreadProc")
+self.expect("\^done")
+
+# Run to the breakpoint
+self.runCmd("-exec-run")
+self.expect("\^running")
+self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+self.runCmd("-thread-info")
+self.expect("\^done,threads=\[\{id=\"1\",(.*)\},\{id=\"2\",(.*)\],current-thread-id=\"2\"")
+
+self.runCmd("-gdb-quit")
+   
Index: packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
===
--- packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
+++ packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+
+LDFLAGS=-pthread
+
+CXX_SOURCES := test_threadinfo.cpp
+
+include $(LEVEL)/Makefile.rules
_