151ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen//===-- main.c --------------------------------------------------*- C++ -*-===// 251ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// 351ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// The LLVM Compiler Infrastructure 451ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// 551ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// This file is distributed under the University of Illinois Open Source 651ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// License. See LICENSE.TXT for details. 751ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// 851ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen//===----------------------------------------------------------------------===// 951ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen#include <stdio.h> 1051ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen 1151ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// This simple program is to test the lldb Python APIs SBTarget, SBFrame, 1251ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// SBFunction, SBSymbol, and SBAddress. 1351ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// 1451ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// When stopped on breakppint 1, we can get the line entry using SBFrame API 1551ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// SBFrame.GetLineEntry(). We'll get the start address for the the line entry 1651ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// with the SBAddress type, resolve the symbol context using the SBTarget API 1751ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// SBTarget.ResolveSymbolContextForAddress() in order to get the SBSymbol. 1851ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// 1951ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// We then stop at breakpoint 2, get the SBFrame, and the the SBFunction object. 2051ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// 2151ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// The address from calling GetStartAddress() on the symbol and the function 2251ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen// should point to the same address, and we also verify that. 2351ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen 2451ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chenint a(int); 2551ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chenint b(int); 2651ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chenint c(int); 2751ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen 2851ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chenint a(int val) 2951ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen{ 3051ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen if (val <= 1) // Find the line number for breakpoint 1 here. 3151ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen val = b(val); 3251ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen else if (val >= 3) 3351ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen val = c(val); 3451ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen 3551ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen return val; // Find the line number for breakpoint 2 here. 3651ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen} 3751ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen 3851ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chenint b(int val) 3951ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen{ 4051ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen return c(val); 4151ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen} 4251ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen 4351ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chenint c(int val) 4451ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen{ 4551ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen return val + 3; 4651ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen} 4751ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen 4851ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chenint main (int argc, char const *argv[]) 4951ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen{ 5051ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen int A1 = a(1); // a(1) -> b(1) -> c(1) 5151ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen printf("a(1) returns %d\n", A1); 5251ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen 5351ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen int B2 = b(2); // b(2) -> c(2) 5451ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen printf("b(2) returns %d\n", B2); 5551ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen 5651ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen int A3 = a(3); // a(3) -> c(3) 5751ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen printf("a(3) returns %d\n", A3); 5851ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen 5951ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen return 0; 6051ed1b614f2c2b6970f50296d7d41c9de2c30ff4Johnny Chen} 61