aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Peter Nilsson <hp@axis.com>2022-02-14 23:53:13 +0100
committerHans-Peter Nilsson <hp@bitrange.com>2022-02-14 23:53:13 +0100
commit4b0e74fd1813aeb302cd97024d9e82a29282fb8d (patch)
tree7b42bba72a72338976af1fb7e122768e2499cfb7
parent81011383d94b2f630cd8fdad989f2e24d4889c1e (diff)
downloadgdb-4b0e74fd1813aeb302cd97024d9e82a29282fb8d.zip
gdb-4b0e74fd1813aeb302cd97024d9e82a29282fb8d.tar.gz
gdb-4b0e74fd1813aeb302cd97024d9e82a29282fb8d.tar.bz2
sim/testsuite/cris: Remove faulty use of basename in C tests
Calls to basename were added here as part of commit e1e1ae6e9b5e "sim: testsuite: fix objdir handling", but that commit missed adding "#include <libgen.h>" or the equivalent GNU extension, see basename(3). Fixing that shows a logical error in the change to openpf1.c; the non-/-prefixed code-path was changed instead of the "/"-prefixed code-path, which is the one executed after that commit. For "newlib" these tests failed linking after that commit. Recent newlib has the (asm-renamed) GNU-extension-variant of basename, but we're better off not using it at all. Unfortunately, compilation failures for C tests run by the machinery in c.exp are currently just marked "unresolved", in contrast to C and assembler tests run by calling run_sim_test. The interaction of calling with the full program-path vs. use of --sysroot exposes a consistency problem: when --sysroot is used, argv[0] isn't the path by which the program can find itself. It's undecided whether argv[0] for the program running in the simulator should be edited (related to the naked argument to the simulator before passing on to the simulated program) to remove a leading --sysroot. Either way, such a change would be out of scope for this commit. * c/stat3.c (mybasename): New macro. Use it instead of basename. * c/openpf1.c: Correct basename-related change and update related comment.
-rw-r--r--sim/testsuite/cris/c/openpf1.c8
-rw-r--r--sim/testsuite/cris/c/stat3.c3
2 files changed, 7 insertions, 4 deletions
diff --git a/sim/testsuite/cris/c/openpf1.c b/sim/testsuite/cris/c/openpf1.c
index 92d12bf..37940d7 100644
--- a/sim/testsuite/cris/c/openpf1.c
+++ b/sim/testsuite/cris/c/openpf1.c
@@ -3,8 +3,8 @@
We assume, with EXE being the name of the executable:
- The simulator executes with cwd the same directory where the executable
- is located (so argv[0] contains a plain filename without directory
- components).
+ is located (also argv[0] contains a plain filename without directory
+ components -or- argv[0] contains the full non-sysroot path to EXE).
- There's no /EXE on the host file system. */
#include <stdio.h>
@@ -21,8 +21,10 @@ int main (int argc, char *argv[])
if (fnam == NULL)
abort ();
strcpy (fnam, "/");
- strcat (fnam, basename (argv[0]));
+ strcat (fnam, argv[0]);
}
+ else
+ fnam = strrchr (argv[0], '/');
f = fopen (fnam, "rb");
if (f == NULL)
diff --git a/sim/testsuite/cris/c/stat3.c b/sim/testsuite/cris/c/stat3.c
index eac4da9..f7c9604 100644
--- a/sim/testsuite/cris/c/stat3.c
+++ b/sim/testsuite/cris/c/stat3.c
@@ -7,13 +7,14 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#define mybasename(x) ({ const char *x_ = (x), *y_ = strrchr (x_, '/'); y_ != NULL ? y_ + 1 : x_; })
int main (int argc, char *argv[])
{
char path[1024] = "/";
struct stat buf;
- strcat (path, basename (argv[0]));
+ strcat (path, mybasename(argv[0]));
if (stat (".", &buf) != 0
|| !S_ISDIR (buf.st_mode))
abort ();