@@ -196,9 +196,9 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
196
196
// We haven't registered the image that contains the pointer.
197
197
if (pair_iterator == m_range_module_map.end ()) {
198
198
LLDB_LOG (log,
199
- " [MemoryReader] Could not resolve find module containing pointer "
200
- " {0:x} read from {1:x}." ,
201
- readValue, address.getAddressData ());
199
+ " [MemoryReader] Could not resolve find module containing pointer "
200
+ " {0:x} read from {1:x}." ,
201
+ readValue, address.getAddressData ());
202
202
return process_pointer;
203
203
}
204
204
@@ -230,10 +230,18 @@ LLDBMemoryReader::resolvePointer(swift::remote::RemoteAddress address,
230
230
231
231
bool LLDBMemoryReader::readBytes (swift::remote::RemoteAddress address,
232
232
uint8_t *dest, uint64_t size) {
233
+ Log *log = GetLog (LLDBLog::Types);
233
234
if (m_local_buffer) {
235
+ bool overflow = false ;
234
236
auto addr = address.getAddressData ();
237
+ auto end = llvm::SaturatingAdd (addr, size, &overflow);
238
+ if (overflow) {
239
+ LLDB_LOGV (log, " [MemoryReader] address {0:x} + size {1} overflows" , addr,
240
+ size);
241
+ return false ;
242
+ }
235
243
if (addr >= *m_local_buffer &&
236
- addr + size <= *m_local_buffer + m_local_buffer_size) {
244
+ end <= *m_local_buffer + m_local_buffer_size) {
237
245
// If this crashes, the assumptions stated in
238
246
// GetDynamicTypeAndAddress_Protocol() most likely no longer
239
247
// hold.
@@ -242,16 +250,13 @@ bool LLDBMemoryReader::readBytes(swift::remote::RemoteAddress address,
242
250
}
243
251
}
244
252
245
- Log *log = GetLog (LLDBLog::Types);
246
-
247
253
LLDB_LOGV (log, " [MemoryReader] asked to read {0} bytes at address {1:x}" ,
248
254
size, address.getAddressData ());
249
255
llvm::Optional<Address> maybeAddr =
250
256
resolveRemoteAddressFromSymbolObjectFile (address.getAddressData ());
251
257
252
- if (!maybeAddr)
253
- maybeAddr =
254
- resolveRemoteAddress (address.getAddressData ());
258
+ if (!maybeAddr)
259
+ maybeAddr = resolveRemoteAddress (address.getAddressData ());
255
260
256
261
if (!maybeAddr) {
257
262
LLDB_LOGV (log, " [MemoryReader] could not resolve address {0:x}" ,
@@ -276,7 +281,7 @@ bool LLDBMemoryReader::readBytes(swift::remote::RemoteAddress address,
276
281
}
277
282
Target &target (m_process.GetTarget ());
278
283
Status error;
279
- // We only want to allow the file-cache optimization if we resolved the
284
+ // We only want to allow the file-cache optimization if we resolved the
280
285
// address to section + offset.
281
286
const bool force_live_memory =
282
287
!readMetadataFromFileCacheEnabled () || !addr.IsSectionOffset ();
@@ -309,27 +314,26 @@ bool LLDBMemoryReader::readString(swift::remote::RemoteAddress address,
309
314
std::string &dest) {
310
315
Log *log = GetLog (LLDBLog::Types);
311
316
312
- auto format_string = [](const std::string &dest) {
313
- StreamString stream;
314
- for (auto c : dest) {
315
- if (c >= 32 && c <= 127 ) {
316
- stream << c;
317
- } else {
318
- stream << " \\ 0" ;
319
- stream.PutHex8 (c);
320
- }
317
+ auto format_string = [](const std::string &dest) {
318
+ StreamString stream;
319
+ for (auto c : dest) {
320
+ if (c >= 32 && c <= 127 ) {
321
+ stream << c;
322
+ } else {
323
+ stream << " \\ 0" ;
324
+ stream.PutHex8 (c);
321
325
}
322
- return std::string (stream.GetData ());
323
- };
326
+ }
327
+ return std::string (stream.GetData ());
328
+ };
324
329
LLDB_LOGV (log, " [MemoryReader] asked to read string data at address {0:x}" ,
325
330
address.getAddressData ());
326
331
327
332
llvm::Optional<Address> maybeAddr =
328
333
resolveRemoteAddressFromSymbolObjectFile (address.getAddressData ());
329
334
330
- if (!maybeAddr)
331
- maybeAddr =
332
- resolveRemoteAddress (address.getAddressData ());
335
+ if (!maybeAddr)
336
+ maybeAddr = resolveRemoteAddress (address.getAddressData ());
333
337
334
338
if (!maybeAddr) {
335
339
LLDB_LOGV (log, " [MemoryReader] could not resolve address {0:x}" ,
@@ -344,15 +348,15 @@ bool LLDBMemoryReader::readString(swift::remote::RemoteAddress address,
344
348
LLDB_LOGV (log, " [MemoryReader] Reading memory from symbol rich binary" );
345
349
346
350
dest = object_file->GetCStrFromSection (section.get (), addr.GetOffset ());
347
- LLDB_LOGV (log, " [MemoryReader] memory read returned string: \" {0}\" " ,
348
- format_string (dest));
351
+ LLDB_LOGV (log, " [MemoryReader] memory read returned string: \" {0}\" " ,
352
+ format_string (dest));
349
353
return true ;
350
354
}
351
355
}
352
356
353
357
Target &target (m_process.GetTarget ());
354
358
Status error;
355
- // We only want to allow the file-cache optimization if we resolved the
359
+ // We only want to allow the file-cache optimization if we resolved the
356
360
// address to section + offset.
357
361
const bool force_live_memory =
358
362
!readMetadataFromFileCacheEnabled () || !addr.IsSectionOffset ();
@@ -381,7 +385,8 @@ void LLDBMemoryReader::popLocalBuffer() {
381
385
}
382
386
383
387
llvm::Optional<std::pair<uint64_t , uint64_t >>
384
- LLDBMemoryReader::addModuleToAddressMap (ModuleSP module , bool register_symbol_obj_file) {
388
+ LLDBMemoryReader::addModuleToAddressMap (ModuleSP module ,
389
+ bool register_symbol_obj_file) {
385
390
if (!readMetadataFromFileCacheEnabled ())
386
391
return {};
387
392
@@ -402,11 +407,10 @@ LLDBMemoryReader::addModuleToAddressMap(ModuleSP module, bool register_symbol_ob
402
407
403
408
#ifndef NDEBUG
404
409
static std::initializer_list<uint64_t > objc_bits = {
405
- SWIFT_ABI_ARM_IS_OBJC_BIT,
406
- SWIFT_ABI_X86_64_IS_OBJC_BIT,
410
+ SWIFT_ABI_ARM_IS_OBJC_BIT, SWIFT_ABI_X86_64_IS_OBJC_BIT,
407
411
SWIFT_ABI_ARM64_IS_OBJC_BIT};
408
412
409
- for (auto objc_bit : objc_bits)
413
+ for (auto objc_bit : objc_bits)
410
414
assert ((module_start_address & objc_bit) != objc_bit &&
411
415
" LLDB file address bit clashes with an obj-c bit!" );
412
416
#endif
@@ -523,7 +527,9 @@ LLDBMemoryReader::resolveRemoteAddress(uint64_t address) const {
523
527
return resolved;
524
528
}
525
529
526
- llvm::Optional<Address> LLDBMemoryReader::resolveRemoteAddressFromSymbolObjectFile (uint64_t address) const {
530
+ llvm::Optional<Address>
531
+ LLDBMemoryReader::resolveRemoteAddressFromSymbolObjectFile (
532
+ uint64_t address) const {
527
533
Log *log (GetLog (LLDBLog::Types));
528
534
529
535
if (!m_process.GetTarget ().GetSwiftReadMetadataFromDSYM ())
@@ -555,8 +561,12 @@ llvm::Optional<Address> LLDBMemoryReader::resolveRemoteAddressFromSymbolObjectFi
555
561
file_address, object_file->GetFileSpec ().GetFilename ());
556
562
return {};
557
563
}
558
-
559
- if (!resolved.GetSection ()->GetParent ()->GetName ().GetStringRef ().contains_insensitive (" DWARF" )) {
564
+
565
+ if (!resolved.GetSection ()
566
+ ->GetParent ()
567
+ ->GetName ()
568
+ .GetStringRef ()
569
+ .contains_insensitive (" DWARF" )) {
560
570
auto *main_object_file = module ->GetObjectFile ();
561
571
resolved = Address (file_address, main_object_file->GetSectionList ());
562
572
}
0 commit comments