outcome_gdb.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Inline GDB pretty printer for result
  2. // (C) 2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
  3. // File Created: Jun 2024
  4. //
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License");
  7. // you may not use this file except in compliance with the License.
  8. // You may obtain a copy of the License in the accompanying file
  9. // Licence.txt or at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS,
  15. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. // See the License for the specific language governing permissions and
  17. // limitations under the License.
  18. //
  19. //
  20. // Distributed under the Boost Software License, Version 1.0.
  21. // (See accompanying file Licence.txt or copy at
  22. // http://www.boost.org/LICENSE_1_0.txt)
  23. // Generated on 2024-08-12T21:44:07
  24. #ifndef BOOST_OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
  25. #define BOOST_OUTCOME_INLINE_GDB_PRETTY_PRINTER_H
  26. #ifndef BOOST_OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS
  27. #if defined(__ELF__)
  28. #ifdef __clang__
  29. #pragma clang diagnostic push
  30. #pragma clang diagnostic ignored "-Woverlength-strings"
  31. #endif
  32. __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",%progbits,1\n"
  33. ".ascii \"\\4gdb.inlined-script.BOOST_OUTCOME_INLINE_GDB_PRETTY_PRINTER_H\\n\"\n"
  34. ".ascii \"import gdb.printing\\n\"\n"
  35. ".ascii \"import os\\n\"\n"
  36. ".ascii \"def synthesise_gdb_value_from_string(s):\\n\"\n"
  37. ".ascii \" '''For when you want to return a synthetic string from children()'''\\n\"\n"
  38. ".ascii \" return gdb.Value(s + '\\\\0').cast(gdb.lookup_type('char').pointer())\\n\"\n"
  39. ".ascii \"class OutcomeBasicOutcomePrinter(object):\\n\"\n"
  40. ".ascii \" '''Print an outcome::basic_outcome<T> and outcome::basic_result<T>'''\\n\"\n"
  41. ".ascii \" def __init__(self, val):\\n\"\n"
  42. ".ascii \" self.val = val\\n\"\n"
  43. ".ascii \" def children(self):\\n\"\n"
  44. ".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
  45. ".ascii \" yield ('value', self.val['_state']['_value'])\\n\"\n"
  46. ".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
  47. ".ascii \" yield ('error', self.val['_state']['_error'])\\n\"\n"
  48. ".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
  49. ".ascii \" yield ('exception', self.val['_ptr'])\\n\"\n"
  50. ".ascii \" def display_hint(self):\\n\"\n"
  51. ".ascii \" return None\\n\"\n"
  52. ".ascii \" def to_string(self):\\n\"\n"
  53. ".ascii \" if self.val['_state']['_status']['status_value'] & 54 == 54:\\n\"\n"
  54. ".ascii \" return 'errored (errno, moved from) + exceptioned'\\n\"\n"
  55. ".ascii \" if self.val['_state']['_status']['status_value'] & 50 == 50:\\n\"\n"
  56. ".ascii \" return 'errored (errno, moved from)'\\n\"\n"
  57. ".ascii \" if self.val['_state']['_status']['status_value'] & 38 == 38:\\n\"\n"
  58. ".ascii \" return 'errored + exceptioned (moved from)'\\n\"\n"
  59. ".ascii \" if self.val['_state']['_status']['status_value'] & 36 == 36:\\n\"\n"
  60. ".ascii \" return 'exceptioned (moved from)'\\n\"\n"
  61. ".ascii \" if self.val['_state']['_status']['status_value'] & 35 == 35:\\n\"\n"
  62. ".ascii \" return 'errored (moved from)'\\n\"\n"
  63. ".ascii \" if self.val['_state']['_status']['status_value'] & 33 == 33:\\n\"\n"
  64. ".ascii \" return 'valued (moved from)'\\n\"\n"
  65. ".ascii \" if self.val['_state']['_status']['status_value'] & 22 == 22:\\n\"\n"
  66. ".ascii \" return 'errored (errno) + exceptioned'\\n\"\n"
  67. ".ascii \" if self.val['_state']['_status']['status_value'] & 18 == 18:\\n\"\n"
  68. ".ascii \" return 'errored (errno)'\\n\"\n"
  69. ".ascii \" if self.val['_state']['_status']['status_value'] & 6 == 6:\\n\"\n"
  70. ".ascii \" return 'errored + exceptioned'\\n\"\n"
  71. ".ascii \" if self.val['_state']['_status']['status_value'] & 4 == 4:\\n\"\n"
  72. ".ascii \" return 'exceptioned'\\n\"\n"
  73. ".ascii \" if self.val['_state']['_status']['status_value'] & 2 == 2:\\n\"\n"
  74. ".ascii \" return 'errored'\\n\"\n"
  75. ".ascii \" if self.val['_state']['_status']['status_value'] & 1 == 1:\\n\"\n"
  76. ".ascii \" return 'valued'\\n\"\n"
  77. ".ascii \" if self.val['_state']['_status']['status_value'] & 0xff == 0:\\n\"\n"
  78. ".ascii \" return 'empty'\\n\"\n"
  79. ".ascii \"class OutcomeCResultStatusPrinter(object):\\n\"\n"
  80. ".ascii \" '''Print a C result'''\\n\"\n"
  81. ".ascii \" def __init__(self, val):\\n\"\n"
  82. ".ascii \" self.val = val\\n\"\n"
  83. ".ascii \" def children(self):\\n\"\n"
  84. ".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
  85. ".ascii \" yield ('value', self.val['value'])\\n\"\n"
  86. ".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
  87. ".ascii \" yield ('error', self.val['error'])\\n\"\n"
  88. ".ascii \" def display_hint(self):\\n\"\n"
  89. ".ascii \" return None\\n\"\n"
  90. ".ascii \" def to_string(self):\\n\"\n"
  91. ".ascii \" if self.val['flags'] & 50 == 50:\\n\"\n"
  92. ".ascii \" return 'errored (errno, moved from)'\\n\"\n"
  93. ".ascii \" if self.val['flags'] & 35 == 35:\\n\"\n"
  94. ".ascii \" return 'errored (moved from)'\\n\"\n"
  95. ".ascii \" if self.val['flags'] & 33 == 33:\\n\"\n"
  96. ".ascii \" return 'valued (moved from)'\\n\"\n"
  97. ".ascii \" if self.val['flags'] & 18 == 18:\\n\"\n"
  98. ".ascii \" return 'errored (errno)'\\n\"\n"
  99. ".ascii \" if self.val['flags'] & 2 == 2:\\n\"\n"
  100. ".ascii \" return 'errored'\\n\"\n"
  101. ".ascii \" if self.val['flags'] & 1 == 1:\\n\"\n"
  102. ".ascii \" return 'valued'\\n\"\n"
  103. ".ascii \" if self.val['flags'] & 0xff == 0:\\n\"\n"
  104. ".ascii \" return 'empty'\\n\"\n"
  105. ".ascii \"class OutcomeCStatusCodePrinter(object):\\n\"\n"
  106. ".ascii \" '''Print a C status code'''\\n\"\n"
  107. ".ascii \" def __init__(self, val):\\n\"\n"
  108. ".ascii \" self.val = val\\n\"\n"
  109. ".ascii \" def children(self):\\n\"\n"
  110. ".ascii \" yield ('domain', self.val['domain'])\\n\"\n"
  111. ".ascii \" yield ('value', self.val['value'])\\n\"\n"
  112. ".ascii \" def display_hint(self):\\n\"\n"
  113. ".ascii \" return None\\n\"\n"
  114. ".ascii \" def to_string(self):\\n\"\n"
  115. ".ascii \" s = str(self.val['domain'])\\n\"\n"
  116. ".ascii \" if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
  117. ".ascii \" return str(self.val['value']) + ' (' + os.strerror(int(self.val['value'])) + ')'\\n\"\n"
  118. ".ascii \" else:\\n\"\n"
  119. ".ascii \" return self.val['value']\\n\"\n"
  120. ".ascii \"def build_pretty_printer():\\n\"\n"
  121. ".ascii \" pp = gdb.printing.RegexpCollectionPrettyPrinter('outcome_v2')\\n\"\n"
  122. ".ascii \" pp.add_printer('outcome_v2::basic_result', '^(boost::)?outcome_v2[_0-9a-f]*::basic_result<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
  123. ".ascii \" pp.add_printer('outcome_v2::basic_outcome', '^(boost::)?outcome_v2[_0-9a-f]*::basic_outcome<.*>$', OutcomeBasicOutcomePrinter)\\n\"\n"
  124. ".ascii \" pp.add_printer('cxx_result_status_code_*', '^cxx_result_status_code_.*$', OutcomeCResultStatusPrinter)\\n\"\n"
  125. ".ascii \" pp.add_printer('cxx_status_code_*', '^cxx_status_code_.*$', OutcomeCStatusCodePrinter)\\n\"\n"
  126. ".ascii \" return pp\\n\"\n"
  127. ".ascii \"def register_printers(obj = None):\\n\"\n"
  128. ".ascii \" gdb.printing.register_pretty_printer(obj, build_pretty_printer(), replace = True)\\n\"\n"
  129. ".ascii \"register_printers(gdb.current_objfile())\\n\"\n"
  130. ".byte 0\n"
  131. ".popsection\n");
  132. #ifdef __clang__
  133. #pragma clang diagnostic pop
  134. #endif
  135. #endif // defined(__ELF__)
  136. #endif // !defined(BOOST_OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS)
  137. #endif // !defined(BOOST_OUTCOME_INLINE_GDB_PRETTY_PRINTER_H)