Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, 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 22 matching lines...) Expand all Loading... | |
| 33 #ifndef COMMON_LINUX_FILE_ID_H__ | 33 #ifndef COMMON_LINUX_FILE_ID_H__ |
| 34 #define COMMON_LINUX_FILE_ID_H__ | 34 #define COMMON_LINUX_FILE_ID_H__ |
| 35 | 35 |
| 36 #include <limits.h> | 36 #include <limits.h> |
| 37 #include <string> | 37 #include <string> |
| 38 | 38 |
| 39 #include "common/linux/guid_creator.h" | 39 #include "common/linux/guid_creator.h" |
| 40 | 40 |
| 41 namespace google_breakpad { | 41 namespace google_breakpad { |
| 42 | 42 |
| 43 static const size_t kMDGUIDSize = sizeof(MDGUID); | 43 // This is somewhat arbitrary, but GNU binutils' ld defaults to |
| 44 // 'sha1', which is 160 bits == 20 bytes, so this is enough to fit | |
| 45 // that, which most binaries will use. | |
| 46 const size_t kMaxBuildID = 20; | |
|
Lei Zhang
2016/02/10 23:08:50
In src/client/linux/microdump_writer/microdump_wri
| |
| 44 | 47 |
| 45 class FileID { | 48 class FileID { |
| 46 public: | 49 public: |
| 47 explicit FileID(const char* path); | 50 explicit FileID(const char* path); |
| 48 ~FileID() {} | 51 ~FileID() {} |
| 49 | 52 |
| 50 // Load the identifier for the elf file path specified in the constructor into | 53 // Load the identifier for the elf file path specified in the constructor into |
| 51 // |identifier|. Return false if the identifier could not be created for the | 54 // |identifier|. Set |identifier_length| to the length of the identifier in |
| 55 // bytes. Return false if the identifier could not be created for this | |
| 52 // file. | 56 // file. |
| 53 // The current implementation will look for a .note.gnu.build-id | 57 // The current implementation will look for a .note.gnu.build-id |
| 54 // section and use that as the file id, otherwise it falls back to | 58 // section and use that as the file id, otherwise it falls back to |
| 55 // XORing the first 4096 bytes of the .text section to generate an identifier. | 59 // XORing the first 4096 bytes of the .text section to generate an identifier. |
| 56 bool ElfFileIdentifier(uint8_t identifier[kMDGUIDSize]); | 60 bool ElfFileIdentifier(uint8_t identifier[kMaxBuildID], |
| 61 size_t* identifier_length); | |
| 57 | 62 |
| 58 // Load the identifier for the elf file mapped into memory at |base| into | 63 // Load the identifier for the elf file mapped into memory at |base| into |
| 59 // |identifier|. Return false if the identifier could not be created for the | 64 // |identifier|. Set |identifier_length| to the length of the identifier in |
| 65 // bytes. Return false if the identifier could not be created for this | |
| 60 // file. | 66 // file. |
| 61 static bool ElfFileIdentifierFromMappedFile(const void* base, | 67 static bool ElfFileIdentifierFromMappedFile(const void* base, |
| 62 uint8_t identifier[kMDGUIDSize]); | 68 uint8_t identifier[kMaxBuildID], |
| 69 size_t* identifier_length); | |
| 63 | 70 |
| 64 // Convert the |identifier| data to a NULL terminated string. The string will | 71 // Convert the |identifier| data to a NULL terminated string. The string will |
| 65 // be formatted as a UUID (e.g., 22F065BB-FC9C-49F7-80FE-26A7CEBD7BCE). | 72 // be formatted as a UUID (e.g., 22F065BB-FC9C-49F7-80FE-26A7CEBD7BCE). |
| 66 // The |buffer| should be at least 37 bytes long to receive all of the data | 73 // The |buffer| should be at least 37 bytes long to receive all of the data |
| 67 // and termination. Shorter buffers will contain truncated data. | 74 // and termination. Shorter buffers will contain truncated data. |
| 68 static void ConvertIdentifierToString(const uint8_t identifier[kMDGUIDSize], | 75 static void ConvertIdentifierToString(const uint8_t identifier[kMaxBuildID], |
| 69 char* buffer, int buffer_length); | 76 char* buffer, int buffer_length); |
| 70 | 77 |
| 71 private: | 78 private: |
| 72 // Storage for the path specified | 79 // Storage for the path specified |
| 73 std::string path_; | 80 std::string path_; |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 } // namespace google_breakpad | 83 } // namespace google_breakpad |
| 77 | 84 |
| 78 #endif // COMMON_LINUX_FILE_ID_H__ | 85 #endif // COMMON_LINUX_FILE_ID_H__ |
| OLD | NEW |