Gary-Hobson commented on code in PR #14838: URL: https://github.com/apache/nuttx/pull/14838#discussion_r1852309133
########## libs/libbuiltin/libgcc/gcov.c: ########## @@ -0,0 +1,272 @@ +/**************************************************************************** + * libs/libbuiltin/libgcc/gcov.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <gcov.h> +#include <string.h> +#include <syslog.h> + +#include <nuttx/lib/lib.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define GCOV_DATA_MAGIC (0x67636461) +#define GCOV_NOTE_MAGIC (0x67636e6f) +#define GCOV_FILENAME_MAGIC (0x6763666e) + +#define GCOV_TAG_FUNCTION (0x01000000) +#define GCOV_TAG_COUNTER_BASE (0x01a10000) + +#define GCOV_TAG_FOR_COUNTER(count) \ + (GCOV_TAG_COUNTER_BASE + ((uint32_t)(count) << 17)) + +#ifdef GCOV_12_FORMAT +# define GCOV_TAG_FUNCTION_LENGTH 12 +#else +# define GCOV_TAG_FUNCTION_LENGTH 3 +#endif + +#ifdef GCOV_12_FORMAT +# define GCOV_UNIT_SIZE 4 +#else +# define GCOV_UNIT_SIZE 1 +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +typedef unsigned int gcov_unsigned_t; + +/* Information about counters for a single function + * + * This data is generated by gcc during compilation and doesn't change + * at run-time. + */ + +struct gcov_ctr_info +{ + unsigned int num; /* Number of counter values for this type */ + FAR gcov_type *values; /* Array of counter values for this type */ +}; + +/* Profiling meta data per function + * + * This data is generated by gcc during compilation and doesn't change + * at run-time. + */ + +struct gcov_fn_info +{ + FAR const struct gcov_info *key; /* Comdat key */ + unsigned int ident; /* Unique ident of function */ + unsigned int lineno_checksum; /* Function lineno checksum */ + unsigned int cfg_checksum; /* Function cfg checksum */ + struct gcov_ctr_info ctrs[1]; /* Instrumented counters */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +FAR struct gcov_info *__gcov_info_start; +FAR struct gcov_info *__gcov_info_end; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void dump_counter(FAR void *buffer, FAR size_t *off, uint64_t v) +{ + if (buffer) + { + memcpy((FAR uint8_t *)buffer + *off, (FAR uint8_t *)&v, sizeof(v)); + } + + *off += sizeof(uint64_t); +} + +static void dump_unsigned(FAR void *buffer, FAR size_t *off, uint32_t v) +{ + if (buffer) + { + memcpy((FAR uint8_t *)buffer + *off, (FAR uint8_t *)&v, sizeof(v)); + } + + *off += sizeof(uint32_t); +} + +static size_t gcov_convert(FAR uint8_t *buffer, + FAR const struct gcov_info *info) +{ + FAR struct gcov_fn_info *gfi; + FAR struct gcov_ctr_info *gci; + uint32_t functions; + uint32_t counts; + uint32_t value; + size_t pos = 0; + + /* File header. */ + + dump_unsigned(buffer, &pos, GCOV_DATA_MAGIC); + dump_unsigned(buffer, &pos, info->version); + dump_unsigned(buffer, &pos, info->stamp); + +#ifdef GCOV_12_FORMAT + dump_unsigned(buffer, &pos, info->checksum); +#endif + + /* Function headers. */ + + for (functions = 0; functions < info->n_functions; functions++) + { + gfi = info->functions[functions]; + + /* Function record. */ + + dump_unsigned(buffer, &pos, GCOV_TAG_FUNCTION); + dump_unsigned(buffer, &pos, GCOV_TAG_FUNCTION_LENGTH); + dump_unsigned(buffer, &pos, gfi->ident); + dump_unsigned(buffer, &pos, gfi->lineno_checksum); + dump_unsigned(buffer, &pos, gfi->cfg_checksum); + + gci = gfi->ctrs; + for (counts = 0; counts < GCOV_COUNTERS; counts++) + { + if (!info->merge[counts]) + { + continue; + } + + /* Counter record. */ + + dump_unsigned(buffer, &pos, GCOV_TAG_FOR_COUNTER(counts)); + dump_unsigned(buffer, &pos, gci->num * 2 * GCOV_UNIT_SIZE); + + for (value = 0; value < gci->num; value++) + { + dump_counter(buffer, &pos, gci->values[value]); + } + + gci++; + } + } + + return pos; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void __gcov_init(FAR struct gcov_info *info) +{ + info->next = __gcov_info_start; + __gcov_info_start = info; +} + +void __gcov_merge_add(FAR gcov_type *counters, unsigned int n_counters) +{ +} + +void __gcov_exit(void) +{ +} + +void __gcov_dump(void) Review Comment: The toolchain already has an implementation of __gcov_dump. I think you can use the default one most of the time. If necessary, we can reimplement __gcov_dump -- 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