Add a very minimal set of .cfi_* statements to get part of backtraces

working (on hello world at least):

~/inst/gdb/bin/gdb --args ./foo
(gdb) b write
...
(gdb) r
...
Breakpoint 1, 0xf7f04270 in write () from /lib32/libc.so.6
(gdb) bt
0  0xf7f04270 in write () from /lib32/libc.so.6
1  0x0804931a in rust_native_cdecl_3 ()
2  0x080487d7 in _rust_wrapper3_ ()
3  0x0804890a in _rust_fn5_main ()
4  0x08049440 in rust_native_cdecl_7 ()
This commit is contained in:
Rafael Ávila de Espíndola 2011-04-28 16:14:04 -04:00
parent 6daca7ea8d
commit b0980b7d79
2 changed files with 35 additions and 3 deletions

View file

@ -11,6 +11,14 @@ fn wstr(int i) -> str {
ret istr(i * wordsz);
}
fn start() -> vec[str] {
ret vec(".cfi_startproc");
}
fn end() -> vec[str] {
ret vec(".cfi_endproc");
}
fn save_callee_saves() -> vec[str] {
ret vec("pushl %ebp",
"pushl %edi",
@ -18,6 +26,27 @@ fn save_callee_saves() -> vec[str] {
"pushl %ebx");
}
fn save_callee_saves_with_cfi() -> vec[str] {
auto offset = 8;
auto t;
t = vec("pushl %ebp");
t += vec(".cfi_def_cfa_offset " + istr(offset));
t += vec(".cfi_offset 5, -" + istr(offset));
t += vec("pushl %edi");
offset += 4;
t += vec(".cfi_def_cfa_offset " + istr(offset));
t += vec("pushl %esi");
offset += 4;
t += vec(".cfi_def_cfa_offset " + istr(offset));
t += vec("pushl %ebx");
offset += 4;
t += vec(".cfi_def_cfa_offset " + istr(offset));
ret t;
}
fn restore_callee_saves() -> vec[str] {
ret vec("popl %ebx",
"popl %esi",
@ -211,9 +240,11 @@ fn native_glue(int n_args, bool pass_task) -> vec[str] {
auto carg = bind copy_arg(pass_task, _);
ret
save_callee_saves()
start()
+ save_callee_saves_with_cfi()
+ vec("movl %esp, %ebp # ebp = rust_sp")
+ vec(".cfi_def_cfa_register 5")
+ store_esp_to_rust_sp_second_arg()
+ load_esp_from_runtime_sp_second_arg()
@ -229,7 +260,8 @@ fn native_glue(int n_args, bool pass_task) -> vec[str] {
+ load_esp_from_rust_sp_second_arg()
+ restore_callee_saves()
+ vec("ret");
+ vec("ret")
+ end();
}

View file

@ -54,7 +54,7 @@ extern "C" void LLVMRustWriteOutputFile(LLVMPassManagerRef PMR, LLVMModuleRef M,
LLVMCodeGenFileType FileType) {
// Set compilation options.
llvm::NoFramePointerElim = true;
llvm::UnwindTablesMandatory = true;
InitializeAllTargets();
InitializeAllAsmPrinters();