From 4cfd07ef07579c09f0c6077479ecdcd428becdcd Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Mon, 20 Jun 2011 00:26:39 +0000 Subject: [PATCH] Add TestInlinedFrame.py to exercise the newly added SBFrame APIs: IsInlined() and GetFunctionName(). llvm-svn: 133404 --- lldb/test/lldbutil.py | 7 +- lldb/test/python_api/frame/inlines/Makefile | 5 ++ .../frame/inlines/TestInlinedFrame.py | 66 +++++++++++++++++++ lldb/test/python_api/frame/inlines/inlines.c | 53 +++++++++++++++ lldb/test/python_api/frame/inlines/inlines.h | 4 ++ 5 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 lldb/test/python_api/frame/inlines/Makefile create mode 100644 lldb/test/python_api/frame/inlines/TestInlinedFrame.py create mode 100644 lldb/test/python_api/frame/inlines/inlines.c create mode 100644 lldb/test/python_api/frame/inlines/inlines.h diff --git a/lldb/test/lldbutil.py b/lldb/test/lldbutil.py index e963ecdfe5d6..4a1aa3556c79 100644 --- a/lldb/test/lldbutil.py +++ b/lldb/test/lldbutil.py @@ -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() diff --git a/lldb/test/python_api/frame/inlines/Makefile b/lldb/test/python_api/frame/inlines/Makefile new file mode 100644 index 000000000000..c5b0d18f995d --- /dev/null +++ b/lldb/test/python_api/frame/inlines/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := inlines.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/python_api/frame/inlines/TestInlinedFrame.py b/lldb/test/python_api/frame/inlines/TestInlinedFrame.py new file mode 100644 index 000000000000..b6b1e6d3fb6d --- /dev/null +++ b/lldb/test/python_api/frame/inlines/TestInlinedFrame.py @@ -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() diff --git a/lldb/test/python_api/frame/inlines/inlines.c b/lldb/test/python_api/frame/inlines/inlines.c new file mode 100644 index 000000000000..1e920f1ef2f6 --- /dev/null +++ b/lldb/test/python_api/frame/inlines/inlines.c @@ -0,0 +1,53 @@ +#include +#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; +} + + diff --git a/lldb/test/python_api/frame/inlines/inlines.h b/lldb/test/python_api/frame/inlines/inlines.h new file mode 100644 index 000000000000..265d7b4966ed --- /dev/null +++ b/lldb/test/python_api/frame/inlines/inlines.h @@ -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);