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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [tui/] [tui.c] - Diff between revs 106 and 107

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

Rev 106 Rev 107
/*
/*
   ** tui.c
   ** tui.c
   **         General functions for the WDB TUI
   **         General functions for the WDB TUI
 */
 */
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <ctype.h>
#include <ctype.h>
#include <malloc.h>
#include <malloc.h>
#include <curses.h>
#include <curses.h>
#ifdef HAVE_TERM_H
#ifdef HAVE_TERM_H
#include <term.h>
#include <term.h>
#endif
#endif
#include <signal.h>
#include <signal.h>
#include <fcntl.h>
#include <fcntl.h>
#include <termio.h>
#include <termio.h>
#include <setjmp.h>
#include <setjmp.h>
#include "defs.h"
#include "defs.h"
#include "gdbcmd.h"
#include "gdbcmd.h"
#include "tui.h"
#include "tui.h"
#include "tuiData.h"
#include "tuiData.h"
#include "tuiLayout.h"
#include "tuiLayout.h"
#include "tuiIO.h"
#include "tuiIO.h"
#include "tuiRegs.h"
#include "tuiRegs.h"
#include "tuiWin.h"
#include "tuiWin.h"
 
 
/* The Solaris header files seem to provide no declaration for this at
/* The Solaris header files seem to provide no declaration for this at
   all when __STDC__ is defined.  This shouldn't conflict with
   all when __STDC__ is defined.  This shouldn't conflict with
   anything.  */
   anything.  */
extern char *tgoto ();
extern char *tgoto ();
 
 
/***********************
/***********************
** Local Definitions
** Local Definitions
************************/
************************/
#define FILEDES         2
#define FILEDES         2
/* Solaris <sys/termios.h> defines CTRL. */
/* Solaris <sys/termios.h> defines CTRL. */
#ifndef CTRL
#ifndef CTRL
#define CTRL(x)         (x & ~0140)
#define CTRL(x)         (x & ~0140)
#endif
#endif
#define CHK(val, dft)   (val<=0 ? dft : val)
#define CHK(val, dft)   (val<=0 ? dft : val)
 
 
#define TOGGLE_USAGE "Usage:toggle breakpoints"
#define TOGGLE_USAGE "Usage:toggle breakpoints"
#define TUI_TOGGLE_USAGE "Usage:\ttoggle $fregs\n\ttoggle breakpoints"
#define TUI_TOGGLE_USAGE "Usage:\ttoggle $fregs\n\ttoggle breakpoints"
 
 
/*****************************
/*****************************
** Local static forward decls
** Local static forward decls
******************************/
******************************/
static void _tuiReset PARAMS ((void));
static void _tuiReset PARAMS ((void));
static void _toggle_command PARAMS ((char *, int));
static void _toggle_command PARAMS ((char *, int));
static void _tui_vToggle_command PARAMS ((va_list));
static void _tui_vToggle_command PARAMS ((va_list));
static Opaque _tui_vDo PARAMS ((TuiOpaqueFuncPtr, va_list));
static Opaque _tui_vDo PARAMS ((TuiOpaqueFuncPtr, va_list));
 
 
 
 
 
 
/***********************
/***********************
** Public Functions
** Public Functions
************************/
************************/
 
 
/*
/*
   ** tuiInit().
   ** tuiInit().
 */
 */
void
void
#ifdef __STDC__
#ifdef __STDC__
tuiInit (char *argv0)
tuiInit (char *argv0)
#else
#else
tuiInit (argv0)
tuiInit (argv0)
     char *argv0;
     char *argv0;
#endif
#endif
{
{
  extern void init_page_info ();
  extern void init_page_info ();
  extern void initialize_tui_files PARAMS ((void));
  extern void initialize_tui_files PARAMS ((void));
 
 
  initialize_tui_files ();
  initialize_tui_files ();
  initializeStaticData ();
  initializeStaticData ();
  initscr ();
  initscr ();
  refresh ();
  refresh ();
  setTermHeightTo (LINES);
  setTermHeightTo (LINES);
  setTermWidthTo (COLS);
  setTermWidthTo (COLS);
  tuiInitWindows ();
  tuiInitWindows ();
  wrefresh (cmdWin->generic.handle);
  wrefresh (cmdWin->generic.handle);
  init_page_info ();
  init_page_info ();
  /* Don't hook debugger output if doing command-window
  /* Don't hook debugger output if doing command-window
     * the XDB way. However, one thing we do want to do in
     * the XDB way. However, one thing we do want to do in
     * XDB style is set up the scrolling region to be
     * XDB style is set up the scrolling region to be
     * the bottom of the screen (tuiTermUnsetup()).
     * the bottom of the screen (tuiTermUnsetup()).
   */
   */
  fputs_unfiltered_hook = NULL;
  fputs_unfiltered_hook = NULL;
  rl_initialize ();             /* need readline initialization to
  rl_initialize ();             /* need readline initialization to
                                   * create termcap sequences
                                   * create termcap sequences
                                 */
                                 */
  tuiTermUnsetup (1, cmdWin->detail.commandInfo.curch);
  tuiTermUnsetup (1, cmdWin->detail.commandInfo.curch);
 
 
  return;
  return;
}                               /* tuiInit */
}                               /* tuiInit */
 
 
 
 
/*
/*
   ** tuiInitWindows().
   ** tuiInitWindows().
 */
 */
