stacktrace.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. koops_stacktrace.h
  3. Copyright (C) 2012 ABRT Team
  4. Copyright (C) 2012 Red Hat, Inc.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #ifndef SATYR_KOOPS_STACKTRACE_H
  18. #define SATYR_KOOPS_STACKTRACE_H
  19. /**
  20. * @file
  21. * @brief Kernel oops stack trace structure and related algorithms.
  22. */
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #include "../report_type.h"
  27. #include <stdbool.h>
  28. #include <inttypes.h>
  29. #include <stddef.h>
  30. struct sr_location;
  31. struct sr_json_value;
  32. struct sr_koops_stacktrace
  33. {
  34. enum sr_report_type type;
  35. /**
  36. * @brief Version of the kernel.
  37. */
  38. char *version;
  39. /**
  40. * http://www.mjmwired.net/kernel/Documentation/oops-tracing.txt
  41. */
  42. bool taint_module_proprietary;
  43. bool taint_module_out_of_tree;
  44. bool taint_forced_module;
  45. bool taint_forced_removal;
  46. bool taint_smp_unsafe;
  47. /** A machine check exception has been raised. */
  48. bool taint_mce;
  49. /** A process has been found in a bad page state.*/
  50. bool taint_page_release;
  51. bool taint_userspace;
  52. bool taint_died_recently;
  53. bool taint_acpi_overridden;
  54. bool taint_warning;
  55. bool taint_staging_driver;
  56. bool taint_firmware_workaround;
  57. /**
  58. * @brief List of loaded modules.
  59. *
  60. * It might be NULL as it is sometimes not included in a
  61. * kerneloops.
  62. */
  63. char **modules;
  64. /**
  65. * @brief Raw kerneloops text.
  66. */
  67. char *raw_oops;
  68. /**
  69. * @brief Call trace. It might be NULL as it is not mandatory.
  70. */
  71. struct sr_koops_frame *frames;
  72. };
  73. /**
  74. * Creates and initializes a new stack trace structure.
  75. * @returns
  76. * It never returns NULL. The returned pointer must be released by
  77. * calling the function sr_koops_stacktrace_free().
  78. */
  79. struct sr_koops_stacktrace *
  80. sr_koops_stacktrace_new();
  81. /**
  82. * Initializes all members of the stacktrace structure to their default
  83. * values. No memory is released, members are simply overwritten.
  84. * This is useful for initializing a stacktrace structure placed on the
  85. * stack.
  86. */
  87. void
  88. sr_koops_stacktrace_init(struct sr_koops_stacktrace *stacktrace);
  89. /**
  90. * Releases the memory held by the stacktrace.
  91. * @param stacktrace
  92. * If the stacktrace is NULL, no operation is performed.
  93. */
  94. void
  95. sr_koops_stacktrace_free(struct sr_koops_stacktrace *stacktrace);
  96. /**
  97. * Creates a duplicate of a stacktrace.
  98. * @param stacktrace
  99. * The stacktrace to be copied. It's not modified by this function.
  100. * @returns
  101. * This function never returns NULL. The returned duplicate must be
  102. * released by calling the function sr_koops_stacktrace_free().
  103. */
  104. struct sr_koops_stacktrace *
  105. sr_koops_stacktrace_dup(struct sr_koops_stacktrace *stacktrace);
  106. /**
  107. * Removes the frame from the stack trace and then deletes it.
  108. * @returns
  109. * True if the frame was found in the thread and removed and deleted.
  110. * False if the frame was not found in the thread.
  111. */
  112. bool
  113. sr_koops_stacktrace_remove_frame(struct sr_koops_stacktrace *stacktrace,
  114. struct sr_koops_frame *frame);
  115. /**
  116. * Parses a textual kernel oops and puts it into a structure. If
  117. * parsing fails, the input parameter is not changed and NULL is
  118. * returned.
  119. * @param input
  120. * Pointer to the string with the kernel oops. If this function
  121. * returns a non-NULL value, the input pointer is modified to point
  122. * after the stacktrace that was just parsed.
  123. */
  124. struct sr_koops_stacktrace *
  125. sr_koops_stacktrace_parse(const char **input,
  126. struct sr_location *location);
  127. char **
  128. sr_koops_stacktrace_parse_modules(const char **input);
  129. /**
  130. * Returns brief, human-readable explanation of the stacktrace.
  131. */
  132. char *
  133. sr_koops_stacktrace_get_reason(struct sr_koops_stacktrace *stacktrace);
  134. /**
  135. * Serializes stacktrace to string.
  136. * @returns
  137. * Newly allocated memory containing the textual representation of the
  138. * provided stacktrace. Caller should free the memory when it's no
  139. * longer needed.
  140. */
  141. char *
  142. sr_koops_stacktrace_to_json(struct sr_koops_stacktrace *stacktrace);
  143. /**
  144. * Deserializes stacktrace from JSON representation.
  145. * @param root
  146. * JSON value to be deserialized.
  147. * @param error_message
  148. * On error, *error_message will contain the description of the error.
  149. * @returns
  150. * Resulting stacktrace, or NULL on error.
  151. */
  152. struct sr_koops_stacktrace *
  153. sr_koops_stacktrace_from_json(struct sr_json_value *root, char **error_message);
  154. void
  155. sr_normalize_koops_stacktrace(struct sr_koops_stacktrace *stacktrace);
  156. #ifdef __cplusplus
  157. }
  158. #endif
  159. #endif