OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [gdb/] [fbsd-nat.c] - Diff between revs 834 and 842

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 834 Rev 842
/* Native-dependent code for FreeBSD.
/* Native-dependent code for FreeBSD.
 
 
   Copyright (C) 2002, 2003, 2004, 2007, 2008, 2009, 2010
   Copyright (C) 2002, 2003, 2004, 2007, 2008, 2009, 2010
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
#include "defs.h"
#include "defs.h"
#include "gdbcore.h"
#include "gdbcore.h"
#include "inferior.h"
#include "inferior.h"
#include "regcache.h"
#include "regcache.h"
#include "regset.h"
#include "regset.h"
#include "gdbthread.h"
#include "gdbthread.h"
 
 
#include "gdb_assert.h"
#include "gdb_assert.h"
#include "gdb_string.h"
#include "gdb_string.h"
#include <sys/types.h>
#include <sys/types.h>
#include <sys/procfs.h>
#include <sys/procfs.h>
#include <sys/sysctl.h>
#include <sys/sysctl.h>
 
 
#include "elf-bfd.h"
#include "elf-bfd.h"
#include "fbsd-nat.h"
#include "fbsd-nat.h"
 
 
/* Return a the name of file that can be opened to get the symbols for
/* Return a the name of file that can be opened to get the symbols for
   the child process identified by PID.  */
   the child process identified by PID.  */
 
 
char *
char *
fbsd_pid_to_exec_file (int pid)
fbsd_pid_to_exec_file (int pid)
{
{
  size_t len = MAXPATHLEN;
  size_t len = MAXPATHLEN;
  char *buf = xcalloc (len, sizeof (char));
  char *buf = xcalloc (len, sizeof (char));
  char *path;
  char *path;
 
 
#ifdef KERN_PROC_PATHNAME
#ifdef KERN_PROC_PATHNAME
  int mib[4];
  int mib[4];
 
 
  mib[0] = CTL_KERN;
  mib[0] = CTL_KERN;
  mib[1] = KERN_PROC;
  mib[1] = KERN_PROC;
  mib[2] = KERN_PROC_PATHNAME;
  mib[2] = KERN_PROC_PATHNAME;
  mib[3] = pid;
  mib[3] = pid;
  if (sysctl (mib, 4, buf, &len, NULL, 0) == 0)
  if (sysctl (mib, 4, buf, &len, NULL, 0) == 0)
    return buf;
    return buf;
#endif
#endif
 
 
  path = xstrprintf ("/proc/%d/file", pid);
  path = xstrprintf ("/proc/%d/file", pid);
  if (readlink (path, buf, MAXPATHLEN) == -1)
  if (readlink (path, buf, MAXPATHLEN) == -1)
    {
    {
      xfree (buf);
      xfree (buf);
      buf = NULL;
      buf = NULL;
    }
    }
 
 
  xfree (path);
  xfree (path);
  return buf;
  return buf;
}
}
 
 
static int
static int
fbsd_read_mapping (FILE *mapfile, unsigned long *start, unsigned long *end,
fbsd_read_mapping (FILE *mapfile, unsigned long *start, unsigned long *end,
                   char *protection)
                   char *protection)
{
{
  /* FreeBSD 5.1-RELEASE uses a 256-byte buffer.  */
  /* FreeBSD 5.1-RELEASE uses a 256-byte buffer.  */
  char buf[256];
  char buf[256];
  int resident, privateresident;
  int resident, privateresident;
  unsigned long obj;
  unsigned long obj;
  int ret = EOF;
  int ret = EOF;
 
 
  /* As of FreeBSD 5.0-RELEASE, the layout is described in
  /* As of FreeBSD 5.0-RELEASE, the layout is described in
     /usr/src/sys/fs/procfs/procfs_map.c.  Somewhere in 5.1-CURRENT a
     /usr/src/sys/fs/procfs/procfs_map.c.  Somewhere in 5.1-CURRENT a
     new column was added to the procfs map.  Therefore we can't use
     new column was added to the procfs map.  Therefore we can't use
     fscanf since we need to support older releases too.  */
     fscanf since we need to support older releases too.  */
  if (fgets (buf, sizeof buf, mapfile) != NULL)
  if (fgets (buf, sizeof buf, mapfile) != NULL)
    ret = sscanf (buf, "%lx %lx %d %d %lx %s", start, end,
    ret = sscanf (buf, "%lx %lx %d %d %lx %s", start, end,
                  &resident, &privateresident, &obj, protection);
                  &resident, &privateresident, &obj, protection);
 
 
  return (ret != 0 && ret != EOF);
  return (ret != 0 && ret != EOF);
}
}
 
 
/* Iterate over all the memory regions in the current inferior,
/* Iterate over all the memory regions in the current inferior,
   calling FUNC for each memory region.  OBFD is passed as the last
   calling FUNC for each memory region.  OBFD is passed as the last
   argument to FUNC.  */
   argument to FUNC.  */
 
 
