Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclarationName.h" |
Sean Callanan | a074482 | 2010-11-01 23:22:47 +0000 | [diff] [blame] | 17 | #include "clang/AST/Decl.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/lldb-private.h" |
| 19 | #include "lldb/Core/Address.h" |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Error.h" |
Sean Callanan | 6184dfe | 2010-06-23 00:47:48 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Module.h" |
| 23 | #include "lldb/Expression/ClangASTSource.h" |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 24 | #include "lldb/Expression/ClangPersistentVariables.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Symbol/ClangASTContext.h" |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 26 | #include "lldb/Symbol/ClangNamespaceDecl.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Symbol/CompileUnit.h" |
| 28 | #include "lldb/Symbol/Function.h" |
| 29 | #include "lldb/Symbol/ObjectFile.h" |
| 30 | #include "lldb/Symbol/SymbolContext.h" |
| 31 | #include "lldb/Symbol/Type.h" |
| 32 | #include "lldb/Symbol/TypeList.h" |
| 33 | #include "lldb/Symbol/Variable.h" |
| 34 | #include "lldb/Symbol/VariableList.h" |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 35 | #include "lldb/Target/ExecutionContext.h" |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 36 | #include "lldb/Target/Process.h" |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 37 | #include "lldb/Target/RegisterContext.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | #include "lldb/Target/StackFrame.h" |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 39 | #include "lldb/Target/Target.h" |
Sean Callanan | a074482 | 2010-11-01 23:22:47 +0000 | [diff] [blame] | 40 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 42 | using namespace lldb; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | using namespace lldb_private; |
| 44 | using namespace clang; |
| 45 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 46 | ClangExpressionDeclMap::ClangExpressionDeclMap (ExecutionContext *exe_ctx) : |
| 47 | m_found_entities (), |
| 48 | m_struct_members (), |
| 49 | m_exe_ctx (), |
| 50 | m_sym_ctx (), |
| 51 | m_persistent_vars (NULL), |
| 52 | m_struct_alignment (0), |
| 53 | m_struct_size (0), |
| 54 | m_struct_laid_out (false), |
| 55 | m_enable_lookups (false), |
| 56 | m_allocated_area (0), |
| 57 | m_materialized_location (0), |
| 58 | m_result_name (), |
| 59 | m_object_pointer_type (), |
| 60 | m_lookedup_types () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 62 | if (exe_ctx) |
| 63 | { |
| 64 | m_exe_ctx = *exe_ctx; |
| 65 | if (exe_ctx->frame) |
| 66 | m_sym_ctx = exe_ctx->frame->GetSymbolContext(lldb::eSymbolContextEverything); |
| 67 | if (exe_ctx->process) |
| 68 | m_persistent_vars = &exe_ctx->process->GetPersistentVariables(); |
| 69 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | ClangExpressionDeclMap::~ClangExpressionDeclMap() |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 73 | { |
| 74 | for (uint64_t entity_index = 0, num_entities = m_found_entities.Size(); |
| 75 | entity_index < num_entities; |
| 76 | ++entity_index) |
| 77 | { |
| 78 | ClangExpressionVariable &entity(m_found_entities.VariableAtIndex(entity_index)); |
| 79 | if (entity.m_parser_vars.get() && |
| 80 | entity.m_parser_vars->m_lldb_value) |
| 81 | delete entity.m_parser_vars->m_lldb_value; |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 82 | |
| 83 | entity.DisableParserVars(); |
| 84 | } |
| 85 | |
| 86 | for (uint64_t pvar_index = 0, num_pvars = m_persistent_vars->Size(); |
| 87 | pvar_index < num_pvars; |
| 88 | ++pvar_index) |
| 89 | { |
| 90 | ClangExpressionVariable &pvar(m_persistent_vars->VariableAtIndex(pvar_index)); |
| 91 | pvar.DisableParserVars(); |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 92 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | |
Sean Callanan | 7a60b94 | 2010-10-08 01:58:41 +0000 | [diff] [blame] | 94 | if (m_materialized_location) |
Sean Callanan | c2c6f77 | 2010-10-26 00:31:56 +0000 | [diff] [blame] | 95 | { |
| 96 | //#define SINGLE_STEP_EXPRESSIONS |
| 97 | |
| 98 | #ifndef SINGLE_STEP_EXPRESSIONS |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 99 | m_exe_ctx.process->DeallocateMemory(m_materialized_location); |
Sean Callanan | c2c6f77 | 2010-10-26 00:31:56 +0000 | [diff] [blame] | 100 | #endif |
Sean Callanan | 7a60b94 | 2010-10-08 01:58:41 +0000 | [diff] [blame] | 101 | m_materialized_location = 0; |
| 102 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 105 | // Interface for IRForTarget |
| 106 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 107 | const ConstString & |
| 108 | ClangExpressionDeclMap::GetPersistentResultName () |
Sean Callanan | 82b74c8 | 2010-08-12 01:56:52 +0000 | [diff] [blame] | 109 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 110 | if (!m_result_name) |
| 111 | m_persistent_vars->GetNextResultName(m_result_name); |
| 112 | return m_result_name; |
Sean Callanan | 82b74c8 | 2010-08-12 01:56:52 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 115 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 116 | ClangExpressionDeclMap::AddPersistentVariable |
| 117 | ( |
| 118 | const clang::NamedDecl *decl, |
| 119 | const ConstString &name, |
| 120 | TypeFromParser parser_type |
| 121 | ) |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 122 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 123 | clang::ASTContext *context(m_exe_ctx.target->GetScratchClangASTContext()->getASTContext()); |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 124 | |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 125 | TypeFromUser user_type(ClangASTContext::CopyType(context, |
Sean Callanan | 82b74c8 | 2010-08-12 01:56:52 +0000 | [diff] [blame] | 126 | parser_type.GetASTContext(), |
| 127 | parser_type.GetOpaqueQualType()), |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 128 | context); |
| 129 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 130 | if (!m_persistent_vars->CreatePersistentVariable (name, user_type)) |
| 131 | return false; |
| 132 | |
| 133 | ClangExpressionVariable *var = m_persistent_vars->GetVariable(name); |
| 134 | |
| 135 | if (!var) |
| 136 | return false; |
| 137 | |
| 138 | var->EnableParserVars(); |
| 139 | |
| 140 | var->m_parser_vars->m_named_decl = decl; |
| 141 | var->m_parser_vars->m_parser_type = parser_type; |
| 142 | |
| 143 | return true; |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 147 | ClangExpressionDeclMap::AddValueToStruct |
| 148 | ( |
| 149 | const clang::NamedDecl *decl, |
| 150 | const ConstString &name, |
| 151 | llvm::Value *value, |
| 152 | size_t size, |
| 153 | off_t alignment |
| 154 | ) |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 155 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 156 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 157 | |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 158 | m_struct_laid_out = false; |
| 159 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 160 | if (m_struct_members.GetVariable(decl)) |
| 161 | return true; |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 162 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 163 | ClangExpressionVariable *var = m_found_entities.GetVariable(decl); |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 164 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 165 | if (!var) |
| 166 | var = m_persistent_vars->GetVariable(decl); |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 167 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 168 | if (!var) |
| 169 | return false; |
| 170 | |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 171 | if (log) |
| 172 | log->Printf("Adding value for decl %p [%s - %s] to the structure", |
| 173 | decl, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 174 | name.GetCString(), |
| 175 | var->m_name.GetCString()); |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 176 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 177 | // We know entity->m_parser_vars is valid because we used a parser variable |
| 178 | // to find it |
| 179 | var->m_parser_vars->m_llvm_value = value; |
| 180 | |
| 181 | var->EnableJITVars(); |
| 182 | var->m_jit_vars->m_alignment = alignment; |
| 183 | var->m_jit_vars->m_size = size; |
| 184 | |
| 185 | m_struct_members.AddVariable(*var); |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 186 | |
| 187 | return true; |
| 188 | } |
| 189 | |
| 190 | bool |
| 191 | ClangExpressionDeclMap::DoStructLayout () |
| 192 | { |
| 193 | if (m_struct_laid_out) |
| 194 | return true; |
| 195 | |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 196 | off_t cursor = 0; |
| 197 | |
| 198 | m_struct_alignment = 0; |
| 199 | m_struct_size = 0; |
| 200 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 201 | for (uint64_t member_index = 0, num_members = m_struct_members.Size(); |
| 202 | member_index < num_members; |
| 203 | ++member_index) |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 204 | { |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 205 | ClangExpressionVariable &member(m_struct_members.VariableAtIndex(member_index)); |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 206 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 207 | if (!member.m_jit_vars.get()) |
| 208 | return false; |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 209 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 210 | if (member_index == 0) |
| 211 | m_struct_alignment = member.m_jit_vars->m_alignment; |
| 212 | |
| 213 | if (cursor % member.m_jit_vars->m_alignment) |
| 214 | cursor += (member.m_jit_vars->m_alignment - (cursor % member.m_jit_vars->m_alignment)); |
| 215 | |
| 216 | member.m_jit_vars->m_offset = cursor; |
| 217 | cursor += member.m_jit_vars->m_size; |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | m_struct_size = cursor; |
| 221 | |
| 222 | m_struct_laid_out = true; |
| 223 | return true; |
| 224 | } |
| 225 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 226 | bool ClangExpressionDeclMap::GetStructInfo |
| 227 | ( |
| 228 | uint32_t &num_elements, |
| 229 | size_t &size, |
| 230 | off_t &alignment |
| 231 | ) |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 232 | { |
| 233 | if (!m_struct_laid_out) |
| 234 | return false; |
| 235 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 236 | num_elements = m_struct_members.Size(); |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 237 | size = m_struct_size; |
| 238 | alignment = m_struct_alignment; |
| 239 | |
| 240 | return true; |
| 241 | } |
| 242 | |
| 243 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 244 | ClangExpressionDeclMap::GetStructElement |
| 245 | ( |
| 246 | const clang::NamedDecl *&decl, |
| 247 | llvm::Value *&value, |
| 248 | off_t &offset, |
| 249 | ConstString &name, |
| 250 | uint32_t index |
| 251 | ) |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 252 | { |
| 253 | if (!m_struct_laid_out) |
| 254 | return false; |
| 255 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 256 | if (index >= m_struct_members.Size()) |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 257 | return false; |
| 258 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 259 | ClangExpressionVariable &member(m_struct_members.VariableAtIndex(index)); |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 260 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 261 | if (!member.m_parser_vars.get() || |
| 262 | !member.m_jit_vars.get()) |
| 263 | return false; |
| 264 | |
| 265 | decl = member.m_parser_vars->m_named_decl; |
| 266 | value = member.m_parser_vars->m_llvm_value; |
| 267 | offset = member.m_jit_vars->m_offset; |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 268 | name = member.m_name; |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 269 | |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 270 | return true; |
| 271 | } |
| 272 | |
Sean Callanan | 02fbafa | 2010-07-27 21:39:39 +0000 | [diff] [blame] | 273 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 274 | ClangExpressionDeclMap::GetFunctionInfo |
| 275 | ( |
| 276 | const clang::NamedDecl *decl, |
| 277 | llvm::Value**& value, |
| 278 | uint64_t &ptr |
| 279 | ) |
Sean Callanan | ba992c5 | 2010-07-27 02:07:53 +0000 | [diff] [blame] | 280 | { |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 281 | ClangExpressionVariable *entity = m_found_entities.GetVariable(decl); |
| 282 | |
| 283 | if (!entity) |
| 284 | return false; |
Sean Callanan | ba992c5 | 2010-07-27 02:07:53 +0000 | [diff] [blame] | 285 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 286 | // We know m_parser_vars is valid since we searched for the variable by |
| 287 | // its NamedDecl |
Sean Callanan | ba992c5 | 2010-07-27 02:07:53 +0000 | [diff] [blame] | 288 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 289 | value = &entity->m_parser_vars->m_llvm_value; |
| 290 | ptr = entity->m_parser_vars->m_lldb_value->GetScalar().ULongLong(); |
| 291 | |
| 292 | return true; |
Sean Callanan | ba992c5 | 2010-07-27 02:07:53 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Sean Callanan | f5857a0 | 2010-07-31 01:32:05 +0000 | [diff] [blame] | 295 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 296 | ClangExpressionDeclMap::GetFunctionAddress |
| 297 | ( |
| 298 | const ConstString &name, |
| 299 | uint64_t &ptr |
| 300 | ) |
Sean Callanan | f5857a0 | 2010-07-31 01:32:05 +0000 | [diff] [blame] | 301 | { |
| 302 | // Back out in all cases where we're not fully initialized |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 303 | if (m_exe_ctx.frame == NULL) |
Sean Callanan | f5857a0 | 2010-07-31 01:32:05 +0000 | [diff] [blame] | 304 | return false; |
| 305 | |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 306 | SymbolContextList sc_list; |
Sean Callanan | f5857a0 | 2010-07-31 01:32:05 +0000 | [diff] [blame] | 307 | |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 308 | m_sym_ctx.FindFunctionsByName(name, false, sc_list); |
Sean Callanan | f5857a0 | 2010-07-31 01:32:05 +0000 | [diff] [blame] | 309 | |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 310 | if (!sc_list.GetSize()) |
Sean Callanan | f5857a0 | 2010-07-31 01:32:05 +0000 | [diff] [blame] | 311 | return false; |
| 312 | |
| 313 | SymbolContext sym_ctx; |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 314 | sc_list.GetContextAtIndex(0, sym_ctx); |
Sean Callanan | f5857a0 | 2010-07-31 01:32:05 +0000 | [diff] [blame] | 315 | |
| 316 | const Address *fun_address; |
| 317 | |
| 318 | if (sym_ctx.function) |
| 319 | fun_address = &sym_ctx.function->GetAddressRange().GetBaseAddress(); |
| 320 | else if (sym_ctx.symbol) |
| 321 | fun_address = &sym_ctx.symbol->GetAddressRangeRef().GetBaseAddress(); |
| 322 | else |
| 323 | return false; |
| 324 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 325 | ptr = fun_address->GetLoadAddress (m_exe_ctx.target); |
Sean Callanan | f5857a0 | 2010-07-31 01:32:05 +0000 | [diff] [blame] | 326 | |
| 327 | return true; |
| 328 | } |
| 329 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 330 | // Interface for CommandObjectExpression |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 331 | |
| 332 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 333 | ClangExpressionDeclMap::Materialize |
| 334 | ( |
| 335 | ExecutionContext *exe_ctx, |
| 336 | lldb::addr_t &struct_address, |
| 337 | Error &err |
| 338 | ) |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 339 | { |
| 340 | bool result = DoMaterialize(false, exe_ctx, NULL, err); |
| 341 | |
| 342 | if (result) |
| 343 | struct_address = m_materialized_location; |
| 344 | |
| 345 | return result; |
| 346 | } |
| 347 | |
| 348 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 349 | ClangExpressionDeclMap::GetObjectPointer |
| 350 | ( |
| 351 | lldb::addr_t &object_ptr, |
| 352 | ExecutionContext *exe_ctx, |
| 353 | Error &err |
| 354 | ) |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 355 | { |
| 356 | if (!exe_ctx || !exe_ctx->frame || !exe_ctx->target || !exe_ctx->process) |
| 357 | { |
| 358 | err.SetErrorString("Couldn't load 'this' because the context is incomplete"); |
| 359 | return false; |
| 360 | } |
| 361 | |
| 362 | if (!m_object_pointer_type.GetOpaqueQualType()) |
| 363 | { |
| 364 | err.SetErrorString("Couldn't load 'this' because its type is unknown"); |
| 365 | return false; |
| 366 | } |
| 367 | |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 368 | static ConstString g_this_const_str ("this"); |
| 369 | Variable *object_ptr_var = FindVariableInScope (*exe_ctx->frame, g_this_const_str, &m_object_pointer_type); |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 370 | |
| 371 | if (!object_ptr_var) |
| 372 | { |
| 373 | err.SetErrorString("Couldn't find 'this' with appropriate type in scope"); |
| 374 | return false; |
| 375 | } |
| 376 | |
| 377 | std::auto_ptr<lldb_private::Value> location_value(GetVariableValue(*exe_ctx, |
| 378 | object_ptr_var, |
| 379 | m_object_pointer_type.GetASTContext())); |
| 380 | |
| 381 | if (!location_value.get()) |
| 382 | { |
| 383 | err.SetErrorString("Couldn't get the location for 'this'"); |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | if (location_value->GetValueType() == Value::eValueTypeLoadAddress) |
| 388 | { |
| 389 | lldb::addr_t value_addr = location_value->GetScalar().ULongLong(); |
| 390 | uint32_t address_byte_size = exe_ctx->target->GetArchitecture().GetAddressByteSize(); |
| 391 | lldb::ByteOrder address_byte_order = exe_ctx->process->GetByteOrder(); |
| 392 | |
| 393 | if (ClangASTType::GetClangTypeBitWidth(m_object_pointer_type.GetASTContext(), m_object_pointer_type.GetOpaqueQualType()) != address_byte_size * 8) |
| 394 | { |
| 395 | err.SetErrorStringWithFormat("'this' is not of an expected pointer size"); |
| 396 | return false; |
| 397 | } |
| 398 | |
| 399 | DataBufferHeap data; |
| 400 | data.SetByteSize(address_byte_size); |
| 401 | Error read_error; |
| 402 | |
| 403 | if (exe_ctx->process->ReadMemory (value_addr, data.GetBytes(), address_byte_size, read_error) != address_byte_size) |
| 404 | { |
| 405 | err.SetErrorStringWithFormat("Coldn't read 'this' from the target: %s", read_error.AsCString()); |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | DataExtractor extractor(data.GetBytes(), data.GetByteSize(), address_byte_order, address_byte_size); |
| 410 | |
| 411 | uint32_t offset = 0; |
| 412 | |
| 413 | object_ptr = extractor.GetPointer(&offset); |
| 414 | |
| 415 | return true; |
| 416 | } |
| 417 | else |
| 418 | { |
| 419 | err.SetErrorString("'this' is not in memory; LLDB must be extended to handle registers"); |
| 420 | return false; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 425 | ClangExpressionDeclMap::Dematerialize |
| 426 | ( |
| 427 | ExecutionContext *exe_ctx, |
| 428 | ClangExpressionVariable *&result, |
| 429 | Error &err |
| 430 | ) |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 431 | { |
Sean Callanan | 82b74c8 | 2010-08-12 01:56:52 +0000 | [diff] [blame] | 432 | return DoMaterialize(true, exe_ctx, &result, err); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Sean Callanan | 32824aa | 2010-07-23 22:19:18 +0000 | [diff] [blame] | 435 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 436 | ClangExpressionDeclMap::DumpMaterializedStruct |
| 437 | ( |
| 438 | ExecutionContext *exe_ctx, |
| 439 | Stream &s, |
| 440 | Error &err |
| 441 | ) |
Sean Callanan | 32824aa | 2010-07-23 22:19:18 +0000 | [diff] [blame] | 442 | { |
| 443 | if (!m_struct_laid_out) |
| 444 | { |
| 445 | err.SetErrorString("Structure hasn't been laid out yet"); |
| 446 | return false; |
| 447 | } |
| 448 | |
| 449 | if (!exe_ctx) |
| 450 | { |
| 451 | err.SetErrorString("Received null execution context"); |
| 452 | return false; |
| 453 | } |
| 454 | |
| 455 | |
| 456 | if (!exe_ctx->process) |
| 457 | { |
| 458 | err.SetErrorString("Couldn't find the process"); |
| 459 | return false; |
| 460 | } |
| 461 | |
| 462 | if (!exe_ctx->target) |
| 463 | { |
| 464 | err.SetErrorString("Couldn't find the target"); |
| 465 | return false; |
| 466 | } |
| 467 | |
| 468 | lldb::DataBufferSP data(new DataBufferHeap(m_struct_size, 0)); |
| 469 | |
| 470 | Error error; |
| 471 | if (exe_ctx->process->ReadMemory (m_materialized_location, data->GetBytes(), data->GetByteSize(), error) != data->GetByteSize()) |
| 472 | { |
| 473 | err.SetErrorStringWithFormat ("Couldn't read struct from the target: %s", error.AsCString()); |
| 474 | return false; |
| 475 | } |
| 476 | |
| 477 | DataExtractor extractor(data, exe_ctx->process->GetByteOrder(), exe_ctx->target->GetArchitecture().GetAddressByteSize()); |
| 478 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 479 | for (uint64_t member_index = 0, num_members = m_struct_members.Size(); |
| 480 | member_index < num_members; |
| 481 | ++member_index) |
Sean Callanan | 32824aa | 2010-07-23 22:19:18 +0000 | [diff] [blame] | 482 | { |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 483 | ClangExpressionVariable &member (m_struct_members.VariableAtIndex(member_index)); |
Sean Callanan | 32824aa | 2010-07-23 22:19:18 +0000 | [diff] [blame] | 484 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 485 | s.Printf("[%s]\n", member.m_name.GetCString()); |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 486 | |
| 487 | if (!member.m_jit_vars.get()) |
| 488 | return false; |
| 489 | |
| 490 | extractor.Dump(&s, // stream |
| 491 | member.m_jit_vars->m_offset, // offset |
| 492 | lldb::eFormatBytesWithASCII, // format |
| 493 | 1, // byte size of individual entries |
| 494 | member.m_jit_vars->m_size, // number of entries |
| 495 | 16, // entries per line |
| 496 | m_materialized_location + member.m_jit_vars->m_offset, // address to print |
| 497 | 0, // bit size (bitfields only; 0 means ignore) |
| 498 | 0); // bit alignment (bitfields only; 0 means ignore) |
Sean Callanan | 32824aa | 2010-07-23 22:19:18 +0000 | [diff] [blame] | 499 | |
| 500 | s.PutChar('\n'); |
| 501 | } |
| 502 | |
| 503 | return true; |
| 504 | } |
| 505 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 506 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 507 | ClangExpressionDeclMap::DoMaterialize |
| 508 | ( |
| 509 | bool dematerialize, |
| 510 | ExecutionContext *exe_ctx, |
| 511 | ClangExpressionVariable **result, |
| 512 | Error &err |
| 513 | ) |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 514 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 515 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 82b74c8 | 2010-08-12 01:56:52 +0000 | [diff] [blame] | 516 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 517 | if (!m_struct_laid_out) |
| 518 | { |
| 519 | err.SetErrorString("Structure hasn't been laid out yet"); |
| 520 | return LLDB_INVALID_ADDRESS; |
| 521 | } |
| 522 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 523 | if (!exe_ctx) |
| 524 | { |
| 525 | err.SetErrorString("Received null execution context"); |
| 526 | return LLDB_INVALID_ADDRESS; |
| 527 | } |
| 528 | |
Sean Callanan | 4583927 | 2010-07-24 01:37:44 +0000 | [diff] [blame] | 529 | if (!exe_ctx->frame) |
| 530 | { |
| 531 | err.SetErrorString("Received null execution frame"); |
| 532 | return LLDB_INVALID_ADDRESS; |
| 533 | } |
| 534 | |
Sean Callanan | e8a59a8 | 2010-09-13 21:34:21 +0000 | [diff] [blame] | 535 | if (!m_struct_size) |
| 536 | { |
| 537 | if (log) |
| 538 | log->PutCString("Not bothering to allocate a struct because no arguments are needed"); |
| 539 | |
| 540 | m_allocated_area = NULL; |
| 541 | |
| 542 | return true; |
| 543 | } |
| 544 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 545 | const SymbolContext &sym_ctx(exe_ctx->frame->GetSymbolContext(lldb::eSymbolContextEverything)); |
| 546 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 547 | if (!dematerialize) |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 548 | { |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 549 | if (m_materialized_location) |
| 550 | { |
| 551 | exe_ctx->process->DeallocateMemory(m_materialized_location); |
| 552 | m_materialized_location = 0; |
| 553 | } |
| 554 | |
Sean Callanan | 7a60b94 | 2010-10-08 01:58:41 +0000 | [diff] [blame] | 555 | if (log) |
| 556 | log->PutCString("Allocating memory for materialized argument struct"); |
| 557 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 558 | lldb::addr_t mem = exe_ctx->process->AllocateMemory(m_struct_alignment + m_struct_size, |
| 559 | lldb::ePermissionsReadable | lldb::ePermissionsWritable, |
| 560 | err); |
| 561 | |
| 562 | if (mem == LLDB_INVALID_ADDRESS) |
| 563 | return false; |
| 564 | |
| 565 | m_allocated_area = mem; |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 568 | m_materialized_location = m_allocated_area; |
| 569 | |
| 570 | if (m_materialized_location % m_struct_alignment) |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 571 | m_materialized_location += (m_struct_alignment - (m_materialized_location % m_struct_alignment)); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 572 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 573 | for (uint64_t member_index = 0, num_members = m_struct_members.Size(); |
| 574 | member_index < num_members; |
| 575 | ++member_index) |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 576 | { |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 577 | ClangExpressionVariable &member (m_struct_members.VariableAtIndex(member_index)); |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 578 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 579 | if (!member.m_parser_vars.get()) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 580 | return false; |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 581 | |
| 582 | ClangExpressionVariable *entity = m_found_entities.GetVariable(member.m_parser_vars->m_named_decl); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 583 | ClangExpressionVariable *persistent_variable = m_persistent_vars->GetVariable(member.m_name); |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 584 | |
| 585 | if (entity) |
| 586 | { |
| 587 | if (!member.m_jit_vars.get()) |
| 588 | return false; |
| 589 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 590 | if (!DoMaterializeOneVariable(dematerialize, *exe_ctx, sym_ctx, member.m_name, member.m_user_type, m_materialized_location + member.m_jit_vars->m_offset, err)) |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 591 | return false; |
| 592 | } |
| 593 | else if (persistent_variable) |
| 594 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 595 | if (member.m_name == m_result_name) |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 596 | { |
| 597 | if (!dematerialize) |
| 598 | continue; |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 599 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 600 | if (log) |
| 601 | log->PutCString("Found result member in the struct"); |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 602 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 603 | *result = &member; |
| 604 | } |
| 605 | |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 606 | if (log) |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 607 | log->Printf("Searched for persistent variable %s and found %s", member.m_name.GetCString(), persistent_variable->m_name.GetCString()); |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 608 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 609 | if (!DoMaterializeOnePersistentVariable(dematerialize, *exe_ctx, persistent_variable->m_name, m_materialized_location + member.m_jit_vars->m_offset, err)) |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 610 | return false; |
| 611 | } |
| 612 | else |
| 613 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 614 | err.SetErrorStringWithFormat("Unexpected variable %s", member.m_name.GetCString()); |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 615 | return false; |
| 616 | } |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 619 | return true; |
| 620 | } |
| 621 | |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 622 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 623 | ClangExpressionDeclMap::DoMaterializeOnePersistentVariable |
| 624 | ( |
| 625 | bool dematerialize, |
| 626 | ExecutionContext &exe_ctx, |
| 627 | const ConstString &name, |
| 628 | lldb::addr_t addr, |
| 629 | Error &err |
| 630 | ) |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 631 | { |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 632 | ClangExpressionVariable *pvar(m_persistent_vars->GetVariable(name)); |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 633 | |
| 634 | if (!pvar) |
| 635 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 636 | err.SetErrorStringWithFormat("Undefined persistent variable %s", name.GetCString()); |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 637 | return LLDB_INVALID_ADDRESS; |
| 638 | } |
| 639 | |
| 640 | size_t pvar_size = pvar->Size(); |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 641 | |
Greg Clayton | 66ed2fb | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 642 | if (!pvar->m_data_sp.get()) |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 643 | return false; |
| 644 | |
Greg Clayton | 66ed2fb | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 645 | uint8_t *pvar_data = pvar->m_data_sp->GetBytes(); |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 646 | Error error; |
| 647 | |
| 648 | if (dematerialize) |
| 649 | { |
| 650 | if (exe_ctx.process->ReadMemory (addr, pvar_data, pvar_size, error) != pvar_size) |
| 651 | { |
| 652 | err.SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString()); |
| 653 | return false; |
| 654 | } |
| 655 | } |
| 656 | else |
| 657 | { |
| 658 | if (exe_ctx.process->WriteMemory (addr, pvar_data, pvar_size, error) != pvar_size) |
| 659 | { |
| 660 | err.SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString()); |
| 661 | return false; |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | return true; |
| 666 | } |
| 667 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 668 | bool |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 669 | ClangExpressionDeclMap::DoMaterializeOneVariable |
| 670 | ( |
| 671 | bool dematerialize, |
| 672 | ExecutionContext &exe_ctx, |
| 673 | const SymbolContext &sym_ctx, |
| 674 | const ConstString &name, |
| 675 | TypeFromUser type, |
| 676 | lldb::addr_t addr, |
| 677 | Error &err |
| 678 | ) |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 679 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 680 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 681 | |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 682 | if (!exe_ctx.frame || !exe_ctx.process) |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 683 | return false; |
| 684 | |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 685 | Variable *var = FindVariableInScope (*exe_ctx.frame, name, &type); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 686 | |
| 687 | if (!var) |
| 688 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 689 | err.SetErrorStringWithFormat("Couldn't find %s with appropriate type", name.GetCString()); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 690 | return false; |
| 691 | } |
| 692 | |
Sean Callanan | 841026f | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 693 | if (log) |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 694 | log->Printf("%s %s with type %p", (dematerialize ? "Dematerializing" : "Materializing"), name.GetCString(), type.GetOpaqueQualType()); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 695 | |
| 696 | std::auto_ptr<lldb_private::Value> location_value(GetVariableValue(exe_ctx, |
| 697 | var, |
| 698 | type.GetASTContext())); |
| 699 | |
| 700 | if (!location_value.get()) |
| 701 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 702 | err.SetErrorStringWithFormat("Couldn't get value for %s", name.GetCString()); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 703 | return false; |
| 704 | } |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 705 | |
| 706 | // The size of the type contained in addr |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 707 | |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 708 | size_t addr_bit_size = ClangASTType::GetClangTypeBitWidth(type.GetASTContext(), type.GetOpaqueQualType()); |
| 709 | size_t addr_byte_size = addr_bit_size % 8 ? ((addr_bit_size + 8) / 8) : (addr_bit_size / 8); |
| 710 | |
| 711 | Value::ValueType value_type = location_value->GetValueType(); |
| 712 | |
| 713 | switch (value_type) |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 714 | { |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 715 | default: |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 716 | { |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 717 | StreamString ss; |
| 718 | |
| 719 | location_value->Dump(&ss); |
| 720 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 721 | err.SetErrorStringWithFormat("%s has a value of unhandled type: %s", name.GetCString(), ss.GetString().c_str()); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 722 | return false; |
| 723 | } |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 724 | break; |
| 725 | case Value::eValueTypeLoadAddress: |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 726 | { |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 727 | lldb::addr_t value_addr = location_value->GetScalar().ULongLong(); |
| 728 | |
| 729 | DataBufferHeap data; |
| 730 | data.SetByteSize(addr_byte_size); |
| 731 | |
| 732 | lldb::addr_t src_addr; |
| 733 | lldb::addr_t dest_addr; |
| 734 | |
| 735 | if (dematerialize) |
| 736 | { |
| 737 | src_addr = addr; |
| 738 | dest_addr = value_addr; |
| 739 | } |
| 740 | else |
| 741 | { |
| 742 | src_addr = value_addr; |
| 743 | dest_addr = addr; |
| 744 | } |
| 745 | |
| 746 | Error error; |
| 747 | if (exe_ctx.process->ReadMemory (src_addr, data.GetBytes(), addr_byte_size, error) != addr_byte_size) |
| 748 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 749 | err.SetErrorStringWithFormat ("Couldn't read %s from the target: %s", name.GetCString(), error.AsCString()); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 750 | return false; |
| 751 | } |
| 752 | |
| 753 | if (exe_ctx.process->WriteMemory (dest_addr, data.GetBytes(), addr_byte_size, error) != addr_byte_size) |
| 754 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 755 | err.SetErrorStringWithFormat ("Couldn't write %s to the target: %s", name.GetCString(), error.AsCString()); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 756 | return false; |
| 757 | } |
| 758 | |
| 759 | if (log) |
| 760 | log->Printf("Copied from 0x%llx to 0x%llx", (uint64_t)src_addr, (uint64_t)addr); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 761 | } |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 762 | break; |
| 763 | case Value::eValueTypeScalar: |
| 764 | { |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 765 | if (location_value->GetContextType() != Value::eContextTypeRegisterInfo) |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 766 | { |
| 767 | StreamString ss; |
| 768 | |
| 769 | location_value->Dump(&ss); |
| 770 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 771 | err.SetErrorStringWithFormat("%s is a scalar of unhandled type: %s", name.GetCString(), ss.GetString().c_str()); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 772 | return false; |
| 773 | } |
| 774 | |
| 775 | lldb::RegisterInfo *register_info = location_value->GetRegisterInfo(); |
| 776 | |
| 777 | if (!register_info) |
| 778 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 779 | err.SetErrorStringWithFormat("Couldn't get the register information for %s", name.GetCString()); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 780 | return false; |
| 781 | } |
| 782 | |
| 783 | RegisterContext *register_context = exe_ctx.GetRegisterContext(); |
| 784 | |
| 785 | if (!register_context) |
| 786 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 787 | err.SetErrorStringWithFormat("Couldn't read register context to read %s from %s", name.GetCString(), register_info->name); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 788 | return false; |
| 789 | } |
| 790 | |
| 791 | uint32_t register_number = register_info->kinds[lldb::eRegisterKindLLDB]; |
| 792 | uint32_t register_byte_size = register_info->byte_size; |
| 793 | |
| 794 | if (dematerialize) |
| 795 | { |
| 796 | // Moving from addr into a register |
| 797 | // |
| 798 | // Case 1: addr_byte_size and register_byte_size are the same |
| 799 | // |
| 800 | // |AABBCCDD| Address contents |
| 801 | // |AABBCCDD| Register contents |
| 802 | // |
| 803 | // Case 2: addr_byte_size is bigger than register_byte_size |
| 804 | // |
| 805 | // Error! (The register should always be big enough to hold the data) |
| 806 | // |
| 807 | // Case 3: register_byte_size is bigger than addr_byte_size |
| 808 | // |
| 809 | // |AABB| Address contents |
| 810 | // |AABB0000| Register contents [on little-endian hardware] |
| 811 | // |0000AABB| Register contents [on big-endian hardware] |
| 812 | |
| 813 | if (addr_byte_size > register_byte_size) |
| 814 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 815 | err.SetErrorStringWithFormat("%s is too big to store in %s", name.GetCString(), register_info->name); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 816 | return false; |
| 817 | } |
| 818 | |
| 819 | uint32_t register_offset; |
| 820 | |
| 821 | switch (exe_ctx.process->GetByteOrder()) |
| 822 | { |
| 823 | default: |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 824 | err.SetErrorStringWithFormat("%s is stored with an unhandled byte order", name.GetCString()); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 825 | return false; |
| 826 | case lldb::eByteOrderLittle: |
| 827 | register_offset = 0; |
| 828 | break; |
| 829 | case lldb::eByteOrderBig: |
| 830 | register_offset = register_byte_size - addr_byte_size; |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | DataBufferHeap register_data (register_byte_size, 0); |
| 835 | |
| 836 | Error error; |
| 837 | if (exe_ctx.process->ReadMemory (addr, register_data.GetBytes() + register_offset, addr_byte_size, error) != addr_byte_size) |
| 838 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 839 | err.SetErrorStringWithFormat ("Couldn't read %s from the target: %s", name.GetCString(), error.AsCString()); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 840 | return false; |
| 841 | } |
| 842 | |
| 843 | DataExtractor register_extractor (register_data.GetBytes(), register_byte_size, exe_ctx.process->GetByteOrder(), exe_ctx.process->GetAddressByteSize()); |
| 844 | |
| 845 | if (!register_context->WriteRegisterBytes(register_number, register_extractor, 0)) |
| 846 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 847 | err.SetErrorStringWithFormat("Couldn't read %s from %s", name.GetCString(), register_info->name); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 848 | return false; |
| 849 | } |
| 850 | } |
| 851 | else |
| 852 | { |
| 853 | // Moving from a register into addr |
| 854 | // |
| 855 | // Case 1: addr_byte_size and register_byte_size are the same |
| 856 | // |
| 857 | // |AABBCCDD| Register contents |
| 858 | // |AABBCCDD| Address contents |
| 859 | // |
| 860 | // Case 2: addr_byte_size is bigger than register_byte_size |
| 861 | // |
| 862 | // Error! (The register should always be big enough to hold the data) |
| 863 | // |
| 864 | // Case 3: register_byte_size is bigger than addr_byte_size |
| 865 | // |
| 866 | // |AABBCCDD| Register contents |
| 867 | // |AABB| Address contents on little-endian hardware |
| 868 | // |CCDD| Address contents on big-endian hardware |
| 869 | |
| 870 | if (addr_byte_size > register_byte_size) |
| 871 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 872 | err.SetErrorStringWithFormat("%s is too big to store in %s", name.GetCString(), register_info->name); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 873 | return false; |
| 874 | } |
| 875 | |
| 876 | uint32_t register_offset; |
| 877 | |
| 878 | switch (exe_ctx.process->GetByteOrder()) |
| 879 | { |
| 880 | default: |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 881 | err.SetErrorStringWithFormat("%s is stored with an unhandled byte order", name.GetCString()); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 882 | return false; |
| 883 | case lldb::eByteOrderLittle: |
| 884 | register_offset = 0; |
| 885 | break; |
| 886 | case lldb::eByteOrderBig: |
| 887 | register_offset = register_byte_size - addr_byte_size; |
| 888 | break; |
| 889 | } |
| 890 | |
| 891 | DataExtractor register_extractor; |
| 892 | |
| 893 | if (!register_context->ReadRegisterBytes(register_number, register_extractor)) |
| 894 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 895 | err.SetErrorStringWithFormat("Couldn't read %s from %s", name.GetCString(), register_info->name); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 896 | return false; |
| 897 | } |
| 898 | |
| 899 | const void *register_data = register_extractor.GetData(®ister_offset, addr_byte_size); |
| 900 | |
| 901 | if (!register_data) |
| 902 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 903 | err.SetErrorStringWithFormat("Read but couldn't extract data for %s from %s", name.GetCString(), register_info->name); |
Sean Callanan | 17c6a05 | 2010-10-05 20:18:48 +0000 | [diff] [blame] | 904 | return false; |
| 905 | } |
| 906 | |
| 907 | Error error; |
| 908 | if (exe_ctx.process->WriteMemory (addr, register_data, addr_byte_size, error) != addr_byte_size) |
| 909 | { |
| 910 | err.SetErrorStringWithFormat ("Couldn't write %s to the target: %s", error.AsCString()); |
| 911 | return false; |
| 912 | } |
| 913 | } |
| 914 | } |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | return true; |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 918 | } |
| 919 | |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 920 | Variable * |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 921 | ClangExpressionDeclMap::FindVariableInScope |
| 922 | ( |
| 923 | StackFrame &frame, |
| 924 | const ConstString &name, |
| 925 | TypeFromUser *type |
| 926 | ) |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 927 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 928 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 929 | |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 930 | VariableList *var_list = frame.GetVariableList(true); |
| 931 | |
Greg Clayton | bf8e42b | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 932 | if (!var_list) |
| 933 | return NULL; |
| 934 | |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 935 | lldb::VariableSP var_sp (var_list->FindVariable(name)); |
| 936 | |
| 937 | const bool append = true; |
| 938 | const uint32_t max_matches = 1; |
| 939 | if (!var_sp) |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 940 | { |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 941 | // Look for globals elsewhere in the module for the frame |
| 942 | ModuleSP module_sp (m_exe_ctx.frame->GetSymbolContext(eSymbolContextModule).module_sp); |
| 943 | if (module_sp) |
| 944 | { |
| 945 | VariableList module_globals; |
| 946 | if (module_sp->FindGlobalVariables (name, append, max_matches, module_globals)) |
| 947 | var_sp = module_globals.GetVariableAtIndex (0); |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | if (!var_sp) |
| 952 | { |
| 953 | // Look for globals elsewhere in the program (all images) |
| 954 | TargetSP target_sp (m_exe_ctx.frame->GetSymbolContext(eSymbolContextTarget).target_sp); |
| 955 | if (target_sp) |
| 956 | { |
| 957 | VariableList program_globals; |
| 958 | if (target_sp->GetImages().FindGlobalVariables (name, append, max_matches, program_globals)) |
| 959 | var_sp = program_globals.GetVariableAtIndex (0); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | if (var_sp && type) |
| 964 | { |
| 965 | if (type->GetASTContext() == var_sp->GetType()->GetClangAST()) |
| 966 | { |
| 967 | if (!ClangASTContext::AreTypesSame(type->GetASTContext(), type->GetOpaqueQualType(), var_sp->GetType()->GetClangType())) |
| 968 | return NULL; |
| 969 | } |
| 970 | else |
| 971 | { |
| 972 | if (log) |
| 973 | log->PutCString("Skipping a candidate variable because of different AST contexts"); |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 974 | return NULL; |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 975 | } |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 976 | } |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 977 | |
| 978 | return var_sp.get(); |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 979 | } |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 980 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 981 | // Interface for ClangASTSource |
| 982 | void |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 983 | ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString &name) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 984 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 985 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 986 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 987 | if (log) |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 988 | log->Printf("Hunting for a definition for '%s'", name.GetCString()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 989 | |
| 990 | // Back out in all cases where we're not fully initialized |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 991 | if (m_exe_ctx.frame == NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 992 | return; |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 993 | |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 994 | SymbolContextList sc_list; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 995 | |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 996 | const char *name_unique_cstr = name.GetCString(); |
| 997 | |
| 998 | if (name_unique_cstr == NULL) |
| 999 | return; |
| 1000 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1001 | // Only look for functions by name out in our symbols if the function |
| 1002 | // doesn't start with our phony prefix of '$' |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 1003 | if (name_unique_cstr[0] != '$') |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1004 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1005 | |
| 1006 | Variable *var = FindVariableInScope(*m_exe_ctx.frame, name); |
| 1007 | |
| 1008 | // If we found a variable in scope, no need to pull up function names |
| 1009 | if (var != NULL) |
| 1010 | { |
| 1011 | AddOneVariable(context, var); |
| 1012 | } |
| 1013 | else |
| 1014 | { |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 1015 | m_sym_ctx.FindFunctionsByName (name, false, sc_list); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1016 | |
| 1017 | bool found_specific = false; |
| 1018 | Symbol *generic_symbol = NULL; |
| 1019 | Symbol *non_extern_symbol = NULL; |
| 1020 | |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 1021 | for (uint32_t index = 0, num_indices = sc_list.GetSize(); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1022 | index < num_indices; |
| 1023 | ++index) |
| 1024 | { |
| 1025 | SymbolContext sym_ctx; |
Greg Clayton | e5748d8 | 2010-11-09 23:46:37 +0000 | [diff] [blame] | 1026 | sc_list.GetContextAtIndex(index, sym_ctx); |
Sean Callanan | 3cfbd33 | 2010-10-06 00:10:07 +0000 | [diff] [blame] | 1027 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1028 | if (sym_ctx.function) |
| 1029 | { |
| 1030 | // TODO only do this if it's a C function; C++ functions may be |
| 1031 | // overloaded |
| 1032 | if (!found_specific) |
| 1033 | AddOneFunction(context, sym_ctx.function, NULL); |
| 1034 | found_specific = true; |
| 1035 | } |
| 1036 | else if (sym_ctx.symbol) |
| 1037 | { |
| 1038 | if (sym_ctx.symbol->IsExternal()) |
| 1039 | generic_symbol = sym_ctx.symbol; |
| 1040 | else |
| 1041 | non_extern_symbol = sym_ctx.symbol; |
| 1042 | } |
| 1043 | } |
| 1044 | |
Sean Callanan | 92aa666 | 2010-09-07 21:49:41 +0000 | [diff] [blame] | 1045 | if (!found_specific) |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1046 | { |
| 1047 | if (generic_symbol) |
| 1048 | AddOneFunction(context, NULL, generic_symbol); |
| 1049 | else if (non_extern_symbol) |
| 1050 | AddOneFunction(context, NULL, non_extern_symbol); |
| 1051 | } |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1052 | |
| 1053 | ClangNamespaceDecl namespace_decl (m_sym_ctx.FindNamespace(name)); |
| 1054 | if (namespace_decl) |
| 1055 | { |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 1056 | clang::NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decl); |
| 1057 | if (clang_namespace_decl) |
| 1058 | { |
| 1059 | // TODO: is this how we get the decl lookups to be called for |
| 1060 | // this namespace?? |
| 1061 | clang_namespace_decl->setHasExternalLexicalStorage(); |
| 1062 | } |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1063 | } |
Sean Callanan | 92aa666 | 2010-09-07 21:49:41 +0000 | [diff] [blame] | 1064 | } |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1065 | } |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1066 | else |
Sean Callanan | 3cfbd33 | 2010-10-06 00:10:07 +0000 | [diff] [blame] | 1067 | { |
Greg Clayton | 5745283 | 2010-11-09 04:42:43 +0000 | [diff] [blame] | 1068 | static ConstString g_lldb_class_name ("$__lldb_class"); |
| 1069 | if (name == g_lldb_class_name) |
| 1070 | { |
| 1071 | // Clang is looking for the type of "this" |
| 1072 | |
| 1073 | VariableList *vars = m_exe_ctx.frame->GetVariableList(false); |
| 1074 | |
| 1075 | if (!vars) |
| 1076 | return; |
| 1077 | |
| 1078 | lldb::VariableSP this_var = vars->FindVariable(ConstString("this")); |
| 1079 | |
| 1080 | if (!this_var) |
| 1081 | return; |
| 1082 | |
| 1083 | Type *this_type = this_var->GetType(); |
| 1084 | |
| 1085 | if (!this_type) |
| 1086 | return; |
| 1087 | |
| 1088 | TypeFromUser this_user_type(this_type->GetClangType(), |
| 1089 | this_type->GetClangAST()); |
| 1090 | |
| 1091 | m_object_pointer_type = this_user_type; |
| 1092 | |
| 1093 | void *pointer_target_type; |
| 1094 | |
| 1095 | if (!ClangASTContext::IsPointerType(this_user_type.GetOpaqueQualType(), |
| 1096 | &pointer_target_type)) |
| 1097 | return; |
| 1098 | |
| 1099 | TypeFromUser class_user_type(pointer_target_type, |
| 1100 | this_type->GetClangAST()); |
| 1101 | |
| 1102 | AddOneType(context, class_user_type, true); |
| 1103 | |
| 1104 | return; |
| 1105 | } |
| 1106 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1107 | ClangExpressionVariable *pvar(m_persistent_vars->GetVariable(name)); |
| 1108 | |
| 1109 | if (pvar) |
| 1110 | AddOneVariable(context, pvar); |
Sean Callanan | 3cfbd33 | 2010-10-06 00:10:07 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1113 | |
Sean Callanan | 6df0840 | 2010-09-27 23:54:58 +0000 | [diff] [blame] | 1114 | // See information on gating of this operation next to the definition for |
| 1115 | // m_lookedup_types. |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 1116 | |
| 1117 | if (m_lookedup_types.find(name_unique_cstr) == m_lookedup_types.end()) |
Sean Callanan | 6df0840 | 2010-09-27 23:54:58 +0000 | [diff] [blame] | 1118 | { |
| 1119 | // 1 The name is added to m_lookedup_types. |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 1120 | m_lookedup_types.insert(std::pair<const char*, bool>(name_unique_cstr, true)); |
Sean Callanan | 6df0840 | 2010-09-27 23:54:58 +0000 | [diff] [blame] | 1121 | |
| 1122 | // 2 The type is looked up and added, potentially causing more type loookups. |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1123 | lldb::TypeSP type = m_sym_ctx.FindTypeByName (name); |
Sean Callanan | 6df0840 | 2010-09-27 23:54:58 +0000 | [diff] [blame] | 1124 | |
| 1125 | if (type.get()) |
| 1126 | { |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1127 | TypeFromUser user_type(type->GetClangType(), |
Sean Callanan | 6df0840 | 2010-09-27 23:54:58 +0000 | [diff] [blame] | 1128 | type->GetClangAST()); |
| 1129 | |
| 1130 | AddOneType(context, user_type, false); |
| 1131 | } |
| 1132 | |
| 1133 | // 3 The name is removed from m_lookedup_types. |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame^] | 1134 | m_lookedup_types.erase(name_unique_cstr); |
Sean Callanan | 6df0840 | 2010-09-27 23:54:58 +0000 | [diff] [blame] | 1135 | } |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | Value * |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1139 | ClangExpressionDeclMap::GetVariableValue |
| 1140 | ( |
| 1141 | ExecutionContext &exe_ctx, |
| 1142 | Variable *var, |
| 1143 | clang::ASTContext *parser_ast_context, |
| 1144 | TypeFromUser *user_type, |
| 1145 | TypeFromParser *parser_type |
| 1146 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1147 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1148 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 6184dfe | 2010-06-23 00:47:48 +0000 | [diff] [blame] | 1149 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1150 | Type *var_type = var->GetType(); |
| 1151 | |
| 1152 | if (!var_type) |
| 1153 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 1154 | if (log) |
| 1155 | log->PutCString("Skipped a definition because it has no type"); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1156 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1159 | void *var_opaque_type = var_type->GetClangType(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1160 | |
| 1161 | if (!var_opaque_type) |
| 1162 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 1163 | if (log) |
| 1164 | log->PutCString("Skipped a definition because it has no Clang type"); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1165 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1168 | TypeList *type_list = var_type->GetTypeList(); |
| 1169 | |
| 1170 | if (!type_list) |
| 1171 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 1172 | if (log) |
| 1173 | log->PutCString("Skipped a definition because the type has no associated type list"); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1174 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | clang::ASTContext *exe_ast_ctx = type_list->GetClangASTContext().getASTContext(); |
| 1178 | |
| 1179 | if (!exe_ast_ctx) |
| 1180 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 1181 | if (log) |
| 1182 | log->PutCString("There is no AST context for the current execution context"); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1183 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1186 | DWARFExpression &var_location_expr = var->LocationExpression(); |
| 1187 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1188 | std::auto_ptr<Value> var_location(new Value); |
| 1189 | |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 1190 | lldb::addr_t loclist_base_load_addr = LLDB_INVALID_ADDRESS; |
| 1191 | |
| 1192 | if (var_location_expr.IsLocationList()) |
| 1193 | { |
| 1194 | SymbolContext var_sc; |
| 1195 | var->CalculateSymbolContext (&var_sc); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 1196 | loclist_base_load_addr = var_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.target); |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 1197 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1198 | Error err; |
| 1199 | |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 1200 | if (!var_location_expr.Evaluate(&exe_ctx, exe_ast_ctx, loclist_base_load_addr, NULL, *var_location.get(), &err)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1201 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 1202 | if (log) |
| 1203 | log->Printf("Error evaluating location: %s", err.AsCString()); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1204 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 1207 | clang::ASTContext *var_ast_context = type_list->GetClangASTContext().getASTContext(); |
| 1208 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1209 | void *type_to_use; |
| 1210 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 1211 | if (parser_ast_context) |
| 1212 | { |
| 1213 | type_to_use = ClangASTContext::CopyType(parser_ast_context, var_ast_context, var_opaque_type); |
| 1214 | |
| 1215 | if (parser_type) |
| 1216 | *parser_type = TypeFromParser(type_to_use, parser_ast_context); |
| 1217 | } |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1218 | else |
| 1219 | type_to_use = var_opaque_type; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1220 | |
| 1221 | if (var_location.get()->GetContextType() == Value::eContextTypeInvalid) |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1222 | var_location.get()->SetContext(Value::eContextTypeClangType, type_to_use); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1223 | |
| 1224 | if (var_location.get()->GetValueType() == Value::eValueTypeFileAddress) |
| 1225 | { |
| 1226 | SymbolContext var_sc; |
| 1227 | var->CalculateSymbolContext(&var_sc); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1228 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1229 | if (!var_sc.module_sp) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1230 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1231 | |
| 1232 | ObjectFile *object_file = var_sc.module_sp->GetObjectFile(); |
| 1233 | |
| 1234 | if (!object_file) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1235 | return NULL; |
| 1236 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1237 | Address so_addr(var_location->GetScalar().ULongLong(), object_file->GetSectionList()); |
| 1238 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1239 | lldb::addr_t load_addr = so_addr.GetLoadAddress(m_exe_ctx.target); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1240 | |
| 1241 | var_location->GetScalar() = load_addr; |
| 1242 | var_location->SetValueType(Value::eValueTypeLoadAddress); |
| 1243 | } |
| 1244 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 1245 | if (user_type) |
| 1246 | *user_type = TypeFromUser(var_opaque_type, var_ast_context); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1247 | |
| 1248 | return var_location.release(); |
| 1249 | } |
| 1250 | |
| 1251 | void |
| 1252 | ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context, |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1253 | Variable* var) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1254 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1255 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1256 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 1257 | TypeFromUser ut; |
| 1258 | TypeFromParser pt; |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1259 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1260 | Value *var_location = GetVariableValue (m_exe_ctx, |
| 1261 | var, |
| 1262 | context.GetASTContext(), |
| 1263 | &ut, |
| 1264 | &pt); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 1265 | |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1266 | NamedDecl *var_decl = context.AddVarDecl(pt.GetOpaqueQualType()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1267 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 1268 | ClangExpressionVariable &entity(m_found_entities.VariableAtIndex(m_found_entities.CreateVariable())); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1269 | std::string decl_name(context.m_decl_name.getAsString()); |
| 1270 | entity.m_name.SetCString (decl_name.c_str()); |
| 1271 | entity.m_user_type = ut; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1272 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 1273 | entity.EnableParserVars(); |
| 1274 | entity.m_parser_vars->m_parser_type = pt; |
| 1275 | entity.m_parser_vars->m_named_decl = var_decl; |
| 1276 | entity.m_parser_vars->m_llvm_value = NULL; |
| 1277 | entity.m_parser_vars->m_lldb_value = var_location; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1278 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 1279 | if (log) |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1280 | { |
Sean Callanan | a074482 | 2010-11-01 23:22:47 +0000 | [diff] [blame] | 1281 | std::string var_decl_print_string; |
| 1282 | llvm::raw_string_ostream var_decl_print_stream(var_decl_print_string); |
| 1283 | var_decl->print(var_decl_print_stream); |
| 1284 | var_decl_print_stream.flush(); |
| 1285 | |
| 1286 | log->Printf("Found variable %s, returned %s", decl_name.c_str(), var_decl_print_string.c_str()); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1287 | } |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | void |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 1291 | ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context, |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 1292 | ClangExpressionVariable *pvar) |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 1293 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1294 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 1295 | |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 1296 | TypeFromUser user_type = pvar->m_user_type; |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 1297 | |
| 1298 | TypeFromParser parser_type(ClangASTContext::CopyType(context.GetASTContext(), |
| 1299 | user_type.GetASTContext(), |
| 1300 | user_type.GetOpaqueQualType()), |
| 1301 | context.GetASTContext()); |
| 1302 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 1303 | NamedDecl *var_decl = context.AddVarDecl(parser_type.GetOpaqueQualType()); |
| 1304 | |
| 1305 | pvar->EnableParserVars(); |
| 1306 | pvar->m_parser_vars->m_parser_type = parser_type; |
| 1307 | pvar->m_parser_vars->m_named_decl = var_decl; |
| 1308 | pvar->m_parser_vars->m_llvm_value = NULL; |
| 1309 | pvar->m_parser_vars->m_lldb_value = NULL; |
Sean Callanan | 45690fe | 2010-08-30 22:17:16 +0000 | [diff] [blame] | 1310 | |
| 1311 | if (log) |
Sean Callanan | a074482 | 2010-11-01 23:22:47 +0000 | [diff] [blame] | 1312 | { |
| 1313 | std::string var_decl_print_string; |
| 1314 | llvm::raw_string_ostream var_decl_print_stream(var_decl_print_string); |
| 1315 | var_decl->print(var_decl_print_stream); |
| 1316 | var_decl_print_stream.flush(); |
| 1317 | |
| 1318 | log->Printf("Added pvar %s, returned %s", pvar->m_name.GetCString(), var_decl_print_string.c_str()); |
| 1319 | } |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1322 | clang::NamespaceDecl * |
| 1323 | ClangExpressionDeclMap::AddNamespace (NameSearchContext &context, const ClangNamespaceDecl &namespace_decl) |
| 1324 | { |
| 1325 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 1326 | |
| 1327 | |
| 1328 | clang::Decl *copied_decl = ClangASTContext::CopyDecl (context.GetASTContext(), |
| 1329 | namespace_decl.GetASTContext(), |
| 1330 | namespace_decl.GetNamespaceDecl()); |
| 1331 | |
| 1332 | return dyn_cast<clang::NamespaceDecl>(copied_decl); |
| 1333 | } |
| 1334 | |
Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame] | 1335 | void |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1336 | ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context, |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1337 | Function* fun, |
| 1338 | Symbol* symbol) |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1339 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1340 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1341 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1342 | NamedDecl *fun_decl; |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1343 | std::auto_ptr<Value> fun_location(new Value); |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1344 | const Address *fun_address; |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1345 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1346 | // only valid for Functions, not for Symbols |
| 1347 | void *fun_opaque_type = NULL; |
| 1348 | clang::ASTContext *fun_ast_context = NULL; |
| 1349 | |
| 1350 | if (fun) |
| 1351 | { |
| 1352 | Type *fun_type = fun->GetType(); |
| 1353 | |
| 1354 | if (!fun_type) |
| 1355 | { |
| 1356 | if (log) |
| 1357 | log->PutCString("Skipped a function because it has no type"); |
| 1358 | return; |
| 1359 | } |
| 1360 | |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1361 | fun_opaque_type = fun_type->GetClangType(); |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1362 | |
| 1363 | if (!fun_opaque_type) |
| 1364 | { |
| 1365 | if (log) |
| 1366 | log->PutCString("Skipped a function because it has no Clang type"); |
| 1367 | return; |
| 1368 | } |
| 1369 | |
| 1370 | fun_address = &fun->GetAddressRange().GetBaseAddress(); |
| 1371 | |
| 1372 | TypeList *type_list = fun_type->GetTypeList(); |
| 1373 | fun_ast_context = type_list->GetClangASTContext().getASTContext(); |
| 1374 | void *copied_type = ClangASTContext::CopyType(context.GetASTContext(), fun_ast_context, fun_opaque_type); |
| 1375 | |
| 1376 | fun_decl = context.AddFunDecl(copied_type); |
| 1377 | } |
| 1378 | else if (symbol) |
| 1379 | { |
| 1380 | fun_address = &symbol->GetAddressRangeRef().GetBaseAddress(); |
| 1381 | |
| 1382 | fun_decl = context.AddGenericFunDecl(); |
| 1383 | } |
| 1384 | else |
| 1385 | { |
| 1386 | if (log) |
| 1387 | log->PutCString("AddOneFunction called with no function and no symbol"); |
| 1388 | return; |
| 1389 | } |
| 1390 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1391 | lldb::addr_t load_addr = fun_address->GetLoadAddress(m_exe_ctx.target); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1392 | fun_location->SetValueType(Value::eValueTypeLoadAddress); |
| 1393 | fun_location->GetScalar() = load_addr; |
| 1394 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 1395 | ClangExpressionVariable &entity(m_found_entities.VariableAtIndex(m_found_entities.CreateVariable())); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1396 | std::string decl_name(context.m_decl_name.getAsString()); |
| 1397 | entity.m_name.SetCString(decl_name.c_str()); |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 1398 | entity.m_user_type = TypeFromUser(fun_opaque_type, fun_ast_context);; |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1399 | |
Sean Callanan | 8c12720 | 2010-08-23 23:09:38 +0000 | [diff] [blame] | 1400 | entity.EnableParserVars(); |
| 1401 | entity.m_parser_vars->m_named_decl = fun_decl; |
| 1402 | entity.m_parser_vars->m_llvm_value = NULL; |
| 1403 | entity.m_parser_vars->m_lldb_value = fun_location.release(); |
| 1404 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 1405 | if (log) |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1406 | { |
Sean Callanan | a074482 | 2010-11-01 23:22:47 +0000 | [diff] [blame] | 1407 | std::string fun_decl_print_string; |
| 1408 | llvm::raw_string_ostream fun_decl_print_stream(fun_decl_print_string); |
| 1409 | fun_decl->print(fun_decl_print_stream); |
| 1410 | fun_decl_print_stream.flush(); |
| 1411 | |
| 1412 | log->Printf("Found %s function %s, returned %s", (fun ? "specific" : "generic"), decl_name.c_str(), fun_decl_print_string.c_str()); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1413 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1414 | } |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1415 | |
| 1416 | void |
| 1417 | ClangExpressionDeclMap::AddOneType(NameSearchContext &context, |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1418 | TypeFromUser &ut, |
| 1419 | bool add_method) |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1420 | { |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1421 | clang::ASTContext *parser_ast_context = context.GetASTContext(); |
| 1422 | clang::ASTContext *user_ast_context = ut.GetASTContext(); |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1423 | |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1424 | void *copied_type = ClangASTContext::CopyType(parser_ast_context, user_ast_context, ut.GetOpaqueQualType()); |
| 1425 | |
| 1426 | TypeFromParser parser_type(copied_type, parser_ast_context); |
| 1427 | |
| 1428 | if (add_method && ClangASTContext::IsAggregateType(copied_type)) |
| 1429 | { |
| 1430 | void *args[1]; |
| 1431 | |
| 1432 | args[0] = ClangASTContext::GetVoidPtrType(parser_ast_context, false); |
| 1433 | |
| 1434 | void *method_type = ClangASTContext::CreateFunctionType (parser_ast_context, |
| 1435 | ClangASTContext::GetBuiltInType_void(parser_ast_context), |
| 1436 | args, |
| 1437 | 1, |
| 1438 | false, |
| 1439 | ClangASTContext::GetTypeQualifiers(copied_type)); |
Greg Clayton | 30449d5 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 1440 | |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1441 | const bool is_virtual = false; |
| 1442 | const bool is_static = false; |
| 1443 | const bool is_inline = false; |
Greg Clayton | 30449d5 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 1444 | const bool is_explicit = false; |
| 1445 | |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1446 | ClangASTContext::AddMethodToCXXRecordType (parser_ast_context, |
| 1447 | copied_type, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1448 | "$__lldb_expr", |
Greg Clayton | 1d8173f | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1449 | method_type, |
| 1450 | lldb::eAccessPublic, |
| 1451 | is_virtual, |
| 1452 | is_static, |
Greg Clayton | 30449d5 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 1453 | is_inline, |
| 1454 | is_explicit); |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1455 | } |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1456 | |
| 1457 | context.AddTypeDecl(copied_type); |
| 1458 | } |