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 API SBTarget. 11 // 12 // When stopped on breakppint 1, and then 2, we can get the line entries using 13 // SBFrame API SBFrame.GetLineEntry(). We'll get the start addresses for the 14 // two line entries; with the start address (of SBAddress type), we can then 15 // resolve the symbol context using the SBTarget API 16 // SBTarget.ResolveSymbolContextForAddress(). 17 // 18 // The two symbol context should point to the same symbol, i.e., 'a' function. 19 20 char my_global_var_of_char_type = 'X'; // Test SBTarget.FindGlobalVariables(...). 21 22 int a(int); 23 int b(int); 24 int c(int); 25 26 int a(int val) 27 { 28 if (val <= 1) // Find the line number for breakpoint 1 here. 29 val = b(val); 30 else if (val >= 3) 31 val = c(val); 32 33 return val; // Find the line number for breakpoint 2 here. 34 } 35 36 int b(int val) 37 { 38 return c(val); 39 } 40 41 int c(int val) 42 { 43 return val + 3; 44 } 45 46 int main (int argc, char const *argv[]) 47 { 48 // Set a break at entry to main. 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