1 //===-- ExpressionVariable.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/Core/Log.h"
11 #include "lldb/Expression/ExpressionVariable.h"
12 #include "lldb/Expression/IRExecutionUnit.h"
13 
14 using namespace lldb_private;
15 
16 ExpressionVariable::~ExpressionVariable()
17 {
18 }
19 
20 uint8_t *
21 ExpressionVariable::GetValueBytes()
22 {
23     const size_t byte_size = m_frozen_sp->GetByteSize();
24     if (byte_size > 0)
25     {
26         if (m_frozen_sp->GetDataExtractor().GetByteSize() < byte_size)
27         {
28             m_frozen_sp->GetValue().ResizeData(byte_size);
29             m_frozen_sp->GetValue().GetData (m_frozen_sp->GetDataExtractor());
30         }
31         return const_cast<uint8_t *>(m_frozen_sp->GetDataExtractor().GetDataStart());
32     }
33     return NULL;
34 }
35 
36 PersistentExpressionState::~PersistentExpressionState ()
37 {
38 }
39 
40 lldb::addr_t
41 PersistentExpressionState::LookupSymbol (const ConstString &name)
42 {
43     SymbolMap::iterator si = m_symbol_map.find(name.GetCString());
44 
45     if (si != m_symbol_map.end())
46         return si->second;
47     else
48         return LLDB_INVALID_ADDRESS;
49 }
50 
51 
52 void
53 PersistentExpressionState::RegisterExecutionUnit (lldb::IRExecutionUnitSP &execution_unit_sp)
54 {
55     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
56 
57     m_execution_units.insert(execution_unit_sp);
58 
59     if (log)
60         log->Printf ("Registering JITted Functions:\n");
61 
62     for (const IRExecutionUnit::JittedFunction &jitted_function : execution_unit_sp->GetJittedFunctions())
63     {
64         if (jitted_function.m_external &&
65             jitted_function.m_name != execution_unit_sp->GetFunctionName() &&
66             jitted_function.m_remote_addr != LLDB_INVALID_ADDRESS)
67         {
68             m_symbol_map[jitted_function.m_name.GetCString()] = jitted_function.m_remote_addr;
69             if (log)
70                 log->Printf ("  Function: %s at 0x%" PRIx64 ".", jitted_function.m_name.GetCString(), jitted_function.m_remote_addr);
71         }
72     }
73 
74     if (log)
75         log->Printf ("Registering JIIted Symbols:\n");
76 
77     for (const IRExecutionUnit::JittedGlobalVariable &global_var : execution_unit_sp->GetJittedGlobalVariables())
78     {
79         if (global_var.m_remote_addr != LLDB_INVALID_ADDRESS)
80         {
81             // Demangle the name before inserting it, so that lookups by the ConstStr of the demangled name
82             // will find the mangled one (needed for looking up metadata pointers.)
83             Mangled mangler(global_var.m_name);
84             mangler.GetDemangledName(lldb::eLanguageTypeUnknown);
85             m_symbol_map[global_var.m_name.GetCString()] = global_var.m_remote_addr;
86             if (log)
87                 log->Printf ("  Symbol: %s at 0x%" PRIx64 ".", global_var.m_name.GetCString(), global_var.m_remote_addr);
88         }
89     }
90 }
91