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