bfd/
[binutils-gdb.git] / gdb / kod.c
index a0969109cf8174929bb9f7f9a1a2c0c23d087061..15db43055ce439e2a53188f704e2bf2d6d9542be 100644 (file)
--- a/gdb/kod.c
+++ b/gdb/kod.c
@@ -1,5 +1,5 @@
 /* Kernel Object Display generic routines and callbacks
-   Copyright 1998, 1999 Free Software Foundation, Inc.
+   Copyright 1998, 1999, 2000 Free Software Foundation, Inc.
 
    Written by Fernando Nasser <fnasser@cygnus.com> for Cygnus Solutions.
 
 #include "gdbcmd.h"
 #include "target.h"
 #include "gdb_string.h"
+#include "kod.h"
 
 /* Prototypes for exported functions.  */
 void _initialize_kod (void);
 
 /* Prototypes for local functions.  */
-static void show_kod (char *, int);
 static void info_kod_command (char *, int);
 static void load_kod_library (char *);
 
@@ -61,7 +61,8 @@ static void gdb_kod_query (char *, char *, int *);
    gdb_kod_close - This is called when the KOD connection to the
    remote should be terminated.  */
 
-static char *(*gdb_kod_open) (void *, void *);
+static char *(*gdb_kod_open) (kod_display_callback_ftype *display,
+                             kod_query_callback_ftype *query);
 static void (*gdb_kod_request) (char *, int);
 static void (*gdb_kod_close) ();
 
@@ -73,17 +74,6 @@ char *operating_system;
    switching OS's.  */
 static char *old_operating_system;
 
-/* Functions imported from the library for all supported OSes.
-   FIXME: we really should do something better, such as dynamically
-   loading the KOD modules.  */
-extern char *ecos_kod_open (void *, void *);
-extern void ecos_kod_request (char *, int);
-extern void ecos_kod_close ();
-extern char *cisco_kod_open (void *, void *);
-extern void cisco_kod_request (char *, int);
-extern void cisco_kod_close ();
-
-
 /* Print a line of data generated by the module.  */
 
 static void
@@ -97,11 +87,13 @@ gdb_kod_display (char *arg)
 static void
 gdb_kod_query (char *arg, char *result, int *maxsiz)
 {
-  int bufsiz = 0;
+  LONGEST bufsiz = 0;
 
-  /* Check if current target has remote_query capabilities.
-     If not, it does not have kod either.  */
-  if (! current_target.to_query)
+  /* Check if current target has remote_query capabilities.  If not,
+     it does not have kod either.  */
+  bufsiz = target_read_partial (&current_target, TARGET_OBJECT_KOD,
+                               NULL, NULL, 0, 0);
+  if (bufsiz < 0)
     {
       strcpy (result,
               "ERR: Kernel Object Display not supported by current target\n");
@@ -109,7 +101,6 @@ gdb_kod_query (char *arg, char *result, int *maxsiz)
     }
 
   /* Just get the maximum buffer size.  */
-  target_query ((int) 'K', 0, 0, &bufsiz);
 
   /* Check if *we* were called just for getting the buffer size.  */
   if (*maxsiz == 0)
@@ -129,7 +120,8 @@ gdb_kod_query (char *arg, char *result, int *maxsiz)
     error ("kod: query argument too long");
 
   /* Send actual request.  */
-  if (target_query ((int) 'K', arg, result, &bufsiz))
+  if (target_read_partial (&current_target, TARGET_OBJECT_KOD,
+                          arg, result, 0, bufsiz) < 0)
     strcpy (result, "ERR: remote query failed");
 }
 
@@ -142,7 +134,17 @@ kod_set_os (char *arg, int from_tty, struct cmd_list_element *command)
 {
   char *p;
 
-  if (command->type != set_cmd)
+  /* NOTE: cagney/2002-03-17: The deprecated_add_show_from_set()
+     function clones the set command passed as a parameter.  The clone
+     operation will include (BUG?) any ``set'' command callback, if
+     present.  Commands like ``info set'' call all the ``show''
+     command callbacks.  Unfortunately, for ``show'' commands cloned
+     from ``set'', this includes callbacks belonging to ``set''
+     commands.  Making this worse, this only occures if
+     deprecated_add_show_from_set() is called after add_cmd_sfunc()
+     (BUG?).  */
+
+  if (cmd_type (command) != set_cmd)
     return;
 
   /* If we had already had an open OS, close it.  */
@@ -153,9 +155,8 @@ kod_set_os (char *arg, int from_tty, struct cmd_list_element *command)
   if (old_operating_system)
     {
       delete_cmd (old_operating_system, &infolist);
-      free (old_operating_system);
+      xfree (old_operating_system);
     }
-  old_operating_system = strdup (operating_system);
 
   if (! operating_system || ! *operating_system)
     {
@@ -170,6 +171,8 @@ kod_set_os (char *arg, int from_tty, struct cmd_list_element *command)
     {
       char *kodlib;
 
+      old_operating_system = xstrdup (operating_system);
+
       load_kod_library (operating_system);
 
       kodlib = (*gdb_kod_open) (gdb_kod_display, gdb_kod_query);
@@ -185,7 +188,7 @@ kod_set_os (char *arg, int from_tty, struct cmd_list_element *command)
        p = "Unknown KOD library";
       printf_filtered ("%s - %s\n", operating_system, p);
 
-      free (kodlib);
+      xfree (kodlib);
     }
 }
 
@@ -226,7 +229,7 @@ load_kod_library (char *lib)
 }
 
 void
-_initialize_kod ()
+_initialize_kod (void)
 {
   struct cmd_list_element *c;
 
@@ -234,6 +237,6 @@ _initialize_kod ()
                   (char *) &operating_system,
                   "Set operating system",
                   &setlist);
-  c->function.sfunc = kod_set_os;
-  add_show_from_set (c, &showlist);
+  set_cmd_sfunc (c, kod_set_os);
+  deprecated_add_show_from_set (c, &showlist);
 }