From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 140F93858416; Sat, 5 Nov 2022 10:53:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 140F93858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667645638; bh=XRqGJORuAnx5/roTP9Ft76/Kx6xpr2LnPRw6ouRwLzQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DDICwnLXG+sCKv1xzCuMzBSCVAUqX4LygnjlJXFGWvQVV2IrjJpCoG7NRoLgFvQeD r3HaC18NA+Lm1QgNqTrNwkak3gvskBo5x+ki6UKbQI9UflRf6SO7cGYoCX2s2iRJJy AeOiIN6EU1ST3Xy18GoEljCYt5y/eqlUNEyGE1aU= From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug testsuite/16947] Fail to compile test case when board file local-remote-host.exp is used Date: Sat, 05 Nov 2022 10:53:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: testsuite X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D16947 Tom de Vries changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |vries at gcc dot gnu.org --- Comment #2 from Tom de Vries --- Let's for a moment take this out of the dejagnu context. This is a minimal test-case: ... $ cat test.c #include const char * s =3D S; int main (void) { printf ("S: '%s'\n", s); return 0; } ... When using -DS=3Dfoo, we run into the problem that there are no quotes: ... $ gcc -DS=3Dfoo test.c && ./a.out :0:3: error: =E2=80=98foo=E2=80=99 undeclared here (not in a = function); did you mean =E2=80=98feof=E2=80=99? test.c:3:18: note: in expansion of macro =E2=80=98S=E2=80=99 const char * s =3D S; ... ^ There's a simple way to fix this ( https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html ): ... +#define STR(s) #s +#define XSTR(s) STR (s) -const char * s =3D S; +const char * s =3D XSTR (S); ... with which we have: ... $ gcc -DS=3Dfoo test.c && ./a.out S: 'foo' ... That however breaks down when using names that have parts that are defined = as macros: ... $ gcc -DS=3D/unix/is/number/one test.c && ./a.out S: '/1/is/number/one' ... See for instance commit 250e8e0d7fe ("[gdb/testsuite] Fix dwo path in fission-*.S"). OK, so let's drop the stringizing patch, and try escaping instead: ... $ gcc -DS=3D\"foo\" test.c && ./a.out S: 'foo' ... Well, that works. Now lets try to do that through ssh: ... $ ssh localhost "gcc -DS=3D\"foo\" test.c && ./a.out" :0:3: error: =E2=80=98foo=E2=80=99 undeclared here (not in a = function); did you mean =E2=80=98feof=E2=80=99? test.c:3:18: note: in expansion of macro =E2=80=98S=E2=80=99 const char * s =3D S; ^ ... And so we arrive at: ... $ ssh localhost "gcc -DS=3D\\\"foo\\\" test.c && ./a.out" S: 'foo' ... If we take the arguments passing of ssh out of the equation by using a comm= and file, we run into the same problem: ... $ echo "gcc -DS=3D\"foo\" test.c && ./a.out" > cmd.sh; ssh localhost bash ./cmd.sh :0:3: error: =E2=80=98foo=E2=80=99 undeclared here (not in a = function); did you mean =E2=80=98feof=E2=80=99? test.c:3:18: note: in expansion of macro =E2=80=98S=E2=80=99 const char * s =3D S; ^ ... because: ... $ cat cmd.sh=20 gcc -DS=3D"foo" test.c && ./a.out ... So, again the same fix: ... $ echo "gcc -DS=3D\\\"foo\\\" test.c && ./a.out" > cmd.sh; ssh localhost ba= sh ./cmd.sh S: 'foo' ... A benefit of this approach though is that it's consistent: we run into the = same problems with and without ssh: ... $ bash ./cmd.sh S: 'foo' ... As for the test-case mentioned, foll-exec.exp, it was fixed by commit 31d913c7e4e ("[testsuite] Remove BASEDIR"), which uses a different mechanism and avoids quoting all-together: it uses argv[0] to determine the basedir of the target exec. So, let's try using argument passing: ... $ cat test.c #include int main (int argc, const char *argv[]) { const char *s =3D argv[1]; printf ("S: '%s'\n", s); return 0; } $ gcc test.c && ./a.out foo S: 'foo' $ ssh localhost "gcc test.c && ./a.out foo" S: 'foo' ... That seems to work well. I've also seen a solution in one test-case (can't remember which atm) which uses gdb's ability to set a variable in the target exec: ... $ gcc -g test.c; ./a.out; gdb -q -batch ./a.out -ex start -ex "set var s=3D\"foo\"" -ex continue=20 S: '(null)' Temporary breakpoint 1 at 0x40050b: file test.c, line 8. Temporary breakpoint 1, main () at test.c:8 8 printf ("S: '%s'\n", s); S: 'foo' [Inferior 1 (process 10855) exited normally] ... But that only works when there's debug info, and may need volatile to work = in presence of optimization. [ Note that the escaping is only there because we use -ex, for interactive gdb, we'd just use (gdb) set var s=3D"foo". ] Still, it does work around the escaping issue for interactive gdb over ssh: ... $ ssh localhost gdb -q ./a.out Reading symbols from ./a.out... (gdb) start Temporary breakpoint 1 at 0x40050b: file test.c, line 8. Starting program: /home/vries/a.out=20 Missing separate debuginfos, use: zypper install glibc-debuginfo-2.31-150300.41.1.x86_64 Temporary breakpoint 1, main () at test.c:8 8 printf ("S: '%s'\n", s); (gdb) set var s=3D"foo" (gdb) c Continuing. S: 'foo' [Inferior 1 (process 11253) exited normally] (gdb)=20 ... But ultimately, we run into the same problem with '$ORIGIN' in gdb_compile,= and this: ... if { [is_remote host] } { lappend new_options "ldflags=3D-Wl,-rpath,\\\\\$ORIGIN" } else { lappend new_options "ldflags=3D-Wl,-rpath,\\\$ORIGIN" } ... seems to be the only fix available. --=20 You are receiving this mail because: You are on the CC list for the bug.=