|
14 | 14 |
|
15 | 15 | #include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
|
16 | 16 | #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
|
| 17 | +#include "Plugins/TypeSystem/Swift/SwiftDemangle.h" |
17 | 18 | #include "Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h"
|
| 19 | +#include "lldb/Core/Address.h" |
18 | 20 | #include "lldb/DataFormatters/FormattersHelpers.h"
|
19 | 21 | #include "lldb/Target/Process.h"
|
20 | 22 | #include "lldb/Target/Target.h"
|
|
23 | 25 | // FIXME: we should not need this
|
24 | 26 | #include "Plugins/Language/ObjC/Cocoa.h"
|
25 | 27 | #include "lldb/lldb-enumerations.h"
|
| 28 | +#include "swift/Demangling/Demangler.h" |
26 | 29 |
|
27 | 30 | using namespace lldb;
|
28 | 31 | using namespace lldb_private;
|
@@ -460,6 +463,41 @@ SwiftArrayBufferHandler::CreateBufferHandler(ValueObject &static_valobj) {
|
460 | 463 | lldb::addr_t storage_location =
|
461 | 464 | buffer_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
|
462 | 465 |
|
| 466 | + lldb_private::Address addr = Address(); |
| 467 | + addr.SetLoadAddress(storage_location, exe_ctx.GetTargetPtr()); |
| 468 | + |
| 469 | + // If the storage_location points to a swiftEmptyArrayStorage symbol, return |
| 470 | + // a SwiftArrayEmptyBufferHandler. |
| 471 | + if (auto *symbol = addr.CalculateSymbolContextSymbol()) { |
| 472 | + auto mangledName = symbol->GetMangled().GetMangledName().GetStringRef(); |
| 473 | + using namespace ::swift::Demangle; |
| 474 | + Demangler dem; |
| 475 | + NodePointer node = dem.demangleSymbol(mangledName); |
| 476 | + if (node && swift_demangle::NodeAtPath(node, Node::Kind::Global)) { |
| 477 | + auto *class_node = swift_demangle::ChildAtPath( |
| 478 | + node, |
| 479 | + {Node::Kind::TypeMetadata, Node::Kind::Type, Node::Kind::Class}); |
| 480 | + if (class_node && class_node->getNumChildren() == 2) { |
| 481 | + auto *module_node = class_node->getFirstChild(); |
| 482 | + auto *ident_node = class_node->getLastChild(); |
| 483 | + if (module_node->getKind() == Node::Kind::Module && |
| 484 | + module_node->hasText() && |
| 485 | + ident_node->getKind() == Node::Kind::Identifier && |
| 486 | + ident_node->hasText()) { |
| 487 | + auto module_name = module_node->getText(); |
| 488 | + auto class_name = ident_node->getText(); |
| 489 | + if (module_name == ::swift::STDLIB_NAME && |
| 490 | + class_name == "__EmptyArrayStorage") { |
| 491 | + CompilerType elem_type( |
| 492 | + valobj.GetCompilerType().GetArrayElementType(exe_scope)); |
| 493 | + return std::unique_ptr<SwiftArrayBufferHandler>( |
| 494 | + new SwiftArrayEmptyBufferHandler(elem_type)); |
| 495 | + } |
| 496 | + } |
| 497 | + } |
| 498 | + } |
| 499 | + } |
| 500 | + |
463 | 501 | if (storage_location != LLDB_INVALID_ADDRESS) {
|
464 | 502 | ProcessSP process_sp(valobj.GetProcessSP());
|
465 | 503 | if (!process_sp)
|
|
0 commit comments