semihosting: use open mode flags from GDB, not from sys/stat.h 04/6804/5
authorPavel Kirienko <pavel.kirienko@gmail.com>
Sun, 9 Jan 2022 21:18:13 +0000 (23:18 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 29 Jan 2022 18:25:21 +0000 (18:25 +0000)
Values defined in sys/stat.h are not guaranteed to match
the constants defined by the GDB remote protocol, which are defined in
https://sourceware.org/gdb/onlinedocs/gdb/Open-Flags.html#Open-Flags.
On my local system (Manjaro 21.2.1 x86_64), for example, O_TRUNC is
defined as 0x40, whereas GDB requires it to be 0x400,
causing all "w" file open modes to misbehave.

This patch has been tested with STM32F446.

Change-Id: Ifb2c740fd689e71d6f1a4bde1edaecd76fdca910
Signed-off-by: Pavel Kirienko <pavel.kirienko@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6804
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
src/target/semihosting_common.c

index 1b65e126cbeb1606e92ebf7544a473ade53ac879..8d3f66ca530e528b5a5803d1e687d6a7eccdf373 100644 (file)
 #include <helper/log.h>
 #include <sys/stat.h>
 
+/**
+ * It is not possible to use O_... flags defined in sys/stat.h because they
+ * are not guaranteed to match the values defined by the GDB Remote Protocol.
+ * See https://sourceware.org/gdb/onlinedocs/gdb/Open-Flags.html#Open-Flags
+ */
+enum {
+       TARGET_O_RDONLY = 0x000,
+       TARGET_O_WRONLY = 0x001,
+       TARGET_O_RDWR   = 0x002,
+       TARGET_O_APPEND = 0x008,
+       TARGET_O_CREAT  = 0x200,
+       TARGET_O_TRUNC  = 0x400,
+       /* O_EXCL=0x800 is not required in this implementation. */
+};
+
+/* GDB remote protocol does not differentiate between text and binary open modes. */
 static const int open_modeflags[12] = {
-       O_RDONLY,
-       O_RDONLY | O_BINARY,
-       O_RDWR,
-       O_RDWR | O_BINARY,
-       O_WRONLY | O_CREAT | O_TRUNC,
-       O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
-       O_RDWR | O_CREAT | O_TRUNC,
-       O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
-       O_WRONLY | O_CREAT | O_APPEND,
-       O_WRONLY | O_CREAT | O_APPEND | O_BINARY,
-       O_RDWR | O_CREAT | O_APPEND,
-       O_RDWR | O_CREAT | O_APPEND | O_BINARY
+       TARGET_O_RDONLY,
+       TARGET_O_RDONLY,
+       TARGET_O_RDWR,
+       TARGET_O_RDWR,
+       TARGET_O_WRONLY | TARGET_O_CREAT | TARGET_O_TRUNC,
+       TARGET_O_WRONLY | TARGET_O_CREAT | TARGET_O_TRUNC,
+       TARGET_O_RDWR   | TARGET_O_CREAT | TARGET_O_TRUNC,
+       TARGET_O_RDWR   | TARGET_O_CREAT | TARGET_O_TRUNC,
+       TARGET_O_WRONLY | TARGET_O_CREAT | TARGET_O_APPEND,
+       TARGET_O_WRONLY | TARGET_O_CREAT | TARGET_O_APPEND,
+       TARGET_O_RDWR   | TARGET_O_CREAT | TARGET_O_APPEND,
+       TARGET_O_RDWR   | TARGET_O_CREAT | TARGET_O_APPEND
 };
 
 static int semihosting_common_fileio_info(struct target *target,

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)