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