Skip to contentSkip to conversation

perf annotate: Fix crashes on empty annotate windows

PATCH Applied James Clark 3 participants 4 messages Apr 20 – Jun 4 perf events

lore
Share & tools
lore

James Clark

author reviewer
#0 lore raw

PATCH 1/1 perf annotate: Fix crashes on empty annotate windows

Annotate can open with an empty window if the disassembly tool fails. After the linked change, the TUI started assuming there was a current annotation line and could assert or segfault in the seek, refresh, and source-toggle paths.

Handle empty annotate windows explicitly: set the asm entry count before resetting the browser, return early when refreshing an empty list, and ignore source line toggle when there is no current annotation line.

Fixes the following when opening an annotation:

perf: ui/browser.c:125: ui_browser__list_head_seek: Assertion `pos != NULL' failed. Aborted

Fixes e201757f7a0a ("perf annotate: Fix source code annotate with objdump")
Assisted-by GitHub Copilot:GPT-5.4
---
 tools/perf/ui/browser.c           | 3 +++
 tools/perf/ui/browsers/annotate.c | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
tools/perf/ui/browser.c +3 -0
index dc88427b4ae5..321187b204d3 100644
@@ -513,6 +513,9 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *browser)
 	struct list_head *head = browser->entries;
 	int row = 0;
 
+	if (browser->nr_entries == 0)
+		return 0;
+
 	if (browser->top == NULL || browser->top == browser->entries)
                 browser->top = ui_browser__list_head_filter_entries(browser, head->next);
 
tools/perf/ui/browsers/annotate.c +4 -1
index ea17e6d29a7e..0261cd922183 100644
@@ -449,6 +449,9 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser,
 	struct annotation_line *al;
 	off_t offset = browser->b.index - browser->b.top_idx;
 
+	if (browser->b.nr_entries == 0)
+		return false;
+
 	browser->b.seek(&browser->b, offset, SEEK_CUR);
 	al = list_entry(browser->b.top, struct annotation_line, node);
 
@@ -542,8 +545,8 @@ static void annotate_browser__show_full_location(struct ui_browser *browser)
 static void ui_browser__init_asm_mode(struct ui_browser *browser)
 {
 	struct annotation *notes = browser__annotation(browser);
-	ui_browser__reset_index(browser);
 	browser->nr_entries = notes->src->nr_asm_entries;
+	ui_browser__reset_index(browser);
 }
 
 static int sym_title(struct symbol *sym, struct map *map, char *title,

---
base-commit: 841dbf4871c57ce2da18c4ea7ffac5487d0eda16
change-id: 20260417-james-perf-annotate-assert-20f520eeb35b

Best regards,

Signature · 1 line
James Clark <[email protected]>
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · James Clark

Annotate can open with an empty window if the disassembly tool fails. After the linked change, the TUI started assuming there was a current annotation line and could assert or segfault in the seek, refresh, and source-toggle paths.

Handle empty annotate windows explicitly: set the asm entry count before resetting the browser, return early when refreshing an empty list, and ignore source line toggle when there is no current annotation line.

Quoted 8 lines

Fixes the following when opening an annotation:

perf: ui/browser.c:125: ui_browser__list_head_seek: Assertion `pos != NULL' failed. Aborted

Fixes e201757f7a0a ("perf annotate: Fix source code annotate with objdump")
Assisted-by GitHub Copilot:GPT-5.4

Thanks,
Namhyung

Quoted 52 lines
---
 tools/perf/ui/browser.c           | 3 +++
 tools/perf/ui/browsers/annotate.c | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
tools/perf/ui/browser.c +3 -0
index dc88427b4ae5..321187b204d3 100644
@@ -513,6 +513,9 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *browser)
 	struct list_head *head = browser->entries;
 	int row = 0;
 
+	if (browser->nr_entries == 0)
+		return 0;
+
 	if (browser->top == NULL || browser->top == browser->entries)
                 browser->top = ui_browser__list_head_filter_entries(browser, head->next);
 
tools/perf/ui/browsers/annotate.c +4 -2
index ea17e6d29a7e..0261cd922183 100644
@@ -449,6 +449,9 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser,
 	struct annotation_line *al;
 	off_t offset = browser->b.index - browser->b.top_idx;
 
+	if (browser->b.nr_entries == 0)
+		return false;
+
 	browser->b.seek(&browser->b, offset, SEEK_CUR);
 	al = list_entry(browser->b.top, struct annotation_line, node);
 
