aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorRafael Ávila de Espíndola <[email protected]>2011-04-28 16:14:04 -0400
committerRafael Ávila de Espíndola <[email protected]>2011-04-28 16:19:20 -0400
commitb0980b7d79e8209ba91a2a85c720f238bbc478ed (patch)
tree54fec2dda56b799aafa2af918971eea939628b1c /src/comp
parentActually perform take/drop on args (oh my!) (diff)
downloadrust-b0980b7d79e8209ba91a2a85c720f238bbc478ed.tar.xz
rust-b0980b7d79e8209ba91a2a85c720f238bbc478ed.zip
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 ()
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/back/x86.rs36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/comp/back/x86.rs b/src/comp/back/x86.rs
index e35af621..09b18309 100644
--- a/src/comp/back/x86.rs
+++ b/src/comp/back/x86.rs
@@ -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();
}