Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBValue.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 | |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBValue.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBStream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 13 | #include "lldb/Breakpoint/Watchpoint.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Core/DataExtractor.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Module.h" |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Scalar.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Stream.h" |
| 19 | #include "lldb/Core/StreamFile.h" |
| 20 | #include "lldb/Core/Value.h" |
| 21 | #include "lldb/Core/ValueObject.h" |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 22 | #include "lldb/Core/ValueObjectConstResult.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/Block.h" |
| 24 | #include "lldb/Symbol/ObjectFile.h" |
| 25 | #include "lldb/Symbol/Variable.h" |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 26 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Target/ExecutionContext.h" |
| 28 | #include "lldb/Target/Process.h" |
| 29 | #include "lldb/Target/StackFrame.h" |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 30 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | #include "lldb/Target/Thread.h" |
| 32 | |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 33 | #include "lldb/API/SBProcess.h" |
| 34 | #include "lldb/API/SBTarget.h" |
| 35 | #include "lldb/API/SBThread.h" |
| 36 | #include "lldb/API/SBFrame.h" |
| 37 | #include "lldb/API/SBDebugger.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | |
| 39 | using namespace lldb; |
| 40 | using namespace lldb_private; |
| 41 | |
| 42 | SBValue::SBValue () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 43 | m_opaque_sp () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
| 47 | SBValue::SBValue (const lldb::ValueObjectSP &value_sp) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 48 | m_opaque_sp (value_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | { |
| 50 | } |
| 51 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 52 | SBValue::SBValue(const SBValue &rhs) : |
| 53 | m_opaque_sp (rhs.m_opaque_sp) |
| 54 | { |
| 55 | } |
| 56 | |
Greg Clayton | d68e089 | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 57 | SBValue & |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 58 | SBValue::operator = (const SBValue &rhs) |
| 59 | { |
| 60 | if (this != &rhs) |
| 61 | m_opaque_sp = rhs.m_opaque_sp; |
| 62 | return *this; |
| 63 | } |
| 64 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | SBValue::~SBValue() |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | bool |
Greg Clayton | d68e089 | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 70 | SBValue::IsValid () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 72 | // If this function ever changes to anything that does more than just |
| 73 | // check if the opaque shared pointer is non NULL, then we need to update |
| 74 | // all "if (m_opaque_sp)" code in this file. |
| 75 | return m_opaque_sp.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 78 | SBError |
| 79 | SBValue::GetError() |
| 80 | { |
| 81 | SBError sb_error; |
| 82 | |
| 83 | if (m_opaque_sp.get()) |
| 84 | sb_error.SetError(m_opaque_sp->GetError()); |
| 85 | |
| 86 | return sb_error; |
| 87 | } |
| 88 | |
Johnny Chen | 968958c | 2011-07-07 20:46:23 +0000 | [diff] [blame] | 89 | user_id_t |
| 90 | SBValue::GetID() |
| 91 | { |
| 92 | if (m_opaque_sp) |
| 93 | return m_opaque_sp->GetID(); |
| 94 | return LLDB_INVALID_UID; |
| 95 | } |
| 96 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | const char * |
| 98 | SBValue::GetName() |
| 99 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 100 | |
| 101 | const char *name = NULL; |
| 102 | if (m_opaque_sp) |
| 103 | name = m_opaque_sp->GetName().GetCString(); |
| 104 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 105 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 106 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 107 | { |
| 108 | if (name) |
| 109 | log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name); |
| 110 | else |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 111 | log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get()); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 112 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 113 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 114 | return name; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | const char * |
| 118 | SBValue::GetTypeName () |
| 119 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 120 | const char *name = NULL; |
| 121 | if (m_opaque_sp) |
| 122 | name = m_opaque_sp->GetTypeName().GetCString(); |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 123 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 124 | if (log) |
| 125 | { |
| 126 | if (name) |
| 127 | log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name); |
| 128 | else |
| 129 | log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get()); |
| 130 | } |
| 131 | |
| 132 | return name; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | size_t |
| 136 | SBValue::GetByteSize () |
| 137 | { |
| 138 | size_t result = 0; |
| 139 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 140 | if (m_opaque_sp) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 141 | result = m_opaque_sp->GetByteSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 143 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 144 | if (log) |
| 145 | log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result); |
| 146 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 147 | return result; |
| 148 | } |
| 149 | |
| 150 | bool |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 151 | SBValue::IsInScope () |
| 152 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 153 | bool result = false; |
| 154 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 155 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 156 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 157 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 158 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 159 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 160 | result = m_opaque_sp->IsInScope (); |
| 161 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 162 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 164 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 165 | if (log) |
| 166 | log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result); |
| 167 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 168 | return result; |
| 169 | } |
| 170 | |
| 171 | const char * |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 172 | SBValue::GetValue () |
| 173 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 174 | const char *cstr = NULL; |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 175 | if (m_opaque_sp) |
| 176 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 177 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 178 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 179 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 180 | cstr = m_opaque_sp->GetValueAsCString (); |
| 181 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 182 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 183 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 184 | if (log) |
| 185 | { |
| 186 | if (cstr) |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 187 | log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 188 | else |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 189 | log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get()); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | return cstr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 195 | ValueType |
| 196 | SBValue::GetValueType () |
| 197 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 198 | ValueType result = eValueTypeInvalid; |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 199 | if (m_opaque_sp) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 200 | result = m_opaque_sp->GetValueType(); |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 201 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 202 | if (log) |
| 203 | { |
| 204 | switch (result) |
| 205 | { |
| 206 | case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break; |
| 207 | case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break; |
| 208 | case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break; |
| 209 | case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break; |
| 210 | case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break; |
| 211 | case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break; |
| 212 | case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break; |
| 213 | case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break; |
| 214 | default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break; |
| 215 | } |
| 216 | } |
| 217 | return result; |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Jim Ingham | 4ae5196 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 220 | const char * |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 221 | SBValue::GetObjectDescription () |
| 222 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 223 | const char *cstr = NULL; |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 224 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 225 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 226 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 227 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 228 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 229 | cstr = m_opaque_sp->GetObjectDescription (); |
| 230 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 231 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 232 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 233 | if (log) |
| 234 | { |
| 235 | if (cstr) |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 236 | log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 237 | else |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 238 | log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get()); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 239 | } |
| 240 | return cstr; |
Jim Ingham | 4ae5196 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 243 | SBType |
| 244 | SBValue::GetType() |
| 245 | { |
| 246 | SBType result; |
| 247 | if (m_opaque_sp) |
| 248 | { |
| 249 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
| 250 | { |
| 251 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 252 | result = SBType(ClangASTType (m_opaque_sp->GetClangAST(), m_opaque_sp->GetClangType())); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 256 | if (log) |
| 257 | { |
| 258 | if (result.IsValid()) |
| 259 | log->Printf ("SBValue(%p)::GetType => %p", m_opaque_sp.get(), &result); |
| 260 | else |
| 261 | log->Printf ("SBValue(%p)::GetType => NULL", m_opaque_sp.get()); |
| 262 | } |
| 263 | return result; |
| 264 | } |
| 265 | |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 266 | bool |
| 267 | SBValue::GetValueDidChange () |
| 268 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 269 | bool result = false; |
| 270 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 271 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 272 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 273 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 274 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 275 | result = m_opaque_sp->GetValueDidChange (); |
| 276 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 277 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 278 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 279 | if (log) |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 280 | log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 281 | |
| 282 | return result; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | const char * |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 286 | SBValue::GetSummary () |
| 287 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 288 | const char *cstr = NULL; |
| 289 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 290 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 291 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 292 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 293 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 294 | cstr = m_opaque_sp->GetSummaryAsCString(); |
| 295 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 296 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 297 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 298 | if (log) |
| 299 | { |
| 300 | if (cstr) |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 301 | log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 302 | else |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 303 | log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get()); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 304 | } |
| 305 | return cstr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | const char * |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 309 | SBValue::GetLocation () |
| 310 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 311 | const char *cstr = NULL; |
| 312 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 313 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 314 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 315 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 316 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 317 | cstr = m_opaque_sp->GetLocationAsCString(); |
| 318 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 319 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 320 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 321 | if (log) |
| 322 | { |
| 323 | if (cstr) |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 324 | log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 325 | else |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 326 | log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get()); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 327 | } |
| 328 | return cstr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | bool |
Jim Ingham | fa3a16a | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 332 | SBValue::SetValueFromCString (const char *value_str) |
| 333 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 334 | bool success = false; |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 335 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 336 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 337 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 338 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 339 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 340 | success = m_opaque_sp->SetValueFromCString (value_str); |
| 341 | } |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 342 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | return success; |
| 344 | } |
| 345 | |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 346 | lldb::SBValue |
Greg Clayton | d68e089 | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 347 | SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 348 | { |
| 349 | lldb::SBValue result; |
| 350 | if (m_opaque_sp) |
| 351 | { |
| 352 | if (type.IsValid()) |
| 353 | { |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 354 | result = SBValue(m_opaque_sp->GetSyntheticChildAtOffset(offset, type.m_opaque_sp->GetClangASTType(), true)); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 355 | result.m_opaque_sp->SetName(ConstString(name)); |
| 356 | } |
| 357 | } |
| 358 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 359 | if (log) |
| 360 | { |
| 361 | if (result.IsValid()) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 362 | log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString()); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 363 | else |
| 364 | log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", m_opaque_sp.get()); |
| 365 | } |
| 366 | return result; |
| 367 | } |
| 368 | |
| 369 | lldb::SBValue |
Greg Clayton | d68e089 | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 370 | SBValue::Cast (SBType type) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 371 | { |
| 372 | return CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type); |
| 373 | } |
| 374 | |
| 375 | lldb::SBValue |
| 376 | SBValue::CreateValueFromExpression (const char *name, const char* expression) |
| 377 | { |
| 378 | lldb::SBValue result; |
| 379 | if (m_opaque_sp) |
| 380 | { |
| 381 | ValueObjectSP result_valobj_sp; |
Greg Clayton | d68e089 | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 382 | m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression, |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame^] | 383 | m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame(), |
Sean Callanan | a8428a4 | 2011-09-22 00:41:11 +0000 | [diff] [blame] | 384 | eExecutionPolicyOnlyWhenNeeded, |
Sean Callanan | 47dc457 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 385 | true, // unwind on error |
| 386 | true, // keep in memory |
| 387 | eNoDynamicValues, |
Greg Clayton | d68e089 | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 388 | result_valobj_sp); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 389 | result_valobj_sp->SetName(ConstString(name)); |
| 390 | result = SBValue(result_valobj_sp); |
| 391 | } |
| 392 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 393 | if (log) |
| 394 | { |
| 395 | if (result.IsValid()) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 396 | log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString()); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 397 | else |
| 398 | log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get()); |
| 399 | } |
| 400 | return result; |
| 401 | } |
| 402 | |
| 403 | lldb::SBValue |
Greg Clayton | d68e089 | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 404 | SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType type) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 405 | { |
| 406 | lldb::SBValue result; |
Johnny Chen | 943485c | 2011-12-15 01:55:36 +0000 | [diff] [blame] | 407 | if (m_opaque_sp && type.IsValid() && type.GetPointerType().IsValid()) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 408 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 409 | SBType real_type(type.GetPointerType()); |
| 410 | |
| 411 | lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); |
| 412 | |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame^] | 413 | ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(), |
Greg Clayton | d68e089 | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 414 | real_type.m_opaque_sp->GetASTContext(), |
| 415 | real_type.m_opaque_sp->GetOpaqueQualType(), |
| 416 | ConstString(name), |
| 417 | buffer, |
| 418 | lldb::endian::InlHostByteOrder(), |
| 419 | GetTarget().GetProcess().GetAddressByteSize())); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 420 | |
Enrico Granata | c931030 | 2011-08-04 17:07:02 +0000 | [diff] [blame] | 421 | ValueObjectSP result_valobj_sp; |
| 422 | |
| 423 | ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress); |
| 424 | if (ptr_result_valobj_sp) |
| 425 | { |
| 426 | Error err; |
| 427 | result_valobj_sp = ptr_result_valobj_sp->Dereference(err); |
| 428 | if (result_valobj_sp) |
| 429 | result_valobj_sp->SetName(ConstString(name)); |
| 430 | } |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 431 | result = SBValue(result_valobj_sp); |
| 432 | } |
| 433 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 434 | if (log) |
| 435 | { |
| 436 | if (result.IsValid()) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 437 | log->Printf ("SBValue(%p)::GetChildFromAddress => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString()); |
Johnny Chen | a713b86 | 2011-08-09 22:38:07 +0000 | [diff] [blame] | 438 | else |
| 439 | log->Printf ("SBValue(%p)::GetChildFromAddress => NULL", m_opaque_sp.get()); |
| 440 | } |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 441 | return result; |
| 442 | } |
| 443 | |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 444 | lldb::SBValue |
Greg Clayton | d68e089 | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 445 | SBValue::CreateValueFromData (const char* name, SBData data, SBType type) |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 446 | { |
| 447 | SBValue result; |
| 448 | |
| 449 | AddressType addr_of_children_priv = eAddressTypeLoad; |
| 450 | |
| 451 | if (m_opaque_sp) |
| 452 | { |
| 453 | ValueObjectSP valobj_sp; |
| 454 | valobj_sp = ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(), |
| 455 | type.m_opaque_sp->GetASTContext() , |
| 456 | type.m_opaque_sp->GetOpaqueQualType(), |
| 457 | ConstString(name), |
| 458 | *data.m_opaque_sp, |
| 459 | LLDB_INVALID_ADDRESS); |
| 460 | valobj_sp->SetAddressTypeOfChildren(addr_of_children_priv); |
| 461 | result = SBValue(valobj_sp); |
| 462 | } |
| 463 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 464 | if (log) |
| 465 | { |
| 466 | if (result.IsValid()) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 467 | log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString()); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 468 | else |
| 469 | log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get()); |
| 470 | } |
| 471 | return result; |
| 472 | } |
| 473 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 474 | SBValue |
| 475 | SBValue::GetChildAtIndex (uint32_t idx) |
| 476 | { |
Greg Clayton | 8f64c47 | 2011-07-15 19:31:49 +0000 | [diff] [blame] | 477 | const bool can_create_synthetic = false; |
| 478 | lldb::DynamicValueType use_dynamic = eNoDynamicValues; |
Johnny Chen | 446ccaa | 2011-06-29 21:19:39 +0000 | [diff] [blame] | 479 | if (m_opaque_sp) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 480 | use_dynamic = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue(); |
Greg Clayton | 8f64c47 | 2011-07-15 19:31:49 +0000 | [diff] [blame] | 481 | return GetChildAtIndex (idx, use_dynamic, can_create_synthetic); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | SBValue |
Greg Clayton | 8f64c47 | 2011-07-15 19:31:49 +0000 | [diff] [blame] | 485 | SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic) |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 486 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | lldb::ValueObjectSP child_sp; |
| 488 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 489 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 490 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 491 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 492 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 493 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | 8f64c47 | 2011-07-15 19:31:49 +0000 | [diff] [blame] | 494 | const bool can_create = true; |
| 495 | child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create); |
| 496 | if (can_create_synthetic && !child_sp) |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 497 | { |
Greg Clayton | 8f64c47 | 2011-07-15 19:31:49 +0000 | [diff] [blame] | 498 | if (m_opaque_sp->IsPointerType()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 499 | { |
Greg Clayton | 8f64c47 | 2011-07-15 19:31:49 +0000 | [diff] [blame] | 500 | child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create); |
| 501 | } |
| 502 | else if (m_opaque_sp->IsArrayType()) |
| 503 | { |
| 504 | child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | if (child_sp) |
| 509 | { |
| 510 | if (use_dynamic != lldb::eNoDynamicValues) |
| 511 | { |
| 512 | lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic)); |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 513 | if (dynamic_sp) |
| 514 | child_sp = dynamic_sp; |
| 515 | } |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 516 | } |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 520 | SBValue sb_value (child_sp); |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 521 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 522 | if (log) |
| 523 | log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get()); |
| 524 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 525 | return sb_value; |
| 526 | } |
| 527 | |
| 528 | uint32_t |
| 529 | SBValue::GetIndexOfChildWithName (const char *name) |
| 530 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 531 | uint32_t idx = UINT32_MAX; |
| 532 | if (m_opaque_sp) |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 533 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 534 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 535 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 536 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 537 | |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 538 | idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name)); |
| 539 | } |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 540 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 541 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 542 | if (log) |
| 543 | { |
| 544 | if (idx == UINT32_MAX) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 545 | log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 546 | else |
| 547 | log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx); |
| 548 | } |
| 549 | return idx; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | SBValue |
| 553 | SBValue::GetChildMemberWithName (const char *name) |
| 554 | { |
Johnny Chen | 446ccaa | 2011-06-29 21:19:39 +0000 | [diff] [blame] | 555 | if (m_opaque_sp) |
| 556 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 557 | lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue(); |
Johnny Chen | 446ccaa | 2011-06-29 21:19:39 +0000 | [diff] [blame] | 558 | return GetChildMemberWithName (name, use_dynamic_value); |
| 559 | } |
| 560 | else |
| 561 | return GetChildMemberWithName (name, eNoDynamicValues); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | SBValue |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 565 | SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value) |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 566 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 567 | lldb::ValueObjectSP child_sp; |
| 568 | const ConstString str_name (name); |
| 569 | |
Greg Clayton | 905acaf | 2011-05-20 22:07:17 +0000 | [diff] [blame] | 570 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 571 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 572 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 573 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 574 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 575 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 576 | child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true); |
| 577 | if (use_dynamic_value != lldb::eNoDynamicValues) |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 578 | { |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 579 | if (child_sp) |
| 580 | { |
| 581 | lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value); |
| 582 | if (dynamic_sp) |
| 583 | child_sp = dynamic_sp; |
| 584 | } |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 585 | } |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 589 | SBValue sb_value (child_sp); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 590 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 591 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 592 | if (log) |
| 593 | log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get()); |
| 594 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 595 | return sb_value; |
| 596 | } |
| 597 | |
Enrico Granata | f7a9b14 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 598 | lldb::SBValue |
Jim Ingham | 1b42575 | 2011-12-08 19:44:08 +0000 | [diff] [blame] | 599 | SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic) |
| 600 | { |
| 601 | if (m_opaque_sp) |
| 602 | { |
| 603 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
| 604 | { |
| 605 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
| 606 | return SBValue (m_opaque_sp->GetDynamicValue(use_dynamic)); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | return SBValue(); |
| 611 | } |
| 612 | |
| 613 | lldb::SBValue |
| 614 | SBValue::GetStaticValue () |
| 615 | { |
| 616 | if (m_opaque_sp) |
| 617 | { |
| 618 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
| 619 | { |
| 620 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
| 621 | return SBValue(m_opaque_sp->GetStaticValue()); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | return SBValue(); |
| 626 | } |
| 627 | |
| 628 | bool |
| 629 | SBValue::IsDynamic() |
| 630 | { |
| 631 | if (m_opaque_sp) |
| 632 | { |
| 633 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
| 634 | { |
| 635 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
| 636 | return m_opaque_sp->IsDynamic(); |
| 637 | } |
| 638 | } |
| 639 | return false; |
| 640 | } |
| 641 | |
| 642 | lldb::SBValue |
Enrico Granata | f7a9b14 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 643 | SBValue::GetValueForExpressionPath(const char* expr_path) |
| 644 | { |
| 645 | lldb::ValueObjectSP child_sp; |
| 646 | if (m_opaque_sp) |
| 647 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 648 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Enrico Granata | f7a9b14 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 649 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 650 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Enrico Granata | f7a9b14 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 651 | // using default values for all the fancy options, just do it if you can |
| 652 | child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | SBValue sb_value (child_sp); |
| 657 | |
| 658 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 659 | if (log) |
| 660 | log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get()); |
| 661 | |
| 662 | return sb_value; |
| 663 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 664 | |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 665 | int64_t |
Enrico Granata | c92eb40 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 666 | SBValue::GetValueAsSigned(SBError& error, int64_t fail_value) |
| 667 | { |
Jim Ingham | 574c3d6 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 668 | error.Clear(); |
Enrico Granata | c92eb40 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 669 | if (m_opaque_sp) |
| 670 | { |
| 671 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
| 672 | { |
| 673 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
| 674 | Scalar scalar; |
| 675 | if (m_opaque_sp->ResolveValue (scalar)) |
| 676 | return scalar.GetRawBits64(fail_value); |
| 677 | else |
| 678 | error.SetErrorString("could not get value"); |
| 679 | } |
| 680 | else |
| 681 | error.SetErrorString("could not get target"); |
| 682 | } |
| 683 | error.SetErrorString("invalid SBValue"); |
| 684 | return fail_value; |
| 685 | } |
| 686 | |
| 687 | uint64_t |
| 688 | SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value) |
| 689 | { |
Jim Ingham | 574c3d6 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 690 | error.Clear(); |
Enrico Granata | c92eb40 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 691 | if (m_opaque_sp) |
| 692 | { |
| 693 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
| 694 | { |
| 695 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
| 696 | Scalar scalar; |
| 697 | if (m_opaque_sp->ResolveValue (scalar)) |
| 698 | return scalar.GetRawBits64(fail_value); |
| 699 | else |
| 700 | error.SetErrorString("could not get value"); |
| 701 | } |
| 702 | else |
| 703 | error.SetErrorString("could not get target"); |
| 704 | } |
| 705 | error.SetErrorString("invalid SBValue"); |
| 706 | return fail_value; |
| 707 | } |
| 708 | |
| 709 | int64_t |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 710 | SBValue::GetValueAsSigned(int64_t fail_value) |
| 711 | { |
| 712 | if (m_opaque_sp) |
| 713 | { |
| 714 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
| 715 | { |
| 716 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
| 717 | Scalar scalar; |
| 718 | if (m_opaque_sp->ResolveValue (scalar)) |
| 719 | return scalar.GetRawBits64(fail_value); |
| 720 | } |
| 721 | } |
| 722 | return fail_value; |
| 723 | } |
| 724 | |
| 725 | uint64_t |
| 726 | SBValue::GetValueAsUnsigned(uint64_t fail_value) |
| 727 | { |
| 728 | if (m_opaque_sp) |
| 729 | { |
| 730 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
| 731 | { |
| 732 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
| 733 | Scalar scalar; |
| 734 | if (m_opaque_sp->ResolveValue (scalar)) |
| 735 | return scalar.GetRawBits64(fail_value); |
| 736 | } |
| 737 | } |
| 738 | return fail_value; |
| 739 | } |
| 740 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 741 | uint32_t |
| 742 | SBValue::GetNumChildren () |
| 743 | { |
| 744 | uint32_t num_children = 0; |
| 745 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 746 | if (m_opaque_sp) |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 747 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 748 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 749 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 750 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 751 | |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 752 | num_children = m_opaque_sp->GetNumChildren(); |
| 753 | } |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 754 | } |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 755 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 756 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 757 | if (log) |
| 758 | log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 759 | |
| 760 | return num_children; |
| 761 | } |
| 762 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | |
| 764 | SBValue |
| 765 | SBValue::Dereference () |
| 766 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 767 | SBValue sb_value; |
| 768 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 769 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 770 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 771 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 772 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 773 | |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 774 | Error error; |
| 775 | sb_value = m_opaque_sp->Dereference (error); |
| 776 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 777 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 778 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 779 | if (log) |
| 780 | log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get()); |
| 781 | |
| 782 | return sb_value; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | bool |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 786 | SBValue::TypeIsPointerType () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 787 | { |
| 788 | bool is_ptr_type = false; |
| 789 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 790 | if (m_opaque_sp) |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 791 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 792 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 793 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 794 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 795 | |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 796 | is_ptr_type = m_opaque_sp->IsPointerType(); |
| 797 | } |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 798 | } |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 799 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 800 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 801 | if (log) |
| 802 | log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type); |
| 803 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 804 | |
| 805 | return is_ptr_type; |
| 806 | } |
| 807 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 808 | void * |
| 809 | SBValue::GetOpaqueType() |
| 810 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 811 | if (m_opaque_sp) |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 812 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 813 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 814 | { |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 815 | Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 816 | |
Greg Clayton | b9dcc51 | 2011-06-29 18:28:50 +0000 | [diff] [blame] | 817 | return m_opaque_sp->GetClangType(); |
| 818 | } |
Greg Clayton | fab305b | 2011-05-20 23:51:26 +0000 | [diff] [blame] | 819 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 820 | return NULL; |
| 821 | } |
| 822 | |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 823 | lldb::SBTarget |
| 824 | SBValue::GetTarget() |
| 825 | { |
| 826 | SBTarget result; |
| 827 | if (m_opaque_sp) |
| 828 | { |
| 829 | if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) |
| 830 | { |
| 831 | result = SBTarget(lldb::TargetSP(m_opaque_sp->GetUpdatePoint().GetTargetSP())); |
| 832 | } |
| 833 | } |
| 834 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 835 | if (log) |
| 836 | { |
| 837 | if (result.get() == NULL) |
| 838 | log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get()); |
| 839 | else |
| 840 | log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), result.get()); |
| 841 | } |
| 842 | return result; |
| 843 | } |
| 844 | |
| 845 | lldb::SBProcess |
| 846 | SBValue::GetProcess() |
| 847 | { |
| 848 | SBProcess result; |
| 849 | if (m_opaque_sp) |
| 850 | { |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 851 | Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); |
| 852 | if (target) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 853 | { |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 854 | result = SBProcess(lldb::ProcessSP(target->GetProcessSP())); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 858 | if (log) |
| 859 | { |
| 860 | if (result.get() == NULL) |
| 861 | log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get()); |
| 862 | else |
| 863 | log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), result.get()); |
| 864 | } |
| 865 | return result; |
| 866 | } |
| 867 | |
| 868 | lldb::SBThread |
| 869 | SBValue::GetThread() |
| 870 | { |
| 871 | SBThread result; |
| 872 | if (m_opaque_sp) |
| 873 | { |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame^] | 874 | if (m_opaque_sp->GetExecutionContextScope()) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 875 | { |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame^] | 876 | result = SBThread(m_opaque_sp->GetExecutionContextScope()->CalculateThread()->GetSP()); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 880 | if (log) |
| 881 | { |
| 882 | if (result.get() == NULL) |
| 883 | log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get()); |
| 884 | else |
| 885 | log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), result.get()); |
| 886 | } |
| 887 | return result; |
| 888 | } |
| 889 | |
| 890 | lldb::SBFrame |
| 891 | SBValue::GetFrame() |
| 892 | { |
| 893 | SBFrame result; |
| 894 | if (m_opaque_sp) |
| 895 | { |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame^] | 896 | if (m_opaque_sp->GetExecutionContextScope()) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 897 | { |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame^] | 898 | result.SetFrame (m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->GetSP()); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 902 | if (log) |
| 903 | { |
| 904 | if (result.get() == NULL) |
| 905 | log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get()); |
| 906 | else |
| 907 | log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), result.get()); |
| 908 | } |
| 909 | return result; |
| 910 | } |
| 911 | |
| 912 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 913 | // Mimic shared pointer... |
| 914 | lldb_private::ValueObject * |
| 915 | SBValue::get() const |
| 916 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 917 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | lldb_private::ValueObject * |
| 921 | SBValue::operator->() const |
| 922 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 923 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | lldb::ValueObjectSP & |
| 927 | SBValue::operator*() |
| 928 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 929 | return m_opaque_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | const lldb::ValueObjectSP & |
| 933 | SBValue::operator*() const |
| 934 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 935 | return m_opaque_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 936 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 937 | |
| 938 | bool |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 939 | SBValue::GetExpressionPath (SBStream &description) |
| 940 | { |
| 941 | if (m_opaque_sp) |
| 942 | { |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 943 | m_opaque_sp->GetExpressionPath (description.ref(), false); |
| 944 | return true; |
| 945 | } |
| 946 | return false; |
| 947 | } |
| 948 | |
| 949 | bool |
| 950 | SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes) |
| 951 | { |
| 952 | if (m_opaque_sp) |
| 953 | { |
| 954 | m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 955 | return true; |
| 956 | } |
| 957 | return false; |
| 958 | } |
| 959 | |
| 960 | bool |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 961 | SBValue::GetDescription (SBStream &description) |
| 962 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 963 | Stream &strm = description.ref(); |
| 964 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 965 | if (m_opaque_sp) |
| 966 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 967 | ValueObject::DumpValueObject (strm, m_opaque_sp.get()); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 968 | } |
| 969 | else |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 970 | strm.PutCString ("No value"); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 971 | |
| 972 | return true; |
| 973 | } |
Greg Clayton | e179a58 | 2011-01-05 18:43:15 +0000 | [diff] [blame] | 974 | |
| 975 | lldb::Format |
Greg Clayton | d68e089 | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 976 | SBValue::GetFormat () |
Greg Clayton | e179a58 | 2011-01-05 18:43:15 +0000 | [diff] [blame] | 977 | { |
| 978 | if (m_opaque_sp) |
| 979 | return m_opaque_sp->GetFormat(); |
| 980 | return eFormatDefault; |
| 981 | } |
| 982 | |
| 983 | void |
| 984 | SBValue::SetFormat (lldb::Format format) |
| 985 | { |
| 986 | if (m_opaque_sp) |
| 987 | m_opaque_sp->SetFormat(format); |
| 988 | } |
| 989 | |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 990 | lldb::SBValue |
| 991 | SBValue::AddressOf() |
| 992 | { |
| 993 | SBValue sb_value; |
| 994 | if (m_opaque_sp) |
| 995 | { |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 996 | Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); |
| 997 | if (target) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 998 | { |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 999 | Mutex::Locker api_locker (target->GetAPIMutex()); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1000 | Error error; |
| 1001 | sb_value = m_opaque_sp->AddressOf (error); |
| 1002 | } |
| 1003 | } |
| 1004 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1005 | if (log) |
| 1006 | log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", m_opaque_sp.get(), sb_value.get()); |
| 1007 | |
| 1008 | return sb_value; |
Johnny Chen | a713b86 | 2011-08-09 22:38:07 +0000 | [diff] [blame] | 1009 | } |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1010 | |
| 1011 | lldb::addr_t |
| 1012 | SBValue::GetLoadAddress() |
| 1013 | { |
| 1014 | lldb::addr_t value = LLDB_INVALID_ADDRESS; |
| 1015 | if (m_opaque_sp) |
| 1016 | { |
| 1017 | Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); |
| 1018 | if (target) |
| 1019 | { |
| 1020 | Mutex::Locker api_locker (target->GetAPIMutex()); |
| 1021 | const bool scalar_is_load_address = true; |
| 1022 | AddressType addr_type; |
| 1023 | value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type); |
| 1024 | if (addr_type == eAddressTypeFile) |
| 1025 | { |
| 1026 | Module* module = m_opaque_sp->GetModule(); |
| 1027 | if (!module) |
| 1028 | value = LLDB_INVALID_ADDRESS; |
| 1029 | else |
| 1030 | { |
| 1031 | Address addr; |
| 1032 | module->ResolveFileAddress(value, addr); |
| 1033 | value = addr.GetLoadAddress(m_opaque_sp->GetUpdatePoint().GetTargetSP().get()); |
| 1034 | } |
| 1035 | } |
| 1036 | else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid) |
| 1037 | value = LLDB_INVALID_ADDRESS; |
| 1038 | } |
| 1039 | } |
| 1040 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1041 | if (log) |
| 1042 | log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", m_opaque_sp.get(), value); |
| 1043 | |
| 1044 | return value; |
| 1045 | } |
| 1046 | |
| 1047 | lldb::SBAddress |
| 1048 | SBValue::GetAddress() |
| 1049 | { |
| 1050 | Address addr; |
| 1051 | if (m_opaque_sp) |
| 1052 | { |
| 1053 | Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); |
| 1054 | if (target) |
| 1055 | { |
| 1056 | lldb::addr_t value = LLDB_INVALID_ADDRESS; |
| 1057 | Mutex::Locker api_locker (target->GetAPIMutex()); |
| 1058 | const bool scalar_is_load_address = true; |
| 1059 | AddressType addr_type; |
| 1060 | value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type); |
| 1061 | if (addr_type == eAddressTypeFile) |
| 1062 | { |
| 1063 | Module* module = m_opaque_sp->GetModule(); |
| 1064 | if (module) |
| 1065 | module->ResolveFileAddress(value, addr); |
| 1066 | } |
| 1067 | else if (addr_type == eAddressTypeLoad) |
| 1068 | { |
| 1069 | // no need to check the return value on this.. if it can actually do the resolve |
| 1070 | // addr will be in the form (section,offset), otherwise it will simply be returned |
| 1071 | // as (NULL, value) |
| 1072 | addr.SetLoadAddress(value, target); |
| 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1077 | if (log) |
| 1078 | log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", m_opaque_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset()); |
| 1079 | return SBAddress(new Address(addr)); |
| 1080 | } |
| 1081 | |
| 1082 | lldb::SBData |
| 1083 | SBValue::GetPointeeData (uint32_t item_idx, |
| 1084 | uint32_t item_count) |
| 1085 | { |
| 1086 | lldb::SBData sb_data; |
| 1087 | if (m_opaque_sp) |
| 1088 | { |
| 1089 | Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); |
| 1090 | if (target) |
| 1091 | { |
| 1092 | DataExtractorSP data_sp(new DataExtractor()); |
| 1093 | Mutex::Locker api_locker (target->GetAPIMutex()); |
| 1094 | m_opaque_sp->GetPointeeData(*data_sp, item_idx, item_count); |
| 1095 | if (data_sp->GetByteSize() > 0) |
| 1096 | *sb_data = data_sp; |
| 1097 | } |
| 1098 | } |
| 1099 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1100 | if (log) |
| 1101 | log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)", |
| 1102 | m_opaque_sp.get(), |
| 1103 | item_idx, |
| 1104 | item_count, |
| 1105 | sb_data.get()); |
| 1106 | |
| 1107 | return sb_data; |
| 1108 | } |
| 1109 | |
| 1110 | lldb::SBData |
| 1111 | SBValue::GetData () |
| 1112 | { |
| 1113 | lldb::SBData sb_data; |
| 1114 | if (m_opaque_sp) |
| 1115 | { |
| 1116 | Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); |
| 1117 | if (target) |
| 1118 | { |
| 1119 | DataExtractorSP data_sp(new DataExtractor()); |
| 1120 | Mutex::Locker api_locker (target->GetAPIMutex()); |
| 1121 | m_opaque_sp->GetData(*data_sp); |
| 1122 | if (data_sp->GetByteSize() > 0) |
| 1123 | *sb_data = data_sp; |
| 1124 | } |
| 1125 | } |
| 1126 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1127 | if (log) |
| 1128 | log->Printf ("SBValue(%p)::GetData () => SBData(%p)", |
| 1129 | m_opaque_sp.get(), |
| 1130 | sb_data.get()); |
| 1131 | |
| 1132 | return sb_data; |
| 1133 | } |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1134 | |
| 1135 | lldb::SBWatchpoint |
| 1136 | SBValue::Watch (bool resolve_location, bool read, bool write) |
| 1137 | { |
| 1138 | lldb::SBWatchpoint sb_watchpoint; |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1139 | if (!m_opaque_sp) |
| 1140 | return sb_watchpoint; |
| 1141 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1142 | Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); |
| 1143 | if (target) |
| 1144 | { |
| 1145 | Mutex::Locker api_locker (target->GetAPIMutex()); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1146 | sb_watchpoint = WatchValue(read, write, false); |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1147 | } |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1148 | LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1149 | if (log) |
| 1150 | log->Printf ("SBValue(%p)::Watch (resolve_location=%i, read=%i, write=%i) => wp(%p)", |
| 1151 | m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get()); |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1152 | return sb_watchpoint; |
| 1153 | } |
| 1154 | |
| 1155 | lldb::SBWatchpoint |
| 1156 | SBValue::WatchPointee (bool resolve_location, bool read, bool write) |
| 1157 | { |
| 1158 | lldb::SBWatchpoint sb_watchpoint; |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1159 | if (!m_opaque_sp) |
| 1160 | return sb_watchpoint; |
| 1161 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1162 | Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); |
| 1163 | if (target) |
| 1164 | { |
| 1165 | Mutex::Locker api_locker (target->GetAPIMutex()); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1166 | sb_watchpoint = WatchValue(read, write, true); |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1167 | } |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1168 | LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1169 | if (log) |
| 1170 | log->Printf ("SBValue(%p)::WatchPointee (resolve_location=%i, read=%i, write=%i) => wp(%p)", |
| 1171 | m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get()); |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1172 | return sb_watchpoint; |
| 1173 | } |
| 1174 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1175 | // Helper function for SBValue::Watch() and SBValue::WatchPointee(). |
| 1176 | SBWatchpoint |
| 1177 | SBValue::WatchValue(bool read, bool write, bool watch_pointee) |
| 1178 | { |
| 1179 | SBWatchpoint sb_wp_empty; |
| 1180 | |
| 1181 | // If the SBValue is not valid, there's no point in even trying to watch it. |
| 1182 | if (!IsValid() || !GetFrame().IsValid()) |
| 1183 | return sb_wp_empty; |
| 1184 | |
| 1185 | // Read and Write cannot both be false. |
| 1186 | if (!read && !write) |
| 1187 | return sb_wp_empty; |
| 1188 | |
| 1189 | // If we are watching the pointee, check that the SBValue is a pointer type. |
| 1190 | if (watch_pointee && !GetType().IsPointerType()) |
| 1191 | return sb_wp_empty; |
| 1192 | |
| 1193 | addr_t addr; |
| 1194 | size_t size; |
| 1195 | if (watch_pointee) { |
| 1196 | addr = GetValueAsUnsigned(LLDB_INVALID_ADDRESS); |
| 1197 | size = GetType().GetPointeeType().GetByteSize(); |
| 1198 | } else { |
| 1199 | addr = GetLoadAddress(); |
| 1200 | size = GetByteSize(); |
| 1201 | } |
| 1202 | |
| 1203 | // Sanity check the address and the size before calling Target::CreateWatchpoint(). |
| 1204 | if (addr == LLDB_INVALID_ADDRESS || size == 0) |
| 1205 | return sb_wp_empty; |
| 1206 | |
| 1207 | uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) | |
| 1208 | (write ? LLDB_WATCH_TYPE_WRITE : 0); |
| 1209 | WatchpointSP wp_sp = GetFrame().m_opaque_sp->GetThread().GetProcess().GetTarget(). |
| 1210 | CreateWatchpoint(addr, size, watch_type); |
| 1211 | |
| 1212 | if (wp_sp) { |
| 1213 | // StackFrame::GetInScopeVariableList(true) to get file globals as well. |
| 1214 | VariableListSP var_list_sp(GetFrame().m_opaque_sp->GetInScopeVariableList(true)); |
| 1215 | VariableSP var_sp = var_list_sp->FindVariable(ConstString(GetName())); |
| 1216 | if (var_sp && var_sp->GetDeclaration().GetFile()) { |
| 1217 | StreamString ss; |
| 1218 | // True to show fullpath for declaration file. |
| 1219 | var_sp->GetDeclaration().DumpStopContext(&ss, true); |
| 1220 | wp_sp->SetDeclInfo(ss.GetString()); |
| 1221 | } |
| 1222 | } |
| 1223 | return wp_sp; |
| 1224 | } |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1225 | |