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 a

⟦e88f19c4c⟧ TextFile

    Length: 8039 (0x1f67)
    Types: TextFile
    Names: »assembly.c«

Derivation

└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
    └─⟦e10a7c8ba⟧ »./UNRELEASED/xgdb.tar.Z« 
        └─⟦ae30648b5⟧ 
            └─⟦this⟧ »./assembly.c« 

TextFile

\f


#ifndef lint
static char rcsid[] = "$Header: assembly.c,v 1.1 89/07/05 15:35:49 hubbard Exp $";
#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.
 * When:	February 23rd, 1989.
 *
 * $Log:	assembly.c,v $
 * Revision 1.1  89/07/05  15:35:49  hubbard
 * Initial revision
 * 
 * 
 */

#include "xgdb.h"

static View *AssemblyView;
void debuggerQueryFunction();

/*
 * Everything needed to handle the disassembled code display pane.
 */

static struct {
     long *addrs;	/* addresses */
     String *list;	/* text strings */
     int nitems;	/* number of lines */
     String addr;	/* current address */
     String function;	/* current function */
} assemblyInfo;

/*
 * Mapped?
 */
Boolean assemblyMapped()
{
     Entry("assemblyMapped");

     if (AssemblyView)
	  Leave(AssemblyView->mapped);
     Leave(FALSE);
}

static void assemblyHiliteLine(addr)
long addr;
{
     register int i;

     Entry("assemblyHiliteLine");

     for (i = 0; i < assemblyInfo.nitems; i++)
	  if (addr == assemblyInfo.addrs[i])
	       XtScrollListHighlight(AssemblyView->output, i);
     Leave_void;
}

/*
 * What to do when an address is selected.
 */
static void assemblySelectLine(w, client_data, data)
Widget w;
caddr_t client_data, data;
{
     XtScrollListReturnStruct *addr = (XtScrollListReturnStruct *)data;

     Entry("assemblySelectLine");

     debuggerAddBkpt(NULL, T_ADDRESS, assemblyInfo.addrs[addr->list_index]);
     assemblyHiliteLine(strtol(dbg_state.S_address, NULL, 16));
     Leave_void;
}

/*
 * Make sure the current address is highlighted.
 */
void assemblyUpdateView()
{
     static Boolean initialized = FALSE;
     FieldAttributes fla;
     long addr1, addr2;

     Entry("assemblyUpdateView");

     if (!initialized) {
	  STASH(assemblyInfo.addr, "0xffffffff");
	  STASH(assemblyInfo.function, "*");
	  initialized = TRUE;
     }
     if (assemblyMapped()) {
	  addr1 = strtol(assemblyInfo.addr, NULL, 16);
	  addr2 = strtol(dbg_state.S_address, NULL, 16);
	  if (addr1 != addr2) {
	       STASH(assemblyInfo.addr, dbg_state.S_address);
	       assemblyHiliteLine(addr2);
	  }
	  if (strcmp(assemblyInfo.function, dbg_state.S_function)) {
	       STASH(assemblyInfo.function, dbg_state.S_function);
	       fla.label = assemblyInfo.function;
	       changeField(nameToField("function_name",
				       AssemblyView->fields),
			   FldLabel, &fla);
	       if (!strcmp(dbg_state.S_frame, "0"))
	            debuggerQueryFunction();
	  }
     }
     Leave_void;
}

/*
 * Display the current disassembled function. This is called as
 * a special handler with the threshold turned off.
 */
