1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
|
/*****************************************************************************
*
* xdbx - X Window System interface to the dbx debugger
*
* Copyright 1989 The University of Texas at Austin
* Copyright 1990 Microelectronics and Computer Technology Corporation
*
* 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 The University of Texas
* and Microelectronics and Computer Technology Corporation (MCC) not be
* used in advertising or publicity pertaining to distribution of
* the software without specific, written prior permission. The
* University of Texas and MCC makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
* ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: Po Cheung
* Created: March 10, 1989
*
*****************************************************************************
*
* xxgdb - X Window System interface to the gdb debugger
*
* Copyright 1990,1993 Thomson Consumer Electronics, Inc.
*
* 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 Thomson Consumer
* Electronics (TCE) not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. TCE makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
* SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*
* Adaptation to GDB: Pierre Willard
* XXGDB Created: December, 1990
*
*****************************************************************************/
/* dataDpy.c:
*
* Provide graphical display of C pointers and structures.
*
* BuildLinePos(): Construct an array indexing the character position of
* each line.
* PositionToLine(): Return the character position of a given line.
* SelectPointer(): Action proc for double click on a pointer value,
* CreateDataPopup(): Create a popup to display the object pointed to by a
* pointer.
* UpdateDataPopup(): Update an unused popupshell to display data.
* AppendList(): Append a popup to the list.
* DeleteList(): Delete a popup from the list.
* pop_down(): pop down the popup and free storage.
* DestroyDataPopup():event handler for destroying a popup, call DeleteList()
* and pop_down() (CRL mod 25)
* MovePopup(): Position the popup.
* print_handler(): Action handler for displaying pointers and structures.
*/
/*
* 01FEB94: bugs fixed (klamer)
* xxgdb does not allow the graphically displaying of members of parents
* from a class.
* xxgdb does not allow the graphically displaying of data through a
* reference.
*/
#include <string.h>
#include "global.h"
#include "regex.h"
#include "datadpy.h"
#define MAXLEVELS 20 /* max level of indentation */
#ifdef GDB
#define INDENT 2 /* # of spaces for each indentation */
#else
#define INDENT 8 /* # of spaces for each indentation */
#endif /* GDB */
#define EMPTY 0
#define UNUSED 1
#define USED 2
#define LEFT_MARGIN 10
#define SCROLLBAR_WIDTH 15
static DataDpyRec **dataDpyTable;
static int dataDpyTableSize = 0;
static DataDpyRec *Parent = NULL;
static DataDpyList *TopParentList = NULL;
static int font_height, font_width;
#ifdef OBSOLETE
static void DestroyDataPopup();
#else
/* CRL mod 25 4/12/91 GWC - changed label widget to command widget in popups */
static void DestroyDataCallback();
#endif
/*
* Build an array which gives the starting text position of each line.
* Very similar to the routine in source.c.
*/
static void BuildLinePos(dataDpy)
DataDpyRec *dataDpy;
{
char *p;
int line, nlines;
int max=0;
nlines = MAX(1, dataDpy->buflen/CHARS_PER_LINE);
dataDpy->linepos = (XawTextPosition *)
XtMalloc ((nlines+2) * sizeof(XawTextPosition));
p = dataDpy->buf;
line = 0;
dataDpy->linepos[line++] = 0;
dataDpy->linepos[line++] = 0;
while (*p) {
if (*p++ == '\n') {
if (line == nlines) { /* buffer full, need more memory */
dataDpy->linepos = (XawTextPosition *)XtRealloc( (void*)dataDpy->linepos,
(nlines + ADD_LINES) * sizeof(XawTextPosition));
nlines += ADD_LINES;
}
dataDpy->linepos[line] = p - dataDpy->buf;
AssignMax(max, dataDpy->linepos[line] - dataDpy->linepos[line-1]);
line++;
}
}
dataDpy->numlines = line - 2;
dataDpy->maxLineLength = max;
/* shrink to min size */
dataDpy->linepos = (XawTextPosition *) XtRealloc
((void*)dataDpy->linepos, line * sizeof(XawTextPosition));
}
/*
* Return the line number for the specified text position.
*/
static int PositionToLine(dataDpy, pos)
DataDpyRec *dataDpy;
XawTextPosition pos;
{
int line;
if (dataDpy && pos >= 0) {
for (line = 1; pos >= dataDpy->linepos[line]; line++);
return (line-1);
}
else
return (0);
}
/* ARGSUSED */
/*
* Called by double click of pointer button.
* If the selected text is a valid pointer, this routine parses the data
* output to obtain the full qualified name of the pointer, and asks
* dbx to print the value of the object the pointer is pointing to.
*/
static void SelectPointer(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
#ifndef GDB
struct re_registers regs;
char *field[MAXLEVELS];
int line, n, r, level, newlevel;
char name[LINESIZ];
#endif
XawTextPosition left, right;
char *selection, *p;
DataDpyRec *dataDpy;
int fromLine;
int i, nbytes;
char command[LINESIZ];
/* Find out which data display output does the selection belong to */
dataDpy = NULL;
for (i=0; dataDpyTable[i]; i++)
if ((Widget) w == (Widget) dataDpyTable[i]->dataDpyWindow) {
dataDpy = dataDpyTable[i];
Parent = dataDpy;
break;
}
if (!dataDpy) return;
/* Get the selection and check if it's a pointer value, 0x???? */
selection = XFetchBytes(display, &nbytes);
if (re_match(dataPattern[D_POINTER].buf, selection, strlen(selection), 0, 0)
< 0) {
Parent = NULL;
return;
}
/* Parse the output to get the fully qualified name of the pointer */
XawTextGetSelectionPos(w, &left, &right);
fromLine = PositionToLine(dataDpy, left);
p = dataDpy->buf + dataDpy->linepos[fromLine];
#ifdef GDB /* (PW) we now use a new parser which should work better,
in particular for arrays */
{
char *parse_gdb_print();
char *newcommand;
newcommand = parse_gdb_print(command, dataDpy->buf, dataDpy->buf + left );
if (*newcommand)
{
if (strchr(selection, '@'))
{
char *p = strchr(newcommand, '*');
if (p != 0)
*p = ' ';
}
PopupMode = True;
query_gdb(newcommand, PARSE_ON | ECHO_OFF | FILTER_OFF);
}
}
#else /* not GDB */
if (re_match(dataPattern[D_FIELD].buf, p, strlen(p), 0, ®s) >= 0) {
r = dataPattern[D_FIELD].reg_token[TK_POINTER];
if (strncmp(selection, p+regs.start[r], regs.end[r]-regs.start[r]))
return;
r = dataPattern[D_FIELD].reg_token[TK_INDENT];
level = regs.end[r]/INDENT;
field[level+1] = NULL;
r = dataPattern[D_FIELD].reg_token[TK_FIELD];
n = regs.end[r] - regs.start[r];
field[level] = (char *) XtMalloc ((n+1) * sizeof(char));
strncpy(field[level], p+regs.start[r], n);
field[level][n] = '\0';
for (line = fromLine-1; line > 0; line--) {
p = dataDpy->buf + dataDpy->linepos[line];
if (re_match(dataPattern[D_STRUCT].buf, p, strlen(p), 0, ®s)>=0){
r = dataPattern[D_STRUCT].reg_token[TK_INDENT];
newlevel = regs.end[r]/INDENT;
if (newlevel == level-1) {
level--;
r = dataPattern[D_STRUCT].reg_token[TK_FIELD];
n = regs.end[r] - regs.start[r];
field[level] = (char *) XtMalloc ((n+1) * sizeof(char));
strncpy(field[level], p+regs.start[r], n);
field[level][n] = '\0';
}
}
}
if (*field[0] == '*' && field[1])
sprintf(name, "(%s)", field[0]+1);
else
strcpy(name, field[0]);
for (i=1; field[i]; i++) {
strcat(name, ".");
strcat(name, field[i]);
}
sprintf(command, "print *(%s)\n", name);
PopupMode = True;
#ifdef GDB
query_gdb(command, PARSE_ON | ECHO_OFF | FILTER_OFF);
#else
query_dbx(command);
#endif /* GDB */
}
#endif /* GDB */
}
/*
* Create a data display with a label.
* The popupshell has a form widget which consists of a label and a text
* widget.
*/
static void CreateDataPopup(dataDpy, label)
DataDpyRec *dataDpy;
char *label;
{
Arg args[MAXARGS];
Cardinal n;
Dimension dataDpyHeight, dataDpyWidth;
XFontStruct *text_font;
static XtActionsRec datadpy_actions[] = {
{"SelectPointer", (XtActionProc) SelectPointer},
{NULL, NULL}
};
static String translations = "#override \n\
<Btn1Down>: SelectStart() SelectWord() SelectPointer() \n\
<Btn1Up>: SelectEnd() \n\
";
n = 0;
dataDpy->popupshell = XtCreatePopupShell("Data Popup",
transientShellWidgetClass, toplevel, args, n);
n = 0;
XtSetArg(args[n], XtNdefaultDistance, 0); n++;
dataDpy->popup = XtCreateManagedWidget("popup", formWidgetClass,
dataDpy->popupshell, args, n);
/* Create the label */
n = 0;
XtSetArg(args[n], XtNtop, (XtArgVal) XawChainTop); n++;
XtSetArg(args[n], XtNbottom, (XtArgVal) XawChainTop); n++;
XtSetArg(args[n], XtNright, (XtArgVal) XawChainRight); n++;
XtSetArg(args[n], XtNleft, (XtArgVal) XawChainLeft); n++;
XtSetArg(args[n], XtNlabel, (XtArgVal) label); n++;
XtSetArg(args[n], XtNresize, (XtArgVal) False); n++;
XtSetArg(args[n], XtNjustify, (XtArgVal) XtJustifyCenter); n++;
#ifdef OBSOLETE
dataDpy->label = XtCreateManagedWidget("label", labelWidgetClass,
dataDpy->popup, args, n);
/* GWC says it is better to use ButtonReleaseMask instead of ButtonPressMask.*/
XtAddEventHandler(dataDpy->label, (EventMask) ButtonPressMask, False,
DestroyDataPopup, dataDpy);
#else
/* CRL mod 25 4/12/91 GWC - changed label widget to command widget in
popups */
dataDpy->label = XtCreateManagedWidget("command", commandWidgetClass,
dataDpy->popup, args, n);
XtAddCallback(dataDpy->label, XtNcallback, DestroyDataCallback, dataDpy);
#endif
/* Create the text window */
n = 0;
XtSetArg(args[n], XtNfromVert, (XtArgVal) dataDpy->label); n++;
XtSetArg(args[n], XtNtop, (XtArgVal) XawChainTop); n++;
XtSetArg(args[n], XtNbottom, (XtArgVal) XawChainBottom); n++;
XtSetArg(args[n], XtNright, (XtArgVal) XawChainRight); n++;
XtSetArg(args[n], XtNleft, (XtArgVal) XawChainLeft); n++;
XtSetArg(args[n], XtNleftMargin, (XtArgVal) LEFT_MARGIN); n++;
XtSetArg(args[n], XtNuseStringInPlace, (XtArgVal) True); n++;
XtSetArg(args[n], XtNstring, (XtArgVal) dataDpy->buf); n++;
XtSetArg(args[n], XtNlength, (XtArgVal) dataDpy->buflen); n++;
XtSetArg(args[n], XtNeditType, (XtArgVal) XawtextRead); n++;
XtSetArg(args[n], XtNscrollHorizontal, XawtextScrollWhenNeeded); n++;
XtSetArg(args[n], XtNscrollVertical, XawtextScrollWhenNeeded); n++;
XtSetArg(args[n], XtNtranslations, XtParseTranslationTable(translations));
n++;
dataDpy->dataDpyWindow = XtCreateManagedWidget("dataDpyWindow",
asciiTextWidgetClass, dataDpy->popup, args, n);
XtAppAddActions(app_context, datadpy_actions, XtNumber(datadpy_actions));
/* Get the text font */
n = 0;
XtSetArg(args[n], XtNfont, &text_font); n++;
XtGetValues(dataDpy->dataDpyWindow, args, n);
/* Estimate the size of the text widget, dataDpyWindow, with the number
of lines and the maximum length of a line. Assume fixed font width.
*/
font_height = text_font->ascent + text_font->descent;
font_width = text_font->max_bounds.width;
dataDpyHeight = dataDpy->numlines * font_height + 5;
dataDpyWidth = dataDpy->maxLineLength * font_width + LEFT_MARGIN;
if (dataDpyHeight > app_resources.dataDpyMaxHeight)
dataDpyWidth += SCROLLBAR_WIDTH;
#if 1 /*(PW)17DEC90 : bug ! */
#define SCROLLBAR_HEIGHT 15
if (dataDpyWidth > app_resources.dataDpyMaxWidth)
dataDpyHeight += SCROLLBAR_HEIGHT;
#endif
AssignMin(dataDpyHeight, app_resources.dataDpyMaxHeight);
AssignMin(dataDpyWidth, app_resources.dataDpyMaxWidth);
n = 0;
XtSetArg(args[n], XtNheight, (XtArgVal) dataDpyHeight); n++;
XtSetArg(args[n], XtNwidth, (XtArgVal) dataDpyWidth); n++;
XtSetValues(dataDpy->dataDpyWindow, args, n);
n = 0;
XtSetArg(args[n], XtNwidth, (XtArgVal) dataDpyWidth); n++;
XtSetValues(dataDpy->label, args, n);
}
/*
* Instead of creating a new popupshell, this routine uses an already
* existing popupshell for data display.
* It changes the label, calculates the size of the popupshell,
* and sets the source of the text window to that of the new data.
*/
static void UpdateDataPopup(dataDpy, label)
DataDpyRec *dataDpy;
char *label;
{
Arg args[MAXARGS];
Cardinal n;
Dimension popupHeight, popupWidth, dataDpyHeight, dataDpyWidth,
labelHeight, labelBorderWidth, dataDpyBorderWidth;
/* Update the label */
n = 0;
XtSetArg(args[n], XtNlabel, (XtArgVal) label); n++;
XtSetValues(dataDpy->label, args, n);
/* Calculate the size of popupshell */
dataDpyHeight = dataDpy->numlines * font_height + 5;
dataDpyWidth = dataDpy->maxLineLength * font_width + 2*10;
#if 1 /*(PW)18DEC90 : bug ! */
if (dataDpyHeight > app_resources.dataDpyMaxHeight)
dataDpyWidth += SCROLLBAR_WIDTH;
if (dataDpyWidth > app_resources.dataDpyMaxWidth)
dataDpyHeight += SCROLLBAR_HEIGHT;
#endif
AssignMin(dataDpyHeight, app_resources.dataDpyMaxHeight);
AssignMin(dataDpyWidth, app_resources.dataDpyMaxWidth);
n = 0;
XtSetArg(args[n], XtNheight, (XtArgVal) &labelHeight); n++;
XtSetArg(args[n], XtNborderWidth, (XtArgVal) &labelBorderWidth); n++;
XtGetValues(dataDpy->label, args, n);
n = 0;
XtSetArg(args[n], XtNborderWidth, (XtArgVal) &dataDpyBorderWidth); n++;
XtGetValues(dataDpy->dataDpyWindow, args, n);
popupHeight = dataDpyHeight + labelHeight + 2*labelBorderWidth +
2*dataDpyBorderWidth;
popupWidth = dataDpyWidth;
n = 0;
XtSetArg(args[n], XtNheight, (XtArgVal) popupHeight); n++;
XtSetArg(args[n], XtNwidth, (XtArgVal) popupWidth); n++;
XtSetValues(dataDpy->popupshell, args, n);
/* Set the text source */
n = 0;
XtSetArg(args[n], XtNstring, (XtArgVal) dataDpy->buf); n++;
XtSetArg(args[n], XtNlength, (XtArgVal) dataDpy->buflen); n++;
XawTextSetSource(dataDpy->dataDpyWindow,
XtCreateWidget("textsrc", asciiSrcObjectClass,
dataDpy->dataDpyWindow, args, n),
0);
}
/*
* Append dataDpy to a DataDpyList pointed to by head.
*/
static void AppendList(head, dataDpy)
DataDpyList **head;
DataDpyRec *dataDpy;
{
DataDpyList *p, *q, *r;
p = (DataDpyList *) XtNew (DataDpyList);
p->dataDpy = dataDpy;
p->next = NULL;
q = *head;
if (!q)
*head = p;
else {
while ((r = q->next))
q = r;
q->next = p;
}
}
/*
* Removes a dataDpy from its parent's list of children.
*/
static void DeleteList(head, dataDpy)
DataDpyList **head;
DataDpyRec *dataDpy;
{
DataDpyList *p, *q;
if ((p = *head)) {
if (p->dataDpy == dataDpy)
*head = p->next;
else {
for (q = p->next; q && q->dataDpy != dataDpy;) {
p = q;
q = p->next;
}
if (q) p->next = q->next;
}
}
}
/*
* Pop down a dataDpy and all its descendants, freeing storage and
* reinitializing fields.
*/
static void pop_down(dataDpy)
DataDpyRec *dataDpy;
{
DataDpyList *p, *q;
XtPopdown(dataDpy->popupshell);
XtFree((void*)dataDpy->linepos);
XtFree(dataDpy->buf);
dataDpy->buf = NULL;
dataDpy->buflen = 0;
dataDpy->linepos = NULL;
dataDpy->state = UNUSED;
dataDpy->parent = NULL;
for (p = dataDpy->childlist; p;) {
pop_down(p->dataDpy);
q = p;
p = p->next;
XtFree((void*)q);
}
dataDpy->childlist = NULL;
}
/*
* Invoked by a ButtonPress event on the label of a data display to
* pop down itself and its descendants.
*/
/* ARGSUSED */
#ifdef OBSOLETE
static void DestroyDataPopup(w, dataDpy, event)
Widget w;
DataDpyRec *dataDpy;
XEvent *event;
#else
/* CRL mod 25 4/12/91 GWC - changed label widget to command widget */
static void DestroyDataCallback(w, dataDpy, call_data)
Widget w;
DataDpyRec *dataDpy;
caddr_t call_data;
#endif
{
if (!dataDpy->parent)
DeleteList(&TopParentList, dataDpy);
else
DeleteList(&dataDpy->parent->childlist, dataDpy);
pop_down(dataDpy);
}
/*
* Position the data display on the screen to reflect the parent-child
* relationship.
*/
static void MovePopup(dataDpy)
DataDpyRec *dataDpy;
{
Arg args[MAXARGS];
Cardinal n;
Screen *screen;
int popupHeight, popupWidth, screenHeight, screenWidth;
Position x, y;
Dimension dataDpyWidth, dataDpyHeight, dataDpyBorderWidth,
labelHeight, labelBorderWidth, width, height, borderWidth;
DataDpyList *p, *q;
Parent = NULL;
if (!dataDpy->parent)
p = TopParentList;
else
p = dataDpy->parent->childlist;
/* Look for its previous sibling */
for (q = p->next; q && q->dataDpy != dataDpy;) {
p = q;
q = q->next;
}
/* If a sibling exists, place the new popup right next to it */
if (q) {
n = 0;
XtSetArg(args[n], XtNwidth, (XtArgVal) &width); n++;
XtSetArg(args[n], XtNborderWidth, (XtArgVal) &borderWidth); n++;
XtGetValues(p->dataDpy->popupshell, args, n);
XtTranslateCoords(p->dataDpy->popupshell, 0, 0, &x, &y);
x += width;
y -= borderWidth;
}
else { /* no siblings */
/* this is the very first popup */
if (!dataDpy->parent) {
x = 0;
y = 0;
}
/* place it under its parent */
else {
n = 0;
XtSetArg(args[n], XtNheight, (XtArgVal) &height); n++;
XtGetValues(dataDpy->parent->popupshell, args, n);
XtTranslateCoords(dataDpy->parent->popupshell, 30, (Position)height,
&x, &y);
}
}
/* Make sure the popup does not go outside of the screen */
n = 0;
XtSetArg(args[n], XtNwidth, (XtArgVal) &dataDpyWidth); n++;
XtSetArg(args[n], XtNheight, (XtArgVal) &dataDpyHeight); n++;
XtSetArg(args[n], XtNborderWidth, (XtArgVal) &dataDpyBorderWidth); n++;
XtGetValues(dataDpy->dataDpyWindow, args, n);
n = 0;
XtSetArg(args[n], XtNheight, (XtArgVal) &labelHeight); n++;
XtSetArg(args[n], XtNborderWidth, (XtArgVal) &labelBorderWidth); n++;
XtGetValues(dataDpy->label, args, n);
popupHeight = dataDpyHeight + labelHeight + 2*labelBorderWidth +
2*dataDpyBorderWidth;
popupWidth = dataDpyWidth;
screen = XtScreen(toplevel);
screenHeight = XHeightOfScreen(screen);
screenWidth = XWidthOfScreen(screen);
if (x + popupWidth > screenWidth && y + popupHeight > screenHeight) {
x = screenWidth - popupWidth;
y = screenHeight - popupHeight;
}
else if (x + popupWidth > screenWidth)
x = screenWidth - popupWidth;
else if (y + popupHeight > screenHeight)
y = screenHeight - popupHeight;
n = 0;
XtSetArg(args[n], XtNx, x); n++;
XtSetArg(args[n], XtNy, y); n++;
XtSetValues(dataDpy->popupshell, args, n);
}
/*
* Handler procedure called by parse().
* The main function to popup a data display.
*/
void print_handler(output)
char *output;
{
DataDpyRec *dataDpy;
int i, j;
if (!output) return;
if (!PopupMode) return;
PopupMode = False;
XDefineCursor(display, XtWindow(toplevel), watch);
if (Parent)
XDefineCursor(display, XtWindow(Parent->dataDpyWindow), watch);
UpdateMessageWindow("Click the label to pop down the data popup",NULL);
/* Searches the table for an unused or empty slot */
/* (PW)17OCT91 : test i < dataDpyTableSize first (else segment violation)*/
for (i=0; dataDpyTable && i < dataDpyTableSize && dataDpyTable[i]
&& dataDpyTable[i]->state == USED ; i++);
if (i == dataDpyTableSize) { /* Table full */
dataDpyTableSize += ADD_SIZE;
dataDpyTable = (DataDpyRec **) XtRealloc ((void*)dataDpyTable,
dataDpyTableSize * sizeof(DataDpyRec *));
for (j=i; j<dataDpyTableSize; j++)
dataDpyTable[j] = NULL;
}
/* Empty slot found, allocate a data structure and initializes some
of the fields. */
if (dataDpyTable[i] == NULL) {
dataDpyTable[i] = (DataDpyRec *) XtMalloc (sizeof(DataDpyRec));
dataDpyTable[i]->state = EMPTY;
dataDpyTable[i]->parent = NULL;
dataDpyTable[i]->childlist = NULL;
}
dataDpy = dataDpyTable[i];
dataDpy->id = i; /* not needed */
dataDpy->buf = XtNewString(output);
dataDpy->buflen = strlen(output);
BuildLinePos(dataDpy);
if (dataDpy->state == EMPTY)
CreateDataPopup(dataDpy, Token.mesg);
else if (dataDpy->state == UNUSED)
UpdateDataPopup(dataDpy, Token.mesg);
dataDpy->state = USED; /* mark it used */
if ((dataDpy->parent = Parent))
AppendList(&Parent->childlist, dataDpy);
else
AppendList(&TopParentList, dataDpy);
MovePopup(dataDpy);
XtPopup(dataDpy->popupshell, XtGrabNone);
if (dataDpy->parent)
XUndefineCursor(display, XtWindow(dataDpy->parent->dataDpyWindow));
XUndefineCursor(display, XtWindow(toplevel));
}
#ifdef GDB
#define GOODCHARNAME(c) \
( (((c) >='a') && ((c) <= 'z')) \
|| (((c) >='A') && ((c) <= 'Z')) \
|| (((c) >='0') && ((c) <= '9')) \
|| ((c) == '_') \
|| ((c) == '$') \
)
static char *result; /* start of result buffer */
static int result_index; /* current index in result buffer */
static char *start_txt; /* pointer 1st char of output to parse */
static char *curr_txt; /* current pointer in output to parse */
/*--------------------------------------------------------------------------+
| |
| Store a character into the buffer. |
| |
| Note that characters are added to the buffer RIGHT TO LEFT ! |
| This is because we parse the output from right to left. |
| |
| If the result buffer is full, we set result to "". |
| |
+--------------------------------------------------------------------------*/
static void add_char(c)
char c;
{
if (result_index == 0) /* buffer full */
{
*result = 0;
return;
}
if ((c == '.') && (result[result_index] == '.'))
return; /* To prevent $1..name for pointers in
g++ parents */
result_index--;
*(result+result_index) = c;
}
/*--------------------------------------------------------------------------+
| |
| Store a string into the buffer. |
| |
+--------------------------------------------------------------------------*/
static void add_string(s)
char *s;
{
int nbchar;
nbchar = strlen(s);
/* copy number from last digit */
while (nbchar > 0)
add_char(*(s + (--nbchar)));
}
/*--------------------------------------------------------------------------+
| |
| Store a number into the buffer. |
| |
+--------------------------------------------------------------------------*/
static void add_num(number)
int number;
{
char tmpnum[128];
sprintf(tmpnum,"%d",number);
add_string(tmpnum);
}
/*--------------------------------------------------------------------------+
| |
| Init buffer. |
| |
| Store a NULL character (as end of string). |
| |
+--------------------------------------------------------------------------*/
static void init_result(buffer,buflen)
char *buffer;
int buflen;
{
result = buffer;
result_index = buflen;
add_char(0); /* end result by null char */
}
/*--------------------------------------------------------------------------+
| |
| Store the current variable or struct name. |
| |
| input : curr_txt points to '=' character, |
| start_txt points to beginning of the parse string. |
| |
| output : curr_txt points to character before 1st character of |
| name. |
| |
| Note : we have to test for the beginning of the parse string, |
| because add_name() is called also for adding the "$n" name |
| of the gdb output. |
| |
+--------------------------------------------------------------------------*/
static void add_name ()
{
curr_txt--; /* point before '=' */
while (*curr_txt == ' ') curr_txt--; /* skip spaces */
/* loop over name */
while ((curr_txt >= start_txt) && GOODCHARNAME(*curr_txt))
add_char(*curr_txt--);
}
/*--------------------------------------------------------------------------+
| |
| Skip all previous characters until corresponding " or ' character. |
| |
| input : curr_txt points before ' or " character |
| |
| output : curr_txt points before corresponding ' or " character. |
| |
+--------------------------------------------------------------------------*/
void search_char(c)
char c;
{
while(1)
{
while(c != *(curr_txt--));
/* make sure there is not a '\' just before */
if (*curr_txt != '\\')
return;
}
}
/*--------------------------------------------------------------------------+
| |
| Skip all previous characters until previous corresponding '{'. |
| All "{...}" sequences are skip. |
| Return the array item number (if applicable) |
| |
| input : curr_txt points to string. |
| |
| output : curr_txt points to character before '{' |
| return number of commas |
| |
+--------------------------------------------------------------------------*/
static int skip_level()
{
int nbcommas;
char c;
nbcommas = 0;
while(1)
{
switch (c = *(curr_txt--))
{
case '{' :
return nbcommas;
case ',' :
nbcommas++;
break;
case '}' :
skip_level();
break;
case '"' :
case '\'' :
search_char(c);
break;
default:
break;
}
}
}
/*--------------------------------------------------------------------------+
| |
| Function to parse an output of a gdb print from |
| a pointer (0x...) and return a command line to |
| print *(0x...) |
| |
| input : command line pointer (LINESIZ size), |
| pointer print output, |
| pointer 0x... |
| |
| output : command line (stored RIGHT justified in commandline) |
| |
| example |
| |
| start = "$1 = { (struct foo *) 0x1224}" |
| current points to 0x1224 in start, |
| |
| commandline = "print *($1)" |
| |
+--------------------------------------------------------------------------*/
char *parse_gdb_print (commandline, start, current)
char *commandline;
char *start;
char *current;
{
char *begin;
start_txt = start; /* in static variables */
curr_txt = current;
begin = strchr(start,'='); /* find '=' in "$n =" */
if (!begin)
return NULL;
init_result(commandline,LINESIZ);
add_string(")\n");
while (begin <= curr_txt)
{
switch (*curr_txt)
{
case '=':
add_name();
/* stop now if we just parsed the '=' in "$n =" */
if (curr_txt >= start_txt)
{
add_char('.');
skip_level();
}
break;
case ',':
case '{':
add_char(']');
add_num(skip_level());
add_char('[');
break;
default:
curr_txt--;
}
}
add_string("print *(");
if (debug)
fprintf(stderr,"datadpy=%s\n",result+result_index);
return result+result_index;
}
#endif /* GDB */
|