1 //===-- main.c --------------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #include <stdio.h>
10 
11 // This simple program is to test the lldb Python APIs SBTarget, SBFrame,
12 // SBFunction, SBSymbol, and SBAddress.
13 //
14 // When stopped on breakppint 1, we can get the line entry using SBFrame API
15 // SBFrame.GetLineEntry().  We'll get the start address for the the line entry
16 // with the SBAddress type, resolve the symbol context using the SBTarget API
17 // SBTarget.ResolveSymbolContextForAddress() in order to get the SBSymbol.
18 //
19 // We then stop at breakpoint 2, get the SBFrame, and the the SBFunction object.
20 //
21 // The address from calling GetStartAddress() on the symbol and the function
22 // should point to the same address, and we also verify that.
23 
24 int a(int);
25 int b(int);
26 int c(int);
27 
a(int val)28 int a(int val)
29 {
30     if (val <= 1) // Find the line number for breakpoint 1 here.
31         val = b(val);
32     else if (val >= 3)
33         val = c(val);
34 
35     return val; // Find the line number for breakpoint 2 here.
36 }
37 
b(int val)38 int b(int val)
39 {
40     return c(val);
41 }
42 
c(int val)43 int c(int val)
44 {
45     return val + 3;
46 }
47 
main(int argc,char const * argv[])48 int main (int argc, char const *argv[])
49 {
50     int A1 = a(1);  // a(1) -> b(1) -> c(1)
51     printf("a(1) returns %d\n", A1);
52 
53     int B2 = b(2);  // b(2) -> c(2)
54     printf("b(2) returns %d\n", B2);
55 
56     int A3 = a(3);  // a(3) -> c(3)
57     printf("a(3) returns %d\n", A3);
58 
59     return 0;
60 }
61