comparison lldb/source/Expression/UserExpression.cpp @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
comparison
equal deleted inserted replaced
172:9fbae9c8bf63 173:0572611fdcc8
166 : UserExpression::eResultTypeAny; 166 : UserExpression::eResultTypeAny;
167 lldb::ExpressionResults execution_results = lldb::eExpressionSetupError; 167 lldb::ExpressionResults execution_results = lldb::eExpressionSetupError;
168 168
169 Target *target = exe_ctx.GetTargetPtr(); 169 Target *target = exe_ctx.GetTargetPtr();
170 if (!target) { 170 if (!target) {
171 LLDB_LOGF(log, "== [UserExpression::Evaluate] Passed a NULL target, can't " 171 LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a NULL target, can't "
172 "run expressions."); 172 "run expressions.");
173 error.SetErrorString("expression passed a null target"); 173 error.SetErrorString("expression passed a null target");
174 return lldb::eExpressionSetupError; 174 return lldb::eExpressionSetupError;
175 } 175 }
176 176
177 Process *process = exe_ctx.GetProcessPtr(); 177 Process *process = exe_ctx.GetProcessPtr();
178 178
179 if (process == nullptr || process->GetState() != lldb::eStateStopped) { 179 if (process == nullptr || process->GetState() != lldb::eStateStopped) {
180 if (execution_policy == eExecutionPolicyAlways) { 180 if (execution_policy == eExecutionPolicyAlways) {
181 LLDB_LOGF(log, 181 LLDB_LOG(log, "== [UserExpression::Evaluate] Expression may not run, but "
182 "== [UserExpression::Evaluate] Expression may not run, but " 182 "is not constant ==");
183 "is not constant ==");
184 183
185 error.SetErrorString("expression needed to run but couldn't"); 184 error.SetErrorString("expression needed to run but couldn't");
186 185
187 return execution_results; 186 return execution_results;
188 } 187 }
223 lldb::UserExpressionSP user_expression_sp( 222 lldb::UserExpressionSP user_expression_sp(
224 target->GetUserExpressionForLanguage(expr, full_prefix, language, 223 target->GetUserExpressionForLanguage(expr, full_prefix, language,
225 desired_type, options, ctx_obj, 224 desired_type, options, ctx_obj,
226 error)); 225 error));
227 if (error.Fail()) { 226 if (error.Fail()) {
228 if (log) 227 LLDB_LOG(log, "== [UserExpression::Evaluate] Getting expression: {0} ==",
229 LLDB_LOGF(log, "== [UserExpression::Evaluate] Getting expression: %s ==", 228 error.AsCString());
230 error.AsCString());
231 return lldb::eExpressionSetupError; 229 return lldb::eExpressionSetupError;
232 } 230 }
233 231
234 if (log) 232 LLDB_LOG(log, "== [UserExpression::Evaluate] Parsing expression {0} ==",
235 LLDB_LOGF(log, "== [UserExpression::Evaluate] Parsing expression %s ==", 233 expr.str());
236 expr.str().c_str());
237 234
238 const bool keep_expression_in_memory = true; 235 const bool keep_expression_in_memory = true;
239 const bool generate_debug_info = options.GetGenerateDebugInfo(); 236 const bool generate_debug_info = options.GetGenerateDebugInfo();
240 237
241 if (options.InvokeCancelCallback(lldb::eExpressionEvaluationParse)) { 238 if (options.InvokeCancelCallback(lldb::eExpressionEvaluationParse)) {
260 if (fixed_text != nullptr) 257 if (fixed_text != nullptr)
261 fixed_expression->append(fixed_text); 258 fixed_expression->append(fixed_text);
262 259
263 // If there is a fixed expression, try to parse it: 260 // If there is a fixed expression, try to parse it:
264 if (!parse_success) { 261 if (!parse_success) {
262 // Delete the expression that failed to parse before attempting to parse
263 // the next expression.
264 user_expression_sp.reset();
265
265 execution_results = lldb::eExpressionParseError; 266 execution_results = lldb::eExpressionParseError;
266 if (fixed_expression && !fixed_expression->empty() && 267 if (fixed_expression && !fixed_expression->empty() &&
267 options.GetAutoApplyFixIts()) { 268 options.GetAutoApplyFixIts()) {
268 lldb::UserExpressionSP fixed_expression_sp( 269 const uint64_t max_fix_retries = options.GetRetriesWithFixIts();
269 target->GetUserExpressionForLanguage(fixed_expression->c_str(), 270 for (uint64_t i = 0; i < max_fix_retries; ++i) {
270 full_prefix, language, 271 // Try parsing the fixed expression.
271 desired_type, options, ctx_obj, 272 lldb::UserExpressionSP fixed_expression_sp(
272 error)); 273 target->GetUserExpressionForLanguage(
273 DiagnosticManager fixed_diagnostic_manager; 274 fixed_expression->c_str(), full_prefix, language, desired_type,
274 parse_success = fixed_expression_sp->Parse( 275 options, ctx_obj, error));
275 fixed_diagnostic_manager, exe_ctx, execution_policy, 276 DiagnosticManager fixed_diagnostic_manager;
276 keep_expression_in_memory, generate_debug_info); 277 parse_success = fixed_expression_sp->Parse(
277 if (parse_success) { 278 fixed_diagnostic_manager, exe_ctx, execution_policy,
278 diagnostic_manager.Clear(); 279 keep_expression_in_memory, generate_debug_info);
279 user_expression_sp = fixed_expression_sp; 280 if (parse_success) {
280 } else { 281 diagnostic_manager.Clear();
281 // If the fixed expression failed to parse, don't tell the user about, 282 user_expression_sp = fixed_expression_sp;
282 // that won't help. 283 break;
283 fixed_expression->clear(); 284 } else {
285 // The fixed expression also didn't parse. Let's check for any new
286 // Fix-Its we could try.
287 if (fixed_expression_sp->GetFixedText()) {
288 *fixed_expression = fixed_expression_sp->GetFixedText();
289 } else {
290 // Fixed expression didn't compile without a fixit, don't retry and
291 // don't tell the user about it.
292 fixed_expression->clear();
293 break;
294 }
295 }
284 } 296 }
285 } 297 }
286 298
287 if (!parse_success) { 299 if (!parse_success) {
288 if (!fixed_expression->empty() && target->GetEnableNotifyAboutFixIts()) { 300 if (!fixed_expression->empty() && target->GetEnableNotifyAboutFixIts()) {
304 if (parse_success) { 316 if (parse_success) {
305 lldb::ExpressionVariableSP expr_result; 317 lldb::ExpressionVariableSP expr_result;
306 318
307 if (execution_policy == eExecutionPolicyNever && 319 if (execution_policy == eExecutionPolicyNever &&
308 !user_expression_sp->CanInterpret()) { 320 !user_expression_sp->CanInterpret()) {
309 if (log) 321 LLDB_LOG(log, "== [UserExpression::Evaluate] Expression may not run, but "
310 LLDB_LOGF(log, 322 "is not constant ==");
311 "== [UserExpression::Evaluate] Expression may not run, but "
312 "is not constant ==");
313 323
314 if (!diagnostic_manager.Diagnostics().size()) 324 if (!diagnostic_manager.Diagnostics().size())
315 error.SetExpressionError(lldb::eExpressionSetupError, 325 error.SetExpressionError(lldb::eExpressionSetupError,
316 "expression needed to run but couldn't"); 326 "expression needed to run but couldn't");
317 } else if (execution_policy == eExecutionPolicyTopLevel) { 327 } else if (execution_policy == eExecutionPolicyTopLevel) {
327 return lldb::eExpressionInterrupted; 337 return lldb::eExpressionInterrupted;
328 } 338 }
329 339
330 diagnostic_manager.Clear(); 340 diagnostic_manager.Clear();
331 341
332 if (log) 342 LLDB_LOG(log, "== [UserExpression::Evaluate] Executing expression ==");
333 LLDB_LOGF(log, "== [UserExpression::Evaluate] Executing expression ==");
334 343
335 execution_results = 344 execution_results =
336 user_expression_sp->Execute(diagnostic_manager, exe_ctx, options, 345 user_expression_sp->Execute(diagnostic_manager, exe_ctx, options,
337 user_expression_sp, expr_result); 346 user_expression_sp, expr_result);
338 347
339 if (execution_results != lldb::eExpressionCompleted) { 348 if (execution_results != lldb::eExpressionCompleted) {
340 if (log) 349 LLDB_LOG(log, "== [UserExpression::Evaluate] Execution completed "
341 LLDB_LOGF(log, "== [UserExpression::Evaluate] Execution completed " 350 "abnormally ==");
342 "abnormally ==");
343 351
344 if (!diagnostic_manager.Diagnostics().size()) 352 if (!diagnostic_manager.Diagnostics().size())
345 error.SetExpressionError( 353 error.SetExpressionError(
346 execution_results, "expression failed to execute, unknown error"); 354 execution_results, "expression failed to execute, unknown error");
347 else 355 else
349 diagnostic_manager.GetString().c_str()); 357 diagnostic_manager.GetString().c_str());
350 } else { 358 } else {
351 if (expr_result) { 359 if (expr_result) {
352 result_valobj_sp = expr_result->GetValueObject(); 360 result_valobj_sp = expr_result->GetValueObject();
353 361
354 if (log) 362 LLDB_LOG(log,
355 LLDB_LOGF(log, 363 "== [UserExpression::Evaluate] Execution completed "
356 "== [UserExpression::Evaluate] Execution completed " 364 "normally with result %s ==",
357 "normally with result %s ==", 365 result_valobj_sp->GetValueAsCString());
358 result_valobj_sp->GetValueAsCString());
359 } else { 366 } else {
360 if (log) 367 LLDB_LOG(log, "== [UserExpression::Evaluate] Execution completed "
361 LLDB_LOGF(log, "== [UserExpression::Evaluate] Execution completed " 368 "normally with no result ==");
362 "normally with no result ==");
363 369
364 error.SetError(UserExpression::kNoResult, lldb::eErrorTypeGeneric); 370 error.SetError(UserExpression::kNoResult, lldb::eErrorTypeGeneric);
365 } 371 }
366 } 372 }
367 } 373 }