Vendor import of lldb trunk r338536:

https://llvm.org/svn/llvm-project/lldb/trunk@338536
This commit is contained in:
Dimitry Andric 2018-08-02 17:33:54 +00:00
parent f73363f1dd
commit 39be7ce233
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/lldb/dist/; revision=337147
svn path=/vendor/lldb/lldb-release_70-r338892/; revision=337308; tag=vendor/lldb/lldb-release_70-r338892
98 changed files with 916 additions and 352 deletions

View File

@ -13,6 +13,7 @@
#include "lldb/Utility/Args.h"
#include "lldb/Utility/StringList.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
namespace lldb_private {
@ -77,8 +78,29 @@ class CompletionRequest {
void SetWordComplete(bool v) { m_word_complete = v; }
/// The array of matches returned.
StringList &GetMatches() { return *m_matches; }
/// Adds a possible completion string. If the completion was already
/// suggested before, it will not be added to the list of results. A copy of
/// the suggested completion is stored, so the given string can be free'd
/// afterwards.
///
/// @param match The suggested completion.
void AddCompletion(llvm::StringRef completion) {
// Add the completion if we haven't seen the same value before.
if (m_match_set.insert(completion).second)
m_matches->AppendString(completion);
}
/// Adds multiple possible completion strings.
///
/// \param completions The list of completions.
///
/// @see AddCompletion
void AddCompletions(const StringList &completions) {
for (std::size_t i = 0; i < completions.GetSize(); ++i)
AddCompletion(completions.GetStringAtIndex(i));
}
std::size_t GetNumberOfMatches() const { return m_matches->GetSize(); }
llvm::StringRef GetCursorArgument() const {
return GetParsedLine().GetArgumentAtIndex(GetCursorIndex());
@ -111,8 +133,15 @@ class CompletionRequest {
/// \btrue if this is a complete option value (a space will be inserted
/// after the completion.) \bfalse otherwise.
bool m_word_complete = false;
// We don't own the list.
// Note: This list is kept private. This is by design to prevent that any
// completion depends on any already computed completion from another backend.
// Note: We don't own the list. It's owned by the creator of the
// CompletionRequest object.
StringList *m_matches;
/// List of added completions so far. Used to filter out duplicates.
llvm::StringSet<> m_match_set;
};
} // namespace lldb_private

View File

@ -524,8 +524,6 @@ class Stream {
//------------------------------------------------------------------
size_t PutULEB128(uint64_t uval);
static void UnitTest(Stream *s);
protected:
//------------------------------------------------------------------
// Member variables

View File

@ -18,7 +18,7 @@ class TestMultipleSimultaneousDebuggers(TestBase):
mydir = TestBase.compute_mydir(__file__)
# This test case fails non-deterministically.
# This test case fails non-deterministically.
@skipIfNoSBHeaders
@expectedFailureAll(bugnumber="llvm.org/pr20282")
def test_multiple_debuggers(self):

View File

@ -16,7 +16,7 @@
class SBBreakpointCallbackCase(TestBase):
NO_DEBUG_INFO_TESTCASE = True
def setUp(self):
TestBase.setUp(self)
self.generateSource('driver.cpp')

View File

@ -791,7 +791,7 @@ def skipIfLLVMTargetMissing(target):
if targets.GetItemAtIndex(i).GetStringValue(99) == target:
found = True
break
return unittest2.skipIf(not found, "requires " + target)
# Call sysctl on darwin to see if a specified hardware feature is available on this machine.

View File

@ -46,7 +46,7 @@ def test_with(self):
# Calling this function now succeeds, but we follow the typedef return type through to
# const char *, and thus don't invoke the Summary formatter.
# clang's libstdc++ on ios arm64 inlines std::string::c_str() always;
# clang's libstdc++ on ios arm64 inlines std::string::c_str() always;
# skip this part of the test.
triple = self.dbg.GetSelectedPlatform().GetTriple()
do_cstr_test = True

View File

@ -48,7 +48,7 @@ def check_after_call(self, num_sigchld):
"Restored the zeroth frame correctly")
def call_function(self):
(target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
(target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
'Stop here in main.', self.main_source_spec)
# Make sure the SIGCHLD behavior is pass/no-stop/no-notify:

View File

@ -37,7 +37,7 @@ def check_after_call(self):
def call_function(self):
"""Test calling function that throws."""
(target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
(target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
'I am about to throw.', self.main_source_spec)
options = lldb.SBExpressionOptions()

View File

@ -22,7 +22,7 @@ def do_test(self, dictionary=None):
"""These basic expression commands should work as expected."""
self.build(dictionary=dictionary)
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
'// Break here', self.main_source_spec)
frame = thread.GetFrameAtIndex(0)

View File

@ -37,7 +37,7 @@ def test_with_dummy_target(self):
def try_expressions(self):
"""Test calling expressions with errors that can be fixed by the FixIts."""
(target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
(target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
'Stop here to evaluate expressions', self.main_source_spec)
options = lldb.SBExpressionOptions()

View File

@ -32,8 +32,8 @@ def cleanup():
"""valobj.AddressOf() should return correct values."""
self.build()
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
'Set breakpoint here.',
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
'Set breakpoint here.',
lldb.SBFileSpec("main.cpp", False))
self.runCmd("command script import --allow-reload s11588.py")
self.runCmd(

View File

@ -25,7 +25,7 @@ def test_issue35310(self):
"""
self.build()
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
'// Break here', self.main_source_spec)
frame = thread.GetFrameAtIndex(0)

View File

@ -16,7 +16,7 @@ class SaveJITObjectsTestCase(TestBase):
def enumerateJITFiles(self):
return [f for f in os.listdir(self.getBuildDir()) if f.startswith("jit")]
def countJITFiles(self):
return len(self.enumerateJITFiles())
@ -31,7 +31,7 @@ def test_save_jit_objects(self):
os.chdir(self.getBuildDir())
src_file = "main.c"
src_file_spec = lldb.SBFileSpec(src_file)
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "break", src_file_spec)

View File

@ -23,7 +23,7 @@ class UnwindFromExpressionTest(TestBase):
def build_and_run_to_bkpt(self):
self.build()
(target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
(target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
"// Set a breakpoint here to get started", self.main_spec)
# Next set a breakpoint in this function, set up Expression options to stop on

View File

@ -22,7 +22,7 @@ def do_test(self, dictionary=None):
"""Printing an xvalue should work."""
self.build(dictionary=dictionary)
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
'// Break here', self.main_source_spec)
frame = thread.GetFrameAtIndex(0)

View File

@ -31,7 +31,7 @@ def setUp(self):
def address_breakpoints(self):
"""Test that breakpoints set on a bad address say they are bad."""
target, process, thread, bkpt = \
lldbutil.run_to_source_breakpoint(self,
lldbutil.run_to_source_breakpoint(self,
"Set a breakpoint here",
lldb.SBFileSpec("main.c"))

View File

@ -34,17 +34,17 @@ def test_auto_continue_on_location(self):
self.build()
self.auto_continue_location()
def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1,
def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1,
pattern="Set a breakpoint here"):
exe = self.getBuildArtifact("a.out")
self.target = self.dbg.CreateTarget(exe)
self.assertTrue(self.target.IsValid(), "Target is not valid")
extra_options_txt = "--auto-continue 1 "
if additional_options:
extra_options_txt += additional_options
bpno = lldbutil.run_break_set_by_source_regexp(self, pattern,
extra_options = extra_options_txt,
bpno = lldbutil.run_break_set_by_source_regexp(self, pattern,
extra_options = extra_options_txt,
num_expected_locations = num_expected_loc)
return bpno

View File

@ -46,12 +46,12 @@ def set_breakpoint (self):
self.assertTrue(target, "Target %s is not valid"%(exe))
# This should create a breakpoint with 3 locations.
bkpt = target.BreakpointCreateByLocation("main.c", self.line)
# The breakpoint list should show 3 locations.
self.assertEqual(bkpt.GetNumLocations(), 3, "Wrong number of locations")
self.expect(
"breakpoint list -f",
"Breakpoint locations shown correctly",
@ -62,7 +62,7 @@ def set_breakpoint (self):
"where = a.out`func_inlined .+unresolved, hit count = 0",
"where = a.out`main .+\[inlined\].+unresolved, hit count = 0"])
return bkpt
return bkpt
def shadowed_bkpt_cond_test(self):
"""Test that options set on the breakpoint and location behave correctly."""
@ -106,7 +106,7 @@ def shadowed_bkpt_command_test(self):
commands = ["AAAAAA", "BBBBBB", "CCCCCC"]
str_list = lldb.SBStringList()
str_list.AppendList(commands, len(commands))
bkpt.SetCommandLineCommands(str_list)
cmd_list = lldb.SBStringList()
bkpt.GetCommandLineCommands(cmd_list)
@ -123,7 +123,7 @@ def shadowed_bkpt_command_test(self):
bkpt.location[1].GetCommandLineCommands(loc_cmd_list)
loc_list_size = loc_list.GetSize()
# Check that the location has the right commands:
self.assertEqual(loc_cmd_list.GetSize() , loc_list_size, "Added the right number of commands to location")
for i in range(0,loc_list_size):

View File

@ -64,7 +64,7 @@ def setup_target(self):
self.target = self.dbg.CreateTarget(exe)
self.assertTrue(self.target, VALID_TARGET)
self.main_file_spec = lldb.SBFileSpec(os.path.join(self.getSourceDir(), "main.c"))
def check_name_in_target(self, bkpt_name):
name_list = lldb.SBStringList()
self.target.GetBreakpointNames(name_list)
@ -74,7 +74,7 @@ def check_name_in_target(self, bkpt_name):
found_it = True
break
self.assertTrue(found_it, "Didn't find the name %s in the target's name list:"%(bkpt_name))
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
@ -107,14 +107,14 @@ def do_check_names(self):
matches = bkpt.MatchesName(bkpt_name)
self.assertTrue(matches, "We didn't match the name we just set")
# Make sure we don't match irrelevant names:
matches = bkpt.MatchesName("NotABreakpoint")
self.assertTrue(not matches, "We matched a name we didn't set.")
# Make sure the name is also in the target:
self.check_name_in_target(bkpt_name)
# Add another name, make sure that works too:
bkpt.AddName(other_bkpt_name)
@ -132,7 +132,7 @@ def do_check_names(self):
bkpt.GetNames(name_list)
num_names = name_list.GetSize()
self.assertTrue(num_names == 1, "Name list has %d items, expected 1."%(num_names))
name = name_list.GetStringAtIndex(0)
self.assertTrue(name == other_bkpt_name, "Remaining name was: %s expected %s."%(name, other_bkpt_name))
@ -156,7 +156,7 @@ def do_check_illegal_names(self):
def do_check_using_names(self):
"""Use Python APIs to check names work in place of breakpoint ID's."""
bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10)
bkpt_name = "ABreakpoint"
other_bkpt_name= "_AnotherBreakpoint"
@ -255,12 +255,12 @@ def do_check_configuring_names(self):
bp_name.SetAutoContinue(new_auto_continue)
self.assertEqual(bp_name.GetAutoContinue(), new_auto_continue, "Couldn't change auto-continue on the name")
self.assertEqual(bkpt.GetAutoContinue(), new_auto_continue, "Option didn't propagate to the breakpoint.")
# Now make this same breakpoint name - but from the command line
cmd_str = "breakpoint name configure %s -o %d -i %d -c '%s' -G %d -t %d -x %d -T '%s' -q '%s' -H '%s'"%(cl_bp_name_string,
self.is_one_shot,
self.ignore_count,
self.condition,
cmd_str = "breakpoint name configure %s -o %d -i %d -c '%s' -G %d -t %d -x %d -T '%s' -q '%s' -H '%s'"%(cl_bp_name_string,
self.is_one_shot,
self.ignore_count,
self.condition,
self.auto_continue,
self.tid,
self.tidx,
@ -269,7 +269,7 @@ def do_check_configuring_names(self):
self.help_string)
for cmd in self.cmd_list:
cmd_str += " -C '%s'"%(cmd)
self.runCmd(cmd_str, check=True)
# Now look up this name again and check its options:
cl_name = lldb.SBBreakpointName(self.target, cl_bp_name_string)
@ -280,14 +280,14 @@ def do_check_configuring_names(self):
new_help = "I do something even more interesting"
cl_name.SetHelpString(new_help)
self.assertEqual(new_help, cl_name.GetHelpString(), "SetHelpString didn't")
# We should have three names now, make sure the target can list them:
name_list = lldb.SBStringList()
self.target.GetBreakpointNames(name_list)
for name_string in [self.bp_name_string, other_bp_name_string, cl_bp_name_string]:
self.assertTrue(name_string in name_list, "Didn't find %s in names"%(name_string))
# Delete the name from the current target. Make sure that works and deletes the
# Delete the name from the current target. Make sure that works and deletes the
# name from the breakpoint as well:
self.target.DeleteBreakpointName(self.bp_name_string)
name_list.Clear()
@ -305,7 +305,7 @@ def do_check_configuring_names(self):
self.assertTrue(self.bp_name_string not in name_list, "Didn't delete %s from the dummy target"%(self.bp_name_string))
# Also make sure the name got removed from breakpoints holding it:
self.assertFalse(bkpt.MatchesName(self.bp_name_string), "Didn't remove the name from the breakpoint.")
def check_permission_results(self, bp_name):
self.assertEqual(bp_name.GetAllowDelete(), False, "Didn't set allow delete.")
protected_bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10)

View File

@ -25,7 +25,7 @@ class HardwareBreakpointMultiThreadTestCase(TestBase):
@expectedFailureAndroid
def test_hw_break_set_delete_multi_thread(self):
self.build()
self.setTearDownCleanup()
self.setTearDownCleanup()
self.break_multi_thread('delete')
# LLDB supports hardware breakpoints for arm and aarch64 architectures.
@ -33,7 +33,7 @@ def test_hw_break_set_delete_multi_thread(self):
@expectedFailureAndroid
def test_hw_break_set_disable_multi_thread(self):
self.build()
self.setTearDownCleanup()
self.setTearDownCleanup()
self.break_multi_thread('disable')
def setUp(self):
@ -74,7 +74,7 @@ def break_multi_thread(self, removal_type):
count = 0
while count < 2 :
self.runCmd("process continue")
# We should be stopped in hw_break_function

View File

@ -65,7 +65,7 @@ def cleanup ():
# Create the targets we are making breakpoints in and copying them to:
self.orig_target = self.dbg.CreateTarget(exe)
self.assertTrue(self.orig_target, VALID_TARGET)
self.copy_target = self.dbg.CreateTarget(exe)
self.assertTrue(self.copy_target, VALID_TARGET)
@ -91,7 +91,7 @@ def check_equivalence(self, source_bps, do_write = True):
num_source_bps = source_bps.GetSize()
num_copy_bps = copy_bps.GetSize()
self.assertTrue(num_source_bps == num_copy_bps, "Didn't get same number of input and output breakpoints - orig: %d copy: %d"%(num_source_bps, num_copy_bps))
for i in range(0, num_source_bps):
source_bp = source_bps.GetBreakpointAtIndex(i)
source_desc = lldb.SBStream()
@ -132,7 +132,7 @@ def do_check_resolvers(self):
source_bps.Append(self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeAuto, empty_module_list, empty_cu_list))
source_bps.Append(self.orig_target.BreakpointCreateByName("blubby", lldb.eFunctionNameTypeFull, empty_module_list,empty_cu_list))
source_bps.Append(self.orig_target.BreakpointCreateBySourceRegex("dont really care", blubby_file_spec))
# And some number greater than one:
self.check_equivalence(source_bps)
@ -185,7 +185,7 @@ def do_check_options(self):
bkpt.SetOneShot(True)
bkpt.SetThreadID(10)
source_bps.Append(bkpt)
# Make sure we get one right:
self.check_equivalence(source_bps)
source_bps.Clear()
@ -232,7 +232,7 @@ def do_check_appending(self):
bkpt.SetThreadID(10)
source_bps.Append(bkpt)
all_bps.Append(bkpt)
error = lldb.SBError()
error = self.orig_target.BreakpointsWriteToFile(self.bkpts_file_spec, source_bps)
self.assertTrue(error.Success(), "Failed writing breakpoints to file: %s."%(error.GetCString()))
@ -265,7 +265,7 @@ def do_check_names(self):
write_bps = lldb.SBBreakpointList(self.orig_target)
bkpt.AddName(good_bkpt_name)
write_bps.Append(bkpt)
error = lldb.SBError()
error = self.orig_target.BreakpointsWriteToFile(self.bkpts_file_spec, write_bps)
self.assertTrue(error.Success(), "Failed writing breakpoints to file: %s."%(error.GetCString()))
@ -282,7 +282,3 @@ def do_check_names(self):
error = self.copy_target.BreakpointsCreateFromFile(self.bkpts_file_spec, names_list, copy_bps)
self.assertTrue(error.Success(), "Failed reading breakpoints from file: %s"%(error.GetCString()))
self.assertTrue(copy_bps.GetSize() == 1, "Found the matching breakpoint.")

View File

@ -1,8 +1,8 @@
"""
Test that breakpoints do not affect stepping.
Check for correct StopReason when stepping to the line with breakpoint
Check for correct StopReason when stepping to the line with breakpoint
which chould be eStopReasonBreakpoint in general,
and eStopReasonPlanComplete when breakpoint's condition fails.
and eStopReasonPlanComplete when breakpoint's condition fails.
"""
from __future__ import print_function
@ -19,7 +19,7 @@ class StepOverBreakpointsTestCase(TestBase):
def setUp(self):
TestBase.setUp(self)
self.build()
exe = self.getBuildArtifact("a.out")
src = lldb.SBFileSpec("main.cpp")
@ -32,7 +32,7 @@ def setUp(self):
self.line1 = line_number('main.cpp', "breakpoint_1")
self.line4 = line_number('main.cpp', "breakpoint_4")
self.breakpoint1 = self.target.BreakpointCreateByLocation(src, self.line1)
self.breakpoint1 = self.target.BreakpointCreateByLocation(src, self.line1)
self.assertTrue(
self.breakpoint1 and self.breakpoint1.GetNumLocations() == 1,
VALID_BREAKPOINT)
@ -52,7 +52,7 @@ def setUp(self):
self.thread = lldbutil.get_one_thread_stopped_at_breakpoint(self.process, self.breakpoint1)
self.assertIsNotNone(self.thread, "Didn't stop at breakpoint 1.")
def test_step_instruction(self):
def test_step_instruction(self):
# Count instructions between breakpoint_1 and breakpoint_4
contextList = self.target.FindFunctions('main', lldb.eFunctionNameTypeAuto)
self.assertEquals(contextList.GetSize(), 1)
@ -89,7 +89,7 @@ def test_step_instruction(self):
@skipIf(bugnumber="llvm.org/pr31972", hostoslist=["windows"])
def test_step_over(self):
#lldb.DBG.EnableLog("lldb", ["step","breakpoint"])
self.thread.StepOver()
# We should be stopped at the breakpoint_2 line with stop plan complete reason
self.assertEquals(self.process.GetState(), lldb.eStateStopped)

View File

@ -38,6 +38,46 @@ def test_de(self):
"""Test that 'de' completes to 'detach '."""
self.complete_from_to('de', 'detach ')
@skipIfFreeBSD # timing out on the FreeBSD buildbot
def test_frame_variable(self):
self.build()
self.main_source = "main.cpp"
self.main_source_spec = lldb.SBFileSpec(self.main_source)
self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
'// Break here', self.main_source_spec)
self.assertEquals(process.GetState(), lldb.eStateStopped)
# FIXME: This pulls in the debug information to make the completions work,
# but the completions should also work without.
self.runCmd("frame variable fooo")
self.complete_from_to('frame variable fo',
'frame variable fooo')
self.complete_from_to('frame variable fooo.',
'frame variable fooo.')
self.complete_from_to('frame variable fooo.dd',
'frame variable fooo.dd')
self.complete_from_to('frame variable ptr_fooo->',
'frame variable ptr_fooo->')
self.complete_from_to('frame variable ptr_fooo->dd',
'frame variable ptr_fooo->dd')
self.complete_from_to('frame variable cont',
'frame variable container')
self.complete_from_to('frame variable container.',
'frame variable container.MemberVar')
self.complete_from_to('frame variable container.Mem',
'frame variable container.MemberVar')
self.complete_from_to('frame variable ptr_cont',
'frame variable ptr_container')
self.complete_from_to('frame variable ptr_container->',
'frame variable ptr_container->MemberVar')
self.complete_from_to('frame variable ptr_container->Mem',
'frame variable ptr_container->MemberVar')
@skipIfFreeBSD # timing out on the FreeBSD buildbot
def test_process_attach_dash_dash_con(self):
"""Test that 'process attach --con' completes to 'process attach --continue '."""
@ -261,7 +301,7 @@ def complete_from_to(self, str_input, patterns, turn_off_re_match=False):
common_match = match_strings.GetStringAtIndex(0)
if num_matches == 0:
compare_string = str_input
else:
else:
if common_match != None and len(common_match) > 0:
compare_string = str_input + common_match
else:
@ -273,8 +313,8 @@ def complete_from_to(self, str_input, patterns, turn_off_re_match=False):
if turn_off_re_match:
self.expect(
compare_string, msg=COMPLETION_MSG(
str_input, p), exe=False, substrs=[p])
str_input, p, match_strings), exe=False, substrs=[p])
else:
self.expect(
compare_string, msg=COMPLETION_MSG(
str_input, p), exe=False, patterns=[p])
str_input, p, match_strings), exe=False, patterns=[p])