void
void
#ifdef __STDC__
#ifdef __STDC__
tuiInitWindows (void)
tuiInitWindows (void)
#else
#else
tuiInitWindows ()
tuiInitWindows ()
#endif
#endif
{
{
  TuiWinType type;
  TuiWinType type;
 
 
  tuiSetLocatorContent (0);
  tuiSetLocatorContent (0);
  showLayout (SRC_COMMAND);
  showLayout (SRC_COMMAND);
  keypad (cmdWin->generic.handle, TRUE);
  keypad (cmdWin->generic.handle, TRUE);
  echo ();
  echo ();
  crmode ();
  crmode ();
  nl ();
  nl ();
  tuiSetWinFocusTo (srcWin);
  tuiSetWinFocusTo (srcWin);
 
 
  return;
  return;
}                               /* tuiInitWindows */
}                               /* tuiInitWindows */
 
 
 
 
/*
/*
   ** tuiCleanUp().
   ** tuiCleanUp().
   **        Kill signal handler and cleanup termination method
   **        Kill signal handler and cleanup termination method
 */
 */
void
void
#ifdef __STDC__
#ifdef __STDC__
tuiResetScreen (void)
tuiResetScreen (void)
#else
#else
tuiResetScreen ()
tuiResetScreen ()
#endif
#endif
{
{
  TuiWinType type = SRC_WIN;
  TuiWinType type = SRC_WIN;
 
 
  keypad (cmdWin->generic.handle, FALSE);
  keypad (cmdWin->generic.handle, FALSE);
  for (; type < MAX_MAJOR_WINDOWS; type++)
  for (; type < MAX_MAJOR_WINDOWS; type++)
    {
    {
      if (m_winPtrNotNull (winList[type]) &&
      if (m_winPtrNotNull (winList[type]) &&
          winList[type]->generic.type != UNDEFINED_WIN &&
          winList[type]->generic.type != UNDEFINED_WIN &&
          !winList[type]->generic.isVisible)
          !winList[type]->generic.isVisible)
        tuiDelWindow (winList[type]);
        tuiDelWindow (winList[type]);
    }
    }
  endwin ();
  endwin ();
  initscr ();
  initscr ();
  refresh ();
  refresh ();
  echo ();
  echo ();
  crmode ();
  crmode ();
  nl ();
  nl ();
 
 
  return;
  return;
}                               /* tuiResetScreen */
}                               /* tuiResetScreen */
 
 
 
 
/*
/*
   ** tuiCleanUp().
   ** tuiCleanUp().
   **        Kill signal handler and cleanup termination method
   **        Kill signal handler and cleanup termination method
 */
 */
void
void
#ifdef __STDC__
#ifdef __STDC__
tuiCleanUp (void)
tuiCleanUp (void)
#else
#else
tuiCleanUp ()
tuiCleanUp ()
#endif
#endif
{
{
  char *buffer;
  char *buffer;
  extern char *term_cursor_move;
  extern char *term_cursor_move;
 
 
  signal (SIGINT, SIG_IGN);
  signal (SIGINT, SIG_IGN);
  tuiTermSetup (0);              /* Restore scrolling region to whole screen */
  tuiTermSetup (0);              /* Restore scrolling region to whole screen */
  keypad (cmdWin->generic.handle, FALSE);
  keypad (cmdWin->generic.handle, FALSE);
  freeAllWindows ();
  freeAllWindows ();
  endwin ();
  endwin ();
  buffer = tgoto (term_cursor_move, 0, termHeight ());
  buffer = tgoto (term_cursor_move, 0, termHeight ());
  tputs (buffer, 1, putchar);
  tputs (buffer, 1, putchar);
  _tuiReset ();
  _tuiReset ();
 
 
  return;
  return;
}                               /* tuiCleanUp */
}                               /* tuiCleanUp */
 
 
 
 
/*
/*
   ** tuiError().
   ** tuiError().
 */
 */
void
void
#ifdef __STDC__
#ifdef __STDC__
tuiError (
tuiError (
           char *string,
           char *string,
           int exitGdb)
           int exitGdb)
#else
#else
tuiError (string, exitGdb)
tuiError (string, exitGdb)
     char *string;
     char *string;
     int exitGdb;
     int exitGdb;
#endif
#endif
{
{
  puts_unfiltered (string);
  puts_unfiltered (string);
  if (exitGdb)
  if (exitGdb)
    {
    {
      tuiCleanUp ();
      tuiCleanUp ();
      exit (-1);
      exit (-1);
    }
    }
 
 
  return;
  return;
}                               /* tuiError */
}                               /* tuiError */
 
 
 
 
/*
/*
   ** tui_vError()
   ** tui_vError()
   **        tuiError with args in a va_list.
   **        tuiError with args in a va_list.
 */
 */
void
void
#ifdef __STDC__
#ifdef __STDC__
tui_vError (
tui_vError (
             va_list args)
             va_list args)
#else
#else
tui_vError (args)
tui_vError (args)
     va_list args;
     va_list args;
#endif
#endif
{
{
  char *string;
  char *string;
  int exitGdb;
  int exitGdb;
 
 
  string = va_arg (args, char *);
  string = va_arg (args, char *);
  exitGdb = va_arg (args, int);
  exitGdb = va_arg (args, int);
 
 
  tuiError (string, exitGdb);
  tuiError (string, exitGdb);
 
 
  return;
  return;
}                               /* tui_vError */
}                               /* tui_vError */
 
 
 
 
/*
/*
   ** tuiFree()
   ** tuiFree()
   **    Wrapper on top of free() to ensure that input address is greater than 0x0
   **    Wrapper on top of free() to ensure that input address is greater than 0x0
 */
 */
void
void
#ifdef __STDC__
#ifdef __STDC__
tuiFree (
tuiFree (
          char *ptr)
          char *ptr)
#else
#else
tuiFree (ptr)
tuiFree (ptr)
     char *ptr;
     char *ptr;
