diff options
author | Serhei Makarov <serhei@serhei.io> | 2023-12-01 14:55:32 -0500 |
---|---|---|
committer | Serhei Makarov <serhei@serhei.io> | 2023-12-01 14:57:58 -0500 |
commit | a62ee609ed5ea7a0a2f09a5cc9ac48cf4db5b983 (patch) | |
tree | 894e5461e566a97fc2feecd7969e055ef091667a | |
parent | 0f0cea1fd659143499ec264e768207db829c3dcd (diff) |
eu-stacktrace WIP: improve error msg when write offset < 0
-rw-r--r-- | src/stacktrace.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/stacktrace.c b/src/stacktrace.c index 9cf7ec69..8d726528 100644 --- a/src/stacktrace.c +++ b/src/stacktrace.c @@ -486,7 +486,7 @@ struct sysprof_passthru_info { int output_fd; SysprofReader *reader; - int pos; /* TODO for debugging purposes */ + int pos; /* for diagnostic purposes */ }; int @@ -507,7 +507,7 @@ struct sysprof_unwind_info { int output_fd; SysprofReader *reader; - int pos; /* TODO for debugging purposes */ + int pos; /* for diagnostic purposes */ int n_addrs; int max_addrs; Dwarf_Addr *addrs; /* allocate blocks of UNWIND_ADDR_INCREMENT */ @@ -963,15 +963,18 @@ Utility is a work-in-progress, see README.eu-stacktrace in the source branch.") if (n_write < 0) error (EXIT_BAD, errno, N_("Write error to file or FIFO '%s'"), output_path); ptrdiff_t offset; + unsigned long int output_pos = 0; if (processing_mode == MODE_NONE) { struct sysprof_passthru_info sni = { output_fd, reader, sizeof reader->header }; offset = sysprof_reader_getframes (reader, &sysprof_none_cb, &sni); + output_pos = sni.pos; } else if (processing_mode == MODE_PASSTHRU) { struct sysprof_passthru_info spi = { output_fd, reader, sizeof reader->header }; offset = sysprof_reader_getframes (reader, &sysprof_passthru_cb, &spi); + output_pos = spi.pos; } else /* processing_mode == MODE_NAIVE */ { @@ -984,9 +987,13 @@ Utility is a work-in-progress, see README.eu-stacktrace in the source branch.") sui.addrs = (Dwarf_Addr *)malloc (sui.max_addrs * sizeof(Dwarf_Addr)); sui.outbuf = (void *)malloc (USHRT_MAX * sizeof(uint8_t)); offset = sysprof_reader_getframes (reader, &sysprof_unwind_cb, &sui); + output_pos = sui.pos; } - if (offset < 0) + if (offset < 0 && output_pos <= sizeof reader->header) error (EXIT_BAD, errno, N_("No frames in file or FIFO '%s'"), input_path); + else if (offset < 0) + error (EXIT_BAD, errno, N_("Error processing file or FIFO '%s' at input offset %ld, output offset %ld"), + input_path, reader->pos, output_pos); sysprof_reader_end (reader); #endif |