24
24
* Included Files
25
25
****************************************************************************/
26
26
27
+ #include <fcntl.h>
27
28
#include <gcov.h>
28
29
#include <stdio.h>
29
30
#include <stdlib.h>
34
35
#include <nuttx/crc16.h>
35
36
#include <nuttx/streams.h>
36
37
37
- /****************************************************************************
38
- * Private Types
39
- ****************************************************************************/
40
-
41
- struct gcov_arg
42
- {
43
- FAR const char * name ;
44
- struct lib_stdoutstream_s stdoutstream ;
45
- struct lib_hexdumpstream_s hexstream ;
46
- };
47
-
48
38
/****************************************************************************
49
39
* Private Functions
50
40
****************************************************************************/
@@ -65,92 +55,6 @@ static void show_usage(FAR const char *progname)
65
55
exit (EXIT_FAILURE );
66
56
}
67
57
68
- /****************************************************************************
69
- * Name: gcov_dump
70
- ****************************************************************************/
71
-
72
- static void gcov_dump (FAR const char * path , FAR const char * strip )
73
- {
74
- if (path == NULL || access (path , F_OK ) != 0 || atoi (strip ) < 0 )
75
- {
76
- fprintf (stderr , "ERROR: Invalid parameter\n" );
77
- return ;
78
- }
79
-
80
- setenv ("GCOV_PREFIX_STRIP" , strip , 1 );
81
- setenv ("GCOV_PREFIX" , path , 1 );
82
- __gcov_dump ();
83
- }
84
-
85
- /****************************************************************************
86
- * Name: stdout_dump
87
- ****************************************************************************/
88
-
89
- #ifndef CONFIG_COVERAGE_TOOLCHAIN
90
- static void stdout_dump (FAR const void * buffer , size_t size ,
91
- FAR void * arg )
92
- {
93
- FAR struct gcov_arg * args = (FAR struct gcov_arg * )arg ;
94
- uint16_t checksum = 0 ;
95
- int i ;
96
-
97
- if (size == 0 )
98
- {
99
- return ;
100
- }
101
-
102
- for (i = 0 ; i < size ; i ++ )
103
- {
104
- checksum += ((FAR const uint8_t * )buffer )[i ];
105
- }
106
-
107
- lib_sprintf (& args -> stdoutstream .common ,
108
- "gcov start filename:%s size: %zuByte\n" ,
109
- args -> name , size );
110
- lib_stream_puts (& args -> hexstream , buffer , size );
111
- lib_stream_flush (& args -> hexstream );
112
- lib_sprintf (& args -> stdoutstream .common ,
113
- "gcov end filename:%s checksum: %#0x\n" ,
114
- args -> name , checksum );
115
- lib_stream_flush (& args -> stdoutstream );
116
- }
117
-
118
- /****************************************************************************
119
- * Name: stdout_filename
120
- ****************************************************************************/
121
-
122
- static void stdout_filename (const char * name , FAR void * arg )
123
- {
124
- FAR struct gcov_arg * args = (FAR struct gcov_arg * )arg ;
125
- args -> name = name ;
126
- __gcov_filename_to_gcfn (name , NULL , NULL );
127
- }
128
-
129
- /****************************************************************************
130
- * Name: gcov_stdout_dump
131
- *
132
- * Description:
133
- * Dump the gcov information of all translation units to stdout.
134
- *
135
- ****************************************************************************/
136
-
137
- static void gcov_stdout_dump (void )
138
- {
139
- FAR struct gcov_info * info = __gcov_info_start ;
140
- FAR struct gcov_info * end = __gcov_info_end ;
141
- struct gcov_arg arg ;
142
-
143
- lib_stdoutstream (& arg .stdoutstream , stdout );
144
- lib_hexdumpstream (& arg .hexstream , & arg .stdoutstream .common );
145
-
146
- while (info != end )
147
- {
148
- __gcov_info_to_gcda (info , stdout_filename , stdout_dump , NULL , & arg );
149
- info = info -> next ;
150
- }
151
- }
152
- #endif
153
-
154
58
/****************************************************************************
155
59
* Public Functions
156
60
****************************************************************************/
@@ -159,14 +63,10 @@ int main(int argc, FAR char *argv[])
159
63
{
160
64
FAR const char * strip = CONFIG_COVERAGE_DEFAULT_PREFIX_STRIP ;
161
65
FAR const char * path = NULL ;
66
+ bool onefile = false;
162
67
int option ;
163
68
164
- if (argc < 2 )
165
- {
166
- show_usage (argv [0 ]);
167
- }
168
-
169
- while ((option = getopt (argc , argv , "d::t:rh" )) != ERROR )
69
+ while ((option = getopt (argc , argv , "d::t:orh" )) != ERROR )
170
70
{
171
71
switch (option )
172
72
{
@@ -191,17 +91,22 @@ int main(int argc, FAR char *argv[])
191
91
}
192
92
}
193
93
194
- #ifndef CONFIG_COVERAGE_TOOLCHAIN
195
- if (path == NULL )
94
+ if (access (path , F_OK ) == 0 )
95
+ {
96
+ onefile = true;
97
+ }
98
+
99
+ if (onefile )
196
100
{
197
- gcov_stdout_dump ( );
101
+ setenv ( "GCOV_DUMP_ONEFILE" , "1" , 1 );
198
102
}
199
103
else
200
- #endif
201
104
{
202
- gcov_dump ( path , strip );
105
+ setenv ( "GCOV_DUMP_ONEFILE" , "0" , 1 );
203
106
}
204
107
205
- printf ("Gcov dump complete\n" );
108
+ setenv ("GCOV_PREFIX_STRIP" , strip , 1 );
109
+ setenv ("GCOV_PREFIX" , path , 1 );
110
+ __gcov_dump ();
206
111
return 0 ;
207
112
}
0 commit comments