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 @@ -226,6 +226,9 @@ virtual bool IsCall() { return false; } + static const char *GetNameForInstructionControlFlowKind( + lldb::InstructionControlFlowKind instruction_control_flow_kind); + protected: Address m_address; // The section offset address of this instruction // We include an address class in the Instruction class to diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -972,6 +972,8 @@ /// control flow of a trace. /// /// A single instruction can match one or more of these categories. +/// The enum -> string conversion is in Disassembler.cpp, don't change +/// this enum without updating that code as well. enum InstructionControlFlowKind { /// The instruction could not be classified. eInstructionControlFlowKindUnknown = 0, 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 @@ -577,6 +577,30 @@ return m_address_class; } +const char *Instruction::GetNameForInstructionControlFlowKind( + lldb::InstructionControlFlowKind instruction_control_flow_kind) { + switch (instruction_control_flow_kind) { + case eInstructionControlFlowKindUnknown: + return "unknown"; + case eInstructionControlFlowKindOther: + return "other"; + case eInstructionControlFlowKindCall: + return "call"; + case eInstructionControlFlowKindReturn: + return "return"; + case eInstructionControlFlowKindJump: + return "jump"; + case eInstructionControlFlowKindCondJump: + return "cond jump"; + case eInstructionControlFlowKindFarCall: + return "far call"; + case eInstructionControlFlowKindFarReturn: + return "far return"; + case eInstructionControlFlowKindFarJump: + return "far jump"; + } +} + void Instruction::Dump(lldb_private::Stream *s, uint32_t max_opcode_byte_size, bool show_address, bool show_bytes, bool show_control_flow_kind, @@ -618,35 +642,10 @@ } if (show_control_flow_kind) { - switch (GetControlFlowKind(exe_ctx)) { - case eInstructionControlFlowKindUnknown: - ss.Printf("%-12s", "unknown"); - break; - case eInstructionControlFlowKindOther: - ss.Printf("%-12s", "other"); - break; - case eInstructionControlFlowKindCall: - ss.Printf("%-12s", "call"); - break; - case eInstructionControlFlowKindReturn: - ss.Printf("%-12s", "return"); - break; - case eInstructionControlFlowKindJump: - ss.Printf("%-12s", "jump"); - break; - case eInstructionControlFlowKindCondJump: - ss.Printf("%-12s", "cond jump"); - break; - case eInstructionControlFlowKindFarCall: - ss.Printf("%-12s", "far call"); - break; - case eInstructionControlFlowKindFarReturn: - ss.Printf("%-12s", "far return"); - break; - case eInstructionControlFlowKindFarJump: - ss.Printf("%-12s", "far jump"); - break; - } + lldb::InstructionControlFlowKind instruction_control_flow_kind = + GetControlFlowKind(exe_ctx); + ss.Printf("%-12s", GetNameForInstructionControlFlowKind( + instruction_control_flow_kind)); } const size_t opcode_pos = ss.GetSizeOfLastLine();