blob: 7e5b40da7d79b554aed78212cf8a9808b08fc2f3 [file] [log] [blame]
Sean Callanan65dafa82010-08-27 01:01:44 +00001//===-- 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 Claytond1719722010-10-05 03:13:51 +000024#include "lldb/Core/ValueObjectConstResult.h"
Sean Callanan65dafa82010-08-27 01:01:44 +000025#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 Callanan3c9c5eb2010-09-21 00:44:12 +000031#include "lldb/Symbol/VariableList.h"
Sean Callanan65dafa82010-08-27 01:01:44 +000032#include "lldb/Target/ExecutionContext.h"
Greg Clayton0baa3942010-11-04 01:54:29 +000033#include "lldb/Target/Process.h"
Sean Callanan3c9c5eb2010-09-21 00:44:12 +000034#include "lldb/Target/StackFrame.h"
Sean Callanan65dafa82010-08-27 01:01:44 +000035#include "lldb/Target/Target.h"
Jim Ingham360f53f2010-11-30 02:22:11 +000036#include "lldb/Target/ThreadPlan.h"
37#include "lldb/Target/ThreadPlanCallUserExpression.h"
Sean Callanan65dafa82010-08-27 01:01:44 +000038
39using namespace lldb_private;
40
Sean Callanan77e93942010-10-29 00:29:03 +000041ClangUserExpression::ClangUserExpression (const char *expr,
42 const char *expr_prefix) :
Sean Callanan65dafa82010-08-27 01:01:44 +000043 m_expr_text(expr),
Johnny Chenb4c0f022010-10-29 20:19:44 +000044 m_expr_prefix(expr_prefix ? expr_prefix : ""),
Sean Callanan3c9c5eb2010-09-21 00:44:12 +000045 m_transformed_text(),
46 m_jit_addr(LLDB_INVALID_ADDRESS),
47 m_cplusplus(false),
48 m_objectivec(false),
Sean Callanana91dd992010-11-19 02:52:21 +000049 m_needs_object_ptr(false),
Sean Callanane8e55572010-12-01 21:35:54 +000050 m_const_object(false),
Sean Callanana91dd992010-11-19 02:52:21 +000051 m_desired_type(NULL, NULL)
Sean Callanan65dafa82010-08-27 01:01:44 +000052{
Sean Callanan65dafa82010-08-27 01:01:44 +000053}
54
Sean Callanan830a9032010-08-27 23:31:21 +000055ClangUserExpression::~ClangUserExpression ()
56{
57}
58
Sean Callanan65dafa82010-08-27 01:01:44 +000059clang::ASTConsumer *
60ClangUserExpression::ASTTransformer (clang::ASTConsumer *passthrough)
61{
Sean Callanana91dd992010-11-19 02:52:21 +000062 return new ASTResultSynthesizer(passthrough,
63 m_desired_type);
Sean Callanan65dafa82010-08-27 01:01:44 +000064}
65
Sean Callanan3c9c5eb2010-09-21 00:44:12 +000066void
67ClangUserExpression::ScanContext(ExecutionContext &exe_ctx)
68{
69 if (!exe_ctx.frame)
70 return;
71
72 VariableList *vars = exe_ctx.frame->GetVariableList(false);
73
74 if (!vars)
75 return;
76
Sean Callanane8e55572010-12-01 21:35:54 +000077 lldb::VariableSP this_var(vars->FindVariable(ConstString("this")));
78 lldb::VariableSP self_var(vars->FindVariable(ConstString("self")));
79
80 if (this_var.get())
81 {
82 Type *this_type = this_var->GetType();
83
84 lldb::clang_type_t pointer_target_type;
85
86 if (ClangASTContext::IsPointerType(this_type->GetClangType(),
87 &pointer_target_type))
88 {
89 TypeFromUser target_ast_type(pointer_target_type, this_type->GetClangAST());
90
91 if (target_ast_type.IsDefined())
92 m_cplusplus = true;
93
94 if (target_ast_type.IsConst())
95 m_const_object = true;
96 }
97 }
98 else if (self_var.get())
99 {
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000100 m_objectivec = true;
Sean Callanane8e55572010-12-01 21:35:54 +0000101 }
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000102}
103
Sean Callanan550f2762010-10-22 23:25:16 +0000104// This is a really nasty hack, meant to fix Objective-C expressions of the form
105// (int)[myArray count]. Right now, because the type information for count is
106// not available, [myArray count] returns id, which can't be directly cast to
107// int without causing a clang error.
108static void
109ApplyObjcCastHack(std::string &expr)
110{
111#define OBJC_CAST_HACK_FROM "(int)["
112#define OBJC_CAST_HACK_TO "(int)(long long)["
113
114 size_t from_offset;
115
116 while ((from_offset = expr.find(OBJC_CAST_HACK_FROM)) != expr.npos)
117 expr.replace(from_offset, sizeof(OBJC_CAST_HACK_FROM) - 1, OBJC_CAST_HACK_TO);
118
119#undef OBJC_CAST_HACK_TO
120#undef OBJC_CAST_HACK_FROM
121}
122
Sean Callanan30892372010-10-24 20:45:49 +0000123// Another hack, meant to allow use of unichar despite it not being available in
124// the type information. Although we could special-case it in type lookup,
125// hopefully we'll figure out a way to #include the same environment as is
126// present in the original source file rather than try to hack specific type
127// definitions in as needed.
128static void
129ApplyUnicharHack(std::string &expr)
130{
131#define UNICHAR_HACK_FROM "unichar"
132#define UNICHAR_HACK_TO "unsigned short"
133
134 size_t from_offset;
135
136 while ((from_offset = expr.find(UNICHAR_HACK_FROM)) != expr.npos)
137 expr.replace(from_offset, sizeof(UNICHAR_HACK_FROM) - 1, UNICHAR_HACK_TO);
138
139#undef UNICHAR_HACK_TO
140#undef UNICHAR_HACK_FROM
141}
142
Sean Callanan550f2762010-10-22 23:25:16 +0000143bool
Sean Callanana91dd992010-11-19 02:52:21 +0000144ClangUserExpression::Parse (Stream &error_stream,
145 ExecutionContext &exe_ctx,
146 TypeFromUser desired_type)
Sean Callanan65dafa82010-08-27 01:01:44 +0000147{
Greg Claytone005f2c2010-11-06 01:53:30 +0000148 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Sean Callanan65dafa82010-08-27 01:01:44 +0000149
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000150 ScanContext(exe_ctx);
151
152 StreamString m_transformed_stream;
153
154 ////////////////////////////////////
155 // Generate the expression
156 //
Sean Callanan550f2762010-10-22 23:25:16 +0000157
158 ApplyObjcCastHack(m_expr_text);
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000159 //ApplyUnicharHack(m_expr_text);
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000160
161 if (m_cplusplus)
162 {
Sean Callanan77e93942010-10-29 00:29:03 +0000163 m_transformed_stream.Printf("%s \n"
164 "typedef unsigned short unichar; \n"
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000165 "void \n"
Sean Callanane8e55572010-12-01 21:35:54 +0000166 "$__lldb_class::%s(void *$__lldb_arg) %s\n"
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000167 "{ \n"
168 " %s; \n"
169 "} \n",
Sean Callanan77e93942010-10-29 00:29:03 +0000170 m_expr_prefix.c_str(),
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000171 FunctionName(),
Sean Callanane8e55572010-12-01 21:35:54 +0000172 (m_const_object ? "const" : ""),
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000173 m_expr_text.c_str());
174
175 m_needs_object_ptr = true;
176 }
177 else
178 {
Sean Callanan77e93942010-10-29 00:29:03 +0000179 m_transformed_stream.Printf("%s \n"
180 "typedef unsigned short unichar;\n"
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000181 "void \n"
Sean Callanan550f2762010-10-22 23:25:16 +0000182 "%s(void *$__lldb_arg) \n"
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000183 "{ \n"
184 " %s; \n"
185 "} \n",
Sean Callanan77e93942010-10-29 00:29:03 +0000186 m_expr_prefix.c_str(),
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000187 FunctionName(),
188 m_expr_text.c_str());
189 }
190
191 m_transformed_text = m_transformed_stream.GetData();
192
193
194 if (log)
195 log->Printf("Parsing the following code:\n%s", m_transformed_text.c_str());
196
Sean Callanan65dafa82010-08-27 01:01:44 +0000197 ////////////////////////////////////
198 // Set up the target and compiler
199 //
200
201 Target *target = exe_ctx.target;
202
203 if (!target)
204 {
205 error_stream.PutCString ("error: invalid target\n");
206 return false;
207 }
208
209 ConstString target_triple;
210
211 target->GetTargetTriple (target_triple);
212
213 if (!target_triple)
214 target_triple = Host::GetTargetTriple ();
215
216 if (!target_triple)
217 {
218 error_stream.PutCString ("error: invalid target triple\n");
219 return false;
220 }
221
222 //////////////////////////
223 // Parse the expression
224 //
225
Sean Callanana91dd992010-11-19 02:52:21 +0000226 m_desired_type = desired_type;
227
Sean Callanan65dafa82010-08-27 01:01:44 +0000228 m_expr_decl_map.reset(new ClangExpressionDeclMap(&exe_ctx));
229
230 ClangExpressionParser parser(target_triple.GetCString(), *this);
231
232 unsigned num_errors = parser.Parse (error_stream);
233
234 if (num_errors)
235 {
236 error_stream.Printf ("error: %d errors parsing expression\n", num_errors);
237 return false;
238 }
239
240 ///////////////////////////////////////////////
241 // Convert the output of the parser to DWARF
242 //
243
244 m_dwarf_opcodes.reset(new StreamString);
245 m_dwarf_opcodes->SetByteOrder (lldb::eByteOrderHost);
246 m_dwarf_opcodes->GetFlags ().Set (Stream::eBinary);
247
248 m_local_variables.reset(new ClangExpressionVariableStore());
249
250 Error dwarf_error = parser.MakeDWARF ();
251
252 if (dwarf_error.Success())
253 {
254 if (log)
255 log->Printf("Code can be interpreted.");
256
257 return true;
258 }
259
260 //////////////////////////////////
261 // JIT the output of the parser
262 //
263
264 m_dwarf_opcodes.reset();
265
Sean Callanan830a9032010-08-27 23:31:21 +0000266 lldb::addr_t jit_end;
267
268 Error jit_error = parser.MakeJIT (m_jit_addr, jit_end, exe_ctx);
Sean Callanan65dafa82010-08-27 01:01:44 +0000269
270 if (jit_error.Success())
271 {
Sean Callanan65dafa82010-08-27 01:01:44 +0000272 return true;
273 }
274 else
275 {
276 error_stream.Printf ("error: expression can't be interpreted or run\n", num_errors);
277 return false;
278 }
279}
280
281bool
Jim Inghamd1686902010-10-14 23:45:03 +0000282ClangUserExpression::PrepareToExecuteJITExpression (Stream &error_stream,
Sean Callananab06af92010-10-19 23:57:21 +0000283 ExecutionContext &exe_ctx,
284 lldb::addr_t &struct_address,
285 lldb::addr_t &object_ptr)
Sean Callanan65dafa82010-08-27 01:01:44 +0000286{
Greg Claytone005f2c2010-11-06 01:53:30 +0000287 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Sean Callanan65dafa82010-08-27 01:01:44 +0000288
Jim Inghamd1686902010-10-14 23:45:03 +0000289 if (m_jit_addr != LLDB_INVALID_ADDRESS)
Sean Callanan65dafa82010-08-27 01:01:44 +0000290 {
Sean Callanan65dafa82010-08-27 01:01:44 +0000291
292 Error materialize_error;
293
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000294
295 if (m_needs_object_ptr && !(m_expr_decl_map->GetObjectPointer(object_ptr, &exe_ctx, materialize_error)))
296 {
297 error_stream.Printf("Couldn't get required object pointer: %s\n", materialize_error.AsCString());
298 return false;
299 }
300
Sean Callanan65dafa82010-08-27 01:01:44 +0000301 if (!m_expr_decl_map->Materialize(&exe_ctx, struct_address, materialize_error))
302 {
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000303 error_stream.Printf("Couldn't materialize struct: %s\n", materialize_error.AsCString());
Sean Callanan65dafa82010-08-27 01:01:44 +0000304 return false;
305 }
306
307 if (log)
308 {
309 log->Printf("Function address : 0x%llx", (uint64_t)m_jit_addr);
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000310
311 if (m_needs_object_ptr)
312 log->Printf("Object pointer : 0x%llx", (uint64_t)object_ptr);
313
Sean Callanan65dafa82010-08-27 01:01:44 +0000314 log->Printf("Structure address : 0x%llx", (uint64_t)struct_address);
315
316 StreamString args;
317
318 Error dump_error;
319
Sean Callanane8a59a82010-09-13 21:34:21 +0000320 if (struct_address)
Sean Callanan65dafa82010-08-27 01:01:44 +0000321 {
Sean Callanane8a59a82010-09-13 21:34:21 +0000322 if (!m_expr_decl_map->DumpMaterializedStruct(&exe_ctx, args, dump_error))
323 {
324 log->Printf("Couldn't extract variable values : %s", dump_error.AsCString("unknown error"));
325 }
326 else
327 {
328 log->Printf("Structure contents:\n%s", args.GetData());
329 }
Sean Callanan65dafa82010-08-27 01:01:44 +0000330 }
331 }
Jim Inghamd1686902010-10-14 23:45:03 +0000332 }
333 return true;
334}
335
336ThreadPlan *
337ClangUserExpression::GetThreadPlanToExecuteJITExpression (Stream &error_stream,
338 ExecutionContext &exe_ctx)
339{
340 lldb::addr_t struct_address;
341
342 lldb::addr_t object_ptr = NULL;
343
344 PrepareToExecuteJITExpression (error_stream, exe_ctx, struct_address, object_ptr);
345
Jim Ingham360f53f2010-11-30 02:22:11 +0000346 // FIXME: This should really return a ThreadPlanCallUserExpression, in order to make sure that we don't release the
347 // ClangUserExpression resources before the thread plan finishes execution in the target. But because we are
348 // forcing unwind_on_error to be true here, in practical terms that can't happen.
Jim Inghamd1686902010-10-14 23:45:03 +0000349 return ClangFunction::GetThreadPlanToCallFunction (exe_ctx,
Sean Callanana65b5272010-12-01 01:28:23 +0000350 m_jit_addr,
351 struct_address,
352 error_stream,
353 true,
354 true,
355 (m_needs_object_ptr ? &object_ptr : NULL));
Jim Inghamd1686902010-10-14 23:45:03 +0000356}
357
358bool
359ClangUserExpression::FinalizeJITExecution (Stream &error_stream,
360 ExecutionContext &exe_ctx,
361 ClangExpressionVariable *&result)
362{
363 Error expr_error;
364
365 if (!m_expr_decl_map->Dematerialize(&exe_ctx, result, expr_error))
366 {
367 error_stream.Printf ("Couldn't dematerialize struct : %s\n", expr_error.AsCString("unknown error"));
368 return false;
369 }
370 return true;
371}
372
Jim Ingham360f53f2010-11-30 02:22:11 +0000373Process::ExecutionResults
Jim Inghamd1686902010-10-14 23:45:03 +0000374ClangUserExpression::Execute (Stream &error_stream,
375 ExecutionContext &exe_ctx,
Jim Inghamea9d4262010-11-05 19:25:48 +0000376 bool discard_on_error,
Jim Ingham360f53f2010-11-30 02:22:11 +0000377 ClangUserExpression::ClangUserExpressionSP &shared_ptr_to_me,
Jim Inghamd1686902010-10-14 23:45:03 +0000378 ClangExpressionVariable *&result)
379{
380 if (m_dwarf_opcodes.get())
381 {
382 // TODO execute the JITted opcodes
383
384 error_stream.Printf("We don't currently support executing DWARF expressions");
385
Jim Ingham360f53f2010-11-30 02:22:11 +0000386 return Process::eExecutionSetupError;
Jim Inghamd1686902010-10-14 23:45:03 +0000387 }
388 else if (m_jit_addr != LLDB_INVALID_ADDRESS)
389 {
390 lldb::addr_t struct_address;
391
392 lldb::addr_t object_ptr = NULL;
393
394 PrepareToExecuteJITExpression (error_stream, exe_ctx, struct_address, object_ptr);
Sean Callanan65dafa82010-08-27 01:01:44 +0000395
Jim Inghamea9d4262010-11-05 19:25:48 +0000396 const bool stop_others = true;
397 const bool try_all_threads = true;
Sean Callanan65dafa82010-08-27 01:01:44 +0000398
Jim Ingham360f53f2010-11-30 02:22:11 +0000399 Address wrapper_address (NULL, m_jit_addr);
400 lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallUserExpression (*(exe_ctx.thread), wrapper_address, struct_address,
401 stop_others, discard_on_error,
402 (m_needs_object_ptr ? &object_ptr : NULL),
403 shared_ptr_to_me));
404 if (call_plan_sp == NULL || !call_plan_sp->ValidatePlan (NULL))
405 return Process::eExecutionSetupError;
406
407 call_plan_sp->SetPrivate(true);
408
409 uint32_t single_thread_timeout_usec = 10000000;
410 Process::ExecutionResults execution_result =
411 exe_ctx.process->RunThreadPlan (exe_ctx, call_plan_sp, stop_others, try_all_threads, discard_on_error,
412 single_thread_timeout_usec, error_stream);
413
414 if (execution_result == Process::eExecutionInterrupted)
Sean Callanan65dafa82010-08-27 01:01:44 +0000415 {
Jim Ingham360f53f2010-11-30 02:22:11 +0000416 if (discard_on_error)
417 error_stream.Printf ("Expression execution was interrupted. The process has been returned to the state before execution.");
418 else
419 error_stream.Printf ("Expression execution was interrupted. The process has been left at the point where it was interrupted.");
420
421 return execution_result;
422 }
423 else if (execution_result != Process::eExecutionCompleted)
424 {
425 error_stream.Printf ("Couldn't execute function; result was %s\n", Process::ExecutionResultAsCString (execution_result));
426 return execution_result;
Sean Callanan65dafa82010-08-27 01:01:44 +0000427 }
428
Jim Ingham360f53f2010-11-30 02:22:11 +0000429 if (FinalizeJITExecution (error_stream, exe_ctx, result))
430 return Process::eExecutionCompleted;
431 else
432 return Process::eExecutionSetupError;
Sean Callanan65dafa82010-08-27 01:01:44 +0000433 }
434 else
435 {
Johnny Chencb395442010-11-10 19:02:11 +0000436 error_stream.Printf("Expression can't be run; neither DWARF nor a JIT compiled function is present");
Jim Ingham360f53f2010-11-30 02:22:11 +0000437 return Process::eExecutionSetupError;
Sean Callanan65dafa82010-08-27 01:01:44 +0000438 }
439}
440
441StreamString &
442ClangUserExpression::DwarfOpcodeStream ()
443{
444 if (!m_dwarf_opcodes.get())
445 m_dwarf_opcodes.reset(new StreamString());
446
447 return *m_dwarf_opcodes.get();
448}
Greg Clayton377e0b42010-10-05 00:31:29 +0000449
Jim Ingham360f53f2010-11-30 02:22:11 +0000450Process::ExecutionResults
Sean Callanan77e93942010-10-29 00:29:03 +0000451ClangUserExpression::Evaluate (ExecutionContext &exe_ctx,
Jim Inghamea9d4262010-11-05 19:25:48 +0000452 bool discard_on_error,
Sean Callanan77e93942010-10-29 00:29:03 +0000453 const char *expr_cstr,
Jim Ingham360f53f2010-11-30 02:22:11 +0000454 const char *expr_prefix,
455 lldb::ValueObjectSP &result_valobj_sp)
Greg Clayton377e0b42010-10-05 00:31:29 +0000456{
457 Error error;
Jim Ingham360f53f2010-11-30 02:22:11 +0000458 Process::ExecutionResults execution_results = Process::eExecutionSetupError;
Greg Clayton0baa3942010-11-04 01:54:29 +0000459
460 if (exe_ctx.process == NULL)
Jim Ingham360f53f2010-11-30 02:22:11 +0000461 {
462 error.SetErrorString ("Must have a process to evaluate expressions.");
463
464 result_valobj_sp.reset (new ValueObjectConstResult (error));
465 return Process::eExecutionSetupError;
466 }
467
Greg Clayton0baa3942010-11-04 01:54:29 +0000468 if (!exe_ctx.process->GetDynamicCheckers())
469 {
470 DynamicCheckerFunctions *dynamic_checkers = new DynamicCheckerFunctions();
471
472 StreamString install_errors;
473
474 if (!dynamic_checkers->Install(install_errors, exe_ctx))
Sean Callananf7731452010-11-05 00:57:06 +0000475 {
476 if (install_errors.GetString().empty())
477 error.SetErrorString ("couldn't install checkers, unknown error");
478 else
479 error.SetErrorString (install_errors.GetString().c_str());
480
481 result_valobj_sp.reset (new ValueObjectConstResult (error));
Jim Ingham360f53f2010-11-30 02:22:11 +0000482 return Process::eExecutionSetupError;
Sean Callananf7731452010-11-05 00:57:06 +0000483 }
484
Greg Clayton0baa3942010-11-04 01:54:29 +0000485 exe_ctx.process->SetDynamicCheckers(dynamic_checkers);
486 }
487
Jim Ingham360f53f2010-11-30 02:22:11 +0000488 ClangUserExpressionSP user_expression_sp (new ClangUserExpression (expr_cstr, expr_prefix));
489
Greg Clayton377e0b42010-10-05 00:31:29 +0000490 StreamString error_stream;
491
Jim Ingham360f53f2010-11-30 02:22:11 +0000492 if (!user_expression_sp->Parse (error_stream, exe_ctx, TypeFromUser(NULL, NULL)))
Greg Clayton377e0b42010-10-05 00:31:29 +0000493 {
494 if (error_stream.GetString().empty())
495 error.SetErrorString ("expression failed to parse, unknown error");
496 else
497 error.SetErrorString (error_stream.GetString().c_str());
498 }
499 else
500 {
501 ClangExpressionVariable *expr_result = NULL;
502
503 error_stream.GetString().clear();
504
Jim Ingham360f53f2010-11-30 02:22:11 +0000505 execution_results = user_expression_sp->Execute (error_stream,
506 exe_ctx,
507 discard_on_error,
508 user_expression_sp,
509 expr_result);
510 if (execution_results != Process::eExecutionCompleted)
Greg Clayton377e0b42010-10-05 00:31:29 +0000511 {
512 if (error_stream.GetString().empty())
513 error.SetErrorString ("expression failed to execute, unknown error");
514 else
515 error.SetErrorString (error_stream.GetString().c_str());
516 }
517 else
518 {
519 // TODO: seems weird to get a pointer to a result object back from
520 // a function. Do we own it? Feels like we do, but from looking at the
521 // code we don't. Might be best to make this a reference and state
522 // explicitly that we don't own it when we get a reference back from
523 // the execute?
524 if (expr_result)
525 {
526 result_valobj_sp = expr_result->GetExpressionResult (&exe_ctx);
527 }
528 else
529 {
Sean Callanan44820ec2010-10-19 20:15:00 +0000530 error.SetErrorString ("Expression did not return a result");
Greg Clayton377e0b42010-10-05 00:31:29 +0000531 }
532 }
533 }
Sean Callanan44820ec2010-10-19 20:15:00 +0000534
Greg Claytond1719722010-10-05 03:13:51 +0000535 if (result_valobj_sp.get() == NULL)
536 result_valobj_sp.reset (new ValueObjectConstResult (error));
537
Jim Ingham360f53f2010-11-30 02:22:11 +0000538 return execution_results;
Johnny Chenb4c0f022010-10-29 20:19:44 +0000539}