DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T m

⟦4e278ae19⟧ TextFile

    Length: 13764 (0x35c4)
    Types: TextFile
    Names: »main.c,v«

Derivation

└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
    └─⟦34cc4e2f7⟧ »./UNRELEASED/xgdb3.2.tar.Z« 
        └─⟦80fac5d7c⟧ 
            └─⟦this⟧ »./RCS/main.c,v« 

TextFile

head     1.1;
access   ;
symbols  ;
locks    hubbard:1.1; strict;
comment  @ * @;


1.1
date     89.07.05.15.36.09;  author hubbard;  state Exp;
branches ;
next     ;


desc
@Initial checkin, Beta version 0.1.
@



1.1
log
@Initial revision
@
text
@\f


#ifndef lint
static char rcsid[] = "$Header$";
#endif

/*
 *
 *                     Copyright 1988, 1989
 *                  PCS Computer Systeme, GmbH
 *                     Munich, West Germany
 *
 *  All rights reserved.
 * 
 *  This is unsupported software and is subject to change without notice.
 *  PCS makes no representations about the suitability of this software
 *  for any purpose. It is supplied "as is" without express or implied
 *  warranty.
 * 
 *  Permission to use, copy, modify, and distribute this software and its
 *  documentation for any purpose and without fee is hereby granted, provided
 *  that the above copyright notice appear in all copies and that both that
 *  copyright notice and this permission notice appear in supporting
 *  documentation, and that the name of PCS Computer Systeme not be used in
 *  advertising or publicity pertaining to distribution of the software
 *  without specific, written prior permission.
 *
 */

/*
 * Author:	Jordan K. Hubbard
 * For:		PCS Computer Systems, GmbH.
 * Why:		Just because.
 * When:	February 10th, 1989.
 *
 * $Log$
 * 
 */

#include "xgdb.h"
#include "xgdb.bm"

app_resourceRec app_resources;

/* more readable, I think. */
#define offset(field)	XtOffset(struct _resources *, field)

static XtResource resources[] = {
     {"showStack",	"ShowStack",	XtRBoolean,	sizeof(Boolean),
	   offset(show_stack), XtRImmediate, (caddr_t)False},
     {"showStatus",	"ShowStatus",	XtRBoolean,	sizeof(Boolean),
	   offset(show_status), XtRImmediate, (caddr_t)False},
     {"showSource",	"ShowSource",	XtRBoolean,	sizeof(Boolean),
	   offset(show_source), XtRImmediate, (caddr_t)False},
     {"showAssembly",	"ShowAssembly",	XtRBoolean,	sizeof(Boolean),
	   offset(show_code), XtRImmediate, (caddr_t)False},
     {"showExec",	"ShowExec",	XtRBoolean,	sizeof(Boolean),
	   offset(show_exec), XtRImmediate, (caddr_t)False},
     {"showBreak",	"ShowBreak",	XtRBoolean,	sizeof(Boolean),
	   offset(show_break), XtRImmediate, (caddr_t)False},
     {"debugger",	"Debugger",	XtRString,	sizeof(String),
	   offset(debugger), XtRString, (caddr_t)DEF_DEBUGGER},
     {"regexpFile",	"RegexpFile",	XtRString,	sizeof(String),
	   offset(reg_file), XtRString, (caddr_t)DEF_REGEXP_FILE},
     {"dbgCursor",	XtCCursor,	XtRCursor,	sizeof(Cursor),
	   offset(cursors.dbg), XtRString, DEF_DBG_CURSOR},
     {"optionCursor",	XtCCursor,	XtRCursor,	sizeof(Cursor),
	   offset(cursors.option), XtRString, DEF_OPT_CURSOR},
     {"popupCursor",	XtCCursor,	XtRCursor,	sizeof(Cursor),
	   offset(cursors.popup), XtRString, DEF_POPUP_CURSOR},
     {"buttonCursor",	XtCCursor,	XtRCursor,	sizeof(Cursor),
	   offset(cursors.button), XtRString, DEF_BUTTON_CURSOR},
     {"labelCursor",	XtCCursor,	XtRCursor,	sizeof(Cursor),
	   offset(cursors.label), XtRString, DEF_LABEL_CURSOR},
     {"busyCursor",	XtCCursor,	XtRCursor,	sizeof(Cursor),
	   offset(cursors.busy), XtRString, DEF_BUSY_CURSOR},
     {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
	   offset(colors.foreground), XtRString, "XtDefaultForeground"},
     {XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
	   offset(colors.background), XtRString, "XtDefaultBackground"},
};

