mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-26 22:38:30 +00:00
Get GDB working
Some checks failed
build / matrix_on_mode () (push) Has been cancelled
build / matrix_on_mode (optlinux) (push) Has been cancelled
build / matrix_on_mode (rel) (push) Has been cancelled
build / matrix_on_mode (tiny) (push) Has been cancelled
build / matrix_on_mode (tinylinux) (push) Has been cancelled
Some checks failed
build / matrix_on_mode () (push) Has been cancelled
build / matrix_on_mode (optlinux) (push) Has been cancelled
build / matrix_on_mode (rel) (push) Has been cancelled
build / matrix_on_mode (tiny) (push) Has been cancelled
build / matrix_on_mode (tinylinux) (push) Has been cancelled
You can now say `gdb hello.com.dbg` and it'll work perfectly.
This commit is contained in:
parent
afc986f741
commit
fbc4fcbb71
18 changed files with 230 additions and 67 deletions
|
@ -30,18 +30,18 @@
|
|||
// @param 8(rsp) x6 is arg
|
||||
// @return tid of child on success, or -errno on error
|
||||
sys_clone_linux:
|
||||
beg
|
||||
pro
|
||||
#ifdef __x86_64__
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
push %rbx
|
||||
cpush %rbx
|
||||
mov %rcx,%r10
|
||||
mov 16(%rbp),%rbx
|
||||
mov $56,%eax // __NR_clone
|
||||
syscall
|
||||
test %rax,%rax
|
||||
jz 2f
|
||||
0: pop %rbx
|
||||
pop %rbp
|
||||
0: cpop %rbx
|
||||
epi
|
||||
ret
|
||||
2: xor %ebp,%ebp // child thread
|
||||
mov %rbx,%rdi // arg
|
||||
|
@ -50,15 +50,13 @@ sys_clone_linux:
|
|||
mov $60,%eax // __NR_exit(exitcode)
|
||||
syscall
|
||||
#elif defined(__aarch64__)
|
||||
stp x29,x30,[sp,#-16]!
|
||||
mov x29,sp
|
||||
mov x8,x3 // swap x3 and x4
|
||||
mov x3,x4 // swap x3 and x4
|
||||
mov x4,x8 // swap x3 and x4
|
||||
mov x8,#220 // __NR_clone
|
||||
svc #0
|
||||
cbz x0,2f
|
||||
ldp x29,x30,[sp],#16
|
||||
epi
|
||||
ret
|
||||
2: mov x29,#0 // wipe backtrace
|
||||
mov x28,x3 // set cosmo tls
|
||||
|
@ -69,4 +67,5 @@ sys_clone_linux:
|
|||
#else
|
||||
#error "unsupported architecture"
|
||||
#endif
|
||||
end
|
||||
.endfn sys_clone_linux,globl,hidden
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
// @param rdx is environ
|
||||
// @param rcx is auxv
|
||||
// @noreturn
|
||||
cosmo: push %rbp
|
||||
mov %rsp,%rbp
|
||||
cosmo: beg
|
||||
pro
|
||||
mov %edi,%r12d
|
||||
mov %rsi,%r13
|
||||
mov %rdx,%r14
|
||||
|
@ -104,7 +104,10 @@ cosmo: push %rbp
|
|||
je 2f
|
||||
push %rax
|
||||
push %rax
|
||||
call .Largs
|
||||
mov %r12d,%edi
|
||||
mov %r13,%rsi
|
||||
mov %r14,%rdx
|
||||
mov %r15,%rcx
|
||||
call *(%rax)
|
||||
pop %rax
|
||||
pop %rax
|
||||
|
@ -112,17 +115,15 @@ cosmo: push %rbp
|
|||
jmp 1b
|
||||
|
||||
// call main()
|
||||
2: call .Largs
|
||||
2: mov %r12d,%edi
|
||||
mov %r13,%rsi
|
||||
mov %r14,%rdx
|
||||
mov %r15,%rcx
|
||||
.weak main
|
||||
call main
|
||||
xchg %eax,%edi
|
||||
call exit
|
||||
|
||||
.Largs: mov %r12d,%edi
|
||||
mov %r13,%rsi
|
||||
mov %r14,%rdx
|
||||
mov %r15,%rcx
|
||||
ret
|
||||
end
|
||||
.endfn cosmo,weak
|
||||
|
||||
// Enables Thread Local Storage.
|
||||
|
|
|
@ -28,8 +28,12 @@ ftrace_hook:
|
|||
|
||||
cmpl $0,__ftrace(%rip)
|
||||
jle 1f
|
||||
.cfi_startproc
|
||||
push %rbp
|
||||
.cfi_def_cfa_offset 16
|
||||
.cfi_offset %rbp, -16
|
||||
mov %rsp,%rbp
|
||||
.cfi_def_cfa_register %rbp
|
||||
and $-16,%rsp
|
||||
sub $128,%rsp
|
||||
movdqu %xmm0,-0x80(%rbp)
|
||||
|
@ -41,13 +45,21 @@ ftrace_hook:
|
|||
movdqu %xmm6,-0x20(%rbp)
|
||||
movdqu %xmm7,-0x10(%rbp)
|
||||
push %rax
|
||||
.cfi_offset %rax, -24
|
||||
push %rcx
|
||||
.cfi_offset %rcx, -32
|
||||
push %rdx
|
||||
.cfi_offset %rdx, -40
|
||||
push %rdi
|
||||
.cfi_offset %rdi, -48
|
||||
push %rsi
|
||||
.cfi_offset %rsi, -56
|
||||
push %r8
|
||||
.cfi_offset %r8, -64
|
||||
push %r9
|
||||
.cfi_offset %r9, -72
|
||||
push %r10
|
||||
.cfi_offset %r10, -80
|
||||
call ftracer
|
||||
movdqu -0x80(%rbp),%xmm0
|
||||
movdqu -0x70(%rbp),%xmm1
|
||||
|
@ -66,12 +78,20 @@ ftrace_hook:
|
|||
pop %rcx
|
||||
pop %rax
|
||||
leave
|
||||
.cfi_restore %rbp
|
||||
.cfi_def_cfa %rsp, 8
|
||||
1: ret
|
||||
.cfi_endproc
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
stp x29,x30,[sp,-384]!
|
||||
.cfi_startproc
|
||||
.cfi_def_cfa_offset 384
|
||||
.cfi_offset 29, -384 // x29 (fp) is saved at [sp - 384]
|
||||
.cfi_offset 30, -376 // x30 (lr) is saved at [sp - 376]
|
||||
mov x29,sp
|
||||
.cfi_def_cfa_register 29
|
||||
stp x0,x1,[sp,16]
|
||||
|
||||
adrp x0,__ftrace
|
||||
|
@ -80,18 +100,45 @@ ftrace_hook:
|
|||
ble 1f
|
||||
|
||||
stp x2,x3,[sp,32]
|
||||
.cfi_offset 2, -352
|
||||
.cfi_offset 3, -344
|
||||
stp x4,x5,[sp,48]
|
||||
.cfi_offset 4, -336
|
||||
.cfi_offset 5, -328
|
||||
stp x6,x7,[sp,64]
|
||||
.cfi_offset 6, -320
|
||||
.cfi_offset 7, -312
|
||||
stp x8,x9,[sp,80]
|
||||
.cfi_offset 8, -304
|
||||
.cfi_offset 9, -296
|
||||
stp x10,x11,[sp,96]
|
||||
.cfi_offset 10, -288
|
||||
.cfi_offset 11, -280
|
||||
stp x12,x13,[sp,112]
|
||||
.cfi_offset 12, -272
|
||||
.cfi_offset 13, -264
|
||||
stp x14,x15,[sp,128]
|
||||
.cfi_offset 14, -256
|
||||
.cfi_offset 15, -248
|
||||
stp x16,x19,[sp,160]
|
||||
.cfi_offset 16, -224
|
||||
.cfi_offset 19, -216
|
||||
stp x20,x21,[sp,176]
|
||||
.cfi_offset 20, -208
|
||||
.cfi_offset 21, -200
|
||||
stp x22,x23,[sp,192]
|
||||
.cfi_offset 22, -192
|
||||
.cfi_offset 23, -184
|
||||
stp x24,x25,[sp,208]
|
||||
.cfi_offset 24, -176
|
||||
.cfi_offset 25, -168
|
||||
stp x26,x27,[sp,224]
|
||||
.cfi_offset 26, -160
|
||||
.cfi_offset 27, -152
|
||||
stp x17,x28,[sp,240]
|
||||
.cfi_offset 17, -144
|
||||
.cfi_offset 28, -136
|
||||
// No CFI directives needed for FP registers
|
||||
stp q0,q1,[sp,256]
|
||||
stp q2,q3,[sp,288]
|
||||
stp q4,q5,[sp,320]
|
||||
|
@ -119,7 +166,12 @@ ftrace_hook:
|
|||
|
||||
1: ldp x0,x1,[sp,16]
|
||||
ldp x29,x30,[sp],384
|
||||
.cfi_restore 29
|
||||
.cfi_restore 30
|
||||
.cfi_def_cfa 7, 0 // On some ARM systems the stack pointer is represented by register 7
|
||||
.cfi_def_cfa_offset 0
|
||||
ret
|
||||
.cfi_endproc
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
.endfn ftrace_hook,globl,hidden
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue