ctkBackTrace.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef __ctkBackTrace_h
  16. #define __ctkBackTrace_h
  17. // CTK includes
  18. #include <ctkCoreExport.h>
  19. // Qt includes
  20. #include <QScopedPointer>
  21. #include <QString>
  22. struct ctkBackTracePrivate;
  23. //---------------------------------------------------------------------------
  24. /**
  25. * \ingroup Core
  26. *
  27. * \brief Obtains a back trace from the current execution context.
  28. *
  29. * \remarks It is generally not safe to use this class in signal handlers.
  30. */
  31. class CTK_CORE_EXPORT ctkBackTrace
  32. {
  33. public:
  34. static size_t const DefaultStackSize;
  35. ctkBackTrace(const ctkBackTrace& other);
  36. /**
  37. * \brief Create a back trace.
  38. * \param framesNumber The default maximum stack size.
  39. */
  40. ctkBackTrace(size_t framesNumber = DefaultStackSize);
  41. virtual ~ctkBackTrace() throw();
  42. /**
  43. * @brief Get the stack size.
  44. * @return The number of stack frames for this back trace.
  45. */
  46. size_t stackSize() const;
  47. /**
  48. * @brief Get the return address for a given stack frame.
  49. * @param frameNumber The stack frame number.
  50. * @return The return address for the stack frame with number <code>frameNumber</code>
  51. * or <code>NULL</code> if there is no corresponding stack frame.
  52. */
  53. void* returnAddress(unsigned frameNumber) const;
  54. /**
  55. * @brief Get a textual representation for a given stack frame.
  56. * @param frameNumber The stack frame number.
  57. * @return A string describing the stack frame with number <code>frameNumber</code>
  58. * or a null QString if there is no corresponding stack frame.
  59. */
  60. QString stackFrame(unsigned frameNumber) const;
  61. /**
  62. * @brief Provides programmatic access to the stack trace information.
  63. *
  64. * The zeroth element of the returned list (assuming the list's size is non-zero)
  65. * represents the top of the stack, which is the last method invocation in the sequence.
  66. *
  67. * @return A list of string representations for each stack frame.
  68. */
  69. QList<QString> stackTrace() const;
  70. private:
  71. QScopedPointer<ctkBackTracePrivate> d;
  72. };
  73. #ifdef Q_CC_MSVC
  74. namespace ctk {
  75. CTK_CORE_EXPORT bool DebugSymInitialize();
  76. }
  77. #endif
  78. #endif // __ctkBackTrace_h