@@ -542,8 +545,8 @@ static void annotate_browser__show_full_location(struct ui_browser *browser)
 static void ui_browser__init_asm_mode(struct ui_browser *browser)
 {
 	struct annotation *notes = browser__annotation(browser);
-	ui_browser__reset_index(browser);
 	browser->nr_entries = notes->src->nr_asm_entries;
+	ui_browser__reset_index(browser);
 }
 
 static int sym_title(struct symbol *sym, struct map *map, char *title,
 
---

base-commit: 841dbf4871c57ce2da18c4ea7ffac5487d0eda16
change-id: 20260417-james-perf-annotate-assert-20f520eeb35b

Best regards,

Signature · 1 line
James Clark <[email protected]>
author reviewer
#2 lore raw
Quoted 15 lines · Namhyung Kim
Quoted 14 lines · James Clark

Annotate can open with an empty window if the disassembly tool fails. After the linked change, the TUI started assuming there was a current annotation line and could assert or segfault in the seek, refresh, and source-toggle paths.

Handle empty annotate windows explicitly: set the asm entry count before resetting the browser, return early when refreshing an empty list, and ignore source line toggle when there is no current annotation line.

Fixes the following when opening an annotation:

   perf: ui/browser.c:125: ui_browser__list_head_seek: Assertion `pos != NULL' failed.
   Aborted
Quoted 9 lines
Quoted 3 lines
Fixes e201757f7a0a ("perf annotate: Fix source code annotate with objdump")
Assisted-by GitHub Copilot:GPT-5.4

Thanks,
Namhyung

Ping, I think this one might have been missed.

Thanks
James

Quoted 52 lines
Quoted 52 lines
---
  tools/perf/ui/browser.c           | 3 +++
  tools/perf/ui/browsers/annotate.c | 5 ++++-
  2 files changed, 7 insertions(+), 1 deletion(-)
tools/perf/ui/browser.c +3 -0
index dc88427b4ae5..321187b204d3 100644
@@ -513,6 +513,9 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *browser)
  	struct list_head *head = browser->entries;
  	int row = 0;
 
+	if (browser->nr_entries == 0)
+		return 0;
+
  	if (browser->top == NULL || browser->top == browser->entries)
                  browser->top = ui_browser__list_head_filter_entries(browser, head->next);
 
tools/perf/ui/browsers/annotate.c +4 -2
index ea17e6d29a7e..0261cd922183 100644
@@ -449,6 +449,9 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser,
  	struct annotation_line *al;
  	off_t offset = browser->b.index - browser->b.top_idx;
 
+	if (browser->b.nr_entries == 0)
+		return false;
+
  	browser->b.seek(&browser->b, offset, SEEK_CUR);
  	al = list_entry(browser->b.top, struct annotation_line, node);
 
@@ -542,8 +545,8 @@ static void annotate_browser__show_full_location(struct ui_browser *browser)
  static void ui_browser__init_asm_mode(struct ui_browser *browser)
  {
  	struct annotation *notes = browser__annotation(browser);
-	ui_browser__reset_index(browser);
  	browser->nr_entries = notes->src->nr_asm_entries;
+	ui_browser__reset_index(browser);
  }
 
  static int sym_title(struct symbol *sym, struct map *map, char *title,
 
---

base-commit: 841dbf4871c57ce2da18c4ea7ffac5487d0eda16
change-id: 20260417-james-perf-annotate-assert-20f520eeb35b

Best regards,

Signature · 1 line
James Clark <[email protected]>
maintainer Applied
#3 lore raw
In reply to Namhyung Kim
Quoted 12 lines · Namhyung Kim
Quoted 11 lines · James Clark

Annotate can open with an empty window if the disassembly tool fails. After the linked change, the TUI started assuming there was a current annotation line and could assert or segfault in the seek, refresh, and source-toggle paths.

Handle empty annotate windows explicitly: set the asm entry count before resetting the browser, return early when refreshing an empty list, and ignore source line toggle when there is no current annotation line.

Fixes the following when opening an annotation:

Quoted 8 lines
Quoted 6 lines

perf: ui/browser.c:125: ui_browser__list_head_seek: Assertion `pos != NULL' failed. Aborted

Fixes e201757f7a0a ("perf annotate: Fix source code annotate with objdump")
Assisted-by GitHub Copilot:GPT-5.4

Thanks, applied to perf-tools-next, for v7.2.

- Arnaldo