PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/breakpad/client/windows/unittests/dump_analysis.h

http://github.com/tomahawk-player/tomahawk
C Header | 102 lines | 51 code | 16 blank | 35 comment | 1 complexity | a8cc6eb21089e4c32e88e531b14504a8 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  1. // Copyright (c) 2010, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. #ifndef CLIENT_WINDOWS_UNITTESTS_DUMP_ANALYSIS_H_
  30. #define CLIENT_WINDOWS_UNITTESTS_DUMP_ANALYSIS_H_
  31. #include "../crash_generation/minidump_generator.h"
  32. // Convenience to get to the PEB pointer in a TEB.
  33. struct FakeTEB {
  34. char dummy[0x30];
  35. void* peb;
  36. };
  37. class DumpAnalysis {
  38. public:
  39. explicit DumpAnalysis(const std::wstring& file_path)
  40. : dump_file_(file_path), dump_file_view_(NULL), dump_file_mapping_(NULL),
  41. dump_file_handle_(NULL) {
  42. EnsureDumpMapped();
  43. }
  44. ~DumpAnalysis();
  45. bool HasStream(ULONG stream_number) const;
  46. // This is template to keep type safety in the front, but we end up casting
  47. // to void** inside the implementation to pass the pointer to Win32. So
  48. // casting here is considered safe.
  49. template <class StreamType>
  50. size_t GetStream(ULONG stream_number, StreamType** stream) const {
  51. return GetStreamImpl(stream_number, reinterpret_cast<void**>(stream));
  52. }
  53. bool HasTebs() const;
  54. bool HasPeb() const;
  55. bool HasMemory(ULONG64 address) const {
  56. return HasMemory<BYTE>(address, NULL);
  57. }
  58. bool HasMemory(const void* address) const {
  59. return HasMemory<BYTE>(address, NULL);
  60. }
  61. template <class StructureType>
  62. bool HasMemory(ULONG64 address, StructureType** structure = NULL) const {
  63. // We can't cope with 64 bit addresses for now.
  64. if (address > 0xFFFFFFFFUL)
  65. return false;
  66. return HasMemory(reinterpret_cast<void*>(address), structure);
  67. }
  68. template <class StructureType>
  69. bool HasMemory(const void* addr_in, StructureType** structure = NULL) const {
  70. return HasMemoryImpl(addr_in, sizeof(StructureType),
  71. reinterpret_cast<void**>(structure));
  72. }
  73. protected:
  74. void EnsureDumpMapped();
  75. HANDLE dump_file_mapping_;
  76. HANDLE dump_file_handle_;
  77. void* dump_file_view_;
  78. std::wstring dump_file_;
  79. private:
  80. // This is the implementation of GetStream<>.
  81. size_t GetStreamImpl(ULONG stream_number, void** stream) const;
  82. // This is the implementation of HasMemory<>.
  83. bool HasMemoryImpl(const void* addr_in, size_t pointersize,
  84. void** structure) const;
  85. };
  86. #endif // CLIENT_WINDOWS_UNITTESTS_DUMP_ANALYSIS_H_