IR -> IR Optimization -> Code Generation(Register allocation/Instruction selection) Assembly
1.top-of-stack caching (1-TOSCA)
2.init garbage collector
1.similar to C++ inheritance
2.gc in COOL runtime
3.Class Tag, Object Size, Dispatch table pointer (similar to C++ vptr), Dispatch table (similar to C++ vtable)
4.register allocation is Graph coloring
(Linear-Scan Register Allocation
is another way to allocate registers)
1.Three-address code (it doesn't be implemented in this course)
1.it contains a concurrent garbage collector
2.the management of application memory
3.how the program accesses variables, mechanisms for passing parameters between procedures
4.interfacing with the operating system
5.The compiler makes assumptions depending on the specific runtime system to generate correct code.
gc is also part of the program
1.gc in runtime
2.how gc works
3.stack-based virtual machine -> register-based virtual machine (?
4.code generation
4-1. stack based machine
4-2. register based machine
-> register allocation and assignment
-> instruction selection/instruction scheduling
5. how to verify and test compiler?
(gdb) x/8xw $sp // examine sp, from sp to show next
8
w
ords inhex
format(gdb) x $sp // examine $sp =>
0xfffffffffab8: 0x00000004
, address is0xfffffffffab8
and value is0x00000004
(gdb) x $sp+4 // examine $sp+4 =>
0xfffffffffabc: 0x004003a8
, address is0xfffffffffabc
and value is0x004003a8
(gdb)
set *((int*)$sp)=0x4
// save value0x4
at address ofsp
(gdb)
p *((int*)($sp))
// get value indecimal
format at address ofsp
(gdb)
p/x *((int*)($sp+4))
// get value inhex
format at address ofsp+4
(gdb) watch *(address) // watch this address
(gdb) info address [yout_symbol] // check yout_symbol from address
(gdb) info symbol [your_addr] // check your_address from symbol
// decimal format: 10進位格式
// hex format: 16進位格式
NOTE:
ldr w9, [x9, #12] // ok
ldr w9, [w9, #12] // error
str w9, [x9, #12] // ok
str w9, [w9, #12] // error
ldr x2, =stdin // ok
ldr w2, =stdin // error, relocate problem
blr x12 // ok
blr w12 // error
adr x12 label // ok
adr w12 label // error
gdb in assembly
Show current assembly instruction in GDB
How to break on assembly instruction at a given address in gdb?
Jumping to the next "instruction" using gdb
Step out of current function with GDB
How do I jump to a breakpoint within GDB?
GDB: Change string in memory on stack
Can I have gdb break on read/write from an address? [duplicate]
step vs next
(程式碼專用)step (會進入子函數)
(程式碼專用)next (不會進入子函數)
(指令專用) stepi/si
(指令專用) nexti/ni
Ref : Porting to 64-bit ARM by Chris Shore, ARM
watch *0x413ffc == 0x33280041 // x7
because when calling "bl puts", value of "0x1" (stdout), which means $x1 was overwritten...
No segmentation fault if program running under gdb
Linux下關閉ALSR(地址空間隨機化)的方法
setarch `uname -m` -R ./yourProgram
gdb input file
(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "/usr/lib/debug".
(gdb) set debug-file-directory // set
/home/ubuntu
as debug directory(gdb) r < g1.graph // input
/home/ubuntu/g1.graph
tograph
executable0< filename
// Reads stdin from filename.< filename
// Reads stdin from filename.1> filename
// Writes stdout to filename.> filename
// Writes stdout to filename.2> filename
// Writes stderr to filename.2>&1
// Writes stderr to the same place as stdout.>& file
//Writes both stdout and stderr to filename.>> filename
// Appends stdout to filename.>>& filename
// Appends both stdout and stderr to filename.(gdb) x &stdin
0x4149b8 <stdin@@GLIBC_2.17>: 0xf7fc6898
(gdb) x 0xf7fc6898
0xf7fc6898: Cannot access memory at address 0xf7fc6898
// =stdin
x2, 403938 <_NoGC_Collect_ok+0x98>
ldr w2, 4038e8 <_NoGC_Collect_ok+0x48>
(gdb) x $x2
0xfffff7fc6898 <
_IO_2_1_stdin_
>: 0xfbad2088(gdb) x &stdin
0x4111b0 <stdin@@GLIBC_2.17>: 0xf7fc6898
_IO_2_1_stdin_
Temp sol:
ldr x2, =0xfffff7fc6898
//stdin
0xfffff7fc6898 <IO_2_1_stdin>: 0xfbad2088ldr x2, =0xfffff7fc7548
//stdout
0xfffff7fc7548 <IO_2_1_stdout>: 0xfbad2084