aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Maguire <alan.maguire@oracle.com>2023-03-10 14:50:48 +0000
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-03-13 09:02:28 -0300
commitd184aaa125ea40ffbae5e2dd3c09abebe8901266 (patch)
tree78586f14227f2367041713d5b99e93eafc040573
parenta9498899109d3be14f17abbc322a8f55a1067bee (diff)
downloadpahole-d184aaa125ea40ffbae5e2dd3c09abebe8901266.tar.gz
fprintf: Generalize function prototype print to support passing conf
function__prototype() writes the function prototype to the passed-in buffer, but uses the default conf_fprint structure which prints parameter names. Generalize into function__prototype_conf() so that callers can pass in their own conf_fprintf; this will be useful for generating prototype strings for type matching. Signed-off-by: Alan Maguire <alan.maguire@oracle.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Tested-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Eduard Zingerman <eddyz87@gmail.com> Cc: Hao Luo <haoluo@google.com> Cc: John Fastabend <john.fastabend@gmail.com> Cc: KP Singh <kpsingh@chromium.org> Cc: Kui-Feng Lee <sinquersw@gmail.com> Cc: Martin KaFai Lau <martin.lau@kernel.org> Cc: Song Liu <songliubraving@fb.com> Cc: Stanislav Fomichev <sdf@google.com> Cc: Timo Beckers <timo@incline.eu> Cc: Yonghong Song <yhs@fb.com> Cc: bpf@vger.kernel.org Link: https://lore.kernel.org/bpf/1678459850-16140-2-git-send-email-alan.maguire@oracle.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--dwarves.h5
-rw-r--r--dwarves_fprintf.c22
2 files changed, 22 insertions, 5 deletions
diff --git a/dwarves.h b/dwarves.h
index e92b2fd5..d04a36d5 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -133,6 +133,7 @@ struct conf_fprintf {
uint8_t hex_fmt:1;
uint8_t strip_inline:1;
uint8_t skip_emitting_atomic_typedefs:1;
+ uint8_t skip_emitting_errors:1;
};
struct cus;
@@ -944,6 +945,10 @@ size_t function__fprintf_stats(const struct tag *tag_func,
FILE *fp);
const char *function__prototype(const struct function *func,
const struct cu *cu, char *bf, size_t len);
+const char *function__prototype_conf(const struct function *func,
+ const struct cu *cu,
+ const struct conf_fprintf *conf,
+ char *bf, size_t len);
static __pure inline uint64_t function__addr(const struct function *func)
{
diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c
index 30355b40..5c6bf9cb 100644
--- a/dwarves_fprintf.c
+++ b/dwarves_fprintf.c
@@ -1102,21 +1102,33 @@ static size_t union__fprintf(struct type *type, const struct cu *cu,
conf->suffix ? " " : "", conf->suffix ?: "");
}
-const char *function__prototype(const struct function *func,
- const struct cu *cu, char *bf, size_t len)
+const char *function__prototype_conf(const struct function *func,
+ const struct cu *cu,
+ const struct conf_fprintf *conf,
+ char *bf, size_t len)
{
FILE *bfp = fmemopen(bf, len, "w");
if (bfp != NULL) {
- ftype__fprintf(&func->proto, cu, NULL, 0, 0, 0, true,
- &conf_fprintf__defaults, bfp);
+ ftype__fprintf(&func->proto, cu, NULL, 0, 0, 0, true, conf,
+ bfp);
fclose(bfp);
- } else
+ } else {
+ if (conf->skip_emitting_errors)
+ return NULL;
snprintf(bf, len, "<ERROR(%s): fmemopen failed!>", __func__);
+ }
return bf;
}
+const char *function__prototype(const struct function *func,
+ const struct cu *cu, char *bf, size_t len)
+{
+ return function__prototype_conf(func, cu, &conf_fprintf__defaults,
+ bf, len);
+}
+
size_t ftype__fprintf_parms(const struct ftype *ftype,
const struct cu *cu, int indent,
const struct conf_fprintf *conf, FILE *fp)