Skip to content

Commit cb4dc37

Browse files
Merge pull request #5340 from gilles-peskine-arm/ssl_debug_helpers_generated.h-commit-header
Commit ssl_debug_helpers.h
2 parents 9fa5bf8 + 863b96a commit cb4dc37

File tree

8 files changed

+75
-48
lines changed

8 files changed

+75
-48
lines changed

library/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ libmbed*
77
/error.c
88
/version_features.c
99
/ssl_debug_helpers_generated.c
10-
/ssl_debug_helpers_generated.h

library/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ if(GEN_FILES)
147147

148148
add_custom_command(
149149
OUTPUT
150-
${CMAKE_CURRENT_BINARY_DIR}/ssl_debug_helpers_generated.h
151150
${CMAKE_CURRENT_BINARY_DIR}/ssl_debug_helpers_generated.c
152151
COMMAND
153152
${MBEDTLS_PYTHON_EXECUTABLE}
@@ -162,7 +161,6 @@ else()
162161
link_to_source(error.c)
163162
link_to_source(version_features.c)
164163
link_to_source(ssl_debug_helpers_generated.c)
165-
link_to_source(ssl_debug_helpers_generated.h)
166164
endif()
167165

168166
if(CMAKE_COMPILER_IS_GNUCC)

library/Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ libmbedcrypto.dll: $(OBJS_CRYPTO)
290290
.PHONY: generated_files
291291
GENERATED_FILES = \
292292
error.c version_features.c \
293-
ssl_debug_helpers_generated.c ssl_debug_helpers_generated.h
293+
ssl_debug_helpers_generated.c
294294
generated_files: $(GENERATED_FILES)
295295

296296
error.c: ../scripts/generate_errors.pl
@@ -300,10 +300,9 @@ error.c:
300300
echo " Gen $@"
301301
$(PERL) ../scripts/generate_errors.pl
302302

303-
ssl_debug_helpers_generated.c: | ssl_debug_helpers_generated.h
304-
ssl_debug_helpers_generated.h: ../scripts/generate_ssl_debug_helpers.py
305-
ssl_debug_helpers_generated.h: $(filter-out %config%,$(wildcard ../include/mbedtls/*.h))
306-
ssl_debug_helpers_generated.h:
303+
ssl_debug_helpers_generated.c: ../scripts/generate_ssl_debug_helpers.py
304+
ssl_debug_helpers_generated.c: $(filter-out %config%,$(wildcard ../include/mbedtls/*.h))
305+
ssl_debug_helpers_generated.c:
307306
echo " Gen $@"
308307
$(PYTHON) ../scripts/generate_ssl_debug_helpers.py --mbedtls-root .. .
309308

library/ssl_debug_helpers.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* \file ssl_debug_helpers.h
3+
*
4+
* \brief Automatically generated helper functions for debugging
5+
*/
6+
/*
7+
* Copyright The Mbed TLS Contributors
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
11+
* not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
#ifndef MBEDTLS_SSL_DEBUG_HELPERS_H
24+
#define MBEDTLS_SSL_DEBUG_HELPERS_H
25+
26+
#include "common.h"
27+
28+
#if defined(MBEDTLS_DEBUG_C)
29+
30+
#include "mbedtls/ssl.h"
31+
#include "ssl_misc.h"
32+
33+
34+
const char *mbedtls_ssl_states_str( mbedtls_ssl_states in );
35+
36+
const char *mbedtls_tls_prf_types_str( mbedtls_tls_prf_types in );
37+
38+
const char *mbedtls_ssl_key_export_type_str( mbedtls_ssl_key_export_type in );
39+
40+
41+
42+
#endif /* MBEDTLS_DEBUG_C */
43+
44+
#endif /* SSL_DEBUG_HELPERS_H */

library/ssl_tls13_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "ssl_misc.h"
3535
#include "ecdh_misc.h"
3636
#include "ssl_tls13_keys.h"
37-
#include "ssl_debug_helpers_generated.h"
37+
#include "ssl_debug_helpers.h"
3838

3939
/* Write extensions */
4040

library/ssl_tls13_server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "mbedtls/debug.h"
2727

2828
#include "ssl_misc.h"
29-
#include "ssl_debug_helpers_generated.h"
29+
#include "ssl_debug_helpers.h"
3030

3131
int mbedtls_ssl_tls13_handshake_server_step( mbedtls_ssl_context *ssl )
3232
{

scripts/generate_ssl_debug_helpers.py

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -232,46 +232,43 @@ def generate_tranlation_function(self):
232232
body = body.format(translation_table='\n'.join(translation_table),
233233
name=self._name,
234234
prototype=self._prototype)
235-
prototype = 'const char *{name}_str( {prototype} in );\n'
236-
prototype = prototype.format(name=self._name,
237-
prototype=self._prototype)
238-
return body, prototype
235+
return body
239236

240237

241238
OUTPUT_C_TEMPLATE = '''\
242239
/* Automatically generated by generate_ssl_debug_helpers.py. DO NOT EDIT. */
243240
244-
#include "common.h"
245-
246-
#if defined(MBEDTLS_DEBUG_C)
247-
248-
#include "ssl_debug_helpers_generated.h"
249-
250-
{functions}
251-
252-
#endif /* MBEDTLS_DEBUG_C */
253-
/* End of automatically generated file. */
254-
255-
'''
256-
257-
OUTPUT_H_TEMPLATE = '''\
258-
/* Automatically generated by generate_ssl_debug_helpers.py. DO NOT EDIT. */
259-
#ifndef MBEDTLS_SSL_DEBUG_HELPERS_H
260-
#define MBEDTLS_SSL_DEBUG_HELPERS_H
241+
/**
242+
* \file ssl_debug_helpers_generated.c
243+
*
244+
* \brief Automatically generated helper functions for debugging
245+
*/
246+
/*
247+
* Copyright The Mbed TLS Contributors
248+
* SPDX-License-Identifier: Apache-2.0
249+
*
250+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
251+
* not use this file except in compliance with the License.
252+
* You may obtain a copy of the License at
253+
*
254+
* http://www.apache.org/licenses/LICENSE-2.0
255+
*
256+
* Unless required by applicable law or agreed to in writing, software
257+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
258+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
259+
* See the License for the specific language governing permissions and
260+
* limitations under the License.
261+
*/
261262
262263
#include "common.h"
263264
264265
#if defined(MBEDTLS_DEBUG_C)
265266
266-
#include "mbedtls/ssl.h"
267-
#include "ssl_misc.h"
267+
#include "ssl_debug_helpers.h"
268268
269269
{functions}
270270
271271
#endif /* MBEDTLS_DEBUG_C */
272-
273-
#endif /* SSL_DEBUG_HELPERS_H */
274-
275272
/* End of automatically generated file. */
276273
277274
'''
@@ -286,34 +283,24 @@ def generate_ssl_debug_helpers(output_directory, mbedtls_root):
286283
source_code = remove_c_comments(f.read())
287284

288285
definitions = dict()
289-
prototypes = dict()
290286
for start, instance in preprocess_c_source_code(source_code, EnumDefinition):
291287
if start in definitions:
292288
continue
293289
if isinstance(instance, EnumDefinition):
294-
definition, prototype = instance.generate_tranlation_function()
290+
definition = instance.generate_tranlation_function()
295291
else:
296292
definition = instance
297-
prototype = instance
298293
definitions[start] = definition
299-
prototypes[start] = prototype
300294

301295
function_definitions = [str(v) for _, v in sorted(definitions.items())]
302-
function_prototypes = [str(v) for _, v in sorted(prototypes.items())]
303296
if output_directory == sys.stdout:
304-
sys.stdout.write(OUTPUT_H_TEMPLATE.format(
305-
functions='\n'.join(function_prototypes)))
306297
sys.stdout.write(OUTPUT_C_TEMPLATE.format(
307298
functions='\n'.join(function_definitions)))
308299
else:
309300
with open(os.path.join(output_directory, 'ssl_debug_helpers_generated.c'), 'w') as f:
310301
f.write(OUTPUT_C_TEMPLATE.format(
311302
functions='\n'.join(function_definitions)))
312303

313-
with open(os.path.join(output_directory, 'ssl_debug_helpers_generated.h'), 'w') as f:
314-
f.write(OUTPUT_H_TEMPLATE.format(
315-
functions='\n'.join(function_prototypes)))
316-
317304

318305
def main():
319306
"""

tests/scripts/check-generated-files.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ check()
118118
check scripts/generate_errors.pl library/error.c
119119
check scripts/generate_query_config.pl programs/test/query_config.c
120120
check scripts/generate_features.pl library/version_features.c
121-
check scripts/generate_ssl_debug_helpers.py library/ssl_debug_helpers_generated.h library/ssl_debug_helpers_generated.c
121+
check scripts/generate_ssl_debug_helpers.py library/ssl_debug_helpers_generated.c
122122
# generate_visualc_files enumerates source files (library/*.c). It doesn't
123123
# care about their content, but the files must exist. So it must run after
124124
# the step that creates or updates these files.

0 commit comments

Comments
 (0)