コード例 #1
0

def test(gdb):
    gdb.Command('break mmap_breakpoint')
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    gdb.ResumeAndExpectStop('finish', 'function-finished')
    # Check that we can read from memory mapped files.
    AssertEquals(gdb_test.ParseNumber(gdb.Eval('*file_mapping')), 123)
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    gdb.ResumeAndExpectStop('finish', 'function-finished')
    file_mapping_str = gdb.Eval('file_mapping')
    file_mapping = gdb_test.ParseNumber(file_mapping_str)
    gdb.Command('break *' + file_mapping_str)
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    # Check that breakpoint in memory mapped code is working.
    AssertEquals(gdb.GetPC(), file_mapping)
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    gdb.ResumeAndExpectStop('finish', 'function-finished')
    file_mapping_str = gdb.Eval('file_mapping')
    file_mapping = gdb_test.ParseNumber(file_mapping_str)
    gdb.Command('break *' + file_mapping_str)
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    # Check that breakpoint in memory mapped code is working.
    AssertEquals(gdb.GetPC(), file_mapping)


if __name__ == '__main__':
    os.environ['NACL_FAULT_INJECTION'] = (
        'MMAP_BYPASS_DESCRIPTOR_SAFETY_CHECK=GF/@')
    gdb_test.RunTest(test, 'mmap')
コード例 #2
0
# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from gdb_test import AssertEquals
import gdb_test


def test(gdb):
    gdb.Command('break test_step_from_function_start')
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    gdb.ResumeCommand('step')
    gdb.ResumeCommand('step')
    gdb.ResumeCommand('step')
    AssertEquals(gdb.Eval('global_var'), '1')
    gdb.Quit()


if __name__ == '__main__':
    gdb_test.RunTest(test, 'step_from_func_start')
コード例 #3
0
# -*- python -*-
# Copyright (c) 2013 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import gdb_test


def test(gdb):
    gdb.ExpectToFailCommand('x 0x1000000')
    gdb.Command('break *0x1000000')
    # GDB sets breakpoints on "continue" and similar commands and removes them
    # when program stops, so it is continue command that we expect to fail.
    gdb.ExpectToFailCommand('continue')
    gdb.Quit()
    return 0


if __name__ == '__main__':
    gdb_test.RunTest(test, 'dummy')
コード例 #4
0
# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from gdb_test import AssertEquals
import gdb_test


def test(gdb):
    gdb.Command('break test_stepi_after_break')
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    # From GDB/MI documentation, 'stepi' statement should be
    #   gdb.ResumeAndExpectStop('stepi', 'end-stepping-range')
    # but in reality 'stepi' stop reason is simply omitted.
    gdb.ResumeCommand('stepi')
    gdb.Quit()
    return 0


if __name__ == '__main__':
    gdb_test.RunTest(test, 'stepi_after_break')
コード例 #5
0
# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from gdb_test import AssertEquals
import gdb_test


def test(gdb):
    gdb.Command('break leaf_call')
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    result = gdb.Command('-stack-list-frames 0 2')
    AssertEquals(result['stack'][0]['frame']['func'], 'leaf_call')
    AssertEquals(result['stack'][1]['frame']['func'], 'nested_calls')
    AssertEquals(result['stack'][2]['frame']['func'], 'main')

    result = gdb.Command('-stack-list-arguments 1 0 1')
    AssertEquals(result['stack-args'][0]['frame']['args'][0]['value'], '2')
    AssertEquals(result['stack-args'][1]['frame']['args'][0]['value'], '1')
    gdb.Command('return')
    gdb.ResumeAndExpectStop('finish', 'function-finished')
    AssertEquals(gdb.Eval('global_var'), '1')


if __name__ == '__main__':
    gdb_test.RunTest(test, 'stack_trace')
コード例 #6
0
# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from gdb_test import AssertEquals
import gdb_test


def test(gdb):
    gdb.Command('break set_global_var')
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    AssertEquals(gdb.Eval('global_var'), '2')
    AssertEquals(gdb.Eval('arg'), '1')
    gdb.ResumeAndExpectStop('finish', 'function-finished')
    AssertEquals(gdb.Eval('global_var'), '1')
    AssertEquals(gdb.Eval('local_var'), '3')
    gdb.Quit()


if __name__ == '__main__':
    gdb_test.RunTest(test, 'print_symbol')
コード例 #7
0
# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from gdb_test import AssertEquals
import gdb_test


def test(gdb):
    gdb.Command('break main')
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    AssertEquals(gdb.Eval('test_call_from_gdb(1)'), '3')
    AssertEquals(gdb.Eval('global_var'), '2')


if __name__ == '__main__':
    gdb_test.RunTest(test, 'call_from_gdb')
コード例 #8
0
# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from gdb_test import AssertEquals
import gdb_test


def test(gdb):
    gdb.Command('break test_change_variable')
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    gdb.Command('set var arg = 2')
    AssertEquals(gdb.Eval('arg'), '2')
    gdb.ResumeCommand('step')
    AssertEquals(gdb.Eval('local_var'), '4')
    gdb.Command('set var local_var = 5')
    AssertEquals(gdb.Eval('local_var'), '5')
    gdb.Command('set var global_var = 1')
    AssertEquals(gdb.Eval('global_var'), '1')
    gdb.ResumeCommand('step')
    AssertEquals(gdb.Eval('global_var'), '8')  # 1 + 5 + 2


if __name__ == '__main__':
    gdb_test.RunTest(test, 'change_variable')
コード例 #9
0
# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from gdb_test import AssertEquals
import gdb_test


def test(gdb):
    gdb.Command('break foo')
    gdb.Command('break bar')
    # Program runs 2 threads, each calls foo and bar - expect 4 breakpoint hits.
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
    gdb.Quit()


if __name__ == '__main__':
    gdb_test.RunTest(test, 'break_continue_thread')
コード例 #10
0
  all_functions = [frame['frame']['func'] for frame in backtrace]
  # Check that 'functions' is a subsequence of 'all_functions'
  s1 = '|' + '|'.join(all_functions) + '|'
  s2 = '|' + '|'.join(functions) + '|'
  assert s2 in s1, '%s not in %s' % (functions, all_functions)


def test(gdb):
  gdb.Command('break inside_f3')
  gdb.ResumeAndExpectStop('continue', 'breakpoint-hit')
  # Check we stopped in inside_f3
  backtrace = gdb.Command('-stack-list-frames')
  CheckBacktrace(backtrace['stack'], ['inside_f3', 'f3'])
  # Check we have one more thread
  thread_info = gdb.Command('-thread-info')
  AssertEquals(len(thread_info['threads']), 2)
  # Select another thread
  syscall_thread_id = thread_info['threads'][0]['id']
  if syscall_thread_id == thread_info['current-thread-id']:
    syscall_thread_id = thread_info['threads'][1]['id']
  gdb.Command('-thread-select %s' % syscall_thread_id)
  # Check that thread waits in usleep
  backtrace = gdb.Command('-stack-list-frames')
  CheckBacktrace(backtrace['stack'], ['pthread_join', 'test_syscall_thread'])
  gdb.Quit()
  return 0


if __name__ == '__main__':
  gdb_test.RunTest(test, 'syscall_thread')
コード例 #11
0
# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from gdb_test import AssertEquals
import gdb_test


def test(gdb):
  # The second superfluous call to LoadManifestFile.  This is a regression test
  # for issue https://code.google.com/p/nativeclient/issues/detail?id=3262 .
  gdb.LoadManifestFile()
  gdb.ResumeCommand('continue')
  gdb.Quit()


if __name__ == '__main__':
  gdb_test.RunTest(test, '')