xref: /llvm-project/lldb/test/API/python_api/target/main.c (revision 882d8e60dd40c01c74b4e16b02cf7ca02e846434)
199451b44SJordan Rupprecht #include <stdio.h>
299451b44SJordan Rupprecht 
399451b44SJordan Rupprecht // This simple program is to test the lldb Python API SBTarget.
499451b44SJordan Rupprecht //
5e9264b74SKazuaki Ishizaki // When stopped on breakpoint 1, and then 2, we can get the line entries using
699451b44SJordan Rupprecht // SBFrame API SBFrame.GetLineEntry().  We'll get the start addresses for the
799451b44SJordan Rupprecht // two line entries; with the start address (of SBAddress type), we can then
899451b44SJordan Rupprecht // resolve the symbol context using the SBTarget API
999451b44SJordan Rupprecht // SBTarget.ResolveSymbolContextForAddress().
1099451b44SJordan Rupprecht //
1199451b44SJordan Rupprecht // The two symbol context should point to the same symbol, i.e., 'a' function.
1299451b44SJordan Rupprecht 
1399451b44SJordan Rupprecht char my_global_var_of_char_type = 'X'; // Test SBTarget.FindGlobalVariables(...).
1499451b44SJordan Rupprecht 
1599451b44SJordan Rupprecht int a(int);
1699451b44SJordan Rupprecht int b(int);
1799451b44SJordan Rupprecht int c(int);
1899451b44SJordan Rupprecht 
a(int val)1999451b44SJordan Rupprecht int a(int val)
2099451b44SJordan Rupprecht {
2199451b44SJordan Rupprecht     if (val <= 1) // Find the line number for breakpoint 1 here.
2299451b44SJordan Rupprecht         val = b(val);
2399451b44SJordan Rupprecht     else if (val >= 3)
2499451b44SJordan Rupprecht         val = c(val);
2599451b44SJordan Rupprecht 
2699451b44SJordan Rupprecht     return val; // Find the line number for breakpoint 2 here.
2799451b44SJordan Rupprecht }
2899451b44SJordan Rupprecht 
b(int val)2999451b44SJordan Rupprecht int b(int val)
3099451b44SJordan Rupprecht {
3199451b44SJordan Rupprecht     return c(val);
3299451b44SJordan Rupprecht }
3399451b44SJordan Rupprecht 
c(int val)3499451b44SJordan Rupprecht int c(int val)
3599451b44SJordan Rupprecht {
3699451b44SJordan Rupprecht     return val + 3;
3799451b44SJordan Rupprecht }
3899451b44SJordan Rupprecht 
main(int argc,char const * argv[],char ** env)39*882d8e60SJonas Devlieghere int main (int argc, char const *argv[], char** env)
4099451b44SJordan Rupprecht {
4199451b44SJordan Rupprecht     // Set a break at entry to main.
4299451b44SJordan Rupprecht     int A1 = a(1);  // a(1) -> b(1) -> c(1)
4399451b44SJordan Rupprecht     printf("a(1) returns %d\n", A1);
4499451b44SJordan Rupprecht 
4599451b44SJordan Rupprecht     int B2 = b(2);  // b(2) -> c(2)
4699451b44SJordan Rupprecht     printf("b(2) returns %d\n", B2);
4799451b44SJordan Rupprecht 
4899451b44SJordan Rupprecht     int A3 = a(3);  // a(3) -> c(3)
4999451b44SJordan Rupprecht     printf("a(3) returns %d\n", A3);
5099451b44SJordan Rupprecht 
51*882d8e60SJonas Devlieghere     for (int i = 1; i < argc; i++) {
52*882d8e60SJonas Devlieghere       printf("arg: %s\n", argv[i]);
53*882d8e60SJonas Devlieghere     }
54*882d8e60SJonas Devlieghere 
55*882d8e60SJonas Devlieghere     while (*env)
56*882d8e60SJonas Devlieghere       printf("env: %s\n", *env++);
57*882d8e60SJonas Devlieghere 
5899451b44SJordan Rupprecht     return 0;
5999451b44SJordan Rupprecht }
60