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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [kod.c] - Diff between revs 105 and 1765

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

Rev 105 Rev 1765
/* Kernel Object Display generic routines and callbacks
/* Kernel Object Display generic routines and callbacks
   Copyright 1998, 1999 Free Software Foundation, Inc.
   Copyright 1998, 1999 Free Software Foundation, Inc.
 
 
   Written by Fernando Nasser <fnasser@cygnus.com> for Cygnus Solutions.
   Written by Fernando Nasser <fnasser@cygnus.com> for Cygnus Solutions.
 
 
   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 2 of the License, or
   the Free Software Foundation; either version 2 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, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */
   Boston, MA 02111-1307, USA.  */
 
 
#include "defs.h"
#include "defs.h"
#include "command.h"
#include "command.h"
#include "gdbcmd.h"
#include "gdbcmd.h"
#include "target.h"
#include "target.h"
#include "gdb_string.h"
#include "gdb_string.h"
#include "kod.h"
#include "kod.h"
 
 
/* Prototypes for exported functions.  */
/* Prototypes for exported functions.  */
void _initialize_kod (void);
void _initialize_kod (void);
 
 
/* Prototypes for local functions.  */
/* Prototypes for local functions.  */
static void info_kod_command (char *, int);
static void info_kod_command (char *, int);
static void load_kod_library (char *);
static void load_kod_library (char *);
 
 
/* Prototypes for callbacks.  These are passed into the KOD modules.  */
/* Prototypes for callbacks.  These are passed into the KOD modules.  */
static void gdb_kod_display (char *);
static void gdb_kod_display (char *);
static void gdb_kod_query (char *, char *, int *);
static void gdb_kod_query (char *, char *, int *);
 
 
/* These functions are imported from the KOD module.
/* These functions are imported from the KOD module.
 
 
   gdb_kod_open - initiates the KOD connection to the remote.  The
   gdb_kod_open - initiates the KOD connection to the remote.  The
   first argument is the display function the module should use to
   first argument is the display function the module should use to
   communicate with the user.  The second argument is the query
   communicate with the user.  The second argument is the query
   function the display should use to communicate with the target.
   function the display should use to communicate with the target.
   This should call error() if there is an error.  Otherwise it should
   This should call error() if there is an error.  Otherwise it should
   return a malloc()d string of the form:
   return a malloc()d string of the form:
 
 
   NAME VERSION - DESCRIPTION
   NAME VERSION - DESCRIPTION
 
 
   Neither NAME nor VERSION should contain a hyphen.
   Neither NAME nor VERSION should contain a hyphen.
 
 
 
 
   gdb_kod_request - This is used when the user enters an "info
   gdb_kod_request - This is used when the user enters an "info
   <module>" request.  The remaining arguments are passed as the first
   <module>" request.  The remaining arguments are passed as the first
   argument.  The second argument is the standard `from_tty'
   argument.  The second argument is the standard `from_tty'
   argument.
   argument.
 
 
 
 
   gdb_kod_close - This is called when the KOD connection to the
   gdb_kod_close - This is called when the KOD connection to the
   remote should be terminated.  */
   remote should be terminated.  */
 
 
static char *(*gdb_kod_open) (kod_display_callback_ftype *display,
static char *(*gdb_kod_open) (kod_display_callback_ftype *display,
                              kod_query_callback_ftype *query);
                              kod_query_callback_ftype *query);
static void (*gdb_kod_request) (char *, int);
static void (*gdb_kod_request) (char *, int);
static void (*gdb_kod_close) ();
static void (*gdb_kod_close) ();
 
 
 
 
/* Name of inferior's operating system.  */
/* Name of inferior's operating system.  */
char *operating_system;
char *operating_system;
 
 
/* We save a copy of the OS so that we can properly reset when
/* We save a copy of the OS so that we can properly reset when
   switching OS's.  */
   switching OS's.  */