int
int
fbsd_find_memory_regions (int (*func) (CORE_ADDR, unsigned long,
fbsd_find_memory_regions (int (*func) (CORE_ADDR, unsigned long,
                                       int, int, int, void *),
                                       int, int, int, void *),
                          void *obfd)
                          void *obfd)
{
{
  pid_t pid = ptid_get_pid (inferior_ptid);
  pid_t pid = ptid_get_pid (inferior_ptid);
  char *mapfilename;
  char *mapfilename;
  FILE *mapfile;
  FILE *mapfile;
  unsigned long start, end, size;
  unsigned long start, end, size;
  char protection[4];
  char protection[4];
  int read, write, exec;
  int read, write, exec;
  struct cleanup *cleanup;
  struct cleanup *cleanup;
 
 
  mapfilename = xstrprintf ("/proc/%ld/map", (long) pid);
  mapfilename = xstrprintf ("/proc/%ld/map", (long) pid);
  cleanup = make_cleanup (xfree, mapfilename);
  cleanup = make_cleanup (xfree, mapfilename);
  mapfile = fopen (mapfilename, "r");
  mapfile = fopen (mapfilename, "r");
  if (mapfile == NULL)
  if (mapfile == NULL)
    error (_("Couldn't open %s."), mapfilename);
    error (_("Couldn't open %s."), mapfilename);
  make_cleanup_fclose (mapfile);
  make_cleanup_fclose (mapfile);
 
 
  if (info_verbose)
  if (info_verbose)
    fprintf_filtered (gdb_stdout,
    fprintf_filtered (gdb_stdout,
                      "Reading memory regions from %s\n", mapfilename);
                      "Reading memory regions from %s\n", mapfilename);
 
 
  /* Now iterate until end-of-file.  */
  /* Now iterate until end-of-file.  */
  while (fbsd_read_mapping (mapfile, &start, &end, &protection[0]))
  while (fbsd_read_mapping (mapfile, &start, &end, &protection[0]))
    {
    {
      size = end - start;
      size = end - start;
 
 
      read = (strchr (protection, 'r') != 0);
      read = (strchr (protection, 'r') != 0);
      write = (strchr (protection, 'w') != 0);
      write = (strchr (protection, 'w') != 0);
      exec = (strchr (protection, 'x') != 0);
      exec = (strchr (protection, 'x') != 0);
 
 
      if (info_verbose)
      if (info_verbose)
        {
        {
          fprintf_filtered (gdb_stdout,
          fprintf_filtered (gdb_stdout,
                            "Save segment, %ld bytes at %s (%c%c%c)\n",
                            "Save segment, %ld bytes at %s (%c%c%c)\n",
                            size, paddress (target_gdbarch, start),
                            size, paddress (target_gdbarch, start),
                            read ? 'r' : '-',
                            read ? 'r' : '-',
                            write ? 'w' : '-',
                            write ? 'w' : '-',
                            exec ? 'x' : '-');
                            exec ? 'x' : '-');
        }
        }
 
 
      /* Invoke the callback function to create the corefile segment. */
      /* Invoke the callback function to create the corefile segment. */
      func (start, size, read, write, exec, obfd);
      func (start, size, read, write, exec, obfd);
    }
    }
 
 
  do_cleanups (cleanup);
  do_cleanups (cleanup);
  return 0;
  return 0;
}
}
 
 
static int
static int
find_signalled_thread (struct thread_info *info, void *data)
find_signalled_thread (struct thread_info *info, void *data)
{
{
  if (info->stop_signal != TARGET_SIGNAL_0
  if (info->stop_signal != TARGET_SIGNAL_0
      && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid))
      && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid))
    return 1;
    return 1;
 
 
  return 0;
  return 0;
}
}
 
 
static enum target_signal
static enum target_signal
find_stop_signal (void)
find_stop_signal (void)
{
{
  struct thread_info *info =
  struct thread_info *info =
    iterate_over_threads (find_signalled_thread, NULL);
    iterate_over_threads (find_signalled_thread, NULL);
 
 
  if (info)
  if (info)
    return info->stop_signal;
    return info->stop_signal;
  else
  else
    return TARGET_SIGNAL_0;
    return TARGET_SIGNAL_0;
}
}
 
 
/* Create appropriate note sections for a corefile, returning them in
/* Create appropriate note sections for a corefile, returning them in
   allocated memory.  */
   allocated memory.  */
 
 