#endif
#endif
{
{
  if (ptr != (char *) NULL)
  if (ptr != (char *) NULL)
    {
    {
      free (ptr);
      free (ptr);
    }
    }
 
 
  return;
  return;
}                               /* tuiFree */
}                               /* tuiFree */
 
 
 
 
/* tuiGetLowDisassemblyAddress().
/* tuiGetLowDisassemblyAddress().
   **        Determine what the low address will be to display in the TUI's
   **        Determine what the low address will be to display in the TUI's
   **        disassembly window.  This may or may not be the same as the
   **        disassembly window.  This may or may not be the same as the
   **        low address input.
   **        low address input.
 */
 */
Opaque
Opaque
#ifdef __STDC__
#ifdef __STDC__
tuiGetLowDisassemblyAddress (
tuiGetLowDisassemblyAddress (
                              Opaque low,
                              Opaque low,
                              Opaque pc)
                              Opaque pc)
#else
#else
tuiGetLowDisassemblyAddress (low, pc)
tuiGetLowDisassemblyAddress (low, pc)
     Opaque low;
     Opaque low;
     Opaque pc;
     Opaque pc;
#endif
#endif
{
{
  int line;
  int line;
  Opaque newLow;
  Opaque newLow;
 
 
  /*
  /*
     ** Determine where to start the disassembly so that the pc is about in the
     ** Determine where to start the disassembly so that the pc is about in the
     ** middle of the viewport.
     ** middle of the viewport.
   */
   */
  for (line = 0, newLow = pc;
  for (line = 0, newLow = pc;
       (newLow > low &&
       (newLow > low &&
        line < (tuiDefaultWinViewportHeight (DISASSEM_WIN,
        line < (tuiDefaultWinViewportHeight (DISASSEM_WIN,
                                             DISASSEM_COMMAND) / 2));)
                                             DISASSEM_COMMAND) / 2));)
    {
    {
      bfd_byte buffer[4];
      bfd_byte buffer[4];
 
 
      newLow -= sizeof (bfd_getb32 (buffer));
      newLow -= sizeof (bfd_getb32 (buffer));
      line++;
      line++;
    }
    }
 
 
  return newLow;
  return newLow;
}                               /* tuiGetLowDisassemblyAddress */
}                               /* tuiGetLowDisassemblyAddress */
 
 
 
 
/* tui_vGetLowDisassemblyAddress().
/* tui_vGetLowDisassemblyAddress().
   **        Determine what the low address will be to display in the TUI's
   **        Determine what the low address will be to display in the TUI's
   **        disassembly window with args in a va_list.
   **        disassembly window with args in a va_list.
 */
 */
Opaque
Opaque
#ifdef __STDC__
#ifdef __STDC__
tui_vGetLowDisassemblyAddress (
tui_vGetLowDisassemblyAddress (
                                va_list args)
                                va_list args)
#else
#else
tui_vGetLowDisassemblyAddress (args)
tui_vGetLowDisassemblyAddress (args)
     va_list args;
     va_list args;
#endif
#endif
{
{
  int line;
  int line;
  Opaque newLow;
  Opaque newLow;
  Opaque low;
  Opaque low;
  Opaque pc;
  Opaque pc;
 
 
  low = va_arg (args, Opaque);
  low = va_arg (args, Opaque);
  pc = va_arg (args, Opaque);
  pc = va_arg (args, Opaque);
 
 
  return (tuiGetLowDisassemblyAddress (low, pc));
  return (tuiGetLowDisassemblyAddress (low, pc));
 
 
}                               /* tui_vGetLowDisassemblyAddress */
}                               /* tui_vGetLowDisassemblyAddress */
 
 
 
 
/*
/*
   ** tuiDo().
   ** tuiDo().
   **        General purpose function to execute a tui function.  Transitions
   **        General purpose function to execute a tui function.  Transitions
   **        between curses and the are handled here.  This function is called
   **        between curses and the are handled here.  This function is called
   **        by non-tui gdb functions.
   **        by non-tui gdb functions.
   **
   **
   **        Errors are caught here.
   **        Errors are caught here.
   **        If there is no error, the value returned by 'func' is returned.
   **        If there is no error, the value returned by 'func' is returned.
   **        If there is an error, then zero is returned.
   **        If there is an error, then zero is returned.
   **
   **
   **       Must not be called with immediate_quit in effect (bad things might
   **       Must not be called with immediate_quit in effect (bad things might
   **       happen, say we got a signal in the middle of a memcpy to quit_return).
   **       happen, say we got a signal in the middle of a memcpy to quit_return).
   **       This is an OK restriction; with very few exceptions immediate_quit can
   **       This is an OK restriction; with very few exceptions immediate_quit can
   **       be replaced by judicious use of QUIT.
   **       be replaced by judicious use of QUIT.
 */
 */
Opaque
Opaque
#ifdef __STDC__
#ifdef __STDC__
tuiDo (
tuiDo (
        TuiOpaqueFuncPtr func,...)
        TuiOpaqueFuncPtr func,...)
#else
#else
tuiDo (func, va_alist)
tuiDo (func, va_alist)
     TuiOpaqueFuncPtr func;
     TuiOpaqueFuncPtr func;
     va_dcl
     va_dcl