#undef offset

static XrmOptionDescRec opts[] = {
    {"-showstack",	"*showStack",		XrmoptionNoArg, "on" },
    {"-showstatus",	"*showStatus",		XrmoptionNoArg, "on" },
    {"-showsource",	"*showSource",		XrmoptionNoArg, "on" },
    {"-showassembly", 	"*showAssembly",	XrmoptionNoArg, "on" },
    {"-showdisplay",	"*showDisplay",		XrmoptionNoArg, "on" },
    {"-showbreak",	"*showBreak",		XrmoptionNoArg, "on" },
    {"-debugger",	"*debugger",		XrmoptionSepArg, NULL },
    {"-regexpfile",	"*regexpFile",		XrmoptionSepArg, NULL },
};

Widget Toplevel, Input;

View Output;

Field *CommandButtons;
Field *MenuButtons;
Field *InputButtons;
Field *OutputButtons;

String program_name, program_class;
char DebuggerCommandBuffer[MAX_CMD_LEN];
String DebuggerPrompt;
String DebuggerPromptRegexp;
String *DebuggerArgs;
String *Global_av;
Cardinal Global_ac;

Parser *Generic;		/* Set in gdb.c to be the generic parser */
Process *DebuggerProcess;	/* always points to the debugger process */

/* Debugger state information */
struct State dbg_state;

/*
 * Everybody needs these..
 */
Arg args[20], aa[20];
Cardinal i, ii;

main(ac, av)
Cardinal ac;
String *av;
{
     Pixmap iconpix;
     void createWorld(), createInitialViews(), initializeState();

     Entry("main");

     setbuf(stderr, NULL);
     /*
      * Figure out what we're called.
      */
     program_name = strip_directory_prefix(*av);
     /*
      * Make up a class name for ourselves.
      */
     program_class = class_from_name(program_name);

     setOutputThreshold(DEF_OUTPUT_THRESHOLD);

     Toplevel = XtInitialize(program_name, program_class,
			     opts, XtNumber(opts),
			     &ac, av);

     /* Remaining args must be for debugger */
     Global_ac = ac;
     Global_av = av;

     iconpix = XCreateBitmapFromData(XtDisplay(Toplevel),
				     DefaultRootWindow(XtDisplay(Toplevel)),
				     xgdb_bits, xgdb_width, xgdb_height );

     XtGetApplicationResources(Toplevel, &app_resources, resources,
			       XtNumber(resources), NULL, 0);

     i = 0;
     XtSetArg(args[i], XtNiconPixmap, iconpix); i++;
     XtSetValues(Toplevel, args, i);

     /* Decide what regular expression syntax to use. */
     re_set_syntax(RE_SYN);

     /* Read in the parser regexp list */
     initializeRegexps(app_resources.reg_file);

     /* Almost ready.. Turn on process handling */
     enableProcessHandling();

     /* Construct the debugger's arg list */
     setDebuggerArgs(app_resources.debugger);

     /* Awaaaaayyy we go.... */
     DebuggerProcess = launchProcess(app_resources.debugger, DebuggerArgs,
				     processDebuggerOutput, NULL,
				     handleDebuggerTermination);
     if (!DebuggerProcess)
	  puke_and_die("Can't find or execute debugger '%s'",
		       app_resources.debugger);
     DebuggerProcess->view = &Output;

     /* Set our initial state */
     initializeState();

     /* Set the debugger's initial state */
     setInitialDebuggerState(DebuggerProcess);

     /* Create all widgets */
     createWorld(Toplevel);

     /* Realize the world */
     XtRealizeWidget(Toplevel);

     /* Silly shell widgets don't recognize XtNcursor */
     XDefineCursor(XtDisplay(Toplevel), XtWindow(Toplevel),
		   app_resources.cursors.dbg);

     /* Create all initial views */
     createInitialViews();

     /* Wheeeee.... */
     XtMainLoop();

     /* Never reached, but let's stay consistent */
     Leave_void; 
}

/*
 * Create all necessary widgets.
 */

