]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Expression/ClangExpressionDeclMap.cpp
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Expression / ClangExpressionDeclMap.cpp
1 //===-- ClangExpressionDeclMap.cpp -----------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/Expression/ClangExpressionDeclMap.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/AST/DeclarationName.h"
13 #include "clang/AST/Decl.h"
14 #include "lldb/lldb-private.h"
15 #include "lldb/Core/Address.h"
16 #include "lldb/Core/Error.h"
17 #include "lldb/Core/Log.h"
18 #include "lldb/Core/Module.h"
19 #include "lldb/Core/ModuleSpec.h"
20 #include "lldb/Core/RegisterValue.h"
21 #include "lldb/Core/ValueObjectConstResult.h"
22 #include "lldb/Core/ValueObjectVariable.h"
23 #include "lldb/Expression/ASTDumper.h"
24 #include "lldb/Expression/ClangASTSource.h"
25 #include "lldb/Expression/ClangPersistentVariables.h"
26 #include "lldb/Expression/Materializer.h"
27 #include "lldb/Host/Endian.h"
28 #include "lldb/Symbol/ClangASTContext.h"
29 #include "lldb/Symbol/ClangNamespaceDecl.h"
30 #include "lldb/Symbol/CompileUnit.h"
31 #include "lldb/Symbol/Function.h"
32 #include "lldb/Symbol/ObjectFile.h"
33 #include "lldb/Symbol/SymbolContext.h"
34 #include "lldb/Symbol/SymbolVendor.h"
35 #include "lldb/Symbol/Type.h"
36 #include "lldb/Symbol/TypeList.h"
37 #include "lldb/Symbol/Variable.h"
38 #include "lldb/Symbol/VariableList.h"
39 #include "lldb/Target/CPPLanguageRuntime.h"
40 #include "lldb/Target/ExecutionContext.h"
41 #include "lldb/Target/ObjCLanguageRuntime.h"
42 #include "lldb/Target/Process.h"
43 #include "lldb/Target/RegisterContext.h"
44 #include "lldb/Target/StackFrame.h"
45 #include "lldb/Target/Target.h"
46 #include "lldb/Target/Thread.h"
47
48 using namespace lldb;
49 using namespace lldb_private;
50 using namespace clang;
51
52 ClangExpressionDeclMap::ClangExpressionDeclMap (bool keep_result_in_memory, ExecutionContext &exe_ctx) :
53     ClangASTSource (exe_ctx.GetTargetSP()),
54     m_found_entities (),
55     m_struct_members (),
56     m_keep_result_in_memory (keep_result_in_memory),
57     m_parser_vars (),
58     m_struct_vars ()
59 {
60     EnableStructVars();
61 }
62
63 ClangExpressionDeclMap::~ClangExpressionDeclMap()
64 {
65     // Note: The model is now that the parser's AST context and all associated
66     //   data does not vanish until the expression has been executed.  This means
67     //   that valuable lookup data (like namespaces) doesn't vanish, but
68
69     DidParse();
70     DisableStructVars();
71 }
72
73 bool
74 ClangExpressionDeclMap::WillParse(ExecutionContext &exe_ctx,
75                                   Materializer *materializer)
76 {
77     ClangASTMetrics::ClearLocalCounters();
78
79     EnableParserVars();
80     m_parser_vars->m_exe_ctx = exe_ctx;
81
82     Target *target = exe_ctx.GetTargetPtr();
83     if (exe_ctx.GetFramePtr())
84         m_parser_vars->m_sym_ctx = exe_ctx.GetFramePtr()->GetSymbolContext(lldb::eSymbolContextEverything);
85     else if (exe_ctx.GetThreadPtr() && exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(0))
86         m_parser_vars->m_sym_ctx = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(0)->GetSymbolContext(lldb::eSymbolContextEverything);
87     else if (exe_ctx.GetProcessPtr())
88     {
89         m_parser_vars->m_sym_ctx.Clear(true);
90         m_parser_vars->m_sym_ctx.target_sp = exe_ctx.GetTargetSP();
91     }
92     else if (target)
93     {
94         m_parser_vars->m_sym_ctx.Clear(true);
95         m_parser_vars->m_sym_ctx.target_sp = exe_ctx.GetTargetSP();
96     }
97
98     if (target)
99     {
100         m_parser_vars->m_persistent_vars = &target->GetPersistentVariables();
101
102         if (!target->GetScratchClangASTContext())
103             return false;
104     }
105
106     m_parser_vars->m_target_info = GetTargetInfo();
107     m_parser_vars->m_materializer = materializer;
108
109     return true;
110 }
111
112 void
113 ClangExpressionDeclMap::DidParse()
114 {
115     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
116
117     if (log)
118         ClangASTMetrics::DumpCounters(log);
119
120     if (m_parser_vars.get())
121     {
122         for (size_t entity_index = 0, num_entities = m_found_entities.GetSize();
123              entity_index < num_entities;
124              ++entity_index)
125         {
126             ClangExpressionVariableSP var_sp(m_found_entities.GetVariableAtIndex(entity_index));
127             if (var_sp)
128                 var_sp->DisableParserVars(GetParserID());
129         }
130
131         for (size_t pvar_index = 0, num_pvars = m_parser_vars->m_persistent_vars->GetSize();
132              pvar_index < num_pvars;
133              ++pvar_index)
134         {
135             ClangExpressionVariableSP pvar_sp(m_parser_vars->m_persistent_vars->GetVariableAtIndex(pvar_index));
136             if (pvar_sp)
137                 pvar_sp->DisableParserVars(GetParserID());
138         }
139
140         DisableParserVars();
141     }
142 }
143
144 // Interface for IRForTarget
145
146 ClangExpressionDeclMap::TargetInfo
147 ClangExpressionDeclMap::GetTargetInfo()
148 {
149     assert (m_parser_vars.get());
150
151     TargetInfo ret;
152
153     ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
154
155     Process *process = exe_ctx.GetProcessPtr();
156     if (process)
157     {
158         ret.byte_order = process->GetByteOrder();
159         ret.address_byte_size = process->GetAddressByteSize();
160     }
161     else
162     {
163         Target *target = exe_ctx.GetTargetPtr();
164         if (target)
165         {
166             ret.byte_order = target->GetArchitecture().GetByteOrder();
167             ret.address_byte_size = target->GetArchitecture().GetAddressByteSize();
168         }
169     }
170
171     return ret;
172 }
173
174 bool
175 ClangExpressionDeclMap::AddPersistentVariable
176 (
177     const NamedDecl *decl,
178     const ConstString &name,
179     TypeFromParser parser_type,
180     bool is_result,
181     bool is_lvalue
182 )
183 {
184     assert (m_parser_vars.get());
185
186     if (m_parser_vars->m_materializer && is_result)
187     {
188         Error err;
189
190         ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
191         Target *target = exe_ctx.GetTargetPtr();
192         if (target == NULL)
193             return false;
194
195         ASTContext *context(target->GetScratchClangASTContext()->getASTContext());
196
197         TypeFromUser user_type(m_ast_importer->DeportType(context,
198                                                           parser_type.GetASTContext(),
199                                                           parser_type.GetOpaqueQualType()),
200                                context);
201
202         uint32_t offset = m_parser_vars->m_materializer->AddResultVariable(user_type, is_lvalue, m_keep_result_in_memory, err);
203
204         ClangExpressionVariableSP var_sp = m_found_entities.CreateVariable(exe_ctx.GetBestExecutionContextScope(),
205                                                                            name,
206                                                                            user_type,
207                                                                            m_parser_vars->m_target_info.byte_order,
208                                                                            m_parser_vars->m_target_info.address_byte_size);
209
210         if (!var_sp)
211             return false;
212
213         var_sp->EnableParserVars(GetParserID());
214
215         ClangExpressionVariable::ParserVars *parser_vars = var_sp->GetParserVars(GetParserID());
216
217         parser_vars->m_named_decl = decl;
218         parser_vars->m_parser_type = parser_type;
219
220         var_sp->EnableJITVars(GetParserID());
221
222         ClangExpressionVariable::JITVars *jit_vars = var_sp->GetJITVars(GetParserID());
223
224         jit_vars->m_offset = offset;
225
226         return true;
227     }
228
229     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
230     ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
231     Target *target = exe_ctx.GetTargetPtr();
232     if (target == NULL)
233         return false;
234
235     ASTContext *context(target->GetScratchClangASTContext()->getASTContext());
236
237     TypeFromUser user_type(m_ast_importer->DeportType(context,
238                                                       parser_type.GetASTContext(),
239                                                       parser_type.GetOpaqueQualType()),
240                            context);
241
242     if (!user_type.GetOpaqueQualType())
243     {
244         if (log)
245             log->Printf("Persistent variable's type wasn't copied successfully");
246         return false;
247     }
248
249     if (!m_parser_vars->m_target_info.IsValid())
250         return false;
251
252     ClangExpressionVariableSP var_sp = m_parser_vars->m_persistent_vars->CreatePersistentVariable (exe_ctx.GetBestExecutionContextScope (),
253                                                                                                    name,
254                                                                                                    user_type,
255                                                                                                    m_parser_vars->m_target_info.byte_order,
256                                                                                                    m_parser_vars->m_target_info.address_byte_size);
257
258     if (!var_sp)
259         return false;
260
261     var_sp->m_frozen_sp->SetHasCompleteType();
262
263     if (is_result)
264         var_sp->m_flags |= ClangExpressionVariable::EVNeedsFreezeDry;
265     else
266         var_sp->m_flags |= ClangExpressionVariable::EVKeepInTarget; // explicitly-declared persistent variables should persist
267
268     if (is_lvalue)
269     {
270         var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
271     }
272     else
273     {
274         var_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
275         var_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
276     }
277
278     if (m_keep_result_in_memory)
279     {
280         var_sp->m_flags |= ClangExpressionVariable::EVKeepInTarget;
281     }
282
283     if (log)
284         log->Printf("Created persistent variable with flags 0x%hx", var_sp->m_flags);
285
286     var_sp->EnableParserVars(GetParserID());
287
288     ClangExpressionVariable::ParserVars *parser_vars = var_sp->GetParserVars(GetParserID());
289
290     parser_vars->m_named_decl = decl;
291     parser_vars->m_parser_type = parser_type;
292
293     return true;
294 }
295
296 bool
297 ClangExpressionDeclMap::AddValueToStruct
298 (
299     const NamedDecl *decl,
300     const ConstString &name,
301     llvm::Value *value,
302     size_t size,
303     lldb::offset_t alignment
304 )
305 {
306     assert (m_struct_vars.get());
307     assert (m_parser_vars.get());
308
309     bool is_persistent_variable = false;
310
311     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
312
313     m_struct_vars->m_struct_laid_out = false;
314
315     if (m_struct_members.GetVariable(decl, GetParserID()))
316         return true;
317
318     ClangExpressionVariableSP var_sp (m_found_entities.GetVariable(decl, GetParserID()));
319
320     if (!var_sp)
321     {
322         var_sp = m_parser_vars->m_persistent_vars->GetVariable(decl, GetParserID());
323         is_persistent_variable = true;
324     }
325
326     if (!var_sp)
327         return false;
328
329     if (log)
330         log->Printf("Adding value for (NamedDecl*)%p [%s - %s] to the structure",
331                     static_cast<const void*>(decl), name.GetCString(),
332                     var_sp->GetName().GetCString());
333
334     // We know entity->m_parser_vars is valid because we used a parser variable
335     // to find it
336
337     ClangExpressionVariable::ParserVars *parser_vars = var_sp->GetParserVars(GetParserID());
338
339     parser_vars->m_llvm_value = value;
340
341     if (ClangExpressionVariable::JITVars *jit_vars = var_sp->GetJITVars(GetParserID()))
342     {
343         // We already laid this out; do not touch
344
345         if (log)
346             log->Printf("Already placed at 0x%llx", (unsigned long long)jit_vars->m_offset);
347     }
348
349     var_sp->EnableJITVars(GetParserID());
350
351     ClangExpressionVariable::JITVars *jit_vars = var_sp->GetJITVars(GetParserID());
352
353     jit_vars->m_alignment = alignment;
354     jit_vars->m_size = size;
355
356     m_struct_members.AddVariable(var_sp);
357
358     if (m_parser_vars->m_materializer)
359     {
360         uint32_t offset = 0;
361
362         Error err;
363
364         if (is_persistent_variable)
365         {
366             offset = m_parser_vars->m_materializer->AddPersistentVariable(var_sp, err);
367         }
368         else
369         {
370             if (const lldb_private::Symbol *sym = parser_vars->m_lldb_sym)
371                 offset = m_parser_vars->m_materializer->AddSymbol(*sym, err);
372             else if (const RegisterInfo *reg_info = var_sp->GetRegisterInfo())
373                 offset = m_parser_vars->m_materializer->AddRegister(*reg_info, err);
374             else if (parser_vars->m_lldb_var)
375                 offset = m_parser_vars->m_materializer->AddVariable(parser_vars->m_lldb_var, err);
376         }
377
378         if (!err.Success())
379             return false;
380
381         if (log)
382             log->Printf("Placed at 0x%llx", (unsigned long long)offset);
383
384         jit_vars->m_offset = offset; // TODO DoStructLayout() should not change this.
385     }
386
387     return true;
388 }
389
390 bool
391 ClangExpressionDeclMap::DoStructLayout ()
392 {
393     assert (m_struct_vars.get());
394
395     if (m_struct_vars->m_struct_laid_out)
396         return true;
397
398     if (!m_parser_vars->m_materializer)
399         return false;
400
401     m_struct_vars->m_struct_alignment = m_parser_vars->m_materializer->GetStructAlignment();
402     m_struct_vars->m_struct_size = m_parser_vars->m_materializer->GetStructByteSize();
403     m_struct_vars->m_struct_laid_out = true;
404     return true;
405 }
406
407 bool ClangExpressionDeclMap::GetStructInfo
408 (
409     uint32_t &num_elements,
410     size_t &size,
411     lldb::offset_t &alignment
412 )
413 {
414     assert (m_struct_vars.get());
415
416     if (!m_struct_vars->m_struct_laid_out)
417         return false;
418
419     num_elements = m_struct_members.GetSize();
420     size = m_struct_vars->m_struct_size;
421     alignment = m_struct_vars->m_struct_alignment;
422
423     return true;
424 }
425
426 bool
427 ClangExpressionDeclMap::GetStructElement
428 (
429     const NamedDecl *&decl,
430     llvm::Value *&value,
431     lldb::offset_t &offset,
432     ConstString &name,
433     uint32_t index
434 )
435 {
436     assert (m_struct_vars.get());
437
438     if (!m_struct_vars->m_struct_laid_out)
439         return false;
440
441     if (index >= m_struct_members.GetSize())
442         return false;
443
444     ClangExpressionVariableSP member_sp(m_struct_members.GetVariableAtIndex(index));
445
446     if (!member_sp)
447         return false;
448
449     ClangExpressionVariable::ParserVars *parser_vars = member_sp->GetParserVars(GetParserID());
450     ClangExpressionVariable::JITVars *jit_vars = member_sp->GetJITVars(GetParserID());
451
452     if (!parser_vars ||
453         !jit_vars ||
454         !member_sp->GetValueObject())
455         return false;
456
457     decl = parser_vars->m_named_decl;
458     value = parser_vars->m_llvm_value;
459     offset = jit_vars->m_offset;
460     name = member_sp->GetName();
461
462     return true;
463 }
464
465 bool
466 ClangExpressionDeclMap::GetFunctionInfo
467 (
468     const NamedDecl *decl,
469     uint64_t &ptr
470 )
471 {
472     ClangExpressionVariableSP entity_sp(m_found_entities.GetVariable(decl, GetParserID()));
473
474     if (!entity_sp)
475         return false;
476
477     // We know m_parser_vars is valid since we searched for the variable by
478     // its NamedDecl
479
480     ClangExpressionVariable::ParserVars *parser_vars = entity_sp->GetParserVars(GetParserID());
481
482     ptr = parser_vars->m_lldb_value.GetScalar().ULongLong();
483
484     return true;
485 }
486
487 static void
488 FindCodeSymbolInContext
489 (
490     const ConstString &name,
491     SymbolContext &sym_ctx,
492     SymbolContextList &sc_list
493 )
494 {
495     SymbolContextList temp_sc_list;
496     if (sym_ctx.module_sp)
497         sym_ctx.module_sp->FindSymbolsWithNameAndType(name, eSymbolTypeAny, temp_sc_list);
498
499     if (!sc_list.GetSize() && sym_ctx.target_sp)
500         sym_ctx.target_sp->GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeAny, temp_sc_list);
501
502     unsigned temp_sc_list_size = temp_sc_list.GetSize();
503     for (unsigned i = 0; i < temp_sc_list_size; i++)
504     {
505         SymbolContext sym_ctx;
506         temp_sc_list.GetContextAtIndex(i, sym_ctx);
507         if (sym_ctx.symbol)
508         {
509             switch (sym_ctx.symbol->GetType())
510             {
511                 case eSymbolTypeCode:
512                 case eSymbolTypeResolver:
513                 case eSymbolTypeReExported:
514                     sc_list.Append(sym_ctx);
515                     break;
516
517                 default:
518                     break;
519             }
520         }
521     }
522 }
523
524 bool
525 ClangExpressionDeclMap::GetFunctionAddress
526 (
527     const ConstString &name,
528     uint64_t &func_addr
529 )
530 {
531     assert (m_parser_vars.get());
532
533     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
534     ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
535     Target *target = exe_ctx.GetTargetPtr();
536     // Back out in all cases where we're not fully initialized
537     if (target == NULL)
538         return false;
539     if (!m_parser_vars->m_sym_ctx.target_sp)
540         return false;
541
542     SymbolContextList sc_list;
543
544     FindCodeSymbolInContext(name, m_parser_vars->m_sym_ctx, sc_list);
545
546     uint32_t sc_list_size = sc_list.GetSize();
547     
548     if (sc_list_size == 0)
549     {
550         // We occasionally get debug information in which a const function is reported
551         // as non-const, so the mangled name is wrong.  This is a hack to compensate.
552
553         if (!strncmp(name.GetCString(), "_ZN", 3) &&
554             strncmp(name.GetCString(), "_ZNK", 4))
555         {
556             std::string fixed_scratch("_ZNK");
557             fixed_scratch.append(name.GetCString() + 3);
558             ConstString fixed_name(fixed_scratch.c_str());
559
560             if (log)
561                 log->Printf("Failed to find symbols given non-const name %s; trying %s", name.GetCString(), fixed_name.GetCString());
562
563             FindCodeSymbolInContext(fixed_name, m_parser_vars->m_sym_ctx, sc_list);
564             sc_list_size = sc_list.GetSize();
565         }
566     }
567     
568     if (sc_list_size == 0)
569     {
570         // Sometimes we get a mangled name for a global function that actually should be "extern C."
571         // This is a hack to compensate.
572         
573         const bool is_mangled = true;
574         Mangled mangled(name, is_mangled);
575                 
576         CPPLanguageRuntime::MethodName method_name(mangled.GetDemangledName());
577         
578         llvm::StringRef basename = method_name.GetBasename();
579         
580         if (!basename.empty())
581         {
582             FindCodeSymbolInContext(ConstString(basename), m_parser_vars->m_sym_ctx, sc_list);
583             sc_list_size = sc_list.GetSize();
584         }
585     }
586
587     for (uint32_t i=0; i<sc_list_size; ++i)
588     {
589         SymbolContext sym_ctx;
590         sc_list.GetContextAtIndex(i, sym_ctx);
591
592         lldb::addr_t callable_load_addr = LLDB_INVALID_ADDRESS;
593
594         if (sym_ctx.function)
595         {
596             const Address func_so_addr = sym_ctx.function->GetAddressRange().GetBaseAddress();
597             if (func_so_addr.IsValid())
598             {
599                 callable_load_addr = func_so_addr.GetCallableLoadAddress(target, false);
600             }
601         }
602         else if (sym_ctx.symbol)
603         {
604             callable_load_addr = sym_ctx.symbol->ResolveCallableAddress(*target);
605         }
606
607         if (callable_load_addr != LLDB_INVALID_ADDRESS)
608         {
609             func_addr = callable_load_addr;
610             return true;
611         }
612     }
613     return false;
614 }
615
616 addr_t
617 ClangExpressionDeclMap::GetSymbolAddress (Target &target,
618                                           Process *process,
619                                           const ConstString &name,
620                                           lldb::SymbolType symbol_type,
621                                           lldb_private::Module *module)
622 {
623     SymbolContextList sc_list;
624
625     if (module)
626         module->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
627     else
628         target.GetImages().FindSymbolsWithNameAndType(name, symbol_type, sc_list);
629
630     const uint32_t num_matches = sc_list.GetSize();
631     addr_t symbol_load_addr = LLDB_INVALID_ADDRESS;
632
633     for (uint32_t i=0; i<num_matches && (symbol_load_addr == 0 || symbol_load_addr == LLDB_INVALID_ADDRESS); i++)
634     {
635         SymbolContext sym_ctx;
636         sc_list.GetContextAtIndex(i, sym_ctx);
637
638         const Address *sym_address = &sym_ctx.symbol->GetAddress();
639
640         if (!sym_address || !sym_address->IsValid())
641             continue;
642
643         if (sym_address)
644         {
645             switch (sym_ctx.symbol->GetType())
646             {
647                 case eSymbolTypeCode:
648                 case eSymbolTypeTrampoline:
649                     symbol_load_addr = sym_address->GetCallableLoadAddress (&target);
650                     break;
651
652                 case eSymbolTypeResolver:
653                     symbol_load_addr = sym_address->GetCallableLoadAddress (&target, true);
654                     break;
655
656                 case eSymbolTypeReExported:
657                     {
658                         ConstString reexport_name = sym_ctx.symbol->GetReExportedSymbolName();
659                         if (reexport_name)
660                         {
661                             ModuleSP reexport_module_sp;
662                             ModuleSpec reexport_module_spec;
663                             reexport_module_spec.GetPlatformFileSpec() = sym_ctx.symbol->GetReExportedSymbolSharedLibrary();
664                             if (reexport_module_spec.GetPlatformFileSpec())
665                             {
666                                 reexport_module_sp = target.GetImages().FindFirstModule(reexport_module_spec);
667                                 if (!reexport_module_sp)
668                                 {
669                                     reexport_module_spec.GetPlatformFileSpec().GetDirectory().Clear();
670                                     reexport_module_sp = target.GetImages().FindFirstModule(reexport_module_spec);
671                                 }
672                             }
673                             symbol_load_addr = GetSymbolAddress(target, process, sym_ctx.symbol->GetReExportedSymbolName(), symbol_type, reexport_module_sp.get());
674                         }
675                     }
676                     break;
677
678                 case eSymbolTypeData:
679                 case eSymbolTypeRuntime:
680                 case eSymbolTypeVariable:
681                 case eSymbolTypeLocal:
682                 case eSymbolTypeParam:
683                 case eSymbolTypeInvalid:
684                 case eSymbolTypeAbsolute:
685                 case eSymbolTypeException:
686                 case eSymbolTypeSourceFile:
687                 case eSymbolTypeHeaderFile:
688                 case eSymbolTypeObjectFile:
689                 case eSymbolTypeCommonBlock:
690                 case eSymbolTypeBlock:
691                 case eSymbolTypeVariableType:
692                 case eSymbolTypeLineEntry:
693                 case eSymbolTypeLineHeader:
694                 case eSymbolTypeScopeBegin:
695                 case eSymbolTypeScopeEnd:
696                 case eSymbolTypeAdditional:
697                 case eSymbolTypeCompiler:
698                 case eSymbolTypeInstrumentation:
699                 case eSymbolTypeUndefined:
700                 case eSymbolTypeObjCClass:
701                 case eSymbolTypeObjCMetaClass:
702                 case eSymbolTypeObjCIVar:
703                     symbol_load_addr = sym_address->GetLoadAddress (&target);
704                     break;
705             }
706         }
707     }
708
709     if (symbol_load_addr == LLDB_INVALID_ADDRESS && process)
710     {
711         ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
712
713         if (runtime)
714         {
715             symbol_load_addr = runtime->LookupRuntimeSymbol(name);
716         }
717     }
718
719     return symbol_load_addr;
720 }
721
722 addr_t
723 ClangExpressionDeclMap::GetSymbolAddress (const ConstString &name, lldb::SymbolType symbol_type)
724 {
725     assert (m_parser_vars.get());
726
727     if (!m_parser_vars->m_exe_ctx.GetTargetPtr())
728         return false;
729
730     return GetSymbolAddress(m_parser_vars->m_exe_ctx.GetTargetRef(), m_parser_vars->m_exe_ctx.GetProcessPtr(), name, symbol_type);
731 }
732
733 const Symbol *
734 ClangExpressionDeclMap::FindGlobalDataSymbol (Target &target,
735                                               const ConstString &name,
736                                               lldb_private::Module *module)
737 {
738     SymbolContextList sc_list;
739
740     if (module)
741         module->FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list);
742     else
743         target.GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list);
744
745     const uint32_t matches = sc_list.GetSize();
746     for (uint32_t i=0; i<matches; ++i)
747     {
748         SymbolContext sym_ctx;
749         sc_list.GetContextAtIndex(i, sym_ctx);
750         if (sym_ctx.symbol)
751         {
752             const Symbol *symbol = sym_ctx.symbol;
753             const Address *sym_address = &symbol->GetAddress();
754
755             if (sym_address && sym_address->IsValid())
756             {
757                 switch (symbol->GetType())
758                 {
759                     case eSymbolTypeData:
760                     case eSymbolTypeRuntime:
761                     case eSymbolTypeAbsolute:
762                     case eSymbolTypeObjCClass:
763                     case eSymbolTypeObjCMetaClass:
764                     case eSymbolTypeObjCIVar:
765                         if (symbol->GetDemangledNameIsSynthesized())
766                         {
767                             // If the demangled name was synthesized, then don't use it
768                             // for expressions. Only let the symbol match if the mangled
769                             // named matches for these symbols.
770                             if (symbol->GetMangled().GetMangledName() != name)
771                                 break;
772                         }
773                         return symbol;
774
775                     case eSymbolTypeReExported:
776                         {
777                             ConstString reexport_name = symbol->GetReExportedSymbolName();
778                             if (reexport_name)
779                             {
780                                 ModuleSP reexport_module_sp;
781                                 ModuleSpec reexport_module_spec;
782                                 reexport_module_spec.GetPlatformFileSpec() = symbol->GetReExportedSymbolSharedLibrary();
783                                 if (reexport_module_spec.GetPlatformFileSpec())
784                                 {
785                                     reexport_module_sp = target.GetImages().FindFirstModule(reexport_module_spec);
786                                     if (!reexport_module_sp)
787                                     {
788                                         reexport_module_spec.GetPlatformFileSpec().GetDirectory().Clear();
789                                         reexport_module_sp = target.GetImages().FindFirstModule(reexport_module_spec);
790                                     }
791                                 }
792                                 return FindGlobalDataSymbol(target, symbol->GetReExportedSymbolName(), reexport_module_sp.get());
793                             }
794                         }
795                         break;
796
797                     case eSymbolTypeCode: // We already lookup functions elsewhere
798                     case eSymbolTypeVariable:
799                     case eSymbolTypeLocal:
800                     case eSymbolTypeParam:
801                     case eSymbolTypeTrampoline:
802                     case eSymbolTypeInvalid:
803                     case eSymbolTypeException:
804                     case eSymbolTypeSourceFile:
805                     case eSymbolTypeHeaderFile:
806                     case eSymbolTypeObjectFile:
807                     case eSymbolTypeCommonBlock:
808                     case eSymbolTypeBlock:
809                     case eSymbolTypeVariableType:
810                     case eSymbolTypeLineEntry:
811                     case eSymbolTypeLineHeader:
812                     case eSymbolTypeScopeBegin:
813                     case eSymbolTypeScopeEnd:
814                     case eSymbolTypeAdditional:
815                     case eSymbolTypeCompiler:
816                     case eSymbolTypeInstrumentation:
817                     case eSymbolTypeUndefined:
818                     case eSymbolTypeResolver:
819                         break;
820                 }
821             }
822         }
823     }
824
825     return NULL;
826 }
827
828 lldb::VariableSP
829 ClangExpressionDeclMap::FindGlobalVariable
830 (
831     Target &target,
832     ModuleSP &module,
833     const ConstString &name,
834     ClangNamespaceDecl *namespace_decl,
835     TypeFromUser *type
836 )
837 {
838     VariableList vars;
839
840     if (module && namespace_decl)
841         module->FindGlobalVariables (name, namespace_decl, true, -1, vars);
842     else
843         target.GetImages().FindGlobalVariables(name, true, -1, vars);
844
845     if (vars.GetSize())
846     {
847         if (type)
848         {
849             for (size_t i = 0; i < vars.GetSize(); ++i)
850             {
851                 VariableSP var_sp = vars.GetVariableAtIndex(i);
852
853                 if (ClangASTContext::AreTypesSame(*type, var_sp->GetType()->GetClangFullType()))
854                     return var_sp;
855             }
856         }
857         else
858         {
859             return vars.GetVariableAtIndex(0);
860         }
861     }
862
863     return VariableSP();
864 }
865
866 // Interface for ClangASTSource
867
868 void
869 ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context)
870 {
871     assert (m_ast_context);
872
873     ClangASTMetrics::RegisterVisibleQuery();
874
875     const ConstString name(context.m_decl_name.getAsString().c_str());
876
877     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
878
879     if (GetImportInProgress())
880     {
881         if (log && log->GetVerbose())
882             log->Printf("Ignoring a query during an import");
883         return;
884     }
885
886     static unsigned int invocation_id = 0;
887     unsigned int current_id = invocation_id++;
888
889     if (log)
890     {
891         if (!context.m_decl_context)
892             log->Printf("ClangExpressionDeclMap::FindExternalVisibleDecls[%u] for '%s' in a NULL DeclContext", current_id, name.GetCString());
893         else if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context.m_decl_context))
894             log->Printf("ClangExpressionDeclMap::FindExternalVisibleDecls[%u] for '%s' in '%s'", current_id, name.GetCString(), context_named_decl->getNameAsString().c_str());
895         else
896             log->Printf("ClangExpressionDeclMap::FindExternalVisibleDecls[%u] for '%s' in a '%s'", current_id, name.GetCString(), context.m_decl_context->getDeclKindName());
897     }
898
899     if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
900     {
901         ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context);
902
903         if (log && log->GetVerbose())
904             log->Printf("  CEDM::FEVD[%u] Inspecting (NamespaceMap*)%p (%d entries)",
905                         current_id, static_cast<void*>(namespace_map.get()),
906                         (int)namespace_map->size());
907
908         if (!namespace_map)
909             return;
910
911         for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
912              i != e;
913              ++i)
914         {
915             if (log)
916                 log->Printf("  CEDM::FEVD[%u] Searching namespace %s in module %s",
917                             current_id,
918                             i->second.GetNamespaceDecl()->getNameAsString().c_str(),
919                             i->first->GetFileSpec().GetFilename().GetCString());
920
921             FindExternalVisibleDecls(context,
922                                      i->first,
923                                      i->second,
924                                      current_id);
925         }
926     }
927     else if (isa<TranslationUnitDecl>(context.m_decl_context))
928     {
929         ClangNamespaceDecl namespace_decl;
930
931         if (log)
932             log->Printf("  CEDM::FEVD[%u] Searching the root namespace", current_id);
933
934         FindExternalVisibleDecls(context,
935                                  lldb::ModuleSP(),
936                                  namespace_decl,
937                                  current_id);
938     }
939
940     if (!context.m_found.variable)
941         ClangASTSource::FindExternalVisibleDecls(context);
942 }
943
944 void
945 ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context,
946                                                   lldb::ModuleSP module_sp,
947                                                   ClangNamespaceDecl &namespace_decl,
948                                                   unsigned int current_id)
949 {
950     assert (m_ast_context);
951
952     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
953
954     SymbolContextList sc_list;
955
956     const ConstString name(context.m_decl_name.getAsString().c_str());
957
958     const char *name_unique_cstr = name.GetCString();
959
960     if (name_unique_cstr == NULL)
961         return;
962
963     static ConstString id_name("id");
964     static ConstString Class_name("Class");
965
966     if (name == id_name || name == Class_name)
967         return;
968
969     // Only look for functions by name out in our symbols if the function
970     // doesn't start with our phony prefix of '$'
971     Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
972     StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
973     if (name_unique_cstr[0] == '$' && !namespace_decl)
974     {
975         static ConstString g_lldb_class_name ("$__lldb_class");
976
977         if (name == g_lldb_class_name)
978         {
979             // Clang is looking for the type of "this"
980
981             if (frame == NULL)
982                 return;
983
984             SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction);
985
986             if (!sym_ctx.function)
987                 return;
988
989             // Get the block that defines the function
990             Block *function_block = sym_ctx.GetFunctionBlock();
991
992             if (!function_block)
993                 return;
994
995             clang::DeclContext *decl_context = function_block->GetClangDeclContext();
996
997             if (!decl_context)
998                 return;
999
1000             clang::CXXMethodDecl *method_decl = llvm::dyn_cast<clang::CXXMethodDecl>(decl_context);
1001
1002             if (method_decl)
1003             {
1004                 clang::CXXRecordDecl *class_decl = method_decl->getParent();
1005
1006                 QualType class_qual_type(class_decl->getTypeForDecl(), 0);
1007
1008                 TypeFromUser class_user_type (class_qual_type.getAsOpaquePtr(),
1009                                               &class_decl->getASTContext());
1010
1011                 if (log)
1012                 {
1013                     ASTDumper ast_dumper(class_qual_type);
1014                     log->Printf("  CEDM::FEVD[%u] Adding type for $__lldb_class: %s", current_id, ast_dumper.GetCString());
1015                 }
1016
1017                 TypeFromParser class_type = CopyClassType(class_user_type, current_id);
1018
1019                 if (!class_type.IsValid())
1020                     return;
1021
1022                 TypeSourceInfo *type_source_info = m_ast_context->getTrivialTypeSourceInfo(QualType::getFromOpaquePtr(class_type.GetOpaqueQualType()));
1023
1024                 if (!type_source_info)
1025                     return;
1026
1027                 TypedefDecl *typedef_decl = TypedefDecl::Create(*m_ast_context,
1028                                                                 m_ast_context->getTranslationUnitDecl(),
1029                                                                 SourceLocation(),
1030                                                                 SourceLocation(),
1031                                                                 context.m_decl_name.getAsIdentifierInfo(),
1032                                                                 type_source_info);
1033
1034
1035                 if (!typedef_decl)
1036                     return;
1037
1038                 context.AddNamedDecl(typedef_decl);
1039
1040                 if (method_decl->isInstance())
1041                 {
1042                     // self is a pointer to the object
1043
1044                     QualType class_pointer_type = method_decl->getASTContext().getPointerType(class_qual_type);
1045
1046                     TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
1047                                                 &method_decl->getASTContext());
1048
1049                     m_struct_vars->m_object_pointer_type = self_user_type;
1050                 }
1051             }
1052             else
1053             {
1054                 // This branch will get hit if we are executing code in the context of a function that
1055                 // claims to have an object pointer (through DW_AT_object_pointer?) but is not formally a
1056                 // method of the class.  In that case, just look up the "this" variable in the the current
1057                 // scope and use its type.
1058                 // FIXME: This code is formally correct, but clang doesn't currently emit DW_AT_object_pointer
1059                 // for C++ so it hasn't actually been tested.
1060
1061                 VariableList *vars = frame->GetVariableList(false);
1062
1063                 lldb::VariableSP this_var = vars->FindVariable(ConstString("this"));
1064
1065                 if (this_var &&
1066                     this_var->IsInScope(frame) &&
1067                     this_var->LocationIsValidForFrame (frame))
1068                 {
1069                     Type *this_type = this_var->GetType();
1070
1071                     if (!this_type)
1072                         return;
1073
1074                     ClangASTType pointee_type = this_type->GetClangForwardType().GetPointeeType();
1075
1076                     if (pointee_type.IsValid())
1077                     {
1078                         if (log)
1079                         {
1080                             ASTDumper ast_dumper(this_type->GetClangFullType());
1081                             log->Printf("  FEVD[%u] Adding type for $__lldb_objc_class: %s", current_id, ast_dumper.GetCString());
1082                         }
1083
1084                         TypeFromUser class_user_type(pointee_type);
1085                         AddOneType(context, class_user_type, current_id);
1086
1087
1088                         TypeFromUser this_user_type(this_type->GetClangFullType());
1089                         m_struct_vars->m_object_pointer_type = this_user_type;
1090                         return;
1091                     }
1092                 }
1093             }
1094
1095             return;
1096         }
1097
1098         static ConstString g_lldb_objc_class_name ("$__lldb_objc_class");
1099         if (name == g_lldb_objc_class_name)
1100         {
1101             // Clang is looking for the type of "*self"
1102
1103             if (!frame)
1104                 return;
1105
1106             SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction);
1107
1108             if (!sym_ctx.function)
1109                 return;
1110
1111             // Get the block that defines the function
1112             Block *function_block = sym_ctx.GetFunctionBlock();
1113
1114             if (!function_block)
1115                 return;
1116
1117             clang::DeclContext *decl_context = function_block->GetClangDeclContext();
1118
1119             if (!decl_context)
1120                 return;
1121
1122             clang::ObjCMethodDecl *method_decl = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_context);
1123
1124             if (method_decl)
1125             {
1126                 ObjCInterfaceDecl* self_interface = method_decl->getClassInterface();
1127
1128                 if (!self_interface)
1129                     return;
1130
1131                 const clang::Type *interface_type = self_interface->getTypeForDecl();
1132
1133                 if (!interface_type)
1134                     return; // This is unlikely, but we have seen crashes where this occurred
1135
1136                 TypeFromUser class_user_type(QualType(interface_type, 0).getAsOpaquePtr(),
1137                                              &method_decl->getASTContext());
1138
1139                 if (log)
1140                 {
1141                     ASTDumper ast_dumper(interface_type);
1142                     log->Printf("  FEVD[%u] Adding type for $__lldb_objc_class: %s", current_id, ast_dumper.GetCString());
1143                 }
1144
1145                 AddOneType(context, class_user_type, current_id);
1146
1147                 if (method_decl->isInstanceMethod())
1148                 {
1149                     // self is a pointer to the object
1150
1151                     QualType class_pointer_type = method_decl->getASTContext().getObjCObjectPointerType(QualType(interface_type, 0));
1152
1153                     TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
1154                                                 &method_decl->getASTContext());
1155
1156                     m_struct_vars->m_object_pointer_type = self_user_type;
1157                 }
1158                 else
1159                 {
1160                     // self is a Class pointer
1161                     QualType class_type = method_decl->getASTContext().getObjCClassType();
1162
1163                     TypeFromUser self_user_type(class_type.getAsOpaquePtr(),
1164                                                 &method_decl->getASTContext());
1165
1166                     m_struct_vars->m_object_pointer_type = self_user_type;
1167                 }
1168
1169                 return;
1170             }
1171             else
1172             {
1173                 // This branch will get hit if we are executing code in the context of a function that
1174                 // claims to have an object pointer (through DW_AT_object_pointer?) but is not formally a
1175                 // method of the class.  In that case, just look up the "self" variable in the the current
1176                 // scope and use its type.
1177
1178                 VariableList *vars = frame->GetVariableList(false);
1179
1180                 lldb::VariableSP self_var = vars->FindVariable(ConstString("self"));
1181
1182                 if (self_var &&
1183                     self_var->IsInScope(frame) &&
1184                     self_var->LocationIsValidForFrame (frame))
1185                 {
1186                     Type *self_type = self_var->GetType();
1187
1188                     if (!self_type)
1189                         return;
1190
1191                     ClangASTType self_clang_type = self_type->GetClangFullType();
1192
1193                     if (self_clang_type.IsObjCClassType())
1194                     {
1195                         return;
1196                     }
1197                     else if (self_clang_type.IsObjCObjectPointerType())
1198                     {
1199                         self_clang_type = self_clang_type.GetPointeeType();
1200
1201                         if (!self_clang_type)
1202                             return;
1203
1204                         if (log)
1205                         {
1206                             ASTDumper ast_dumper(self_type->GetClangFullType());
1207                             log->Printf("  FEVD[%u] Adding type for $__lldb_objc_class: %s", current_id, ast_dumper.GetCString());
1208                         }
1209
1210                         TypeFromUser class_user_type (self_clang_type);
1211
1212                         AddOneType(context, class_user_type, current_id);
1213
1214                         TypeFromUser self_user_type(self_type->GetClangFullType());
1215
1216                         m_struct_vars->m_object_pointer_type = self_user_type;
1217                         return;
1218                     }
1219                 }
1220             }
1221
1222             return;
1223         }
1224
1225         // any other $__lldb names should be weeded out now
1226         if (!::strncmp(name_unique_cstr, "$__lldb", sizeof("$__lldb") - 1))
1227             return;
1228
1229         do
1230         {
1231             if (!target)
1232                 break;
1233
1234             ClangASTContext *scratch_clang_ast_context = target->GetScratchClangASTContext();
1235
1236             if (!scratch_clang_ast_context)
1237                 break;
1238
1239             ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext();
1240
1241             if (!scratch_ast_context)
1242                 break;
1243
1244             TypeDecl *ptype_type_decl = m_parser_vars->m_persistent_vars->GetPersistentType(name);
1245
1246             if (!ptype_type_decl)
1247                 break;
1248
1249             Decl *parser_ptype_decl = m_ast_importer->CopyDecl(m_ast_context, scratch_ast_context, ptype_type_decl);
1250
1251             if (!parser_ptype_decl)
1252                 break;
1253
1254             TypeDecl *parser_ptype_type_decl = dyn_cast<TypeDecl>(parser_ptype_decl);
1255
1256             if (!parser_ptype_type_decl)
1257                 break;
1258
1259             if (log)
1260                 log->Printf("  CEDM::FEVD[%u] Found persistent type %s", current_id, name.GetCString());
1261
1262             context.AddNamedDecl(parser_ptype_type_decl);
1263         } while (0);
1264
1265         ClangExpressionVariableSP pvar_sp(m_parser_vars->m_persistent_vars->GetVariable(name));
1266
1267         if (pvar_sp)
1268         {
1269             AddOneVariable(context, pvar_sp, current_id);
1270             return;
1271         }
1272
1273         const char *reg_name(&name.GetCString()[1]);
1274
1275         if (m_parser_vars->m_exe_ctx.GetRegisterContext())
1276         {
1277             const RegisterInfo *reg_info(m_parser_vars->m_exe_ctx.GetRegisterContext()->GetRegisterInfoByName(reg_name));
1278
1279             if (reg_info)
1280             {
1281                 if (log)
1282                     log->Printf("  CEDM::FEVD[%u] Found register %s", current_id, reg_info->name);
1283
1284                 AddOneRegister(context, reg_info, current_id);
1285             }
1286         }
1287     }
1288     else
1289     {
1290         ValueObjectSP valobj;
1291         VariableSP var;
1292         Error err;
1293
1294         if (frame && !namespace_decl)
1295         {
1296             valobj = frame->GetValueForVariableExpressionPath(name_unique_cstr,
1297                                                               eNoDynamicValues,
1298                                                               StackFrame::eExpressionPathOptionCheckPtrVsMember |
1299                                                               StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1300                                                               StackFrame::eExpressionPathOptionsNoSyntheticChildren |
1301                                                               StackFrame::eExpressionPathOptionsNoSyntheticArrayRange,
1302                                                               var,
1303                                                               err);
1304
1305             // If we found a variable in scope, no need to pull up function names
1306             if (err.Success() && var)
1307             {
1308                 AddOneVariable(context, var, valobj, current_id);
1309                 context.m_found.variable = true;
1310                 return;
1311             }
1312         }
1313
1314         if (target)
1315         {
1316             var = FindGlobalVariable (*target,
1317                                       module_sp,
1318                                       name,
1319                                       &namespace_decl,
1320                                       NULL);
1321
1322             if (var)
1323             {
1324                 valobj = ValueObjectVariable::Create(target, var);
1325                 AddOneVariable(context, var, valobj, current_id);
1326                 context.m_found.variable = true;
1327                 return;
1328             }
1329         }
1330         
1331         std::vector<clang::NamedDecl *> decls_from_modules;
1332         
1333         if (target)
1334         {
1335             if (ClangModulesDeclVendor *decl_vendor = target->GetClangModulesDeclVendor())
1336             {
1337                 decl_vendor->FindDecls(name, false, UINT32_MAX, decls_from_modules);
1338             }
1339         }
1340
1341         if (!context.m_found.variable)
1342         {
1343             const bool include_inlines = false;
1344             const bool append = false;
1345
1346             if (namespace_decl && module_sp)
1347             {
1348                 const bool include_symbols = false;
1349
1350                 module_sp->FindFunctions(name,
1351                                          &namespace_decl,
1352                                          eFunctionNameTypeBase,
1353                                          include_symbols,
1354                                          include_inlines,
1355                                          append,
1356                                          sc_list);
1357             }
1358             else if (target && !namespace_decl)
1359             {
1360                 const bool include_symbols = true;
1361
1362                 // TODO Fix FindFunctions so that it doesn't return
1363                 //   instance methods for eFunctionNameTypeBase.
1364
1365                 target->GetImages().FindFunctions(name,
1366                                                   eFunctionNameTypeFull,
1367                                                   include_symbols,
1368                                                   include_inlines,
1369                                                   append,
1370                                                   sc_list);
1371             }
1372
1373             if (sc_list.GetSize())
1374             {
1375                 Symbol *extern_symbol = NULL;
1376                 Symbol *non_extern_symbol = NULL;
1377
1378                 for (uint32_t index = 0, num_indices = sc_list.GetSize();
1379                      index < num_indices;
1380                      ++index)
1381                 {
1382                     SymbolContext sym_ctx;
1383                     sc_list.GetContextAtIndex(index, sym_ctx);
1384
1385                     if (sym_ctx.function)
1386                     {
1387                         clang::DeclContext *decl_ctx = sym_ctx.function->GetClangDeclContext();
1388
1389                         if (!decl_ctx)
1390                             continue;
1391
1392                         // Filter out class/instance methods.
1393                         if (dyn_cast<clang::ObjCMethodDecl>(decl_ctx))
1394                             continue;
1395                         if (dyn_cast<clang::CXXMethodDecl>(decl_ctx))
1396                             continue;
1397
1398                         AddOneFunction(context, sym_ctx.function, NULL, current_id);
1399                         context.m_found.function_with_type_info = true;
1400                         context.m_found.function = true;
1401                     }
1402                     else if (sym_ctx.symbol)
1403                     {
1404                         if (sym_ctx.symbol->GetType() == eSymbolTypeReExported && target)
1405                         {
1406                             sym_ctx.symbol = sym_ctx.symbol->ResolveReExportedSymbol(*target);
1407                             if (sym_ctx.symbol == NULL)
1408                                 continue;
1409                         }
1410
1411                         if (sym_ctx.symbol->IsExternal())
1412                             extern_symbol = sym_ctx.symbol;
1413                         else
1414                             non_extern_symbol = sym_ctx.symbol;
1415                     }
1416                 }
1417                 
1418                 if (!context.m_found.function_with_type_info)
1419                 {
1420                     for (clang::NamedDecl *decl : decls_from_modules)
1421                     {
1422                         if (llvm::isa<clang::FunctionDecl>(decl))
1423                         {
1424                             clang::NamedDecl *copied_decl = llvm::cast<FunctionDecl>(m_ast_importer->CopyDecl(m_ast_context, &decl->getASTContext(), decl));
1425                             context.AddNamedDecl(copied_decl);
1426                             context.m_found.function_with_type_info = true;
1427                         }
1428                     }
1429                 }
1430
1431                 if (!context.m_found.function_with_type_info)
1432                 {
1433                     if (extern_symbol)
1434                     {
1435                         AddOneFunction (context, NULL, extern_symbol, current_id);
1436                         context.m_found.function = true;
1437                     }
1438                     else if (non_extern_symbol)
1439                     {
1440                         AddOneFunction (context, NULL, non_extern_symbol, current_id);
1441                         context.m_found.function = true;
1442                     }
1443                 }
1444             }
1445
1446             if (target && !context.m_found.variable && !namespace_decl)
1447             {
1448                 // We couldn't find a non-symbol variable for this.  Now we'll hunt for a generic
1449                 // data symbol, and -- if it is found -- treat it as a variable.
1450
1451                 const Symbol *data_symbol = FindGlobalDataSymbol(*target, name);
1452
1453                 if (data_symbol)
1454                 {
1455                     std::string warning("got name from symbols: ");
1456                     warning.append(name.AsCString());
1457                     const unsigned diag_id = m_ast_context->getDiagnostics().getCustomDiagID(clang::DiagnosticsEngine::Level::Warning, "%0");
1458                     m_ast_context->getDiagnostics().Report(diag_id) << warning.c_str();
1459                     AddOneGenericVariable(context, *data_symbol, current_id);
1460                     context.m_found.variable = true;
1461                 }
1462             }
1463         }
1464     }
1465 }
1466
1467 //static clang_type_t
1468 //MaybePromoteToBlockPointerType
1469 //(
1470 //    ASTContext *ast_context,
1471 //    clang_type_t candidate_type
1472 //)
1473 //{
1474 //    if (!candidate_type)
1475 //        return candidate_type;
1476 //
1477 //    QualType candidate_qual_type = QualType::getFromOpaquePtr(candidate_type);
1478 //
1479 //    const PointerType *candidate_pointer_type = dyn_cast<PointerType>(candidate_qual_type);
1480 //
1481 //    if (!candidate_pointer_type)
1482 //        return candidate_type;
1483 //
1484 //    QualType pointee_qual_type = candidate_pointer_type->getPointeeType();
1485 //
1486 //    const RecordType *pointee_record_type = dyn_cast<RecordType>(pointee_qual_type);
1487 //
1488 //    if (!pointee_record_type)
1489 //        return candidate_type;
1490 //
1491 //    RecordDecl *pointee_record_decl = pointee_record_type->getDecl();
1492 //
1493 //    if (!pointee_record_decl->isRecord())
1494 //        return candidate_type;
1495 //
1496 //    if (!pointee_record_decl->getName().startswith(llvm::StringRef("__block_literal_")))
1497 //        return candidate_type;
1498 //
1499 //    QualType generic_function_type = ast_context->getFunctionNoProtoType(ast_context->UnknownAnyTy);
1500 //    QualType block_pointer_type = ast_context->getBlockPointerType(generic_function_type);
1501 //
1502 //    return block_pointer_type.getAsOpaquePtr();
1503 //}
1504
1505 bool
1506 ClangExpressionDeclMap::GetVariableValue (VariableSP &var,
1507                                           lldb_private::Value &var_location,
1508                                           TypeFromUser *user_type,
1509                                           TypeFromParser *parser_type)
1510 {
1511     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1512
1513     Type *var_type = var->GetType();
1514
1515     if (!var_type)
1516     {
1517         if (log)
1518             log->PutCString("Skipped a definition because it has no type");
1519         return false;
1520     }
1521
1522     ClangASTType var_clang_type = var_type->GetClangFullType();
1523
1524     if (!var_clang_type)
1525     {
1526         if (log)
1527             log->PutCString("Skipped a definition because it has no Clang type");
1528         return false;
1529     }
1530
1531     ASTContext *ast = var_type->GetClangASTContext().getASTContext();
1532
1533     if (!ast)
1534     {
1535         if (log)
1536             log->PutCString("There is no AST context for the current execution context");
1537         return false;
1538     }
1539     //var_clang_type = MaybePromoteToBlockPointerType (ast, var_clang_type);
1540
1541     DWARFExpression &var_location_expr = var->LocationExpression();
1542
1543     Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1544     Error err;
1545
1546     if (var->GetLocationIsConstantValueData())
1547     {
1548         DataExtractor const_value_extractor;
1549
1550         if (var_location_expr.GetExpressionData(const_value_extractor))
1551         {
1552             var_location = Value(const_value_extractor.GetDataStart(), const_value_extractor.GetByteSize());
1553             var_location.SetValueType(Value::eValueTypeHostAddress);
1554         }
1555         else
1556         {
1557             if (log)
1558                 log->Printf("Error evaluating constant variable: %s", err.AsCString());
1559             return false;
1560         }
1561     }
1562
1563     ClangASTType type_to_use = GuardedCopyType(var_clang_type);
1564
1565     if (!type_to_use)
1566     {
1567         if (log)
1568             log->Printf("Couldn't copy a variable's type into the parser's AST context");
1569
1570         return false;
1571     }
1572
1573     if (parser_type)
1574         *parser_type = TypeFromParser(type_to_use);
1575
1576     if (var_location.GetContextType() == Value::eContextTypeInvalid)
1577         var_location.SetClangType(type_to_use);
1578
1579     if (var_location.GetValueType() == Value::eValueTypeFileAddress)
1580     {
1581         SymbolContext var_sc;
1582         var->CalculateSymbolContext(&var_sc);
1583
1584         if (!var_sc.module_sp)
1585             return false;
1586
1587         Address so_addr(var_location.GetScalar().ULongLong(), var_sc.module_sp->GetSectionList());
1588
1589         lldb::addr_t load_addr = so_addr.GetLoadAddress(target);
1590
1591         if (load_addr != LLDB_INVALID_ADDRESS)
1592         {
1593             var_location.GetScalar() = load_addr;
1594             var_location.SetValueType(Value::eValueTypeLoadAddress);
1595         }
1596     }
1597
1598     if (user_type)
1599         *user_type = TypeFromUser(var_clang_type);
1600
1601     return true;
1602 }
1603
1604 void
1605 ClangExpressionDeclMap::AddOneVariable (NameSearchContext &context, VariableSP var, ValueObjectSP valobj, unsigned int current_id)
1606 {
1607     assert (m_parser_vars.get());
1608
1609     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1610
1611     TypeFromUser ut;
1612     TypeFromParser pt;
1613     Value var_location;
1614
1615     if (!GetVariableValue (var, var_location, &ut, &pt))
1616         return;
1617
1618     clang::QualType parser_opaque_type = QualType::getFromOpaquePtr(pt.GetOpaqueQualType());
1619
1620     if (parser_opaque_type.isNull())
1621         return;
1622
1623     if (const clang::Type *parser_type = parser_opaque_type.getTypePtr())
1624     {
1625         if (const TagType *tag_type = dyn_cast<TagType>(parser_type))
1626             CompleteType(tag_type->getDecl());
1627         if (const ObjCObjectPointerType *objc_object_ptr_type = dyn_cast<ObjCObjectPointerType>(parser_type))
1628             CompleteType(objc_object_ptr_type->getInterfaceDecl());
1629     }
1630
1631
1632     bool is_reference = pt.IsReferenceType();
1633
1634     NamedDecl *var_decl = NULL;
1635     if (is_reference)
1636         var_decl = context.AddVarDecl(pt);
1637     else
1638         var_decl = context.AddVarDecl(pt.GetLValueReferenceType());
1639
1640     std::string decl_name(context.m_decl_name.getAsString());
1641     ConstString entity_name(decl_name.c_str());
1642     ClangExpressionVariableSP entity(m_found_entities.CreateVariable (valobj));
1643
1644     assert (entity.get());
1645     entity->EnableParserVars(GetParserID());
1646     ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID());
1647     parser_vars->m_parser_type = pt;
1648     parser_vars->m_named_decl  = var_decl;
1649     parser_vars->m_llvm_value  = NULL;
1650     parser_vars->m_lldb_value  = var_location;
1651     parser_vars->m_lldb_var    = var;
1652
1653     if (is_reference)
1654         entity->m_flags |= ClangExpressionVariable::EVTypeIsReference;
1655
1656     if (log)
1657     {
1658         ASTDumper orig_dumper(ut.GetOpaqueQualType());
1659         ASTDumper ast_dumper(var_decl);
1660         log->Printf("  CEDM::FEVD[%u] Found variable %s, returned %s (original %s)", current_id, decl_name.c_str(), ast_dumper.GetCString(), orig_dumper.GetCString());
1661     }
1662 }
1663
1664 void
1665 ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
1666                                        ClangExpressionVariableSP &pvar_sp,
1667                                        unsigned int current_id)
1668 {
1669     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1670
1671     TypeFromUser user_type (pvar_sp->GetTypeFromUser());
1672
1673     TypeFromParser parser_type (GuardedCopyType(user_type));
1674
1675     if (!parser_type.GetOpaqueQualType())
1676     {
1677         if (log)
1678             log->Printf("  CEDM::FEVD[%u] Couldn't import type for pvar %s", current_id, pvar_sp->GetName().GetCString());
1679         return;
1680     }
1681
1682     NamedDecl *var_decl = context.AddVarDecl(parser_type.GetLValueReferenceType());
1683
1684     pvar_sp->EnableParserVars(GetParserID());
1685     ClangExpressionVariable::ParserVars *parser_vars = pvar_sp->GetParserVars(GetParserID());
1686     parser_vars->m_parser_type = parser_type;
1687     parser_vars->m_named_decl = var_decl;
1688     parser_vars->m_llvm_value = NULL;
1689     parser_vars->m_lldb_value.Clear();
1690
1691     if (log)
1692     {
1693         ASTDumper ast_dumper(var_decl);
1694         log->Printf("  CEDM::FEVD[%u] Added pvar %s, returned %s", current_id, pvar_sp->GetName().GetCString(), ast_dumper.GetCString());
1695     }
1696 }
1697
1698 void
1699 ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
1700                                               const Symbol &symbol,
1701                                               unsigned int current_id)
1702 {
1703     assert(m_parser_vars.get());
1704
1705     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1706
1707     Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1708
1709     if (target == NULL)
1710         return;
1711
1712     ASTContext *scratch_ast_context = target->GetScratchClangASTContext()->getASTContext();
1713
1714     TypeFromUser user_type (ClangASTContext::GetBasicType(scratch_ast_context, eBasicTypeVoid).GetPointerType().GetLValueReferenceType());
1715     TypeFromParser parser_type (ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid).GetPointerType().GetLValueReferenceType());
1716     NamedDecl *var_decl = context.AddVarDecl(parser_type);
1717
1718     std::string decl_name(context.m_decl_name.getAsString());
1719     ConstString entity_name(decl_name.c_str());
1720     ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx.GetBestExecutionContextScope (),
1721                                                                       entity_name,
1722                                                                       user_type,
1723                                                                       m_parser_vars->m_target_info.byte_order,
1724                                                                       m_parser_vars->m_target_info.address_byte_size));
1725     assert (entity.get());
1726
1727     entity->EnableParserVars(GetParserID());
1728     ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID());
1729
1730     const Address &symbol_address = symbol.GetAddress();
1731     lldb::addr_t symbol_load_addr = symbol_address.GetLoadAddress(target);
1732
1733     //parser_vars->m_lldb_value.SetContext(Value::eContextTypeClangType, user_type.GetOpaqueQualType());
1734     parser_vars->m_lldb_value.SetClangType(user_type);
1735     parser_vars->m_lldb_value.GetScalar() = symbol_load_addr;
1736     parser_vars->m_lldb_value.SetValueType(Value::eValueTypeLoadAddress);
1737
1738     parser_vars->m_parser_type = parser_type;
1739     parser_vars->m_named_decl  = var_decl;
1740     parser_vars->m_llvm_value  = NULL;
1741     parser_vars->m_lldb_sym    = &symbol;
1742
1743     if (log)
1744     {
1745         ASTDumper ast_dumper(var_decl);
1746
1747         log->Printf("  CEDM::FEVD[%u] Found variable %s, returned %s", current_id, decl_name.c_str(), ast_dumper.GetCString());
1748     }
1749 }
1750
1751 bool
1752 ClangExpressionDeclMap::ResolveUnknownTypes()
1753 {
1754     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1755     Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1756
1757     ASTContext *scratch_ast_context = target->GetScratchClangASTContext()->getASTContext();
1758
1759     for (size_t index = 0, num_entities = m_found_entities.GetSize();
1760          index < num_entities;
1761          ++index)
1762     {
1763         ClangExpressionVariableSP entity = m_found_entities.GetVariableAtIndex(index);
1764
1765         ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID());
1766
1767         if (entity->m_flags & ClangExpressionVariable::EVUnknownType)
1768         {
1769             const NamedDecl *named_decl = parser_vars->m_named_decl;
1770             const VarDecl *var_decl = dyn_cast<VarDecl>(named_decl);
1771
1772             if (!var_decl)
1773             {
1774                 if (log)
1775                     log->Printf("Entity of unknown type does not have a VarDecl");
1776                 return false;
1777             }
1778
1779             if (log)
1780             {
1781                 ASTDumper ast_dumper(const_cast<VarDecl*>(var_decl));
1782                 log->Printf("Variable of unknown type now has Decl %s", ast_dumper.GetCString());
1783             }
1784
1785             QualType var_type = var_decl->getType();
1786             TypeFromParser parser_type(var_type.getAsOpaquePtr(), &var_decl->getASTContext());
1787
1788             lldb::clang_type_t copied_type = m_ast_importer->CopyType(scratch_ast_context, &var_decl->getASTContext(), var_type.getAsOpaquePtr());
1789
1790             if (!copied_type)
1791             {
1792                 if (log)
1793                     log->Printf("ClangExpressionDeclMap::ResolveUnknownType - Couldn't import the type for a variable");
1794
1795                 return (bool) lldb::ClangExpressionVariableSP();
1796             }
1797
1798             TypeFromUser user_type(copied_type, scratch_ast_context);
1799
1800 //            parser_vars->m_lldb_value.SetContext(Value::eContextTypeClangType, user_type.GetOpaqueQualType());
1801             parser_vars->m_lldb_value.SetClangType(user_type);
1802             parser_vars->m_parser_type = parser_type;
1803
1804             entity->SetClangType(user_type);
1805
1806             entity->m_flags &= ~(ClangExpressionVariable::EVUnknownType);
1807         }
1808     }
1809
1810     return true;
1811 }
1812
1813 void
1814 ClangExpressionDeclMap::AddOneRegister (NameSearchContext &context,
1815                                         const RegisterInfo *reg_info,
1816                                         unsigned int current_id)
1817 {
1818     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1819
1820     ClangASTType clang_type = ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (m_ast_context,
1821                                                                                     reg_info->encoding,
1822                                                                                     reg_info->byte_size * 8);
1823
1824     if (!clang_type)
1825     {
1826         if (log)
1827             log->Printf("  Tried to add a type for %s, but couldn't get one", context.m_decl_name.getAsString().c_str());
1828         return;
1829     }
1830
1831     TypeFromParser parser_clang_type (clang_type);
1832
1833     NamedDecl *var_decl = context.AddVarDecl(parser_clang_type);
1834
1835     ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
1836                                                                       m_parser_vars->m_target_info.byte_order,
1837                                                                       m_parser_vars->m_target_info.address_byte_size));
1838     assert (entity.get());
1839
1840     std::string decl_name(context.m_decl_name.getAsString());
1841     entity->SetName (ConstString (decl_name.c_str()));
1842     entity->SetRegisterInfo (reg_info);
1843     entity->EnableParserVars(GetParserID());
1844     ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID());
1845     parser_vars->m_parser_type = parser_clang_type;
1846     parser_vars->m_named_decl = var_decl;
1847     parser_vars->m_llvm_value = NULL;
1848     parser_vars->m_lldb_value.Clear();
1849     entity->m_flags |= ClangExpressionVariable::EVBareRegister;
1850
1851     if (log)
1852     {
1853         ASTDumper ast_dumper(var_decl);
1854         log->Printf("  CEDM::FEVD[%d] Added register %s, returned %s", current_id, context.m_decl_name.getAsString().c_str(), ast_dumper.GetCString());
1855     }
1856 }
1857
1858 void
1859 ClangExpressionDeclMap::AddOneFunction (NameSearchContext &context,
1860                                         Function* function,
1861                                         Symbol* symbol,
1862                                         unsigned int current_id)
1863 {
1864     assert (m_parser_vars.get());
1865
1866     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1867
1868     NamedDecl *function_decl = NULL;
1869     const Address *fun_address = NULL;
1870     ClangASTType function_clang_type;
1871
1872     bool is_indirect_function = false;
1873
1874     if (function)
1875     {
1876         Type *function_type = function->GetType();
1877
1878         if (!function_type)
1879         {
1880             if (log)
1881                 log->PutCString("  Skipped a function because it has no type");
1882             return;
1883         }
1884
1885         function_clang_type = function_type->GetClangFullType();
1886
1887         if (!function_clang_type)
1888         {
1889             if (log)
1890                 log->PutCString("  Skipped a function because it has no Clang type");
1891             return;
1892         }
1893
1894         fun_address = &function->GetAddressRange().GetBaseAddress();
1895
1896         ClangASTType copied_function_type = GuardedCopyType(function_clang_type);
1897         if (copied_function_type)
1898         {
1899             function_decl = context.AddFunDecl(copied_function_type);
1900
1901             if (!function_decl)
1902             {
1903                 if (log)
1904                 {
1905                     log->Printf ("  Failed to create a function decl for '%s' {0x%8.8" PRIx64 "}",
1906                                  function_type->GetName().GetCString(),
1907                                  function_type->GetID());
1908                 }
1909
1910                 return;
1911             }
1912         }
1913         else
1914         {
1915             // We failed to copy the type we found
1916             if (log)
1917             {
1918                 log->Printf ("  Failed to import the function type '%s' {0x%8.8" PRIx64 "} into the expression parser AST contenxt",
1919                              function_type->GetName().GetCString(),
1920                              function_type->GetID());
1921             }
1922
1923             return;
1924         }
1925     }
1926     else if (symbol)
1927     {
1928         fun_address = &symbol->GetAddress();
1929         function_decl = context.AddGenericFunDecl();
1930         is_indirect_function = symbol->IsIndirect();
1931     }
1932     else
1933     {
1934         if (log)
1935             log->PutCString("  AddOneFunction called with no function and no symbol");
1936         return;
1937     }
1938
1939     Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1940
1941     lldb::addr_t load_addr = fun_address->GetCallableLoadAddress(target, is_indirect_function);
1942
1943     ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx.GetBestExecutionContextScope (),
1944                                                                       m_parser_vars->m_target_info.byte_order,
1945                                                                       m_parser_vars->m_target_info.address_byte_size));
1946     assert (entity.get());
1947
1948     std::string decl_name(context.m_decl_name.getAsString());
1949     entity->SetName(ConstString(decl_name.c_str()));
1950     entity->SetClangType (function_clang_type);
1951     entity->EnableParserVars(GetParserID());
1952
1953     ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID());
1954
1955     if (load_addr != LLDB_INVALID_ADDRESS)
1956     {
1957         parser_vars->m_lldb_value.SetValueType(Value::eValueTypeLoadAddress);
1958         parser_vars->m_lldb_value.GetScalar() = load_addr;
1959     }
1960     else
1961     {
1962         // We have to try finding a file address.
1963
1964         lldb::addr_t file_addr = fun_address->GetFileAddress();
1965
1966         parser_vars->m_lldb_value.SetValueType(Value::eValueTypeFileAddress);
1967         parser_vars->m_lldb_value.GetScalar() = file_addr;
1968     }
1969
1970
1971     parser_vars->m_named_decl  = function_decl;
1972     parser_vars->m_llvm_value  = NULL;
1973
1974     if (log)
1975     {
1976         ASTDumper ast_dumper(function_decl);
1977
1978         StreamString ss;
1979
1980         fun_address->Dump(&ss, m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(), Address::DumpStyleResolvedDescription);
1981
1982         log->Printf("  CEDM::FEVD[%u] Found %s function %s (description %s), returned %s",
1983                     current_id,
1984                     (function ? "specific" : "generic"),
1985                     decl_name.c_str(),
1986                     ss.GetData(),
1987                     ast_dumper.GetCString());
1988     }
1989 }
1990
1991 TypeFromParser
1992 ClangExpressionDeclMap::CopyClassType(TypeFromUser &ut,
1993                                       unsigned int current_id)
1994 {
1995     ClangASTType copied_clang_type = GuardedCopyType(ut);
1996
1997     if (!copied_clang_type)
1998     {
1999         Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
2000
2001         if (log)
2002             log->Printf("ClangExpressionDeclMap::CopyClassType - Couldn't import the type");
2003
2004         return TypeFromParser();
2005     }
2006
2007     if (copied_clang_type.IsAggregateType() && copied_clang_type.GetCompleteType ())
2008     {
2009         ClangASTType void_clang_type = ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid);
2010         ClangASTType void_ptr_clang_type = void_clang_type.GetPointerType();
2011
2012         ClangASTType method_type = ClangASTContext::CreateFunctionType (m_ast_context,
2013                                                                         void_clang_type,
2014                                                                         &void_ptr_clang_type,
2015                                                                         1,
2016                                                                         false,
2017                                                                         copied_clang_type.GetTypeQualifiers());
2018
2019         const bool is_virtual = false;
2020         const bool is_static = false;
2021         const bool is_inline = false;
2022         const bool is_explicit = false;
2023         const bool is_attr_used = true;
2024         const bool is_artificial = false;
2025
2026         copied_clang_type.AddMethodToCXXRecordType ("$__lldb_expr",
2027                                                     method_type,
2028                                                     lldb::eAccessPublic,
2029                                                     is_virtual,
2030                                                     is_static,
2031                                                     is_inline,
2032                                                     is_explicit,
2033                                                     is_attr_used,
2034                                                     is_artificial);
2035     }
2036
2037     return TypeFromParser(copied_clang_type);
2038 }
2039
2040 void
2041 ClangExpressionDeclMap::AddOneType(NameSearchContext &context,
2042                                    TypeFromUser &ut,
2043                                    unsigned int current_id)
2044 {
2045     ClangASTType copied_clang_type = GuardedCopyType(ut);
2046
2047     if (!copied_clang_type)
2048     {
2049         Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
2050
2051         if (log)
2052             log->Printf("ClangExpressionDeclMap::AddOneType - Couldn't import the type");
2053
2054         return;
2055     }
2056
2057     context.AddTypeDecl(copied_clang_type);
2058 }