📄 xgdb.c
字号:
for (cp = buf; c = *cp++; *out++ = c) ; break; case 'f': /* current file name */ for (cp = source_window_symtab->filename; c = *cp++; *out++ = c) ; break; case 'b': /* break # we're stopped at */ bpstat = stop_bpstat; if (bpstat == 0 && (brkno = bpstat_num(&bpstat) < 0)) /* if no breakpoint, don't do cmd */ return; (void) sprintf(buf, "%d", brkno); for (cp = buf; c = *cp++; *out++ = c) ; break; } } else *out++ = c; } *out = 0; reinitialize_more_filter(); /* have to exit via readline or tty modes stay messed up */ for (cp = cmd_line; c = *cp++; ) rl_stuff_char(c); rl_stuff_char('\n'); input_avail = 1;}/* * Define and display all the buttons. */static voidaddbutton(parent, name, function, closure) Widget parent; char *name; void (*function) (); caddr_t closure;{ static XtCallbackRec Callback[] = { {NULL, (caddr_t) NULL}, {NULL, (caddr_t) NULL}, }; static Arg commandArgs[] = { {XtNlabel, (XtArgVal) NULL}, {XtNcallback, (XtArgVal) Callback}, }; Widget w; char wname[128]; register char *cp; strcpy(wname, name); while ((cp = index(wname, '*')) || (cp = index(wname, '.'))) *cp -= 0x10; if (w = XtNameToWidget(parent, wname)) XtDestroyWidget(w); Callback[0].callback = (XtCallbackProc) function; Callback[0].closure = (caddr_t) closure; commandArgs[0].value = (XtArgVal) name; XtCreateManagedWidget(wname, commandWidgetClass, parent, commandArgs, XtNumber(commandArgs));}/* * Create the button windows and store them in `buttons'. */static voidcreate_buttons(parent) Widget parent;{ addbutton(parent, "quit", do_command, "quit");}static voidbutton_command(arg) char *arg;{ char *label; unsigned int len; if (! arg) error_no_arg("button label and command"); for (len = strlen(arg); len > 0 && isspace(arg[len - 1]); --len) ; if (len == 0) error_no_arg("button label and command"); arg[len] = 0; /* make a copy of button label & command for toolkit to use */ label = malloc(len + 1); strcpy(label, arg); /* find the end of the label */ if (*label == '"') { if ((arg = index(++label, '"')) == 0) { printf("button label missing closing quote\n"); return; } *arg++ = 0; } else if (arg = index(label, ' ')) *arg++ = 0; else arg = label; while (*arg && isspace(*arg)) ++arg; addbutton(button_box_widget, label, do_command, arg);}static voidbutton_delete_command(arg) char *arg;{ unsigned int len; Widget w; register char *cp; if (! arg) error_no_arg("button name"); for (len = strlen(arg); len > 0 && isspace(arg[len - 1]); --len) ; if (len == 0) error_no_arg("button name"); arg[len] = 0; /* find the end of the label */ if (*arg == '"') { if ((cp = index(++arg, '"')) == 0) { printf("button label missing closing quote\n"); return; } *cp++ = 0; } while ((cp = index(arg, '*')) || (cp = index(arg, '.'))) *cp -= 0x10; if (w = XtNameToWidget(button_box_widget, arg)) XtDestroyWidget(w);}/* * Create a "label window" that just displays the string LABEL. */static Widgetcreate_label(name, label) char *name, *label;{ Arg args[1]; Widget w; XtSetArg(args[0], XtNlabel, label); w = XtCreateManagedWidget(name, labelWidgetClass, containing_widget, args, XtNumber(args)); return (w);}static voidxgdb_insert_char(w, e, s, c) Widget w; XEvent* e; String* s; Cardinal* c;{ register int len, i; char buf[1024]; register char* cp = buf; KeySym keysym; len = XLookupString(&e->xkey, cp, sizeof(buf), &keysym, 0); if (len <= 0) return; for (i = 0; i < len; ++i) rl_stuff_char(cp[i]); input_avail = 1;}static voidxgdb_receive_selection(w, dat, sel, seltype, val, len, fmt) Widget w; XtPointer dat; Atom *sel, *seltype; XtPointer val; unsigned long *len; int *fmt;{ register int l = *len; register char *cp; if (*seltype == 0 || l == 0) { int nbytes; char *line = XFetchBuffer(XtDisplay(w), &nbytes, 0); if ((l = nbytes) <= 0) return; val = line; } else cp = (char *)val; while (--l >= 0) rl_stuff_char(*cp++); input_avail = 1; XFree(val);}static voidxgdb_insert_selection(w, e, s, c) Widget w; XEvent* e; String* s; Cardinal* c;{ XtGetSelectionValue(w, XA_PRIMARY, XA_STRING, xgdb_receive_selection, 0, e->xbutton.time);}static voidxgdb_insert_string(w, e, s, c) Widget w; XEvent* e; String* s; Cardinal* c;{ register int n = *c; register char *cp; while (--n >= 0) for (cp = *s++; cp && *cp; ++cp) rl_stuff_char(*cp); input_avail = 1;}static voidxgdb_newline(w, e, s, c) Widget w; XEvent* e; String* s; Cardinal* c;{ rl_stuff_char('\n'); input_avail = 1;}static XtActionsRec textact[] = { {"xgdb-insert-char", xgdb_insert_char}, {"xgdb-insert-selection", xgdb_insert_selection}, {"xgdb-insert-string", xgdb_insert_string}, {"xgdb-newline", xgdb_newline},};static char *texttr = "\Ctrl<Key>L: redraw-display() \n\Ctrl<Key>R: search(backward) \n\Ctrl<Key>S: search(forward) \n\Ctrl<Key>V: next-page() \n\Meta<Key>V: previous-page() \n\Ctrl<Key>Z: scroll-one-line-up() \n\Meta<Key>Z: scroll-one-line-down() \n\:Meta<Key>\\<: beginning-of-file() \n\:Meta<Key>\\>: end-of-file() \n\<Key>Up: previous-line() \n\<Key>Down: next-line() \n\<Key>Left: backward-character() \n\<Key>Right: forward-character() \n\<Key>: xgdb-insert-char() \n\<FocusIn>: focus-in() \n\<FocusOut>: focus-out() \n\<Btn1Down>: select-start() \n\<Btn1Motion>: extend-adjust() \n\<Btn1Up>: extend-end() \n\<Btn2Down>: xgdb-insert-selection() \n\<Btn3Down>: extend-start() \n\<Btn3Motion>: extend-adjust() \n\<Btn3Up>: extend-end() \";/* * Create a subwindow of PARENT that displays and scrolls the contents of * file FILENAME. */static Widgetcreate_text_widget(parent, filename) Widget parent; char *filename;{ static Arg arg[] = { {XtNstring, 0}, {XtNtype, XawAsciiFile}, {XtNcursor, None}, {XtNtranslations, 0}, }; Widget text_widget; arg[0].value = (XtArgVal)filename; arg[3].value = (XtArgVal)XtParseTranslationTable(texttr); text_widget = XtCreateManagedWidget("src", asciiTextWidgetClass, parent, arg, XtNumber(arg)); return (text_widget);}/* * Entry point to create the widgets representing our display. */voidxgdb_create_window(){ /* initialize toolkit, setup defaults */ char *dummy_argv[] = { "xgdb", 0 }; int dummy_argc = 1; main_widget = XtAppInitialize(&app_context, "Xgdb", NULL, 0, &dummy_argc, dummy_argv, NULL, NULL, 0); XtAppAddActions(app_context, textact, XtNumber(textact)); display = XtDisplay(main_widget); containing_widget = XtCreateManagedWidget("frame", panedWidgetClass, main_widget, NULL, 0); sprintf(version_label, "XGDB %s", version); button_box_widget = XtCreateManagedWidget("buttons", boxWidgetClass, containing_widget, NULL, 0); create_buttons(button_box_widget); source_name_widget = create_label("srcLabel", "No source file yet."); source_text_widget = create_text_widget(containing_widget, "/dev/null"); XtRealizeWidget(main_widget); XFlush(display);}/* * If we use an X window, the readline input loop is told to call * this function before reading a character from stdin. *//*ARGSUSED*/static voidxgdb_window_hook(){ register int inmask = 1 << fileno(stdin); register int xmask = 1 << ConnectionNumber(display); register int nfds, pend; int input_rfds; XEvent ev; /* * Display our current idea of the `interesting' source file then * loop, dispatching window events until data is available on * stdin. Then return so the input data can be processed. */ input_avail = 0; xgdb_display_source(); input_rfds = 0; while (input_avail == 0 && (input_rfds & inmask) == 0) { pend = XPending(display); if (!pend) { input_rfds = inmask | xmask; nfds = select(32, &input_rfds, 0, 0, (struct timeval *)0); if (nfds == -1 && errno == EINTR) continue; } if (pend || (input_rfds & xmask)) { XNextEvent(display, &ev); XtDispatchEvent(&ev); } }}void_initialize_xgdb(){ extern void (*window_hook) (); extern int inhibit_windows; extern struct cmd_list_element *deletelist; if (inhibit_windows) return; if (! displayname) { displayname = getenv("DISPLAY"); if (! displayname) { fprintf(stderr, "xgdb: no display name\n"); inhibit_windows = 1; return; } } xgdb_create_window(); window_hook = xgdb_window_hook; add_com("button", class_support, button_command,"Add command button to xgdb window. First argument is button\n\label, second is command associated with button. Command can\n\include printf-like escapes:\n\ %s for current selection,\n\ %S for first 'word' of current selection,\n\ %e for current selection or expression at insertion pt,\n\ %E for current selection or expression at insertion pt,\n\ %l for current line number,\n\ %L for line program stopped at,\n\ %f for current file name,\n\ %b for current breakpoint number."); add_cmd("button", class_support, button_delete_command,"Delete a button from the xgdb window.\n\Argument is name of button to be deleted.", &deletelist);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -