1 | /* |
2 | A program to test DBUG features. Used by tests-t.pl |
3 | */ |
4 | |
5 | char *push1=0; |
6 | |
7 | #include <my_global.h> /* This includes dbug.h */ |
8 | #include <my_sys.h> |
9 | #include <my_pthread.h> |
10 | #include <string.h> |
11 | |
12 | const char *func3() |
13 | { |
14 | DBUG_ENTER("func3" ); |
15 | DBUG_RETURN(DBUG_EVALUATE("ret3" , "ok" , "ko" )); |
16 | } |
17 | |
18 | void func2() |
19 | { |
20 | const char *s __attribute__((unused)); |
21 | DBUG_ENTER("func2" ); |
22 | s=func3(); |
23 | DBUG_PRINT("info" , ("s=%s" , s)); |
24 | DBUG_VOID_RETURN; |
25 | } |
26 | |
27 | int func1() |
28 | { |
29 | DBUG_ENTER("func1" ); |
30 | func2(); |
31 | if (push1) |
32 | { |
33 | DBUG_PUSH(push1); |
34 | fprintf(DBUG_FILE, "=> push1\n" ); |
35 | } |
36 | DBUG_RETURN(10); |
37 | } |
38 | |
39 | int main (int argc __attribute__((unused)), |
40 | char *argv[] __attribute__((unused))) |
41 | { |
42 | #ifdef DBUG_OFF |
43 | return 1; |
44 | #else |
45 | int i; |
46 | if (argc == 1) |
47 | return 0; |
48 | |
49 | MY_INIT("dbug-tests" ); |
50 | |
51 | dup2(1, 2); |
52 | for (i = 1; i < argc; i++) |
53 | { |
54 | if (strncmp(argv[i], "--push1=" , 8) == 0) |
55 | push1=argv[i]+8; |
56 | else |
57 | DBUG_PUSH (argv[i]); |
58 | } |
59 | { |
60 | DBUG_ENTER ("main" ); |
61 | func1(); |
62 | DBUG_EXECUTE_IF("dump" , |
63 | { |
64 | char s[1000]; |
65 | DBUG_EXPLAIN(s, sizeof(s)-1); |
66 | DBUG_DUMP("dump" , (uchar*)s, strlen(s)); |
67 | }); |
68 | DBUG_EXECUTE_IF("push" , DBUG_PUSH("+t" ); ); |
69 | DBUG_EXECUTE("execute" , fprintf(DBUG_FILE, "=> execute\n" ); ); |
70 | DBUG_EXECUTE_IF("set" , DBUG_SET("+F" ); ); |
71 | fprintf(DBUG_FILE, "=> evaluate: %s\n" , |
72 | DBUG_EVALUATE("evaluate" , "ON" , "OFF" )); |
73 | fprintf(DBUG_FILE, "=> evaluate_if: %s\n" , |
74 | DBUG_EVALUATE_IF("evaluate_if" , "ON" , "OFF" )); |
75 | DBUG_EXECUTE_IF("pop" , DBUG_POP(); ); |
76 | { |
77 | char s[1000] __attribute__((unused)); |
78 | DBUG_EXPLAIN(s, sizeof(s)-1); |
79 | DBUG_PRINT("explain" , ("dbug explained: %s" , s)); |
80 | } |
81 | func2(); |
82 | DBUG_LEAVE; |
83 | } |
84 | DBUG_SET("" ); /* to not have my_end() in the traces */ |
85 | my_end(0); |
86 | return 0; |
87 | #endif /* DBUG_OFF */ |
88 | } |
89 | |