aboutsummaryrefslogtreecommitdiff
path: root/libgcc
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2022-03-30 21:45:23 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2022-04-28 20:46:49 +0200
commit39d80300b3c769c3a7805a46ee5facc6adf1a4d0 (patch)
tree2c8609ca844a90b8006e39f11c2735a91fe73dff /libgcc
parent68a4673fe25e067df74373a45180d80c70da102f (diff)
downloadgcc-39d80300b3c769c3a7805a46ee5facc6adf1a4d0.zip
gcc-39d80300b3c769c3a7805a46ee5facc6adf1a4d0.tar.gz
gcc-39d80300b3c769c3a7805a46ee5facc6adf1a4d0.tar.bz2
gcov: Add __gcov_filename_to_gcfn()
gcc/ * doc/invoke.texi (fprofile-info-section): Mention __gcov_filename_to_gcfn(). Use "freestanding" to match with C11 standard language. Fix minor example code issues. * gcov-io.h (GCOV_FILENAME_MAGIC): Define and document. gcc/testsuite/ * gcc.dg/gcov-info-to-gcda.c: Test __gcov_filename_to_gcfn(). libgcc/ * gcov.h (__gcov_info_to_gcda): Mention __gcov_filename_to_gcfn(). (__gcov_filename_to_gcfn): Declare and document. * libgcov-driver.c (dump_string): New. (__gcov_filename_to_gcfn): Likewise. (__gcov_info_to_gcda): Adjust comment to match C11 standard language.
Diffstat (limited to 'libgcc')
-rw-r--r--libgcc/gcov.h17
-rw-r--r--libgcc/libgcov-driver.c32
2 files changed, 47 insertions, 2 deletions
diff --git a/libgcc/gcov.h b/libgcc/gcov.h
index cea9302..cdd4206 100644
--- a/libgcc/gcov.h
+++ b/libgcc/gcov.h
@@ -43,7 +43,8 @@ extern void __gcov_dump (void);
stream. The ALLOCATE_FN callback shall allocate memory with a size in
characters specified by the first callback parameter. The ARG parameter is
a user-provided argument passed as the last argument to the callback
- functions. */
+ functions. It is recommended to use the __gcov_filename_to_gcfn()
+ in the filename callback function. */
extern void
__gcov_info_to_gcda (const struct gcov_info *__info,
@@ -52,4 +53,18 @@ __gcov_info_to_gcda (const struct gcov_info *__info,
void *(*__allocate_fn) (unsigned, void *),
void *__arg);
+/* Convert the FILENAME to a gcfn data stream. The DUMP_FN callback is
+ subsequently called with chunks (the begin and length of the chunk are
+ passed as the first two callback parameters) of the gcfn data stream.
+ The ARG parameter is a user-provided argument passed as the last
+ argument to the DUMP_FN callback function. This function is intended
+ to be used by the filename callback of __gcov_info_to_gcda(). The gcfn
+ data stream is used by the merge-stream subcommand of the gcov-tool to
+ get the filename associated with a gcda data stream. */
+
+extern void
+__gcov_filename_to_gcfn (const char *__filename,
+ void (*__dump_fn) (const void *, unsigned, void *),
+ void *__arg);
+
#endif /* GCC_GCOV_H */
diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index 10831e8..d4517d2 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -410,6 +410,23 @@ dump_counter (gcov_type counter,
dump_unsigned (0, dump_fn, arg);
}
+/* Dump the STRING using the DUMP handler called with ARG. */
+
+static inline void
+dump_string (const char *string,
+ void (*dump_fn) (const void *, unsigned, void *),
+ void *arg)
+{
+ unsigned length = 0;
+
+ if (string)
+ length = strlen (string) + 1;
+
+ dump_unsigned (length, dump_fn, arg);
+ if (string)
+ (*dump_fn) (string, length, arg);
+}
+
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
/* Store all TOP N counters where each has a dynamic length. */
@@ -768,7 +785,7 @@ __gcov_init (struct gcov_info *info)
#ifdef NEED_L_GCOV_INFO_TO_GCDA
/* Convert the gcov info to a gcda data stream. It is intended for
- free-standing environments which do not support the C library file I/O. */
+ freestanding environments which do not support the C library file I/O. */
void
__gcov_info_to_gcda (const struct gcov_info *gi_ptr,
@@ -780,4 +797,17 @@ __gcov_info_to_gcda (const struct gcov_info *gi_ptr,
(*filename_fn) (gi_ptr->filename, arg);
write_one_data (gi_ptr, NULL, dump_fn, allocate_fn, arg);
}
+
+/* Convert the filename to a gcfn data stream. It is intended for
+ freestanding environments which do not support the C library file I/O. */
+
+void
+__gcov_filename_to_gcfn (const char *filename,
+ void (*dump_fn) (const void *, unsigned, void *),
+ void *arg)
+{
+ dump_unsigned (GCOV_FILENAME_MAGIC, dump_fn, arg);
+ dump_unsigned (GCOV_VERSION, dump_fn, arg);
+ dump_string (filename, dump_fn, arg);
+}
#endif /* NEED_L_GCOV_INFO_TO_GCDA */