Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ClangExpressionVariable.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/ClangExpressionVariable.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "clang/AST/ASTContext.h" |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 17 | #include "lldb/Core/ConstString.h" |
| 18 | #include "lldb/Core/DataExtractor.h" |
| 19 | #include "lldb/Core/Stream.h" |
| 20 | #include "lldb/Core/Value.h" |
Sean Callanan | e8a59a8 | 2010-09-13 21:34:21 +0000 | [diff] [blame] | 21 | #include "lldb/Target/ExecutionContext.h" |
| 22 | #include "lldb/Target/Process.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace lldb_private; |
| 25 | using namespace clang; |
| 26 | |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 27 | ClangExpressionVariable::ClangExpressionVariable() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | { |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 29 | m_name = ""; |
| 30 | m_user_type = TypeFromUser(NULL, NULL); |
| 31 | m_parser_vars.reset(NULL); |
| 32 | m_jit_vars.reset(NULL); |
| 33 | m_data_vars.reset(NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 36 | void ClangExpressionVariable::DisableDataVars() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | { |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 38 | if (m_data_vars.get() && m_data_vars->m_data) |
| 39 | delete m_data_vars->m_data; |
| 40 | m_data_vars.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 43 | Error |
| 44 | ClangExpressionVariable::Print (Stream &output_stream, |
| 45 | ExecutionContext &exe_ctx, |
| 46 | lldb::Format format, |
| 47 | bool show_types, |
| 48 | bool show_summary, |
| 49 | bool verbose) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | { |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 51 | Error err; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 53 | Value val; |
Sean Callanan | 4a19f58 | 2010-10-01 02:06:46 +0000 | [diff] [blame] | 54 | if (!PointValueAtData (val, NULL)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | { |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 56 | err.SetErrorToGenericError(); |
| 57 | err.SetErrorStringWithFormat("Variable doesn't contain a value"); |
| 58 | return err; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 61 | if (val.GetContextType () == Value::eContextTypeInvalid && |
| 62 | val.GetValueType () == Value::eValueTypeScalar && |
| 63 | format == lldb::eFormatDefault) |
| 64 | { |
| 65 | // The expression result is just a scalar with no special formatting |
| 66 | val.GetScalar ().GetValue (&output_stream, show_types); |
| 67 | output_stream.EOL (); |
| 68 | return err; |
| 69 | } |
| 70 | |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 71 | clang::ASTContext *ast_context = m_user_type.GetASTContext(); |
| 72 | |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 73 | // The expression result is more complex and requires special handling |
| 74 | DataExtractor data; |
| 75 | Error expr_error = val.GetValueAsData (&exe_ctx, ast_context, data, 0); |
| 76 | |
Sean Callanan | e8a59a8 | 2010-09-13 21:34:21 +0000 | [diff] [blame] | 77 | |
| 78 | // Set byte order and pointer size to TARGET byte order and pointer size! |
| 79 | |
| 80 | data.SetByteOrder(exe_ctx.process->GetByteOrder()); |
| 81 | data.SetAddressByteSize(exe_ctx.process->GetAddressByteSize()); |
| 82 | |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 83 | if (!expr_error.Success ()) |
| 84 | { |
| 85 | err.SetErrorToGenericError (); |
| 86 | err.SetErrorStringWithFormat ("Couldn't resolve variable value: %s", expr_error.AsCString ()); |
| 87 | return err; |
| 88 | } |
| 89 | |
| 90 | if (format == lldb::eFormatDefault) |
| 91 | format = val.GetValueDefaultFormat (); |
| 92 | |
Greg Clayton | 462d414 | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 93 | void *clang_type = val.GetClangType (); |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 94 | |
| 95 | output_stream.Printf("%s = ", m_name.c_str()); |
| 96 | |
| 97 | if (clang_type) |
| 98 | { |
| 99 | if (show_types) |
| 100 | output_stream.Printf("(%s) ", ClangASTType::GetClangTypeName (clang_type).GetCString()); |
| 101 | |
| 102 | ClangASTType::DumpValue (ast_context, // The ASTContext that the clang type belongs to |
| 103 | clang_type, // The opaque clang type we want to dump that value of |
| 104 | &exe_ctx, // The execution context for memory and variable access |
| 105 | &output_stream, // Stream to dump to |
| 106 | format, // Format to use when dumping |
| 107 | data, // A buffer containing the bytes for the clang type |
| 108 | 0, // Byte offset within "data" where value is |
| 109 | data.GetByteSize (), // Size in bytes of the value we are dumping |
| 110 | 0, // Bitfield bit size |
| 111 | 0, // Bitfield bit offset |
| 112 | show_types, // Show types? |
| 113 | show_summary, // Show summary? |
| 114 | verbose, // Debug logging output? |
| 115 | UINT32_MAX); // Depth to dump in case this is an aggregate type |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | data.Dump (&output_stream, // Stream to dump to |
| 120 | 0, // Byte offset within "data" |
| 121 | format, // Format to use when dumping |
| 122 | data.GetByteSize (), // Size in bytes of each item we are dumping |
| 123 | 1, // Number of items to dump |
| 124 | UINT32_MAX, // Number of items per line |
| 125 | LLDB_INVALID_ADDRESS, // Invalid address, don't show any offset/address context |
| 126 | 0, // Bitfield bit size |
| 127 | 0); // Bitfield bit offset |
| 128 | } |
| 129 | |
| 130 | output_stream.EOL(); |
| 131 | |
| 132 | return err; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 135 | ClangExpressionVariable::ClangExpressionVariable(const ClangExpressionVariable &cev) : |
| 136 | m_name(cev.m_name), |
Sean Callanan | 8194e42 | 2010-08-30 21:15:33 +0000 | [diff] [blame] | 137 | m_user_type(cev.m_user_type), |
| 138 | m_store(cev.m_store), |
| 139 | m_index(cev.m_index) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | { |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 141 | if (cev.m_parser_vars.get()) |
| 142 | { |
| 143 | m_parser_vars.reset(new struct ParserVars); |
| 144 | *m_parser_vars.get() = *cev.m_parser_vars.get(); |
| 145 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 147 | if (cev.m_jit_vars.get()) |
| 148 | { |
| 149 | m_jit_vars.reset(new struct JITVars); |
| 150 | *m_jit_vars.get() = *cev.m_jit_vars.get(); |
| 151 | } |
| 152 | |
| 153 | if (cev.m_data_vars.get()) |
| 154 | { |
| 155 | m_data_vars.reset(new struct DataVars); |
| 156 | *m_data_vars.get() = *cev.m_data_vars.get(); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | bool |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 161 | ClangExpressionVariable::PointValueAtData(Value &value, ExecutionContext *exe_ctx) |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 162 | { |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 163 | if (!m_data_vars.get() || !m_data_vars->m_data) |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 164 | return false; |
| 165 | |
| 166 | value.SetContext(Value::eContextTypeOpaqueClangQualType, m_user_type.GetOpaqueQualType()); |
| 167 | value.SetValueType(Value::eValueTypeHostAddress); |
| 168 | value.GetScalar() = (uint64_t)m_data_vars->m_data->GetBytes(); |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 169 | clang::ASTContext *ast_context = m_user_type.GetASTContext(); |
| 170 | |
| 171 | if (exe_ctx) |
| 172 | value.ResolveValue (exe_ctx, ast_context); |
Sean Callanan | a622343 | 2010-08-20 01:02:30 +0000 | [diff] [blame] | 173 | |
| 174 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 175 | } |