A dynamic tracer for Linux

type.h 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef _PLY_TYPE_H
  2. #define _PLY_TYPE_H
  3. #include <stddef.h>
  4. #include <stdio.h>
  5. struct ttdef {
  6. char *name;
  7. struct type *type;
  8. };
  9. struct tscalar {
  10. size_t size;
  11. int is_signed:1;
  12. char *name;
  13. };
  14. struct tptr {
  15. struct type *type;
  16. };
  17. struct tarray {
  18. struct type *type;
  19. size_t len;
  20. };
  21. struct tmap {
  22. struct type *vtype;
  23. struct type *ktype;
  24. size_t len;
  25. };
  26. struct tfield {
  27. char *name;
  28. struct type *type;
  29. /* function arguments */
  30. int optional:1;
  31. };
  32. #define tfields_foreach(_f, _fields) \
  33. for ((_f) = (_fields); (_f)->type->ttype != T_VOID; (_f)++)
  34. struct tstruct {
  35. char *name;
  36. int packed:1;
  37. struct tfield *fields;
  38. };
  39. struct tfunc {
  40. struct type *type;
  41. struct tfield *args;
  42. };
  43. enum ttype {
  44. T_VOID,
  45. T_TYPEDEF,
  46. T_SCALAR,
  47. T_POINTER,
  48. T_ARRAY,
  49. T_MAP,
  50. T_STRUCT,
  51. /* T_UNION, TODO */
  52. T_FUNC,
  53. };
  54. struct type {
  55. enum ttype ttype;
  56. union {
  57. struct ttdef tdef;
  58. struct tscalar scalar;
  59. struct tptr ptr;
  60. struct tarray array;
  61. struct tmap map;
  62. struct tstruct sou;
  63. struct tfunc func;
  64. };
  65. };
  66. int type_equal (struct type *a, struct type *b);
  67. int type_compatible(struct type *a, struct type *b);
  68. void type_dump (struct type *t, FILE *fp);
  69. void type_dump_cdecl(struct type *t, FILE *fp);
  70. ssize_t type_alignof(struct type *t);
  71. ssize_t type_offsetof(struct type *t, const char *field);
  72. ssize_t type_sizeof(struct type *t);
  73. int type_add(struct type *t);
  74. int type_add_list(struct type **ts);
  75. struct type *type_array_of(struct type *type, size_t len);
  76. struct type *type_map_of(struct type *ktype, struct type *vtype);
  77. struct type *type_ptr_of(struct type *type);
  78. /* built-in types */
  79. extern struct type t_void;
  80. extern struct type t_char;
  81. extern struct type t_schar;
  82. extern struct type t_uchar;
  83. extern struct type t_short;
  84. extern struct type t_sshort;
  85. extern struct type t_ushort;
  86. extern struct type t_int;
  87. extern struct type t_sint;
  88. extern struct type t_uint;
  89. extern struct type t_long;
  90. extern struct type t_slong;
  91. extern struct type t_ulong;
  92. extern struct type t_llong;
  93. extern struct type t_sllong;
  94. extern struct type t_ullong;
  95. #endif /* _PLY_TYPE_H */