Add back code to implement "frame var -a,-l,-g" filters.

r285226 dropped the code that did these checks.  I am pretty
sure that was inadvertent, so I added that back in and added
a test for it.

<rdar://problem/31661252>

llvm-svn: 300564
This commit is contained in:
Jim Ingham 2017-04-18 16:52:16 +00:00
parent d8ad303f15
commit eb236735e5
4 changed files with 168 additions and 32 deletions

View File

@ -0,0 +1,6 @@
LEVEL = ../../make
C_SOURCES := main.c
CFLAGS_EXTRAS += -std=c99
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,99 @@
"""
Make sure the frame variable -g, -a, and -l flags work.
"""
from __future__ import print_function
import os
import time
import re
import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *
class TestFrameVar(TestBase):
mydir = TestBase.compute_mydir(__file__)
# If your test case doesn't stress debug info, the
# set this to true. That way it won't be run once for
# each debug info format.
NO_DEBUG_INFO_TESTCASE = True
def test_frame_var(self):
self.build()
self.do_test()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
def do_test(self):
exe = os.path.join(os.getcwd(), "a.out")
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Now create a breakpoint in main.c at the source matching
# "Set a breakpoint here"
breakpoint = target.BreakpointCreateBySourceRegex(
"Set a breakpoint here", lldb.SBFileSpec("main.c"))
self.assertTrue(breakpoint and
breakpoint.GetNumLocations() >= 1,
VALID_BREAKPOINT)
error = lldb.SBError()
# This is the launch info. If you want to launch with arguments or
# environment variables, add them using SetArguments or
# SetEnvironmentEntries
launch_info = lldb.SBLaunchInfo(None)
process = target.Launch(launch_info, error)
self.assertTrue(process, PROCESS_IS_VALID)
# Did we hit our breakpoint?
from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
threads = get_threads_stopped_at_breakpoint(process, breakpoint)
self.assertTrue(
len(threads) == 1,
"There should be a thread stopped at our breakpoint")
# The hit count for the breakpoint should be 1.
self.assertTrue(breakpoint.GetHitCount() == 1)
frame = threads[0].GetFrameAtIndex(0)
command_result = lldb.SBCommandReturnObject()
interp = self.dbg.GetCommandInterpreter()
# Just get args:
result = interp.HandleCommand("frame var -l", command_result)
self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed")
output = command_result.GetOutput()
self.assertTrue("argc" in output, "Args didn't find argc")
self.assertTrue("argv" in output, "Args didn't find argv")
self.assertTrue("test_var" not in output, "Args found a local")
self.assertTrue("g_var" not in output, "Args found a global")
# Just get locals:
result = interp.HandleCommand("frame var -a", command_result)
self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed")
output = command_result.GetOutput()
self.assertTrue("argc" not in output, "Locals found argc")
self.assertTrue("argv" not in output, "Locals found argv")
self.assertTrue("test_var" in output, "Locals didn't find test_var")
self.assertTrue("g_var" not in output, "Locals found a global")
# Get the file statics:
result = interp.HandleCommand("frame var -l -a -g", command_result)
self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed")
output = command_result.GetOutput()
self.assertTrue("argc" not in output, "Globals found argc")
self.assertTrue("argv" not in output, "Globals found argv")
self.assertTrue("test_var" not in output, "Globals found test_var")
self.assertTrue("g_var" in output, "Globals didn't find g_var")

View File

@ -0,0 +1,11 @@
#include <stdio.h>
int g_var = 200;
int
main(int argc, char **argv)
{
int test_var = 10;
printf ("Set a breakpoint here: %d %d.\n", test_var, g_var);
return 0;
}

View File

@ -655,42 +655,62 @@ protected:
if (num_variables > 0) {
for (size_t i = 0; i < num_variables; i++) {
var_sp = variable_list->GetVariableAtIndex(i);
bool dump_variable = true;
std::string scope_string;
if (dump_variable && m_option_variable.show_scope)
scope_string = GetScopeString(var_sp).str();
switch (var_sp->GetScope())
{
case eValueTypeVariableGlobal:
if (!m_option_variable.show_globals)
continue;
break;
case eValueTypeVariableStatic:
if (!m_option_variable.show_globals)
continue;
break;
case eValueTypeVariableArgument:
if (!m_option_variable.show_args)
continue;
break;
case eValueTypeVariableLocal:
if (!m_option_variable.show_locals)
continue;
break;
default:
continue;
break;
}
std::string scope_string;
if (m_option_variable.show_scope)
scope_string = GetScopeString(var_sp).str();
if (dump_variable) {
// Use the variable object code to make sure we are
// using the same APIs as the public API will be
// using...
valobj_sp = frame->GetValueObjectForFrameVariable(
var_sp, m_varobj_options.use_dynamic);
if (valobj_sp) {
// When dumping all variables, don't print any variables
// that are not in scope to avoid extra unneeded output
if (valobj_sp->IsInScope()) {
if (!valobj_sp->GetTargetSP()
->GetDisplayRuntimeSupportValues() &&
valobj_sp->IsRuntimeSupportValue())
continue;
// Use the variable object code to make sure we are
// using the same APIs as the public API will be
// using...
valobj_sp = frame->GetValueObjectForFrameVariable(
var_sp, m_varobj_options.use_dynamic);
if (valobj_sp) {
// When dumping all variables, don't print any variables
// that are not in scope to avoid extra unneeded output
if (valobj_sp->IsInScope()) {
if (!valobj_sp->GetTargetSP()
->GetDisplayRuntimeSupportValues() &&
valobj_sp->IsRuntimeSupportValue())
continue;
if (!scope_string.empty())
s.PutCString(scope_string);
if (!scope_string.empty())
s.PutCString(scope_string);
if (m_option_variable.show_decl &&
var_sp->GetDeclaration().GetFile()) {
var_sp->GetDeclaration().DumpStopContext(&s, false);
s.PutCString(": ");
}
options.SetFormat(format);
options.SetVariableFormatDisplayLanguage(
valobj_sp->GetPreferredDisplayLanguage());
options.SetRootValueObjectName(
var_sp ? var_sp->GetName().AsCString() : nullptr);
valobj_sp->Dump(result.GetOutputStream(), options);
if (m_option_variable.show_decl &&
var_sp->GetDeclaration().GetFile()) {
var_sp->GetDeclaration().DumpStopContext(&s, false);
s.PutCString(": ");
}
options.SetFormat(format);
options.SetVariableFormatDisplayLanguage(
valobj_sp->GetPreferredDisplayLanguage());
options.SetRootValueObjectName(
var_sp ? var_sp->GetName().AsCString() : nullptr);
valobj_sp->Dump(result.GetOutputStream(), options);
}
}
}