1 | #include <stdio.h> |
2 | |
3 | // This simple program is to test the lldb Python API SBTarget. |
4 | // |
5 | // When stopped on breakpoint 1, and then 2, we can get the line entries using |
6 | // SBFrame API SBFrame.GetLineEntry(). We'll get the start addresses for the |
7 | // two line entries; with the start address (of SBAddress type), we can then |
8 | // resolve the symbol context using the SBTarget API |
9 | // SBTarget.ResolveSymbolContextForAddress(). |
10 | // |
11 | // The two symbol context should point to the same symbol, i.e., 'a' function. |
12 | |
13 | char my_global_var_of_char_type = 'X'; // Test SBTarget.FindGlobalVariables(...). |
14 | |
15 | int a(int); |
16 | int b(int); |
17 | int c(int); |
18 | |
19 | int a(int val) |
20 | { |
21 | if (val <= 1) // Find the line number for breakpoint 1 here. |
22 | val = b(val); |
23 | else if (val >= 3) |
24 | val = c(val); |
25 | |
26 | return val; // Find the line number for breakpoint 2 here. |
27 | } |
28 | |
29 | int b(int val) |
30 | { |
31 | return c(val); |
32 | } |
33 | |
34 | int c(int val) |
35 | { |
36 | return val + 3; |
37 | } |
38 | |
39 | int main (int argc, char const *argv[], char** env) |
40 | { |
41 | // Set a break at entry to main. |
42 | int A1 = a(val: 1); // a(1) -> b(1) -> c(1) |
43 | printf(format: "a(1) returns %d\n" , A1); |
44 | |
45 | int B2 = b(val: 2); // b(2) -> c(2) |
46 | printf(format: "b(2) returns %d\n" , B2); |
47 | |
48 | int A3 = a(val: 3); // a(3) -> c(3) |
49 | printf(format: "a(3) returns %d\n" , A3); |
50 | |
51 | for (int i = 1; i < argc; i++) { |
52 | printf(format: "arg: %s\n" , argv[i]); |
53 | } |
54 | |
55 | while (*env) |
56 | printf(format: "env: %s\n" , *env++); |
57 | |
58 | return 0; |
59 | } |
60 | |