static char *old_operating_system;
static char *old_operating_system;
 
 
/* Print a line of data generated by the module.  */
/* Print a line of data generated by the module.  */
 
 
static void
static void
gdb_kod_display (char *arg)
gdb_kod_display (char *arg)
{
{
  printf_filtered ("%s", arg);
  printf_filtered ("%s", arg);
}
}
 
 
/* Queries the target on behalf of the module.  */
/* Queries the target on behalf of the module.  */
 
 
static void
static void
gdb_kod_query (char *arg, char *result, int *maxsiz)
gdb_kod_query (char *arg, char *result, int *maxsiz)
{
{
  int bufsiz = 0;
  int bufsiz = 0;
 
 
  /* Check if current target has remote_query capabilities.
  /* Check if current target has remote_query capabilities.
     If not, it does not have kod either.  */
     If not, it does not have kod either.  */
  if (! current_target.to_query)
  if (! current_target.to_query)
    {
    {
      strcpy (result,
      strcpy (result,
              "ERR: Kernel Object Display not supported by current target\n");
              "ERR: Kernel Object Display not supported by current target\n");
      return;
      return;
    }
    }
 
 
  /* Just get the maximum buffer size.  */
  /* Just get the maximum buffer size.  */
  target_query ((int) 'K', 0, 0, &bufsiz);
  target_query ((int) 'K', 0, 0, &bufsiz);
 
 
  /* Check if *we* were called just for getting the buffer size.  */
  /* Check if *we* were called just for getting the buffer size.  */
  if (*maxsiz == 0)
  if (*maxsiz == 0)
    {
    {
      *maxsiz = bufsiz;
      *maxsiz = bufsiz;
      strcpy (result, "OK");
      strcpy (result, "OK");
      return;
      return;
    }
    }
 
 
  /* Check if caller can handle a buffer this large, if not, adjust.  */
  /* Check if caller can handle a buffer this large, if not, adjust.  */
  if (bufsiz > *maxsiz)
  if (bufsiz > *maxsiz)
    bufsiz = *maxsiz;
    bufsiz = *maxsiz;
 
 
  /* See if buffer can hold the query (usually it can, as the query is
  /* See if buffer can hold the query (usually it can, as the query is
     short).  */
     short).  */
  if (strlen (arg) >= bufsiz)
  if (strlen (arg) >= bufsiz)
    error ("kod: query argument too long");
    error ("kod: query argument too long");
 
 
  /* Send actual request.  */
  /* Send actual request.  */
  if (target_query ((int) 'K', arg, result, &bufsiz))
  if (target_query ((int) 'K', arg, result, &bufsiz))
    strcpy (result, "ERR: remote query failed");
    strcpy (result, "ERR: remote query failed");
}
}
 
 
/* Print name of kod command after selecting the appropriate kod
/* Print name of kod command after selecting the appropriate kod
   formatting library module.  As a side effect we create a new "info"
   formatting library module.  As a side effect we create a new "info"
   subcommand which is what the user actually uses to query the OS.  */
   subcommand which is what the user actually uses to query the OS.  */
 
 
