From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1147) id B1FC3395A407; Thu, 17 Nov 2022 09:55:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1FC3395A407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668678956; bh=RzGv0wjJAsExEfuxBfCkOJeCNa8ZCDaH4KAvZjfJwzI=; h=From:To:Subject:Date:From; b=Z4gVqRVj8XaNnktylObJXmC8JnL1Iqm6XdKVa40ZP6NxRzK+1SPELUJrmbXp99TSD e65Lnnqo1NLuyLmZhsxv1C1oQzncjd7NMT8DUO+65MZF+XSvhaZRAd5XphEMMTcnJl qvSLLU9R7aIviU5XXyRa4zq1ByHdZS5gXmwmXlzA= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Rainer Orth To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix various procfs.c compilation errors X-Act-Checkin: binutils-gdb X-Git-Author: Rainer Orth X-Git-Refname: refs/heads/master X-Git-Oldrev: 01804a098dea7d08857eee82bcaad04676dd8ea1 X-Git-Newrev: f4ad82b3bcc4ae2cecba00177561ddfad49ccef2 Message-Id: <20221117095556.B1FC3395A407@sourceware.org> Date: Thu, 17 Nov 2022 09:55:56 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df4ad82b3bcc4= ae2cecba00177561ddfad49ccef2 commit f4ad82b3bcc4ae2cecba00177561ddfad49ccef2 Author: Rainer Orth Date: Thu Nov 17 10:55:25 2022 +0100 Fix various procfs.c compilation errors =20 procfs.c has accumulated several compilation errors lately (some of them new with GCC 12), which are fixed by this patch: =20 * auxv_parse gets: =20 /vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:144:7: error: =C2=91int procfs_target::auxv_parse(gdb_byte**, gdb_byte*, CORE_ADDR*, CORE_ADDR*= )=C2=92 marked =C2=91override=C2=92, but does not override 144 | int auxv_parse (gdb_byte **readptr, | ^~~~~~~~~~ =20 Obviouly, procfs.c was missed in the auxv_parse constification. =20 * dead_procinfo has: =20 /vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c: In function =C2=91void dead_procinfo(procinfo*, const char*, int)=C2=92: /vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:563:11: warning: the addre= ss of =C2=91procinfo::pathname=C2=92 will never be NULL [-Waddress] 563 | if (pi->pathname) | ~~~~^~~~~~~~ /vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:238:8: note: =C2=91procinfo::pathname=C2=92 declared here 238 | char pathname[MAX_PROC_NAME_SIZE]; /* Pathname to /proc en= try */ | ^~~~~~~~ =20 The warning is correct, so the code can lose support for the NULL pathname case. =20 * create_inferior has this ugly warning: =20 /vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c: In member function =C2=91= virtual void procfs_target::create_inferior(const char*, const std::string&= , char**, int)=C2=92: /vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:2815:19: warning: =C2=91ch= ar* std::strncpy(char*, const char*, size_t)=C2=92 output truncated before = terminating nul copying as many bytes from a string as its length [-Wstring= op-truncation] 2815 | strncpy (tryname, p, len); | ~~~~~~~~^~~~~~~~~~~~~~~~~ /vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:2814:26: note: length comp= uted here 2814 | len =3D strlen (p); | ~~~~~~~^~~ =20 It seems that this is another case of GCC PR middle-end/88059, which Martin Sebor refuses to fix. So I'm using the hack suggested in the PR to use memcpy instead of strncpy. =20 * find_memory_regions_callback fails with =20 /vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c: In function =C2=91int fin= d_memory_regions_callback(prmap*, find_memory_region_ftype, void*)=C2=92: /vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:3167:18: error: too few ar= guments to function 3167 | return (*func) ((CORE_ADDR) map->pr_vaddr, | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ 3168 | map->pr_size, | ~~~~~~~~~~~~~ 3169 | (map->pr_mflags & MA_READ) !=3D 0, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3170 | (map->pr_mflags & MA_WRITE) !=3D 0, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3171 | (map->pr_mflags & MA_EXEC) !=3D 0, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3172 | 1, /* MODIFIED is unknown, pass it as true. = */ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~ 3173 | data); | ~~~~~ =20 Again, procfs.c was overlooked when adding the new memory_tagged arg. Unfortunately, it wasn't even documented in gdb/defs.h when it was added in =20 commit 68cffbbd4406b4efe1aa6e18460b1d7ca02549f1 Author: Luis Machado Date: Thu Mar 31 11:42:35 2022 +0100 =20 [AArch64] MTE corefile support =20 With those changes, procfs.c compiles again. Together with the hack from the Solaris gdbsupport breakage reported in PR build/29791, I was able to build and test gdb on both amd64-pc-solaris2.11 and sparcv9-sun-solaris2.11. =20 Approved-By: Simon Marchi Diff: --- gdb/procfs.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/gdb/procfs.c b/gdb/procfs.c index c5715627f6f..141db3dd793 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -141,8 +141,8 @@ public: bool info_proc (const char *, enum info_proc_what) override; =20 #if PR_MODEL_NATIVE =3D=3D PR_MODEL_LP64 - int auxv_parse (gdb_byte **readptr, - gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp) + int auxv_parse (const gdb_byte **readptr, + const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp) override; #endif =20 @@ -169,11 +169,12 @@ static procfs_target the_procfs_target; is presented in 64-bit format. We need to provide a custom parser to handle that. */ int -procfs_target::auxv_parse (gdb_byte **readptr, - gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp) +procfs_target::auxv_parse (const gdb_byte **readptr, + const gdb_byte *endptr, CORE_ADDR *typep, + CORE_ADDR *valp) { enum bfd_endian byte_order =3D gdbarch_byte_order (target_gdbarch ()); - gdb_byte *ptr =3D *readptr; + const gdb_byte *ptr =3D *readptr; =20 if (endptr =3D=3D ptr) return 0; @@ -559,15 +560,7 @@ enum { NOKILL, KILL }; static void dead_procinfo (procinfo *pi, const char *msg, int kill_p) { - char procfile[80]; - - if (pi->pathname) - print_sys_errmsg (pi->pathname, errno); - else - { - xsnprintf (procfile, sizeof (procfile), "process %d", pi->pid); - print_sys_errmsg (procfile, errno); - } + print_sys_errmsg (pi->pathname, errno); if (kill_p =3D=3D KILL) kill (pi->pid, SIGKILL); =20 @@ -2813,7 +2806,7 @@ procfs_target::create_inferior (const char *exec_file, len =3D p1 - p; else len =3D strlen (p); - strncpy (tryname, p, len); + memcpy (tryname, p, len); tryname[len] =3D '\0'; strcat (tryname, "/"); strcat (tryname, shell_file); @@ -3170,6 +3163,7 @@ find_memory_regions_callback (struct prmap *map, (map->pr_mflags & MA_WRITE) !=3D 0, (map->pr_mflags & MA_EXEC) !=3D 0, 1, /* MODIFIED is unknown, pass it as true. */ + false, data); }