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 demonstrate the capability of the lldb command 11 // "breakpoint command add" to add a set of commands to a breakpoint to be 12 // executed when the breakpoint is hit. 13 // 14 // In particular, we want to break within c(), but only if the immediate caller 15 // is a(). 16 17 int a(int); 18 int b(int); 19 int c(int); 20 21 int a(int val) 22 { 23 if (val <= 1) 24 return b(val); 25 else if (val >= 3) 26 return c(val); // Find the line number where c's parent frame is a here. 27 28 return val; 29 } 30 31 int b(int val) 32 { 33 return c(val); 34 } 35 36 int c(int val) 37 { 38 return val + 3; 39 } 40 41 int main (int argc, char const *argv[]) 42 { 43 int A1 = a(1); // a(1) -> b(1) -> c(1) 44 printf("a(1) returns %d\n", A1); 45 46 int B2 = b(2); // b(2) -> c(2) 47 printf("b(2) returns %d\n", B2); 48 49 int A3 = a(3); // a(3) -> c(3) 50 printf("a(3) returns %d\n", A3); 51 52 return 0; 53 } 54