OLD | NEW |
---|---|
1 // Copyright (c) 2010 Google Inc. | 1 // Copyright (c) 2010 Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 #include <map> | 87 #include <map> |
88 #include <string> | 88 #include <string> |
89 #include <vector> | 89 #include <vector> |
90 | 90 |
91 #include "common/using_std_string.h" | 91 #include "common/using_std_string.h" |
92 #include "google_breakpad/processor/code_module.h" | 92 #include "google_breakpad/processor/code_module.h" |
93 #include "google_breakpad/processor/code_modules.h" | 93 #include "google_breakpad/processor/code_modules.h" |
94 #include "google_breakpad/processor/dump_context.h" | 94 #include "google_breakpad/processor/dump_context.h" |
95 #include "google_breakpad/processor/dump_object.h" | 95 #include "google_breakpad/processor/dump_object.h" |
96 #include "google_breakpad/processor/memory_region.h" | 96 #include "google_breakpad/processor/memory_region.h" |
97 #include "google_breakpad/processor/proc_maps_linux.h" | |
97 | 98 |
98 | 99 |
99 namespace google_breakpad { | 100 namespace google_breakpad { |
100 | 101 |
101 | 102 |
102 using std::map; | 103 using std::map; |
103 using std::vector; | 104 using std::vector; |
104 | 105 |
105 | 106 |
106 class Minidump; | 107 class Minidump; |
107 template<typename AddressType, typename EntryType> class RangeMap; | 108 template<typename AddressType, typename EntryType> class RangeMap; |
108 | 109 |
109 | 110 |
110 // MinidumpObject is the base of all Minidump* objects except for Minidump | 111 // MinidumpObject is the base of all Minidump* objects except for Minidump |
111 // itself. | 112 // itself. |
112 class MinidumpObject : public DumpObject { | 113 class MinidumpObject : public DumpObject { |
113 public: | 114 public: |
114 virtual ~MinidumpObject() {} | 115 virtual ~MinidumpObject() {} |
115 | 116 |
116 protected: | 117 protected: |
117 explicit MinidumpObject(Minidump* minidump); | 118 explicit MinidumpObject(Minidump* minidump); |
118 | 119 |
119 // Refers to the Minidump object that is the ultimate parent of this | 120 // Refers to the Minidump object that is the ultimate parent of this |
120 // Some MinidumpObjects are owned by other MinidumpObjects, but at the | 121 // Some MinidumpObjects are owned by other MinidumpObjects, but at the |
121 // root of the ownership tree is always a Minidump. The Minidump object | 122 // root of the ownership tree is always a Minidump. The Minidump object |
122 // is kept here for access to its seeking and reading facilities, and | 123 // is kept here for access to its seeking and reading facilities, and |
123 // for access to data about the minidump file itself, such as whether | 124 // for access to data about the minidump file itself, such as whether |
124 // it should be byte-swapped. | 125 // it should be byte-swapped. |
125 Minidump* minidump_; | 126 Minidump* minidump_; |
126 }; | 127 }; |
ivanpe
2015/07/27 18:12:42
please, remove the whitespace after the ;
liuandrew
2015/07/27 23:09:26
Done.
| |
127 | 128 |
128 | 129 |
129 // This class exists primarily to provide a virtual destructor in a base | 130 // This class exists primarily to provide a virtual destructor in a base |
130 // class common to all objects that might be stored in | 131 // class common to all objects that might be stored in |
131 // Minidump::mStreamObjects. Some object types will never be stored in | 132 // Minidump::mStreamObjects. Some object types will never be stored in |
132 // Minidump::mStreamObjects, but are represented as streams and adhere to the | 133 // Minidump::mStreamObjects, but are represented as streams and adhere to the |
133 // same interface, and may be derived from this class. | 134 // same interface, and may be derived from this class. |
134 class MinidumpStream : public MinidumpObject { | 135 class MinidumpStream : public MinidumpObject { |
135 public: | 136 public: |
136 virtual ~MinidumpStream() {} | 137 virtual ~MinidumpStream() {} |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 // Return true if the memory protection allows writing. | 802 // Return true if the memory protection allows writing. |
802 bool IsWritable() const; | 803 bool IsWritable() const; |
803 | 804 |
804 // Print a human-readable representation of the object to stdout. | 805 // Print a human-readable representation of the object to stdout. |
805 void Print(); | 806 void Print(); |
806 | 807 |
807 private: | 808 private: |
808 // These objects are managed by MinidumpMemoryInfoList. | 809 // These objects are managed by MinidumpMemoryInfoList. |
809 friend class MinidumpMemoryInfoList; | 810 friend class MinidumpMemoryInfoList; |
810 | 811 |
811 explicit MinidumpMemoryInfo(Minidump* minidump); | 812 explicit MinidumpMemoryInfo(Minidump* minidump_); |
812 | 813 |
813 // This works like MinidumpStream::Read, but is driven by | 814 // This works like MinidumpStream::Read, but is driven by |
814 // MinidumpMemoryInfoList. No size checking is done, because | 815 // MinidumpMemoryInfoList. No size checking is done, because |
815 // MinidumpMemoryInfoList handles that directly. | 816 // MinidumpMemoryInfoList handles that directly. |
816 bool Read(); | 817 bool Read(); |
817 | 818 |
818 MDRawMemoryInfo memory_info_; | 819 MDRawMemoryInfo memory_info_; |
819 }; | 820 }; |
820 | 821 |
821 // MinidumpMemoryInfoList contains a list of information about | 822 // MinidumpMemoryInfoList contains a list of information about |
(...skipping 12 matching lines...) Expand all Loading... | |
834 // Print a human-readable representation of the object to stdout. | 835 // Print a human-readable representation of the object to stdout. |
835 void Print(); | 836 void Print(); |
836 | 837 |
837 private: | 838 private: |
838 friend class Minidump; | 839 friend class Minidump; |
839 | 840 |
840 typedef vector<MinidumpMemoryInfo> MinidumpMemoryInfos; | 841 typedef vector<MinidumpMemoryInfo> MinidumpMemoryInfos; |
841 | 842 |
842 static const uint32_t kStreamType = MD_MEMORY_INFO_LIST_STREAM; | 843 static const uint32_t kStreamType = MD_MEMORY_INFO_LIST_STREAM; |
843 | 844 |
844 explicit MinidumpMemoryInfoList(Minidump* minidump); | 845 explicit MinidumpMemoryInfoList(Minidump* minidump_); |
845 | 846 |
846 bool Read(uint32_t expected_size); | 847 bool Read(uint32_t expected_size); |
847 | 848 |
848 // Access to memory info using addresses as the key. | 849 // Access to memory info using addresses as the key. |
849 RangeMap<uint64_t, unsigned int> *range_map_; | 850 RangeMap<uint64_t, unsigned int> *range_map_; |
850 | 851 |
851 MinidumpMemoryInfos* infos_; | 852 MinidumpMemoryInfos* infos_; |
852 uint32_t info_count_; | 853 uint32_t info_count_; |
853 }; | 854 }; |
854 | 855 |
856 // MinidumpLinuxMaps wraps information about a single mapped memory region | |
857 // from /proc/self/maps. | |
858 class MinidumpLinuxMaps : public MinidumpObject { | |
859 public: | |
860 // The memory address of the base of the mapped region. | |
861 uint64_t GetBase() const { return valid_ ? region_.start : 0; } | |
862 // The size of the mapped region. | |
863 uint64_t GetSize() const { return valid_ ? region_.end - region_.start : 0; } | |
864 | |
865 // The permissions of the mapped region. | |
866 bool IsReadable() const { | |
867 return valid_ ? region_.permissions & MappedMemoryRegion::READ : false; | |
868 } | |
869 bool IsWriteable() const { | |
870 return valid_ ? region_.permissions & MappedMemoryRegion::WRITE : false; | |
871 } | |
872 bool IsExecutable() const { | |
873 return valid_ ? region_.permissions & MappedMemoryRegion::EXECUTE : false; | |
874 } | |
875 bool IsPrivate() const { | |
876 return valid_ ? region_.permissions & MappedMemoryRegion::PRIVATE : false; | |
877 } | |
878 | |
879 // The offset of the mapped region. | |
880 uint64_t GetOffset() const { return valid_ ? region_.offset : 0; } | |
881 | |
882 // The major device number. | |
883 uint8_t GetMajorDevice() const { return valid_ ? region_.major_device : 0; } | |
884 // The minor device number. | |
885 uint8_t GetMinorDevice() const { return valid_ ? region_.minor_device : 0; } | |
886 | |
887 // The inode of the mapped region. | |
888 long GetInode() const { return valid_ ? region_.inode : 0; } | |
889 | |
890 // The pathname of the mapped region. | |
891 const string GetPathname() const { return valid_ ? region_.path : ""; } | |
892 | |
893 // Print the contents of this mapping. | |
894 void Print(); | |
895 | |
896 private: | |
897 // These objects are managed by MinidumpLinuxMapsList. | |
898 friend class MinidumpLinuxMapsList; | |
899 | |
900 // This caller owns the pointer. | |
901 explicit MinidumpLinuxMaps(Minidump *minidump); | |
902 | |
903 // Read data about a single mapping from /proc/self/maps and load the data | |
904 // into this object. The input vector is in the same format as a line from | |
905 // /proc/self/maps. | |
906 | |
907 // The memory region struct that this class wraps. | |
908 struct MappedMemoryRegion region_; | |
909 }; | |
910 | |
911 // MinidumpLinuxMapsList corresponds to the Linux-exclusive MD_LINUX_MAPS | |
912 // stream, which contains the contents of /prod/self/maps, which contains | |
913 // the mapped memory regions and their access permissions. | |
914 class MinidumpLinuxMapsList : public MinidumpStream { | |
915 public: | |
916 virtual ~MinidumpLinuxMapsList(); | |
917 | |
918 // Get mapping at the given memory address. The caller owns the pointer. | |
919 const MinidumpLinuxMaps *GetLinuxMapsForAddress(uint64_t address) const; | |
920 // Get mapping at the given index. The caller owns the pointer. | |
921 const MinidumpLinuxMaps *GetLinuxMapsAtIndex(unsigned int index) const; | |
922 | |
923 // Print the contents of /proc/self/maps to stdout. | |
924 void Print(); | |
925 | |
926 private: | |
927 friend class Minidump; | |
928 | |
929 typedef vector<MinidumpLinuxMaps *> MinidumpLinuxMappings; | |
930 | |
931 static const uint32_t kStreamType = MD_LINUX_MAPS; | |
932 | |
933 // The caller owns the pointer. | |
934 explicit MinidumpLinuxMapsList(Minidump *minidump); | |
935 | |
936 // Read and load the contents of the process mapping data. | |
937 // The stream should have data in the form of /proc/self/maps. | |
938 // This method returns whether the stream was read successfully. | |
939 bool Read(uint32_t expected_size); | |
940 | |
941 // The list of individual mappings. | |
942 MinidumpLinuxMappings *maps_; | |
943 // The number of mappings. | |
944 uint32_t maps_count_; | |
945 }; | |
855 | 946 |
856 // Minidump is the user's interface to a minidump file. It wraps MDRawHeader | 947 // Minidump is the user's interface to a minidump file. It wraps MDRawHeader |
857 // and provides access to the minidump's top-level stream directory. | 948 // and provides access to the minidump's top-level stream directory. |
858 class Minidump { | 949 class Minidump { |
859 public: | 950 public: |
860 // path is the pathname of a file containing the minidump. | 951 // path is the pathname of a file containing the minidump. |
861 explicit Minidump(const string& path); | 952 explicit Minidump(const string& path); |
862 // input is an istream wrapping minidump data. Minidump holds a | 953 // input is an istream wrapping minidump data. Minidump holds a |
863 // weak pointer to input, and the caller must ensure that the stream | 954 // weak pointer to input, and the caller must ensure that the stream |
864 // is valid as long as the Minidump object is. | 955 // is valid as long as the Minidump object is. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
905 virtual MinidumpThreadList* GetThreadList(); | 996 virtual MinidumpThreadList* GetThreadList(); |
906 virtual MinidumpModuleList* GetModuleList(); | 997 virtual MinidumpModuleList* GetModuleList(); |
907 virtual MinidumpMemoryList* GetMemoryList(); | 998 virtual MinidumpMemoryList* GetMemoryList(); |
908 virtual MinidumpException* GetException(); | 999 virtual MinidumpException* GetException(); |
909 virtual MinidumpAssertion* GetAssertion(); | 1000 virtual MinidumpAssertion* GetAssertion(); |
910 virtual MinidumpSystemInfo* GetSystemInfo(); | 1001 virtual MinidumpSystemInfo* GetSystemInfo(); |
911 virtual MinidumpMiscInfo* GetMiscInfo(); | 1002 virtual MinidumpMiscInfo* GetMiscInfo(); |
912 virtual MinidumpBreakpadInfo* GetBreakpadInfo(); | 1003 virtual MinidumpBreakpadInfo* GetBreakpadInfo(); |
913 virtual MinidumpMemoryInfoList* GetMemoryInfoList(); | 1004 virtual MinidumpMemoryInfoList* GetMemoryInfoList(); |
914 | 1005 |
1006 // The next method also calls GetStream, but is exclusive for Linux dumps. | |
1007 virtual MinidumpLinuxMapsList *GetLinuxMapsList(); | |
1008 | |
915 // The next set of methods are provided for users who wish to access | 1009 // The next set of methods are provided for users who wish to access |
916 // data in minidump files directly, while leveraging the rest of | 1010 // data in minidump files directly, while leveraging the rest of |
917 // this class and related classes to handle the basic minidump | 1011 // this class and related classes to handle the basic minidump |
918 // structure and known stream types. | 1012 // structure and known stream types. |
919 | 1013 |
920 unsigned int GetDirectoryEntryCount() const { | 1014 unsigned int GetDirectoryEntryCount() const { |
921 return valid_ ? header_.stream_count : 0; | 1015 return valid_ ? header_.stream_count : 0; |
922 } | 1016 } |
923 const MDRawDirectory* GetDirectoryEntryAtIndex(unsigned int index) const; | 1017 const MDRawDirectory* GetDirectoryEntryAtIndex(unsigned int index) const; |
924 | 1018 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 // construction or after a failed Read(); true following a successful | 1115 // construction or after a failed Read(); true following a successful |
1022 // Read(). | 1116 // Read(). |
1023 bool valid_; | 1117 bool valid_; |
1024 }; | 1118 }; |
1025 | 1119 |
1026 | 1120 |
1027 } // namespace google_breakpad | 1121 } // namespace google_breakpad |
1028 | 1122 |
1029 | 1123 |
1030 #endif // GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_H__ | 1124 #endif // GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_H__ |
OLD | NEW |