diff options
author | Che-yu Wu <cheyuw@google.com> | 2017-08-17 17:12:03 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-08-22 05:08:48 -0700 |
commit | 00e022272938d3c3f8b5d60f11c960d9da5546ac (patch) | |
tree | 94948ade8c96c4c566fde04c7ef2177bf1a36fbe /extra/stack_analyzer/stack_analyzer_unittest.py | |
parent | ef09835e1941a2388e15b410791bed6ff5d84339 (diff) | |
download | chrome-ec-00e022272938d3c3f8b5d60f11c960d9da5546ac.tar.gz |
extra/stack_analyzer: Fix cbz/cbnz and addr2line parsing.
Fix the cbz/cbnz operands parsing.
Parse the discriminator output of addr2line.
BUG=none
BRANCH=none
TEST=extra/stack_analyzer/stack_analyzer_unittest.py
Change-Id: Iade1c14db0dc63fa65ef0f5df778b4f4f1e4f802
Signed-off-by: Che-yu Wu <cheyuw@google.com>
Reviewed-on: https://chromium-review.googlesource.com/625498
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'extra/stack_analyzer/stack_analyzer_unittest.py')
-rwxr-xr-x | extra/stack_analyzer/stack_analyzer_unittest.py | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/extra/stack_analyzer/stack_analyzer_unittest.py b/extra/stack_analyzer/stack_analyzer_unittest.py index 2c0a4ae8f1..e011a670c4 100755 --- a/extra/stack_analyzer/stack_analyzer_unittest.py +++ b/extra/stack_analyzer/stack_analyzer_unittest.py @@ -57,7 +57,7 @@ class ArmAnalyzerTest(unittest.TestCase): return rets def testInstructionMatching(self): - jump_list = self.AppendConditionCode(['b', 'bx']) + ['cbz', 'cbnz'] + jump_list = self.AppendConditionCode(['b', 'bx']) jump_list += (list(opcode + '.n' for opcode in jump_list) + list(opcode + '.w' for opcode in jump_list)) for opcode in jump_list: @@ -66,6 +66,12 @@ class ArmAnalyzerTest(unittest.TestCase): self.assertIsNone(sa.ArmAnalyzer.JUMP_OPCODE_RE.match('bl')) self.assertIsNone(sa.ArmAnalyzer.JUMP_OPCODE_RE.match('blx')) + cbz_list = ['cbz', 'cbnz', 'cbz.n', 'cbnz.n', 'cbz.w', 'cbnz.w'] + for opcode in cbz_list: + self.assertIsNotNone(sa.ArmAnalyzer.CBZ_CBNZ_OPCODE_RE.match(opcode)) + + self.assertIsNone(sa.ArmAnalyzer.CBZ_CBNZ_OPCODE_RE.match('cbn')) + call_list = self.AppendConditionCode(['bl', 'blx']) call_list += list(opcode + '.n' for opcode in call_list) for opcode in call_list: @@ -78,6 +84,11 @@ class ArmAnalyzerTest(unittest.TestCase): self.assertEqual(result.group(1), '53f90') self.assertEqual(result.group(2), 'get_time+0x18') + result = sa.ArmAnalyzer.CBZ_CBNZ_OPERAND_RE.match('r6, 53f90 <get+0x0>') + self.assertIsNotNone(result) + self.assertEqual(result.group(1), '53f90') + self.assertEqual(result.group(2), 'get+0x0') + self.assertIsNotNone(sa.ArmAnalyzer.PUSH_OPCODE_RE.match('push')) self.assertIsNone(sa.ArmAnalyzer.PUSH_OPCODE_RE.match('pushal')) self.assertIsNotNone(sa.ArmAnalyzer.STM_OPCODE_RE.match('stmdb')) @@ -313,7 +324,8 @@ class StackAnalyzerTest(unittest.TestCase): '00001000 <hook_task>:\n' ' 1000: dead beef\tfake\n' ' 1004: 4770\t\tbx lr\n' - ' 1006: 00015cfc\t.word 0x00015cfc\n' + ' 1006: b113\tcbz r3, 100929de <flash_command_write>\n' + ' 1008: 00015cfc\t.word 0x00015cfc\n' '00002000 <console_task>:\n' ' 2000: b508\t\tpush {r3, lr} ; malformed comments,; r0, r1 \n' ' 2002: f00e fcc5\tbl 1000 <hook_task>\n' @@ -324,7 +336,8 @@ class StackAnalyzerTest(unittest.TestCase): '00010000 <look_task>:' ) function_map = self.analyzer.AnalyzeDisassembly(disasm_text) - func_hook_task = sa.Function(0x1000, 'hook_task', 0, []) + func_hook_task = sa.Function(0x1000, 'hook_task', 0, [ + sa.Callsite(0x1006, 0x100929de, True, None)]) expect_funcmap = { 0x1000: func_hook_task, 0x2000: sa.Function(0x2000, 'console_task', 8, @@ -391,8 +404,13 @@ class StackAnalyzerTest(unittest.TestCase): @mock.patch('subprocess.check_output') def testAddressToLine(self, checkoutput_mock): - checkoutput_mock.return_value = 'test.c [1]' - self.assertEqual(self.analyzer.AddressToLine(0x1234), 'test.c [1]') + checkoutput_mock.return_value = 'test.c:1' + self.assertEqual(self.analyzer.AddressToLine(0x1234), 'test.c:1') + checkoutput_mock.assert_called_once_with( + ['addr2line', '-e', './ec.RW.elf', '1234']) + + checkoutput_mock.return_value = 'test.c:1 (discriminator 1289031)' + self.assertEqual(self.analyzer.AddressToLine(0x1234), 'test.c:1') checkoutput_mock.assert_called_once_with( ['addr2line', '-e', './ec.RW.elf', '1234']) |