View File

@ -7,8 +7,15 @@ class Foo
}
};
struct Container { int MemberVar; };
int main()
{
Foo f;
f.Bar(1, 2);
Foo fooo;
Foo *ptr_fooo = &fooo;
fooo.Bar(1, 2);
Container container;
Container *ptr_container = &container;
return container.MemberVar = 3; // Break here
}

View File

@ -49,7 +49,7 @@ def test_value(self):
def test_ptr_and_ref(self):
"""Test that ref and ptr to std::bitset is displayed correctly"""
self.build()
(_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self,
(_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self,
'Check ref and ptr',
lldb.SBFileSpec("main.cpp", False))
@ -57,6 +57,6 @@ def test_ptr_and_ref(self):
self.check("ptr", 13)
lldbutil.continue_to_breakpoint(process, bkpt)
self.check("ref", 200)
self.check("ptr", 200)

View File

@ -90,7 +90,7 @@ def cleanup():
self.runCmd("n") # This gets up past the printf
self.runCmd("n") # Now advance over the first push_back.
self.expect("frame variable numbers_list",
substrs=['list has 1 items',
'[0] = ',

View File

@ -134,7 +134,7 @@ def test_ref_and_ptr(self):
"""Test that the data formatters work on ref and ptr."""
self.build()
(self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint(
self, "Stop here to check by ref and ptr.",
self, "Stop here to check by ref and ptr.",
lldb.SBFileSpec("main.cpp", False))
# The reference should print just like the value:
self.check_ii("ref")

View File

@ -130,7 +130,7 @@ def test_ref_and_ptr(self):
"""Test that the data formatters work on ref and ptr."""
self.build()
(self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint(
self, "Stop here to check by ref and ptr.",
self, "Stop here to check by ref and ptr.",
lldb.SBFileSpec("main.cpp", False))
# The reference should print just like the value:
self.check_ii("ref")
@ -139,4 +139,4 @@ def test_ref_and_ptr(self):
substrs=["ptr =", "size=7"])
self.expect("expr ptr",
substrs=["size=7"])

View File

@ -192,7 +192,7 @@ def test_ref_and_ptr(self):
self.check_numbers("ref")
# The pointer should just show the right number of elements:
self.expect("frame variable ptr", substrs=['ptr =', ' size=7'])
self.expect("p ptr", substrs=['$', 'size=7'])

View File

@ -40,7 +40,7 @@ def test_with_run_command(self):
self.assertEqual('"foobar"', frame.GetValueForVariablePath("ts[0]").GetSummary())
self.assertFalse(frame.GetValueForVariablePath("ts[1]").IsValid())
self.assertEqual(1, frame.GetValueForVariablePath("tt[0]").GetValueAsUnsigned())
self.assertEqual('"baz"', frame.GetValueForVariablePath("tt[1]").GetSummary())
self.assertEqual(2, frame.GetValueForVariablePath("tt[2]").GetValueAsUnsigned())

View File

@ -96,7 +96,7 @@ def cleanup():
if not skip_exec:
self.assertTrue(process.GetState() == lldb.eStateStopped,
"Process should be stopped at __dyld_start")
threads = lldbutil.get_stopped_threads(
process, lldb.eStopReasonExec)
self.assertTrue(

View File

@ -18,7 +18,7 @@ class TestFrameGuessLanguage(TestBase):
mydir = TestBase.compute_mydir(__file__)
# If your test case doesn't stress debug info, the
# 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
@ -84,6 +84,6 @@ def do_test(self):
self.check_language(thread, 0, c_frame_language)
self.check_language(thread, 1, lldb.eLanguageTypeC_plus_plus)
self.check_language(thread, 2, lldb.eLanguageTypeC_plus_plus)

View File

@ -17,7 +17,7 @@ class TestFrameVar(TestBase):
mydir = TestBase.compute_mydir(__file__)
# If your test case doesn't stress debug info, the
# 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
@ -67,7 +67,7 @@ def do_test(self):
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")
@ -85,7 +85,7 @@ def do_test(self):
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")
@ -94,6 +94,6 @@ def do_test(self):
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

@ -98,12 +98,12 @@ def haltReason(self):
return "T05thread:00000001;06:9038d60f00700000;07:98b4062680ffffff;10:c0d7bf1b80ffffff;"
def readRegister(self, register):
regs = {0x0: "00b0060000610000",
0xa: "68fe471c80ffffff",
0xc: "60574a1c80ffffff",
0xd: "18f3042680ffffff",
0xe: "be8a4d7142000000",
0xf: "50df471c80ffffff",
regs = {0x0: "00b0060000610000",
0xa: "68fe471c80ffffff",
0xc: "60574a1c80ffffff",
0xd: "18f3042680ffffff",
0xe: "be8a4d7142000000",
0xf: "50df471c80ffffff",
0x10: "c0d7bf1b80ffffff" }
if register in regs:
return regs[register]

View File

@ -467,7 +467,7 @@ def assertPacketLogContains(self, packets):
i = 0
j = 0
log = self.server.responder.packetLog
while i < len(packets) and j < len(log):
if log[j] == packets[i]:
i += 1

View File

@ -17,7 +17,7 @@ class TestHistoryRecall(TestBase):
mydir = TestBase.compute_mydir(__file__)
# If your test case doesn't stress debug info, the
# 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
@ -35,7 +35,7 @@ def sample_test(self):
result = lldb.SBCommandReturnObject()
interp.HandleCommand("command history", result, True)
interp.HandleCommand("platform list", result, True)
interp.HandleCommand("!0", result, False)
self.assertTrue(result.Succeeded(), "!0 command did not work: %s"%(result.GetError()))
self.assertTrue("command history" in result.GetOutput(), "!0 didn't rerun command history")

View File

@ -20,7 +20,7 @@ class LoadUnloadTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
@ -210,7 +210,7 @@ def test_dyld_library_path(self):
if not self.platformIsDarwin():
env_cmd_string += ":" + wd
self.runCmd(env_cmd_string)
# This time, the hidden library should be picked up.
self.expect("run", substrs=["return", "12345"])

View File

@ -20,7 +20,7 @@ class LoadUsingPathsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
@ -52,8 +52,8 @@ def test_load_using_paths(self):
# The directory with the dynamic library we did not link to.
path_dir = os.path.join(self.getBuildDir(), "hidden")
(target, process, thread,
_) = lldbutil.run_to_source_breakpoint(self,
(target, process, thread,
_) = lldbutil.run_to_source_breakpoint(self,
"Break here to do the load using paths",
lldb.SBFileSpec("main.cpp"))
error = lldb.SBError()
@ -63,18 +63,18 @@ def test_load_using_paths(self):
paths.AppendString(os.path.join(self.wd, "no_such_dir"))
out_spec = lldb.SBFileSpec()
# First try with no correct directories on the path, and make sure that doesn't blow up:
token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)
self.assertEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Only looked on the provided path.")
# Now add the correct dir to the paths list and try again:
paths.AppendString(self.hidden_dir)
token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)
self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token")
self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library")
# Make sure this really is in the image list:
loaded_module = target.FindModule(out_spec)
@ -89,11 +89,11 @@ def test_load_using_paths(self):
# Make sure the token works to unload it:
process.UnloadImage(token)
# Make sure this really is no longer in the image list:
# Make sure this really is no longer in the image list:
loaded_module = target.FindModule(out_spec)
self.assertFalse(loaded_module.IsValid(), "The unloaded module is no longer in the image list.")
# Make sure a relative path also works:
paths.Clear()
paths.AppendString(os.path.join(self.wd, "no_such_dir"))
@ -107,7 +107,7 @@ def test_load_using_paths(self):
self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library with relative path")
process.UnloadImage(token)
# Make sure the presence of an empty path doesn't mess anything up:
paths.Clear()
paths.AppendString("")
@ -122,7 +122,7 @@ def test_load_using_paths(self):
self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library with included empty path")
process.UnloadImage(token)
# Finally, passing in an absolute path should work like the basename:
@ -140,4 +140,4 @@ def test_load_using_paths(self):
self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token")
self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library")

View File

@ -35,4 +35,4 @@ def test(self):
self.assertTrue(found_it, "Couldn't find unlikely_to_occur_name in loaded libraries.")

View File

@ -81,7 +81,7 @@ def test(self):
self.expect(
"register read ymm" + str(i),
substrs=[pattern])
self.expect("continue", PROCESS_STOPPED, substrs=['stopped'])
# Check stop reason; Should be either signal SIGTRAP or EXC_BREAKPOINT

View File

@ -68,7 +68,7 @@ def test_with_python(self):
# Run again and we will stop in inner_sint the second time outer_sint is called.
# Then test stepping out two frames at once:
thread_list = lldbutil.continue_to_breakpoint(self.process, inner_sint_bkpt)
self.assertTrue(len(thread_list) == 1)
thread = thread_list[0]

View File

@ -90,7 +90,7 @@ def create_during_step_base(self, step_cmd, step_stop_reason):
target = self.dbg.GetSelectedTarget()
# This should create a breakpoint in the stepping thread.
self.bkpt = target.BreakpointCreateByLocation("main.cpp", self.breakpoint)
self.bkpt = target.BreakpointCreateByLocation("main.cpp", self.breakpoint)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)

View File

@ -92,7 +92,7 @@ def test_unique_stacks(self):
self.assertTrue(
num_threads >= 10,
'Number of expected threads and actual threads do not match.')
# Attempt to walk each of the thread's executing the thread3 function to
# the same breakpoint.
def is_thread3(thread):

View File

@ -61,7 +61,7 @@ def do_until (self, args, until_lines, expected_linenum):
cmd_line = "thread until"
for line_num in until_lines:
cmd_line += " %d"%(line_num)
cmd_interp.HandleCommand(cmd_line, ret_obj)
self.assertTrue(ret_obj.Succeeded(), "'%s' failed: %s."%(cmd_line, ret_obj.GetError()))

View File

@ -85,7 +85,7 @@ def test_multiple_watchpoints_on_same_word(self):
# Set a watchpoint at byteArray[3]
self.expect("watchpoint set variable byteArray[3]", WATCHPOINT_CREATED,
substrs=['Watchpoint created','size = 1'])
# Resume inferior.
self.runCmd("process continue")
@ -98,6 +98,6 @@ def test_multiple_watchpoints_on_same_word(self):
else:
self.expect("thread list -v", STOPPED_DUE_TO_WATCHPOINT,
substrs=['stopped', 'stop reason = watchpoint 3'])
# Resume inferior.
self.runCmd("process continue")

View File

@ -65,9 +65,9 @@ def do_test(self, test_enable):
wp.SetEnabled(False)
self.assertTrue(not wp.IsEnabled(), "The watchpoint thinks it is still enabled")
process.Continue()
stop_reason = thread.GetStopReason()
self.assertEqual(stop_reason, lldb.eStopReasonBreakpoint, "We didn't stop at our breakpoint.")
@ -78,4 +78,4 @@ def do_test(self, test_enable):
process.Continue()
stop_reason = thread.GetStopReason()
self.assertEqual(stop_reason, lldb.eStopReasonWatchpoint, "We didn't stop at our watchpoint")

View File

@ -17,7 +17,7 @@ class TestFindTypesOnStructType(TestBase):
mydir = TestBase.compute_mydir(__file__)
# If your test case doesn't stress debug info, the
# 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

View File

@ -18,7 +18,7 @@ class DynamicValueSameBaseTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
# If your test case doesn't stress debug info, the
# 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
@ -35,7 +35,7 @@ def setUp(self):
def sample_test(self):
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
"Break here to get started", self.main_source_file)
"Break here to get started", self.main_source_file)
# Set breakpoints in the two class methods and run to them:
namesp_bkpt = target.BreakpointCreateBySourceRegex("namesp function did something.", self.main_source_file)
@ -62,5 +62,5 @@ def sample_test(self):
virtual_type = virtual_this.GetType().GetUnqualifiedType()
self.assertEqual(virtual_type.GetName(), "Virtual *", "Didn't get the right dynamic type")

View File

@ -49,7 +49,7 @@ def get_test_frame(self, exe):
src_file = "main.cpp"
src_file_spec = lldb.SBFileSpec(src_file)
(target, process, thread, main_breakpoint) = lldbutil.run_to_source_breakpoint(self,
(target, process, thread, main_breakpoint) = lldbutil.run_to_source_breakpoint(self,
"break here", src_file_spec, exe_name = exe)
# Get frame for current thread
return thread.GetSelectedFrame()

View File

@ -4,4 +4,4 @@
lldbinline.MakeInlineTest(
__file__, globals(), [
decorators.expectedFailureAll(
oslist=["windows"], bugnumber="llvm.org/pr24764")])
oslist=["windows"], bugnumber="llvm.org/pr24764")])

