diff --git a/lldb/include/lldb/Core/Disassembler.h b/lldb/include/lldb/Core/Disassembler.h --- a/lldb/include/lldb/Core/Disassembler.h +++ b/lldb/include/lldb/Core/Disassembler.h @@ -176,14 +176,14 @@ virtual void SetDescription(llvm::StringRef) { } // May be overridden in sub-classes that have descriptions. - lldb::OptionValueSP ReadArray(FILE *in_file, Stream *out_stream, + lldb::OptionValueSP ReadArray(FILE *in_file, Stream &out_stream, OptionValue::Type data_type); - lldb::OptionValueSP ReadDictionary(FILE *in_file, Stream *out_stream); + lldb::OptionValueSP ReadDictionary(FILE *in_file, Stream &out_stream); bool DumpEmulation(const ArchSpec &arch); - virtual bool TestEmulation(Stream *stream, const char *test_file_name); + virtual bool TestEmulation(Stream &stream, const char *test_file_name); bool Emulate(const ArchSpec &arch, uint32_t evaluate_options, void *baton, EmulateInstruction::ReadMemoryCallback read_mem_callback, diff --git a/lldb/include/lldb/Core/EmulateInstruction.h b/lldb/include/lldb/Core/EmulateInstruction.h --- a/lldb/include/lldb/Core/EmulateInstruction.h +++ b/lldb/include/lldb/Core/EmulateInstruction.h @@ -375,7 +375,7 @@ return UnconditionalCondition; } - virtual bool TestEmulation(Stream *out_stream, ArchSpec &arch, + virtual bool TestEmulation(Stream &out_stream, ArchSpec &arch, OptionValueDictionary *test_data) = 0; virtual std::optional diff --git a/lldb/source/API/SBInstruction.cpp b/lldb/source/API/SBInstruction.cpp --- a/lldb/source/API/SBInstruction.cpp +++ b/lldb/source/API/SBInstruction.cpp @@ -345,6 +345,6 @@ lldb::InstructionSP inst_sp(GetOpaque()); if (inst_sp) - return inst_sp->TestEmulation(output_stream.get(), test_file); + return inst_sp->TestEmulation(output_stream.ref(), test_file); return false; } diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp --- a/lldb/source/Core/Disassembler.cpp +++ b/lldb/source/Core/Disassembler.cpp @@ -687,7 +687,7 @@ return false; } -OptionValueSP Instruction::ReadArray(FILE *in_file, Stream *out_stream, +OptionValueSP Instruction::ReadArray(FILE *in_file, Stream &out_stream, OptionValue::Type data_type) { bool done = false; char buffer[1024]; @@ -697,7 +697,7 @@ int idx = 0; while (!done) { if (!fgets(buffer, 1023, in_file)) { - out_stream->Printf( + out_stream.Printf( "Instruction::ReadArray: Error reading file (fgets).\n"); option_value_sp.reset(); return option_value_sp; @@ -746,7 +746,7 @@ return option_value_sp; } -OptionValueSP Instruction::ReadDictionary(FILE *in_file, Stream *out_stream) { +OptionValueSP Instruction::ReadDictionary(FILE *in_file, Stream &out_stream) { bool done = false; char buffer[1024]; @@ -757,7 +757,7 @@ while (!done) { // Read the next line in the file if (!fgets(buffer, 1023, in_file)) { - out_stream->Printf( + out_stream.Printf( "Instruction::ReadDictionary: Error reading file (fgets).\n"); option_value_sp.reset(); return option_value_sp; @@ -792,8 +792,8 @@ key = matches[1].str(); value = matches[2].str(); } else { - out_stream->Printf("Instruction::ReadDictionary: Failure executing " - "regular expression.\n"); + out_stream.Printf("Instruction::ReadDictionary: Failure executing " + "regular expression.\n"); option_value_sp.reset(); return option_value_sp; } @@ -848,32 +848,29 @@ return option_value_sp; } -bool Instruction::TestEmulation(Stream *out_stream, const char *file_name) { - if (!out_stream) - return false; - +bool Instruction::TestEmulation(Stream &out_stream, const char *file_name) { if (!file_name) { - out_stream->Printf("Instruction::TestEmulation: Missing file_name."); + out_stream.Printf("Instruction::TestEmulation: Missing file_name."); return false; } FILE *test_file = FileSystem::Instance().Fopen(file_name, "r"); if (!test_file) { - out_stream->Printf( + out_stream.Printf( "Instruction::TestEmulation: Attempt to open test file failed."); return false; } char buffer[256]; if (!fgets(buffer, 255, test_file)) { - out_stream->Printf( + out_stream.Printf( "Instruction::TestEmulation: Error reading first line of test file.\n"); fclose(test_file); return false; } if (strncmp(buffer, "InstructionEmulationState={", 27) != 0) { - out_stream->Printf("Instructin::TestEmulation: Test file does not contain " - "emulation state dictionary\n"); + out_stream.Printf("Instructin::TestEmulation: Test file does not contain " + "emulation state dictionary\n"); fclose(test_file); return false; } @@ -883,7 +880,7 @@ OptionValueSP data_dictionary_sp(ReadDictionary(test_file, out_stream)); if (!data_dictionary_sp) { - out_stream->Printf( + out_stream.Printf( "Instruction::TestEmulation: Error reading Dictionary Object.\n"); fclose(test_file); return false; @@ -899,8 +896,8 @@ OptionValueSP value_sp = data_dictionary->GetValueForKey(description_key); if (!value_sp) { - out_stream->Printf("Instruction::TestEmulation: Test file does not " - "contain description string.\n"); + out_stream.Printf("Instruction::TestEmulation: Test file does not " + "contain description string.\n"); return false; } @@ -908,7 +905,7 @@ value_sp = data_dictionary->GetValueForKey(triple_key); if (!value_sp) { - out_stream->Printf( + out_stream.Printf( "Instruction::TestEmulation: Test file does not contain triple.\n"); return false; } @@ -925,9 +922,9 @@ insn_emulator_up->TestEmulation(out_stream, arch, data_dictionary); if (success) - out_stream->Printf("Emulation test succeeded."); + out_stream.Printf("Emulation test succeeded."); else - out_stream->Printf("Emulation test failed."); + out_stream.Printf("Emulation test failed."); return success; } diff --git a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h --- a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h +++ b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h @@ -132,7 +132,7 @@ InstructionCondition GetInstructionCondition() override; - bool TestEmulation(Stream *out_stream, ArchSpec &arch, + bool TestEmulation(Stream &out_stream, ArchSpec &arch, OptionValueDictionary *test_data) override; std::optional GetRegisterInfo(lldb::RegisterKind reg_kind, diff --git a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp --- a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp +++ b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp @@ -14345,10 +14345,10 @@ return cond; } -bool EmulateInstructionARM::TestEmulation(Stream *out_stream, ArchSpec &arch, +bool EmulateInstructionARM::TestEmulation(Stream &out_stream, ArchSpec &arch, OptionValueDictionary *test_data) { if (!test_data) { - out_stream->Printf("TestEmulation: Missing test data.\n"); + out_stream.Printf("TestEmulation: Missing test data.\n"); return false; } @@ -14361,7 +14361,7 @@ uint32_t test_opcode; if ((value_sp.get() == nullptr) || (value_sp->GetType() != OptionValue::eTypeUInt64)) { - out_stream->Printf("TestEmulation: Error reading opcode from test file.\n"); + out_stream.Printf("TestEmulation: Error reading opcode from test file.\n"); return false; } test_opcode = value_sp->GetValueAs().value_or(0); @@ -14377,7 +14377,7 @@ m_opcode_mode = eModeARM; m_opcode.SetOpcode32(test_opcode, endian::InlHostByteOrder()); } else { - out_stream->Printf("TestEmulation: Invalid arch.\n"); + out_stream.Printf("TestEmulation: Invalid arch.\n"); return false; } @@ -14387,26 +14387,26 @@ value_sp = test_data->GetValueForKey(before_key); if ((value_sp.get() == nullptr) || (value_sp->GetType() != OptionValue::eTypeDictionary)) { - out_stream->Printf("TestEmulation: Failed to find 'before' state.\n"); + out_stream.Printf("TestEmulation: Failed to find 'before' state.\n"); return false; } OptionValueDictionary *state_dictionary = value_sp->GetAsDictionary(); if (!before_state.LoadStateFromDictionary(state_dictionary)) { - out_stream->Printf("TestEmulation: Failed loading 'before' state.\n"); + out_stream.Printf("TestEmulation: Failed loading 'before' state.\n"); return false; } value_sp = test_data->GetValueForKey(after_key); if ((value_sp.get() == nullptr) || (value_sp->GetType() != OptionValue::eTypeDictionary)) { - out_stream->Printf("TestEmulation: Failed to find 'after' state.\n"); + out_stream.Printf("TestEmulation: Failed to find 'after' state.\n"); return false; } state_dictionary = value_sp->GetAsDictionary(); if (!after_state.LoadStateFromDictionary(state_dictionary)) { - out_stream->Printf("TestEmulation: Failed loading 'after' state.\n"); + out_stream.Printf("TestEmulation: Failed loading 'after' state.\n"); return false; } @@ -14418,14 +14418,14 @@ bool success = EvaluateInstruction(eEmulateInstructionOptionAutoAdvancePC); if (!success) { - out_stream->Printf("TestEmulation: EvaluateInstruction() failed.\n"); + out_stream.Printf("TestEmulation: EvaluateInstruction() failed.\n"); return false; } success = before_state.CompareState(after_state, out_stream); if (!success) - out_stream->Printf( - "TestEmulation: State after emulation does not match 'after' state.\n"); + out_stream.Printf("TestEmulation: State after emulation does not match " + "'after' state.\n"); return success; } diff --git a/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.h b/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.h --- a/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.h +++ b/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.h @@ -35,7 +35,7 @@ bool LoadStateFromDictionary(lldb_private::OptionValueDictionary *test_data); bool CompareState(EmulationStateARM &other_state, - lldb_private::Stream *out_stream); + lldb_private::Stream &out_stream); static size_t ReadPseudoMemory(lldb_private::EmulateInstruction *instruction, void *baton, diff --git a/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp b/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp --- a/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp +++ b/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp @@ -215,44 +215,43 @@ } bool EmulationStateARM::CompareState(EmulationStateARM &other_state, - Stream *out_stream) { + Stream &out_stream) { bool match = true; for (int i = 0; match && i < 17; ++i) { if (m_gpr[i] != other_state.m_gpr[i]) { match = false; - out_stream->Printf("r%d: 0x%x != 0x%x\n", i, m_gpr[i], - other_state.m_gpr[i]); + out_stream.Printf("r%d: 0x%x != 0x%x\n", i, m_gpr[i], + other_state.m_gpr[i]); } } for (int i = 0; match && i < 32; ++i) { if (m_vfp_regs.s_regs[i] != other_state.m_vfp_regs.s_regs[i]) { match = false; - out_stream->Printf("s%d: 0x%x != 0x%x\n", i, m_vfp_regs.s_regs[i], - other_state.m_vfp_regs.s_regs[i]); + out_stream.Printf("s%d: 0x%x != 0x%x\n", i, m_vfp_regs.s_regs[i], + other_state.m_vfp_regs.s_regs[i]); } } for (int i = 0; match && i < 16; ++i) { if (m_vfp_regs.d_regs[i] != other_state.m_vfp_regs.d_regs[i]) { match = false; - out_stream->Printf("d%d: 0x%" PRIx64 " != 0x%" PRIx64 "\n", i + 16, - m_vfp_regs.d_regs[i], - other_state.m_vfp_regs.d_regs[i]); + out_stream.Printf("d%d: 0x%" PRIx64 " != 0x%" PRIx64 "\n", i + 16, + m_vfp_regs.d_regs[i], other_state.m_vfp_regs.d_regs[i]); } } // other_state is the expected state. If it has memory, check it. if (!other_state.m_memory.empty() && m_memory != other_state.m_memory) { match = false; - out_stream->Printf("memory does not match\n"); - out_stream->Printf("got memory:\n"); + out_stream.Printf("memory does not match\n"); + out_stream.Printf("got memory:\n"); for (auto p : m_memory) - out_stream->Printf("0x%08" PRIx64 ": 0x%08x\n", p.first, p.second); - out_stream->Printf("expected memory:\n"); + out_stream.Printf("0x%08" PRIx64 ": 0x%08x\n", p.first, p.second); + out_stream.Printf("expected memory:\n"); for (auto p : other_state.m_memory) - out_stream->Printf("0x%08" PRIx64 ": 0x%08x\n", p.first, p.second); + out_stream.Printf("0x%08" PRIx64 ": 0x%08x\n", p.first, p.second); } return match; diff --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h --- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h +++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h @@ -60,7 +60,7 @@ bool EvaluateInstruction(uint32_t evaluate_options) override; - bool TestEmulation(lldb_private::Stream *out_stream, + bool TestEmulation(lldb_private::Stream &out_stream, lldb_private::ArchSpec &arch, lldb_private::OptionValueDictionary *test_data) override { return false; diff --git a/lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.h b/lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.h --- a/lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.h +++ b/lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.h @@ -52,7 +52,7 @@ bool SetTargetTriple(const ArchSpec &arch) override; bool ReadInstruction() override; bool EvaluateInstruction(uint32_t options) override; - bool TestEmulation(Stream *out_stream, ArchSpec &arch, + bool TestEmulation(Stream &out_stream, ArchSpec &arch, OptionValueDictionary *test_data) override; std::optional GetRegisterInfo(lldb::RegisterKind reg_kind, diff --git a/lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.cpp b/lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.cpp --- a/lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.cpp +++ b/lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.cpp @@ -187,7 +187,7 @@ } bool EmulateInstructionLoongArch::TestEmulation( - Stream *out_stream, ArchSpec &arch, OptionValueDictionary *test_data) { + Stream &out_stream, ArchSpec &arch, OptionValueDictionary *test_data) { return false; } diff --git a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h --- a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h +++ b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h @@ -75,7 +75,7 @@ const lldb_private::Address &inst_addr, lldb_private::Target *target) override; - bool TestEmulation(lldb_private::Stream *out_stream, + bool TestEmulation(lldb_private::Stream &out_stream, lldb_private::ArchSpec &arch, lldb_private::OptionValueDictionary *test_data) override { return false; diff --git a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h --- a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h +++ b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h @@ -67,7 +67,7 @@ bool EvaluateInstruction(uint32_t evaluate_options) override; - bool TestEmulation(lldb_private::Stream *out_stream, + bool TestEmulation(lldb_private::Stream &out_stream, lldb_private::ArchSpec &arch, lldb_private::OptionValueDictionary *test_data) override { return false; diff --git a/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h b/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h --- a/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h +++ b/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h @@ -57,7 +57,7 @@ bool EvaluateInstruction(uint32_t evaluate_options) override; - bool TestEmulation(Stream *out_stream, ArchSpec &arch, + bool TestEmulation(Stream &out_stream, ArchSpec &arch, OptionValueDictionary *test_data) override { return false; } diff --git a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h --- a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h +++ b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h @@ -61,7 +61,7 @@ bool SetTargetTriple(const ArchSpec &arch) override; bool ReadInstruction() override; bool EvaluateInstruction(uint32_t options) override; - bool TestEmulation(Stream *out_stream, ArchSpec &arch, + bool TestEmulation(Stream &out_stream, ArchSpec &arch, OptionValueDictionary *test_data) override; std::optional GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) override; diff --git a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp --- a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp +++ b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp @@ -1748,7 +1748,7 @@ return SupportsThisArch(arch); } -bool EmulateInstructionRISCV::TestEmulation(Stream *out_stream, ArchSpec &arch, +bool EmulateInstructionRISCV::TestEmulation(Stream &out_stream, ArchSpec &arch, OptionValueDictionary *test_data) { return false; }