char *
char *
fbsd_make_corefile_notes (bfd *obfd, int *note_size)
fbsd_make_corefile_notes (bfd *obfd, int *note_size)
{
{
  const struct regcache *regcache = get_current_regcache ();
  const struct regcache *regcache = get_current_regcache ();
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
  gregset_t gregs;
  gregset_t gregs;
  fpregset_t fpregs;
  fpregset_t fpregs;
  char *note_data = NULL;
  char *note_data = NULL;
  Elf_Internal_Ehdr *i_ehdrp;
  Elf_Internal_Ehdr *i_ehdrp;
  const struct regset *regset;
  const struct regset *regset;
  size_t size;
  size_t size;
 
 
  /* Put a "FreeBSD" label in the ELF header.  */
  /* Put a "FreeBSD" label in the ELF header.  */
  i_ehdrp = elf_elfheader (obfd);
  i_ehdrp = elf_elfheader (obfd);
  i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
  i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
 
 
  gdb_assert (gdbarch_regset_from_core_section_p (gdbarch));
  gdb_assert (gdbarch_regset_from_core_section_p (gdbarch));
 
 
  size = sizeof gregs;
  size = sizeof gregs;
  regset = gdbarch_regset_from_core_section (gdbarch, ".reg", size);
  regset = gdbarch_regset_from_core_section (gdbarch, ".reg", size);
  gdb_assert (regset && regset->collect_regset);
  gdb_assert (regset && regset->collect_regset);
  regset->collect_regset (regset, regcache, -1, &gregs, size);
  regset->collect_regset (regset, regcache, -1, &gregs, size);
 
 
  note_data = elfcore_write_prstatus (obfd, note_data, note_size,
  note_data = elfcore_write_prstatus (obfd, note_data, note_size,
                                      ptid_get_pid (inferior_ptid),
                                      ptid_get_pid (inferior_ptid),
                                      find_stop_signal (), &gregs);
                                      find_stop_signal (), &gregs);
 
 
  size = sizeof fpregs;
  size = sizeof fpregs;
  regset = gdbarch_regset_from_core_section (gdbarch, ".reg2", size);
  regset = gdbarch_regset_from_core_section (gdbarch, ".reg2", size);
  gdb_assert (regset && regset->collect_regset);
  gdb_assert (regset && regset->collect_regset);
  regset->collect_regset (regset, regcache, -1, &fpregs, size);
  regset->collect_regset (regset, regcache, -1, &fpregs, size);
 
 
  note_data = elfcore_write_prfpreg (obfd, note_data, note_size,
  note_data = elfcore_write_prfpreg (obfd, note_data, note_size,
                                     &fpregs, sizeof (fpregs));
                                     &fpregs, sizeof (fpregs));
 
 
  if (get_exec_file (0))
  if (get_exec_file (0))
    {
    {
      char *fname = strrchr (get_exec_file (0), '/') + 1;
      char *fname = strrchr (get_exec_file (0), '/') + 1;
      char *psargs = xstrdup (fname);
      char *psargs = xstrdup (fname);
 
 
      if (get_inferior_args ())
      if (get_inferior_args ())
        psargs = reconcat (psargs, psargs, " ", get_inferior_args (), NULL);
        psargs = reconcat (psargs, psargs, " ", get_inferior_args (), NULL);
 
 
      note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
      note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
                                          fname, psargs);
                                          fname, psargs);
    }
    }
 
 
  make_cleanup (xfree, note_data);
  make_cleanup (xfree, note_data);
  return note_data;
  return note_data;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.