Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 1 | //===-- ClangUserExpression.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 | // C Includes |
| 11 | #include <stdio.h> |
| 12 | #if HAVE_SYS_TYPES_H |
| 13 | # include <sys/types.h> |
| 14 | #endif |
| 15 | |
| 16 | // C++ Includes |
| 17 | #include <cstdlib> |
| 18 | #include <string> |
| 19 | #include <map> |
| 20 | |
| 21 | #include "lldb/Core/ConstString.h" |
| 22 | #include "lldb/Core/Log.h" |
| 23 | #include "lldb/Core/StreamString.h" |
Greg Clayton | d171972 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 24 | #include "lldb/Core/ValueObjectConstResult.h" |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 25 | #include "lldb/Expression/ClangExpressionDeclMap.h" |
| 26 | #include "lldb/Expression/ClangExpressionParser.h" |
| 27 | #include "lldb/Expression/ClangFunction.h" |
| 28 | #include "lldb/Expression/ASTResultSynthesizer.h" |
| 29 | #include "lldb/Expression/ClangUserExpression.h" |
| 30 | #include "lldb/Host/Host.h" |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 31 | #include "lldb/Symbol/VariableList.h" |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 32 | #include "lldb/Target/ExecutionContext.h" |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 33 | #include "lldb/Target/StackFrame.h" |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 34 | #include "lldb/Target/Target.h" |
| 35 | |
| 36 | using namespace lldb_private; |
| 37 | |
| 38 | ClangUserExpression::ClangUserExpression (const char *expr) : |
| 39 | m_expr_text(expr), |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 40 | m_transformed_text(), |
| 41 | m_jit_addr(LLDB_INVALID_ADDRESS), |
| 42 | m_cplusplus(false), |
| 43 | m_objectivec(false), |
| 44 | m_needs_object_ptr(false) |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 45 | { |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Sean Callanan | 830a903 | 2010-08-27 23:31:21 +0000 | [diff] [blame] | 48 | ClangUserExpression::~ClangUserExpression () |
| 49 | { |
| 50 | } |
| 51 | |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 52 | clang::ASTConsumer * |
| 53 | ClangUserExpression::ASTTransformer (clang::ASTConsumer *passthrough) |
| 54 | { |
| 55 | return new ASTResultSynthesizer(passthrough); |
| 56 | } |
| 57 | |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 58 | void |
| 59 | ClangUserExpression::ScanContext(ExecutionContext &exe_ctx) |
| 60 | { |
| 61 | if (!exe_ctx.frame) |
| 62 | return; |
| 63 | |
| 64 | VariableList *vars = exe_ctx.frame->GetVariableList(false); |
| 65 | |
| 66 | if (!vars) |
| 67 | return; |
| 68 | |
| 69 | if (vars->FindVariable(ConstString("this")).get()) |
| 70 | m_cplusplus = true; |
| 71 | else if (vars->FindVariable(ConstString("self")).get()) |
| 72 | m_objectivec = true; |
| 73 | } |
| 74 | |
Sean Callanan | 550f276 | 2010-10-22 23:25:16 +0000 | [diff] [blame] | 75 | // This is a really nasty hack, meant to fix Objective-C expressions of the form |
| 76 | // (int)[myArray count]. Right now, because the type information for count is |
| 77 | // not available, [myArray count] returns id, which can't be directly cast to |
| 78 | // int without causing a clang error. |
| 79 | static void |
| 80 | ApplyObjcCastHack(std::string &expr) |
| 81 | { |
| 82 | #define OBJC_CAST_HACK_FROM "(int)[" |
| 83 | #define OBJC_CAST_HACK_TO "(int)(long long)[" |
| 84 | |
| 85 | size_t from_offset; |
| 86 | |
| 87 | while ((from_offset = expr.find(OBJC_CAST_HACK_FROM)) != expr.npos) |
| 88 | expr.replace(from_offset, sizeof(OBJC_CAST_HACK_FROM) - 1, OBJC_CAST_HACK_TO); |
| 89 | |
| 90 | #undef OBJC_CAST_HACK_TO |
| 91 | #undef OBJC_CAST_HACK_FROM |
| 92 | } |
| 93 | |
Sean Callanan | 3089237 | 2010-10-24 20:45:49 +0000 | [diff] [blame] | 94 | // Another hack, meant to allow use of unichar despite it not being available in |
| 95 | // the type information. Although we could special-case it in type lookup, |
| 96 | // hopefully we'll figure out a way to #include the same environment as is |
| 97 | // present in the original source file rather than try to hack specific type |
| 98 | // definitions in as needed. |
| 99 | static void |
| 100 | ApplyUnicharHack(std::string &expr) |
| 101 | { |
| 102 | #define UNICHAR_HACK_FROM "unichar" |
| 103 | #define UNICHAR_HACK_TO "unsigned short" |
| 104 | |
| 105 | size_t from_offset; |
| 106 | |
| 107 | while ((from_offset = expr.find(UNICHAR_HACK_FROM)) != expr.npos) |
| 108 | expr.replace(from_offset, sizeof(UNICHAR_HACK_FROM) - 1, UNICHAR_HACK_TO); |
| 109 | |
| 110 | #undef UNICHAR_HACK_TO |
| 111 | #undef UNICHAR_HACK_FROM |
| 112 | } |
| 113 | |
Sean Callanan | 550f276 | 2010-10-22 23:25:16 +0000 | [diff] [blame] | 114 | bool |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 115 | ClangUserExpression::Parse (Stream &error_stream, ExecutionContext &exe_ctx) |
| 116 | { |
| 117 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 118 | |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 119 | ScanContext(exe_ctx); |
| 120 | |
| 121 | StreamString m_transformed_stream; |
| 122 | |
| 123 | //////////////////////////////////// |
| 124 | // Generate the expression |
| 125 | // |
Sean Callanan | 550f276 | 2010-10-22 23:25:16 +0000 | [diff] [blame] | 126 | |
| 127 | ApplyObjcCastHack(m_expr_text); |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 128 | //ApplyUnicharHack(m_expr_text); |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 129 | |
| 130 | if (m_cplusplus) |
| 131 | { |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 132 | m_transformed_stream.Printf("typedef unsigned short unichar; \n" |
| 133 | "void \n" |
Sean Callanan | 550f276 | 2010-10-22 23:25:16 +0000 | [diff] [blame] | 134 | "$__lldb_class::%s(void *$__lldb_arg) \n" |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 135 | "{ \n" |
| 136 | " %s; \n" |
| 137 | "} \n", |
| 138 | FunctionName(), |
| 139 | m_expr_text.c_str()); |
| 140 | |
| 141 | m_needs_object_ptr = true; |
| 142 | } |
| 143 | else |
| 144 | { |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 145 | m_transformed_stream.Printf("typedef unsigned short unichar;\n" |
| 146 | "void \n" |
Sean Callanan | 550f276 | 2010-10-22 23:25:16 +0000 | [diff] [blame] | 147 | "%s(void *$__lldb_arg) \n" |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 148 | "{ \n" |
| 149 | " %s; \n" |
| 150 | "} \n", |
| 151 | FunctionName(), |
| 152 | m_expr_text.c_str()); |
| 153 | } |
| 154 | |
| 155 | m_transformed_text = m_transformed_stream.GetData(); |
| 156 | |
| 157 | |
| 158 | if (log) |
| 159 | log->Printf("Parsing the following code:\n%s", m_transformed_text.c_str()); |
| 160 | |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 161 | //////////////////////////////////// |
| 162 | // Set up the target and compiler |
| 163 | // |
| 164 | |
| 165 | Target *target = exe_ctx.target; |
| 166 | |
| 167 | if (!target) |
| 168 | { |
| 169 | error_stream.PutCString ("error: invalid target\n"); |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | ConstString target_triple; |
| 174 | |
| 175 | target->GetTargetTriple (target_triple); |
| 176 | |
| 177 | if (!target_triple) |
| 178 | target_triple = Host::GetTargetTriple (); |
| 179 | |
| 180 | if (!target_triple) |
| 181 | { |
| 182 | error_stream.PutCString ("error: invalid target triple\n"); |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | ////////////////////////// |
| 187 | // Parse the expression |
| 188 | // |
| 189 | |
| 190 | m_expr_decl_map.reset(new ClangExpressionDeclMap(&exe_ctx)); |
| 191 | |
| 192 | ClangExpressionParser parser(target_triple.GetCString(), *this); |
| 193 | |
| 194 | unsigned num_errors = parser.Parse (error_stream); |
| 195 | |
| 196 | if (num_errors) |
| 197 | { |
| 198 | error_stream.Printf ("error: %d errors parsing expression\n", num_errors); |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | /////////////////////////////////////////////// |
| 203 | // Convert the output of the parser to DWARF |
| 204 | // |
| 205 | |
| 206 | m_dwarf_opcodes.reset(new StreamString); |
| 207 | m_dwarf_opcodes->SetByteOrder (lldb::eByteOrderHost); |
| 208 | m_dwarf_opcodes->GetFlags ().Set (Stream::eBinary); |
| 209 | |
| 210 | m_local_variables.reset(new ClangExpressionVariableStore()); |
| 211 | |
| 212 | Error dwarf_error = parser.MakeDWARF (); |
| 213 | |
| 214 | if (dwarf_error.Success()) |
| 215 | { |
| 216 | if (log) |
| 217 | log->Printf("Code can be interpreted."); |
| 218 | |
| 219 | return true; |
| 220 | } |
| 221 | |
| 222 | ////////////////////////////////// |
| 223 | // JIT the output of the parser |
| 224 | // |
| 225 | |
| 226 | m_dwarf_opcodes.reset(); |
| 227 | |
Sean Callanan | 830a903 | 2010-08-27 23:31:21 +0000 | [diff] [blame] | 228 | lldb::addr_t jit_end; |
| 229 | |
| 230 | Error jit_error = parser.MakeJIT (m_jit_addr, jit_end, exe_ctx); |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 231 | |
| 232 | if (jit_error.Success()) |
| 233 | { |
| 234 | if (log) |
| 235 | { |
| 236 | log->Printf("Code can be run in the target."); |
| 237 | |
| 238 | StreamString disassembly_stream; |
| 239 | |
| 240 | Error err = parser.DisassembleFunction(disassembly_stream, exe_ctx); |
| 241 | |
| 242 | if (!err.Success()) |
| 243 | { |
| 244 | log->Printf("Couldn't disassemble function : %s", err.AsCString("unknown error")); |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | log->Printf("Function disassembly:\n%s", disassembly_stream.GetData()); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | return true; |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | error_stream.Printf ("error: expression can't be interpreted or run\n", num_errors); |
| 257 | return false; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | bool |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 262 | ClangUserExpression::PrepareToExecuteJITExpression (Stream &error_stream, |
Sean Callanan | ab06af9 | 2010-10-19 23:57:21 +0000 | [diff] [blame] | 263 | ExecutionContext &exe_ctx, |
| 264 | lldb::addr_t &struct_address, |
| 265 | lldb::addr_t &object_ptr) |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 266 | { |
| 267 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 268 | |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 269 | if (m_jit_addr != LLDB_INVALID_ADDRESS) |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 270 | { |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 271 | |
| 272 | Error materialize_error; |
| 273 | |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 274 | |
| 275 | if (m_needs_object_ptr && !(m_expr_decl_map->GetObjectPointer(object_ptr, &exe_ctx, materialize_error))) |
| 276 | { |
| 277 | error_stream.Printf("Couldn't get required object pointer: %s\n", materialize_error.AsCString()); |
| 278 | return false; |
| 279 | } |
| 280 | |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 281 | if (!m_expr_decl_map->Materialize(&exe_ctx, struct_address, materialize_error)) |
| 282 | { |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 283 | error_stream.Printf("Couldn't materialize struct: %s\n", materialize_error.AsCString()); |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 284 | return false; |
| 285 | } |
| 286 | |
| 287 | if (log) |
| 288 | { |
| 289 | log->Printf("Function address : 0x%llx", (uint64_t)m_jit_addr); |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 290 | |
| 291 | if (m_needs_object_ptr) |
| 292 | log->Printf("Object pointer : 0x%llx", (uint64_t)object_ptr); |
| 293 | |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 294 | log->Printf("Structure address : 0x%llx", (uint64_t)struct_address); |
| 295 | |
| 296 | StreamString args; |
| 297 | |
| 298 | Error dump_error; |
| 299 | |
Sean Callanan | e8a59a8 | 2010-09-13 21:34:21 +0000 | [diff] [blame] | 300 | if (struct_address) |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 301 | { |
Sean Callanan | e8a59a8 | 2010-09-13 21:34:21 +0000 | [diff] [blame] | 302 | if (!m_expr_decl_map->DumpMaterializedStruct(&exe_ctx, args, dump_error)) |
| 303 | { |
| 304 | log->Printf("Couldn't extract variable values : %s", dump_error.AsCString("unknown error")); |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | log->Printf("Structure contents:\n%s", args.GetData()); |
| 309 | } |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 310 | } |
| 311 | } |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 312 | } |
| 313 | return true; |
| 314 | } |
| 315 | |
| 316 | ThreadPlan * |
| 317 | ClangUserExpression::GetThreadPlanToExecuteJITExpression (Stream &error_stream, |
| 318 | ExecutionContext &exe_ctx) |
| 319 | { |
| 320 | lldb::addr_t struct_address; |
| 321 | |
| 322 | lldb::addr_t object_ptr = NULL; |
| 323 | |
| 324 | PrepareToExecuteJITExpression (error_stream, exe_ctx, struct_address, object_ptr); |
| 325 | |
| 326 | return ClangFunction::GetThreadPlanToCallFunction (exe_ctx, |
| 327 | m_jit_addr, |
| 328 | struct_address, |
| 329 | error_stream, |
| 330 | true, |
| 331 | true, |
| 332 | (m_needs_object_ptr ? &object_ptr : NULL)); |
| 333 | } |
| 334 | |
| 335 | bool |
| 336 | ClangUserExpression::FinalizeJITExecution (Stream &error_stream, |
| 337 | ExecutionContext &exe_ctx, |
| 338 | ClangExpressionVariable *&result) |
| 339 | { |
| 340 | Error expr_error; |
| 341 | |
| 342 | if (!m_expr_decl_map->Dematerialize(&exe_ctx, result, expr_error)) |
| 343 | { |
| 344 | error_stream.Printf ("Couldn't dematerialize struct : %s\n", expr_error.AsCString("unknown error")); |
| 345 | return false; |
| 346 | } |
| 347 | return true; |
| 348 | } |
| 349 | |
| 350 | bool |
| 351 | ClangUserExpression::Execute (Stream &error_stream, |
| 352 | ExecutionContext &exe_ctx, |
| 353 | ClangExpressionVariable *&result) |
| 354 | { |
| 355 | if (m_dwarf_opcodes.get()) |
| 356 | { |
| 357 | // TODO execute the JITted opcodes |
| 358 | |
| 359 | error_stream.Printf("We don't currently support executing DWARF expressions"); |
| 360 | |
| 361 | return false; |
| 362 | } |
| 363 | else if (m_jit_addr != LLDB_INVALID_ADDRESS) |
| 364 | { |
| 365 | lldb::addr_t struct_address; |
| 366 | |
| 367 | lldb::addr_t object_ptr = NULL; |
| 368 | |
| 369 | PrepareToExecuteJITExpression (error_stream, exe_ctx, struct_address, object_ptr); |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 370 | |
| 371 | ClangFunction::ExecutionResults execution_result = |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 372 | ClangFunction::ExecuteFunction (exe_ctx, |
| 373 | m_jit_addr, |
| 374 | struct_address, |
| 375 | true, |
| 376 | true, |
Sean Callanan | 0027cec | 2010-10-07 18:17:31 +0000 | [diff] [blame] | 377 | 10000000, |
Sean Callanan | 3c9c5eb | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 378 | error_stream, |
| 379 | (m_needs_object_ptr ? &object_ptr : NULL)); |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 380 | |
| 381 | if (execution_result != ClangFunction::eExecutionCompleted) |
| 382 | { |
| 383 | const char *result_name; |
| 384 | |
| 385 | switch (execution_result) |
| 386 | { |
| 387 | case ClangFunction::eExecutionCompleted: |
| 388 | result_name = "eExecutionCompleted"; |
| 389 | break; |
| 390 | case ClangFunction::eExecutionDiscarded: |
| 391 | result_name = "eExecutionDiscarded"; |
| 392 | break; |
| 393 | case ClangFunction::eExecutionInterrupted: |
| 394 | result_name = "eExecutionInterrupted"; |
| 395 | break; |
| 396 | case ClangFunction::eExecutionSetupError: |
| 397 | result_name = "eExecutionSetupError"; |
| 398 | break; |
| 399 | case ClangFunction::eExecutionTimedOut: |
| 400 | result_name = "eExecutionTimedOut"; |
| 401 | break; |
| 402 | } |
| 403 | |
| 404 | error_stream.Printf ("Couldn't execute function; result was %s\n", result_name); |
| 405 | return false; |
| 406 | } |
| 407 | |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 408 | return FinalizeJITExecution (error_stream, exe_ctx, result); |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 409 | } |
| 410 | else |
| 411 | { |
| 412 | error_stream.Printf("Expression can't be run; neither DWARF nor a JIT compiled function are present"); |
| 413 | return false; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | StreamString & |
| 418 | ClangUserExpression::DwarfOpcodeStream () |
| 419 | { |
| 420 | if (!m_dwarf_opcodes.get()) |
| 421 | m_dwarf_opcodes.reset(new StreamString()); |
| 422 | |
| 423 | return *m_dwarf_opcodes.get(); |
| 424 | } |
Greg Clayton | 377e0b4 | 2010-10-05 00:31:29 +0000 | [diff] [blame] | 425 | |
| 426 | |
Greg Clayton | d171972 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 427 | lldb::ValueObjectSP |
| 428 | ClangUserExpression::Evaluate (ExecutionContext &exe_ctx, const char *expr_cstr) |
Greg Clayton | 377e0b4 | 2010-10-05 00:31:29 +0000 | [diff] [blame] | 429 | { |
| 430 | Error error; |
Greg Clayton | d171972 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 431 | lldb::ValueObjectSP result_valobj_sp; |
Greg Clayton | 377e0b4 | 2010-10-05 00:31:29 +0000 | [diff] [blame] | 432 | ClangUserExpression user_expression (expr_cstr); |
| 433 | |
| 434 | StreamString error_stream; |
| 435 | |
| 436 | if (!user_expression.Parse (error_stream, exe_ctx)) |
| 437 | { |
| 438 | if (error_stream.GetString().empty()) |
| 439 | error.SetErrorString ("expression failed to parse, unknown error"); |
| 440 | else |
| 441 | error.SetErrorString (error_stream.GetString().c_str()); |
| 442 | } |
| 443 | else |
| 444 | { |
| 445 | ClangExpressionVariable *expr_result = NULL; |
| 446 | |
| 447 | error_stream.GetString().clear(); |
| 448 | |
| 449 | if (!user_expression.Execute (error_stream, exe_ctx, expr_result)) |
| 450 | { |
| 451 | if (error_stream.GetString().empty()) |
| 452 | error.SetErrorString ("expression failed to execute, unknown error"); |
| 453 | else |
| 454 | error.SetErrorString (error_stream.GetString().c_str()); |
| 455 | } |
| 456 | else |
| 457 | { |
| 458 | // TODO: seems weird to get a pointer to a result object back from |
| 459 | // a function. Do we own it? Feels like we do, but from looking at the |
| 460 | // code we don't. Might be best to make this a reference and state |
| 461 | // explicitly that we don't own it when we get a reference back from |
| 462 | // the execute? |
| 463 | if (expr_result) |
| 464 | { |
| 465 | result_valobj_sp = expr_result->GetExpressionResult (&exe_ctx); |
| 466 | } |
| 467 | else |
| 468 | { |
Sean Callanan | 44820ec | 2010-10-19 20:15:00 +0000 | [diff] [blame] | 469 | error.SetErrorString ("Expression did not return a result"); |
Greg Clayton | 377e0b4 | 2010-10-05 00:31:29 +0000 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | } |
Sean Callanan | 44820ec | 2010-10-19 20:15:00 +0000 | [diff] [blame] | 473 | |
Greg Clayton | d171972 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 474 | if (result_valobj_sp.get() == NULL) |
| 475 | result_valobj_sp.reset (new ValueObjectConstResult (error)); |
| 476 | |
| 477 | return result_valobj_sp; |
Greg Clayton | 377e0b4 | 2010-10-05 00:31:29 +0000 | [diff] [blame] | 478 | } |