Skip to contentSkip to conversation

Prevent infinite loop if unwind fails

PATCH New Francis Giraldeau 1 participant 1 message Nov 22, 2013 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Prevent infinite loop if unwind fails

Unwind may loop forever if sample is incomplete or bogus. Bound the number of unw_step() that yield the same IP to prevent infinite loop.

---
 tools/perf/util/unwind.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/unwind.c +7 -1
index 958723b..bf45b6b 100644
@@ -520,7 +520,8 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
 {
 	unw_addr_space_t addr_space;
 	unw_cursor_t c;
-	int ret;
+	unw_word_t prev_ip = 0;
+	int ret, rec = 0;
 
 	addr_space = unw_create_addr_space(&accessors, 0);
 	if (!addr_space) {
@@ -537,6 +538,11 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
 
 		unw_get_reg(&c, UNW_REG_IP, &ip);
 		ret = entry(ip, ui->thread, ui->machine, cb, arg);
+		if (prev_ip != ip)
+			rec = 0;
+		if (++rec >= 100)
+			break;
+		prev_ip = ip;
 	}
 
 	unw_destroy_addr_space(addr_space);
Signature · 1 line
1.8.1.2