From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 56291 invoked by alias); 19 Aug 2017 08:11:36 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 55154 invoked by uid 89); 19 Aug 2017 08:11:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-21.9 required=5.0 tests=AWL,BAYES_00,DATE_IN_PAST_06_12,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=H*M:stream X-Spam-Status: No, score=-21.9 required=5.0 tests=AWL,BAYES_00,DATE_IN_PAST_06_12,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 19 Aug 2017 08:11:05 +0000 Received: from stream.wildebeest.org (ADijon-357-1-27-209.w109-217.abo.wanadoo.fr [109.217.50.209]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 9B2DD33138D5; Sat, 19 Aug 2017 10:11:03 +0200 (CEST) Received: by stream.wildebeest.org (Postfix, from userid 1000) id 6BE7D101FF3; Fri, 18 Aug 2017 23:54:43 +0200 (CEST) Date: Sat, 19 Aug 2017 08:11:00 -0000 From: Mark Wielaard To: Ulf Hermann Cc: elfutils-devel@sourceware.org Subject: Re: [PATCH v3] Cast pid_t to long long when printing Message-ID: <20170818215443.GI3169@stream> References: <47fb818e-8ade-bb8f-3588-6eb8595f5612@qt.io> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vtzGhvizbBRQ85DL" Content-Disposition: inline In-Reply-To: <47fb818e-8ade-bb8f-3588-6eb8595f5612@qt.io> User-Agent: Mutt/1.8.3 (2017-05-23) X-IsSubscribed: yes X-SW-Source: 2017-q3/txt/msg00093.txt.bz2 --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 444 On Fri, Aug 18, 2017 at 05:20:02PM +0200, Ulf Hermann wrote: > We don't know sizeof(pid_t) as it's not specified in any standard. In > order to still print it, we cast to long long, the largest integer type > we can easily print. That is surprising. But then printing it as long long is as good as any other choice. I did tweak the patch a little so there is always a space after the cast and no line gets longer than 80 chars. Thanks, Mark --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Cast-pid_t-to-long-long-when-printing.patch" Content-length: 4385 >From 760925bc7b43814d30ee4e0396709fe8a3f66cd6 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 18 Aug 2017 17:20:02 +0200 Subject: [PATCH] Cast pid_t to long long when printing We don't know sizeof(pid_t) as it's not specified in any standard. In order to still print it, we cast to long long, the largest integer type we can easily print. Signed-off-by: Ulf Hermann Signed-off-by: Mark Wielaard --- src/ChangeLog | 4 ++++ src/stack.c | 32 ++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8aa57051..daedfca6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2017-05-04 Ulf Hermann + + * stack.c: Print pid_t using %lld. + 2017-08-18 Ulf Hermann * readelf.c: Hardcode the signal numbers for non-linux systems. diff --git a/src/stack.c b/src/stack.c index 6f2ff69f..7c180b79 100644 --- a/src/stack.c +++ b/src/stack.c @@ -362,7 +362,7 @@ print_frames (struct frames *frames, pid_t tid, int dwflerr, const char *what) if (frames->frames > 0) frames_shown = true; - printf ("TID %d:\n", tid); + printf ("TID %lld:\n", (long long) tid); int frame_nr = 0; for (int nr = 0; nr < frames->frames && (maxframes == 0 || frame_nr < maxframes); nr++) @@ -419,8 +419,8 @@ print_frames (struct frames *frames, pid_t tid, int dwflerr, const char *what) } if (frames->frames > 0 && frame_nr == maxframes) - error (0, 0, "tid %d: shown max number of frames " - "(%d, use -n 0 for unlimited)", tid, maxframes); + error (0, 0, "tid %lld: shown max number of frames " + "(%d, use -n 0 for unlimited)", (long long) tid, maxframes); else if (dwflerr != 0) { if (frames->frames > 0) @@ -440,11 +440,12 @@ print_frames (struct frames *frames, pid_t tid, int dwflerr, const char *what) else modname = ""; } - error (0, 0, "%s tid %d at 0x%" PRIx64 " in %s: %s", what, tid, - pc_adjusted, modname, dwfl_errmsg (dwflerr)); + error (0, 0, "%s tid %lld at 0x%" PRIx64 " in %s: %s", what, + (long long) tid, pc_adjusted, modname, dwfl_errmsg (dwflerr)); } else - error (0, 0, "%s tid %d: %s", what, tid, dwfl_errmsg (dwflerr)); + error (0, 0, "%s tid %lld: %s", what, (long long) tid, + dwfl_errmsg (dwflerr)); } } @@ -575,10 +576,11 @@ parse_opt (int key, char *arg __attribute__ ((unused)), int err = dwfl_linux_proc_report (dwfl, pid); if (err < 0) - error (EXIT_BAD, 0, "dwfl_linux_proc_report pid %d: %s", pid, - dwfl_errmsg (-1)); + error (EXIT_BAD, 0, "dwfl_linux_proc_report pid %lld: %s", + (long long) pid, dwfl_errmsg (-1)); else if (err > 0) - error (EXIT_BAD, err, "dwfl_linux_proc_report pid %d", pid); + error (EXIT_BAD, err, "dwfl_linux_proc_report pid %lld", + (long long) pid); } if (core != NULL) @@ -597,10 +599,11 @@ parse_opt (int key, char *arg __attribute__ ((unused)), { int err = dwfl_linux_proc_attach (dwfl, pid, false); if (err < 0) - error (EXIT_BAD, 0, "dwfl_linux_proc_attach pid %d: %s", pid, - dwfl_errmsg (-1)); + error (EXIT_BAD, 0, "dwfl_linux_proc_attach pid %lld: %s", + (long long) pid, dwfl_errmsg (-1)); else if (err > 0) - error (EXIT_BAD, err, "dwfl_linux_proc_attach pid %d", pid); + error (EXIT_BAD, err, "dwfl_linux_proc_attach pid %lld", + (long long) pid); } if (core != NULL) @@ -688,7 +691,7 @@ invoked with bad or missing arguments it will exit with return code 64.") if (show_modules) { - printf ("PID %d - %s module memory map\n", dwfl_pid (dwfl), + printf ("PID %lld - %s module memory map\n", (long long) dwfl_pid (dwfl), pid != 0 ? "process" : "core"); if (dwfl_getmodules (dwfl, module_callback, NULL, 0) != 0) error (EXIT_BAD, 0, "dwfl_getmodules: %s", dwfl_errmsg (-1)); @@ -721,7 +724,8 @@ invoked with bad or missing arguments it will exit with return code 64.") } else { - printf ("PID %d - %s\n", dwfl_pid (dwfl), pid != 0 ? "process" : "core"); + printf ("PID %lld - %s\n", (long long) dwfl_pid (dwfl), + pid != 0 ? "process" : "core"); switch (dwfl_getthreads (dwfl, thread_callback, &frames)) { case DWARF_CB_OK: -- 2.13.5 --vtzGhvizbBRQ85DL--