static void
static void
kod_set_os (char *arg, int from_tty, struct cmd_list_element *command)
kod_set_os (char *arg, int from_tty, struct cmd_list_element *command)
{
{
  char *p;
  char *p;
 
 
  if (command->type != set_cmd)
  if (command->type != set_cmd)
    return;
    return;
 
 
  /* If we had already had an open OS, close it.  */
  /* If we had already had an open OS, close it.  */
  if (gdb_kod_close)
  if (gdb_kod_close)
    (*gdb_kod_close) ();
    (*gdb_kod_close) ();
 
 
  /* Also remove the old OS's command.  */
  /* Also remove the old OS's command.  */
  if (old_operating_system)
  if (old_operating_system)
    {
    {
      delete_cmd (old_operating_system, &infolist);
      delete_cmd (old_operating_system, &infolist);
      free (old_operating_system);
      free (old_operating_system);
    }
    }
  old_operating_system = xstrdup (operating_system);
  old_operating_system = xstrdup (operating_system);
 
 
  if (! operating_system || ! *operating_system)
  if (! operating_system || ! *operating_system)
    {
    {
      /* If user set operating system to empty, we want to forget we
      /* If user set operating system to empty, we want to forget we
         had a module open.  Setting these variables is just nice for
         had a module open.  Setting these variables is just nice for
         debugging and clarity.  */
         debugging and clarity.  */
      gdb_kod_open = NULL;
      gdb_kod_open = NULL;
      gdb_kod_request = NULL;
      gdb_kod_request = NULL;
      gdb_kod_close = NULL;
      gdb_kod_close = NULL;
    }
    }
  else
  else
    {
    {
      char *kodlib;
      char *kodlib;
 
 
      load_kod_library (operating_system);
      load_kod_library (operating_system);
 
 
      kodlib = (*gdb_kod_open) (gdb_kod_display, gdb_kod_query);
      kodlib = (*gdb_kod_open) (gdb_kod_display, gdb_kod_query);
 
 
      /* Add kod related info commands to gdb.  */
      /* Add kod related info commands to gdb.  */
      add_info (operating_system, info_kod_command,
      add_info (operating_system, info_kod_command,
                "Displays information about Kernel Objects.");
                "Displays information about Kernel Objects.");
 
 
      p = strrchr (kodlib, '-');
      p = strrchr (kodlib, '-');
      if (p != NULL)
      if (p != NULL)
        p++;
        p++;
      else
      else
        p = "Unknown KOD library";
        p = "Unknown KOD library";
      printf_filtered ("%s - %s\n", operating_system, p);
      printf_filtered ("%s - %s\n", operating_system, p);
 
 
      free (kodlib);
      free (kodlib);
    }
    }
}
}
 
 
/* Print information about currently known kernel objects of the
/* Print information about currently known kernel objects of the
   specified type or a list of all known kernel object types if
   specified type or a list of all known kernel object types if
   argument is empty.  */
   argument is empty.  */
 
 
static void
static void
info_kod_command (char *arg, int from_tty)
info_kod_command (char *arg, int from_tty)
{
{
  (*gdb_kod_request) (arg, from_tty);
  (*gdb_kod_request) (arg, from_tty);
}
}
 
 
/* Print name of kod command after selecting the appropriate kod
/* Print name of kod command after selecting the appropriate kod
   formatting library module.  */
   formatting library module.  */
 
 
static void
static void
load_kod_library (char *lib)
load_kod_library (char *lib)
{
{
#if 0
#if 0
  /* FIXME: Don't have the eCos code here.  */
  /* FIXME: Don't have the eCos code here.  */
  if (! strcmp (lib, "ecos"))
  if (! strcmp (lib, "ecos"))
    {
    {
      gdb_kod_open = ecos_kod_open;
      gdb_kod_open = ecos_kod_open;
      gdb_kod_request = ecos_kod_request;
      gdb_kod_request = ecos_kod_request;
      gdb_kod_close = ecos_kod_close;
      gdb_kod_close = ecos_kod_close;
    }
    }
  else
  else
#endif /* 0 */
#endif /* 0 */
   if (! strcmp (lib, "cisco"))
   if (! strcmp (lib, "cisco"))
    {
    {
      gdb_kod_open = cisco_kod_open;
      gdb_kod_open = cisco_kod_open;
      gdb_kod_request = cisco_kod_request;
      gdb_kod_request = cisco_kod_request;
      gdb_kod_close = cisco_kod_close;
      gdb_kod_close = cisco_kod_close;
    }
    }
  else
  else
    error ("Unknown operating system: %s\n", operating_system);
    error ("Unknown operating system: %s\n", operating_system);
}
}
 
 
void
void
_initialize_kod ()
_initialize_kod ()
{
{
  struct cmd_list_element *c;
  struct cmd_list_element *c;
 
 
  c = add_set_cmd ("os", no_class, var_string,
  c = add_set_cmd ("os", no_class, var_string,
                   (char *) &operating_system,
                   (char *) &operating_system,
                   "Set operating system",
                   "Set operating system",
                   &setlist);
                   &setlist);
  c->function.sfunc = kod_set_os;
  c->function.sfunc = kod_set_os;
  add_show_from_set (c, &showlist);
  add_show_from_set (c, &showlist);
}
}
 
 

powered by: WebSVN 2.1.0

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