static char label_trans[] = "\
<Btn1Down>:	PopupMenu()\n\
<Key>A: 	CreateView(ASSEMBLY)\n\
<Key>B: 	CreateView(BREAK)\n\
<Key>E: 	CreateView(AUTOEXEC)\n\
<Key>S: 	CreateView(SOURCE)\n\
<Key>T: 	CreateView(STACK)\n\
<Key>?: 	CreateView(STATUS)\n";

static char input_trans[] = "<Ctrl>C:	ClearInput()\n";

static void clear(w, client_data, data)
Widget w;
caddr_t client_data;
caddr_t data;
{
     Entry("clear");

     XtTextSetLastPos(w, 0);
     XtTextSetInsertionPoint(w, 0);
     Leave_void;
}

void create_view(), view_close();
static XtActionsRec actions[] = {
     { "CreateView",	create_view },
     { "ViewClose",	view_close },
     { "PopupMenu",     popupMenu },
     { "PopdownMenu",	popdownMenu },
     { "ClearInput",	clear },
     { NULL, NULL},
};

void createWorld(daddy)
Widget daddy;
{
     static XtCallbackRec callback[2], callback2[2];
     Widget tmp, outer;
     SimpleField outButtons[2];
     Cursor curs;
     void freezeSize();
     String tmp_str;
     char vers[80];

     Entry("createWorld");

     XtAddActions(actions, XtNumber(actions));

     /* outmost paned widget */
     outer = XtCreateManagedWidget(program_name, vPanedWidgetClass, daddy,
				   NULL, ZERO);

     /* Create the command buttons */
     i = 0;
     XtSetArg(args[i], XtNallowVert, TRUE); i++;
     tmp = XtCreateManagedWidget(NULL, viewportWidgetClass, outer,
				 args, i);

     i = 0;
     tmp = XtCreateManagedWidget("commandButtons", boxWidgetClass, tmp,
				 args, i);
     convertSimpleToField(DebuggerCommands, &CommandButtons);
     createFields(tmp, CommandButtons, DebuggerProcess);

     /* Label for menu */
     i = 0;
     curs = XCreateFontCursor(XtDisplay(Toplevel), XC_spider);
     sprintf(vers, "%s Version %s", program_name, VERSION);
     XtSetArg(args[i], XtNcursor, curs); i++;
     tmp = XtCreateManagedWidget(vers, labelWidgetClass, outer, args, i);
     XtOverrideTranslations(tmp, XtParseTranslationTable(label_trans));
     freezeSize(tmp);

     /* Create a menu attached to the label */
     createMenu(tmp, Options);

     /* Create input area buttons */
     i = 0;
     XtSetArg(args[i], XtNallowVert, TRUE); i++;
     tmp = XtCreateManagedWidget(NULL, viewportWidgetClass, outer,
				 args, i);

     i = 0;
     tmp = XtCreateManagedWidget("inputButtons", boxWidgetClass, tmp,
				 args, i);
     convertSimpleToField(InputRegionCommands, &InputButtons);
     createFields(tmp, InputButtons, DebuggerProcess);

     /* Create the the input area itself */
     i = 0;
     XtSetArg(args[i], XtNstring, DebuggerCommandBuffer); i++;
     XtSetArg(args[i], XtNlength, MAX_CMD_LEN); i++;
     XtSetArg(args[i], XtNeditType, XttextEdit); i++;
     XtSetArg(args[i], XtNheight, MIN_INPUT_SIZE); i++;
     Input = XtCreateManagedWidget("editWin", asciiStringWidgetClass, outer,
			   args, i);
     XtOverrideTranslations(Input, XtParseTranslationTable(input_trans));
     XtPanedSetMinMax(Input, MIN_INPUT_SIZE, 9999);

     /* Create the main output view */
     SetSimpleFld(outButtons[0], app_resources.debugger, redirectOutput);
     SetSimpleFld(outButtons[1], NULL, NULL);
     convertSimpleToField(outButtons, &OutputButtons);
     OutputButtons[0].attr_mask |= FldResizable;
     OutputButtons[0].attrs.resizable = TRUE;

     ii = 0;
     callback[0].callback = sendToDebugger;
     callback2[0].callback = interruptDebugger;
     STASHF(tmp_str, DebuggerPrompt);
     XtSetArg(aa[ii], XtNprompt, tmp_str);				ii++;
     XtSetArg(aa[ii], XtNenterCallback, callback);			ii++;
     XtSetArg(aa[ii], XtNinterruptCallback, callback2);			ii++;
     viewCreate(&Output, outer, "debuggerOutput", OutputButtons,
		ttyWidgetClass, aa, ii);
     XtPanedSetMinMax(Output.view, MIN_OUTPUT_SIZE, 9999);
     Leave_void;
}

