A dynamic tracer for Linux

ply.c 833B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "node.h"
  4. #include "sym.h"
  5. typedef struct prog {
  6. char *probe;
  7. node_t *ast;
  8. symtab_t locals;
  9. symtab_t *globals;
  10. } prog_t;
  11. symtab_t globals = { .sym = NULL, .len = 0 };
  12. prog_t *prog_get(void)
  13. {
  14. prog_t *p;
  15. p = calloc(1, sizeof(*p));
  16. p->globals = &globals,
  17. /* reads{pid()} @ quantize(arg2) */
  18. p->ast =
  19. node_expr('@',
  20. node_cons(
  21. node_expr('m',
  22. node_cons(
  23. node_ident("reads"),
  24. node_expr('(', node_ident("pid"))
  25. )
  26. ),
  27. node_expr('(',
  28. node_cons(
  29. node_ident("quantize"),
  30. node_ident("arg2")
  31. )
  32. )
  33. )
  34. );
  35. return p;
  36. }
  37. int main(void)
  38. {
  39. node_dump_info_t info = {
  40. .indent = 2,
  41. .fp = stdout,
  42. };
  43. prog_t *p = prog_get();
  44. node_dump(p->ast, &info);
  45. return 0;
  46. }