"""
Test the 'memory read' command.
"""
import os, time
import re
import unittest2
import lldb
from lldbtest import *
class MemoryReadTestCase(TestBase):
mydir = os.path.join("functionalities", "memory", "read")
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@dsym_test
def test_memory_read_with_dsym(self):
"""Test the 'memory read' command with plain and vector formats."""
self.buildDsym()
self.memory_read_command()
@dwarf_test
def test_memory_read_with_dwarf(self):
"""Test the 'memory read' command with plain and vector formats."""
self.buildDwarf()
self.memory_read_command()
def setUp(self):
TestBase.setUp(self)
self.line = line_number('main.cpp', '// Set break point at this line.')
def memory_read_command(self):
"""Test the 'memory read' command with plain and vector formats."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
self.expect("breakpoint set -f main.cpp -l %d" % self.line,
BREAKPOINT_CREATED,
startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" %
self.line)
self.runCmd("run", RUN_SUCCEEDED)
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped', 'stop reason = breakpoint'])
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
substrs = [' resolved, hit count = 1'])
self.runCmd("memory read -f d -c 1 `&argc`")
line = self.res.GetOutput().splitlines()[0]
items = line.split(':')
address = int(items[0], 0)
argc = int(items[1], 0)
self.assertTrue(address > 0 and argc == 1)
self.runCmd("memory read --format uint32_t[] --size 4 --count 4 `&argc`")
lines = self.res.GetOutput().splitlines()
for i in range(4):
if i == 0:
self.assertTrue(argc == int(lines[i].split(':')[1].strip(' {}'), 0))
addr = int(lines[i].split(':')[0], 0)
self.assertTrue(addr == (address + i*4))
self.expect("memory read --format char[] --size 7 --count 1 `&my_string`",
substrs = ['abcdefg'])
self.expect("memory read --format 'hex float' --size 16 `&argc`",
substrs = ['unsupported byte size (16) for hex float format'])
self.expect("memory read --format 'float' --count 1 --size 8 `&my_double`",
substrs = ['1234.'])
self.expect("memory read --format 'float' --count 1 --size 20 `&my_double`",
substrs = ['unsupported byte size (20) for float format'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()