I'm trying to debug a very simple program in GDB to see what its code looks
like in assembly. I built tcc-0.9.27 on x86_64 windows. My source code
looks like this:

```c
int main(int argc, char **argv)
{
        int test = 255;
        test = test + 1;
        return 0;
}
```

```bash
tcc -g -o main.exe main.c
gdb main
GNU gdb (GDB) 16.3
(gdb) b main
(gdb) r
(gdb) disas /s
Dump of assembler code for function main:
main.c
2 {
   0x0000000000401000 <+0>:     push   rbp
   0x0000000000401001 <+1>:     mov    rbp,rsp
   0x0000000000401004 <+4>:     sub    rsp,0x10
   0x000000000040100b <+11>:    mov    QWORD PTR [rbp+0x10],rcx
   0x000000000040100f <+15>:    mov    QWORD PTR [rbp+0x18],rdx
=> 0x0000000000401013 <+19>:    mov    eax,0xff
   0x0000000000401018 <+24>:    mov    DWORD PTR [rbp-0x4],eax

3               int test = 255;
```

It seems like the source code is not mapped to assembly correctly here. I
would expect for the source line 3 to appear above the program address
0x0000000000401013 (which has an arrow next to it), since this is actually
where we move 255 to the register which is then moved onto the stack
variable.

For comparison, GCC maps the source code like this:

```bash
(gdb) disas /s
Dump of assembler code for function main:
main.c:
2       {
   0x00007ff7b6b71450 <+0>:     push   rbp
   0x00007ff7b6b71451 <+1>:     mov    rbp,rsp
   0x00007ff7b6b71454 <+4>:     sub    rsp,0x30
   0x00007ff7b6b71458 <+8>:     mov    DWORD PTR [rbp+0x10],ecx
   0x00007ff7b6b7145b <+11>:    mov    QWORD PTR [rbp+0x18],rdx
   0x00007ff7b6b7145f <+15>:    call   0x7ff7b6b71550 <__main>

3               int test = 255;
=> 0x00007ff7b6b71464 <+20>:    mov    DWORD PTR [rbp-0x4],0xff
```
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to