Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #define _GNU_SOURCE
  2.  
  3. #include <stdio.h>
  4. #include <limits.h>
  5. #include <string.h>
  6. #include <errno.h>
  7.  
  8. /* ========================================================================= */
  9. static int indent_level = 0;
  10.  
  11. __attribute__ ((no_instrument_function)) static void
  12. indent()
  13. {
  14. int i;
  15.  
  16. /* green TRACE word */
  17. printf("\x1B[32m" "TRACE:" "\x1B[0m");
  18.  
  19. for (i=0; i<indent_level; i++) {
  20. putc(' ', stdout);
  21. }
  22. }
  23.  
  24. __attribute__ ((no_instrument_function)) void
  25. __cyg_profile_func_enter(void *this_fn, void *call_site)
  26. {
  27. char cmd[PATH_MAX];
  28. FILE *p;
  29.  
  30. (void)call_site;
  31.  
  32. indent();
  33.  
  34. sprintf(cmd, "addr2line -pif -e %s %p", program_invocation_name,
  35. this_fn);
  36. p = popen(cmd, "r");
  37. if (p) {
  38. char res[PATH_MAX];
  39. size_t len;
  40.  
  41. fgets(res, sizeof(res), p);
  42. len = strlen(res);
  43. if (len > 1) {
  44. res[len - 1] = '\0';
  45. }
  46. pclose(p);
  47. printf("function %s {\n", res);
  48. } else {
  49. printf("function UNKNOWN (addr %p) {\n", this_fn);
  50. }
  51. indent_level++;
  52. }
  53.  
  54. __attribute__ ((no_instrument_function)) void
  55. __cyg_profile_func_exit(void *this_fn, void *call_site)
  56. {
  57. (void)this_fn;
  58. (void)call_site;
  59.  
  60. indent_level--;
  61. indent();
  62.  
  63. printf("}\n");
  64. }
  65.  
  66. /* ========================================================================= */
  67.  
  68. static void
  69. world()
  70. {
  71. printf("Hello world!\n");
  72. }
  73.  
  74. static void
  75. hello()
  76. {
  77. world();
  78. }
  79.  
  80. int
  81. main()
  82. {
  83. hello();
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement