[Lldb-commits] [lldb] r265858 - -thread-info in lldbmi does not conform to protocol. Should end with current thread id
Chuck Ries via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 8 15:17:54 PDT 2016
Author: chuckr
Date: Fri Apr 8 17:17:53 2016
New Revision: 265858
URL: http://llvm.org/viewvc/llvm-project?rev=265858&view=rev
Log:
-thread-info in lldbmi does not conform to protocol. Should end with current thread id
-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="0xffffe410",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)
Patch from jacdavis at microsoft.com
Reviewers: zturner, chuckr
Differential Revision: http://reviews.llvm.org/differential/revision/edit/18880/
Added:
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
Modified:
lldb/trunk/tools/lldb-mi/MICmdCmdThread.cpp
lldb/trunk/tools/lldb-mi/MICmdCmdThread.h
Added: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile?rev=265858&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/Makefile Fri Apr 8 17:17:53 2016
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+
+LDFLAGS=-pthread
+
+CXX_SOURCES := test_threadinfo.cpp
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py?rev=265858&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py Fri Apr 8 17:17:53 2016
@@ -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")
+
Added: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp?rev=265858&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/test_threadinfo.cpp Fri Apr 8 17:17:53 2016
@@ -0,0 +1,21 @@
+#include <cstdlib>
+#include <iostream>
+#include <thread>
+
+using namespace std;
+
+void
+ThreadProc()
+{
+ int i = 0;
+ i++;
+}
+
+int
+main()
+{
+ thread t(ThreadProc);
+ t.join();
+
+ return 0;
+}
Modified: lldb/trunk/tools/lldb-mi/MICmdCmdThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdThread.cpp?rev=265858&r1=265857&r2=265858&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdThread.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdThread.cpp Fri Apr 8 17:17:53 2016
@@ -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 @@ CMICmdCmdThreadInfo::Execute()
}
}
+ // -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 @@ CMICmdCmdThreadInfo::Acknowledge()
++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;
Modified: lldb/trunk/tools/lldb-mi/MICmdCmdThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdThread.h?rev=265858&r1=265857&r2=265858&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdThread.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdThread.h Fri Apr 8 17:17:53 2016
@@ -60,4 +60,8 @@ class CMICmdCmdThreadInfo : public CMICm
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;
};
More information about the lldb-commits
mailing list