String assemblyDisplayFunction(P_ARGS)
P_ARG_DECL;
{
     register int i, list_size;
     register String cp, cp_end;
     int start, end, space, newln;
     struct re_registers regs;
     char buf[256], addr[12], line[230];

     Entry("assemblyDisplayFunction");

     P_CHECKARGS;

     /* Find the ASDUMP_START and ASDUMP_END keywords */
     if ((matchExp(s, "ASDS", &regs)) < 0) {
	  Leave(s);
     }
     else {
	  cp = s + regs.end[0];
	  start = regs.start[0];
     }
     if ((end = matchExp(s, "ASDE", &regs)) < 0) {
	  Leave(s);
     }
     else {
	  cp_end = s + regs.start[0];
	  end = regs.end[0];
     }
     /* Prepare storage */
     if (assemblyInfo.list) {
	  for (i = 0; i < assemblyInfo.nitems; i++)
	       XtFree(assemblyInfo.list[i]);
	  XtFree(assemblyInfo.list);
     }
     if (assemblyInfo.addrs)
	  XtFree(assemblyInfo.addrs);

     assemblyInfo.list = (String *)XtMalloc(LINE_CHUNK * sizeof(String));
     assemblyInfo.addrs =  (long *)XtMalloc(LINE_CHUNK * sizeof(long));
     list_size = LINE_CHUNK;
     i = 0;

     while (cp != cp_end) {
	  if (i == list_size) {
	       list_size += LINE_CHUNK;

	       assemblyInfo.list = (String *)XtRealloc(assemblyInfo.list,
						       list_size *
						       sizeof(String));
	       assemblyInfo.addrs =  (long *)XtRealloc(assemblyInfo.addrs,
						       list_size *
						       sizeof(long));
	  }
	  space = iindex(cp, ' ');
	  newln = iindex(cp, '\n');
	  if (space < 0 || newln < 0) {
	       puke("%p: Bad assembly line at '%s'", cp);
	       Leave_void;
	  }
	  assemblyInfo.addrs[i] = strtol(cp, NULL, 16);
	  CPYN(addr, cp, space);
	  CPYN(line, cp + space, newln - space);
	  sprintf(buf, "%s: %s", addr, line);
	  STASHF(assemblyInfo.list[i], buf);
	  i++;
	  cp += (newln + 1);
     }
     assemblyInfo.nitems = i;
     XtScrollListChange(AssemblyView->output, assemblyInfo.list,
			i, 0, TRUE);
     assemblyHiliteLine(strtol(dbg_state.S_address, NULL, 16));
     *len -= clipString(s, start, end);
     toggleOutputThreshold();
     Leave(s);
}

/*
 * The following are invoked directly by the translation manager.
 */
void assembly_step(w, ev, av, ac)
Widget w;
XEvent *ev;
String *av;
Cardinal *ac;
{
     Entry("assembly_step");

     debuggerStepI(NULL, NULL, NULL);
     Leave_void;
}

void assembly_next(w, ev, av, ac)
Widget w;
XEvent *ev;
String *av;
Cardinal *ac;
{
     Entry("assembly_next");

     debuggerStepIThrough(NULL, NULL, NULL);
     Leave_void;
}

/*
 * Create the assembly code view pane.
 */
void assemblyCreateView(w, client_data, data)
Widget w;
caddr_t client_data, data;
{
     static FormField buttons[] = {
	  { { "close", viewCloseShell },	2,  FALSE,  0,  0,  0,  0 },
	  { { "query", debuggerQueryFunction }, 2,  FALSE,  0,  5,  0,  1 },
	  { { "Function:", NULL },		0,  FALSE,  0,  10,  0,  2 },
	  { { "function_name", NULL },		1,  TRUE,   0,  5,  0,  3 },
	  { { NULL, NULL },			0,  0,  0,  0,  0,  0 },
     };
     static XtActionsRec asm_actions[] = {
	  { "Step", assembly_step },
	  { "Next", assembly_next },
     };
     static char asm_trans[] = "<Key>S: Step()\n <Key>N: Next()\n";
     static XtTranslations trans = NULL;
     FieldAttributes fla;
     Field *flist;
     String name = ((w) ? XtWidgetToName(w) : (String)data);

     Entry("assemblyCreateView");

     if (!AssemblyView) {
	  convertFormToField(buttons, &flist);

	  if (!trans) {
	       XtAddActions(asm_actions, XtNumber(asm_actions));
	       trans = XtParseTranslationTable(asm_trans);
	  }

	  ii = 0;
	  XtSetArg(aa[ii], XtNforceColumns,  TRUE);			ii++;
	  XtSetArg(aa[ii], XtNdefaultColumns, 1);			ii++;
	  XtSetArg(aa[ii], XtNrepositionOnHilite, TRUE); 		ii++;
	  XtSetArg(aa[ii], XtNscrollVertical, TRUE);			ii++;
	  if (assemblyInfo.list) {
	       XtSetArg(aa[ii], XtNlist, assemblyInfo.list);		ii++;
	       XtSetArg(aa[ii], XtNnumberStrings, assemblyInfo.nitems);	ii++;
	  }
	  AssemblyView = viewCreateShell(name, flist,
					 scrollListWidgetClass,
					 aa, ii);
	  XtAddCallback(AssemblyView->output, XtNcallback, assemblySelectLine,
			NULL);
	  XtAugmentTranslations(AssemblyView->output, trans);

     }
     XtPopup(AssemblyView->parent, XtGrabNone);
     XRaiseWindow(XtDisplay(AssemblyView->parent),
		  XtWindow(AssemblyView->parent));
     AssemblyView->mapped = TRUE;

     /* Make the field that invoked us go insensitive */
     fla.sensitive = FALSE;
     changeField(nameToField(name, client_data), FldSensitive, &fla);
     assemblyUpdateView();
     Leave_void;
}