View File

@ -18,7 +18,7 @@ def test_all_but_c(self):
@expectedFailureAll(oslist=["windows"])
def test_c(self):
self.do_test(True)
def do_test(self, test_c):
self.build()

View File

@ -53,14 +53,14 @@ def check_frame(self, thread):
options = lldb.SBExpressionOptions()
inVal_expr = frame.EvaluateExpression("inVal", options)
self.check_value(inVal_expr, 10)
thread.StepOut()
outVal_ret = thread.GetStopReturnValue()
self.check_value(outVal_ret, 30)
def expr_test(self, trivial):
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
"Set a breakpoint here", self.main_source_file)
"Set a breakpoint here", self.main_source_file)
# Stop in a function that takes a trivial value, and try both frame var & expr to get its value:
if trivial:

View File

@ -191,7 +191,7 @@ def evaluateDwarfExpression(self, dwarf_opcode, byte_order):
break
if val == DW_OP_regx:
# Read register number
# Read register number
self.assertTrue(len(dwarf_opcode) > (index + 1))
reg_no = int(dwarf_opcode.pop(index + 1), 16)
@ -201,7 +201,7 @@ def evaluateDwarfExpression(self, dwarf_opcode, byte_order):
["read packet: $p{0:x}#00".format(reg_no),
{"direction": "send", "regex": r"^\$([0-9a-fA-F]+)#",
"capture": {1: "p_response"}}],True)
Context = self.expect_gdbremote_sequence()
self.assertIsNotNone(Context)
p_response = Context.get("p_response")
@ -219,7 +219,7 @@ def evaluateDwarfExpression(self, dwarf_opcode, byte_order):
elif val == DW_OP_lit1:
# Push literal 1
dwarf_data.append(1)
elif val == DW_OP_lit26:
# Push literal 26
dwarf_data.append(26)

View File

