60 lines · c
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 using6// SBFrame API SBFrame.GetLineEntry(). We'll get the start addresses for the7// two line entries; with the start address (of SBAddress type), we can then8// resolve the symbol context using the SBTarget API9// SBTarget.ResolveSymbolContextForAddress().10//11// The two symbol context should point to the same symbol, i.e., 'a' function.12 13char my_global_var_of_char_type = 'X'; // Test SBTarget.FindGlobalVariables(...).14 15int a(int);16int b(int);17int c(int);18 19int 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 29int b(int val)30{31 return c(val);32}33 34int c(int val)35{36 return val + 3;37}38 39int main (int argc, char const *argv[], char** env)40{41 // Set a break at entry to main.42 int A1 = a(1); // a(1) -> b(1) -> c(1)43 printf("a(1) returns %d\n", A1);44 45 int B2 = b(2); // b(2) -> c(2)46 printf("b(2) returns %d\n", B2);47 48 int A3 = a(3); // a(3) -> c(3)49 printf("a(3) returns %d\n", A3);50 51 for (int i = 1; i < argc; i++) {52 printf("arg: %s\n", argv[i]);53 }54 55 while (*env)56 printf("env: %s\n", *env++);57 58 return 0;59}60