public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Ulf Hermann <ulf.hermann@qt.io>
To: <elfutils-devel@sourceware.org>
Subject: [PATCH v2] Cast pid_t to long long when printing
Date: Mon, 08 May 2017 13:05:00 -0000	[thread overview]
Message-ID: <0e73b569-766f-62a3-a03d-533f46329aa0@qt.io> (raw)

On windows x86_64 pid_t is 64bit wide. We need to adapt our printf
format respectively.

(We can actually print the extra bits in a portable way, so let's do it 
rather than casting to int and ignoring them.)

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
  src/ChangeLog |  4 ++++
  src/stack.c   | 22 +++++++++++-----------
  2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index a474331..1c67b57 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
  2017-05-04  Ulf Hermann  <ulf.hermann@qt.io>
  +	* stack.c: Cast pid_t to int when printing using %d.
+
+2017-05-04  Ulf Hermann  <ulf.hermann@qt.io>
+
  	* strip.c: Close and reopen file when renaming.
   2017-05-04  Ulf Hermann  <ulf.hermann@qt.io>
diff --git a/src/stack.c b/src/stack.c
index 1f5a1c6..da912e5 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,11 @@ print_frames (struct frames *frames, pid_t tid, 
int dwflerr, const char *what)
  	      else
  		modname = "<unknown>";
  	    }
-	  error (0, 0, "%s tid %d at 0x%" PRIx64 " in %s: %s", what, tid,
+	  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 +575,10 @@ 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,
+	    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 +597,10 @@ 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,
+	    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 +688,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 +721,7 @@ 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.8.1.windows.1

                 reply	other threads:[~2017-05-08 10:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0e73b569-766f-62a3-a03d-533f46329aa0@qt.io \
    --to=ulf.hermann@qt.io \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).