This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Make procfs.c build warning free
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 9 Sep 2008 03:26:13 +0100
- Subject: Make procfs.c build warning free
Hi,
This file is currently built without -Werror. The attached patch fixes all
the warnings I could find.
The -Wformat errors I saw were actually due to passing a non-constant string
to printf-like functions. This file has quite a bit of #ifdefing, so I
may have missed some warning, but I audited all printf-like calls, and
all looked OK to me. Particularly, Makefile.in mentions prints pid_t
varables, but it doesn't seem there's any variable of type pid_t in
the file anymore -- pids and tids are stored as ints in the
procinfo structure.
The rest of the warnings were about printing longs with %d format, and a
couple of functions that were not updated to take gdb_byte pointers
instead of char or void pointers.
Tested on i386-pc-solaris2.11, with both gcc and SunCC.
OK?
--
Pedro Alves
2008-09-09 Pedro Alves <pedro@codesourcery.com>
Make it compile without warnings.
* procfs.c (dead_procinfo): Pass a constant string as format to
error.
(procfs_address_to_host_pointer): Add cast to gdb_type *.
(procfs_find_LDT_entry): Adjust format string to long int
ptid.tid.
(procfs_xfer_partial): Adjust prototype. Add gdb_byte* cast.
(procfs_xfer_memory): Adjust prototype.
(info_mappings_callback, info_proc_mappings): Adjust to not pass a
variable as printf_filtered format.
(procfs_make_note_section): Change type of auxv local to gdb_byte.
---
gdb/Makefile.in | 6 ---
gdb/procfs.c | 86 +++++++++++++++++++++++++++++---------------------------
2 files changed, 46 insertions(+), 46 deletions(-)
Index: src/gdb/procfs.c
===================================================================
--- src.orig/gdb/procfs.c 2008-09-09 03:00:08.000000000 +0100
+++ src/gdb/procfs.c 2008-09-09 03:05:44.000000000 +0100
@@ -126,13 +126,13 @@ static void procfs_kill_inferior (void);
static void procfs_mourn_inferior (void);
static void procfs_create_inferior (char *, char *, char **, int);
static ptid_t procfs_wait (ptid_t, struct target_waitstatus *);
-static int procfs_xfer_memory (CORE_ADDR, char *, int, int,
+static int procfs_xfer_memory (CORE_ADDR, gdb_byte *, int, int,
struct mem_attrib *attrib,
struct target_ops *);
static LONGEST procfs_xfer_partial (struct target_ops *ops,
enum target_object object,
const char *annex,
- void *readbuf, const void *writebuf,
+ gdb_byte *readbuf, const gdb_byte *writebuf,
ULONGEST offset, LONGEST len);
static int procfs_thread_alive (ptid_t);
@@ -867,7 +867,7 @@ dead_procinfo (procinfo *pi, char *msg,
kill (pi->pid, SIGKILL);
destroy_procinfo (pi);
- error ((msg));
+ error ("%s", msg);
}
/*
@@ -2903,7 +2903,7 @@ procfs_address_to_host_pointer (CORE_ADD
gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr));
gdbarch_address_to_pointer (current_gdbarch, builtin_type_void_data_ptr,
- &ptr, addr);
+ (gdb_byte *) &ptr, addr);
return ptr;
}
@@ -3065,14 +3065,14 @@ procfs_find_LDT_entry (ptid_t ptid)
/* Find procinfo for the lwp. */
if ((pi = find_procinfo (PIDGET (ptid), TIDGET (ptid))) == NULL)
{
- warning (_("procfs_find_LDT_entry: could not find procinfo for %d:%d."),
+ warning (_("procfs_find_LDT_entry: could not find procinfo for %d:%ld."),
PIDGET (ptid), TIDGET (ptid));
return NULL;
}
/* get its general registers. */
if ((gregs = proc_get_gregs (pi)) == NULL)
{
- warning (_("procfs_find_LDT_entry: could not read gregs for %d:%d."),
+ warning (_("procfs_find_LDT_entry: could not read gregs for %d:%ld."),
PIDGET (ptid), TIDGET (ptid));
return NULL;
}
@@ -4370,18 +4370,18 @@ wait_again:
static LONGEST
procfs_xfer_partial (struct target_ops *ops, enum target_object object,
- const char *annex, void *readbuf,
- const void *writebuf, ULONGEST offset, LONGEST len)
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
{
switch (object)
{
case TARGET_OBJECT_MEMORY:
if (readbuf)
- return (*ops->deprecated_xfer_memory) (offset, readbuf, len,
- 0/*read*/, NULL, ops);
+ return (*ops->deprecated_xfer_memory) (offset, readbuf,
+ len, 0/*read*/, NULL, ops);
if (writebuf)
- return (*ops->deprecated_xfer_memory) (offset, writebuf, len,
- 1/*write*/, NULL, ops);
+ return (*ops->deprecated_xfer_memory) (offset, (gdb_byte *) writebuf,
+ len, 1/*write*/, NULL, ops);
return -1;
#ifdef NEW_PROC_API
@@ -4410,7 +4410,7 @@ procfs_xfer_partial (struct target_ops *
negative values, but this capability isn't implemented here.) */
static int
-procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int dowrite,
+procfs_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int dowrite,
struct mem_attrib *attrib, struct target_ops *target)
{
procinfo *pi;
@@ -5773,23 +5773,28 @@ mappingflags (long flags)
static int
info_mappings_callback (struct prmap *map, int (*ignore) (), void *unused)
{
- char *data_fmt_string;
+ unsigned int pr_off;
- if (gdbarch_addr_bit (current_gdbarch) == 32)
- data_fmt_string = "\t%#10lx %#10lx %#10x %#10x %7s\n";
- else
- data_fmt_string = " %#18lx %#18lx %#10x %#10x %7s\n";
-
- printf_filtered (data_fmt_string,
- (unsigned long) map->pr_vaddr,
- (unsigned long) map->pr_vaddr + map->pr_size - 1,
- map->pr_size,
#ifdef PCAGENT /* Horrible hack: only defined on Solaris 2.6+ */
- (unsigned int) map->pr_offset,
+ pr_off = (unsigned int) map->pr_offset;
#else
- map->pr_off,
+ pr_off = map->pr_off;
#endif
- mappingflags (map->pr_mflags));
+
+ if (gdbarch_addr_bit (current_gdbarch) == 32)
+ printf_filtered ("\t%#10lx %#10lx %#10x %#10x %7s\n",
+ (unsigned long) map->pr_vaddr,
+ (unsigned long) map->pr_vaddr + map->pr_size - 1,
+ map->pr_size,
+ pr_off,
+ mappingflags (map->pr_mflags));
+ else
+ printf_filtered (" %#18lx %#18lx %#10x %#10x %7s\n",
+ (unsigned long) map->pr_vaddr,
+ (unsigned long) map->pr_vaddr + map->pr_size - 1,
+ map->pr_size,
+ pr_off,
+ mappingflags (map->pr_mflags));
return 0;
}
@@ -5803,23 +5808,24 @@ info_mappings_callback (struct prmap *ma
static void
info_proc_mappings (procinfo *pi, int summary)
{
- char *header_fmt_string;
-
- if (gdbarch_ptr_bit (current_gdbarch) == 32)
- header_fmt_string = "\t%10s %10s %10s %10s %7s\n";
- else
- header_fmt_string = " %18s %18s %10s %10s %7s\n";
-
if (summary)
return; /* No output for summary mode. */
printf_filtered (_("Mapped address spaces:\n\n"));
- printf_filtered (header_fmt_string,
- "Start Addr",
- " End Addr",
- " Size",
- " Offset",
- "Flags");
+ if (gdbarch_ptr_bit (current_gdbarch) == 32)
+ printf_filtered ("\t%10s %10s %10s %10s %7s\n",
+ "Start Addr",
+ " End Addr",
+ " Size",
+ " Offset",
+ "Flags");
+ else
+ printf_filtered (" %18s %18s %10s %10s %7s\n",
+ "Start Addr",
+ " End Addr",
+ " Size",
+ " Offset",
+ "Flags");
iterate_over_mappings (pi, NULL, NULL, info_mappings_callback);
printf_filtered ("\n");
@@ -6145,7 +6151,7 @@ procfs_make_note_section (bfd *obfd, int
char *note_data = NULL;
char *inf_args;
struct procfs_corefile_thread_data thread_args;
- char *auxv;
+ gdb_byte *auxv;
int auxv_len;
if (get_exec_file (0))
Index: src/gdb/Makefile.in
===================================================================
--- src.orig/gdb/Makefile.in 2008-09-08 20:02:16.000000000 +0100
+++ src/gdb/Makefile.in 2008-09-09 03:05:44.000000000 +0100
@@ -1370,12 +1370,6 @@ printcmd.o: $(srcdir)/printcmd.c
$(GDB_WERROR_CFLAGS) $(COMPILE.post) $(srcdir)/printcmd.c
$(POSTCOMPILE)
-# FIXME: Procfs.o gets -Wformat errors because things like pid_t don't
-# match output format strings.
-procfs.o: $(srcdir)/procfs.c
- $(COMPILE.pre) $(INTERNAL_WARN_CFLAGS) $(COMPILE.post) $(srcdir)/procfs.c
- $(POSTCOMPILE)
-
# Message files. Based on code in gcc/Makefile.in.
# Rules for generating translated message descriptions. Disabled by