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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 #ifndef _WIN32 | 82 #ifndef _WIN32 |
83 #include <unistd.h> | 83 #include <unistd.h> |
84 #endif | 84 #endif |
85 | 85 |
86 #include <iostream> | 86 #include <iostream> |
87 #include <map> | 87 #include <map> |
88 #include <string> | 88 #include <string> |
89 #include <vector> | 89 #include <vector> |
90 | 90 |
| 91 #include "common/basictypes.h" |
91 #include "common/using_std_string.h" | 92 #include "common/using_std_string.h" |
92 #include "google_breakpad/processor/code_module.h" | 93 #include "google_breakpad/processor/code_module.h" |
93 #include "google_breakpad/processor/code_modules.h" | 94 #include "google_breakpad/processor/code_modules.h" |
94 #include "google_breakpad/processor/dump_context.h" | 95 #include "google_breakpad/processor/dump_context.h" |
95 #include "google_breakpad/processor/dump_object.h" | 96 #include "google_breakpad/processor/dump_object.h" |
96 #include "google_breakpad/processor/memory_region.h" | 97 #include "google_breakpad/processor/memory_region.h" |
| 98 #include "google_breakpad/processor/proc_maps_linux.h" |
97 | 99 |
98 | 100 |
99 namespace google_breakpad { | 101 namespace google_breakpad { |
100 | 102 |
101 | 103 |
102 using std::map; | 104 using std::map; |
103 using std::vector; | 105 using std::vector; |
104 | 106 |
105 | 107 |
106 class Minidump; | 108 class Minidump; |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 // Return true if the memory protection allows writing. | 803 // Return true if the memory protection allows writing. |
802 bool IsWritable() const; | 804 bool IsWritable() const; |
803 | 805 |
804 // Print a human-readable representation of the object to stdout. | 806 // Print a human-readable representation of the object to stdout. |
805 void Print(); | 807 void Print(); |
806 | 808 |
807 private: | 809 private: |
808 // These objects are managed by MinidumpMemoryInfoList. | 810 // These objects are managed by MinidumpMemoryInfoList. |
809 friend class MinidumpMemoryInfoList; | 811 friend class MinidumpMemoryInfoList; |
810 | 812 |
811 explicit MinidumpMemoryInfo(Minidump* minidump); | 813 explicit MinidumpMemoryInfo(Minidump* minidump_); |
812 | 814 |
813 // This works like MinidumpStream::Read, but is driven by | 815 // This works like MinidumpStream::Read, but is driven by |
814 // MinidumpMemoryInfoList. No size checking is done, because | 816 // MinidumpMemoryInfoList. No size checking is done, because |
815 // MinidumpMemoryInfoList handles that directly. | 817 // MinidumpMemoryInfoList handles that directly. |
816 bool Read(); | 818 bool Read(); |
817 | 819 |
818 MDRawMemoryInfo memory_info_; | 820 MDRawMemoryInfo memory_info_; |
819 }; | 821 }; |
820 | 822 |
821 // MinidumpMemoryInfoList contains a list of information about | 823 // 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. | 836 // Print a human-readable representation of the object to stdout. |
835 void Print(); | 837 void Print(); |
836 | 838 |
837 private: | 839 private: |
838 friend class Minidump; | 840 friend class Minidump; |
839 | 841 |
840 typedef vector<MinidumpMemoryInfo> MinidumpMemoryInfos; | 842 typedef vector<MinidumpMemoryInfo> MinidumpMemoryInfos; |
841 | 843 |
842 static const uint32_t kStreamType = MD_MEMORY_INFO_LIST_STREAM; | 844 static const uint32_t kStreamType = MD_MEMORY_INFO_LIST_STREAM; |
843 | 845 |
844 explicit MinidumpMemoryInfoList(Minidump* minidump); | 846 explicit MinidumpMemoryInfoList(Minidump* minidump_); |
845 | 847 |
846 bool Read(uint32_t expected_size); | 848 bool Read(uint32_t expected_size); |
847 | 849 |
848 // Access to memory info using addresses as the key. | 850 // Access to memory info using addresses as the key. |
849 RangeMap<uint64_t, unsigned int> *range_map_; | 851 RangeMap<uint64_t, unsigned int> *range_map_; |
850 | 852 |
851 MinidumpMemoryInfos* infos_; | 853 MinidumpMemoryInfos* infos_; |
852 uint32_t info_count_; | 854 uint32_t info_count_; |
853 }; | 855 }; |
854 | 856 |
| 857 // MinidumpLinuxMaps wraps information about a single mapped memory region |
| 858 // from /proc/self/maps. |
| 859 class MinidumpLinuxMaps : public MinidumpObject { |
| 860 public: |
| 861 // The memory address of the base of the mapped region. |
| 862 uint64_t GetBase() const { return valid_ ? region_.start : 0; } |
| 863 // The size of the mapped region. |
| 864 uint64_t GetSize() const { return valid_ ? region_.end - region_.start : 0; } |
| 865 |
| 866 // The permissions of the mapped region. |
| 867 bool IsReadable() const { |
| 868 return valid_ ? region_.permissions & MappedMemoryRegion::READ : false; |
| 869 } |
| 870 bool IsWriteable() const { |
| 871 return valid_ ? region_.permissions & MappedMemoryRegion::WRITE : false; |
| 872 } |
| 873 bool IsExecutable() const { |
| 874 return valid_ ? region_.permissions & MappedMemoryRegion::EXECUTE : false; |
| 875 } |
| 876 bool IsPrivate() const { |
| 877 return valid_ ? region_.permissions & MappedMemoryRegion::PRIVATE : false; |
| 878 } |
| 879 |
| 880 // The offset of the mapped region. |
| 881 uint64_t GetOffset() const { return valid_ ? region_.offset : 0; } |
| 882 |
| 883 // The major device number. |
| 884 uint8_t GetMajorDevice() const { return valid_ ? region_.major_device : 0; } |
| 885 // The minor device number. |
| 886 uint8_t GetMinorDevice() const { return valid_ ? region_.minor_device : 0; } |
| 887 |
| 888 // The inode of the mapped region. |
| 889 uint64_t GetInode() const { return valid_ ? region_.inode : 0; } |
| 890 |
| 891 // The pathname of the mapped region. |
| 892 const string GetPathname() const { return valid_ ? region_.path : ""; } |
| 893 |
| 894 // Print the contents of this mapping. |
| 895 void Print(); |
| 896 |
| 897 private: |
| 898 // These objects are managed by MinidumpLinuxMapsList. |
| 899 friend class MinidumpLinuxMapsList; |
| 900 |
| 901 // This caller owns the pointer. |
| 902 explicit MinidumpLinuxMaps(Minidump *minidump); |
| 903 |
| 904 // Read data about a single mapping from /proc/self/maps and load the data |
| 905 // into this object. The input vector is in the same format as a line from |
| 906 // /proc/self/maps. |
| 907 |
| 908 // The memory region struct that this class wraps. |
| 909 MappedMemoryRegion region_; |
| 910 |
| 911 DISALLOW_COPY_AND_ASSIGN(MinidumpLinuxMaps); |
| 912 }; |
| 913 |
| 914 // MinidumpLinuxMapsList corresponds to the Linux-exclusive MD_LINUX_MAPS |
| 915 // stream, which contains the contents of /prod/self/maps, which contains |
| 916 // the mapped memory regions and their access permissions. |
| 917 class MinidumpLinuxMapsList : public MinidumpStream { |
| 918 public: |
| 919 virtual ~MinidumpLinuxMapsList(); |
| 920 |
| 921 // Get mapping at the given memory address. The caller owns the pointer. |
| 922 const MinidumpLinuxMaps *GetLinuxMapsForAddress(uint64_t address) const; |
| 923 // Get mapping at the given index. The caller owns the pointer. |
| 924 const MinidumpLinuxMaps *GetLinuxMapsAtIndex(unsigned int index) const; |
| 925 |
| 926 // Print the contents of /proc/self/maps to stdout. |
| 927 void Print(); |
| 928 |
| 929 private: |
| 930 friend class Minidump; |
| 931 |
| 932 typedef vector<MinidumpLinuxMaps *> MinidumpLinuxMappings; |
| 933 |
| 934 static const uint32_t kStreamType = MD_LINUX_MAPS; |
| 935 |
| 936 // The caller owns the pointer. |
| 937 explicit MinidumpLinuxMapsList(Minidump *minidump); |
| 938 |
| 939 // Read and load the contents of the process mapping data. |
| 940 // The stream should have data in the form of /proc/self/maps. |
| 941 // This method returns whether the stream was read successfully. |
| 942 bool Read(uint32_t expected_size); |
| 943 |
| 944 // The list of individual mappings. |
| 945 MinidumpLinuxMappings *maps_; |
| 946 // The number of mappings. |
| 947 uint32_t maps_count_; |
| 948 |
| 949 DISALLOW_COPY_AND_ASSIGN(MinidumpLinuxMapsList); |
| 950 }; |
855 | 951 |
856 // Minidump is the user's interface to a minidump file. It wraps MDRawHeader | 952 // 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. | 953 // and provides access to the minidump's top-level stream directory. |
858 class Minidump { | 954 class Minidump { |
859 public: | 955 public: |
860 // path is the pathname of a file containing the minidump. | 956 // path is the pathname of a file containing the minidump. |
861 explicit Minidump(const string& path); | 957 explicit Minidump(const string& path); |
862 // input is an istream wrapping minidump data. Minidump holds a | 958 // input is an istream wrapping minidump data. Minidump holds a |
863 // weak pointer to input, and the caller must ensure that the stream | 959 // weak pointer to input, and the caller must ensure that the stream |
864 // is valid as long as the Minidump object is. | 960 // 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(); | 1001 virtual MinidumpThreadList* GetThreadList(); |
906 virtual MinidumpModuleList* GetModuleList(); | 1002 virtual MinidumpModuleList* GetModuleList(); |
907 virtual MinidumpMemoryList* GetMemoryList(); | 1003 virtual MinidumpMemoryList* GetMemoryList(); |
908 virtual MinidumpException* GetException(); | 1004 virtual MinidumpException* GetException(); |
909 virtual MinidumpAssertion* GetAssertion(); | 1005 virtual MinidumpAssertion* GetAssertion(); |
910 virtual MinidumpSystemInfo* GetSystemInfo(); | 1006 virtual MinidumpSystemInfo* GetSystemInfo(); |
911 virtual MinidumpMiscInfo* GetMiscInfo(); | 1007 virtual MinidumpMiscInfo* GetMiscInfo(); |
912 virtual MinidumpBreakpadInfo* GetBreakpadInfo(); | 1008 virtual MinidumpBreakpadInfo* GetBreakpadInfo(); |
913 virtual MinidumpMemoryInfoList* GetMemoryInfoList(); | 1009 virtual MinidumpMemoryInfoList* GetMemoryInfoList(); |
914 | 1010 |
| 1011 // The next method also calls GetStream, but is exclusive for Linux dumps. |
| 1012 virtual MinidumpLinuxMapsList *GetLinuxMapsList(); |
| 1013 |
915 // The next set of methods are provided for users who wish to access | 1014 // The next set of methods are provided for users who wish to access |
916 // data in minidump files directly, while leveraging the rest of | 1015 // data in minidump files directly, while leveraging the rest of |
917 // this class and related classes to handle the basic minidump | 1016 // this class and related classes to handle the basic minidump |
918 // structure and known stream types. | 1017 // structure and known stream types. |
919 | 1018 |
920 unsigned int GetDirectoryEntryCount() const { | 1019 unsigned int GetDirectoryEntryCount() const { |
921 return valid_ ? header_.stream_count : 0; | 1020 return valid_ ? header_.stream_count : 0; |
922 } | 1021 } |
923 const MDRawDirectory* GetDirectoryEntryAtIndex(unsigned int index) const; | 1022 const MDRawDirectory* GetDirectoryEntryAtIndex(unsigned int index) const; |
924 | 1023 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 // construction or after a failed Read(); true following a successful | 1120 // construction or after a failed Read(); true following a successful |
1022 // Read(). | 1121 // Read(). |
1023 bool valid_; | 1122 bool valid_; |
1024 }; | 1123 }; |
1025 | 1124 |
1026 | 1125 |
1027 } // namespace google_breakpad | 1126 } // namespace google_breakpad |
1028 | 1127 |
1029 | 1128 |
1030 #endif // GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_H__ | 1129 #endif // GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_H__ |
OLD | NEW |