Skip to content

Commit ea04fe1

Browse files
Aditya Bodkhenamhyung
authored andcommitted
perf script: perf script tests fails with segfault
pert script tests fails with segmentation fault as below: 92: perf script tests: --- start --- test child forked, pid 103769 DB test [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.012 MB /tmp/perf-test-script.7rbftEpOzX/perf.data (9 samples) ] /usr/libexec/perf-core/tests/shell/script.sh: line 35: 103780 Segmentation fault (core dumped) perf script -i "${perfdatafile}" -s "${db_test}" --- Cleaning up --- ---- end(-1) ---- 92: perf script tests : FAILED! Backtrace pointed to : #0 0x0000000010247dd0 in maps.machine () #1 0x00000000101d178c in db_export.sample () #2 0x00000000103412c8 in python_process_event () #3 0x000000001004eb28 in process_sample_event () #4 0x000000001024fcd0 in machines.deliver_event () #5 0x000000001025005c in perf_session.deliver_event () #6 0x00000000102568b0 in __ordered_events__flush.part.0 () torvalds#7 0x0000000010251618 in perf_session.process_events () torvalds#8 0x0000000010053620 in cmd_script () torvalds#9 0x00000000100b5a28 in run_builtin () torvalds#10 0x00000000100b5f94 in handle_internal_command () torvalds#11 0x0000000010011114 in main () Further investigation reveals that this occurs in the `perf script tests`, because it uses `db_test.py` script. This script sets `perf_db_export_mode = True`. With `perf_db_export_mode` enabled, if a sample originates from a hypervisor, perf doesn't set maps for "[H]" sample in the code. Consequently, `al->maps` remains NULL when `maps__machine(al->maps)` is called from `db_export__sample`. As al->maps can be NULL in case of Hypervisor samples , use thread->maps because even for Hypervisor sample, machine should exist. If we don't have machine for some reason, return -1 to avoid segmentation fault. Reported-by: Disha Goel <[email protected]> Signed-off-by: Aditya Bodkhe <[email protected]> Reviewed-by: Adrian Hunter <[email protected]> Tested-by: Disha Goel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Suggested-by: Adrian Hunter <[email protected]> Signed-off-by: Namhyung Kim <[email protected]>
1 parent 63e3759 commit ea04fe1

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

tools/perf/util/db-export.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al,
181181
if (al->map) {
182182
struct dso *dso = map__dso(al->map);
183183

184-
err = db_export__dso(dbe, dso, maps__machine(al->maps));
184+
err = db_export__dso(dbe, dso, maps__machine(thread__maps(al->thread)));
185185
if (err)
186186
return err;
187187
*dso_db_id = dso__db_id(dso);
@@ -256,6 +256,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe,
256256
al.map = map__get(node->ms.map);
257257
al.maps = maps__get(thread__maps(thread));
258258
al.addr = node->ip;
259+
al.thread = thread__get(thread);
259260

260261
if (al.map && !al.sym)
261262
al.sym = dso__find_symbol(map__dso(al.map), al.addr);
@@ -358,14 +359,18 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,
358359
};
359360
struct thread *main_thread;
360361
struct comm *comm = NULL;
361-
struct machine *machine;
362+
struct machine *machine = NULL;
362363
int err;
363364

365+
if (thread__maps(thread))
366+
machine = maps__machine(thread__maps(thread));
367+
if (!machine)
368+
return -1;
369+
364370
err = db_export__evsel(dbe, evsel);
365371
if (err)
366372
return err;
367373

368-
machine = maps__machine(al->maps);
369374
err = db_export__machine(dbe, machine);
370375
if (err)
371376
return err;

tools/perf/util/scripting-engines/trace-event-python.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ static void python_export_sample_table(struct db_export *dbe,
13061306

13071307
tuple_set_d64(t, 0, es->db_id);
13081308
tuple_set_d64(t, 1, es->evsel->db_id);
1309-
tuple_set_d64(t, 2, maps__machine(es->al->maps)->db_id);
1309+
tuple_set_d64(t, 2, maps__machine(thread__maps(es->al->thread))->db_id);
13101310
tuple_set_d64(t, 3, thread__db_id(es->al->thread));
13111311
tuple_set_d64(t, 4, es->comm_db_id);
13121312
tuple_set_d64(t, 5, es->dso_db_id);

0 commit comments

Comments
 (0)