xiaoxiang781216 commented on code in PR #14877: URL: https://github.com/apache/nuttx/pull/14877#discussion_r1851937063
########## libs/libbuiltin/compiler-rt/coverage.c: ########## @@ -225,14 +219,9 @@ void __llvm_profile_register_names_function(void *names_start, * llvm-prof. See the clang profiling documentation for details. */ -void __llvm_profile_dump(const char *path) +void __llvm_profile_dump(lib_puts_t puts, FAR void *stream) Review Comment: remove puts ########## libs/libbuiltin/compiler-rt/coverage.c: ########## @@ -266,61 +262,55 @@ void __llvm_profile_dump(const char *path) hdr.names_delta = (uintptr_t)names_begin; hdr.value_kind_last = IPVK_LAST; - fd = _NX_OPEN(filename, O_WRONLY | O_CREAT); - if (fd < 0) + puts(handle, &hdr, sizeof(hdr)); + puts(handle, data_begin, sizeof(__llvm_profile_data) * num_data); + puts(handle, counters_begin, sizeof(uint64_t) * num_counters); + puts(handle, names_begin, names_size); + + for (; padding_bytes_after_names != 0; --padding_bytes_after_names) { - _NX_SETERRNO(fd); - return; + puts(handle, &c, 1); } +} - /* Header */ +void __gcov_dump(void) +{ - ret = _NX_WRITE(fd, &hdr, sizeof(hdr)); - if (ret != sizeof(hdr)) - { - _NX_SETERRNO(ret); - goto exit; - } +#ifdef CONFIG_COVERAGE_DUMP_MEMORY - /* Data */ + struct lib_memoutstream_s stream; - ret = _NX_WRITE(fd, data_begin, sizeof(__llvm_profile_data) * num_data); - if (ret != sizeof(__llvm_profile_data) * num_data) - { - _NX_SETERRNO(ret); - goto exit; - } + lib_memoutstream(&stream, + CONFIG_COVERAGE_DUMP_MEMORY_ADDR, + CONFIG_COVERAGE_DUMP_MEMORY_SIZE); - /* Counters */ + __llvm_profile_dump(stream.puts, &stream); - ret = _NX_WRITE(fd, counters_begin, sizeof(uint64_t) * num_counters); - if (ret != sizeof(uint64_t) * num_counters) - { - _NX_SETERRNO(ret); - goto exit; - } +#elif defined (CONFIG_COVERAGE_DUMP_FILE) - /* Names */ + struct lib_rawoutstream_s stream; + char *path; + int fd; - ret = _NX_WRITE(fd, names_begin, names_size); - if (ret != names_size) + path = getenv("GCOV_PREFIX"); + fd = _NX_OPEN(path, O_WRONLY | O_CREAT); + if (fd < 0) { - _NX_SETERRNO(ret); - goto exit; + _NX_SETERRNO(fd); + return; } - /* Padding */ + lib_rawoutstream(&stream, fd); - for (; padding_bytes_after_names != 0; --padding_bytes_after_names) - { - ret = _NX_WRITE(fd, "\0", 1); - if (ret != 1) - { - _NX_SETERRNO(ret); - break; - } - } + __llvm_profile_dump(stream.common.puts, &stream); -exit: _NX_CLOSE(fd); + +#endif + +} + +void __gcov_reset(void) +{ + Review Comment: remove blank line ########## libs/libbuiltin/compiler-rt/coverage.c: ########## @@ -266,61 +255,43 @@ void __llvm_profile_dump(const char *path) hdr.names_delta = (uintptr_t)names_begin; hdr.value_kind_last = IPVK_LAST; - fd = _NX_OPEN(filename, O_WRONLY | O_CREAT); - if (fd < 0) - { - _NX_SETERRNO(fd); - return; - } - - /* Header */ - - ret = _NX_WRITE(fd, &hdr, sizeof(hdr)); - if (ret != sizeof(hdr)) - { - _NX_SETERRNO(ret); - goto exit; - } - - /* Data */ + puts(stream, &hdr, sizeof(hdr)); Review Comment: call lib_stream_puts instead -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org