Add TestInlinedFrame.py to exercise the newly added SBFrame APIs: IsInlined() and GetFunctionName().

llvm-svn: 133404
This commit is contained in:
Johnny Chen 2011-06-20 00:26:39 +00:00
parent a945a32981
commit 4cfd07ef07
5 changed files with 132 additions and 3 deletions

View File

@ -293,7 +293,7 @@ def get_function_names(thread):
Returns a sequence of function names from the stack frames of this thread.
"""
def GetFuncName(i):
return thread.GetFrameAtIndex(i).GetFunction().GetName()
return thread.GetFrameAtIndex(i).GetFunctionName()
return map(GetFuncName, range(thread.GetNumFrames()))
@ -393,8 +393,9 @@ def print_stacktrace(thread, string_buffer = False):
num=i, addr=load_addr, mod=mods[i], symbol=symbols[i], offset=symbol_offset)
else:
print >> output, " frame #{num}: {addr:#016x} {mod}`{func} at {file}:{line} {args}".format(
num=i, addr=load_addr, mod=mods[i], func=funcs[i], file=files[i], line=lines[i],
args=get_args_as_string(frame, showFuncName=False))
num=i, addr=load_addr, mod=mods[i],
func='%s [inlined]' % funcs[i] if frame.IsInlined() else funcs[i],
file=files[i], line=lines[i], args=get_args_as_string(frame, showFuncName=False))
if string_buffer:
return output.getvalue()

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
C_SOURCES := inlines.c
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,66 @@
"""
Testlldb Python SBFrame APIs IsInlined() and GetFunctionName().
"""
import os, time
import re
import unittest2
import lldb, lldbutil
from lldbtest import *
class InlinedFrameAPITestCase(TestBase):
mydir = os.path.join("python_api", "frame", "inlines")
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@python_api_test
def test_stop_at_outer_inline_dsym(self):
"""Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName()."""
self.buildDsym()
self.do_stop_at_outer_inline()
@python_api_test
def test_stop_at_outer_inline_with_dwarf(self):
"""Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName()."""
self.buildDwarf()
self.do_stop_at_outer_inline()
def do_stop_at_outer_inline(self):
"""Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName()."""
exe = os.path.join(os.getcwd(), "a.out")
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Now create a breakpoint on main.c by name 'c'.
breakpoint = target.BreakpointCreateByName('outer_inline', 'a.out')
#print "breakpoint:", breakpoint
self.assertTrue(breakpoint and
breakpoint.GetNumLocations() > 1,
VALID_BREAKPOINT)
# Now launch the process, and do not stop at the entry point.
process = target.LaunchSimple(None, None, os.getcwd())
process = target.GetProcess()
self.assertTrue(process.GetState() == lldb.eStateStopped,
PROCESS_STOPPED)
# The first breakpoint should correspond to an inlined call frame.
frame0 = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
self.assertTrue(frame0.IsInlined() and
frame0.GetFunctionName() == 'outer_inline')
self.runCmd("bt")
if self.TraceOn():
print "Full stack traces when first stopped on the breakpoint 'outer_inline':"
import lldbutil
print lldbutil.print_stacktraces(process)
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()

View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include "inlines.h"
#define INLINE_ME __inline__ __attribute__((always_inline))
int
not_inlined_2 (int input)
{
printf ("Called in not_inlined_2 with : %d.\n", input);
return input;
}
int
not_inlined_1 (int input)
{
printf ("Called in not_inlined_1 with %d.\n", input);
return not_inlined_2(input);
}
INLINE_ME int
inner_inline (int inner_input, int mod_value)
{
int inner_result;
inner_result = inner_input % mod_value;
printf ("Returning: %d.\n", inner_result);
return not_inlined_1 (inner_result);
}
INLINE_ME int
outer_inline (int outer_input)
{
int outer_result;
outer_result = inner_inline (outer_input, outer_input % 3);
return outer_result;
}
int
main (int argc, char **argv)
{
printf ("Starting...\n");
int (*func_ptr) (int);
func_ptr = outer_inline;
outer_inline (argc);
func_ptr (argc);
return 0;
}

View File

@ -0,0 +1,4 @@
int inner_inline (int inner_input, int mod_value);
int outer_inline (int outer_input);
int not_inlined_2 (int input);
int not_inlined_1 (int input);