@ -184,9 +184,10 @@ def CMD_MSG(str):
return "Command '%s' returns successfully" % str
def COMPLETION_MSG(str_before, str_after):
def COMPLETION_MSG(str_before, str_after, completions):
'''A generic message generator for the completion mechanism.'''
return "'%s' successfully completes to '%s'" % (str_before, str_after)
return ("'%s' successfully completes to '%s', but completions were:\n%s"
% (str_before, str_after, "\n".join(completions)))
def EXP_MSG(str, actual, exe):
@ -702,8 +703,8 @@ def getBuildDir(self):
"""Return the full path to the current test."""
return os.path.join(os.environ["LLDB_BUILD"], self.mydir,
self.getBuildDirBasename())
def makeBuildDir(self):
"""Create the test-specific working directory, deleting any previous
contents."""
@ -712,11 +713,11 @@ def makeBuildDir(self):
if os.path.isdir(bdir):
shutil.rmtree(bdir)
lldbutil.mkdir_p(bdir)
def getBuildArtifact(self, name="a.out"):
"""Return absolute path to an artifact in the test's build directory."""
return os.path.join(self.getBuildDir(), name)
def getSourcePath(self, name):
"""Return absolute path to a file in the test's source directory."""
return os.path.join(self.getSourceDir(), name)
@ -1844,7 +1845,7 @@ def generateSource(self, source):
temp = os.path.join(self.getSourceDir(), template)
with open(temp, 'r') as f:
content = f.read()
public_api_dir = os.path.join(
os.environ["LLDB_SRC"], "include", "lldb", "API")

View File

@ -740,7 +740,7 @@ def get_crashed_threads(test, process):
def run_to_breakpoint_make_target(test, exe_name, in_cwd):
if in_cwd:
exe = test.getBuildArtifact(exe_name)
# Create the target
target = test.dbg.CreateTarget(exe)
test.assertTrue(target, "Target: %s is not valid."%(exe_name))
@ -756,8 +756,8 @@ def run_to_breakpoint_do_run(test, target, bkpt, launch_info):
error = lldb.SBError()
process = target.Launch(launch_info, error)
test.assertTrue(process,
"Could not create a valid process for %s: %s"%(target.GetExecutable().GetFilename(),
test.assertTrue(process,
"Could not create a valid process for %s: %s"%(target.GetExecutable().GetFilename(),
error.GetCString()))
# Frame #0 should be at our breakpoint.
@ -768,7 +768,7 @@ def run_to_breakpoint_do_run(test, target, bkpt, launch_info):
thread = threads[0]
return (target, process, thread, bkpt)
def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
exe_name = "a.out",
bkpt_module = None,
in_cwd = True):
@ -818,7 +818,7 @@ def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
# Set the breakpoints
breakpoint = target.BreakpointCreateBySourceRegex(
bkpt_pattern, source_spec, bkpt_module)
test.assertTrue(breakpoint.GetNumLocations() > 0,
test.assertTrue(breakpoint.GetNumLocations() > 0,
'No locations found for source breakpoint: "%s", file: "%s", dir: "%s"'%(bkpt_pattern, source_spec.GetFilename(), source_spec.GetDirectory()))
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info)

View File

@ -55,12 +55,12 @@ def find_app_in_bundle_test(self):
error = lldb.SBError()
process = target.Launch(launch_info, error)
self.assertTrue(process.IsValid(), "Could not create a valid process for TestApp: %s"%(error.GetCString()))
# Frame #0 should be at our breakpoint.
threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
self.assertTrue(len(threads) == 1, "Expected 1 thread to stop at breakpoint, %d did."%(len(threads)))

View File

@ -47,7 +47,7 @@ def test_attach_and_check_dsyms(self):
sleep(5)
# Since the library that was dlopen()'ed is now removed, lldb will need to find the
# binary & dSYM via target.exec-search-paths
# binary & dSYM via target.exec-search-paths
settings_str = "settings set target.exec-search-paths " + self.get_process_working_directory() + "/hide.app"
self.runCmd(settings_str)

View File

@ -46,7 +46,7 @@ def test_attach_and_check_dsyms(self):
sleep(5)
# Since the library that was dlopen()'ed is now removed, lldb will need to find the
# binary & dSYM via target.exec-search-paths
# binary & dSYM via target.exec-search-paths
settings_str = "settings set target.exec-search-paths " + self.get_process_working_directory() + "/hide.app"
self.runCmd(settings_str)
self.runCmd("process attach -p " + str(popen.pid))
@ -67,7 +67,7 @@ def test_attach_and_check_dsyms(self):
dsym_name = mod.GetSymbolFileSpec().GetFilename()
self.assertTrue (dsym_name == 'MyFramework', "Check that we found the dSYM for the bundle that was loaded")
i=i+1
self.assertTrue(found_module, "Check that we found the framework loaded in lldb's image list")
if __name__ == '__main__':

View File

@ -1,4 +1,4 @@
"""Test that we get thread names when interrupting a process."""
"""Test that we get thread names when interrupting a process."""
from __future__ import print_function
@ -63,7 +63,7 @@ def test_with_python_api(self):
process.Kill()
# The process will set a global variable 'threads_up_and_running' to 1 when
# The process will set a global variable 'threads_up_and_running' to 1 when
# it has has completed its setup. Sleep for one second, pause the program,
# check to see if the global has that value, and continue if it does not.
def wait_until_program_setup_complete(self, process, listener):
@ -107,7 +107,7 @@ def wait_for_running(self, process, listener):
return False
# Listen to the process events until we get an event saying the process is
# stopped. Retry up to five times in case we get other events that we are
# stopped. Retry up to five times in case we get other events that we are
# not looking for.
def wait_for_stop(self, process, listener):
retry_count = 5

View File

@ -23,7 +23,7 @@ class TestNameLookup(TestBase):
@expectedFailureAll(oslist=["windows"], bugnumber='llvm.org/pr21765')
def test_target(self):
"""Exercise SBTarget.FindFunctions() with various name masks.
A previous regression caused mangled names to not be able to be looked up.
This test verifies that using a mangled name with eFunctionNameTypeFull works
and that using a function basename with eFunctionNameTypeFull works for all
@ -36,7 +36,7 @@ def test_target(self):
self.assertTrue(target, VALID_TARGET)
exe_module = target.FindModule(target.GetExecutable())
c_name_to_symbol = {}
cpp_name_to_symbol = {}
mangled_to_symbol = {}
@ -54,7 +54,7 @@ def test_target(self):
c_name_to_symbol[name] = symbol
# Make sure each mangled name turns up exactly one match when looking up
# functions by full name and using the mangled name as the name in the
# functions by full name and using the mangled name as the name in the
# lookup
self.assertGreaterEqual(len(mangled_to_symbol), 6)
for mangled in mangled_to_symbol.keys():
@ -63,5 +63,5 @@ def test_target(self):
for symbol_context in symbol_contexts:
self.assertTrue(symbol_context.GetFunction().IsValid())
self.assertTrue(symbol_context.GetSymbol().IsValid())

View File

@ -23,7 +23,7 @@ def setUp(self):
@add_test_categories(['pyapi'])
def test_byte_order_and_address_byte_size(self):
"""Test the SBData::SetData() to ensure the byte order and address
"""Test the SBData::SetData() to ensure the byte order and address
byte size are obeyed"""
addr_data = b'\x11\x22\x33\x44\x55\x66\x77\x88'
error = lldb.SBError()

View File

@ -17,7 +17,7 @@ class RenameThisSampleTestTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
# If your test case doesn't stress debug info, the
# 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
@ -40,7 +40,7 @@ def sample_test(self):
# It optionally takes an SBLaunchOption argument if you want to pass
# arguments or environment variables.
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
"Set a breakpoint here", self.main_source_file)
"Set a breakpoint here", self.main_source_file)
frame = thread.GetFrameAtIndex(0)
test_var = frame.FindVariable("test_var")

View File

@ -528,7 +528,7 @@ def test_all_settings_exist(self):
# settings under an ".experimental" domain should have two properties:
# 1. If the name does not exist with "experimental" in the name path,
# the name lookup should try to find it without "experimental". So
# a previously-experimental setting that has been promoted to a
# a previously-experimental setting that has been promoted to a
# "real" setting will still be set by the original name.
# 2. Changing a setting with .experimental., name, where the setting
# does not exist either with ".experimental." or without, should

View File

@ -139,7 +139,7 @@ def copyScript(self, sourceFile):
with open(destFile, 'w+') as dest:
dest.write(src.read().replace("a.out", self.myexe))
return destFile
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races

View File

@ -16,7 +16,7 @@ class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase):
THREAD_COUNT = 5
@skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
@skipIfDarwinEmbedded # <rdar://problem/27005337>
@skipIfDarwinEmbedded # <rdar://problem/27005337>
def gather_stop_replies_via_qThreadStopInfo(self, thread_count):
# Set up the inferior args.
inferior_args = []

View File

@ -1162,7 +1162,7 @@ def breakpoint_set_and_remove_work(self, want_hardware=False):
BREAKPOINT_KIND = 1
# Set default packet type to Z0 (software breakpoint)
z_packet_type = 0
z_packet_type = 0
# If hardware breakpoint is requested set packet type to Z1
if want_hardware == True:

View File

