how to dump a Instruction in gdb?

Hi, all:
I want to know how to dump the a instruction in gdb. I can dump a Module use M.dump(), also is there any such print function which can be used in gdb for a single instruction and its operand?
also I’m confused with the concept about " the type a instruction", why a instruction should have a type, how we decide the type of a instruction? for example, for the following instruction:
%i = alloca i32, align 4 ; <i32*> [#uses=2]
the following isa is true:
isa(II->getType())

is that the type of a instruction is decided by the type of the result operand? and it has nothing to do with the opcode for a instruction?

thanks.

tianwei

Hi,

I want to know how to dump the a instruction in gdb. I can dump a Module
use M.dump(), also is there any such print function which can be used in gdb
for a single instruction and its operand?

you can dump most things in LLVM the same way as for a module: if I is your
instruction, I.dump() or I->dump() should work, depending on whether it is
a pointer or a reference.

thanks very much. so for following iterator, how can I use the dump function?
for (inst_iterator II = inst_begin(F), E = inst_end(F); II != E; ++II) {

}

also I’m confused with the concept about " the type a instruction", why a
instruction should have a type, how we decide the type of a instruction? for
example, for the following instruction:
%i = alloca i32, align 4 ; <i32*> [#uses=2]
the following isa is true:
isa(II->getType())

is that the type of a instruction is decided by the type of the result
operand? and it has nothing to do with the opcode for a instruction?

You can see the type in the assembler above:

%i = alloca i32, align 4 ; <i32*> [#uses=2]

the <i32*> in the comment at the end tells you that %i is an i32*.
The alloca instruction allocates the given type on the stack and
returns a pointer to it. You allocate an i32 so you get a pointer
to an i32 back.

ok, I will read the language reference manual again. thanks.

You can try it yourself. First try II->dump(), compile. If it does not
work, try II.dump(). Even you can try (*II)->dump().
Or you can read the source code of inst_iterator, to see what it is,
which operator it overloads.