[PATCH] Cast pid_t to int when printing it with %d

Ulf Hermann ulf.hermann@qt.io
Thu May 4 16:00:00 GMT 2017


On windows x86_64 pid_t is 64bit wide. We ignore the extra bits as those
messages are only informational anyway.

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

diff --git a/src/ChangeLog b/src/ChangeLog
index 0d1e57d..3c880b4 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>
+
 	* addr2line.c: Don't assume unix file system conventions.
 	* size.c: Likewise.
 	* strip.c: Likewise.
diff --git a/src/stack.c b/src/stack.c
index 1f5a1c6..eb62b8a 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 %d:\n", (int)tid);
   int frame_nr = 0;
   for (int nr = 0; nr < frames->frames && (maxframes == 0
 					   || frame_nr < maxframes); nr++)
@@ -420,7 +420,7 @@ 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);
+	   "(%d, use -n 0 for unlimited)", (int)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 %d at 0x%" PRIx64 " in %s: %s", what, (int)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 %d: %s", what, (int)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 %d: %s", (int)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 %d", (int)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 %d: %s", (int)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 %d", (int)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 %d - %s module memory map\n", (int)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 %d - %s\n", (int)dwfl_pid (dwfl), pid != 0 ? "process" : "core");
       switch (dwfl_getthreads (dwfl, thread_callback, &frames))
 	{
 	case DWARF_CB_OK:
-- 
2.1.4



More information about the Elfutils-devel mailing list