Page 1 of 1
Check this GCC function out
Posted: Sat Oct 04, 2003 12:15 pm
by Neo
Code: Select all
void dump_registers()
{
???unsigned int _EAX,_EBX,_ECX,_EDX;
???printf("\n\tDump Registers here");
???__asm__ __volatile__ ( "movl %%eax,%w0" : "=g"(_EAX): "a"(_EAX) );
???__asm__ __volatile__ ( "movl %%ebx,%w0" : "=g"(_EBX): "b"(_EBX) );
???__asm__ __volatile__ ( "movl %%ecx,%w0" : "=g"(_ECX): "c"(_ECX) );
???__asm__ __volatile__ ( "movl %%edx,%w0" : "=g"(_EDX): "d"(_EDX) );
???printf("\nEAX = %x\nEBX = %x\nECX = %x\nEDX = %x",_EAX,_EBX,_ECX,_EDX);
}
IS this function right? I get errors when i replace %w0 with %w1 etc..
Also does this give the actual register values or is there something more.I'm a beginer ya know
btw does anyone have a better dump registers function.
Also which is the best choice for an executable file format ?
Re:Check this GCC function out
Posted: Sat Oct 04, 2003 3:21 pm
by kaos
Neo wrote:
Code: Select all
void dump_registers()
{
unsigned int _EAX,_EBX,_ECX,_EDX;
printf("\n\tDump Registers here");
The previous line will mung the registers. The compiler-generated function setup code might too.
Neo wrote:
Code: Select all
__asm__ __volatile__ ( "movl %%eax,%w0" : "=g"(_EAX): "a"(_EAX) );
__asm__ __volatile__ ( "movl %%ebx,%w0" : "=g"(_EBX): "b"(_EBX) );
__asm__ __volatile__ ( "movl %%ecx,%w0" : "=g"(_ECX): "c"(_ECX) );
__asm__ __volatile__ ( "movl %%edx,%w0" : "=g"(_EDX): "d"(_EDX) );
printf("\nEAX = %x\nEBX = %x\nECX = %x\nEDX = %x",_EAX,_EBX,_ECX,_EDX);
}
IS this function right? I get errors when i replace %w0 with %w1 etc..
Also does this give the actual register values or is there something more.I'm a beginer ya know
You might try compiling with the -S flag so that you can see gcc's assembly output.
Neo wrote:
btw does anyone have a better dump registers function.
Also which is the best choice for an executable file format ?
Here's what I would use to dump registers:
Code: Select all
#define I386_DUMP_REGISTERS() \
{ \
__asm__ __volatile__ ("pushl %edx"); \
__asm__ __volatile__ ("pushl %ecx"); \
__asm__ __volatile__ ("pushl %ebx"); \
__asm__ __volatile__ ("pushl %eax"); \
__asm__ __volatile__ ("call __dumpregs"); \
__asm__ __volatile__ ("pop %eax"); \
__asm__ __volatile__ ("pop %eax"); \
__asm__ __volatile__ ("pop %eax"); \
__asm__ __volatile__ ("pop %eax"); \
}
void _dumpregs(int eax, int ebx, int ecx, int edx)
{
printf("\nEAX = %x\nEBX = %x\nECX = %x\nEDX = %x\n", eax, ebx, ecx, edx);
}
Elf is supposedly the best executable format; it does have a lot of options, but it is rather complex. Coff is simple.
Re:Check this GCC function out
Posted: Sat Oct 04, 2003 4:19 pm
by df
elf wastes a register on PIC... its a shame PE is so complex and coff is lacking that little extra

Re:Check this GCC function out
Posted: Sun Oct 05, 2003 3:23 am
by Pype.Clicker
Neo wrote:
Code: Select all
__asm__ __volatile__ ( "movl %%eax,%w0" : "=g"(_EAX): "a"(_EAX) );
will hardly do what you want it to do! you're trying to tell the compiler that it must execute "mov [_EAX],eax" under the constraint that "eax must hold the content of _EAX" before execution of the command.
the resulting assembler code will look like