Reads a line from a maps file being read by maps_file_reader and extends mappings with a new MemoryMap::Mapping describing the line.
| 55 | }; |
| 56 | |
| 57 | // Reads a line from a maps file being read by maps_file_reader and extends |
| 58 | // mappings with a new MemoryMap::Mapping describing the line. |
| 59 | ParseResult ParseMapsLine(DelimitedFileReader* maps_file_reader, |
| 60 | std::vector<MemoryMap::Mapping>* mappings) { |
| 61 | std::string field; |
| 62 | LinuxVMAddress start_address; |
| 63 | switch (maps_file_reader->GetDelim('-', &field)) { |
| 64 | case DelimitedFileReader::Result::kError: |
| 65 | return ParseResult::kError; |
| 66 | case DelimitedFileReader::Result::kEndOfFile: |
| 67 | return ParseResult::kEndOfFile; |
| 68 | case DelimitedFileReader::Result::kSuccess: |
| 69 | field.pop_back(); |
| 70 | if (!HexStringToNumber(field, &start_address)) { |
| 71 | LOG(ERROR) << "format error"; |
| 72 | return ParseResult::kError; |
| 73 | } |
| 74 | if (!mappings->empty() && start_address < mappings->back().range.End()) { |
| 75 | return ParseResult::kRetry; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | LinuxVMAddress end_address; |
| 80 | if (maps_file_reader->GetDelim(' ', &field) != |
| 81 | DelimitedFileReader::Result::kSuccess || |
| 82 | (field.pop_back(), !HexStringToNumber(field, &end_address))) { |
| 83 | LOG(ERROR) << "format error"; |
| 84 | return ParseResult::kError; |
| 85 | } |
| 86 | if (end_address < start_address) { |
| 87 | LOG(ERROR) << "format error"; |
| 88 | return ParseResult::kError; |
| 89 | } |
| 90 | // Skip zero-length mappings. |
| 91 | if (end_address == start_address) { |
| 92 | std::string rest_of_line; |
| 93 | if (maps_file_reader->GetLine(&rest_of_line) != |
| 94 | DelimitedFileReader::Result::kSuccess) { |
| 95 | LOG(ERROR) << "format error"; |
| 96 | return ParseResult::kError; |
| 97 | } |
| 98 | return ParseResult::kSuccess; |
| 99 | } |
| 100 | |
| 101 | // TODO(jperaza): set bitness properly |
| 102 | #if defined(ARCH_CPU_64_BITS) |
| 103 | constexpr bool is_64_bit = true; |
| 104 | #else |
| 105 | constexpr bool is_64_bit = false; |
| 106 | #endif |
| 107 | |
| 108 | MemoryMap::Mapping mapping; |
| 109 | mapping.range.SetRange(is_64_bit, start_address, end_address - start_address); |
| 110 | |
| 111 | if (maps_file_reader->GetDelim(' ', &field) != |
| 112 | DelimitedFileReader::Result::kSuccess || |
| 113 | (field.pop_back(), field.size() != 4)) { |
| 114 | LOG(ERROR) << "format error"; |
no test coverage detected