2014-03-15 00:57:48 +00:00
"""
Test thread step - in , step - over and step - out work with the " Avoid no debug " option .
"""
2015-10-23 17:04:29 +00:00
from __future__ import print_function
2015-11-03 19:20:39 +00:00
2014-03-15 00:57:48 +00:00
import os
import re
2014-03-25 18:55:48 +00:00
import sys
2016-02-04 23:04:17 +00:00
import lldb
from lldbsuite . test . decorators import *
2015-11-03 02:06:18 +00:00
from lldbsuite . test . lldbtest import *
2016-02-04 23:04:17 +00:00
from lldbsuite . test import lldbutil
2014-03-15 00:57:48 +00:00
2016-09-06 20:57:50 +00:00
2014-03-15 00:57:48 +00:00
class ReturnValueTestCase ( TestBase ) :
mydir = TestBase . compute_mydir ( __file__ )
2015-10-26 09:28:32 +00:00
@add_test_categories ( [ ' pyapi ' ] )
2015-09-30 10:12:40 +00:00
def test_step_out_with_python ( self ) :
2014-03-15 00:57:48 +00:00
""" Test stepping out using avoid-no-debug with dsyms. """
2015-09-30 10:12:40 +00:00
self . build ( )
2014-03-15 00:57:48 +00:00
self . get_to_starting_point ( )
self . do_step_out_past_nodebug ( )
2015-10-26 09:28:32 +00:00
@add_test_categories ( [ ' pyapi ' ] )
2016-09-06 20:57:50 +00:00
@decorators.expectedFailureAll (
compiler = " gcc " , bugnumber = " llvm.org/pr28549 " )
@decorators.expectedFailureAll (
compiler = " clang " ,
compiler_version = [
" >= " ,
" 3.9 " ] ,
archs = [ " i386 " ] ,
bugnumber = " llvm.org/pr28549 " )
2015-09-30 10:12:40 +00:00
def test_step_over_with_python ( self ) :
2014-03-15 00:57:48 +00:00
""" Test stepping over using avoid-no-debug with dwarf. """
2015-09-30 10:12:40 +00:00
self . build ( )
2014-03-15 00:57:48 +00:00
self . get_to_starting_point ( )
self . do_step_over_past_nodebug ( )
2015-10-26 09:28:32 +00:00
@add_test_categories ( [ ' pyapi ' ] )
2016-09-06 20:57:50 +00:00
@decorators.expectedFailureAll (
compiler = " gcc " , bugnumber = " llvm.org/pr28549 " )
@decorators.expectedFailureAll (
compiler = " clang " ,
compiler_version = [
" >= " ,
" 3.9 " ] ,
archs = [ " i386 " ] ,
bugnumber = " llvm.org/pr28549 " )
2017-09-25 18:19:39 +00:00
@expectedFailureAll ( oslist = [ " ios " , " tvos " , " bridgeos " ] , bugnumber = " <rdar://problem/34026777> " ) # lldb doesn't step past last source line in function on arm64
2015-09-30 10:12:40 +00:00
def test_step_in_with_python ( self ) :
2014-03-15 00:57:48 +00:00
""" Test stepping in using avoid-no-debug with dwarf. """
2015-09-30 10:12:40 +00:00
self . build ( )
2014-03-15 00:57:48 +00:00
self . get_to_starting_point ( )
self . do_step_in_past_nodebug ( )
2016-09-06 20:57:50 +00:00
def setUp ( self ) :
2014-03-15 00:57:48 +00:00
TestBase . setUp ( self )
self . main_source = " with-debug.c "
self . main_source_spec = lldb . SBFileSpec ( " with-debug.c " )
2016-09-06 20:57:50 +00:00
self . dbg . HandleCommand (
" settings set target.process.thread.step-out-avoid-nodebug true " )
2014-03-15 00:57:48 +00:00
2016-09-06 20:57:50 +00:00
def tearDown ( self ) :
self . dbg . HandleCommand (
" settings set target.process.thread.step-out-avoid-nodebug false " )
2014-07-28 22:53:49 +00:00
TestBase . tearDown ( self )
2014-03-15 00:57:48 +00:00
2016-09-06 20:57:50 +00:00
def hit_correct_line ( self , pattern ) :
target_line = line_number ( self . main_source , pattern )
self . assertTrue (
target_line != 0 ,
" Could not find source pattern " +
pattern )
2014-03-15 00:57:48 +00:00
cur_line = self . thread . frames [ 0 ] . GetLineEntry ( ) . GetLine ( )
2016-09-06 20:57:50 +00:00
self . assertTrue (
cur_line == target_line ,
" Stepped to line %d instead of expected %d with pattern ' %s ' . " %
( cur_line ,
target_line ,
pattern ) )
def hit_correct_function ( self , pattern ) :
2014-03-15 00:57:48 +00:00
name = self . thread . frames [ 0 ] . GetFunctionName ( )
2016-09-06 20:57:50 +00:00
self . assertTrue (
pattern in name , " Got to ' %s ' not the expected function ' %s ' . " %
( name , pattern ) )
2014-03-15 00:57:48 +00:00
2016-09-06 20:57:50 +00:00
def get_to_starting_point ( self ) :
2018-01-19 23:24:35 +00:00
exe = self . getBuildArtifact ( " a.out " )
2014-03-15 00:57:48 +00:00
error = lldb . SBError ( )
self . target = self . dbg . CreateTarget ( exe )
self . assertTrue ( self . target , VALID_TARGET )
2016-09-06 20:57:50 +00:00
inner_bkpt = self . target . BreakpointCreateBySourceRegex (
" Stop here and step out of me " , self . main_source_spec )
2014-03-15 00:57:48 +00:00
self . assertTrue ( inner_bkpt , VALID_BREAKPOINT )
# Now launch the process, and do not stop at entry point.
2016-09-06 20:57:50 +00:00
self . process = self . target . LaunchSimple (
None , None , self . get_process_working_directory ( ) )
2014-03-15 00:57:48 +00:00
self . assertTrue ( self . process , PROCESS_IS_VALID )
# Now finish, and make sure the return value is correct.
2016-09-06 20:57:50 +00:00
threads = lldbutil . get_threads_stopped_at_breakpoint (
self . process , inner_bkpt )
2014-03-15 00:57:48 +00:00
self . assertTrue ( len ( threads ) == 1 , " Stopped at inner breakpoint. " )
self . thread = threads [ 0 ]
2014-07-28 22:53:49 +00:00
2014-03-15 00:57:48 +00:00
def do_step_out_past_nodebug ( self ) :
# The first step out takes us to the called_from_nodebug frame, just to make sure setting
2016-09-06 20:57:50 +00:00
# step-out-avoid-nodebug doesn't change the behavior in frames with
# debug info.
2014-03-15 00:57:48 +00:00
self . thread . StepOut ( )
2016-09-06 20:57:50 +00:00
self . hit_correct_line (
" intermediate_return_value = called_from_nodebug_actual(some_value) " )
2014-03-15 00:57:48 +00:00
self . thread . StepOut ( )
2016-09-06 20:57:50 +00:00
self . hit_correct_line (
" int return_value = no_debug_caller(5, called_from_nodebug) " )
2014-03-15 00:57:48 +00:00
2016-09-06 20:57:50 +00:00
def do_step_over_past_nodebug ( self ) :
2014-03-15 00:57:48 +00:00
self . thread . StepOver ( )
2016-09-06 20:57:50 +00:00
self . hit_correct_line (
" intermediate_return_value = called_from_nodebug_actual(some_value) " )
2014-03-15 00:57:48 +00:00
self . thread . StepOver ( )
2016-09-06 20:57:50 +00:00
self . hit_correct_line ( " return intermediate_return_value " )
2014-03-15 00:57:48 +00:00
self . thread . StepOver ( )
# Note, lldb doesn't follow gdb's distinction between "step-out" and "step-over/step-in"
# when exiting a frame. In all cases we leave the pc at the point where we exited the
# frame. In gdb, step-over/step-in move to the end of the line they stepped out to.
# If we ever change this we will need to fix this test.
2016-09-06 20:57:50 +00:00
self . hit_correct_line (
" int return_value = no_debug_caller(5, called_from_nodebug) " )
2014-03-15 00:57:48 +00:00
2016-09-06 20:57:50 +00:00
def do_step_in_past_nodebug ( self ) :
2014-03-15 00:57:48 +00:00
self . thread . StepInto ( )
2016-09-06 20:57:50 +00:00
self . hit_correct_line (
" intermediate_return_value = called_from_nodebug_actual(some_value) " )
2014-03-15 00:57:48 +00:00
self . thread . StepInto ( )
2016-09-06 20:57:50 +00:00
self . hit_correct_line ( " return intermediate_return_value " )
2014-03-15 00:57:48 +00:00
self . thread . StepInto ( )
# Note, lldb doesn't follow gdb's distinction between "step-out" and "step-over/step-in"
# when exiting a frame. In all cases we leave the pc at the point where we exited the
# frame. In gdb, step-over/step-in move to the end of the line they stepped out to.
# If we ever change this we will need to fix this test.
2016-09-06 20:57:50 +00:00
self . hit_correct_line (
" int return_value = no_debug_caller(5, called_from_nodebug) " )