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 |
| 16 | #include "lldb/lldb-private.h" |
| 17 | #include "lldb/Core/Address.h" |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Error.h" |
Sean Callanan | 6184dfe | 2010-06-23 00:47:48 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Module.h" |
| 21 | #include "lldb/Expression/ClangASTSource.h" |
| 22 | #include "lldb/Symbol/ClangASTContext.h" |
| 23 | #include "lldb/Symbol/CompileUnit.h" |
| 24 | #include "lldb/Symbol/Function.h" |
| 25 | #include "lldb/Symbol/ObjectFile.h" |
| 26 | #include "lldb/Symbol/SymbolContext.h" |
| 27 | #include "lldb/Symbol/Type.h" |
| 28 | #include "lldb/Symbol/TypeList.h" |
| 29 | #include "lldb/Symbol/Variable.h" |
| 30 | #include "lldb/Symbol/VariableList.h" |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 31 | #include "lldb/Target/ExecutionContext.h" |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 32 | #include "lldb/Target/Process.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/Target/StackFrame.h" |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 34 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | using namespace lldb_private; |
| 37 | using namespace clang; |
| 38 | |
| 39 | ClangExpressionDeclMap::ClangExpressionDeclMap(ExecutionContext *exe_ctx) : |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 40 | m_exe_ctx(exe_ctx), |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 41 | m_struct_laid_out(false), |
| 42 | m_materialized_location(0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | { |
| 44 | if (exe_ctx && exe_ctx->frame) |
| 45 | m_sym_ctx = new SymbolContext(exe_ctx->frame->GetSymbolContext(lldb::eSymbolContextEverything)); |
| 46 | else |
| 47 | m_sym_ctx = NULL; |
| 48 | } |
| 49 | |
| 50 | ClangExpressionDeclMap::~ClangExpressionDeclMap() |
| 51 | { |
| 52 | uint32_t num_tuples = m_tuples.size (); |
| 53 | uint32_t tuple_index; |
| 54 | |
| 55 | for (tuple_index = 0; tuple_index < num_tuples; ++tuple_index) |
| 56 | delete m_tuples[tuple_index].m_value; |
| 57 | |
| 58 | if (m_sym_ctx) |
| 59 | delete m_sym_ctx; |
| 60 | } |
| 61 | |
| 62 | bool |
| 63 | ClangExpressionDeclMap::GetIndexForDecl (uint32_t &index, |
| 64 | const clang::Decl *decl) |
| 65 | { |
| 66 | uint32_t num_tuples = m_tuples.size (); |
| 67 | uint32_t tuple_index; |
| 68 | |
| 69 | for (tuple_index = 0; tuple_index < num_tuples; ++tuple_index) |
| 70 | { |
| 71 | if (m_tuples[tuple_index].m_decl == decl) |
| 72 | { |
| 73 | index = tuple_index; |
| 74 | return true; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return false; |
| 79 | } |
| 80 | |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 81 | // Interface for IRForTarget |
| 82 | |
| 83 | bool |
| 84 | ClangExpressionDeclMap::AddValueToStruct (llvm::Value *value, |
| 85 | const clang::NamedDecl *decl, |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 86 | std::string &name, |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 87 | void *parser_type, |
| 88 | clang::ASTContext *parser_ast_context, |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 89 | size_t size, |
| 90 | off_t alignment) |
| 91 | { |
| 92 | m_struct_laid_out = false; |
| 93 | |
| 94 | StructMemberIterator iter; |
| 95 | |
| 96 | for (iter = m_members.begin(); |
| 97 | iter != m_members.end(); |
| 98 | ++iter) |
| 99 | { |
| 100 | if (iter->m_decl == decl) |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | StructMember member; |
| 105 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 106 | member.m_value = value; |
| 107 | member.m_decl = decl; |
| 108 | member.m_name = name; |
| 109 | member.m_parser_type = TypeFromParser(parser_type, parser_ast_context); |
| 110 | member.m_offset = 0; |
| 111 | member.m_size = size; |
| 112 | member.m_alignment = alignment; |
Sean Callanan | 8bce665 | 2010-07-13 21:41:46 +0000 | [diff] [blame] | 113 | |
| 114 | m_members.push_back(member); |
| 115 | |
| 116 | return true; |
| 117 | } |
| 118 | |
| 119 | bool |
| 120 | ClangExpressionDeclMap::DoStructLayout () |
| 121 | { |
| 122 | if (m_struct_laid_out) |
| 123 | return true; |
| 124 | |
| 125 | StructMemberIterator iter; |
| 126 | |
| 127 | off_t cursor = 0; |
| 128 | |
| 129 | m_struct_alignment = 0; |
| 130 | m_struct_size = 0; |
| 131 | |
| 132 | for (iter = m_members.begin(); |
| 133 | iter != m_members.end(); |
| 134 | ++iter) |
| 135 | { |
| 136 | if (iter == m_members.begin()) |
| 137 | m_struct_alignment = iter->m_alignment; |
| 138 | |
| 139 | if (cursor % iter->m_alignment) |
| 140 | cursor += (iter->m_alignment - (cursor % iter->m_alignment)); |
| 141 | |
| 142 | iter->m_offset = cursor; |
| 143 | cursor += iter->m_size; |
| 144 | } |
| 145 | |
| 146 | m_struct_size = cursor; |
| 147 | |
| 148 | m_struct_laid_out = true; |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | bool ClangExpressionDeclMap::GetStructInfo (uint32_t &num_elements, |
| 153 | size_t &size, |
| 154 | off_t &alignment) |
| 155 | { |
| 156 | if (!m_struct_laid_out) |
| 157 | return false; |
| 158 | |
| 159 | num_elements = m_members.size(); |
| 160 | size = m_struct_size; |
| 161 | alignment = m_struct_alignment; |
| 162 | |
| 163 | return true; |
| 164 | } |
| 165 | |
| 166 | bool |
| 167 | ClangExpressionDeclMap::GetStructElement (const clang::NamedDecl *&decl, |
| 168 | llvm::Value *&value, |
| 169 | off_t &offset, |
| 170 | uint32_t index) |
| 171 | { |
| 172 | if (!m_struct_laid_out) |
| 173 | return false; |
| 174 | |
| 175 | if (index >= m_members.size()) |
| 176 | return false; |
| 177 | |
| 178 | decl = m_members[index].m_decl; |
| 179 | value = m_members[index].m_value; |
| 180 | offset = m_members[index].m_offset; |
| 181 | |
| 182 | return true; |
| 183 | } |
| 184 | |
Sean Callanan | 02fbafa | 2010-07-27 21:39:39 +0000 | [diff] [blame^] | 185 | bool |
| 186 | ClangExpressionDeclMap::GetFunctionInfo (const clang::NamedDecl *decl, |
| 187 | llvm::Value**& value, |
| 188 | uint64_t &ptr) |
Sean Callanan | ba992c5 | 2010-07-27 02:07:53 +0000 | [diff] [blame] | 189 | { |
| 190 | TupleIterator iter; |
| 191 | |
| 192 | for (iter = m_tuples.begin(); |
| 193 | iter != m_tuples.end(); |
| 194 | ++iter) |
| 195 | { |
| 196 | if (decl == iter->m_decl) |
| 197 | { |
Sean Callanan | 02fbafa | 2010-07-27 21:39:39 +0000 | [diff] [blame^] | 198 | value = &iter->m_llvm_value; |
| 199 | ptr = iter->m_value->GetScalar().ULongLong(); |
| 200 | return true; |
Sean Callanan | ba992c5 | 2010-07-27 02:07:53 +0000 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
Sean Callanan | 02fbafa | 2010-07-27 21:39:39 +0000 | [diff] [blame^] | 204 | return false; |
Sean Callanan | ba992c5 | 2010-07-27 02:07:53 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | // Interface for DwarfExpression |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 208 | lldb_private::Value |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | *ClangExpressionDeclMap::GetValueForIndex (uint32_t index) |
| 210 | { |
| 211 | if (index >= m_tuples.size ()) |
| 212 | return NULL; |
| 213 | |
| 214 | return m_tuples[index].m_value; |
| 215 | } |
| 216 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 217 | // Interface for CommandObjectExpression |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 218 | |
| 219 | bool |
| 220 | ClangExpressionDeclMap::Materialize (ExecutionContext *exe_ctx, |
| 221 | lldb::addr_t &struct_address, |
| 222 | Error &err) |
| 223 | { |
| 224 | bool result = DoMaterialize(false, exe_ctx, NULL, err); |
| 225 | |
| 226 | if (result) |
| 227 | struct_address = m_materialized_location; |
| 228 | |
| 229 | return result; |
| 230 | } |
| 231 | |
| 232 | bool |
| 233 | ClangExpressionDeclMap::Dematerialize (ExecutionContext *exe_ctx, |
| 234 | lldb_private::Value &result_value, |
| 235 | Error &err) |
| 236 | { |
| 237 | return DoMaterialize(true, exe_ctx, &result_value, err); |
| 238 | } |
| 239 | |
Sean Callanan | 32824aa | 2010-07-23 22:19:18 +0000 | [diff] [blame] | 240 | bool |
| 241 | ClangExpressionDeclMap::DumpMaterializedStruct(ExecutionContext *exe_ctx, |
| 242 | Stream &s, |
| 243 | Error &err) |
| 244 | { |
| 245 | if (!m_struct_laid_out) |
| 246 | { |
| 247 | err.SetErrorString("Structure hasn't been laid out yet"); |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | if (!exe_ctx) |
| 252 | { |
| 253 | err.SetErrorString("Received null execution context"); |
| 254 | return false; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | if (!exe_ctx->process) |
| 259 | { |
| 260 | err.SetErrorString("Couldn't find the process"); |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | if (!exe_ctx->target) |
| 265 | { |
| 266 | err.SetErrorString("Couldn't find the target"); |
| 267 | return false; |
| 268 | } |
| 269 | |
| 270 | lldb::DataBufferSP data(new DataBufferHeap(m_struct_size, 0)); |
| 271 | |
| 272 | Error error; |
| 273 | if (exe_ctx->process->ReadMemory (m_materialized_location, data->GetBytes(), data->GetByteSize(), error) != data->GetByteSize()) |
| 274 | { |
| 275 | err.SetErrorStringWithFormat ("Couldn't read struct from the target: %s", error.AsCString()); |
| 276 | return false; |
| 277 | } |
| 278 | |
| 279 | DataExtractor extractor(data, exe_ctx->process->GetByteOrder(), exe_ctx->target->GetArchitecture().GetAddressByteSize()); |
| 280 | |
| 281 | StructMemberIterator iter; |
| 282 | |
| 283 | for (iter = m_members.begin(); |
| 284 | iter != m_members.end(); |
| 285 | ++iter) |
| 286 | { |
| 287 | s.Printf("[%s]\n", iter->m_name.c_str()); |
| 288 | |
| 289 | extractor.Dump(&s, // stream |
| 290 | iter->m_offset, // offset |
| 291 | lldb::eFormatBytesWithASCII, // format |
| 292 | 1, // byte size of individual entries |
| 293 | iter->m_size, // number of entries |
| 294 | 16, // entries per line |
| 295 | m_materialized_location + iter->m_offset, // address to print |
| 296 | 0, // bit size (bitfields only; 0 means ignore) |
| 297 | 0); // bit alignment (bitfields only; 0 means ignore) |
| 298 | |
| 299 | s.PutChar('\n'); |
| 300 | } |
| 301 | |
| 302 | return true; |
| 303 | } |
| 304 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 305 | bool |
| 306 | ClangExpressionDeclMap::DoMaterialize (bool dematerialize, |
| 307 | ExecutionContext *exe_ctx, |
| 308 | lldb_private::Value *result_value, |
| 309 | Error &err) |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 310 | { |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 311 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 312 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 313 | if (!m_struct_laid_out) |
| 314 | { |
| 315 | err.SetErrorString("Structure hasn't been laid out yet"); |
| 316 | return LLDB_INVALID_ADDRESS; |
| 317 | } |
| 318 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 319 | if (!exe_ctx) |
| 320 | { |
| 321 | err.SetErrorString("Received null execution context"); |
| 322 | return LLDB_INVALID_ADDRESS; |
| 323 | } |
| 324 | |
Sean Callanan | 4583927 | 2010-07-24 01:37:44 +0000 | [diff] [blame] | 325 | if (!exe_ctx->frame) |
| 326 | { |
| 327 | err.SetErrorString("Received null execution frame"); |
| 328 | return LLDB_INVALID_ADDRESS; |
| 329 | } |
| 330 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 331 | const SymbolContext &sym_ctx(exe_ctx->frame->GetSymbolContext(lldb::eSymbolContextEverything)); |
| 332 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 333 | if (!dematerialize) |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 334 | { |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 335 | if (m_materialized_location) |
| 336 | { |
| 337 | exe_ctx->process->DeallocateMemory(m_materialized_location); |
| 338 | m_materialized_location = 0; |
| 339 | } |
| 340 | |
| 341 | lldb::addr_t mem = exe_ctx->process->AllocateMemory(m_struct_alignment + m_struct_size, |
| 342 | lldb::ePermissionsReadable | lldb::ePermissionsWritable, |
| 343 | err); |
| 344 | |
| 345 | if (mem == LLDB_INVALID_ADDRESS) |
| 346 | return false; |
| 347 | |
| 348 | m_allocated_area = mem; |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 351 | m_materialized_location = m_allocated_area; |
| 352 | |
| 353 | if (m_materialized_location % m_struct_alignment) |
| 354 | { |
| 355 | m_materialized_location += (m_struct_alignment - (m_materialized_location % m_struct_alignment)); |
| 356 | } |
| 357 | |
| 358 | StructMemberIterator iter; |
| 359 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 360 | for (iter = m_members.begin(); |
| 361 | iter != m_members.end(); |
| 362 | ++iter) |
| 363 | { |
| 364 | uint32_t tuple_index; |
| 365 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 366 | if (!GetIndexForDecl(tuple_index, iter->m_decl)) |
| 367 | { |
| 368 | if (iter->m_name.find("___clang_expr_result") == std::string::npos) |
| 369 | { |
| 370 | err.SetErrorStringWithFormat("Unexpected variable %s", iter->m_name.c_str()); |
| 371 | return false; |
| 372 | } |
| 373 | |
| 374 | if (log) |
| 375 | log->Printf("Found special result variable %s", iter->m_name.c_str()); |
| 376 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 377 | if (dematerialize) |
| 378 | { |
| 379 | clang::ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext()); |
| 380 | |
| 381 | if (!context) |
| 382 | { |
| 383 | err.SetErrorString("Couldn't find a scratch AST context to put the result type into"); |
| 384 | } |
| 385 | |
| 386 | TypeFromUser copied_type(ClangASTContext::CopyType(context, |
| 387 | iter->m_parser_type.GetASTContext(), |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 388 | iter->m_parser_type.GetOpaqueQualType()), |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 389 | context); |
| 390 | |
Sean Callanan | 841026f | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 391 | result_value->SetContext(Value::eContextTypeOpaqueClangQualType, copied_type.GetOpaqueQualType()); |
| 392 | |
| 393 | result_value->SetValueType(Value::eValueTypeLoadAddress); |
| 394 | result_value->GetScalar() = (uintptr_t)m_materialized_location + iter->m_offset; |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 397 | continue; |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 398 | } |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 399 | |
| 400 | Tuple &tuple(m_tuples[tuple_index]); |
| 401 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 402 | if (!DoMaterializeOneVariable(dematerialize, *exe_ctx, sym_ctx, iter->m_name.c_str(), tuple.m_user_type, m_materialized_location + iter->m_offset, err)) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 403 | return false; |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 406 | return true; |
| 407 | } |
| 408 | |
| 409 | bool |
| 410 | ClangExpressionDeclMap::DoMaterializeOneVariable(bool dematerialize, |
| 411 | ExecutionContext &exe_ctx, |
| 412 | const SymbolContext &sym_ctx, |
| 413 | const char *name, |
| 414 | TypeFromUser type, |
| 415 | lldb::addr_t addr, |
| 416 | Error &err) |
| 417 | { |
| 418 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 419 | |
| 420 | Variable *var = FindVariableInScope(sym_ctx, name, &type); |
| 421 | |
| 422 | if (!var) |
| 423 | { |
| 424 | err.SetErrorStringWithFormat("Couldn't find %s with appropriate type", name); |
| 425 | return false; |
| 426 | } |
| 427 | |
Sean Callanan | 841026f | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 428 | if (log) |
| 429 | log->Printf("%s %s with type %p", (dematerialize ? "Dematerializing" : "Materializing"), name, type.GetOpaqueQualType()); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 430 | |
| 431 | std::auto_ptr<lldb_private::Value> location_value(GetVariableValue(exe_ctx, |
| 432 | var, |
| 433 | type.GetASTContext())); |
| 434 | |
| 435 | if (!location_value.get()) |
| 436 | { |
| 437 | err.SetErrorStringWithFormat("Couldn't get value for %s", name); |
| 438 | return false; |
| 439 | } |
| 440 | |
| 441 | if (location_value->GetValueType() == Value::eValueTypeLoadAddress) |
| 442 | { |
| 443 | lldb::addr_t value_addr = location_value->GetScalar().ULongLong(); |
| 444 | |
Sean Callanan | 841026f | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 445 | size_t bit_size = ClangASTContext::GetTypeBitSize(type.GetASTContext(), type.GetOpaqueQualType()); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 446 | size_t byte_size = bit_size % 8 ? ((bit_size + 8) / 8) : (bit_size / 8); |
| 447 | |
| 448 | DataBufferHeap data; |
| 449 | data.SetByteSize(byte_size); |
| 450 | |
| 451 | lldb::addr_t src_addr; |
| 452 | lldb::addr_t dest_addr; |
| 453 | |
| 454 | if (dematerialize) |
| 455 | { |
| 456 | src_addr = addr; |
| 457 | dest_addr = value_addr; |
| 458 | } |
| 459 | else |
| 460 | { |
| 461 | src_addr = value_addr; |
| 462 | dest_addr = addr; |
| 463 | } |
| 464 | |
| 465 | Error error; |
| 466 | if (exe_ctx.process->ReadMemory (src_addr, data.GetBytes(), byte_size, error) != byte_size) |
| 467 | { |
| 468 | err.SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString()); |
| 469 | return false; |
| 470 | } |
| 471 | |
| 472 | if (exe_ctx.process->WriteMemory (dest_addr, data.GetBytes(), byte_size, error) != byte_size) |
| 473 | { |
| 474 | err.SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString()); |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | if (log) |
| 479 | log->Printf("Copied from 0x%llx to 0x%llx", (uint64_t)src_addr, (uint64_t)addr); |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | StreamString ss; |
| 484 | |
| 485 | location_value->Dump(&ss); |
| 486 | |
| 487 | err.SetErrorStringWithFormat("%s has a value of unhandled type: %s", name, ss.GetString().c_str()); |
| 488 | } |
| 489 | |
| 490 | return true; |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 493 | Variable* |
| 494 | ClangExpressionDeclMap::FindVariableInScope(const SymbolContext &sym_ctx, |
| 495 | const char *name, |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 496 | TypeFromUser *type) |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 497 | { |
| 498 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 499 | |
| 500 | Function *function(m_sym_ctx->function); |
| 501 | Block *block(m_sym_ctx->block); |
| 502 | |
| 503 | if (!function || !block) |
| 504 | { |
| 505 | if (log) |
| 506 | log->Printf("function = %p, block = %p", function, block); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 507 | return NULL; |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | BlockList& blocks(function->GetBlocks(true)); |
| 511 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 512 | ConstString name_cs(name); |
| 513 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 514 | lldb::user_id_t current_block_id; |
| 515 | |
| 516 | for (current_block_id = block->GetID(); |
| 517 | current_block_id != Block::InvalidID; |
| 518 | current_block_id = blocks.GetParent(current_block_id)) |
| 519 | { |
| 520 | Block *current_block(blocks.GetBlockByID(current_block_id)); |
| 521 | |
| 522 | lldb::VariableListSP var_list = current_block->GetVariableList(false, true); |
| 523 | |
| 524 | if (!var_list) |
| 525 | continue; |
| 526 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 527 | lldb::VariableSP var = var_list->FindVariable(name_cs); |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 528 | |
| 529 | if (!var) |
| 530 | continue; |
| 531 | |
| 532 | // var->GetType()->GetClangAST() is the program's AST context and holds |
| 533 | // var->GetType()->GetOpaqueClangQualType(). |
| 534 | |
| 535 | // type is m_type for one of the struct members, which was added by |
| 536 | // AddValueToStruct. That type was extracted from the AST context of |
| 537 | // the compiler in IRForTarget. The original for the type was copied |
| 538 | // out of the program's AST context by AddOneVariable. |
| 539 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 540 | // So that we can compare these two without having to copy back |
| 541 | // something we already had in the original AST context, we maintain |
| 542 | // m_orig_type and m_ast_context (which are passed into |
| 543 | // MaterializeOneVariable by Materialize) for each variable. |
| 544 | |
| 545 | if (!type) |
| 546 | return var.get(); |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 547 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 548 | if (type->GetASTContext() == var->GetType()->GetClangAST()) |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 549 | { |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 550 | if (!ClangASTContext::AreTypesSame(type->GetASTContext(), type, var->GetType()->GetOpaqueClangQualType())) |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 551 | continue; |
| 552 | } |
| 553 | else |
| 554 | { |
| 555 | if (log) |
| 556 | log->PutCString("Skipping a candidate variable because of different AST contexts"); |
| 557 | continue; |
| 558 | } |
| 559 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 560 | return var.get(); |
| 561 | } |
| 562 | |
| 563 | { |
| 564 | CompileUnit *compile_unit = m_sym_ctx->comp_unit; |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 565 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 566 | if (!compile_unit) |
| 567 | { |
| 568 | if (log) |
| 569 | log->Printf("compile_unit = %p", compile_unit); |
| 570 | return NULL; |
| 571 | } |
| 572 | |
| 573 | lldb::VariableListSP var_list = compile_unit->GetVariableList(true); |
| 574 | |
| 575 | if (!var_list) |
| 576 | return NULL; |
| 577 | |
| 578 | lldb::VariableSP var = var_list->FindVariable(name_cs); |
| 579 | |
| 580 | if (!var) |
| 581 | return NULL; |
| 582 | |
| 583 | if (!type) |
| 584 | return var.get(); |
| 585 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 586 | if (type->GetASTContext() == var->GetType()->GetClangAST()) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 587 | { |
Sean Callanan | 841026f | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 588 | if (!ClangASTContext::AreTypesSame(type->GetASTContext(), type->GetOpaqueQualType(), var->GetType()->GetOpaqueClangQualType())) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 589 | return NULL; |
| 590 | } |
| 591 | else |
| 592 | { |
| 593 | if (log) |
| 594 | log->PutCString("Skipping a candidate variable because of different AST contexts"); |
| 595 | return NULL; |
| 596 | } |
| 597 | |
| 598 | return var.get(); |
| 599 | } |
| 600 | |
| 601 | return NULL; |
| 602 | } |
| 603 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 604 | // Interface for ClangASTSource |
| 605 | void |
| 606 | ClangExpressionDeclMap::GetDecls(NameSearchContext &context, |
| 607 | const char *name) |
| 608 | { |
Sean Callanan | 6184dfe | 2010-06-23 00:47:48 +0000 | [diff] [blame] | 609 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 610 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 611 | if (log) |
| 612 | log->Printf("Hunting for a definition for %s", name); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 613 | |
| 614 | // Back out in all cases where we're not fully initialized |
| 615 | if (!m_exe_ctx || !m_exe_ctx->frame || !m_sym_ctx) |
| 616 | return; |
| 617 | |
| 618 | Function *function = m_sym_ctx->function; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 619 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 620 | if (!function) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 621 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 622 | if (log) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 623 | log->Printf("Can't evaluate an expression when not in a function"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 624 | return; |
| 625 | } |
| 626 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 627 | ConstString name_cs(name); |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 628 | SymbolContextList sym_ctxs; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 629 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 630 | m_sym_ctx->FindFunctionsByName(name_cs, false, sym_ctxs); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 631 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 632 | for (uint32_t index = 0, num_indices = sym_ctxs.GetSize(); |
| 633 | index < num_indices; |
| 634 | ++index) |
| 635 | { |
| 636 | SymbolContext sym_ctx; |
| 637 | sym_ctxs.GetContextAtIndex(index, sym_ctx); |
| 638 | |
| 639 | if (sym_ctx.function) |
| 640 | AddOneFunction(context, sym_ctx.function, NULL); |
| 641 | else if(sym_ctx.symbol) |
| 642 | AddOneFunction(context, NULL, sym_ctx.symbol); |
| 643 | } |
| 644 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 645 | Variable *var = FindVariableInScope(*m_sym_ctx, name); |
| 646 | |
| 647 | if (var) |
| 648 | AddOneVariable(context, var); |
| 649 | } |
| 650 | |
| 651 | Value * |
| 652 | ClangExpressionDeclMap::GetVariableValue(ExecutionContext &exe_ctx, |
| 653 | Variable *var, |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 654 | clang::ASTContext *parser_ast_context, |
| 655 | TypeFromUser *user_type, |
| 656 | TypeFromParser *parser_type) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 657 | { |
Sean Callanan | 6184dfe | 2010-06-23 00:47:48 +0000 | [diff] [blame] | 658 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 659 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 660 | Type *var_type = var->GetType(); |
| 661 | |
| 662 | if (!var_type) |
| 663 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 664 | if (log) |
| 665 | log->PutCString("Skipped a definition because it has no type"); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 666 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | void *var_opaque_type = var_type->GetOpaqueClangQualType(); |
| 670 | |
| 671 | if (!var_opaque_type) |
| 672 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 673 | if (log) |
| 674 | log->PutCString("Skipped a definition because it has no Clang type"); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 675 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 678 | TypeList *type_list = var_type->GetTypeList(); |
| 679 | |
| 680 | if (!type_list) |
| 681 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 682 | if (log) |
| 683 | 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] | 684 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | clang::ASTContext *exe_ast_ctx = type_list->GetClangASTContext().getASTContext(); |
| 688 | |
| 689 | if (!exe_ast_ctx) |
| 690 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 691 | if (log) |
| 692 | log->PutCString("There is no AST context for the current execution context"); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 693 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 696 | DWARFExpression &var_location_expr = var->LocationExpression(); |
| 697 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 698 | std::auto_ptr<Value> var_location(new Value); |
| 699 | |
| 700 | Error err; |
| 701 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 702 | if (!var_location_expr.Evaluate(&exe_ctx, exe_ast_ctx, NULL, *var_location.get(), &err)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 703 | { |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 704 | if (log) |
| 705 | log->Printf("Error evaluating location: %s", err.AsCString()); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 706 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 709 | clang::ASTContext *var_ast_context = type_list->GetClangASTContext().getASTContext(); |
| 710 | |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 711 | void *type_to_use; |
| 712 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 713 | if (parser_ast_context) |
| 714 | { |
| 715 | type_to_use = ClangASTContext::CopyType(parser_ast_context, var_ast_context, var_opaque_type); |
| 716 | |
| 717 | if (parser_type) |
| 718 | *parser_type = TypeFromParser(type_to_use, parser_ast_context); |
| 719 | } |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 720 | else |
| 721 | type_to_use = var_opaque_type; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 722 | |
| 723 | if (var_location.get()->GetContextType() == Value::eContextTypeInvalid) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 724 | var_location.get()->SetContext(Value::eContextTypeOpaqueClangQualType, type_to_use); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | |
| 726 | if (var_location.get()->GetValueType() == Value::eValueTypeFileAddress) |
| 727 | { |
| 728 | SymbolContext var_sc; |
| 729 | var->CalculateSymbolContext(&var_sc); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 730 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 731 | if (!var_sc.module_sp) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 732 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 733 | |
| 734 | ObjectFile *object_file = var_sc.module_sp->GetObjectFile(); |
| 735 | |
| 736 | if (!object_file) |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 737 | return NULL; |
| 738 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 739 | Address so_addr(var_location->GetScalar().ULongLong(), object_file->GetSectionList()); |
| 740 | |
| 741 | lldb::addr_t load_addr = so_addr.GetLoadAddress(m_exe_ctx->process); |
| 742 | |
| 743 | var_location->GetScalar() = load_addr; |
| 744 | var_location->SetValueType(Value::eValueTypeLoadAddress); |
| 745 | } |
| 746 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 747 | if (user_type) |
| 748 | *user_type = TypeFromUser(var_opaque_type, var_ast_context); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 749 | |
| 750 | return var_location.release(); |
| 751 | } |
| 752 | |
| 753 | void |
| 754 | ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context, |
| 755 | Variable* var) |
| 756 | { |
| 757 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 758 | |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 759 | TypeFromUser ut; |
| 760 | TypeFromParser pt; |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 761 | |
| 762 | Value *var_location = GetVariableValue(*m_exe_ctx, |
| 763 | var, |
| 764 | context.GetASTContext(), |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 765 | &ut, |
| 766 | &pt); |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 767 | |
Greg Clayton | 1674b12 | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 768 | NamedDecl *var_decl = context.AddVarDecl(pt.GetOpaqueQualType()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 769 | |
| 770 | Tuple tuple; |
| 771 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 772 | tuple.m_decl = var_decl; |
Sean Callanan | 336a000 | 2010-07-17 00:43:37 +0000 | [diff] [blame] | 773 | tuple.m_value = var_location; |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 774 | tuple.m_user_type = ut; |
| 775 | tuple.m_parser_type = pt; |
Sean Callanan | 02fbafa | 2010-07-27 21:39:39 +0000 | [diff] [blame^] | 776 | tuple.m_llvm_value = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 777 | |
| 778 | m_tuples.push_back(tuple); |
| 779 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 780 | if (log) |
| 781 | log->PutCString("Found variable"); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | void |
| 785 | ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context, |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 786 | Function* fun, |
| 787 | Symbol* symbol) |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 788 | { |
Sean Callanan | 6184dfe | 2010-06-23 00:47:48 +0000 | [diff] [blame] | 789 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 790 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 791 | NamedDecl *fun_decl; |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 792 | std::auto_ptr<Value> fun_location(new Value); |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 793 | const Address *fun_address; |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 794 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 795 | // only valid for Functions, not for Symbols |
| 796 | void *fun_opaque_type = NULL; |
| 797 | clang::ASTContext *fun_ast_context = NULL; |
| 798 | |
| 799 | if (fun) |
| 800 | { |
| 801 | Type *fun_type = fun->GetType(); |
| 802 | |
| 803 | if (!fun_type) |
| 804 | { |
| 805 | if (log) |
| 806 | log->PutCString("Skipped a function because it has no type"); |
| 807 | return; |
| 808 | } |
| 809 | |
| 810 | fun_opaque_type = fun_type->GetOpaqueClangQualType(); |
| 811 | |
| 812 | if (!fun_opaque_type) |
| 813 | { |
| 814 | if (log) |
| 815 | log->PutCString("Skipped a function because it has no Clang type"); |
| 816 | return; |
| 817 | } |
| 818 | |
| 819 | fun_address = &fun->GetAddressRange().GetBaseAddress(); |
| 820 | |
| 821 | TypeList *type_list = fun_type->GetTypeList(); |
| 822 | fun_ast_context = type_list->GetClangASTContext().getASTContext(); |
| 823 | void *copied_type = ClangASTContext::CopyType(context.GetASTContext(), fun_ast_context, fun_opaque_type); |
| 824 | |
| 825 | fun_decl = context.AddFunDecl(copied_type); |
| 826 | } |
| 827 | else if (symbol) |
| 828 | { |
| 829 | fun_address = &symbol->GetAddressRangeRef().GetBaseAddress(); |
| 830 | |
| 831 | fun_decl = context.AddGenericFunDecl(); |
| 832 | } |
| 833 | else |
| 834 | { |
| 835 | if (log) |
| 836 | log->PutCString("AddOneFunction called with no function and no symbol"); |
| 837 | return; |
| 838 | } |
| 839 | |
| 840 | lldb::addr_t load_addr = fun_address->GetLoadAddress(m_exe_ctx->process); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 841 | fun_location->SetValueType(Value::eValueTypeLoadAddress); |
| 842 | fun_location->GetScalar() = load_addr; |
| 843 | |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 844 | Tuple tuple; |
| 845 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 846 | tuple.m_decl = fun_decl; |
| 847 | tuple.m_value = fun_location.release(); |
Sean Callanan | f328c9f | 2010-07-20 23:31:16 +0000 | [diff] [blame] | 848 | tuple.m_user_type = TypeFromUser(fun_opaque_type, fun_ast_context); |
Sean Callanan | 02fbafa | 2010-07-27 21:39:39 +0000 | [diff] [blame^] | 849 | tuple.m_llvm_value = NULL; |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 850 | |
| 851 | m_tuples.push_back(tuple); |
| 852 | |
Sean Callanan | 810f22d | 2010-07-16 00:09:46 +0000 | [diff] [blame] | 853 | if (log) |
| 854 | log->PutCString("Found function"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 855 | } |