Injecting user defined opcode

Mahmood Naderan via gcc-help gcc-help@gcc.gnu.org
Sat Jun 29 19:53:00 GMT 2019


Hi,

An empty main code results in the following opcode and assembly lines according to GDB.

$ gcc -masm=intel -g test.c -o test 
$ gdb ./test 
(gdb) set disassembly-flavor intel 
(gdb) list 
1       void main() 
2       { 
3       } 
(gdb) disass /r main 
Dump of assembler code for function main:    
  0x00000000004004ed <+0>:     55      push   rbp    
  0x00000000004004ee <+1>:     48 89 e5        mov    rbp,rsp    
  0x00000000004004f1 <+4>:     5d      pop    rbp    
  0x00000000004004f2 <+5>:     c3      ret 
End of assembler dump. (gdb) 




Now, when I put one assembly line with dummy opcode, it seems that gcc combines that with the subsequent line and doesn't create a machine code which I wrote.



(gdb) set disassembly-flavor intel 
(gdb) list 
1       void main() 
2       { 
3         __asm__(".byte 0x00"); 
4       } 
(gdb) disass /r main 
Dump of assembler code for function main:
    0x00000000004004ed <+0>:     55      push   rbp
    0x00000000004004ee <+1>:     48 89 e5        mov    rbp,rsp
    0x00000000004004f1 <+4>:     00 5d c3        add    BYTE PTR [rbp-0x3d],bl 
End of assembler dump. 


I expected to see something like this


  0x00000000004004ed <+0>:     55      push   rbp
  0x00000000004004ee <+1>:     48 89 e5        mov    rbp,rsp   
    ==========>                          00            INVALID
  0x00000000004004f1 <+4>:     5d      pop    rbp     
  0x00000000004004f2 <+5>:     c3      ret


Can I do that?

Regards,
Mahmood



More information about the Gcc-help mailing list