Skip to content

Commit d36ae49

Browse files
committed
Add string conversion for InstructionControlFlowKind enum
Refactor the string conversion of the `lldb::InstructionControlFlowKind` enum out of `Instruction::Dump` to enable reuse of this logic by the JSON TraceDumper (to be implemented in separate diff). Will coordinate the landing of this change with D130320 since there will be a minor merge conflict between these changes. Test Plan: Run unittests ``` > ninja check-lldb [4/5] Running lldb unit test suite Testing Time: 10.13s Passed: 1084 ``` Verify '-k' flag's output ``` (lldb) thread trace dump instructions -k thread hfinkel#1: tid = 1375377 libstdc++.so.6`std::ostream::flush() + 43 7048: 0x00007ffff7b54dab return retq 7047: 0x00007ffff7b54daa other popq %rbx 7046: 0x00007ffff7b54da7 other movq %rbx, %rax 7045: 0x00007ffff7b54da5 cond jump je 0x11adb0 ; <+48> 7044: 0x00007ffff7b54da2 other cmpl $-0x1, %eax libc.so.6`_IO_fflush + 249 7043: 0x00007ffff7161729 return retq 7042: 0x00007ffff7161728 other popq %rbp 7041: 0x00007ffff7161727 other popq %rbx 7040: 0x00007ffff7161725 other movl %edx, %eax 7039: 0x00007ffff7161721 other addq $0x8, %rsp 7038: 0x00007ffff7161709 cond jump je 0x87721 ; <+241> 7037: 0x00007ffff7161707 other decl (%rsi) 7036: 0x00007ffff71616fe cond jump je 0x87707 ; <+215> 7035: 0x00007ffff71616f7 other cmpl $0x0, 0x33de92(%rip) ; __libc_multiple_threads 7034: 0x00007ffff71616ef other movq $0x0, 0x8(%rsi) 7033: 0x00007ffff71616ed cond jump jne 0x87721 ; <+241> 7032: 0x00007ffff71616e9 other subl $0x1, 0x4(%rsi) 7031: 0x00007ffff71616e2 other movq 0x88(%rbx), %rsi 7030: 0x00007ffff71616e0 cond jump jne 0x87721 ; <+241> 7029: 0x00007ffff71616da other testl $0x8000, (%rbx) ; imm = 0x8000 ``` Differential Revision: https://reviews.llvm.org/D130580
1 parent 964aeb7 commit d36ae49

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

lldb/include/lldb/Core/Disassembler.h

+3
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ class Instruction {
226226

227227
virtual bool IsCall() { return false; }
228228

229+
static const char *GetNameForInstructionControlFlowKind(
230+
lldb::InstructionControlFlowKind instruction_control_flow_kind);
231+
229232
protected:
230233
Address m_address; // The section offset address of this instruction
231234
// We include an address class in the Instruction class to

lldb/source/Core/Disassembler.cpp

+28-29
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,30 @@ AddressClass Instruction::GetAddressClass() {
577577
return m_address_class;
578578
}
579579

580+
const char *Instruction::GetNameForInstructionControlFlowKind(
581+
lldb::InstructionControlFlowKind instruction_control_flow_kind) {
582+
switch (instruction_control_flow_kind) {
583+
case eInstructionControlFlowKindUnknown:
584+
return "unknown";
585+
case eInstructionControlFlowKindOther:
586+
return "other";
587+
case eInstructionControlFlowKindCall:
588+
return "call";
589+
case eInstructionControlFlowKindReturn:
590+
return "return";
591+
case eInstructionControlFlowKindJump:
592+
return "jump";
593+
case eInstructionControlFlowKindCondJump:
594+
return "cond jump";
595+
case eInstructionControlFlowKindFarCall:
596+
return "far call";
597+
case eInstructionControlFlowKindFarReturn:
598+
return "far return";
599+
case eInstructionControlFlowKindFarJump:
600+
return "far jump";
601+
}
602+
}
603+
580604
void Instruction::Dump(lldb_private::Stream *s, uint32_t max_opcode_byte_size,
581605
bool show_address, bool show_bytes,
582606
bool show_control_flow_kind,
@@ -618,35 +642,10 @@ void Instruction::Dump(lldb_private::Stream *s, uint32_t max_opcode_byte_size,
618642
}
619643

620644
if (show_control_flow_kind) {
621-
switch (GetControlFlowKind(exe_ctx)) {
622-
case eInstructionControlFlowKindUnknown:
623-
ss.Printf("%-12s", "unknown");
624-
break;
625-
case eInstructionControlFlowKindOther:
626-
ss.Printf("%-12s", "other");
627-
break;
628-
case eInstructionControlFlowKindCall:
629-
ss.Printf("%-12s", "call");
630-
break;
631-
case eInstructionControlFlowKindReturn:
632-
ss.Printf("%-12s", "return");
633-
break;
634-
case eInstructionControlFlowKindJump:
635-
ss.Printf("%-12s", "jump");
636-
break;
637-
case eInstructionControlFlowKindCondJump:
638-
ss.Printf("%-12s", "cond jump");
639-
break;
640-
case eInstructionControlFlowKindFarCall:
641-
ss.Printf("%-12s", "far call");
642-
break;
643-
case eInstructionControlFlowKindFarReturn:
644-
ss.Printf("%-12s", "far return");
645-
break;
646-
case eInstructionControlFlowKindFarJump:
647-
ss.Printf("%-12s", "far jump");
648-
break;
649-
}
645+
lldb::InstructionControlFlowKind instruction_control_flow_kind =
646+
GetControlFlowKind(exe_ctx);
647+
ss.Printf("%-12s", GetNameForInstructionControlFlowKind(
648+
instruction_control_flow_kind));
650649
}
651650

652651
const size_t opcode_pos = ss.GetSizeOfLastLine();

0 commit comments

Comments
 (0)