@@ -260,15 +260,12 @@ std::shared_ptr<LLDBMemoryReader> SwiftLanguageRuntime::GetMemoryReader() {
260
260
return m_memory_reader_sp;
261
261
}
262
262
263
- void SwiftLanguageRuntime::PushLocalBuffer (uint64_t local_buffer,
263
+ MemoryReaderLocalBufferHolder SwiftLanguageRuntime::PushLocalBuffer (uint64_t local_buffer,
264
264
uint64_t local_buffer_size) {
265
- ((LLDBMemoryReader *)GetMemoryReader ().get ())
265
+ return ((LLDBMemoryReader *)GetMemoryReader ().get ())
266
266
->pushLocalBuffer (local_buffer, local_buffer_size);
267
267
}
268
268
269
- void SwiftLanguageRuntime::PopLocalBuffer () {
270
- ((LLDBMemoryReader *)GetMemoryReader ().get ())->popLocalBuffer ();
271
- }
272
269
273
270
class LLDBTypeInfoProvider : public swift ::remote::TypeInfoProvider {
274
271
SwiftLanguageRuntime &m_runtime;
@@ -1599,8 +1596,7 @@ llvm::Expected<std::string> SwiftLanguageRuntime::GetEnumCaseName(
1599
1596
return " " ;
1600
1597
1601
1598
auto *eti = llvm::cast<EnumTypeInfo>(ti);
1602
- PushLocalBuffer ((int64_t )data.GetDataStart (), data.GetByteSize ());
1603
- auto defer = llvm::make_scope_exit ([&] { PopLocalBuffer (); });
1599
+ auto buffer_holder = PushLocalBuffer ((int64_t )data.GetDataStart (), data.GetByteSize ());
1604
1600
RemoteAddress addr (data.GetDataStart ());
1605
1601
int case_index;
1606
1602
if (eti->projectEnumValue (*GetMemoryReader (), addr, &case_index))
@@ -2313,85 +2309,87 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Existential(
2313
2309
return false ;
2314
2310
}
2315
2311
2312
+ // This scope is needed because the validation code will call PushLocalBuffer,
2313
+ // so we need to pop it before that call.
2314
+ {
2315
+ MemoryReaderLocalBufferHolder holder;
2316
+ if (use_local_buffer)
2317
+ holder = PushLocalBuffer (
2318
+ existential_address,
2319
+ llvm::expectedToOptional (in_value.GetByteSize ()).value_or (0 ));
2316
2320
2317
- if (use_local_buffer)
2318
- PushLocalBuffer (
2319
- existential_address,
2320
- llvm::expectedToOptional (in_value.GetByteSize ()).value_or (0 ));
2321
-
2322
- swift::remote::RemoteAddress remote_existential (existential_address);
2323
-
2324
- ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
2325
- if (!reflection_ctx)
2326
- return false ;
2327
- auto tr_ts = tss->GetTypeSystemSwiftTypeRef ();
2328
- if (!tr_ts)
2329
- return false ;
2330
-
2331
- auto flavor = SwiftLanguageRuntime::GetManglingFlavor (
2332
- existential_type.GetMangledTypeName ());
2333
- CompilerType dynamic_type;
2334
- uint64_t dynamic_address = 0 ;
2335
- if (flavor == swift::Mangle::ManglingFlavor::Default) {
2336
- auto pair = reflection_ctx->ProjectExistentialAndUnwrapClass (
2337
- remote_existential, *existential_typeref, tr_ts->GetDescriptorFinder ());
2338
-
2339
- if (!pair) {
2340
- if (log )
2341
- log ->Printf (" Runtime failed to get dynamic type of existential" );
2342
- return false ;
2343
- }
2344
-
2345
- const swift::reflection::TypeRef *typeref;
2346
- swift::remote::RemoteAddress out_address (nullptr );
2347
- std::tie (typeref, out_address) = *pair;
2321
+ swift::remote::RemoteAddress remote_existential (existential_address);
2348
2322
2349
- auto ts = tss->GetTypeSystemSwiftTypeRef ();
2350
- if (!ts)
2351
- return false ;
2352
- swift::Demangle::Demangler dem;
2353
- swift::Demangle::NodePointer node = typeref->getDemangling (dem);
2354
- dynamic_type = ts->RemangleAsType (dem, node, flavor);
2355
- dynamic_address = out_address.getAddressData ();
2356
- } else {
2357
- // In the embedded Swift case, the existential container just points to the
2358
- // instance.
2359
- auto reflection_ctx = GetReflectionContext ();
2323
+ ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
2360
2324
if (!reflection_ctx)
2361
2325
return false ;
2362
- auto maybe_addr_or_symbol =
2363
- reflection_ctx->ReadPointer (existential_address);
2364
- if (!maybe_addr_or_symbol)
2326
+ auto tr_ts = tss->GetTypeSystemSwiftTypeRef ();
2327
+ if (!tr_ts)
2365
2328
return false ;
2366
2329
2367
- uint64_t address = 0 ;
2368
- if (maybe_addr_or_symbol->isResolved ()) {
2369
- address = maybe_addr_or_symbol->getOffset ();
2330
+ auto flavor = SwiftLanguageRuntime::GetManglingFlavor (
2331
+ existential_type.GetMangledTypeName ());
2332
+ CompilerType dynamic_type;
2333
+ uint64_t dynamic_address = 0 ;
2334
+ if (flavor == swift::Mangle::ManglingFlavor::Default) {
2335
+ auto pair = reflection_ctx->ProjectExistentialAndUnwrapClass (
2336
+ remote_existential, *existential_typeref,
2337
+ tr_ts->GetDescriptorFinder ());
2338
+
2339
+ if (!pair) {
2340
+ if (log )
2341
+ log ->Printf (" Runtime failed to get dynamic type of existential" );
2342
+ return false ;
2343
+ }
2344
+
2345
+ const swift::reflection::TypeRef *typeref;
2346
+ swift::remote::RemoteAddress out_address (nullptr );
2347
+ std::tie (typeref, out_address) = *pair;
2348
+
2349
+ auto ts = tss->GetTypeSystemSwiftTypeRef ();
2350
+ if (!ts)
2351
+ return false ;
2352
+ swift::Demangle::Demangler dem;
2353
+ swift::Demangle::NodePointer node = typeref->getDemangling (dem);
2354
+ dynamic_type = ts->RemangleAsType (dem, node, flavor);
2355
+ dynamic_address = out_address.getAddressData ();
2370
2356
} else {
2371
- SymbolContextList sc_list;
2372
- auto &module_list = GetProcess ().GetTarget ().GetImages ();
2373
- module_list.FindSymbolsWithNameAndType (
2374
- ConstString (maybe_addr_or_symbol->getSymbol ()), eSymbolTypeAny,
2375
- sc_list);
2376
- if (sc_list.GetSize () != 1 )
2357
+ // In the embedded Swift case, the existential container just points to
2358
+ // the instance.
2359
+ auto reflection_ctx = GetReflectionContext ();
2360
+ if (!reflection_ctx)
2361
+ return false ;
2362
+ auto maybe_addr_or_symbol =
2363
+ reflection_ctx->ReadPointer (existential_address);
2364
+ if (!maybe_addr_or_symbol)
2377
2365
return false ;
2378
2366
2379
- SymbolContext sc = sc_list[0 ];
2380
- Symbol *symbol = sc.symbol ;
2381
- address = symbol->GetLoadAddress (&GetProcess ().GetTarget ());
2382
- }
2367
+ uint64_t address = 0 ;
2368
+ if (maybe_addr_or_symbol->isResolved ()) {
2369
+ address = maybe_addr_or_symbol->getOffset ();
2370
+ } else {
2371
+ SymbolContextList sc_list;
2372
+ auto &module_list = GetProcess ().GetTarget ().GetImages ();
2373
+ module_list.FindSymbolsWithNameAndType (
2374
+ ConstString (maybe_addr_or_symbol->getSymbol ()), eSymbolTypeAny,
2375
+ sc_list);
2376
+ if (sc_list.GetSize () != 1 )
2377
+ return false ;
2378
+
2379
+ SymbolContext sc = sc_list[0 ];
2380
+ Symbol *symbol = sc.symbol ;
2381
+ address = symbol->GetLoadAddress (&GetProcess ().GetTarget ());
2382
+ }
2383
2383
2384
- dynamic_type =
2385
- GetDynamicTypeAndAddress_EmbeddedClass (address, existential_type);
2386
- if (!dynamic_type)
2387
- return false ;
2388
- dynamic_address = maybe_addr_or_symbol->getOffset ();
2384
+ dynamic_type =
2385
+ GetDynamicTypeAndAddress_EmbeddedClass (address, existential_type);
2386
+ if (!dynamic_type)
2387
+ return false ;
2388
+ dynamic_address = maybe_addr_or_symbol->getOffset ();
2389
+ }
2390
+ class_type_or_name.SetCompilerType (dynamic_type);
2391
+ address.SetRawAddress (dynamic_address);
2389
2392
}
2390
- if (use_local_buffer)
2391
- PopLocalBuffer ();
2392
-
2393
- class_type_or_name.SetCompilerType (dynamic_type);
2394
- address.SetRawAddress (dynamic_address);
2395
2393
2396
2394
#ifndef NDEBUG
2397
2395
if (ModuleList::GetGlobalModuleListProperties ()
@@ -2893,8 +2891,9 @@ Value::ValueType SwiftLanguageRuntime::GetValueType(
2893
2891
existential_address = in_value.GetAddressOf ();
2894
2892
}
2895
2893
2894
+ MemoryReaderLocalBufferHolder holder;
2896
2895
if (use_local_buffer)
2897
- PushLocalBuffer (
2896
+ holder = PushLocalBuffer (
2898
2897
existential_address,
2899
2898
llvm::expectedToOptional (in_value.GetByteSize ()).value_or (0 ));
2900
2899
@@ -2906,8 +2905,6 @@ Value::ValueType SwiftLanguageRuntime::GetValueType(
2906
2905
reflection_ctx->IsValueInlinedInExistentialContainer (
2907
2906
remote_existential);
2908
2907
2909
- if (use_local_buffer)
2910
- PopLocalBuffer ();
2911
2908
2912
2909
// An error has occurred when trying to read value witness table,
2913
2910
// default to treating it as pointer.
0 commit comments