fork download
  1. /*
  2. DBG_L0 exits
  3. DBG_L1 exits + calls
  4. DBG_L2 exits + calls + returns (value)
  5. DBG_L3 exits + calls + returns (address)
  6. DBG_L4 exits + calls + returns (value + address)
  7. DBG_L5 exits + calls + returns + args (value)
  8. DBG_L6 exits + calls + returns + args (address)
  9. DBG_L7 exits + calls + returns + args (value + address)
  10. DBG_L8 exits + calls + returns + args + vars (value)
  11. DBG_L9 exits + calls + returns + args + vars (address)
  12. DBG_LA exits + calls + returns + args + vars (value + address)
  13. */
  14.  
  15.  
  16.  
  17. enum Bool_e
  18. {
  19. False,
  20. True
  21. };
  22.  
  23. #define DBG_LA
  24.  
  25.  
  26. #ifndef _DBG_MACROS_H
  27. #define _DBG_MACROS_H 1U
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31.  
  32.  
  33.  
  34. #define __PRINT_HEADING( HEADING_STR, \
  35.   SPACE_NUM ) \
  36.   printf( "\t" HEADING_STR "%" #SPACE_NUM "s" "file: %s" "\n" \
  37.   "\t" " " "%" #SPACE_NUM "s" "function: %s" "\n", \
  38.   "", \
  39.   __FILE__, \
  40.   "", \
  41.   __FUNC__ )
  42.  
  43. #define __PRINT_NAME( SPACE_NUM, \
  44.   NAME ) \
  45.   printf( "\t" " " "%" #SPACE_NUM "s" "name: " #NAME "\n", \
  46.   "" )
  47.  
  48. #define __PRINT_LINE( SPACE_NUM ) \
  49.   printf( "\t" " " "%" #SPACE_NUM "s" "line: %d" "\n", \
  50.   "", \
  51.   __LINE__ )
  52.  
  53. #if ( defined( DBG_L0 ) \
  54.   defined( DBG_L1 ) \
  55.   defined( DBG_L2 ) \
  56.   defined( DBG_L4 ) \
  57.   defined( DBG_L5 ) \
  58.   defined( DBG_L7 ) \
  59.   defined( DBG_L8 ) \
  60.   defined( DBG_LA ) )
  61. #define __PRINT_VALUE( SPACE_NUM, \
  62.   CONV_SPEC_STR, \
  63.   VALUE ) \
  64.   printf( "\t" " " "%" #SPACE_NUM "s" "value: %" CONV_SPEC_STR "\n", \
  65.   "", \
  66.   VALUE )
  67. #else
  68. #define __PRINT_VALUE( SPACE_NUM, \
  69.   CONV_SPEC_STR, \
  70.   VALUE )
  71. #endif
  72.  
  73. #if ( defined( DBG_L3 ) \
  74.   defined( DBG_L4 ) \
  75.   defined( DBG_L6 ) \
  76.   defined( DBG_L7 ) \
  77.   defined( DBG_L9 ) \
  78.   defined( DBG_LA ) )
  79. #define __PRINT_ADDRESS( SPACE_NUM, \
  80.   ADDRESS ) \
  81.   printf( "\t" " " "%" #SPACE_NUM "s" "address: %p" "\n", \
  82.   "", \
  83.   (void *)ADDRESS )
  84. #else
  85. #define __PRINT_ADDRESS( SPACE_NUM, \
  86.   ADDRESS )
  87. #endif
  88.  
  89. #if ( defined( DBG_L0 ) \
  90.   defined( DBG_L1 ) \
  91.   defined( DBG_L2 ) \
  92.   defined( DBG_L3 ) \
  93.   defined( DBG_L4 ) \
  94.   defined( DBG_L5 ) \
  95.   defined( DBG_L6 ) \
  96.   defined( DBG_L7 ) \
  97.   defined( DBG_L8 ) \
  98.   defined( DBG_L9 ) \
  99.   defined( DBG_LA ) )
  100. #define SET_FUNC_NAME( FUNC ) \
  101.   const char *__FUNC__ = #FUNC
  102. #else
  103. #define SET_FUNC_NAME( FUNC )
  104. #endif
  105.  
  106. #if ( defined( DBG_L1 ) \
  107.   defined( DBG_L2 ) \
  108.   defined( DBG_L3 ) \
  109.   defined( DBG_L4 ) \
  110.   defined( DBG_L5 ) \
  111.   defined( DBG_L6 ) \
  112.   defined( DBG_L7 ) \
  113.   defined( DBG_L8 ) \
  114.   defined( DBG_L9 ) \
  115.   defined( DBG_LA ) )
  116. #define CALL_DUMP() \
  117.   __PRINT_HEADING( "[DBG|CALL]", \
  118.   1 )
  119. #else
  120. #define CALL_DUMP()
  121. #endif
  122.  
  123. #if ( defined( DBG_L5 ) \
  124.   defined( DBG_L6 ) \
  125.   defined( DBG_L7 ) \
  126.   defined( DBG_L8 ) \
  127.   defined( DBG_L9 ) \
  128.   defined( DBG_LA ) )
  129. #define ARG_DUMP( ARG, \
  130.   CONV_SPEC_STR ) \
  131.   do \
  132.   { \
  133.   __PRINT_HEADING( "[ DBG|ARG]", \
  134.   2 ); \
  135.   __PRINT_NAME( 2, \
  136.   ARG ); \
  137.   __PRINT_VALUE( 2, \
  138.   CONV_SPEC_STR, \
  139.   ARG ); \
  140.   __PRINT_ADDRESS( 2, \
  141.   &ARG ); \
  142.   } while ( 0 )
  143.  
  144. #define PTRARG_DUMP( ARG, \
  145.   CONV_SPEC_STR ) \
  146.   do \
  147.   { \
  148.   __PRINT_HEADING( "[ DBG|ARG]", \
  149.   2 ); \
  150.   __PRINT_NAME( 2, \
  151.   ARG ); \
  152.   __PRINT_VALUE( 2, \
  153.   CONV_SPEC_STR, \
  154.   *ARG ); \
  155.   __PRINT_ADDRESS( 2, \
  156.   ARG ); \
  157.   } while ( 0 )
  158. #else
  159. #define ARG_DUMP( ARG, \
  160.   CONV_SPEC_STR )
  161.  
  162. #define PTRARG_DUMP( ARG, \
  163.   CONV_SPEC_STR )
  164. #endif
  165.  
  166. #if ( defined( DBG_L8 ) \
  167.   defined( DBG_L9 ) \
  168.   defined( DBG_LA ) )
  169. #define VAR_DUMP( VAR, \
  170.   CONV_SPEC_STR ) \
  171.   do \
  172.   { \
  173.   __PRINT_HEADING( "[ DBG|VAR]", \
  174.   2 ); \
  175.   __PRINT_NAME( 2, \
  176.   VAR ); \
  177.   __PRINT_VALUE( 2, \
  178.   CONV_SPEC_STR, \
  179.   VAR ); \
  180.   __PRINT_ADDRESS( 2, \
  181.   &VAR ); \
  182.   } while ( 0 )
  183.  
  184. #define PTRVAR_DUMP( VAR, \
  185.   CONV_SPEC_STR ) \
  186.   do \
  187.   { \
  188.   __PRINT_HEADING( "[ DBG|VAR]", \
  189.   2 ); \
  190.   __PRINT_NAME( 2, \
  191.   VAR ); \
  192.   __PRINT_VALUE( 2, \
  193.   CONV_SPEC_STR, \
  194.   *VAR ); \
  195.   __PRINT_ADDRESS( 2, \
  196.   VAR ); \
  197.   } while ( 0 )
  198. #else
  199. #define VAR_DUMP( VAR, \
  200.   CONV_SPEC_STR )
  201.  
  202. #define PTRVAR_DUMP( VAR, \
  203.   CONV_SPEC_STR )
  204. #endif
  205.  
  206. #if ( defined( DBG_L2 ) \
  207.   defined( DBG_L3 ) \
  208.   defined( DBG_L4 ) \
  209.   defined( DBG_L5 ) \
  210.   defined( DBG_L6 ) \
  211.   defined( DBG_L7 ) \
  212.   defined( DBG_L8 ) \
  213.   defined( DBG_L9 ) \
  214.   defined( DBG_LA ) )
  215. #define RET_DUMP( RET, \
  216.   CONV_SPEC_STR ) \
  217.   do \
  218.   { \
  219.   __PRINT_HEADING( "[DBG|RET ]", \
  220.   1 ); \
  221.   __PRINT_LINE( 1 ); \
  222.   __PRINT_VALUE( 1, \
  223.   CONV_SPEC_STR, \
  224.   (RET) ); \
  225.   __PRINT_ADDRESS( 1, \
  226.   &(RET) ); \
  227.   \
  228.   return RET; \
  229.   } while ( 0 )
  230.  
  231. #define PTRRET_DUMP( RET, \
  232.   CONV_SPEC_STR ) \
  233.   do \
  234.   { \
  235.   __PRINT_HEADING( "[DBG|RET ]", \
  236.   1 ); \
  237.   __PRINT_LINE( 1 ); \
  238.   __PRINT_VALUE( 1, \
  239.   CONV_SPEC_STR, \
  240.   *(RET) ); \
  241.   __PRINT_ADDRESS( 1, \
  242.   (RET) ); \
  243.   \
  244.   return RET; \
  245.   } while ( 0 )
  246. #else
  247. #define RET_DUMP( RET, \
  248.   CONV_SPEC_STR ) \
  249.   return RET
  250.  
  251. #define PTRRET_DUMP( RET, \
  252.   CONV_SPEC_STR ) \
  253.   return RET
  254. #endif
  255.  
  256. #if ( defined( DBG_L0 ) \
  257.   defined( DBG_L1 ) \
  258.   defined( DBG_L2 ) \
  259.   defined( DBG_L3 ) \
  260.   defined( DBG_L4 ) \
  261.   defined( DBG_L5 ) \
  262.   defined( DBG_L6 ) \
  263.   defined( DBG_L7 ) \
  264.   defined( DBG_L8 ) \
  265.   defined( DBG_L9 ) \
  266.   defined( DBG_LA ) )
  267. #define EXIT_DUMP( EXIT ) \
  268.   do \
  269.   { \
  270.   __PRINT_HEADING( "[DBG|EXIT]", \
  271.   1 ); \
  272.   __PRINT_LINE( 1 ); \
  273.   __PRINT_VALUE( 1, \
  274.   "d", \
  275.   (EXIT) ); \
  276.   \
  277.   exit( EXIT ); \
  278.   } while ( 0 )
  279. #else
  280. #define EXIT_DUMP( EXIT ) \
  281.   exit( EXIT )
  282. #endif
  283.  
  284. #endif
  285.  
  286.  
  287.  
  288. int operations( int a,
  289. int b,
  290. int * mul )
  291. {
  292. int add;
  293.  
  294.  
  295. SET_FUNC_NAME( operations );
  296. CALL_DUMP();
  297. ARG_DUMP( a, "d" );
  298. ARG_DUMP( b, "d" );
  299. PTRARG_DUMP( mul, "d" );
  300.  
  301. add = a + b;
  302. *mul = a * b;
  303.  
  304.  
  305. RET_DUMP( add, "d" );
  306. }
  307.  
  308.  
  309.  
  310. int main( void )
  311. {
  312. int a = 2, b = 3, add = 0, mul = 0;
  313.  
  314.  
  315. SET_FUNC_NAME( main );
  316. CALL_DUMP();
  317.  
  318. add = operations( a,
  319. b,
  320. &mul );
  321.  
  322.  
  323. EXIT_DUMP( 0 );
  324. }
  325.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:54:15: error: missing binary operator before token "defined"
prog.c:74:15: error: missing binary operator before token "defined"
prog.c:90:15: error: missing binary operator before token "defined"
prog.c:107:15: error: missing binary operator before token "defined"
prog.c:124:15: error: missing binary operator before token "defined"
prog.c:167:15: error: missing binary operator before token "defined"
prog.c:207:15: error: missing binary operator before token "defined"
prog.c:257:15: error: missing binary operator before token "defined"
stdout
Standard output is empty