<div dir="ltr">Thank you Abid!</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 8, 2014 at 9:07 PM, Hafiz Abid Qadeer <span dir="ltr"><<a href="mailto:hafiz_abid@mentor.com" target="_blank">hafiz_abid@mentor.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: abidh<br>
Date: Mon Dec 8 12:07:40 2014<br>
New Revision: 223674<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=223674&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=223674&view=rev</a><br>
Log:<br>
Fix a bug where global variable can be reported as local.<br>
<br>
There was an error in ORing mask which is used for getting a list of variables.<br>
Previously, these constants were unnamed, and possible it become the reason of this<br>
bug. Also added test case for -stack-list-local and -stack-list_arguments.<br>
<br>
Patch from Ilia K <<a href="mailto:ki.stfu@gmail.com">ki.stfu@gmail.com</a>>.<br>
<br>
Added:<br>
lldb/trunk/test/tools/lldb-mi/TestMiStack.py<br>
Modified:<br>
lldb/trunk/test/tools/lldb-mi/main.c<br>
lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp<br>
lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp<br>
lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h<br>
lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp<br>
<br>
Added: lldb/trunk/test/tools/lldb-mi/TestMiStack.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/TestMiStack.py?rev=223674&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/TestMiStack.py?rev=223674&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/test/tools/lldb-mi/TestMiStack.py (added)<br>
+++ lldb/trunk/test/tools/lldb-mi/TestMiStack.py Mon Dec 8 12:07:40 2014<br>
@@ -0,0 +1,122 @@<br>
+"""<br>
+Test that the lldb-mi driver works with -stack-xxx commands<br>
+"""<br>
+<br>
+import os<br>
+import unittest2<br>
+import lldb<br>
+from lldbtest import *<br>
+<br>
+class MiStackTestCase(TestBase):<br>
+<br>
+ mydir = TestBase.compute_mydir(__file__)<br>
+ myexe = "a.out"<br>
+<br>
+ @classmethod<br>
+ def classCleanup(cls):<br>
+ """Cleanup the test byproducts."""<br>
+ try:<br>
+ os.remove("child_send.txt")<br>
+ os.remove("child_read.txt")<br>
+ os.remove(cls.myexe)<br>
+ except:<br>
+ pass<br>
+<br>
+ @lldbmi_test<br>
+ def test_lldbmi_stackargs(self):<br>
+ """Test that 'lldb-mi --interpreter' can shows arguments."""<br>
+ import pexpect<br>
+ self.buildDefault()<br>
+<br>
+ # So that the child gets torn down after the test.<br>
+ self.child = pexpect.spawn('%s --interpreter' % (self.lldbMiExec))<br>
+ child = self.child<br>
+ child.setecho(True)<br>
+ # Turn on logging for input/output to/from the child.<br>
+ with open('child_send.txt', 'w') as f_send:<br>
+ with open('child_read.txt', 'w') as f_read:<br>
+ child.logfile_send = f_send<br>
+ child.logfile_read = f_read<br>
+<br>
+ # Load executable<br>
+ child.sendline("-file-exec-and-symbols %s" % (self.myexe))<br>
+ child.expect("\^done")<br>
+<br>
+ # Run to main<br>
+ child.sendline("-break-insert -f main")<br>
+ child.expect("\^done,bkpt={number=\"1\"")<br>
+ child.sendline("-exec-run")<br>
+ child.expect("\^running")<br>
+ child.expect("\*stopped,reason=\"breakpoint-hit\"")<br>
+<br>
+ # Test arguments<br>
+ child.sendline("-stack-list-arguments 0")<br>
+ child.expect("\^done,stack-args=\[frame={level=\"0\",args=\[{name=\"argc\",value=\"1\"},{name=\"argv\",value=\".*\"}\]}")<br>
+<br>
+ # Now that the necessary logging is done, restore logfile to None to<br>
+ # stop further logging.<br>
+ child.logfile_send = None<br>
+ child.logfile_read = None<br>
+<br>
+ with open('child_send.txt', 'r') as fs:<br>
+ if self.TraceOn():<br>
+ print "\n\nContents of child_send.txt:"<br>
+ print fs.read()<br>
+ with open('child_read.txt', 'r') as fr:<br>
+ from_child = fr.read()<br>
+ if self.TraceOn():<br>
+ print "\n\nContents of child_read.txt:"<br>
+ print from_child<br>
+<br>
+ @lldbmi_test<br>
+ def test_lldbmi_locals(self):<br>
+ """Test that 'lldb-mi --interpreter' can shows local variables."""<br>
+ import pexpect<br>
+ self.buildDefault()<br>
+<br>
+ # So that the child gets torn down after the test.<br>
+ self.child = pexpect.spawn('%s --interpreter' % (self.lldbMiExec))<br>
+ child = self.child<br>
+ child.setecho(True)<br>
+ # Turn on logging for input/output to/from the child.<br>
+ with open('child_send.txt', 'w') as f_send:<br>
+ with open('child_read.txt', 'w') as f_read:<br>
+ child.logfile_send = f_send<br>
+ child.logfile_read = f_read<br>
+<br>
+ # Load executable<br>
+ child.sendline("-file-exec-and-symbols %s" % (self.myexe))<br>
+ child.expect("\^done")<br>
+<br>
+ # Run to main<br>
+ self.line = line_number('main.c', '//BP_localstest')<br>
+ child.sendline("-break-insert --file main.c:%d" % (self.line))<br>
+ child.expect("\^done,bkpt={number=\"1\"")<br>
+ child.sendline("-exec-run")<br>
+ child.expect("\^running")<br>
+ child.expect("\*stopped,reason=\"breakpoint-hit\"")<br>
+<br>
+ # Test locals<br>
+ child.sendline("-stack-list-locals 0")<br>
+ child.expect("\^done,locals=\[{name=\"a\",value=\"10\"},{name=\"b\",value=\"20\"}\]")<br>
+<br>
+ # Now that the necessary logging is done, restore logfile to None to<br>
+ # stop further logging.<br>
+ child.logfile_send = None<br>
+ child.logfile_read = None<br>
+<br>
+ with open('child_send.txt', 'r') as fs:<br>
+ if self.TraceOn():<br>
+ print "\n\nContents of child_send.txt:"<br>
+ print fs.read()<br>
+ with open('child_read.txt', 'r') as fr:<br>
+ from_child = fr.read()<br>
+ if self.TraceOn():<br>
+ print "\n\nContents of child_read.txt:"<br>
+ print from_child<br>
+<br>
+if __name__ == '__main__':<br>
+ import atexit<br>
+ lldb.SBDebugger.Initialize()<br>
+ atexit.register(lambda: lldb.SBDebugger.Terminate())<br>
+ unittest2.main()<br>
<br>
Modified: lldb/trunk/test/tools/lldb-mi/main.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/main.c?rev=223674&r1=223673&r2=223674&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/main.c?rev=223674&r1=223673&r2=223674&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/test/tools/lldb-mi/main.c (original)<br>
+++ lldb/trunk/test/tools/lldb-mi/main.c Mon Dec 8 12:07:40 2014<br>
@@ -20,6 +20,7 @@ int main (int argc, char const *argv[])<br>
printf("argc=%d\n", argc);<br>
a = a_MyFunction();<br>
b = b_MyFunction();<br>
+ //BP_localstest<br>
if (doloop)<br>
infloop();<br>
if (argc > 1 && *argv[1] == 'l') {<br>
<br>
Modified: lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp?rev=223674&r1=223673&r2=223674&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp?rev=223674&r1=223673&r2=223674&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp (original)<br>
+++ lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp Mon Dec 8 12:07:40 2014<br>
@@ -432,7 +432,7 @@ CMICmdCmdStackListArguments::Execute(voi<br>
{<br>
lldb::SBFrame frame = thread.GetFrameAtIndex(i);<br>
CMICmnMIValueList miValueList(true);<br>
- const MIuint maskVarTypes = 0x1000;<br>
+ const MIuint maskVarTypes = CMICmnLLDBDebugSessionInfo::eVariableType_Arguments;<br>
if (!rSessionInfo.MIResponseFormVariableInfo3(frame, maskVarTypes, miValueList))<br>
return MIstatus::failure;<br>
const CMICmnMIValueConst miValueConst(CMIUtilString::Format("%d", i));<br>
@@ -600,7 +600,7 @@ CMICmdCmdStackListLocals::Execute(void)<br>
MIunused(nFrames);<br>
lldb::SBFrame frame = (nFrame != UINT64_MAX) ? thread.GetFrameAtIndex(nFrame) : thread.GetSelectedFrame();<br>
CMICmnMIValueList miValueList(true);<br>
- const MIuint maskVarTypes = 0x0110;<br>
+ const MIuint maskVarTypes = CMICmnLLDBDebugSessionInfo::eVariableType_Locals;<br>
if (!rSessionInfo.MIResponseFormVariableInfo(frame, maskVarTypes, miValueList))<br>
return MIstatus::failure;<br>
<br>
<br>
Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp?rev=223674&r1=223673&r2=223674&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp?rev=223674&r1=223673&r2=223674&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp (original)<br>
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp Mon Dec 8 12:07:40 2014<br>
@@ -254,7 +254,7 @@ CMICmnLLDBDebugSessionInfo::GetThreadFra<br>
<br>
// Function args<br>
CMICmnMIValueList miValueList(true);<br>
- const MIuint maskVarTypes = 0x1000;<br>
+ const MIuint maskVarTypes = eVariableType_Arguments;<br>
if (!MIResponseFormVariableInfo(frame, maskVarTypes, miValueList))<br>
return MIstatus::failure;<br>
<br>
@@ -327,7 +327,7 @@ CMICmnLLDBDebugSessionInfo::GetThreadFra<br>
<br>
// Function args<br>
CMICmnMIValueList miValueList(true);<br>
- const MIuint maskVarTypes = 0x1000;<br>
+ const MIuint maskVarTypes = eVariableType_Arguments;<br>
if (!MIResponseFormVariableInfo2(frame, maskVarTypes, miValueList))<br>
return MIstatus::failure;<br>
<br>
@@ -647,10 +647,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFo<br>
// tuple type object past in.<br>
// Type: Method.<br>
// Args: vrFrame - (R) LLDB thread object.<br>
-// vMaskVarTypes - (R) 0x1000 = arguments,<br>
-// 0x0100 = locals,<br>
-// 0x0010 = statics,<br>
-// 0x0001 = in scope only.<br>
+// vMaskVarTypes - (R) Construed according to VariableType_e.<br>
// vwrMIValueList - (W) MI value list object.<br>
// Return: MIstatus::success - Functional succeeded.<br>
// MIstatus::failure - Functional failed.<br>
@@ -663,10 +660,10 @@ CMICmnLLDBDebugSessionInfo::MIResponseFo<br>
bool bOk = MIstatus::success;<br>
lldb::SBFrame &rFrame = const_cast<lldb::SBFrame &>(vrFrame);<br>
<br>
- const bool bArg = (vMaskVarTypes & 0x1000);<br>
- const bool bLocals = (vMaskVarTypes & 0x0100);<br>
- const bool bStatics = (vMaskVarTypes & 0x0010);<br>
- const bool bInScopeOnly = (vMaskVarTypes & 0x0001);<br>
+ const bool bArg = (vMaskVarTypes & eVariableType_Arguments);<br>
+ const bool bLocals = (vMaskVarTypes & eVariableType_Locals);<br>
+ const bool bStatics = (vMaskVarTypes & eVariableType_Statics);<br>
+ const bool bInScopeOnly = (vMaskVarTypes & eVariableType_InScope);<br>
lldb::SBValueList listArg = rFrame.GetVariables(bArg, bLocals, bStatics, bInScopeOnly);<br>
const MIuint nArgs = listArg.GetSize();<br>
for (MIuint i = 0; bOk && (i < nArgs); i++)<br>
@@ -690,10 +687,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFo<br>
// tuple type object past in.<br>
// Type: Method.<br>
// Args: vrFrame - (R) LLDB thread object.<br>
-// vMaskVarTypes - (R) 0x1000 = arguments,<br>
-// 0x0100 = locals,<br>
-// 0x0010 = statics,<br>
-// 0x0001 = in scope only.<br>
+// vMaskVarTypes - (R) Construed according to VariableType_e.<br>
// vwrMIValueList - (W) MI value list object.<br>
// Return: MIstatus::success - Functional succeeded.<br>
// MIstatus::failure - Functional failed.<br>
@@ -706,10 +700,10 @@ CMICmnLLDBDebugSessionInfo::MIResponseFo<br>
bool bOk = MIstatus::success;<br>
lldb::SBFrame &rFrame = const_cast<lldb::SBFrame &>(vrFrame);<br>
<br>
- const bool bArg = (vMaskVarTypes & 0x1000);<br>
- const bool bLocals = (vMaskVarTypes & 0x0100);<br>
- const bool bStatics = (vMaskVarTypes & 0x0010);<br>
- const bool bInScopeOnly = (vMaskVarTypes & 0x0001);<br>
+ const bool bArg = (vMaskVarTypes & eVariableType_Arguments);<br>
+ const bool bLocals = (vMaskVarTypes & eVariableType_Locals);<br>
+ const bool bStatics = (vMaskVarTypes & eVariableType_Statics);<br>
+ const bool bInScopeOnly = (vMaskVarTypes & eVariableType_InScope);<br>
const MIuint nMaxRecusiveDepth = 10;<br>
MIuint nCurrentRecursiveDepth = 0;<br>
lldb::SBValueList listArg = rFrame.GetVariables(bArg, bLocals, bStatics, bInScopeOnly);<br>
@@ -730,10 +724,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFo<br>
// tuple type object past in.<br>
// Type: Method.<br>
// Args: vrFrame - (R) LLDB thread object.<br>
-// vMaskVarTypes - (R) 0x1000 = arguments,<br>
-// 0x0100 = locals,<br>
-// 0x0010 = statics,<br>
-// 0x0001 = in scope only.<br>
+// vMaskVarTypes - (R) Construed according to VariableType_e.<br>
// vwrMIValueList - (W) MI value list object.<br>
// Return: MIstatus::success - Functional succeeded.<br>
// MIstatus::failure - Functional failed.<br>
@@ -746,10 +737,10 @@ CMICmnLLDBDebugSessionInfo::MIResponseFo<br>
bool bOk = MIstatus::success;<br>
lldb::SBFrame &rFrame = const_cast<lldb::SBFrame &>(vrFrame);<br>
<br>
- const bool bArg = (vMaskVarTypes & 0x1000);<br>
- const bool bLocals = (vMaskVarTypes & 0x0100);<br>
- const bool bStatics = (vMaskVarTypes & 0x0010);<br>
- const bool bInScopeOnly = (vMaskVarTypes & 0x0001);<br>
+ const bool bArg = (vMaskVarTypes & eVariableType_Arguments);<br>
+ const bool bLocals = (vMaskVarTypes & eVariableType_Locals);<br>
+ const bool bStatics = (vMaskVarTypes & eVariableType_Statics);<br>
+ const bool bInScopeOnly = (vMaskVarTypes & eVariableType_InScope);<br>
const MIuint nMaxRecusiveDepth = 10;<br>
MIuint nCurrentRecursiveDepth = 0;<br>
lldb::SBValueList listArg = rFrame.GetVariables(bArg, bLocals, bStatics, bInScopeOnly);<br>
<br>
Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h?rev=223674&r1=223673&r2=223674&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h?rev=223674&r1=223673&r2=223674&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h (original)<br>
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h Mon Dec 8 12:07:40 2014<br>
@@ -103,6 +103,19 @@ class CMICmnLLDBDebugSessionInfo : publi<br>
MIuint m_nBrkPtThreadId; // Restrict the breakpoint to the specified thread-id<br>
};<br>
<br>
+ // Enumerations:<br>
+ public:<br>
+ //++ ===================================================================<br>
+ // Details: The type of variable used by MIResponseFormVariableInfo family functions.<br>
+ //--<br>
+ enum VariableType_e<br>
+ {<br>
+ eVariableType_InScope = (1u << 0), // In scope only.<br>
+ eVariableType_Statics = (1u << 1), // Statics.<br>
+ eVariableType_Locals = (1u << 2), // Locals.<br>
+ eVariableType_Arguments = (1u << 3) // Arguments.<br>
+ };<br>
+<br>
// Typedefs:<br>
public:<br>
typedef std::vector<uint32_t> VecActiveThreadId_t;<br>
<br>
Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp?rev=223674&r1=223673&r2=223674&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp?rev=223674&r1=223673&r2=223674&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp (original)<br>
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp Mon Dec 8 12:07:40 2014<br>
@@ -1077,7 +1077,7 @@ CMICmnLLDBDebuggerHandleEvents::MiStoppe<br>
if (bOk)<br>
{<br>
CMICmnMIValueList miValueList(true);<br>
- const MIuint maskVarTypes = 0x1000;<br>
+ const MIuint maskVarTypes = CMICmnLLDBDebugSessionInfo::eVariableType_Arguments;<br>
bOk = rSession.MIResponseFormVariableInfo2(frame, maskVarTypes, miValueList);<br>
<br>
CMICmnMIValueTuple miValueTuple;<br>
@@ -1153,7 +1153,7 @@ CMICmnLLDBDebuggerHandleEvents::HandlePr<br>
<br>
// Function args<br>
CMICmnMIValueList miValueList(true);<br>
- const MIuint maskVarTypes = 0x1000;<br>
+ const MIuint maskVarTypes = CMICmnLLDBDebugSessionInfo::eVariableType_Arguments;<br>
if (!rSession.MIResponseFormVariableInfo2(frame, maskVarTypes, miValueList))<br>
return MIstatus::failure;<br>
CMICmnMIValueTuple miValueTuple;<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br>
</blockquote></div><br></div>