#endif
#endif
{
{
  extern int terminal_is_ours;
  extern int terminal_is_ours;
 
 
  Opaque ret = (Opaque) NULL;
  Opaque ret = (Opaque) NULL;
 
 
  /* It is an error to be tuiDo'ing if we
  /* It is an error to be tuiDo'ing if we
     * don't own the terminal.
     * don't own the terminal.
   */
   */
  if (!terminal_is_ours)
  if (!terminal_is_ours)
    return ret;
    return ret;
 
 
  if (tui_version)
  if (tui_version)
    {
    {
      va_list args;
      va_list args;
 
 
#ifdef __STDC__
#ifdef __STDC__
      va_start (args, func);
      va_start (args, func);
#else
#else
      va_start (args);
      va_start (args);
#endif
#endif
      ret = _tui_vDo (func, args);
      ret = _tui_vDo (func, args);
      va_end (args);
      va_end (args);
    }
    }
 
 
  return ret;
  return ret;
}                               /* tuiDo */
}                               /* tuiDo */
 
 
 
 
/*
/*
   ** tuiDoAndReturnToTop().
   ** tuiDoAndReturnToTop().
   **        General purpose function to execute a tui function.  Transitions
   **        General purpose function to execute a tui function.  Transitions
   **        between curses and the are handled here.  This function is called
   **        between curses and the are handled here.  This function is called
   **        by non-tui gdb functions who wish to reset gdb to the top level.
   **        by non-tui gdb functions who wish to reset gdb to the top level.
   **        After the tuiDo is performed, a return to the top level occurs.
   **        After the tuiDo is performed, a return to the top level occurs.
   **
   **
   **        Errors are caught here.
   **        Errors are caught here.
   **        If there is no error, the value returned by 'func' is returned.
   **        If there is no error, the value returned by 'func' is returned.
   **        If there is an error, then zero is returned.
   **        If there is an error, then zero is returned.
   **
   **
   **       Must not be called with immediate_quit in effect (bad things might
   **       Must not be called with immediate_quit in effect (bad things might
   **       happen, say we got a signal in the middle of a memcpy to quit_return).
   **       happen, say we got a signal in the middle of a memcpy to quit_return).
   **       This is an OK restriction; with very few exceptions immediate_quit can
   **       This is an OK restriction; with very few exceptions immediate_quit can
   **       be replaced by judicious use of QUIT.
   **       be replaced by judicious use of QUIT.
   **
   **
 */
 */
Opaque
Opaque
#ifdef __STDC__
#ifdef __STDC__
tuiDoAndReturnToTop (
tuiDoAndReturnToTop (
                      TuiOpaqueFuncPtr func,...)
                      TuiOpaqueFuncPtr func,...)
#else
#else
tuiDoAndReturnToTop (func, va_alist)
tuiDoAndReturnToTop (func, va_alist)
     TuiOpaqueFuncPtr func;
     TuiOpaqueFuncPtr func;
     va_dcl
     va_dcl
#endif
#endif
{
{
  extern int terminal_is_ours;
  extern int terminal_is_ours;
 
 
  Opaque ret = (Opaque) NULL;
  Opaque ret = (Opaque) NULL;
 
 
  /* It is an error to be tuiDo'ing if we
  /* It is an error to be tuiDo'ing if we
     * don't own the terminal.
     * don't own the terminal.
   */
   */
  if (!terminal_is_ours)
  if (!terminal_is_ours)
    return ret;
    return ret;
 
 
  if (tui_version)
  if (tui_version)
    {
    {
      va_list args;
      va_list args;
 
 
#ifdef __STDC__
#ifdef __STDC__
      va_start (args, func);
      va_start (args, func);
#else
#else
      va_start (args);
      va_start (args);
#endif
#endif
      ret = _tui_vDo (func, args);
      ret = _tui_vDo (func, args);
 
 
      /* force a return to the top level */
      /* force a return to the top level */
      return_to_top_level (RETURN_ERROR);
      return_to_top_level (RETURN_ERROR);
    }
    }
 
 
  return ret;
  return ret;
}                               /* tuiDoAndReturnToTop */
}                               /* tuiDoAndReturnToTop */
 
 
 
 
void
void
#ifdef __STDC__
#ifdef __STDC__
tui_vSelectSourceSymtab (
tui_vSelectSourceSymtab (
                          va_list args)
                          va_list args)
#else
#else
tui_vSelectSourceSymtab (args)
tui_vSelectSourceSymtab (args)
     va_list args;
     va_list args;
#endif
#endif
{
{
  struct symtab *s = va_arg (args, struct symtab *);
  struct symtab *s = va_arg (args, struct symtab *);
 
 
  select_source_symtab (s);
  select_source_symtab (s);
  return;
  return;
}                               /* tui_vSelectSourceSymtab */
}                               /* tui_vSelectSourceSymtab */
 
 
 
 
/*
/*
   ** _initialize_tui().
   ** _initialize_tui().
   **      Function to initialize gdb commands, for tui window manipulation.
   **      Function to initialize gdb commands, for tui window manipulation.
 */
 */
