size_t EmulateInstruction::WriteMemoryDefault (EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, const void *dst, size_t length) { StreamFile strm (stdout, false); strm.Printf (" Write to Memory (address = 0x%" PRIx64 ", length = %" PRIu64 ", context = ", addr, (uint64_t)length); context.Dump (strm, instruction); strm.EOL(); return length; }
bool EmulateInstruction::WriteRegisterDefault (EmulateInstruction *instruction, void *baton, const Context &context, const RegisterInfo *reg_info, const RegisterValue ®_value) { StreamFile strm (stdout, false); strm.Printf (" Write to Register (name = %s, value = " , reg_info->name); reg_value.Dump(&strm, reg_info, false, false, eFormatDefault); strm.PutCString (", context = "); context.Dump (strm, instruction); strm.EOL(); return true; }
bool EmulateInstruction::ReadRegisterDefault (EmulateInstruction *instruction, void *baton, const RegisterInfo *reg_info, RegisterValue ®_value) { StreamFile strm (stdout, false); strm.Printf (" Read Register (%s)\n", reg_info->name); lldb::RegisterKind reg_kind; uint32_t reg_num; if (GetBestRegisterKindAndNumber (reg_info, reg_kind, reg_num)) reg_value.SetUInt64((uint64_t)reg_kind << 24 | reg_num); else reg_value.SetUInt64(0); return true; }
//------------------------------------------------------------------ /// Install the utility function into a process /// /// @param[in] error_stream /// A stream to print parse errors and warnings to. /// /// @param[in] exe_ctx /// The execution context to install the utility function to. /// /// @return /// True on success (no errors); false otherwise. //------------------------------------------------------------------ bool ClangUtilityFunction::Install (Stream &error_stream, ExecutionContext &exe_ctx) { lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { error_stream.PutCString("error: already installed\n"); return false; } //////////////////////////////////// // Set up the target and compiler // Target *target = exe_ctx.GetTargetPtr(); if (!target) { error_stream.PutCString ("error: invalid target\n"); return false; } Process *process = exe_ctx.GetProcessPtr(); if (!process) { error_stream.PutCString ("error: invalid process\n"); return false; } ////////////////////////// // Parse the expression // bool keep_result_in_memory = false; m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx)); m_data_allocator.reset(new ProcessDataAllocator(*process)); if (!m_expr_decl_map->WillParse(exe_ctx)) { error_stream.PutCString ("error: current process state is unsuitable for expression parsing\n"); return false; } ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this); unsigned num_errors = parser.Parse (error_stream); if (num_errors) { error_stream.Printf ("error: %d errors parsing expression\n", num_errors); m_expr_decl_map.reset(); return false; } ////////////////////////////////// // JIT the output of the parser // lldb::ClangExpressionVariableSP const_result; bool evaluated_statically = false; // should stay that way Error jit_error = parser.PrepareForExecution (m_jit_alloc, m_jit_start_addr, m_jit_end_addr, exe_ctx, m_data_allocator.get(), evaluated_statically, const_result, eExecutionPolicyAlways); if (log) { StreamString dump_string; m_data_allocator->Dump(dump_string); log->Printf("Data buffer contents:\n%s", dump_string.GetString().c_str()); } if (m_jit_start_addr != LLDB_INVALID_ADDRESS) m_jit_process_wp = lldb::ProcessWP(process->shared_from_this()); #if 0 // jingham: look here StreamFile logfile ("/tmp/exprs.txt", "a"); logfile.Printf ("0x%16.16" PRIx64 ": func = %s, source =\n%s\n", m_jit_start_addr, m_function_name.c_str(), m_function_text.c_str()); #endif m_expr_decl_map->DidParse(); m_expr_decl_map.reset(); if (jit_error.Success()) { return true; } else { const char *error_cstr = jit_error.AsCString(); if (error_cstr && error_cstr[0]) error_stream.Printf ("error: %s\n", error_cstr); else error_stream.Printf ("error: expression can't be interpreted or run\n"); return false; } }
//------------------------------------------------------------------ /// Install the utility function into a process /// /// @param[in] error_stream /// A stream to print parse errors and warnings to. /// /// @param[in] exe_ctx /// The execution context to install the utility function to. /// /// @return /// True on success (no errors); false otherwise. //------------------------------------------------------------------ bool ClangUtilityFunction::Install (Stream &error_stream, ExecutionContext &exe_ctx) { if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { error_stream.PutCString("error: already installed\n"); return false; } //////////////////////////////////// // Set up the target and compiler // Target *target = exe_ctx.GetTargetPtr(); if (!target) { error_stream.PutCString ("error: invalid target\n"); return false; } Process *process = exe_ctx.GetProcessPtr(); if (!process) { error_stream.PutCString ("error: invalid process\n"); return false; } ////////////////////////// // Parse the expression // bool keep_result_in_memory = false; m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx)); if (!m_expr_decl_map->WillParse(exe_ctx, NULL)) { error_stream.PutCString ("error: current process state is unsuitable for expression parsing\n"); return false; } ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this); unsigned num_errors = parser.Parse (error_stream); if (num_errors) { error_stream.Printf ("error: %d errors parsing expression\n", num_errors); m_expr_decl_map.reset(); return false; } ////////////////////////////////// // JIT the output of the parser // bool can_interpret = false; // should stay that way Error jit_error = parser.PrepareForExecution (m_jit_start_addr, m_jit_end_addr, m_execution_unit_ap, exe_ctx, can_interpret, eExecutionPolicyAlways); if (m_jit_start_addr != LLDB_INVALID_ADDRESS) m_jit_process_wp = lldb::ProcessWP(process->shared_from_this()); #if 0 // jingham: look here StreamFile logfile ("/tmp/exprs.txt", "a"); logfile.Printf ("0x%16.16" PRIx64 ": func = %s, source =\n%s\n", m_jit_start_addr, m_function_name.c_str(), m_function_text.c_str()); #endif m_expr_decl_map->DidParse(); m_expr_decl_map.reset(); if (jit_error.Success()) { return true; } else { const char *error_cstr = jit_error.AsCString(); if (error_cstr && error_cstr[0]) error_stream.Printf ("error: %s\n", error_cstr); else error_stream.Printf ("error: expression can't be interpreted or run\n"); return false; } }
//------------------------------------------------------------------ /// Install the utility function into a process /// /// @param[in] diagnostic_manager /// A diagnostic manager to report errors and warnings to. /// /// @param[in] exe_ctx /// The execution context to install the utility function to. /// /// @return /// True on success (no errors); false otherwise. //------------------------------------------------------------------ bool ClangUtilityFunction::Install(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) { if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { diagnostic_manager.PutCString(eDiagnosticSeverityWarning, "already installed"); return false; } //////////////////////////////////// // Set up the target and compiler // Target *target = exe_ctx.GetTargetPtr(); if (!target) { diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid target"); return false; } Process *process = exe_ctx.GetProcessPtr(); if (!process) { diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid process"); return false; } ////////////////////////// // Parse the expression // bool keep_result_in_memory = false; ResetDeclMap(exe_ctx, keep_result_in_memory); if (!DeclMap()->WillParse(exe_ctx, NULL)) { diagnostic_manager.PutCString( eDiagnosticSeverityError, "current process state is unsuitable for expression parsing"); return false; } const bool generate_debug_info = true; ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this, generate_debug_info); unsigned num_errors = parser.Parse(diagnostic_manager); if (num_errors) { ResetDeclMap(); return false; } ////////////////////////////////// // JIT the output of the parser // bool can_interpret = false; // should stay that way Error jit_error = parser.PrepareForExecution( m_jit_start_addr, m_jit_end_addr, m_execution_unit_sp, exe_ctx, can_interpret, eExecutionPolicyAlways); if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { m_jit_process_wp = process->shared_from_this(); if (parser.GetGenerateDebugInfo()) m_execution_unit_sp->CreateJITModule(FunctionName()); } #if 0 // jingham: look here StreamFile logfile ("/tmp/exprs.txt", "a"); logfile.Printf ("0x%16.16" PRIx64 ": func = %s, source =\n%s\n", m_jit_start_addr, m_function_name.c_str(), m_function_text.c_str()); #endif DeclMap()->DidParse(); ResetDeclMap(); if (jit_error.Success()) { return true; } else { const char *error_cstr = jit_error.AsCString(); if (error_cstr && error_cstr[0]) { diagnostic_manager.Printf(eDiagnosticSeverityError, "%s", error_cstr); } else { diagnostic_manager.PutCString(eDiagnosticSeverityError, "expression can't be interpreted or run"); } return false; } }