1 |
From f4e8d57b6ad6f599de54c020ba185db83cb011a3 Mon Sep 17 00:00:00 2001 |
2 |
From: Josh Stone <jistone@redhat.com> |
3 |
Date: Thu, 16 Aug 2018 11:26:27 -0700 |
4 |
Subject: [PATCH] std: stop backtracing when the frames are full |
5 |
|
6 |
--- |
7 |
src/libstd/sys/cloudabi/backtrace.rs | 18 ++++++++++-------- |
8 |
src/libstd/sys/redox/backtrace/tracing.rs | 18 ++++++++++-------- |
9 |
src/libstd/sys/unix/backtrace/tracing/gcc_s.rs | 18 ++++++++++-------- |
10 |
3 files changed, 30 insertions(+), 24 deletions(-) |
11 |
|
12 |
diff --git a/src/libstd/sys/cloudabi/backtrace.rs b/src/libstd/sys/cloudabi/backtrace.rs |
13 |
index 1b970187558c..2c43b5937ce5 100644 |
14 |
--- a/src/libstd/sys/cloudabi/backtrace.rs |
15 |
+++ b/src/libstd/sys/cloudabi/backtrace.rs |
16 |
@@ -64,6 +64,10 @@ extern "C" fn trace_fn( |
17 |
arg: *mut libc::c_void, |
18 |
) -> uw::_Unwind_Reason_Code { |
19 |
let cx = unsafe { &mut *(arg as *mut Context) }; |
20 |
+ if cx.idx >= cx.frames.len() { |
21 |
+ return uw::_URC_NORMAL_STOP; |
22 |
+ } |
23 |
+ |
24 |
let mut ip_before_insn = 0; |
25 |
let mut ip = unsafe { uw::_Unwind_GetIPInfo(ctx, &mut ip_before_insn) as *mut libc::c_void }; |
26 |
if !ip.is_null() && ip_before_insn == 0 { |
27 |
@@ -73,14 +77,12 @@ extern "C" fn trace_fn( |
28 |
} |
29 |
|
30 |
let symaddr = unsafe { uw::_Unwind_FindEnclosingFunction(ip) }; |
31 |
- if cx.idx < cx.frames.len() { |
32 |
- cx.frames[cx.idx] = Frame { |
33 |
- symbol_addr: symaddr as *mut u8, |
34 |
- exact_position: ip as *mut u8, |
35 |
- inline_context: 0, |
36 |
- }; |
37 |
- cx.idx += 1; |
38 |
- } |
39 |
+ cx.frames[cx.idx] = Frame { |
40 |
+ symbol_addr: symaddr as *mut u8, |
41 |
+ exact_position: ip as *mut u8, |
42 |
+ inline_context: 0, |
43 |
+ }; |
44 |
+ cx.idx += 1; |
45 |
|
46 |
uw::_URC_NO_REASON |
47 |
} |
48 |
diff --git a/src/libstd/sys/redox/backtrace/tracing.rs b/src/libstd/sys/redox/backtrace/tracing.rs |
49 |
index bb70ca360370..c0414b78f8d6 100644 |
50 |
--- a/src/libstd/sys/redox/backtrace/tracing.rs |
51 |
+++ b/src/libstd/sys/redox/backtrace/tracing.rs |
52 |
@@ -68,6 +68,10 @@ pub fn unwind_backtrace(frames: &mut [Frame]) |
53 |
extern fn trace_fn(ctx: *mut uw::_Unwind_Context, |
54 |
arg: *mut libc::c_void) -> uw::_Unwind_Reason_Code { |
55 |
let cx = unsafe { &mut *(arg as *mut Context) }; |
56 |
+ if cx.idx >= cx.frames.len() { |
57 |
+ return uw::_URC_NORMAL_STOP; |
58 |
+ } |
59 |
+ |
60 |
let mut ip_before_insn = 0; |
61 |
let mut ip = unsafe { |
62 |
uw::_Unwind_GetIPInfo(ctx, &mut ip_before_insn) as *mut libc::c_void |
63 |
@@ -94,14 +98,12 @@ extern fn trace_fn(ctx: *mut uw::_Unwind_Context, |
64 |
unsafe { uw::_Unwind_FindEnclosingFunction(ip) } |
65 |
}; |
66 |
|
67 |
- if cx.idx < cx.frames.len() { |
68 |
- cx.frames[cx.idx] = Frame { |
69 |
- symbol_addr: symaddr as *mut u8, |
70 |
- exact_position: ip as *mut u8, |
71 |
- inline_context: 0, |
72 |
- }; |
73 |
- cx.idx += 1; |
74 |
- } |
75 |
+ cx.frames[cx.idx] = Frame { |
76 |
+ symbol_addr: symaddr as *mut u8, |
77 |
+ exact_position: ip as *mut u8, |
78 |
+ inline_context: 0, |
79 |
+ }; |
80 |
+ cx.idx += 1; |
81 |
|
82 |
uw::_URC_NO_REASON |
83 |
} |
84 |
diff --git a/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs b/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs |
85 |
index 1b92fc0e6ad0..6e8415686792 100644 |
86 |
--- a/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs |
87 |
+++ b/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs |
88 |
@@ -68,6 +68,10 @@ pub fn unwind_backtrace(frames: &mut [Frame]) |
89 |
extern fn trace_fn(ctx: *mut uw::_Unwind_Context, |
90 |
arg: *mut libc::c_void) -> uw::_Unwind_Reason_Code { |
91 |
let cx = unsafe { &mut *(arg as *mut Context) }; |
92 |
+ if cx.idx >= cx.frames.len() { |
93 |
+ return uw::_URC_NORMAL_STOP; |
94 |
+ } |
95 |
+ |
96 |
let mut ip_before_insn = 0; |
97 |
let mut ip = unsafe { |
98 |
uw::_Unwind_GetIPInfo(ctx, &mut ip_before_insn) as *mut libc::c_void |
99 |
@@ -94,14 +98,12 @@ extern fn trace_fn(ctx: *mut uw::_Unwind_Context, |
100 |
unsafe { uw::_Unwind_FindEnclosingFunction(ip) } |
101 |
}; |
102 |
|
103 |
- if cx.idx < cx.frames.len() { |
104 |
- cx.frames[cx.idx] = Frame { |
105 |
- symbol_addr: symaddr as *mut u8, |
106 |
- exact_position: ip as *mut u8, |
107 |
- inline_context: 0, |
108 |
- }; |
109 |
- cx.idx += 1; |
110 |
- } |
111 |
+ cx.frames[cx.idx] = Frame { |
112 |
+ symbol_addr: symaddr as *mut u8, |
113 |
+ exact_position: ip as *mut u8, |
114 |
+ inline_context: 0, |
115 |
+ }; |
116 |
+ cx.idx += 1; |
117 |
|
118 |
uw::_URC_NO_REASON |
119 |
} |
120 |
-- |
121 |
2.17.1 |
122 |
|