Re: pmap: German umlauts are shown as question marks

"Dr. Werner Fink" <[email protected]> Tue, 5 Nov 2024 13:08:59 +0100
Newsgroups gmane.linux.procps.devel
Message-ID <[email protected]>
--q0sYwXQYySzBo8PG
Content-Type: multipart/mixed; boundary="PuJ52KpdgP0Mkqsc"
Content-Disposition: inline


--PuJ52KpdgP0Mkqsc
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2024/11/05 11:53:33 +0100, Dr. Werner Fink wrote:
> On 2024/11/05 09:23:16 +0100, Daniel Hofstetter wrote:
> > Hi,
> >=20
> > I noticed that if I have a binary with German umlauts, the umlauts are
> > shown correctly in the first line but not in the memory map. There,
> > they are shown as question marks:
> >=20
> > $ pmap 19508
> > 19508:   ./target/debug/hello_=C3=A4=C3=B6=C3=BC
> > 00005db66dc51000     20K r---- hello_??????
> > 00005db66dc56000    264K r-x-- hello_??????
> > 00005db66dc98000     52K r---- hello_??????
> > 00005db66dca5000     12K r---- hello_??????
> > 00005db66dca8000      4K rw--- hello_??????
>=20
> There are two places where isprint(3) is checking the bytes of the remain=
ing
> path in /proc/<pid>/maps ... UTF-8 encoding are multibyte characters means
> such multibyte characters are mapped to `?' for each byte.
>=20

A dirty hack for checking for (multi)byte characters with mblen(3)
=2E.. strlen(3) usage could be optimized indeed.

--=20
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr

--PuJ52KpdgP0Mkqsc
Content-Type: text/x-patch; charset=utf-8
Content-Disposition: attachment; filename="x.patch"
Content-Transfer-Encoding: quoted-printable

--- src/pmap.c
+++ src/pmap.c	2024-11-05 12:04:25.265048972 +0000
@@ -199,9 +199,13 @@ static void discover_shm_minor(void)
 			*tmp =3D '\0';
 		tmp =3D mapbuf_b;
 		while (*tmp) {
-			if (!isprint(*tmp))
+			int n =3D mblen(tmp, strlen(tmp));
+			if (n < 0) {
 				*tmp =3D '?';
-			tmp++;
+				tmp++;
+			} else {
+				tmp +=3D n;
+			}
 		}
 		if (start > (unsigned long)addr)
 			continue;
@@ -684,9 +688,13 @@ static int one_proc (struct pids_stack *
 			*tmp =3D '\0';
 		tmp =3D mapbuf;
 		while (*tmp) {
-			if (!isprint(*tmp))
+			int n =3D mblen(tmp, strlen(tmp));
+			if (n < 0) {
 				*tmp =3D '?';
-			tmp++;
+				tmp++;
+			} else {
+				tmp +=3D n;
+			}
 		}
=20
 		diff =3D end - start_To_Avoid_Warning;

--PuJ52KpdgP0Mkqsc--

--q0sYwXQYySzBo8PG
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQJgBAABCABKFiEEGwa/WjgpkPvLonW+UOkNVR3Bay4FAmcqCtQsFIAAAAAAFQAO
cGthLWFkZHJlc3NAZ251cGcub3Jnd2VybmVyQHN1c2UuZGUACgkQUOkNVR3Bay4x
1hAAmLWHJZ8+BMQntBGHsZuWt6ycvZOQqhcHoSsJX9hBnwbhpPRtvDH06QORBPUg
d0rK8k4/LhljI5K07IHWssR/CYPJetPhIgvtNmVLhEOz5gle3xoLiuz33gyA1Sar
oEMlfvrMK7XtgCfg11NvNra7GHCk3kOm5s7MLLpb+yngEk2qKA7STc/Ugf412WmL
hRKlEnUvVErlLgMoO7umXcOC7px6u0z41UvK+rIelCKHZSy3ElQklz4FZK/j4qQ7
EM+wkJe695DEh/U6Yyjv8MakfhDqFBXnthHFQ32uEt+xqojvekqWcufHgzh1Rq5b
ThYS6xWzzGRxPIcYTY3bwYXm+KcknWXSDTHbHCNpiUwF7aXnnqmTTT4VSZJXBfyN
XBgwIDTgDkJUnmFERF81W3LGrbIoTTwCAFUspnyQgHHLm6cJtOUW2gwwLVsWwtFi
aiGt/MFU1gdI+CMRGcdNWcCOy3sFvdQGm3+BCsqrqmnI1tnRI4kaEYUJTcJSuVZK
9m0aHPNJ1SpamvEzKsZ0JoBOmB9xJ2JvkNPAzCL94bos40FUMHJyEVeEGND1cYM5
Qxy6GL9rQpW3xPMvt5ZMv2W70LTUKuR+is0J/I3mxbiVaiZFSBSovUmsTBfKDxNx
dj1sjaRkrEPnLZOBIL26/VvsIkvGg46FkyeXL2ORUpe4dkg=
=vPjo
-----END PGP SIGNATURE-----

--q0sYwXQYySzBo8PG--