Check this GCC function out

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Check this GCC function out

Post 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 ?
Only Human
kaos

Re:Check this GCC function out

Post 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.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:Check this GCC function out

Post by df »

elf wastes a register on PIC... its a shame PE is so complex and coff is lacking that little extra :)
-- Stu --
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Check this GCC function out

Post 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

Code: Select all

    mov eax,[ebp-4]
    mov [ebp-4],eax
Post Reply