summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Syromyatnikov <evgsyr@gmail.com>2020-03-30 06:03:03 +0200
committerEugene Syromyatnikov <evgsyr@gmail.com>2020-03-30 23:14:24 +0200
commit851abed7ecc9e6ebb7f8e7c0334d24ca1df3a9b5 (patch)
treecaacd910b7cbe95bebb996464204e5c911174e8f
parent36f32a255db09886f7f9ba08ec712b8742f0c312 (diff)
downloadstrace-851abed7ecc9e6ebb7f8e7c0334d24ca1df3a9b5.tar.gz
Move print_nonzero_bytes from clone.c to util.c
As it is to be used elsewhere. * clone.c (print_nonzero_bytes): Move it... * util.c (print_nonzero_bytes): ...here. Remove static qualifier. * defs.h (print_nonzero_bytes): New declaration.
-rw-r--r--clone.c66
-rw-r--r--defs.h29
-rw-r--r--util.c43
3 files changed, 72 insertions, 66 deletions
diff --git a/clone.c b/clone.c
index e8cbd7914..872b32978 100644
--- a/clone.c
+++ b/clone.c
@@ -151,72 +151,6 @@ struct strace_clone_args {
uint64_t set_tid_size;
};
-/**
- * Print a region of tracee memory only in case non-zero bytes are present
- * there. It almost fits into printstr_ex, but it has some pretty specific
- * behaviour peculiarities (like printing of ellipsis on error) to readily
- * integrate it there.
- *
- * Since it is expected to be used for printing tail of a structure in tracee's
- * memory, it accepts a combination of start_addr/start_offs/total_len and does
- * the relevant calculations itself.
- *
- * @param prefix A string printed in cases something is going to be printed.
- * @param start_addr Address of the beginning of a structure (whose tail
- * is supposedly to be printed) in tracee's memory.
- * @param start_offs Offset from the beginning of the structure where the tail
- * data starts.
- * @param total_len Total size of the tracee's memory region containing
- * the structure and the tail data.
- * Caller is responsible for imposing a sensible (usually
- * mandated by the kernel interface, like get_pagesize())
- * limit here.
- * @param style Passed to string_quote as "style" parameter.
- * @return Returns true is anything was printed, false otherwise.
- */
-static bool
-print_nonzero_bytes(struct tcb *const tcp, const char *prefix,
- const kernel_ulong_t start_addr,
- const unsigned int start_offs,
- const unsigned int total_len,
- const unsigned int style)
-{
- if (start_offs >= total_len)
- return false;
-
- const kernel_ulong_t addr = start_addr + start_offs;
- const unsigned int len = total_len - start_offs;
- const unsigned int size = MIN(len, max_strlen);
-
- char *str = malloc(len);
-
- if (!str) {
- error_func_msg("memory exhausted when tried to allocate"
- " %u bytes", len);
- tprintf("%s???", prefix);
- return true;
- }
-
- bool ret = true;
-
- if (umoven(tcp, addr, len, str)) {
- tprintf("%s???", prefix);
- } else if (is_filled(str, 0, len)) {
- ret = false;
- } else {
- tprints(prefix);
- tprintf("/* bytes %u..%u */ ", start_offs, total_len - 1);
-
- print_quoted_string(str, size, style);
-
- if (size < len)
- tprints("...");
- }
-
- free(str);
- return ret;
-}
-
SYS_FUNC(clone3)
{
static const size_t minsz = offsetofend(struct strace_clone_args, tls);
diff --git a/defs.h b/defs.h
index 27b02c598..c5c92d71a 100644
--- a/defs.h
+++ b/defs.h
@@ -989,6 +989,35 @@ extern int
printstr_ex(struct tcb *, kernel_ulong_t addr, kernel_ulong_t len,
unsigned int user_style);
+/**
+ * Print a region of tracee memory only in case non-zero bytes are present
+ * there. It almost fits into printstr_ex, but it has some pretty specific
+ * behaviour peculiarities (like printing of ellipsis on error) to readily
+ * integrate it there.
+ *
+ * Since it is expected to be used for printing tail of a structure in tracee's
+ * memory, it accepts a combination of start_addr/start_offs/total_len and does
+ * the relevant calculations itself.
+ *
+ * @param prefix A string printed in cases something is going to be printed.
+ * @param start_addr Address of the beginning of a structure (whose tail
+ * is supposedly to be printed) in tracee's memory.
+ * @param start_offs Offset from the beginning of the structure where the tail
+ * data starts.
+ * @param total_len Total size of the tracee's memory region containing
+ * the structure and the tail data.
+ * Caller is responsible for imposing a sensible (usually
+ * mandated by the kernel interface, like get_pagesize())
+ * limit here.
+ * @param style Passed to string_quote as "style" parameter.
+ * @return Returns true is anything was printed, false otherwise.
+ */
+extern bool print_nonzero_bytes(struct tcb *const tcp, const char *prefix,
+ const kernel_ulong_t start_addr,
+ const unsigned int start_offs,
+ const unsigned int total_len,
+ const unsigned int style);
+
extern int
printpathn(struct tcb *, kernel_ulong_t addr, unsigned int n);
diff --git a/util.c b/util.c
index 1a0e44a0c..1cb767d05 100644
--- a/util.c
+++ b/util.c
@@ -960,6 +960,49 @@ printstr_ex(struct tcb *const tcp, const kernel_ulong_t addr,
return rc;
}
+bool
+print_nonzero_bytes(struct tcb *const tcp, const char *prefix,
+ const kernel_ulong_t start_addr,
+ const unsigned int start_offs,
+ const unsigned int total_len,
+ const unsigned int style)
+{
+ if (start_offs >= total_len)
+ return false;
+
+ const kernel_ulong_t addr = start_addr + start_offs;
+ const unsigned int len = total_len - start_offs;
+ const unsigned int size = MIN(len, max_strlen);
+
+ char *str = malloc(len);
+
+ if (!str) {
+ error_func_msg("memory exhausted when tried to allocate"
+ " %u bytes", len);
+ tprintf("%s???", prefix);
+ return true;
+ }
+
+ bool ret = true;
+
+ if (umoven(tcp, addr, len, str)) {
+ tprintf("%s???", prefix);
+ } else if (is_filled(str, 0, len)) {
+ ret = false;
+ } else {
+ tprints(prefix);
+ tprintf("/* bytes %u..%u */ ", start_offs, total_len - 1);
+
+ print_quoted_string(str, size, style);
+
+ if (size < len)
+ tprints("...");
+ }
+
+ free(str);
+ return ret;
+}
+
void
dumpiov_upto(struct tcb *const tcp, const int len, const kernel_ulong_t addr,
kernel_ulong_t data_size)