outcome_gdb.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* Inline GDB pretty printer for result
  2. (C) 2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
  3. File Created: Jun 2024
  4. Boost Software License - Version 1.0 - August 17th, 2003
  5. Permission is hereby granted, free of charge, to any person or organization
  6. obtaining a copy of the software and accompanying documentation covered by
  7. this license (the "Software") to use, reproduce, display, distribute,
  8. execute, and transmit the Software, and to prepare derivative works of the
  9. Software, and to permit third-parties to whom the Software is furnished to
  10. do so, all subject to the following:
  11. The copyright notices in the Software and this entire statement, including
  12. the above license grant, this restriction and the following disclaimer,
  13. must be included in all copies of the Software, in whole or in part, and
  14. all derivative works of the Software, unless such copies or derivative
  15. works are solely in the form of machine-executable object code generated by
  16. a source language processor.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  20. SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  21. FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  22. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef BOOST_OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
  26. #define BOOST_OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
  27. #ifndef BOOST_OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS
  28. #if defined(__ELF__)
  29. #ifdef __clang__
  30. #pragma clang diagnostic push
  31. #pragma clang diagnostic ignored "-Woverlength-strings"
  32. #endif
  33. __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
  34. ".byte 4 /* Python Text */\n"
  35. ".ascii \"gdb.inlined-script\\n\"\n"
  36. ".ascii \"import gdb.printing\\n\"\n"
  37. ".ascii \"import os\\n\"\n"
  38. ".ascii \"def synthesise_gdb_value_from_string(s):\\n\"\n"
  39. ".ascii \" '''For when you want to return a synthetic string from children()'''\\n\"\n"
  40. ".ascii \" return gdb.Value(s + '\\0').cast(gdb.lookup_type('char').pointer())\\n\"\n"
  41. ".ascii \"class OutcomeBasicOutcomePrinter(object):\\n\"\n"
  42. ".ascii \" '''Print an outcome::basic_outcome<T> and outcome::basic_result<T>'''\\n\"\n"
  43. ".ascii \" def __init__(self, val):\\n\"\n"
  44. ".ascii \" self.val = val\\n\"\n"
  45. ".ascii \" def children(self):\\n\"\n"
  46. ".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
  47. ".ascii \" yield ('value', self.val['_state']['_value'])\\n\"\n"
  48. ".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
  49. ".ascii \" yield ('error', self.val['_state']['_error'])\\n\"\n"
  50. ".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
  51. ".ascii \" yield ('exception', self.val['_ptr'])\\n\"\n"
  52. ".ascii \" def display_hint(self):\\n\"\n"
  53. ".ascii \" return None\\n\"\n"
  54. ".ascii \" def to_string(self):\\n\"\n"
  55. ".ascii \" if self.val['_state']['_status']['status_value'] & 54 == 54:\\n\"\n"
  56. ".ascii \" return 'errored (errno, moved from) + exceptioned'\\n\"\n"
  57. ".ascii \" if self.val['_state']['_status']['status_value'] & 50 == 50:\\n\"\n"
  58. ".ascii \" return 'errored (errno, moved from)'\\n\"\n"
  59. ".ascii \" if self.val['_state']['_status']['status_value'] & 38 == 38:\\n\"\n"
  60. ".ascii \" return 'errored + exceptioned (moved from)'\\n\"\n"
  61. ".ascii \" if self.val['_state']['_status']['status_value'] & 36 == 36:\\n\"\n"
  62. ".ascii \" return 'exceptioned (moved from)'\\n\"\n"
  63. ".ascii \" if self.val['_state']['_status']['status_value'] & 35 == 35:\\n\"\n"
  64. ".ascii \" return 'errored (moved from)'\\n\"\n"
  65. ".ascii \" if self.val['_state']['_status']['status_value'] & 33 == 33:\\n\"\n"
  66. ".ascii \" return 'valued (moved from)'\\n\"\n"
  67. ".ascii \" if self.val['_state']['_status']['status_value'] & 22 == 22:\\n\"\n"
  68. ".ascii \" return 'errored (errno) + exceptioned'\\n\"\n"
  69. ".ascii \" if self.val['_state']['_status']['status_value'] & 18 == 18:\\n\"\n"
  70. ".ascii \" return 'errored (errno)'\\n\"\n"
  71. ".ascii \" if self.val['_state']['_status']['status_value'] & 6 == 6:\\n\"\n"
  72. ".ascii \" return 'errored + exceptioned'\\n\"\n"
  73. ".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
  74. ".ascii \" return 'exceptioned'\\n\"\n"
  75. ".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
  76. ".ascii \" return 'errored'\\n\"\n"
  77. ".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
  78. ".ascii \" return 'valued'\\n\"\n"
  79. ".ascii \" if self.val['_state']['_status']['status_value'] & 0xff == 0:\\n\"\n"
  80. ".ascii \" return 'empty'\\n\"\n"
  81. ".ascii \"class OutcomeCResultStatusPrinter(object):\\n\"\n"
  82. ".ascii \" '''Print a C result'''\\n\"\n"
  83. ".ascii \" def __init__(self, val):\\n\"\n"
  84. ".ascii \" self.val = val\\n\"\n"
  85. ".ascii \" def children(self):\\n\"\n"
  86. ".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
  87. ".ascii \" yield ('value', self.val['value'])\\n\"\n"
  88. ".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
  89. ".ascii \" yield ('error', self.val['error'])\\n\"\n"
  90. ".ascii \" def display_hint(self):\\n\"\n"
  91. ".ascii \" return None\\n\"\n"
  92. ".ascii \" def to_string(self):\\n\"\n"
  93. ".ascii \" if self.val['flags'] & 50 == 50:\\n\"\n"
  94. ".ascii \" return 'errored (errno, moved from)'\\n\"\n"
  95. ".ascii \" if self.val['flags'] & 35 == 35:\\n\"\n"
  96. ".ascii \" return 'errored (moved from)'\\n\"\n"
  97. ".ascii \" if self.val['flags'] & 33 == 33:\\n\"\n"
  98. ".ascii \" return 'valued (moved from)'\\n\"\n"
  99. ".ascii \" if self.val['flags'] & 18 == 18:\\n\"\n"
  100. ".ascii \" return 'errored (errno)'\\n\"\n"
  101. ".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
  102. ".ascii \" return 'errored'\\n\"\n"
  103. ".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
  104. ".ascii \" return 'valued'\\n\"\n"
  105. ".ascii \" if self.val['flags'] & 0xff == 0:\\n\"\n"
  106. ".ascii \" return 'empty'\\n\"\n"
  107. ".ascii \"class OutcomeCStatusCodePrinter(object):\\n\"\n"
  108. ".ascii \" '''Print a C status code'''\\n\"\n"
  109. ".ascii \" def __init__(self, val):\\n\"\n"
  110. ".ascii \" self.val = val\\n\"\n"
  111. ".ascii \" def children(self):\\n\"\n"
  112. ".ascii \" yield ('domain', self.val['domain'])\\n\"\n"
  113. ".ascii \" yield ('value', self.val['value'])\\n\"\n"
  114. ".ascii \" def display_hint(self):\\n\"\n"
  115. ".ascii \" return None\\n\"\n"
  116. ".ascii \" def to_string(self):\\n\"\n"
  117. ".ascii \" s = str(self.val['domain'])\\n\"\n"
  118. ".ascii \" if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
  119. ".ascii \" return str(self.val['value']) + ' (' + os.strerror(int(self.val['value'])) + ')'\\n\"\n"
  120. ".ascii \" else:\\n\"\n"
  121. ".ascii \" return self.val['value']\\n\"\n"
  122. ".ascii \"def build_pretty_printer():\\n\"\n"
  123. ".ascii \" pp = gdb.printing.RegexpCollectionPrettyPrinter('outcome_v2')\\n\"\n"
  124. ".ascii \" pp.add_printer('outcome_v2::basic_result', '^(boost::)?outcome_v2[_0-9a-f]*::basic_result<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
  125. ".ascii \" pp.add_printer('outcome_v2::basic_outcome', '^(boost::)?outcome_v2[_0-9a-f]*::basic_outcome<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
  126. ".ascii \" pp.add_printer('cxx_result_status_code_*', '^cxx_result_status_code_.*$', OutcomeCResultStatusPrinter)\\n\"\n"
  127. ".ascii \" pp.add_printer('cxx_status_code_*', '^cxx_status_code_.*$', OutcomeCStatusCodePrinter)\\n\"\n"
  128. ".ascii \" return pp\\n\"\n"
  129. ".ascii \"def register_printers(obj = None):\\n\"\n"
  130. ".ascii \" gdb.printing.register_pretty_printer(obj, build_pretty_printer(), replace = True)\\n\"\n"
  131. ".ascii \"register_printers(gdb.current_objfile())\\n\"\n"
  132. ".byte 0\n"
  133. ".popsection\n");
  134. #ifdef __clang__
  135. #pragma clang diagnostic pop
  136. #endif
  137. #endif
  138. #endif
  139. #endif