/*
 * Initially create any views that the user has asked for in the
 * command line or resource manager.
 */
void createInitialViews()
{
     Entry("createInitialViews");

     if (app_resources.show_status)
	  statusCreateView(NULL, MenuButtons, STATUS_N);
     if (app_resources.show_stack)
	  stackCreateView(NULL,	MenuButtons, STACK_N);
     if (app_resources.show_exec)
	  autoExecCreateView(NULL, MenuButtons, AUTOEXEC_N);
     if (app_resources.show_break)
	  breakCreateView(NULL,	MenuButtons, BREAKPOINTS_N);
     if (app_resources.show_source)
	  sourceCreateView(NULL, MenuButtons, SOURCE_N);
     if (app_resources.show_code)
	  assemblyCreateView(NULL, MenuButtons, ASSEMBLY_N);
     Leave_void;
}

/*
 * For translation direct creation.
 */
void create_view(w, ev, av, ac)
Widget w;
XEvent *ev;
String *av;
Cardinal *ac;
{
     Entry("createView");

     if (ac && *ac == 1) {
	  if (!strcmp(av[0], "ASSEMBLY"))
	       assemblyCreateView(NULL, MenuButtons, ASSEMBLY_N);
	  else if (!strcmp(av[0], "BREAK"))
	       breakCreateView(NULL, MenuButtons, BREAKPOINTS_N);
	  else if (!strcmp(av[0], "AUTOEXEC"))
	       autoExecCreateView(NULL, MenuButtons, AUTOEXEC_N);
	  else if (!strcmp(av[0], "SOURCE"))
	       sourceCreateView(NULL, MenuButtons, SOURCE_N);
	  else if (!strcmp(av[0], "STACK"))
	       stackCreateView(NULL, MenuButtons, STACK_N);
	  else if (!strcmp(av[0], "STATUS"))
	       statusCreateView(NULL, MenuButtons, STATUS_N);
	  else
	       puke("%p: Unknown view '%s'.", av[0]);
     }
     else
	  puke("%p: Bad arg count.");
     Leave_void;
}
    
/*
 * Initialize the debugger state structure.
 */
void initializeState()
{
     Entry("initializeState");

     STASH(dbg_state.S_dir,		INITIAL);
     STASH(dbg_state.S_file_path,	INITIAL);
     STASH(dbg_state.S_exec_file,	INITIAL);
     STASH(dbg_state.S_symbol_file,	INITIAL);
     STASH(dbg_state.S_core_file,	INITIAL);
     STASH(dbg_state.S_text_segment,	INITIAL);
     STASH(dbg_state.S_data_segment,	INITIAL);
     STASH(dbg_state.S_stack_segment,	INITIAL);
     STASH(dbg_state.S_breakpoint,	INITIAL);
     STASH(dbg_state.S_file,		INITIAL);
     STASH(dbg_state.S_function,	INITIAL);
     STASH(dbg_state.S_line,		"0");
     STASH(dbg_state.S_address,		"0x0");
     STASH(dbg_state.S_frame,		"0");

     dbg_state.S_userInput = FALSE;
     dbg_state.S_outputSent = FALSE;
     dbg_state.S_promptSeen = FALSE;
     Leave_void;
}

/*
 * Make a paned child retain its size.
 */
void freezeSize(w)
Widget w;
{
     Dimension height;
     
     Entry("freezeSize");

     XtSetArg(args[0], XtNheight, &height);
     XtGetValues(w, args, ONE);
     XtPanedSetMinMax(w, height, height);
     Leave_void;
}

#include "IntrinsicP.h"
#include "CoreP.h"
/*
 * Given a widget, return its name. This really should be provided by
 * the toolkit, but rumor has it that this will be implemented in R4
 * under the same name. If and when this time comes, this code should
 * be removed (it violates the opaque type rules).
 */
String XtWidgetToName(w)
Widget w;
{
     Entry("XtWidgetToName");

     Leave(((WidgetRec *)w)->core.name);
}
@