@ -90,7 +90,7 @@ int CommandCompletions::SourceFiles(CommandInterpreter &interpreter,
} else {
completer.DoCompletion(searcher);
}
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
static int DiskFilesOrDirectories(const llvm::Twine &partial_name,
@ -103,7 +103,7 @@ static int DiskFilesOrDirectories(const llvm::Twine &partial_name,
partial_name.toVector(CompletionBuffer);
if (CompletionBuffer.size() >= PATH_MAX)
return 0;
return matches.GetSize();
namespace fs = llvm::sys::fs;
namespace path = llvm::sys::path;
@ -145,7 +145,7 @@ static int DiskFilesOrDirectories(const llvm::Twine &partial_name,
// Make sure it ends with a separator.
path::append(CompletionBuffer, path::get_separator());
matches.AppendString(CompletionBuffer);
return 1;
return matches.GetSize();
}
// We want to keep the form the user typed, so we special case this to
@ -224,13 +224,21 @@ static int DiskFilesOrDirectories(const llvm::Twine &partial_name,
return matches.GetSize();
}
static int DiskFilesOrDirectories(CompletionRequest &request,
bool only_directories) {
request.SetWordComplete(false);
StandardTildeExpressionResolver resolver;
StringList matches;
DiskFilesOrDirectories(request.GetCursorArgumentPrefix(), only_directories,
matches, resolver);
request.AddCompletions(matches);
return request.GetNumberOfMatches();
}
int CommandCompletions::DiskFiles(CommandInterpreter &interpreter,
CompletionRequest &request,
SearchFilter *searcher) {
request.SetWordComplete(false);
StandardTildeExpressionResolver Resolver;
return DiskFiles(request.GetCursorArgumentPrefix(), request.GetMatches(),
Resolver);
return DiskFilesOrDirectories(request, /*only_dirs*/ false);
}
int CommandCompletions::DiskFiles(const llvm::Twine &partial_file_name,
@ -242,10 +250,7 @@ int CommandCompletions::DiskFiles(const llvm::Twine &partial_file_name,
int CommandCompletions::DiskDirectories(CommandInterpreter &interpreter,
CompletionRequest &request,
SearchFilter *searcher) {
request.SetWordComplete(false);
StandardTildeExpressionResolver Resolver;
return DiskDirectories(request.GetCursorArgumentPrefix(),
request.GetMatches(), Resolver);
return DiskFilesOrDirectories(request, /*only_dirs*/ true);
}
int CommandCompletions::DiskDirectories(const llvm::Twine &partial_file_name,
@ -267,7 +272,7 @@ int CommandCompletions::Modules(CommandInterpreter &interpreter,
} else {
completer.DoCompletion(searcher);
}
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
int CommandCompletions::Symbols(CommandInterpreter &interpreter,
@ -283,7 +288,7 @@ int CommandCompletions::Symbols(CommandInterpreter &interpreter,
} else {
completer.DoCompletion(searcher);
}
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
int CommandCompletions::SettingsNames(CommandInterpreter &interpreter,
@ -304,20 +309,23 @@ int CommandCompletions::SettingsNames(CommandInterpreter &interpreter,
}
size_t exact_matches_idx = SIZE_MAX;
const size_t num_matches =
g_property_names.AutoComplete(request.GetCursorArgumentPrefix(),
request.GetMatches(), exact_matches_idx);
StringList matches;
g_property_names.AutoComplete(request.GetCursorArgumentPrefix(), matches,
exact_matches_idx);
request.SetWordComplete(exact_matches_idx != SIZE_MAX);
return num_matches;
request.AddCompletions(matches);
return request.GetNumberOfMatches();
}
int CommandCompletions::PlatformPluginNames(CommandInterpreter &interpreter,
CompletionRequest &request,
SearchFilter *searcher) {
const uint32_t num_matches = PluginManager::AutoCompletePlatformName(
request.GetCursorArgumentPrefix(), request.GetMatches());
StringList new_matches;
std::size_t num_matches = PluginManager::AutoCompletePlatformName(
request.GetCursorArgumentPrefix(), new_matches);
request.SetWordComplete(num_matches == 1);
return num_matches;
request.AddCompletions(new_matches);
return request.GetNumberOfMatches();
}
int CommandCompletions::ArchitectureNames(CommandInterpreter &interpreter,
@ -409,10 +417,10 @@ CommandCompletions::SourceFileCompleter::DoCompletion(SearchFilter *filter) {
filter->Search(*this);
// Now convert the filelist to completions:
for (size_t i = 0; i < m_matching_files.GetSize(); i++) {
m_request.GetMatches().AppendString(
m_request.AddCompletion(
m_matching_files.GetFileSpecAtIndex(i).GetFilename().GetCString());
}
return m_request.GetMatches().GetSize();
return m_request.GetNumberOfMatches();
}
//----------------------------------------------------------------------
@ -478,9 +486,9 @@ size_t CommandCompletions::SymbolCompleter::DoCompletion(SearchFilter *filter) {
filter->Search(*this);
collection::iterator pos = m_match_set.begin(), end = m_match_set.end();
for (pos = m_match_set.begin(); pos != end; pos++)
m_request.GetMatches().AppendString((*pos).GetCString());
m_request.AddCompletion((*pos).GetCString());
return m_request.GetMatches().GetSize();
return m_request.GetNumberOfMatches();
}
//----------------------------------------------------------------------
@ -517,7 +525,7 @@ Searcher::CallbackReturn CommandCompletions::ModuleCompleter::SearchCallback(
match = false;
if (match) {
m_request.GetMatches().AppendString(cur_file_name);
m_request.AddCompletion(cur_file_name);
}
}
return Searcher::eCallbackReturnContinue;
@ -525,5 +533,5 @@ Searcher::CallbackReturn CommandCompletions::ModuleCompleter::SearchCallback(
size_t CommandCompletions::ModuleCompleter::DoCompletion(SearchFilter *filter) {
filter->Search(*this);
return m_request.GetMatches().GetSize();
return m_request.GetNumberOfMatches();
}

View File

@ -241,7 +241,7 @@ class CommandObjectCommandsSource : public CommandObjectParsed {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
Options *GetOptions() override { return &m_options; }
@ -1429,7 +1429,7 @@ class CommandObjectCommandsScriptImport : public CommandObjectParsed {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
Options *GetOptions() override { return &m_options; }

View File

@ -470,7 +470,7 @@ class CommandObjectFrameVariable : public CommandObjectParsed {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eVariablePathCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:

View File

@ -143,7 +143,7 @@ bool CommandObjectMultiword::Execute(const char *args_string,
if (num_subcmd_matches > 0) {
error_msg.append(" Possible completions:");
for (size_t i = 0; i < num_subcmd_matches; i++) {
for (size_t i = 0; i < matches.GetSize(); i++) {
error_msg.append("\n\t");
error_msg.append(matches.GetStringAtIndex(i));
}
@ -190,21 +190,22 @@ int CommandObjectMultiword::HandleCompletion(CompletionRequest &request) {
// Any of the command matches will provide a complete word, otherwise the
// individual completers will override this.
request.SetWordComplete(true);
auto &matches = request.GetMatches();
auto arg0 = request.GetParsedLine()[0].ref;
if (request.GetCursorIndex() == 0) {
AddNamesMatchingPartialString(m_subcommand_dict, arg0, matches);
StringList new_matches;
AddNamesMatchingPartialString(m_subcommand_dict, arg0, new_matches);
request.AddCompletions(new_matches);
if (matches.GetSize() == 1 && matches.GetStringAtIndex(0) != nullptr &&
(arg0 == matches.GetStringAtIndex(0))) {
if (new_matches.GetSize() == 1 &&
new_matches.GetStringAtIndex(0) != nullptr &&
(arg0 == new_matches.GetStringAtIndex(0))) {
StringList temp_matches;
CommandObject *cmd_obj = GetSubcommandObject(arg0, &temp_matches);
if (cmd_obj != nullptr) {
if (request.GetParsedLine().GetArgumentCount() == 1) {
request.SetWordComplete(true);
} else {
matches.DeleteStringAtIndex(0);
request.GetParsedLine().Shift();
request.SetCursorCharPosition(0);
request.GetParsedLine().AppendArgument(llvm::StringRef());
@ -212,14 +213,17 @@ int CommandObjectMultiword::HandleCompletion(CompletionRequest &request) {
}
}
}
return matches.GetSize();
return new_matches.GetSize();
} else {
CommandObject *sub_command_object = GetSubcommandObject(arg0, &matches);
StringList new_matches;
CommandObject *sub_command_object = GetSubcommandObject(arg0, &new_matches);
if (sub_command_object == nullptr) {
return matches.GetSize();
request.AddCompletions(new_matches);
return request.GetNumberOfMatches();
} else {
// Remove the one match that we got from calling GetSubcommandObject.
matches.DeleteStringAtIndex(0);
new_matches.DeleteStringAtIndex(0);
request.AddCompletions(new_matches);
request.GetParsedLine().Shift();
request.SetCursorIndex(request.GetCursorIndex() - 1);
return sub_command_object->HandleCompletion(request);
@ -366,7 +370,6 @@ int CommandObjectProxy::HandleCompletion(CompletionRequest &request) {
CommandObject *proxy_command = GetProxyCommandObject();
if (proxy_command)
return proxy_command->HandleCompletion(request);
request.GetMatches().Clear();
return 0;
}
@ -375,7 +378,6 @@ int CommandObjectProxy::HandleArgumentCompletion(
CommandObject *proxy_command = GetProxyCommandObject();
if (proxy_command)
return proxy_command->HandleArgumentCompletion(request, opt_element_vector);
request.GetMatches().Clear();
return 0;
}

View File

@ -181,7 +181,7 @@ class CommandObjectPlatformSelect : public CommandObjectParsed {
int HandleCompletion(CompletionRequest &request) override {
CommandCompletions::PlatformPluginNames(GetCommandInterpreter(), request,
nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
Options *GetOptions() override { return &m_option_group; }
@ -1583,9 +1583,9 @@ class CommandObjectPlatformProcessAttach : public CommandObjectParsed {
const uint32_t num_matches = process_infos.GetSize();
if (num_matches > 0) {
for (uint32_t i = 0; i < num_matches; ++i) {
request.GetMatches().AppendString(
request.AddCompletion(llvm::StringRef(
process_infos.GetProcessNameAtIndex(i),
process_infos.GetProcessNameLengthAtIndex(i));
process_infos.GetProcessNameLengthAtIndex(i)));
}
}
}

View File

@ -48,7 +48,7 @@ class CommandObjectPluginLoad : public CommandObjectParsed {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:

View File

@ -141,7 +141,7 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
Options *GetOptions() override { return &m_options; }
@ -410,9 +410,9 @@ class CommandObjectProcessAttach : public CommandObjectProcessLaunchOrAttach {
const size_t num_matches = process_infos.GetSize();
if (num_matches > 0) {
for (size_t i = 0; i < num_matches; ++i) {
request.GetMatches().AppendString(
request.AddCompletion(llvm::StringRef(
process_infos.GetProcessNameAtIndex(i),
process_infos.GetProcessNameLengthAtIndex(i));
process_infos.GetProcessNameLengthAtIndex(i)));
}
}
}

View File

@ -172,7 +172,7 @@ insert-before or insert-after.");
}
}
}
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:
@ -272,7 +272,7 @@ class CommandObjectSettingsShow : public CommandObjectParsed {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:
@ -338,7 +338,7 @@ class CommandObjectSettingsList : public CommandObjectParsed {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:
@ -427,7 +427,7 @@ class CommandObjectSettingsRemove : public CommandObjectRaw {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:
@ -544,7 +544,7 @@ class CommandObjectSettingsReplace : public CommandObjectRaw {
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:
@ -644,7 +644,7 @@ class CommandObjectSettingsInsertBefore : public CommandObjectRaw {
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:
@ -749,7 +749,7 @@ class CommandObjectSettingsInsertAfter : public CommandObjectRaw {
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:
@ -843,7 +843,7 @@ class CommandObjectSettingsAppend : public CommandObjectRaw {
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:
@ -924,7 +924,7 @@ class CommandObjectSettingsClear : public CommandObjectParsed {
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:

View File

@ -201,7 +201,7 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:
@ -1810,7 +1810,7 @@ class CommandObjectTargetModulesModuleAutoComplete
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eModuleCompletion, request,
nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
};
@ -1851,7 +1851,7 @@ class CommandObjectTargetModulesSourceFileAutoComplete
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSourceFileCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
};
@ -2393,7 +2393,7 @@ class CommandObjectTargetModulesAdd : public CommandObjectParsed {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
protected:
@ -3987,7 +3987,7 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
Options *GetOptions() override { return &m_option_group; }

View File

@ -2350,7 +2350,6 @@ size_t FormatEntity::AutoComplete(CompletionRequest &request) {
request.SetWordComplete(false);
str = str.drop_front(request.GetMatchStartPoint());
request.GetMatches().Clear();
const size_t dollar_pos = str.rfind('$');
if (dollar_pos == llvm::StringRef::npos)
@ -2360,7 +2359,7 @@ size_t FormatEntity::AutoComplete(CompletionRequest &request) {
if (dollar_pos == str.size() - 1) {
std::string match = str.str();
match.append("{");
request.GetMatches().AppendString(match);
request.AddCompletion(match);
return 1;
}
@ -2378,8 +2377,10 @@ size_t FormatEntity::AutoComplete(CompletionRequest &request) {
llvm::StringRef partial_variable(str.substr(dollar_pos + 2));
if (partial_variable.empty()) {
// Suggest all top level entites as we are just past "${"
AddMatches(&g_root, str, llvm::StringRef(), request.GetMatches());
return request.GetMatches().GetSize();
StringList new_matches;
AddMatches(&g_root, str, llvm::StringRef(), new_matches);
request.AddCompletions(new_matches);
return request.GetNumberOfMatches();
}
// We have a partially specified variable, find it
@ -2395,19 +2396,23 @@ size_t FormatEntity::AutoComplete(CompletionRequest &request) {
// Exact match
if (n > 0) {
// "${thread.info" <TAB>
request.GetMatches().AppendString(MakeMatch(str, "."));
request.AddCompletion(MakeMatch(str, "."));
} else {
// "${thread.id" <TAB>
request.GetMatches().AppendString(MakeMatch(str, "}"));
request.AddCompletion(MakeMatch(str, "}"));
request.SetWordComplete(true);
}
} else if (remainder.equals(".")) {
// "${thread." <TAB>
AddMatches(entry_def, str, llvm::StringRef(), request.GetMatches());
StringList new_matches;
AddMatches(entry_def, str, llvm::StringRef(), new_matches);
request.AddCompletions(new_matches);
} else {
// We have a partial match
// "${thre" <TAB>
AddMatches(entry_def, str, remainder, request.GetMatches());
StringList new_matches;
AddMatches(entry_def, str, remainder, new_matches);
request.AddCompletions(new_matches);
}
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}

View File

@ -245,10 +245,10 @@ int IOHandlerDelegate::IOHandlerComplete(IOHandler &io_handler,
io_handler.GetDebugger().GetCommandInterpreter(),
CommandCompletions::eVariablePathCompletion, request, nullptr);
size_t num_matches = request.GetMatches().GetSize();
size_t num_matches = request.GetNumberOfMatches();
if (num_matches > 0) {
std::string common_prefix;
request.GetMatches().LongestCommonPrefix(common_prefix);
matches.LongestCommonPrefix(common_prefix);
const size_t partial_name_len = request.GetCursorArgumentPrefix().size();
// If we matched a unique single command, add a space... Only do this if

View File

@ -478,7 +478,7 @@ void CommandInterpreter::LoadCommandDictionary() {
std::unique_ptr<CommandObjectRegexCommand> break_regex_cmd_ap(
new CommandObjectRegexCommand(
*this, "_regexp-break",
"Set a breakpoint using one of several shorthand formats.\n",
"Set a breakpoint using one of several shorthand formats.",
"\n"
"_regexp-break <filename>:<linenum>\n"
" main.c:12 // Break at line 12 of "
@ -527,7 +527,7 @@ void CommandInterpreter::LoadCommandDictionary() {
std::unique_ptr<CommandObjectRegexCommand> tbreak_regex_cmd_ap(
new CommandObjectRegexCommand(
*this, "_regexp-tbreak",
"Set a one-shot breakpoint using one of several shorthand formats.\n",
"Set a one-shot breakpoint using one of several shorthand formats.",
"\n"
"_regexp-break <filename>:<linenum>\n"
" main.c:12 // Break at line 12 of "
@ -1703,7 +1703,6 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
}
int CommandInterpreter::HandleCompletionMatches(CompletionRequest &request) {
auto &matches = request.GetMatches();
int num_command_matches = 0;
bool look_for_subcommand = false;
@ -1713,30 +1712,34 @@ int CommandInterpreter::HandleCompletionMatches(CompletionRequest &request) {
if (request.GetCursorIndex() == -1) {
// We got nothing on the command line, so return the list of commands
bool include_aliases = true;
StringList new_matches;
num_command_matches =
GetCommandNamesMatchingPartialString("", include_aliases, matches);
GetCommandNamesMatchingPartialString("", include_aliases, new_matches);
request.AddCompletions(new_matches);
} else if (request.GetCursorIndex() == 0) {
// The cursor is in the first argument, so just do a lookup in the
// dictionary.
StringList new_matches;
CommandObject *cmd_obj = GetCommandObject(
request.GetParsedLine().GetArgumentAtIndex(0), &matches);
num_command_matches = matches.GetSize();
request.GetParsedLine().GetArgumentAtIndex(0), &new_matches);
if (num_command_matches == 1 && cmd_obj && cmd_obj->IsMultiwordObject() &&
matches.GetStringAtIndex(0) != nullptr &&
new_matches.GetStringAtIndex(0) != nullptr &&
strcmp(request.GetParsedLine().GetArgumentAtIndex(0),
matches.GetStringAtIndex(0)) == 0) {
new_matches.GetStringAtIndex(0)) == 0) {
if (request.GetParsedLine().GetArgumentCount() == 1) {
request.SetWordComplete(true);
} else {
look_for_subcommand = true;
num_command_matches = 0;
matches.DeleteStringAtIndex(0);
new_matches.DeleteStringAtIndex(0);
request.GetParsedLine().AppendArgument(llvm::StringRef());
request.SetCursorIndex(request.GetCursorIndex() + 1);
request.SetCursorCharPosition(0);
}
}
request.AddCompletions(new_matches);
num_command_matches = request.GetNumberOfMatches();
}
if (request.GetCursorIndex() > 0 || look_for_subcommand) {
@ -1773,8 +1776,7 @@ int CommandInterpreter::HandleCompletion(
return 0;
else if (first_arg[0] == CommandHistory::g_repeat_char) {
if (auto hist_str = m_command_history.FindString(first_arg)) {
request.GetMatches().Clear();
request.GetMatches().InsertStringAtIndex(0, *hist_str);
matches.InsertStringAtIndex(0, *hist_str);
return -2;
} else
return 0;
@ -1812,7 +1814,7 @@ int CommandInterpreter::HandleCompletion(
common_prefix.push_back(quote_char);
common_prefix.push_back(' ');
}
request.GetMatches().InsertStringAtIndex(0, common_prefix.c_str());
matches.InsertStringAtIndex(0, common_prefix.c_str());
}
return num_command_matches;
}

View File

@ -267,7 +267,6 @@ int CommandObject::HandleCompletion(CompletionRequest &request) {
if (WantsRawCommandString() && !WantsCompletion()) {
// FIXME: Abstract telling the completion to insert the completion
// character.
request.GetMatches().Clear();
return -1;
} else {
// Can we do anything generic with the options?
@ -282,7 +281,7 @@ int CommandObject::HandleCompletion(CompletionRequest &request) {
bool handled_by_options = cur_options->HandleOptionCompletion(
request, opt_element_vector, GetCommandInterpreter());
if (handled_by_options)
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
// If we got here, the last word is not an option or an option argument.

View File

@ -97,9 +97,8 @@ int CommandObjectRegexCommand::HandleCompletion(CompletionRequest &request) {
if (m_completion_type_mask) {
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), m_completion_type_mask, request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
} else {
request.GetMatches().Clear();
request.SetWordComplete(false);
}
return 0;

View File

@ -575,8 +575,7 @@ bool OptionValue::DumpQualifiedName(Stream &strm) const {
size_t OptionValue::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
request.SetWordComplete(false);
request.GetMatches().Clear();
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
Status OptionValue::SetValueFromString(llvm::StringRef value,

View File

@ -76,9 +76,8 @@ lldb::OptionValueSP OptionValueArch::DeepCopy() const {
size_t OptionValueArch::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
request.SetWordComplete(false);
request.GetMatches().Clear();
CommandCompletions::InvokeCommonCompletionCallbacks(
interpreter, CommandCompletions::eArchitectureCompletion, request,
nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}

View File

@ -79,7 +79,6 @@ lldb::OptionValueSP OptionValueBoolean::DeepCopy() const {
size_t OptionValueBoolean::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
request.SetWordComplete(false);
request.GetMatches().Clear();
static const llvm::StringRef g_autocomplete_entries[] = {
"true", "false", "on", "off", "yes", "no", "1", "0"};
@ -91,7 +90,7 @@ size_t OptionValueBoolean::AutoComplete(CommandInterpreter &interpreter,
for (auto entry : entries) {
if (entry.startswith_lower(request.GetCursorArgumentPrefix()))
request.GetMatches().AppendString(entry);
request.AddCompletion(entry);
}
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}

View File

@ -112,20 +112,18 @@ lldb::OptionValueSP OptionValueEnumeration::DeepCopy() const {
size_t OptionValueEnumeration::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
request.SetWordComplete(false);
request.GetMatches().Clear();
const uint32_t num_enumerators = m_enumerations.GetSize();
if (!request.GetCursorArgumentPrefix().empty()) {
for (size_t i = 0; i < num_enumerators; ++i) {
llvm::StringRef name = m_enumerations.GetCStringAtIndex(i).GetStringRef();
if (name.startswith(request.GetCursorArgumentPrefix()))
request.GetMatches().AppendString(name);
request.AddCompletion(name);
}
} else {
// only suggest "true" or "false" by default
for (size_t i = 0; i < num_enumerators; ++i)
request.GetMatches().AppendString(
m_enumerations.GetCStringAtIndex(i).GetStringRef());
request.AddCompletion(m_enumerations.GetCStringAtIndex(i).GetStringRef());
}
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}

View File

@ -102,10 +102,9 @@ lldb::OptionValueSP OptionValueFileSpec::DeepCopy() const {
size_t OptionValueFileSpec::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
request.SetWordComplete(false);
request.GetMatches().Clear();
CommandCompletions::InvokeCommonCompletionCallbacks(
interpreter, m_completion_mask, request, nullptr);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
const lldb::DataBufferSP &OptionValueFileSpec::GetFileContents() {

View File

@ -70,7 +70,6 @@ lldb::OptionValueSP OptionValueUUID::DeepCopy() const {
size_t OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
request.SetWordComplete(false);
request.GetMatches().Clear();
ExecutionContext exe_ctx(interpreter.GetExecutionContext());
Target *target = exe_ctx.GetTargetPtr();
if (target) {
@ -86,12 +85,12 @@ size_t OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
llvm::ArrayRef<uint8_t> module_bytes = module_uuid.GetBytes();
if (module_bytes.size() >= uuid_bytes.size() &&
module_bytes.take_front(uuid_bytes.size()).equals(uuid_bytes)) {
request.GetMatches().AppendString(module_uuid.GetAsString());
request.AddCompletion(module_uuid.GetAsString());
}
}
}
}
}
}
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}

View File

@ -680,7 +680,7 @@ bool Options::HandleOptionCompletion(CompletionRequest &request,
if (!def.short_option)
continue;
opt_str[1] = def.short_option;
request.GetMatches().AppendString(opt_str);
request.AddCompletion(opt_str);
}
return true;
@ -692,7 +692,7 @@ bool Options::HandleOptionCompletion(CompletionRequest &request,
full_name.erase(full_name.begin() + 2, full_name.end());
full_name.append(def.long_option);
request.GetMatches().AppendString(full_name.c_str());
request.AddCompletion(full_name.c_str());
}
return true;
} else if (opt_defs_index != OptionArgElement::eUnrecognizedArg) {
@ -705,10 +705,10 @@ bool Options::HandleOptionCompletion(CompletionRequest &request,
strcmp(opt_defs[opt_defs_index].long_option, cur_opt_str) != 0) {
std::string full_name("--");
full_name.append(opt_defs[opt_defs_index].long_option);
request.GetMatches().AppendString(full_name.c_str());
request.AddCompletion(full_name.c_str());
return true;
} else {
request.GetMatches().AppendString(request.GetCursorArgument());
request.AddCompletion(request.GetCursorArgument());
return true;
}
} else {
@ -728,17 +728,7 @@ bool Options::HandleOptionCompletion(CompletionRequest &request,
if (strstr(def.long_option, cur_opt_str + 2) == def.long_option) {
std::string full_name("--");
full_name.append(def.long_option);
// The options definitions table has duplicates because of the
// way the grouping information is stored, so only add once.
bool duplicate = false;
for (size_t k = 0; k < request.GetMatches().GetSize(); k++) {
if (request.GetMatches().GetStringAtIndex(k) == full_name) {
duplicate = true;
break;
}
}
if (!duplicate)
request.GetMatches().AppendString(full_name.c_str());
request.AddCompletion(full_name.c_str());
}
}
}
@ -790,7 +780,7 @@ bool Options::HandleOptionArgumentCompletion(
for (int i = 0; enum_values[i].string_value != nullptr; i++) {
if (strstr(enum_values[i].string_value, match_string.c_str()) ==
enum_values[i].string_value) {
request.GetMatches().AppendString(enum_values[i].string_value);
request.AddCompletion(enum_values[i].string_value);
return_value = true;
}
}

View File

@ -83,9 +83,9 @@ PlatformSP PlatformAndroid::CreateInstance(bool force, const ArchSpec *arch) {
break;
#if defined(__ANDROID__)
// Only accept "unknown" for the vendor if the host is android and it
// Only accept "unknown" for the vendor if the host is android and if
// "unknown" wasn't specified (it was just returned because it was NOT
// specified_
// specified).
case llvm::Triple::VendorType::UnknownVendor:
create = !arch->TripleVendorWasSpecified();
break;
@ -95,7 +95,7 @@ PlatformSP PlatformAndroid::CreateInstance(bool force, const ArchSpec *arch) {
}
if (create) {
switch (triple.getOS()) {
switch (triple.getEnvironment()) {
case llvm::Triple::Android:
break;
@ -103,8 +103,8 @@ PlatformSP PlatformAndroid::CreateInstance(bool force, const ArchSpec *arch) {
// Only accept "unknown" for the OS if the host is android and it
// "unknown" wasn't specified (it was just returned because it was NOT
// specified)
case llvm::Triple::OSType::UnknownOS:
create = !arch->TripleOSWasSpecified();
case llvm::Triple::EnvironmentType::UnknownEnvironment:
create = !arch->TripleEnvironmentWasSpecified();
break;
#endif
default:

View File

@ -78,7 +78,7 @@ PlatformSP PlatformWindows::CreateInstance(bool force,
create = true;
break;
case llvm::Triple::UnknownArch:
case llvm::Triple::UnknownVendor:
create = !arch->TripleVendorWasSpecified();
break;

View File

@ -13,8 +13,6 @@
#include "DWARFUnit.h"
class DWARFCompileUnit : public DWARFUnit {
friend class DWARFUnit;
public:
static DWARFUnitSP Extract(SymbolFileDWARF *dwarf2Data,
const lldb_private::DWARFDataExtractor &debug_info,

View File

@ -33,8 +33,6 @@ enum DWARFProducer {
};
class DWARFUnit {
friend class DWARFCompileUnit;
using die_iterator_range =
llvm::iterator_range<DWARFDebugInfoEntry::collection::iterator>;

View File

@ -644,11 +644,12 @@ static void PrivateAutoComplete(
break;
case '-':
if (partial_path[1] == '>' && !prefix_path.str().empty()) {
if (partial_path.size() > 1 && partial_path[1] == '>' &&
!prefix_path.str().empty()) {
switch (type_class) {
case lldb::eTypeClassPointer: {
CompilerType pointee_type(compiler_type.GetPointeeType());
if (partial_path[2]) {
if (partial_path.size() > 2 && partial_path[2]) {
// If there is more after the "->", then search deeper
PrivateAutoComplete(
frame, partial_path.substr(2), prefix_path + "->",
@ -672,7 +673,7 @@ static void PrivateAutoComplete(
case lldb::eTypeClassUnion:
case lldb::eTypeClassStruct:
case lldb::eTypeClassClass:
if (partial_path[1]) {
if (partial_path.size() > 1 && partial_path[1]) {
// If there is more after the ".", then search deeper
PrivateAutoComplete(frame, partial_path.substr(1),
prefix_path + ".", compiler_type, matches,
@ -760,9 +761,11 @@ size_t Variable::AutoComplete(const ExecutionContext &exe_ctx,
CompilerType compiler_type;
bool word_complete = false;
StringList matches;
PrivateAutoComplete(exe_ctx.GetFramePtr(), request.GetCursorArgumentPrefix(),
"", compiler_type, request.GetMatches(), word_complete);
"", compiler_type, matches, word_complete);
request.SetWordComplete(word_complete);
request.AddCompletions(matches);
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}

View File

@ -255,12 +255,14 @@ size_t ArchSpec::AutoComplete(CompletionRequest &request) {
for (uint32_t i = 0; i < llvm::array_lengthof(g_core_definitions); ++i) {
if (NameMatches(g_core_definitions[i].name, NameMatch::StartsWith,
request.GetCursorArgumentPrefix()))
request.GetMatches().AppendString(g_core_definitions[i].name);
request.AddCompletion(g_core_definitions[i].name);
}
} else {
ListSupportedArchNames(request.GetMatches());
StringList matches;
ListSupportedArchNames(matches);
request.AddCompletions(matches);
}
return request.GetMatches().GetSize();
return request.GetNumberOfMatches();
}
#define CPU_ANY (UINT32_MAX)

View File

@ -20,6 +20,7 @@ CompletionRequest::CompletionRequest(llvm::StringRef command_line,
: m_command(command_line), m_raw_cursor_pos(raw_cursor_pos),
m_match_start_point(match_start_point),
m_max_return_elements(max_return_elements), m_matches(&matches) {
matches.Clear();
// We parse the argument up to the cursor, so the last argument in
// parsed_line is the one containing the cursor, and the cursor is after the

View File

@ -526,48 +526,3 @@ size_t Stream::PutCStringAsRawHex8(const char *s) {
m_flags.Set(eBinary);
return bytes_written;
}
void Stream::UnitTest(Stream *s) {
s->PutHex8(0x12);
s->PutChar(' ');
s->PutHex16(0x3456, endian::InlHostByteOrder());
s->PutChar(' ');
s->PutHex16(0x3456, eByteOrderBig);
s->PutChar(' ');
s->PutHex16(0x3456, eByteOrderLittle);
s->PutChar(' ');
s->PutHex32(0x789abcde, endian::InlHostByteOrder());
s->PutChar(' ');
s->PutHex32(0x789abcde, eByteOrderBig);
s->PutChar(' ');
s->PutHex32(0x789abcde, eByteOrderLittle);
s->PutChar(' ');
s->PutHex64(0x1122334455667788ull, endian::InlHostByteOrder());
s->PutChar(' ');
s->PutHex64(0x1122334455667788ull, eByteOrderBig);
s->PutChar(' ');
s->PutHex64(0x1122334455667788ull, eByteOrderLittle);
const char *hola = "Hello World!!!";
s->PutChar(' ');
s->PutCString(hola);
s->PutChar(' ');
s->Write(hola, 5);
s->PutChar(' ');
s->PutCStringAsRawHex8(hola);
s->PutChar(' ');
s->PutCStringAsRawHex8("01234");
s->PutChar(' ');
s->Printf("pid=%i", 12733);
s->PutChar(' ');
s->PrintfAsRawHex8("pid=%i", 12733);
s->PutChar('\n');
}

View File

@ -14,6 +14,7 @@ add_lldb_unittest(UtilityTests
NameMatchesTest.cpp
StatusTest.cpp
StreamTeeTest.cpp
StreamTest.cpp
StringExtractorTest.cpp
StructuredDataTest.cpp
TildeExpressionResolverTest.cpp

View File

@ -34,7 +34,70 @@ TEST(CompletionRequest, Constructor) {
EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 2u);
EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(1), "b");
// This is the generated matches should be equal to our passed string list.
EXPECT_EQ(&request.GetMatches(), &matches);
}
TEST(CompletionRequest, DuplicateFiltering) {
std::string command = "a bad c";
const unsigned cursor_pos = 3;
StringList matches;
CompletionRequest request(command, cursor_pos, 0, 0, matches);
EXPECT_EQ(0U, request.GetNumberOfMatches());
// Add foo twice
request.AddCompletion("foo");
EXPECT_EQ(1U, request.GetNumberOfMatches());
EXPECT_EQ(1U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
request.AddCompletion("foo");
EXPECT_EQ(1U, request.GetNumberOfMatches());
EXPECT_EQ(1U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
// Add bar twice
request.AddCompletion("bar");
EXPECT_EQ(2U, request.GetNumberOfMatches());
EXPECT_EQ(2U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
request.AddCompletion("bar");
EXPECT_EQ(2U, request.GetNumberOfMatches());
EXPECT_EQ(2U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
// Add foo again.
request.AddCompletion("foo");
EXPECT_EQ(2U, request.GetNumberOfMatches());
EXPECT_EQ(2U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
// Add something with an existing prefix
request.AddCompletion("foobar");
EXPECT_EQ(3U, request.GetNumberOfMatches());
EXPECT_EQ(3U, matches.GetSize());
EXPECT_STREQ("foo", matches.GetStringAtIndex(0));
EXPECT_STREQ("bar", matches.GetStringAtIndex(1));
EXPECT_STREQ("foobar", matches.GetStringAtIndex(2));
}
TEST(CompletionRequest, TestCompletionOwnership) {
std::string command = "a bad c";
const unsigned cursor_pos = 3;
StringList matches;
CompletionRequest request(command, cursor_pos, 0, 0, matches);
std::string Temporary = "bar";
request.AddCompletion(Temporary);
// Manipulate our completion. The request should have taken a copy, so that
// shouldn't influence anything.
Temporary[0] = 'f';
EXPECT_EQ(1U, request.GetNumberOfMatches());
EXPECT_STREQ("bar", matches.GetStringAtIndex(0));
}

View File

@ -0,0 +1,474 @@
//===-- StreamTest.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/StreamString.h"
#include "gtest/gtest.h"
using namespace lldb_private;
namespace {
struct StreamTest : ::testing::Test {
// Note: Stream is an abstract class, so we use StreamString to test it. To
// make it easier to change this later, only methods in this class explicitly
// refer to the StringStream class.
StreamString s;
// We return here a std::string because that way gtest can print better
// assertion messages.
std::string TakeValue() {
std::string result = s.GetString().str();
s.Clear();
return result;
}
};
}
namespace {
// A StreamTest where we expect the Stream output to be binary.
struct BinaryStreamTest : StreamTest {
void SetUp() override {
s.GetFlags().Set(Stream::eBinary);
}
};
}
TEST_F(StreamTest, ChangingByteOrder) {
s.SetByteOrder(lldb::eByteOrderPDP);
EXPECT_EQ(lldb::eByteOrderPDP, s.GetByteOrder());
}
TEST_F(StreamTest, PutChar) {
s.PutChar('a');
EXPECT_EQ("a", TakeValue());
s.PutChar('1');
EXPECT_EQ("1", TakeValue());
}
TEST_F(StreamTest, PutCharWhitespace) {
s.PutChar(' ');
EXPECT_EQ(" ", TakeValue());
s.PutChar('\n');
EXPECT_EQ("\n", TakeValue());
s.PutChar('\r');
EXPECT_EQ("\r", TakeValue());
s.PutChar('\t');
EXPECT_EQ("\t", TakeValue());
}
TEST_F(StreamTest, PutCString) {
s.PutCString("");
EXPECT_EQ("", TakeValue());
s.PutCString("foobar");
EXPECT_EQ("foobar", TakeValue());
s.PutCString(" ");
EXPECT_EQ(" ", TakeValue());
}
TEST_F(StreamTest, PutCStringWithStringRef) {
s.PutCString(llvm::StringRef(""));
EXPECT_EQ("", TakeValue());
s.PutCString(llvm::StringRef("foobar"));
EXPECT_EQ("foobar", TakeValue());
s.PutCString(llvm::StringRef(" "));
EXPECT_EQ(" ", TakeValue());
}
TEST_F(StreamTest, QuotedCString) {
s.QuotedCString("foo");
EXPECT_EQ(R"("foo")", TakeValue());
s.QuotedCString("ba r");
EXPECT_EQ(R"("ba r")", TakeValue());
s.QuotedCString(" ");
EXPECT_EQ(R"(" ")", TakeValue());
}
TEST_F(StreamTest, PutCharNull) {
s.PutChar('\0');
EXPECT_EQ(std::string("\0", 1), TakeValue());
s.PutChar('a');
EXPECT_EQ(std::string("a", 1), TakeValue());
}
TEST_F(StreamTest, PutCStringAsRawHex8) {
s.PutCStringAsRawHex8("foobar");
EXPECT_EQ("666f6f626172", TakeValue());
s.PutCStringAsRawHex8(" ");
EXPECT_EQ("20", TakeValue());
}
TEST_F(StreamTest, PutHex8) {
s.PutHex8((uint8_t)55);
EXPECT_EQ("37", TakeValue());
s.PutHex8(std::numeric_limits<uint8_t>::max());
EXPECT_EQ("ff", TakeValue());
s.PutHex8((uint8_t)0);
EXPECT_EQ("00", TakeValue());
}
TEST_F(StreamTest, PutNHex8) {
s.PutNHex8(0, (uint8_t)55);
EXPECT_EQ("", TakeValue());
s.PutNHex8(1, (uint8_t)55);
EXPECT_EQ("37", TakeValue());
s.PutNHex8(2, (uint8_t)55);
EXPECT_EQ("3737", TakeValue());
s.PutNHex8(1, (uint8_t)56);
EXPECT_EQ("38", TakeValue());
}
TEST_F(StreamTest, PutHex16ByteOrderLittle) {
s.PutHex16(0x1234U, lldb::eByteOrderLittle);
EXPECT_EQ("3412", TakeValue());
s.PutHex16(std::numeric_limits<uint16_t>::max(), lldb::eByteOrderLittle);
EXPECT_EQ("ffff", TakeValue());
s.PutHex16(0U, lldb::eByteOrderLittle);
EXPECT_EQ("0000", TakeValue());
}
TEST_F(StreamTest, PutHex16ByteOrderBig) {
s.PutHex16(0x1234U, lldb::eByteOrderBig);
EXPECT_EQ("1234", TakeValue());
s.PutHex16(std::numeric_limits<uint16_t>::max(), lldb::eByteOrderBig);
EXPECT_EQ("ffff", TakeValue());
s.PutHex16(0U, lldb::eByteOrderBig);
EXPECT_EQ("0000", TakeValue());
}
TEST_F(StreamTest, PutHex32ByteOrderLittle) {
s.PutHex32(0x12345678U, lldb::eByteOrderLittle);
EXPECT_EQ("78563412", TakeValue());
s.PutHex32(std::numeric_limits<uint32_t>::max(), lldb::eByteOrderLittle);
EXPECT_EQ("ffffffff", TakeValue());
s.PutHex32(0U, lldb::eByteOrderLittle);
EXPECT_EQ("00000000", TakeValue());
}
TEST_F(StreamTest, PutHex32ByteOrderBig) {
s.PutHex32(0x12345678U, lldb::eByteOrderBig);
EXPECT_EQ("12345678", TakeValue());
s.PutHex32(std::numeric_limits<uint32_t>::max(), lldb::eByteOrderBig);
EXPECT_EQ("ffffffff", TakeValue());
s.PutHex32(0U, lldb::eByteOrderBig);
EXPECT_EQ("00000000", TakeValue());
}
TEST_F(StreamTest, PutHex64ByteOrderLittle) {
s.PutHex64(0x1234567890ABCDEFU, lldb::eByteOrderLittle);
EXPECT_EQ("efcdab9078563412", TakeValue());
s.PutHex64(std::numeric_limits<uint64_t>::max(), lldb::eByteOrderLittle);
EXPECT_EQ("ffffffffffffffff", TakeValue());
s.PutHex64(0U, lldb::eByteOrderLittle);
EXPECT_EQ("0000000000000000", TakeValue());
}
TEST_F(StreamTest, PutHex64ByteOrderBig) {
s.PutHex64(0x1234567890ABCDEFU, lldb::eByteOrderBig);
EXPECT_EQ("1234567890abcdef", TakeValue());
s.PutHex64(std::numeric_limits<uint64_t>::max(), lldb::eByteOrderBig);
EXPECT_EQ("ffffffffffffffff", TakeValue());
s.PutHex64(0U, lldb::eByteOrderBig);
EXPECT_EQ("0000000000000000", TakeValue());
}
//------------------------------------------------------------------------------
// Shift operator tests.
//------------------------------------------------------------------------------
TEST_F(StreamTest, ShiftOperatorChars) {
s << 'a' << 'b';
EXPECT_EQ("ab", TakeValue());
}
TEST_F(StreamTest, ShiftOperatorStrings) {
s << "cstring\n";
s << llvm::StringRef("llvm::StringRef\n");
EXPECT_EQ("cstring\nllvm::StringRef\n", TakeValue());
}
TEST_F(StreamTest, ShiftOperatorInts) {
s << std::numeric_limits<int8_t>::max() << " ";
s << std::numeric_limits<int16_t>::max() << " ";
s << std::numeric_limits<int32_t>::max() << " ";
s << std::numeric_limits<int64_t>::max();
EXPECT_EQ("127 32767 2147483647 9223372036854775807", TakeValue());
}
TEST_F(StreamTest, ShiftOperatorUInts) {
s << std::numeric_limits<uint8_t>::max() << " ";
s << std::numeric_limits<uint16_t>::max() << " ";
s << std::numeric_limits<uint32_t>::max() << " ";
s << std::numeric_limits<uint64_t>::max();
EXPECT_EQ("ff ffff ffffffff ffffffffffffffff", TakeValue());
}
TEST_F(StreamTest, ShiftOperatorPtr) {
// This test is a bit tricky because pretty much everything related to
// pointer printing seems to lead to UB or IB. So let's make the most basic
// test that just checks that we print *something*. This way we at least know
// that pointer printing doesn't do really bad things (e.g. crashing, reading
// OOB/uninitialized memory which the sanitizers would spot).
// Shift our own pointer to the output.
int i = 3;
int *ptr = &i;
s << ptr;
EXPECT_TRUE(!TakeValue().empty());
}
TEST_F(StreamTest, PutPtr) {
// See the ShiftOperatorPtr test for the rationale.
int i = 3;
int *ptr = &i;
s.PutPointer(ptr);
EXPECT_TRUE(!TakeValue().empty());
}
// Alias to make it more clear that 'invalid' means for the Stream interface
// that it should use the host byte order.
const static auto hostByteOrder = lldb::eByteOrderInvalid;
//------------------------------------------------------------------------------
// PutRawBytes/PutBytesAsRawHex tests.
//------------------------------------------------------------------------------
TEST_F(StreamTest, PutBytesAsRawHex8ToBigEndian) {
uint32_t value = 0x12345678;
s.PutBytesAsRawHex8(static_cast<void*>(&value), sizeof(value),
hostByteOrder, lldb::eByteOrderBig);
EXPECT_EQ("78563412", TakeValue());
}
TEST_F(StreamTest, PutRawBytesToBigEndian) {
uint32_t value = 0x12345678;
s.PutRawBytes(static_cast<void*>(&value), sizeof(value),
hostByteOrder, lldb::eByteOrderBig);
EXPECT_EQ("\x78\x56\x34\x12", TakeValue());
}
TEST_F(StreamTest, PutBytesAsRawHex8ToLittleEndian) {
uint32_t value = 0x12345678;
s.PutBytesAsRawHex8(static_cast<void*>(&value), sizeof(value),
hostByteOrder, lldb::eByteOrderLittle);
EXPECT_EQ("12345678", TakeValue());
}
TEST_F(StreamTest, PutRawBytesToLittleEndian) {
uint32_t value = 0x12345678;
s.PutRawBytes(static_cast<void*>(&value), sizeof(value),
hostByteOrder, lldb::eByteOrderLittle);
EXPECT_EQ("\x12\x34\x56\x78", TakeValue());
}
TEST_F(StreamTest, PutBytesAsRawHex8ToMixedEndian) {
uint32_t value = 0x12345678;
s.PutBytesAsRawHex8(static_cast<void*>(&value), sizeof(value),
hostByteOrder, lldb::eByteOrderPDP);
// FIXME: PDP byte order is not actually implemented but Stream just silently
// prints the value in some random byte order...
#if 0
EXPECT_EQ("34127856", TakeValue());
#endif
}
TEST_F(StreamTest, PutRawBytesToMixedEndian) {
uint32_t value = 0x12345678;
s.PutRawBytes(static_cast<void*>(&value), sizeof(value),
lldb::eByteOrderInvalid, lldb::eByteOrderPDP);
// FIXME: PDP byte order is not actually implemented but Stream just silently
// prints the value in some random byte order...
#if 0
EXPECT_EQ("\x34\x12\x78\x56", TakeValue());
#endif
}
//------------------------------------------------------------------------------
// ULEB128 support for binary streams.
//------------------------------------------------------------------------------
TEST_F(BinaryStreamTest, PutULEB128OneByte) {
auto bytes = s.PutULEB128(0x74ULL);
EXPECT_EQ("\x74", TakeValue());
EXPECT_EQ(1U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128TwoBytes) {
auto bytes = s.PutULEB128(0x1985ULL);
EXPECT_EQ("\x85\x33", TakeValue());
EXPECT_EQ(2U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128ThreeBytes) {
auto bytes = s.PutULEB128(0x5023ULL);
EXPECT_EQ("\xA3\xA0\x1", TakeValue());
EXPECT_EQ(3U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128FourBytes) {
auto bytes = s.PutULEB128(0xA48032ULL);
EXPECT_EQ("\xB2\x80\x92\x5", TakeValue());
EXPECT_EQ(4U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128FiveBytes) {
auto bytes = s.PutULEB128(0x12345678ULL);
EXPECT_EQ("\xF8\xAC\xD1\x91\x1", TakeValue());
EXPECT_EQ(5U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128SixBytes) {
auto bytes = s.PutULEB128(0xABFE3FAFDFULL);
EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\x15", TakeValue());
EXPECT_EQ(6U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128SevenBytes) {
auto bytes = s.PutULEB128(0xDABFE3FAFDFULL);
EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\x3", TakeValue());
EXPECT_EQ(7U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128EightBytes) {
auto bytes = s.PutULEB128(0x7CDABFE3FAFDFULL);
EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x3", TakeValue());
EXPECT_EQ(8U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128NineBytes) {
auto bytes = s.PutULEB128(0x327CDABFE3FAFDFULL);
EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x93\x3", TakeValue());
EXPECT_EQ(9U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128MaxValue) {
auto bytes = s.PutULEB128(std::numeric_limits<uint64_t>::max());
EXPECT_EQ("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x1", TakeValue());
EXPECT_EQ(10U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128Zero) {
auto bytes = s.PutULEB128(0x0U);
EXPECT_EQ(std::string("\0", 1), TakeValue());
EXPECT_EQ(1U, bytes);
}
TEST_F(BinaryStreamTest, PutULEB128One) {
auto bytes = s.PutULEB128(0x1U);
EXPECT_EQ("\x1", TakeValue());
EXPECT_EQ(1U, bytes);
}
//------------------------------------------------------------------------------
// SLEB128 support for binary streams.
//------------------------------------------------------------------------------
TEST_F(BinaryStreamTest, PutSLEB128OneByte) {
auto bytes = s.PutSLEB128(0x74LL);
EXPECT_EQ(std::string("\xF4\0", 2), TakeValue());
EXPECT_EQ(2U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128TwoBytes) {
auto bytes = s.PutSLEB128(0x1985LL);
EXPECT_EQ("\x85\x33", TakeValue());
EXPECT_EQ(2U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128ThreeBytes) {
auto bytes = s.PutSLEB128(0x5023LL);
EXPECT_EQ("\xA3\xA0\x1", TakeValue());
EXPECT_EQ(3U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128FourBytes) {
auto bytes = s.PutSLEB128(0xA48032LL);
EXPECT_EQ("\xB2\x80\x92\x5", TakeValue());
EXPECT_EQ(4U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128FiveBytes) {
auto bytes = s.PutSLEB128(0x12345678LL);
EXPECT_EQ("\xF8\xAC\xD1\x91\x1", TakeValue());
EXPECT_EQ(5U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128SixBytes) {
auto bytes = s.PutSLEB128(0xABFE3FAFDFLL);
EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\x15", TakeValue());
EXPECT_EQ(6U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128SevenBytes) {
auto bytes = s.PutSLEB128(0xDABFE3FAFDFLL);
EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\x3", TakeValue());
EXPECT_EQ(7U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128EightBytes) {
auto bytes = s.PutSLEB128(0x7CDABFE3FAFDFLL);
EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x3", TakeValue());
EXPECT_EQ(8U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128NineBytes) {
auto bytes = s.PutSLEB128(0x327CDABFE3FAFDFLL);
EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x93\x3", TakeValue());
EXPECT_EQ(9U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128MaxValue) {
auto bytes = s.PutSLEB128(std::numeric_limits<int64_t>::max());
EXPECT_EQ(std::string("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\0", 10), TakeValue());
EXPECT_EQ(10U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128Zero) {
auto bytes = s.PutSLEB128(0x0);
EXPECT_EQ(std::string("\0", 1), TakeValue());
EXPECT_EQ(1U, bytes);
}
TEST_F(BinaryStreamTest, PutSLEB128One) {
auto bytes = s.PutSLEB128(0x1);
EXPECT_EQ(std::string("\x1", 1), TakeValue());
EXPECT_EQ(1U, bytes);
}
//------------------------------------------------------------------------------
// SLEB128/ULEB128 support for non-binary streams.
//------------------------------------------------------------------------------
// The logic for this is very simple, so it should be enough to test some basic
// use cases.
TEST_F(StreamTest, PutULEB128) {
auto bytes = s.PutULEB128(0x74ULL);
EXPECT_EQ("0x74", TakeValue());
EXPECT_EQ(4U, bytes);
}
TEST_F(StreamTest, PutSLEB128) {
auto bytes = s.PutSLEB128(0x1985LL);
EXPECT_EQ("0x6533", TakeValue());
EXPECT_EQ(6U, bytes);
}