I have spent quite some time looking for a way to test if the format
strings in inttypes.h (PRIu32, PRIx32, ...) are correctly used in
openocd.
I have checked the compile flags of GCC and CLang; searched on-line,
tried to build some test at runtime ... Nothing that works well!
Maybe moving openocd to C++ could help, but ...

The only 'clean' solution seems to cross-compile openocd for targets
that have different data sizes. Actually this could be enough to
guarantee that openocd compiles for 'real' targets.

Do you have any better tool or ideas?

The patch series I just proposed in http://openocd.zylin.com/5814
has been created with a crap trick on the code.
I copied locally and modified the files as below:
    /usr/include/inttypes.h
        -# define PRIx32        "x"
        +# define PRIx32        __PRI64_PREFIX "x"
        ...
    /usr/include/bits/stdint-uintn.h
        -typedef __uint32_t uint32_t;
        +typedef __uint64_t uint32_t;
Practically I have changed the size of the 32 bit data types to 64
and kept aligned the corresponding conversion specifiers, so printf
will not complain when 'uint32_t' is used with 'PRIx32' and similar.
But any case in which the code uses incorrectly:
- 'int' with 'PRIx32', or
- 'uint32_t' with '%d'
triggers a compile error.
The patch series is the result of fixing all the errors above.
Of course the binary after such crap compilation is not expected to
run, but that's fine!

Still I had to add further hacks to hide other compile issues that
get triggered by the trick above.

I would like to enforce proper checks on patches pushed on gerrit.
Do you think it could make sense to refine the crap trick above?

Antonio


_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to