Fix gdb C++ compilation on Solaris (PR build/20712)

gdb 7.12 doesn't compile as C++ (tried with g++ 4.9) on Solaris (tried
10 and 12, sparc and x86).  The following patch (relative to the 7.12
release, though I expect most if not all issues to be present on trunk,
too) fixes this.

Only a few of the changes bear explanation:

* Initially, compilation failed whereever defs.h. was included:

In file included from /vol/src/gnu/gdb/gdb-7.12/gdb/gdb.c:19:0:
/vol/src/gnu/gdb/gdb-7.12/gdb/defs.h:630:33: error: 'double atof(const char*)' conflicts with a previous declaration
 extern double atof (const char *); /* X3.159-1989  4.10.1.1 */
                                 ^
In file included from /usr/include/stdlib.h:17:0,
                 from build-gnulib/import/stdlib.h:36,
                 from /vol/src/gnu/gdb/gdb-7.12/gdb/common/common-defs.h:32,
                 from /vol/src/gnu/gdb/gdb-7.12/gdb/defs.h:28,
                 from /vol/src/gnu/gdb/gdb-7.12/gdb/gdb.c:19:
/vol/gcc-4.9/lib/gcc/i386-pc-solaris2.10/4.9.0/include-fixed/iso/stdlib_iso.h:119:15: note: previous declaration 'double std::atof(const char*)'
 extern double atof(const char *);
               ^

  This is due to this gem in gdb/defs.h which seems to have been present
  like forever:

#ifndef atof
extern double atof (const char *);	/* X3.159-1989  4.10.1.1 */
#endif

  In the Solaris headers, the appropriate functions are in namespace std,
  thus the conflict.  I've wrapped the defs.h declaration in !__cplusplus
  to avoid this; perhaps it can go completely instead.

* All the casts are necessary to appease g++ and should be pretty
  obvious.

* The sol-thread.c changes are here to handle

/vol/src/gnu/gdb/gdb-7.12/gdb/sol-thread.c: In function 'void _initialize_sol_thread()':
/vol/src/gnu/gdb/gdb-7.12/gdb/sol-thread.c:1252:36: error: invalid conversion from 'void*' to 'void (*)(int)' [-fpermissive]
   if (!(p_##X = dlsym (dlhandle, #X))) \
                                    ^
/vol/src/gnu/gdb/gdb-7.12/gdb/sol-thread.c:1255:3: note: in expansion of macro 'resolve'
   resolve (td_log);
   ^

  and are modeled after linux-thread-db.c (try_thread_db_load_1).

The patch allowed both 32 and 64-bit C++ builds on sparc-sun-solaris2.10
and i386-pc-solaris2.10 to complete.  The resulting binary hasn't seen
more than a smoke test (invoke it on itself, b main, run) yet.

When investigating the failure to detect -static-libstdc++
support (more below), I found two more issues which only show up with
-Werror:

/vol/src/gnu/gdb/gdb/local/gdb/procfs.c: In function 'ssd* proc_get_LDT_entry(procinfo*, int)':
/vol/src/gnu/gdb/gdb/local/gdb/procfs.c:2487:19: error: variable 'old_chain' set but not used [-Werror=unused-but-set-variable]
   struct cleanup *old_chain = NULL;
                   ^

Unless I'm mistaken, you need to run do_cleanups on every return from
the function.

Afterwards, I ran a 32-bit compilation, which (after adding
--disable-largefile to avoid

In file included from /usr/include/sys/procfs.h:28:0,
                 from /vol/src/gnu/gdb/gdb/local/gdb/i386-sol2-nat.c:23:
/usr/include/sys/old_procfs.h:39:2: error: #error "Cannot use procfs in the large file compilation environment"
 #error "Cannot use procfs in the large file compilation environment"
  ^

and two more instances) revealed

/vol/src/gnu/gdb/gdb/local/gdb/top.c: In function 'void gdb_safe_append_history()':
/vol/src/gnu/gdb/gdb/local/gdb/top.c:1170:59: error: format '%d' expects argument of type 'int', but argument 3 has type 'pid_t {aka long int}' [-Werror=format=]
     = xstrprintf ("%s-gdb%d~", history_filename, getpid ());
                                                           ^

Fixed by casting pid_t to long and printing it as such.
This commit is contained in:
Rainer Orth
2016-10-25 15:19:46 +02:00
parent b30f354acb
commit b196bc4cb4
5 changed files with 127 additions and 71 deletions

View File

@@ -791,7 +791,7 @@ destroy_procinfo (procinfo *pi)
static void
do_destroy_procinfo_cleanup (void *pi)
{
destroy_procinfo (pi);
destroy_procinfo ((procinfo *) pi);
}
enum { NOKILL, KILL };
@@ -845,7 +845,7 @@ sysset_t_alloc (procinfo * pi)
sysset_t *ret;
int size = sysset_t_size (pi);
ret = xmalloc (size);
ret = (sysset_t *) xmalloc (size);
#ifdef DYNAMIC_SYSCALLS
ret->pr_size = ((pi->num_syscalls + (8 * sizeof (uint64_t) - 1))
/ (8 * sizeof (uint64_t)));
@@ -1675,7 +1675,7 @@ proc_set_traced_sysentry (procinfo *pi, sysset_t *sysset)
- sizeof (sysset_t)
+ sysset_t_size (pi);
argp = xmalloc (argp_size);
argp = (struct gdb_proc_ctl_pcsentry *) xmalloc (argp_size);
argp->cmd = PCSENTRY;
memcpy (&argp->sysset, sysset, sysset_t_size (pi));
@@ -1720,7 +1720,7 @@ proc_set_traced_sysexit (procinfo *pi, sysset_t *sysset)
- sizeof (sysset_t)
+ sysset_t_size (pi);
argp = xmalloc (argp_size);
argp = (struct gdb_proc_ctl_pcsexit *) xmalloc (argp_size);
argp->cmd = PCSEXIT;
memcpy (&argp->sysset, sysset, sysset_t_size (pi));
@@ -2512,9 +2512,13 @@ proc_get_LDT_entry (procinfo *pi, int key)
break; /* end of table */
/* If key matches, return this entry. */
if (ldt_entry->sel == key)
return ldt_entry;
{
do_cleanups (old_chain);
return ldt_entry;
}
}
/* Loop ended, match not found. */
do_cleanups (old_chain);
return NULL;
#else
int nldt, i;
@@ -2756,7 +2760,7 @@ proc_update_threads (procinfo *pi)
static void
do_closedir_cleanup (void *dir)
{
closedir (dir);
closedir ((DIR *) dir);
}
static int
@@ -3836,7 +3840,7 @@ wait_again:
add_thread (temp_ptid);
status->kind = TARGET_WAITKIND_STOPPED;
status->value.sig = 0;
status->value.sig = GDB_SIGNAL_0;
return retval;
}
#endif
@@ -4567,7 +4571,7 @@ procfs_create_inferior (struct target_ops *ops, char *exec_file,
if (path == NULL)
path = "/bin:/usr/bin";
tryname = alloca (strlen (path) + strlen (shell_file) + 2);
tryname = (char *) alloca (strlen (path) + strlen (shell_file) + 2);
for (p = path; p != NULL; p = p1 ? p1 + 1: NULL)
{
p1 = strchr (p, ':');
@@ -5367,7 +5371,8 @@ struct procfs_corefile_thread_data {
static int
procfs_corefile_thread_callback (procinfo *pi, procinfo *thread, void *data)
{
struct procfs_corefile_thread_data *args = data;
struct procfs_corefile_thread_data *args
= (struct procfs_corefile_thread_data *) data;
if (pi != NULL)
{