Sean Callanan | e33724f | 2015-09-03 00:35:46 +0000 | [diff] [blame] | 1 | //===-- ExpressionVariable.cpp ----------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Sean Callanan | e33724f | 2015-09-03 00:35:46 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/Expression/ExpressionVariable.h" |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 10 | #include "lldb/Expression/IRExecutionUnit.h" |
Adrian Prantl | 03219f7 | 2018-04-30 23:59:17 +0000 | [diff] [blame] | 11 | #include "lldb/Target/Target.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 12 | #include "lldb/Utility/Log.h" |
Sean Callanan | e33724f | 2015-09-03 00:35:46 +0000 | [diff] [blame] | 13 | |
Sean Callanan | bc8ac34 | 2015-09-04 20:49:51 +0000 | [diff] [blame] | 14 | using namespace lldb_private; |
| 15 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 16 | ExpressionVariable::~ExpressionVariable() {} |
Sean Callanan | bc8ac34 | 2015-09-04 20:49:51 +0000 | [diff] [blame] | 17 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | uint8_t *ExpressionVariable::GetValueBytes() { |
| 19 | const size_t byte_size = m_frozen_sp->GetByteSize(); |
| 20 | if (byte_size > 0) { |
| 21 | if (m_frozen_sp->GetDataExtractor().GetByteSize() < byte_size) { |
| 22 | m_frozen_sp->GetValue().ResizeData(byte_size); |
| 23 | m_frozen_sp->GetValue().GetData(m_frozen_sp->GetDataExtractor()); |
Sean Callanan | bc8ac34 | 2015-09-04 20:49:51 +0000 | [diff] [blame] | 24 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | return const_cast<uint8_t *>( |
| 26 | m_frozen_sp->GetDataExtractor().GetDataStart()); |
| 27 | } |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 28 | return nullptr; |
Sean Callanan | bc8ac34 | 2015-09-04 20:49:51 +0000 | [diff] [blame] | 29 | } |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 30 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | PersistentExpressionState::~PersistentExpressionState() {} |
| 32 | |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 33 | lldb::addr_t PersistentExpressionState::LookupSymbol(ConstString name) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | SymbolMap::iterator si = m_symbol_map.find(name.GetCString()); |
| 35 | |
| 36 | if (si != m_symbol_map.end()) |
| 37 | return si->second; |
| 38 | else |
| 39 | return LLDB_INVALID_ADDRESS; |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 40 | } |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | void PersistentExpressionState::RegisterExecutionUnit( |
| 43 | lldb::IRExecutionUnitSP &execution_unit_sp) { |
| 44 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 45 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | m_execution_units.insert(execution_unit_sp); |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 47 | |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 48 | LLDB_LOGF(log, "Registering JITted Functions:\n"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | |
| 50 | for (const IRExecutionUnit::JittedFunction &jitted_function : |
| 51 | execution_unit_sp->GetJittedFunctions()) { |
| 52 | if (jitted_function.m_external && |
| 53 | jitted_function.m_name != execution_unit_sp->GetFunctionName() && |
| 54 | jitted_function.m_remote_addr != LLDB_INVALID_ADDRESS) { |
| 55 | m_symbol_map[jitted_function.m_name.GetCString()] = |
| 56 | jitted_function.m_remote_addr; |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 57 | LLDB_LOGF(log, " Function: %s at 0x%" PRIx64 ".", |
| 58 | jitted_function.m_name.GetCString(), |
| 59 | jitted_function.m_remote_addr); |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 60 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 63 | LLDB_LOGF(log, "Registering JIIted Symbols:\n"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | |
| 65 | for (const IRExecutionUnit::JittedGlobalVariable &global_var : |
| 66 | execution_unit_sp->GetJittedGlobalVariables()) { |
| 67 | if (global_var.m_remote_addr != LLDB_INVALID_ADDRESS) { |
| 68 | // Demangle the name before inserting it, so that lookups by the ConstStr |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 69 | // of the demangled name will find the mangled one (needed for looking up |
| 70 | // metadata pointers.) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 71 | Mangled mangler(global_var.m_name); |
| 72 | mangler.GetDemangledName(lldb::eLanguageTypeUnknown); |
| 73 | m_symbol_map[global_var.m_name.GetCString()] = global_var.m_remote_addr; |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 74 | LLDB_LOGF(log, " Symbol: %s at 0x%" PRIx64 ".", |
| 75 | global_var.m_name.GetCString(), global_var.m_remote_addr); |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 76 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | } |
Sean Callanan | bd4dc69 | 2016-03-21 22:23:38 +0000 | [diff] [blame] | 78 | } |
Adrian Prantl | 29db51d | 2019-08-27 22:50:40 +0000 | [diff] [blame] | 79 | |
| 80 | ConstString PersistentExpressionState::GetNextPersistentVariableName( |
| 81 | Target &target, llvm::StringRef Prefix) { |
| 82 | llvm::SmallString<64> name; |
| 83 | { |
| 84 | llvm::raw_svector_ostream os(name); |
| 85 | os << Prefix << target.GetNextPersistentVariableIndex(); |
| 86 | } |
| 87 | return ConstString(name); |
| 88 | } |