xiaoxiang781216 commented on code in PR #14877: URL: https://github.com/apache/nuttx/pull/14877#discussion_r1853221280
########## libs/libbuiltin/compiler-rt/coverage.c: ########## @@ -266,61 +256,83 @@ 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)) + size += sizeof(hdr); + if (sizeof(hdr) != lib_stream_puts(stream, &hdr, sizeof(hdr))) { - _NX_SETERRNO(ret); goto exit; } - /* Data */ - - ret = _NX_WRITE(fd, data_begin, sizeof(__llvm_profile_data) * num_data); - if (ret != sizeof(__llvm_profile_data) * num_data) + size += sizeof(__llvm_profile_data) * num_data; + if (sizeof(__llvm_profile_data) * num_data != + lib_stream_puts(stream, data_begin, + sizeof(__llvm_profile_data) * num_data)) { - _NX_SETERRNO(ret); goto exit; } - /* Counters */ - - ret = _NX_WRITE(fd, counters_begin, sizeof(uint64_t) * num_counters); - if (ret != sizeof(uint64_t) * num_counters) + size += sizeof(uint64_t) * num_counters; + if (sizeof(uint64_t) * num_counters != + lib_stream_puts(stream, counters_begin, + sizeof(uint64_t) * num_counters)) { - _NX_SETERRNO(ret); goto exit; } - /* Names */ - - ret = _NX_WRITE(fd, names_begin, names_size); - if (ret != names_size) + size += names_size; + if (names_size != lib_stream_puts(stream, names_begin, names_size)) { - _NX_SETERRNO(ret); goto exit; } - /* Padding */ - for (; padding_bytes_after_names != 0; --padding_bytes_after_names) { - ret = _NX_WRITE(fd, "\0", 1); - if (ret != 1) + size += 1; + if (1 != lib_stream_puts(stream, &c, 1)) { - _NX_SETERRNO(ret); break; } } exit: + + return size; +} + +void __gcov_dump(void) +{ + struct lib_rawoutstream_s stream; + char *path; Review Comment: FAR char *path ########## libs/libbuiltin/compiler-rt/coverage.c: ########## @@ -225,14 +219,10 @@ 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) +size_t __llvm_profile_dump(FAR void *stream) Review Comment: void to lib_outstream_s ########## libs/libbuiltin/compiler-rt/coverage.c: ########## @@ -266,61 +256,83 @@ 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)) + size += sizeof(hdr); + if (sizeof(hdr) != lib_stream_puts(stream, &hdr, sizeof(hdr))) { - _NX_SETERRNO(ret); goto exit; } - /* Data */ - - ret = _NX_WRITE(fd, data_begin, sizeof(__llvm_profile_data) * num_data); - if (ret != sizeof(__llvm_profile_data) * num_data) + size += sizeof(__llvm_profile_data) * num_data; + if (sizeof(__llvm_profile_data) * num_data != + lib_stream_puts(stream, data_begin, + sizeof(__llvm_profile_data) * num_data)) { - _NX_SETERRNO(ret); goto exit; } - /* Counters */ - - ret = _NX_WRITE(fd, counters_begin, sizeof(uint64_t) * num_counters); - if (ret != sizeof(uint64_t) * num_counters) + size += sizeof(uint64_t) * num_counters; + if (sizeof(uint64_t) * num_counters != + lib_stream_puts(stream, counters_begin, + sizeof(uint64_t) * num_counters)) { - _NX_SETERRNO(ret); goto exit; } - /* Names */ - - ret = _NX_WRITE(fd, names_begin, names_size); - if (ret != names_size) + size += names_size; + if (names_size != lib_stream_puts(stream, names_begin, names_size)) { - _NX_SETERRNO(ret); goto exit; } - /* Padding */ - for (; padding_bytes_after_names != 0; --padding_bytes_after_names) { - ret = _NX_WRITE(fd, "\0", 1); - if (ret != 1) + size += 1; + if (1 != lib_stream_puts(stream, &c, 1)) { - _NX_SETERRNO(ret); break; } } exit: + + return size; +} + +void __gcov_dump(void) +{ + struct lib_rawoutstream_s stream; + char *path; + int fd; + + path = getenv("GCOV_PREFIX"); + if (!path) + { + return; + } + + fd = _NX_OPEN(path, O_WRONLY | O_CREAT); + if (fd < 0) + { + _NX_SETERRNO(fd); + return; + } + + lib_rawoutstream(&stream, fd); + + __llvm_profile_dump(&stream); + _NX_CLOSE(fd); } + +size_t __gcov_dump_to_memory(FAR char *ptr, size_t size) Review Comment: ```suggestion size_t __gcov_dump_to_memory(FAR void *ptr, size_t size) ``` -- 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