void
void
_initialize_tui ()
_initialize_tui ()
{
{
#if 0
#if 0
  if (tui_version)
  if (tui_version)
    {
    {
      add_com ("toggle", class_tui, _toggle_command,
      add_com ("toggle", class_tui, _toggle_command,
               "Toggle Terminal UI Features\n\
               "Toggle Terminal UI Features\n\
Usage: Toggle $fregs\n\
Usage: Toggle $fregs\n\
\tToggles between single and double precision floating point registers.\n");
\tToggles between single and double precision floating point registers.\n");
    }
    }
#endif
#endif
  char *helpStr;
  char *helpStr;
 
 
  if (tui_version)
  if (tui_version)
    helpStr = "Toggle Specified Features\n\
    helpStr = "Toggle Specified Features\n\
Usage:\ttoggle $fregs\n\ttoggle breakpoints";
Usage:\ttoggle $fregs\n\ttoggle breakpoints";
  else
  else
    helpStr = "Toggle Specified Features\nUsage:toggle breakpoints";
    helpStr = "Toggle Specified Features\nUsage:toggle breakpoints";
  add_abbrev_prefix_cmd ("toggle",
  add_abbrev_prefix_cmd ("toggle",
                         class_tui,
                         class_tui,
                         _toggle_command,
                         _toggle_command,
                         helpStr,
                         helpStr,
                         &togglelist,
                         &togglelist,
                         "toggle ",
                         "toggle ",
                         1,
                         1,
                         &cmdlist);
                         &cmdlist);
}                               /* _initialize_tui */
}                               /* _initialize_tui */
 
 
 
 
/*
/*
   ** va_catch_errors().
   ** va_catch_errors().
   **       General purpose function to execute a function, catching errors.
   **       General purpose function to execute a function, catching errors.
   **       If there is no error, the value returned by 'func' is returned.
   **       If there is no error, the value returned by 'func' is returned.
   **       If there is error, then zero is returned.
   **       If there is error, then zero is returned.
   **       Note that 'func' must take a variable argument list as well.
   **       Note that 'func' must take a variable argument list as well.
   **
   **
   **       Must not be called with immediate_quit in effect (bad things might
   **       Must not be called with immediate_quit in effect (bad things might
   **       happen, say we got a signal in the middle of a memcpy to quit_return).
   **       happen, say we got a signal in the middle of a memcpy to quit_return).
   **       This is an OK restriction; with very few exceptions immediate_quit can
   **       This is an OK restriction; with very few exceptions immediate_quit can
   **       be replaced by judicious use of QUIT.
   **       be replaced by judicious use of QUIT.
 */
 */
Opaque
Opaque
#ifdef __STDC__
#ifdef __STDC__
va_catch_errors (
va_catch_errors (
                  TuiOpaqueFuncPtr func,
                  TuiOpaqueFuncPtr func,
                  va_list args)
                  va_list args)
#else
#else
va_catch_errors (func, args)
va_catch_errors (func, args)
     TuiOpaqueFuncPtr func;
     TuiOpaqueFuncPtr func;
     va_list args;
     va_list args;
#endif
#endif
{
{
  Opaque ret = (Opaque) NULL;
  Opaque ret = (Opaque) NULL;
 
 
  /*
  /*
     ** We could have used catch_errors(), but it doesn't handle variable args.
     ** We could have used catch_errors(), but it doesn't handle variable args.
     ** Also, for the tui, we always want to catch all errors, so we don't
     ** Also, for the tui, we always want to catch all errors, so we don't
     ** need to pass a mask, or an error string.
     ** need to pass a mask, or an error string.
   */
   */
  jmp_buf saved_error;
  jmp_buf saved_error;
  jmp_buf saved_quit;
  jmp_buf saved_quit;
  jmp_buf tmp_jmp;
  jmp_buf tmp_jmp;
  struct cleanup *saved_cleanup_chain;
  struct cleanup *saved_cleanup_chain;
  char *saved_error_pre_print;
  char *saved_error_pre_print;
  char *saved_quit_pre_print;
  char *saved_quit_pre_print;
  extern jmp_buf error_return;
  extern jmp_buf error_return;
  extern jmp_buf quit_return;
  extern jmp_buf quit_return;
 
 
  saved_cleanup_chain = save_cleanups ();
  saved_cleanup_chain = save_cleanups ();
  saved_error_pre_print = error_pre_print;
  saved_error_pre_print = error_pre_print;
  saved_quit_pre_print = quit_pre_print;
  saved_quit_pre_print = quit_pre_print;
 
 
  memcpy ((char *) saved_error, (char *) error_return, sizeof (jmp_buf));
  memcpy ((char *) saved_error, (char *) error_return, sizeof (jmp_buf));
  error_pre_print = "";
  error_pre_print = "";
  memcpy (saved_quit, quit_return, sizeof (jmp_buf));
  memcpy (saved_quit, quit_return, sizeof (jmp_buf));
  quit_pre_print = "";
  quit_pre_print = "";
 
 
  if (setjmp (tmp_jmp) == 0)
  if (setjmp (tmp_jmp) == 0)
    {
    {
      va_list argList = args;
      va_list argList = args;
      memcpy (error_return, tmp_jmp, sizeof (jmp_buf));
      memcpy (error_return, tmp_jmp, sizeof (jmp_buf));
      memcpy (quit_return, tmp_jmp, sizeof (jmp_buf));
      memcpy (quit_return, tmp_jmp, sizeof (jmp_buf));
      ret = func (argList);
      ret = func (argList);
    }
    }
  restore_cleanups (saved_cleanup_chain);
  restore_cleanups (saved_cleanup_chain);
  memcpy (error_return, saved_error, sizeof (jmp_buf));
  memcpy (error_return, saved_error, sizeof (jmp_buf));
  error_pre_print = saved_error_pre_print;
  error_pre_print = saved_error_pre_print;
  memcpy (quit_return, saved_quit, sizeof (jmp_buf));
  memcpy (quit_return, saved_quit, sizeof (jmp_buf));
  quit_pre_print = saved_quit_pre_print;
  quit_pre_print = saved_quit_pre_print;
 
 
  return ret;
  return ret;
}
}
 
 
/*
/*
   ** vcatch_errors().
   ** vcatch_errors().
   **        Catch errors occurring in tui or non tui function, handling
   **        Catch errors occurring in tui or non tui function, handling
   **        variable param lists. Note that 'func' must take a variable
   **        variable param lists. Note that 'func' must take a variable
   **        argument list as well.
   **        argument list as well.
 */
 */
Opaque
Opaque
#ifdef __STDC__
#ifdef __STDC__
vcatch_errors (
vcatch_errors (
                OpaqueFuncPtr func,...)
                OpaqueFuncPtr func,...)
#else
#else
vcatch_errors (va_alist)
vcatch_errors (va_alist)
     va_dcl
     va_dcl
/*
/*
   vcatch_errors(func, va_alist)
   vcatch_errors(func, va_alist)
   OpaqueFuncPtr    func;
   OpaqueFuncPtr    func;
   va_dcl
   va_dcl
 */
 */
#endif
#endif
{
{
  Opaque ret = (Opaque) NULL;
  Opaque ret = (Opaque) NULL;
  va_list args;
  va_list args;
#ifdef __STDC__
#ifdef __STDC__
  va_start (args, func);
  va_start (args, func);
/*
/*
   va_arg(args, OpaqueFuncPtr);
   va_arg(args, OpaqueFuncPtr);
 */
 */
#else
#else
  OpaqueFuncPtr func;
  OpaqueFuncPtr func;
 
 
  va_start (args);
  va_start (args);
  func = va_arg (args, OpaqueFuncPtr);
  func = va_arg (args, OpaqueFuncPtr);
#endif
#endif
  ret = va_catch_errors (func, args);
  ret = va_catch_errors (func, args);
  va_end (args);
  va_end (args);
 
 
  return ret;
  return ret;
}
}
 
 
 
 
void
void
#ifdef __STDC__
#ifdef __STDC__
strcat_to_buf (
strcat_to_buf (
                char *buf,
                char *buf,
                int buflen,
                int buflen,
                char *itemToAdd)
                char *itemToAdd)
#else
#else
strcat_to_buf (buf, buflen, itemToAdd)
strcat_to_buf (buf, buflen, itemToAdd)
     char *buf;
     char *buf;
     int buflen;
     int buflen;
     char *itemToAdd;
     char *itemToAdd;
#endif
#endif
{
{
  if (itemToAdd != (char *) NULL && buf != (char *) NULL)
  if (itemToAdd != (char *) NULL && buf != (char *) NULL)
    {
    {
      if ((strlen (buf) + strlen (itemToAdd)) <= buflen)
      if ((strlen (buf) + strlen (itemToAdd)) <= buflen)
        strcat (buf, itemToAdd);
        strcat (buf, itemToAdd);
      else
      else
        strncat (buf, itemToAdd, (buflen - strlen (buf)));
        strncat (buf, itemToAdd, (buflen - strlen (buf)));
    }
    }
 
 
  return;
  return;
}                               /* strcat_to_buf */
}                               /* strcat_to_buf */
 
 
/* VARARGS */
/* VARARGS */
void
void
#ifdef ANSI_PROTOTYPES
#ifdef ANSI_PROTOTYPES
strcat_to_buf_with_fmt (
strcat_to_buf_with_fmt (
                         char *buf,
                         char *buf,
                         int bufLen,
                         int bufLen,
                         char *format,...)
                         char *format,...)
#else
#else
strcat_to_buf_with_fmt (va_alist)
strcat_to_buf_with_fmt (va_alist)
     va_dcl
     va_dcl
#endif
#endif
{
{
  char *linebuffer;
  char *linebuffer;
  struct cleanup *old_cleanups;
  struct cleanup *old_cleanups;
  va_list args;
  va_list args;
#ifdef ANSI_PROTOTYPES
#ifdef ANSI_PROTOTYPES
  va_start (args, format);
  va_start (args, format);
#else
#else
  char *buf;
  char *buf;
  int bufLen;
  int bufLen;
  char *format;
  char *format;
 
 
  va_start (args);
  va_start (args);
  buf = va_arg (args, char *);
  buf = va_arg (args, char *);
  bufLen = va_arg (args, int);
  bufLen = va_arg (args, int);
  format = va_arg (args, char *);
  format = va_arg (args, char *);
#endif
#endif
  vasprintf (&linebuffer, format, args);
  vasprintf (&linebuffer, format, args);
  old_cleanups = make_cleanup (free, linebuffer);
  old_cleanups = make_cleanup (free, linebuffer);
  strcat_to_buf (buf, bufLen, linebuffer);
  strcat_to_buf (buf, bufLen, linebuffer);
  do_cleanups (old_cleanups);
  do_cleanups (old_cleanups);
  va_end (args);
  va_end (args);
}
}
 
 
 
 
 
 
 
 
 
 
/***********************
/***********************
** Static Functions
** Static Functions
************************/
************************/
 
 
 
 
/*
/*
   ** _tui_vDo().
   ** _tui_vDo().
   **        General purpose function to execute a tui function.  Transitions
   **        General purpose function to execute a tui function.  Transitions
   **        between curses and the are handled here.  This function is called
   **        between curses and the are handled here.  This function is called
   **        by non-tui gdb functions.
   **        by non-tui gdb functions.
   **
   **
   **        Errors are caught here.
   **        Errors are caught here.
   **        If there is no error, the value returned by 'func' is returned.
   **        If there is no error, the value returned by 'func' is returned.
   **        If there is an error, then zero is returned.
   **        If there is an error, then zero is returned.
   **
   **
   **       Must not be called with immediate_quit in effect (bad things might
   **       Must not be called with immediate_quit in effect (bad things might
   **       happen, say we got a signal in the middle of a memcpy to quit_return).
   **       happen, say we got a signal in the middle of a memcpy to quit_return).
   **       This is an OK restriction; with very few exceptions immediate_quit can
   **       This is an OK restriction; with very few exceptions immediate_quit can
   **       be replaced by judicious use of QUIT.
   **       be replaced by judicious use of QUIT.
 */
 */
static Opaque
static Opaque
#ifdef __STDC__
#ifdef __STDC__
_tui_vDo (
_tui_vDo (
           TuiOpaqueFuncPtr func,
           TuiOpaqueFuncPtr func,
           va_list args)
           va_list args)
#else
#else
_tui_vDo (func, args)
_tui_vDo (func, args)
     TuiOpaqueFuncPtr func;
     TuiOpaqueFuncPtr func;
     va_list args;
     va_list args;
#endif
#endif
{
{
  extern int terminal_is_ours;
  extern int terminal_is_ours;
 
 
  Opaque ret = (Opaque) NULL;
  Opaque ret = (Opaque) NULL;
 
 
  /* It is an error to be tuiDo'ing if we
  /* It is an error to be tuiDo'ing if we
     * don't own the terminal.
     * don't own the terminal.
   */
   */
  if (!terminal_is_ours)
  if (!terminal_is_ours)
    return ret;
    return ret;
 
 
  if (tui_version)
  if (tui_version)
    {
    {
      /* If doing command window the "XDB way" (command window
      /* If doing command window the "XDB way" (command window
         * is unmanaged by curses...
         * is unmanaged by curses...
       */
       */
      /* Set up terminal for TUI */
      /* Set up terminal for TUI */
      tuiTermSetup (1);
      tuiTermSetup (1);
 
 
      ret = va_catch_errors (func, args);
      ret = va_catch_errors (func, args);
 
 
      /* Set up terminal for command window */
      /* Set up terminal for command window */
      tuiTermUnsetup (1, cmdWin->detail.commandInfo.curch);
      tuiTermUnsetup (1, cmdWin->detail.commandInfo.curch);
    }
    }
 
 
  return ret;
  return ret;
}                               /* _tui_vDo */
}                               /* _tui_vDo */
 
 
 
 
static void
static void
#ifdef __STDC__
#ifdef __STDC__
_toggle_command (
_toggle_command (
                  char *arg,
                  char *arg,
                  int fromTTY)
                  int fromTTY)
#else
#else
_toggle_command (arg, fromTTY)
_toggle_command (arg, fromTTY)
     char *arg;
     char *arg;
     int fromTTY;
     int fromTTY;
#endif
#endif
{
{
  printf_filtered ("Specify feature to toggle.\n%s\n",
  printf_filtered ("Specify feature to toggle.\n%s\n",
                   (tui_version) ? TUI_TOGGLE_USAGE : TOGGLE_USAGE);
                   (tui_version) ? TUI_TOGGLE_USAGE : TOGGLE_USAGE);
/*
/*
   tuiDo((TuiOpaqueFuncPtr)_Toggle_command, arg, fromTTY);
   tuiDo((TuiOpaqueFuncPtr)_Toggle_command, arg, fromTTY);
 */
 */
}
}
 
 
/*
/*
   ** _tui_vToggle_command().
   ** _tui_vToggle_command().
 */
 */
static void
static void
#ifdef __STDC__
#ifdef __STDC__
_tui_vToggle_command (
_tui_vToggle_command (
                       va_list args)
                       va_list args)
#else
#else
_tui_vToggle_command (args)
_tui_vToggle_command (args)
     va_list args;
     va_list args;
#endif
#endif
{
{
  char *arg;
  char *arg;
  int fromTTY;
  int fromTTY;
 
 
  arg = va_arg (args, char *);
  arg = va_arg (args, char *);
 
 
  if (arg == (char *) NULL)
  if (arg == (char *) NULL)
    printf_filtered (TOGGLE_USAGE);
    printf_filtered (TOGGLE_USAGE);
  else
  else
    {
    {
      char *ptr = (char *) tuiStrDup (arg);
      char *ptr = (char *) tuiStrDup (arg);
      int i;
      int i;
 
 
      for (i = 0; (ptr[i]); i++)
      for (i = 0; (ptr[i]); i++)
        ptr[i] = toupper (arg[i]);
        ptr[i] = toupper (arg[i]);
 
 
      if (subsetCompare (ptr, TUI_FLOAT_REGS_NAME))
      if (subsetCompare (ptr, TUI_FLOAT_REGS_NAME))
        tuiToggleFloatRegs ();
        tuiToggleFloatRegs ();
/*        else if (subsetCompare(ptr, "ANOTHER TOGGLE OPTION"))
/*        else if (subsetCompare(ptr, "ANOTHER TOGGLE OPTION"))
   ...
   ...
 */
 */
      else
      else
        printf_filtered (TOGGLE_USAGE);
        printf_filtered (TOGGLE_USAGE);
      tuiFree (ptr);
      tuiFree (ptr);
    }
    }
 
 
  return;
  return;
}                               /* _tuiToggle_command */
}                               /* _tuiToggle_command */
 
 
 
 
static void
static void
#ifdef __STDC__
#ifdef __STDC__
_tuiReset (void)
_tuiReset (void)
#else
#else
_tuiReset ()
_tuiReset ()
#endif
#endif
{
{
  struct termio mode;
  struct termio mode;
 
 
  /*
  /*
     ** reset the teletype mode bits to a sensible state.
     ** reset the teletype mode bits to a sensible state.
     ** Copied tset.c
     ** Copied tset.c
   */
   */
#if ! defined (USG) && defined (TIOCGETC)
#if ! defined (USG) && defined (TIOCGETC)
  struct tchars tbuf;
  struct tchars tbuf;
#endif /* !USG && TIOCGETC */
#endif /* !USG && TIOCGETC */
#ifdef UCB_NTTY
#ifdef UCB_NTTY
  struct ltchars ltc;
  struct ltchars ltc;
 
 
  if (ldisc == NTTYDISC)
  if (ldisc == NTTYDISC)
    {
    {
      ioctl (FILEDES, TIOCGLTC, &ltc);
      ioctl (FILEDES, TIOCGLTC, &ltc);
      ltc.t_suspc = CHK (ltc.t_suspc, CTRL ('Z'));
      ltc.t_suspc = CHK (ltc.t_suspc, CTRL ('Z'));
      ltc.t_dsuspc = CHK (ltc.t_dsuspc, CTRL ('Y'));
      ltc.t_dsuspc = CHK (ltc.t_dsuspc, CTRL ('Y'));
      ltc.t_rprntc = CHK (ltc.t_rprntc, CTRL ('R'));
      ltc.t_rprntc = CHK (ltc.t_rprntc, CTRL ('R'));
      ltc.t_flushc = CHK (ltc.t_flushc, CTRL ('O'));
      ltc.t_flushc = CHK (ltc.t_flushc, CTRL ('O'));
      ltc.t_werasc = CHK (ltc.t_werasc, CTRL ('W'));
      ltc.t_werasc = CHK (ltc.t_werasc, CTRL ('W'));
      ltc.t_lnextc = CHK (ltc.t_lnextc, CTRL ('V'));
      ltc.t_lnextc = CHK (ltc.t_lnextc, CTRL ('V'));
      ioctl (FILEDES, TIOCSLTC, &ltc);
      ioctl (FILEDES, TIOCSLTC, &ltc);
    }
    }
#endif /* UCB_NTTY */
#endif /* UCB_NTTY */
#ifndef USG
#ifndef USG
#ifdef TIOCGETC
#ifdef TIOCGETC
  ioctl (FILEDES, TIOCGETC, &tbuf);
  ioctl (FILEDES, TIOCGETC, &tbuf);
  tbuf.t_intrc = CHK (tbuf.t_intrc, CTRL ('?'));
  tbuf.t_intrc = CHK (tbuf.t_intrc, CTRL ('?'));
  tbuf.t_quitc = CHK (tbuf.t_quitc, CTRL ('\\'));
  tbuf.t_quitc = CHK (tbuf.t_quitc, CTRL ('\\'));
  tbuf.t_startc = CHK (tbuf.t_startc, CTRL ('Q'));
  tbuf.t_startc = CHK (tbuf.t_startc, CTRL ('Q'));
  tbuf.t_stopc = CHK (tbuf.t_stopc, CTRL ('S'));
  tbuf.t_stopc = CHK (tbuf.t_stopc, CTRL ('S'));
  tbuf.t_eofc = CHK (tbuf.t_eofc, CTRL ('D'));
  tbuf.t_eofc = CHK (tbuf.t_eofc, CTRL ('D'));
  /* brkc is left alone */
  /* brkc is left alone */
  ioctl (FILEDES, TIOCSETC, &tbuf);
  ioctl (FILEDES, TIOCSETC, &tbuf);
#endif /* TIOCGETC */
#endif /* TIOCGETC */
  mode.sg_flags &= ~(RAW
  mode.sg_flags &= ~(RAW
#ifdef CBREAK
#ifdef CBREAK
                     | CBREAK
                     | CBREAK
#endif /* CBREAK */
#endif /* CBREAK */
                     | VTDELAY | ALLDELAY);
                     | VTDELAY | ALLDELAY);
  mode.sg_flags |= XTABS | ECHO | CRMOD | ANYP;
  mode.sg_flags |= XTABS | ECHO | CRMOD | ANYP;
#else /*USG */
#else /*USG */
  ioctl (FILEDES, TCGETA, &mode);
  ioctl (FILEDES, TCGETA, &mode);
  mode.c_cc[VINTR] = CHK (mode.c_cc[VINTR], CTRL ('?'));
  mode.c_cc[VINTR] = CHK (mode.c_cc[VINTR], CTRL ('?'));
  mode.c_cc[VQUIT] = CHK (mode.c_cc[VQUIT], CTRL ('\\'));
  mode.c_cc[VQUIT] = CHK (mode.c_cc[VQUIT], CTRL ('\\'));
  mode.c_cc[VEOF] = CHK (mode.c_cc[VEOF], CTRL ('D'));
  mode.c_cc[VEOF] = CHK (mode.c_cc[VEOF], CTRL ('D'));
 
 
  mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | INLCR | IGNCR | IUCLC | IXOFF);
  mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | INLCR | IGNCR | IUCLC | IXOFF);
  mode.c_iflag |= (BRKINT | ISTRIP | ICRNL | IXON);
  mode.c_iflag |= (BRKINT | ISTRIP | ICRNL | IXON);
  mode.c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | OFDEL |
  mode.c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | OFDEL |
                    NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY);
                    NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY);
  mode.c_oflag |= (OPOST | ONLCR);
  mode.c_oflag |= (OPOST | ONLCR);
  mode.c_cflag &= ~(CSIZE | PARODD | CLOCAL);
  mode.c_cflag &= ~(CSIZE | PARODD | CLOCAL);
#ifndef hp9000s800
#ifndef hp9000s800
  mode.c_cflag |= (CS8 | CREAD);
  mode.c_cflag |= (CS8 | CREAD);
#else /*hp9000s800 */
#else /*hp9000s800 */
  mode.c_cflag |= (CS8 | CSTOPB | CREAD);
  mode.c_cflag |= (CS8 | CSTOPB | CREAD);
#endif /* hp9000s800 */
#endif /* hp9000s800 */
  mode.c_lflag &= ~(XCASE | ECHONL | NOFLSH);
  mode.c_lflag &= ~(XCASE | ECHONL | NOFLSH);
  mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOK);
  mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOK);
  ioctl (FILEDES, TCSETAW, &mode);
  ioctl (FILEDES, TCSETAW, &mode);
#endif /* USG */
#endif /* USG */
 
 
  return;
  return;
}                               /* _tuiReset */
}                               /* _tuiReset */
 
 

powered by: WebSVN 2.1.0

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