1 /* Tcl/Tk interface routines.
2 Copyright 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
4 Written by Stu Grossman <grossman@cygnus.com> of Cygnus Support.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #include "tracepoint.h"
44 /* start-sanitize-ide */
48 /* end-sanitize-ide */
51 #ifdef ANSI_PROTOTYPES
61 #include <sys/ioctl.h>
62 #include "gdb_string.h"
69 #include <sys/stropts.h>
78 #define GDBTK_PATH_SEP ";"
80 #define GDBTK_PATH_SEP ":"
83 /* Some versions (1.3.79, 1.3.81) of Linux don't support SIOCSPGRP the way
84 gdbtk wants to use it... */
89 int gdbtk_load_hash
PARAMS ((char *, unsigned long));
90 int (*ui_load_progress_hook
) PARAMS ((char *, unsigned long));
92 static void null_routine
PARAMS ((int));
93 static void gdbtk_flush
PARAMS ((FILE *));
94 static void gdbtk_fputs
PARAMS ((const char *, FILE *));
95 static int gdbtk_query
PARAMS ((const char *, va_list));
96 static char *gdbtk_readline
PARAMS ((char *));
97 static void gdbtk_init
PARAMS ((char *));
98 static void tk_command_loop
PARAMS ((void));
99 static void gdbtk_call_command
PARAMS ((struct cmd_list_element
*, char *, int));
100 static int gdbtk_wait
PARAMS ((int, struct target_waitstatus
*));
101 static void x_event
PARAMS ((int));
102 static void gdbtk_interactive
PARAMS ((void));
103 static void cleanup_init
PARAMS ((int));
104 static void tk_command
PARAMS ((char *, int));
105 static int gdb_disassemble
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
106 static int compare_lines
PARAMS ((const PTR
, const PTR
));
107 static int gdbtk_dis_asm_read_memory
PARAMS ((bfd_vma
, bfd_byte
*, int, disassemble_info
*));
108 static int gdb_path_conv
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
109 static int gdb_stop
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
110 static int gdb_confirm_quit
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
111 static int gdb_force_quit
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
112 static int gdb_listfiles
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
113 static int gdb_listfuncs
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
114 static int call_wrapper
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
115 static int gdb_cmd
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
116 static int gdb_fetch_registers
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
117 static void gdbtk_readline_end
PARAMS ((void));
118 static int gdb_changed_register_list
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
119 static void register_changed_p
PARAMS ((int, void *));
120 static int gdb_get_breakpoint_list
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
121 static int gdb_get_breakpoint_info
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
122 static void breakpoint_notify
PARAMS ((struct breakpoint
*, const char *));
123 static void gdbtk_create_breakpoint
PARAMS ((struct breakpoint
*));
124 static void gdbtk_delete_breakpoint
PARAMS ((struct breakpoint
*));
125 static void gdbtk_modify_breakpoint
PARAMS ((struct breakpoint
*));
126 static int gdb_loc
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
127 static int gdb_eval
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
128 static int gdb_sourcelines
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
129 static int map_arg_registers
PARAMS ((int, char *[], void (*) (int, void *), void *));
130 static void get_register_name
PARAMS ((int, void *));
131 static int gdb_regnames
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
132 static void get_register
PARAMS ((int, void *));
133 static int gdb_target_has_execution_command
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
134 static int gdb_load_info
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
135 static int gdb_get_vars_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
136 static int gdb_get_function_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
137 static int gdb_get_line_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
138 static int gdb_get_file_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
139 static int gdb_tracepoint_exists_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
140 static int gdb_get_tracepoint_info
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
141 static int gdb_actions_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
142 static int gdb_prompt_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
143 static int gdb_find_file_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
144 static int gdb_get_tracepoint_list
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
145 static void gdbtk_create_tracepoint
PARAMS ((struct tracepoint
*));
146 static void gdbtk_delete_tracepoint
PARAMS ((struct tracepoint
*));
147 static void tracepoint_notify
PARAMS ((struct tracepoint
*, const char *));
149 /* Handle for TCL interpreter */
151 static Tcl_Interp
*interp
= NULL
;
154 static int x_fd
; /* X network socket */
157 /* This variable is true when the inferior is running. Although it's
158 possible to disable most input from widgets and thus prevent
159 attempts to do anything while the inferior is running, any commands
160 that get through - even a simple memory read - are Very Bad, and
161 may cause GDB to crash or behave strangely. So, this variable
162 provides an extra layer of defense. */
164 static int running_now
;
166 /* This variable determines where memory used for disassembly is read from.
167 If > 0, then disassembly comes from the exec file rather than the
168 target (which might be at the other end of a slow serial link). If
169 == 0 then disassembly comes from target. If < 0 disassembly is
170 automatically switched to the target if it's an inferior process,
171 otherwise the exec file is used. */
173 static int disassemble_from_exec
= -1;
177 /* Supply malloc calls for tcl/tk. We do not want to do this on
178 Windows, because Tcl_Alloc is probably in a DLL which will not call
179 the mmalloc routines. */
185 return xmalloc (size
);
189 Tcl_Realloc (ptr
, size
)
193 return xrealloc (ptr
, size
);
203 #endif /* ! _WIN32 */
213 /* On Windows, if we hold a file open, other programs can't write to
214 it. In particular, we don't want to hold the executable open,
215 because it will mean that people have to get out of the debugging
216 session in order to remake their program. So we close it, although
217 this will cost us if and when we need to reopen it. */
227 bfd_cache_close (o
->obfd
);
230 if (exec_bfd
!= NULL
)
231 bfd_cache_close (exec_bfd
);
236 /* The following routines deal with stdout/stderr data, which is created by
237 {f}printf_{un}filtered and friends. gdbtk_fputs and gdbtk_flush are the
238 lowest level of these routines and capture all output from the rest of GDB.
239 Normally they present their data to tcl via callbacks to the following tcl
240 routines: gdbtk_tcl_fputs, gdbtk_tcl_fputs_error, and gdbtk_flush. These
241 in turn call tk routines to update the display.
243 Under some circumstances, you may want to collect the output so that it can
244 be returned as the value of a tcl procedure. This can be done by
245 surrounding the output routines with calls to start_saving_output and
246 finish_saving_output. The saved data can then be retrieved with
247 get_saved_output (but this must be done before the call to
248 finish_saving_output). */
250 /* Dynamic string for output. */
252 static Tcl_DString
*result_ptr
;
254 /* Dynamic string for stderr. This is only used if result_ptr is
257 static Tcl_DString
*error_string_ptr
;
264 /* Force immediate screen update */
266 Tcl_VarEval (interp
, "gdbtk_tcl_flush", NULL
);
271 gdbtk_fputs (ptr
, stream
)
276 Tcl_DStringAppend (result_ptr
, (char *) ptr
, -1);
277 else if (error_string_ptr
!= NULL
&& stream
== gdb_stderr
)
278 Tcl_DStringAppend (error_string_ptr
, (char *) ptr
, -1);
283 Tcl_DStringInit (&str
);
285 Tcl_DStringAppend (&str
, "gdbtk_tcl_fputs", -1);
286 Tcl_DStringAppendElement (&str
, (char *)ptr
);
288 Tcl_Eval (interp
, Tcl_DStringValue (&str
));
289 Tcl_DStringFree (&str
);
294 gdbtk_query (query
, args
)
298 char buf
[200], *merge
[2];
302 vsprintf (buf
, query
, args
);
303 merge
[0] = "gdbtk_tcl_query";
305 command
= Tcl_Merge (2, merge
);
306 Tcl_Eval (interp
, command
);
309 val
= atol (interp
->result
);
315 #ifdef ANSI_PROTOTYPES
316 gdbtk_readline_begin (char *format
, ...)
318 gdbtk_readline_begin (va_alist
)
323 char buf
[200], *merge
[2];
326 #ifdef ANSI_PROTOTYPES
327 va_start (args
, format
);
331 format
= va_arg (args
, char *);
334 vsprintf (buf
, format
, args
);
335 merge
[0] = "gdbtk_tcl_readline_begin";
337 command
= Tcl_Merge (2, merge
);
338 Tcl_Eval (interp
, command
);
343 gdbtk_readline (prompt
)
354 merge
[0] = "gdbtk_tcl_readline";
356 command
= Tcl_Merge (2, merge
);
357 result
= Tcl_Eval (interp
, command
);
359 if (result
== TCL_OK
)
361 return (strdup (interp
-> result
));
365 gdbtk_fputs (interp
-> result
, gdb_stdout
);
366 gdbtk_fputs ("\n", gdb_stdout
);
372 gdbtk_readline_end ()
374 Tcl_Eval (interp
, "gdbtk_tcl_readline_end");
379 #ifdef ANSI_PROTOTYPES
380 dsprintf_append_element (Tcl_DString
*dsp
, char *format
, ...)
382 dsprintf_append_element (va_alist
)
389 #ifdef ANSI_PROTOTYPES
390 va_start (args
, format
);
396 dsp
= va_arg (args
, Tcl_DString
*);
397 format
= va_arg (args
, char *);
400 vsprintf (buf
, format
, args
);
402 Tcl_DStringAppendElement (dsp
, buf
);
406 gdb_path_conv (clientData
, interp
, argc
, argv
)
407 ClientData clientData
;
413 char pathname
[256], *ptr
;
415 error ("wrong # args");
416 cygwin32_conv_to_full_win32_path (argv
[1], pathname
);
417 for (ptr
= pathname
; *ptr
; ptr
++)
423 char *pathname
= argv
[1];
425 Tcl_DStringAppend (result_ptr
, pathname
, strlen(pathname
));
430 gdb_get_breakpoint_list (clientData
, interp
, argc
, argv
)
431 ClientData clientData
;
436 struct breakpoint
*b
;
437 extern struct breakpoint
*breakpoint_chain
;
440 error ("wrong # args");
442 for (b
= breakpoint_chain
; b
; b
= b
->next
)
443 if (b
->type
== bp_breakpoint
)
444 dsprintf_append_element (result_ptr
, "%d", b
->number
);
450 gdb_get_breakpoint_info (clientData
, interp
, argc
, argv
)
451 ClientData clientData
;
456 struct symtab_and_line sal
;
457 static char *bptypes
[] = {"breakpoint", "hardware breakpoint", "until",
458 "finish", "watchpoint", "hardware watchpoint",
459 "read watchpoint", "access watchpoint",
460 "longjmp", "longjmp resume", "step resume",
461 "through sigtramp", "watchpoint scope",
463 static char *bpdisp
[] = {"delete", "delstop", "disable", "donttouch"};
464 struct command_line
*cmd
;
466 struct breakpoint
*b
;
467 extern struct breakpoint
*breakpoint_chain
;
468 char *funcname
, *filename
;
471 error ("wrong # args");
473 bpnum
= atoi (argv
[1]);
475 for (b
= breakpoint_chain
; b
; b
= b
->next
)
476 if (b
->number
== bpnum
)
479 if (!b
|| b
->type
!= bp_breakpoint
)
480 error ("Breakpoint #%d does not exist", bpnum
);
482 sal
= find_pc_line (b
->address
, 0);
484 filename
= symtab_to_filename (sal
.symtab
);
485 if (filename
== NULL
)
487 Tcl_DStringAppendElement (result_ptr
, filename
);
488 find_pc_partial_function (b
->address
, &funcname
, NULL
, NULL
);
489 Tcl_DStringAppendElement (result_ptr
, funcname
);
490 dsprintf_append_element (result_ptr
, "%d", sal
.line
);
491 dsprintf_append_element (result_ptr
, "0x%lx", b
->address
);
492 Tcl_DStringAppendElement (result_ptr
, bptypes
[b
->type
]);
493 Tcl_DStringAppendElement (result_ptr
, b
->enable
== enabled
? "1" : "0");
494 Tcl_DStringAppendElement (result_ptr
, bpdisp
[b
->disposition
]);
495 dsprintf_append_element (result_ptr
, "%d", b
->ignore_count
);
497 Tcl_DStringStartSublist (result_ptr
);
498 for (cmd
= b
->commands
; cmd
; cmd
= cmd
->next
)
499 Tcl_DStringAppendElement (result_ptr
, cmd
->line
);
500 Tcl_DStringEndSublist (result_ptr
);
502 Tcl_DStringAppendElement (result_ptr
, b
->cond_string
);
504 dsprintf_append_element (result_ptr
, "%d", b
->thread
);
505 dsprintf_append_element (result_ptr
, "%d", b
->hit_count
);
511 breakpoint_notify(b
, action
)
512 struct breakpoint
*b
;
517 struct symtab_and_line sal
;
520 if (b
->type
!= bp_breakpoint
)
523 /* We ensure that ACTION contains no special Tcl characters, so we
525 sal
= find_pc_line (b
->address
, 0);
526 filename
= symtab_to_filename (sal
.symtab
);
527 if (filename
== NULL
)
529 sprintf (buf
, "gdbtk_tcl_breakpoint %s %d 0x%lx %d {%s}", action
, b
->number
,
530 (long)b
->address
, sal
.line
, filename
);
532 v
= Tcl_Eval (interp
, buf
);
536 gdbtk_fputs (interp
->result
, gdb_stdout
);
537 gdbtk_fputs ("\n", gdb_stdout
);
542 gdbtk_create_breakpoint(b
)
543 struct breakpoint
*b
;
545 breakpoint_notify (b
, "create");
549 gdbtk_delete_breakpoint(b
)
550 struct breakpoint
*b
;
552 breakpoint_notify (b
, "delete");
556 gdbtk_modify_breakpoint(b
)
557 struct breakpoint
*b
;
559 breakpoint_notify (b
, "modify");
562 /* This implements the TCL command `gdb_loc', which returns a list consisting
563 of the source and line number associated with the current pc. */
566 gdb_loc (clientData
, interp
, argc
, argv
)
567 ClientData clientData
;
573 struct symtab_and_line sal
;
577 if (!have_full_symbols () && !have_partial_symbols ())
579 Tcl_SetResult (interp
, "No symbol table is loaded", TCL_STATIC
);
585 pc
= selected_frame
? selected_frame
->pc
: stop_pc
;
586 sal
= find_pc_line (pc
, 0);
590 struct symtabs_and_lines sals
;
593 sals
= decode_line_spec (argv
[1], 1);
600 error ("Ambiguous line spec");
605 error ("wrong # args");
608 Tcl_DStringAppendElement (result_ptr
, sal
.symtab
->filename
);
610 Tcl_DStringAppendElement (result_ptr
, "");
612 find_pc_partial_function (pc
, &funcname
, NULL
, NULL
);
613 Tcl_DStringAppendElement (result_ptr
, funcname
);
615 filename
= symtab_to_filename (sal
.symtab
);
616 if (filename
== NULL
)
618 Tcl_DStringAppendElement (result_ptr
, filename
);
620 dsprintf_append_element (result_ptr
, "%d", sal
.line
); /* line number */
622 dsprintf_append_element (result_ptr
, "0x%s", paddr_nz(pc
)); /* PC in current frame */
624 dsprintf_append_element (result_ptr
, "0x%s", paddr_nz(stop_pc
)); /* Real PC */
629 /* This implements the TCL command `gdb_eval'. */
632 gdb_eval (clientData
, interp
, argc
, argv
)
633 ClientData clientData
;
638 struct expression
*expr
;
639 struct cleanup
*old_chain
;
643 error ("wrong # args");
645 expr
= parse_expression (argv
[1]);
647 old_chain
= make_cleanup (free_current_contents
, &expr
);
649 val
= evaluate_expression (expr
);
651 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
652 gdb_stdout
, 0, 0, 0, 0);
654 do_cleanups (old_chain
);
659 /* gdb_get_mem addr form size num aschar*/
660 /* dump a block of memory */
661 /* addr: address of data to dump */
662 /* form: a char indicating format */
663 /* size: size of each element; 1,2,4, or 8 bytes*/
664 /* num: the number of 'size' elements to return */
665 /* acshar: an optional ascii character to use in ASCII dump */
666 /* returns a list of 'num' elements followed by an optional */
669 gdb_get_mem (clientData
, interp
, argc
, argv
)
670 ClientData clientData
;
675 int size
, asize
, num
, i
, j
;
676 CORE_ADDR addr
, saved_addr
, ptr
;
678 struct type
*val_type
;
680 char c
, buff
[128], aschar
;
683 error ("wrong # args");
685 addr
= (CORE_ADDR
)strtoul(argv
[1],(char **)NULL
,0);
688 size
= (int)strtoul(argv
[3],(char **)NULL
,0);
689 num
= (int)strtoul(argv
[4],(char **)NULL
,0);
694 val_type
= builtin_type_char
;
698 val_type
= builtin_type_short
;
702 val_type
= builtin_type_int
;
706 val_type
= builtin_type_long_long
;
710 val_type
= builtin_type_char
;
714 for (i
=0; i
< num
; i
++)
716 vptr
= value_at (val_type
, addr
, (asection
*)NULL
);
717 print_scalar_formatted (VALUE_CONTENTS(vptr
), val_type
, format
, asize
, gdb_stdout
);
718 fputs_unfiltered (" ", gdb_stdout
);
724 val_type
= builtin_type_char
;
728 for (j
=0; j
< num
*size
; j
++)
730 c
= *(char *)VALUE_CONTENTS(value_at (val_type
, ptr
, (asection
*)NULL
));
731 if (c
< 32 || c
> 126)
740 fputs_unfiltered (buff
, gdb_stdout
);
747 /* This implements the TCL command `gdb_sourcelines', which returns a list of
748 all of the lines containing executable code for the specified source file
749 (ie: lines where you can put breakpoints). */
752 gdb_sourcelines (clientData
, interp
, argc
, argv
)
753 ClientData clientData
;
758 struct symtab
*symtab
;
759 struct linetable_entry
*le
;
763 error ("wrong # args");
765 symtab
= lookup_symtab (argv
[1]);
768 error ("No such file");
770 /* If there's no linetable, or no entries, then we are done. */
772 if (!symtab
->linetable
773 || symtab
->linetable
->nitems
== 0)
775 Tcl_DStringAppendElement (result_ptr
, "");
779 le
= symtab
->linetable
->item
;
780 nlines
= symtab
->linetable
->nitems
;
782 for (;nlines
> 0; nlines
--, le
++)
784 /* If the pc of this line is the same as the pc of the next line, then
787 && le
->pc
== (le
+ 1)->pc
)
790 dsprintf_append_element (result_ptr
, "%d", le
->line
);
797 map_arg_registers (argc
, argv
, func
, argp
)
800 void (*func
) PARAMS ((int regnum
, void *argp
));
805 /* Note that the test for a valid register must include checking the
806 reg_names array because NUM_REGS may be allocated for the union of the
807 register sets within a family of related processors. In this case, the
808 trailing entries of reg_names will change depending upon the particular
809 processor being debugged. */
811 if (argc
== 0) /* No args, just do all the regs */
815 && reg_names
[regnum
] != NULL
816 && *reg_names
[regnum
] != '\000';
823 /* Else, list of register #s, just do listed regs */
824 for (; argc
> 0; argc
--, argv
++)
826 regnum
= atoi (*argv
);
830 && reg_names
[regnum
] != NULL
831 && *reg_names
[regnum
] != '\000')
834 error ("bad register number");
841 get_register_name (regnum
, argp
)
843 void *argp
; /* Ignored */
845 Tcl_DStringAppendElement (result_ptr
, reg_names
[regnum
]);
848 /* This implements the TCL command `gdb_regnames', which returns a list of
849 all of the register names. */
852 gdb_regnames (clientData
, interp
, argc
, argv
)
853 ClientData clientData
;
861 return map_arg_registers (argc
, argv
, get_register_name
, NULL
);
864 #ifndef REGISTER_CONVERTIBLE
865 #define REGISTER_CONVERTIBLE(x) (0 != 0)
868 #ifndef REGISTER_CONVERT_TO_VIRTUAL
869 #define REGISTER_CONVERT_TO_VIRTUAL(x, y, z, a)
872 #ifndef INVALID_FLOAT
873 #define INVALID_FLOAT(x, y) (0 != 0)
877 get_register (regnum
, fp
)
881 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
882 char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
883 int format
= (int)fp
;
885 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
887 Tcl_DStringAppendElement (result_ptr
, "Optimized out");
891 /* Convert raw data to virtual format if necessary. */
893 if (REGISTER_CONVERTIBLE (regnum
))
895 REGISTER_CONVERT_TO_VIRTUAL (regnum
, REGISTER_VIRTUAL_TYPE (regnum
),
896 raw_buffer
, virtual_buffer
);
899 memcpy (virtual_buffer
, raw_buffer
, REGISTER_VIRTUAL_SIZE (regnum
));
904 printf_filtered ("0x");
905 for (j
= 0; j
< REGISTER_RAW_SIZE (regnum
); j
++)
907 register int idx
= TARGET_BYTE_ORDER
== BIG_ENDIAN
? j
908 : REGISTER_RAW_SIZE (regnum
) - 1 - j
;
909 printf_filtered ("%02x", (unsigned char)raw_buffer
[idx
]);
913 val_print (REGISTER_VIRTUAL_TYPE (regnum
), virtual_buffer
, 0,
914 gdb_stdout
, format
, 1, 0, Val_pretty_default
);
916 Tcl_DStringAppend (result_ptr
, " ", -1);
920 gdb_fetch_registers (clientData
, interp
, argc
, argv
)
921 ClientData clientData
;
929 error ("wrong # args");
937 return map_arg_registers (argc
, argv
, get_register
, (void *) format
);
940 /* This contains the previous values of the registers, since the last call to
941 gdb_changed_register_list. */
943 static char old_regs
[REGISTER_BYTES
];
946 register_changed_p (regnum
, argp
)
948 void *argp
; /* Ignored */
950 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
952 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
955 if (memcmp (&old_regs
[REGISTER_BYTE (regnum
)], raw_buffer
,
956 REGISTER_RAW_SIZE (regnum
)) == 0)
959 /* Found a changed register. Save new value and return its number. */
961 memcpy (&old_regs
[REGISTER_BYTE (regnum
)], raw_buffer
,
962 REGISTER_RAW_SIZE (regnum
));
964 dsprintf_append_element (result_ptr
, "%d", regnum
);
968 gdb_changed_register_list (clientData
, interp
, argc
, argv
)
969 ClientData clientData
;
977 return map_arg_registers (argc
, argv
, register_changed_p
, NULL
);
980 /* This implements the TCL command `gdb_cmd', which sends its argument into
981 the GDB command scanner. */
984 gdb_cmd (clientData
, interp
, argc
, argv
)
985 ClientData clientData
;
990 Tcl_DString
*save_ptr
= NULL
;
993 error ("wrong # args");
998 /* for the load instruction (and possibly others later) we
999 set result_ptr to NULL so gdbtk_fputs() will not buffer
1000 all the data until the command is finished. */
1002 if (strncmp ("load ", argv
[1], 5) == 0
1003 || strncmp ("while ", argv
[1], 6) == 0)
1005 Tcl_DStringAppend (result_ptr
, "", -1);
1006 save_ptr
= result_ptr
;
1010 execute_command (argv
[1], 1);
1012 bpstat_do_actions (&stop_bpstat
);
1015 result_ptr
= save_ptr
;
1020 /* Client of call_wrapper - this routine performs the actual call to
1021 the client function. */
1023 struct wrapped_call_args
1034 struct wrapped_call_args
*args
;
1036 args
->val
= (*args
->func
) (args
->func
, args
->interp
, args
->argc
, args
->argv
);
1040 /* This routine acts as a top-level for all GDB code called by tcl/Tk. It
1041 handles cleanups, and calls to return_to_top_level (usually via error).
1042 This is necessary in order to prevent a longjmp out of the bowels of Tk,
1043 possibly leaving things in a bad state. Since this routine can be called
1044 recursively, it needs to save and restore the contents of the jmp_buf as
1048 call_wrapper (clientData
, interp
, argc
, argv
)
1049 ClientData clientData
;
1054 struct wrapped_call_args wrapped_args
;
1055 Tcl_DString result
, *old_result_ptr
;
1056 Tcl_DString error_string
, *old_error_string_ptr
;
1058 Tcl_DStringInit (&result
);
1059 old_result_ptr
= result_ptr
;
1060 result_ptr
= &result
;
1062 Tcl_DStringInit (&error_string
);
1063 old_error_string_ptr
= error_string_ptr
;
1064 error_string_ptr
= &error_string
;
1066 wrapped_args
.func
= (Tcl_CmdProc
*)clientData
;
1067 wrapped_args
.interp
= interp
;
1068 wrapped_args
.argc
= argc
;
1069 wrapped_args
.argv
= argv
;
1070 wrapped_args
.val
= 0;
1072 if (!catch_errors (wrapped_call
, &wrapped_args
, "", RETURN_MASK_ALL
))
1074 wrapped_args
.val
= TCL_ERROR
; /* Flag an error for TCL */
1076 gdb_flush (gdb_stderr
); /* Flush error output */
1078 gdb_flush (gdb_stdout
); /* Sometimes error output comes here as well */
1080 /* In case of an error, we may need to force the GUI into idle
1081 mode because gdbtk_call_command may have bombed out while in
1082 the command routine. */
1085 Tcl_Eval (interp
, "gdbtk_tcl_idle");
1088 if (Tcl_DStringLength (&error_string
) == 0)
1090 Tcl_DStringResult (interp
, &result
);
1091 Tcl_DStringFree (&error_string
);
1093 else if (Tcl_DStringLength (&result
) == 0)
1095 Tcl_DStringResult (interp
, &error_string
);
1096 Tcl_DStringFree (&result
);
1100 Tcl_ResetResult (interp
);
1101 Tcl_AppendResult (interp
, Tcl_DStringValue (&result
),
1102 Tcl_DStringValue (&error_string
), (char *) NULL
);
1103 Tcl_DStringFree (&result
);
1104 Tcl_DStringFree (&error_string
);
1107 result_ptr
= old_result_ptr
;
1108 error_string_ptr
= old_error_string_ptr
;
1114 return wrapped_args
.val
;
1118 gdb_listfiles (clientData
, interp
, argc
, argv
)
1119 ClientData clientData
;
1124 struct objfile
*objfile
;
1125 struct partial_symtab
*psymtab
;
1126 struct symtab
*symtab
;
1128 ALL_PSYMTABS (objfile
, psymtab
)
1129 Tcl_DStringAppendElement (result_ptr
, psymtab
->filename
);
1131 ALL_SYMTABS (objfile
, symtab
)
1132 Tcl_DStringAppendElement (result_ptr
, symtab
->filename
);
1138 gdb_listfuncs (clientData
, interp
, argc
, argv
)
1139 ClientData clientData
;
1144 struct symtab
*symtab
;
1145 struct blockvector
*bv
;
1151 error ("wrong # args");
1153 symtab
= lookup_symtab (argv
[1]);
1156 error ("No such file");
1158 bv
= BLOCKVECTOR (symtab
);
1159 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
1161 b
= BLOCKVECTOR_BLOCK (bv
, i
);
1162 /* Skip the sort if this block is always sorted. */
1163 if (!BLOCK_SHOULD_SORT (b
))
1164 sort_block_syms (b
);
1165 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
1167 sym
= BLOCK_SYM (b
, j
);
1168 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1170 Tcl_DStringAppendElement (result_ptr
, SYMBOL_NAME(sym
));
1178 gdb_stop (clientData
, interp
, argc
, argv
)
1179 ClientData clientData
;
1187 quit_flag
= 1; /* hope something sees this */
1192 /* Prepare to accept a new executable file. This is called when we
1193 want to clear away everything we know about the old file, without
1194 asking the user. The Tcl code will have already asked the user if
1195 necessary. After this is called, we should be able to run the
1196 `file' command without getting any questions. */
1199 gdb_clear_file (clientData
, interp
, argc
, argv
)
1200 ClientData clientData
;
1205 if (inferior_pid
!= 0 && target_has_execution
)
1208 target_detach (NULL
, 0);
1213 if (target_has_execution
)
1216 symbol_file_command (NULL
, 0);
1221 /* Ask the user to confirm an exit request. */
1224 gdb_confirm_quit (clientData
, interp
, argc
, argv
)
1225 ClientData clientData
;
1232 ret
= quit_confirm ();
1233 Tcl_DStringAppendElement (result_ptr
, ret
? "1" : "0");
1237 /* Quit without asking for confirmation. */
1240 gdb_force_quit (clientData
, interp
, argc
, argv
)
1241 ClientData clientData
;
1246 quit_force ((char *) NULL
, 1);
1250 /* This implements the TCL command `gdb_disassemble'. */
1253 gdbtk_dis_asm_read_memory (memaddr
, myaddr
, len
, info
)
1257 disassemble_info
*info
;
1259 extern struct target_ops exec_ops
;
1263 res
= xfer_memory (memaddr
, myaddr
, len
, 0, &exec_ops
);
1274 /* We need a different sort of line table from the normal one cuz we can't
1275 depend upon implicit line-end pc's for lines. This is because of the
1276 reordering we are about to do. */
1278 struct my_line_entry
{
1285 compare_lines (mle1p
, mle2p
)
1289 struct my_line_entry
*mle1
, *mle2
;
1292 mle1
= (struct my_line_entry
*) mle1p
;
1293 mle2
= (struct my_line_entry
*) mle2p
;
1295 val
= mle1
->line
- mle2
->line
;
1300 return mle1
->start_pc
- mle2
->start_pc
;
1304 gdb_disassemble (clientData
, interp
, argc
, argv
)
1305 ClientData clientData
;
1310 CORE_ADDR pc
, low
, high
;
1311 int mixed_source_and_assembly
;
1312 static disassemble_info di
;
1313 static int di_initialized
;
1315 if (! di_initialized
)
1317 INIT_DISASSEMBLE_INFO_NO_ARCH (di
, gdb_stdout
,
1318 (fprintf_ftype
) fprintf_unfiltered
);
1319 di
.flavour
= bfd_target_unknown_flavour
;
1320 di
.memory_error_func
= dis_asm_memory_error
;
1321 di
.print_address_func
= dis_asm_print_address
;
1325 di
.mach
= tm_print_insn_info
.mach
;
1326 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1327 di
.endian
= BFD_ENDIAN_BIG
;
1329 di
.endian
= BFD_ENDIAN_LITTLE
;
1331 if (argc
!= 3 && argc
!= 4)
1332 error ("wrong # args");
1334 if (strcmp (argv
[1], "source") == 0)
1335 mixed_source_and_assembly
= 1;
1336 else if (strcmp (argv
[1], "nosource") == 0)
1337 mixed_source_and_assembly
= 0;
1339 error ("First arg must be 'source' or 'nosource'");
1341 low
= parse_and_eval_address (argv
[2]);
1345 if (find_pc_partial_function (low
, NULL
, &low
, &high
) == 0)
1346 error ("No function contains specified address");
1349 high
= parse_and_eval_address (argv
[3]);
1351 /* If disassemble_from_exec == -1, then we use the following heuristic to
1352 determine whether or not to do disassembly from target memory or from the
1355 If we're debugging a local process, read target memory, instead of the
1356 exec file. This makes disassembly of functions in shared libs work
1359 Else, we're debugging a remote process, and should disassemble from the
1360 exec file for speed. However, this is no good if the target modifies its
1361 code (for relocation, or whatever).
1364 if (disassemble_from_exec
== -1)
1365 if (strcmp (target_shortname
, "child") == 0
1366 || strcmp (target_shortname
, "procfs") == 0
1367 || strcmp (target_shortname
, "vxprocess") == 0)
1368 disassemble_from_exec
= 0; /* It's a child process, read inferior mem */
1370 disassemble_from_exec
= 1; /* It's remote, read the exec file */
1372 if (disassemble_from_exec
)
1373 di
.read_memory_func
= gdbtk_dis_asm_read_memory
;
1375 di
.read_memory_func
= dis_asm_read_memory
;
1377 /* If just doing straight assembly, all we need to do is disassemble
1378 everything between low and high. If doing mixed source/assembly, we've
1379 got a totally different path to follow. */
1381 if (mixed_source_and_assembly
)
1382 { /* Come here for mixed source/assembly */
1383 /* The idea here is to present a source-O-centric view of a function to
1384 the user. This means that things are presented in source order, with
1385 (possibly) out of order assembly immediately following. */
1386 struct symtab
*symtab
;
1387 struct linetable_entry
*le
;
1390 struct my_line_entry
*mle
;
1391 struct symtab_and_line sal
;
1396 symtab
= find_pc_symtab (low
); /* Assume symtab is valid for whole PC range */
1401 /* First, convert the linetable to a bunch of my_line_entry's. */
1403 le
= symtab
->linetable
->item
;
1404 nlines
= symtab
->linetable
->nitems
;
1409 mle
= (struct my_line_entry
*) alloca (nlines
* sizeof (struct my_line_entry
));
1413 /* Copy linetable entries for this function into our data structure, creating
1414 end_pc's and setting out_of_order as appropriate. */
1416 /* First, skip all the preceding functions. */
1418 for (i
= 0; i
< nlines
- 1 && le
[i
].pc
< low
; i
++) ;
1420 /* Now, copy all entries before the end of this function. */
1423 for (; i
< nlines
- 1 && le
[i
].pc
< high
; i
++)
1425 if (le
[i
].line
== le
[i
+ 1].line
1426 && le
[i
].pc
== le
[i
+ 1].pc
)
1427 continue; /* Ignore duplicates */
1429 mle
[newlines
].line
= le
[i
].line
;
1430 if (le
[i
].line
> le
[i
+ 1].line
)
1432 mle
[newlines
].start_pc
= le
[i
].pc
;
1433 mle
[newlines
].end_pc
= le
[i
+ 1].pc
;
1437 /* If we're on the last line, and it's part of the function, then we need to
1438 get the end pc in a special way. */
1443 mle
[newlines
].line
= le
[i
].line
;
1444 mle
[newlines
].start_pc
= le
[i
].pc
;
1445 sal
= find_pc_line (le
[i
].pc
, 0);
1446 mle
[newlines
].end_pc
= sal
.end
;
1450 /* Now, sort mle by line #s (and, then by addresses within lines). */
1453 qsort (mle
, newlines
, sizeof (struct my_line_entry
), compare_lines
);
1455 /* Now, for each line entry, emit the specified lines (unless they have been
1456 emitted before), followed by the assembly code for that line. */
1458 next_line
= 0; /* Force out first line */
1459 for (i
= 0; i
< newlines
; i
++)
1461 /* Print out everything from next_line to the current line. */
1463 if (mle
[i
].line
>= next_line
)
1466 print_source_lines (symtab
, next_line
, mle
[i
].line
+ 1, 0);
1468 print_source_lines (symtab
, mle
[i
].line
, mle
[i
].line
+ 1, 0);
1470 next_line
= mle
[i
].line
+ 1;
1473 for (pc
= mle
[i
].start_pc
; pc
< mle
[i
].end_pc
; )
1476 fputs_unfiltered (" ", gdb_stdout
);
1477 print_address (pc
, gdb_stdout
);
1478 fputs_unfiltered (":\t ", gdb_stdout
);
1479 pc
+= (*tm_print_insn
) (pc
, &di
);
1480 fputs_unfiltered ("\n", gdb_stdout
);
1487 for (pc
= low
; pc
< high
; )
1490 fputs_unfiltered (" ", gdb_stdout
);
1491 print_address (pc
, gdb_stdout
);
1492 fputs_unfiltered (":\t ", gdb_stdout
);
1493 pc
+= (*tm_print_insn
) (pc
, &di
);
1494 fputs_unfiltered ("\n", gdb_stdout
);
1498 gdb_flush (gdb_stdout
);
1504 tk_command (cmd
, from_tty
)
1510 struct cleanup
*old_chain
;
1512 /* Catch case of no argument, since this will make the tcl interpreter dump core. */
1514 error_no_arg ("tcl command to interpret");
1516 retval
= Tcl_Eval (interp
, cmd
);
1518 result
= strdup (interp
->result
);
1520 old_chain
= make_cleanup (free
, result
);
1522 if (retval
!= TCL_OK
)
1525 printf_unfiltered ("%s\n", result
);
1527 do_cleanups (old_chain
);
1531 cleanup_init (ignored
)
1535 Tcl_DeleteInterp (interp
);
1539 /* Come here during long calculations to check for GUI events. Usually invoked
1540 via the QUIT macro. */
1543 gdbtk_interactive ()
1545 /* Tk_DoOneEvent (TK_DONT_WAIT|TK_IDLE_EVENTS); */
1548 /* Come here when there is activity on the X file descriptor. */
1554 /* Process pending events */
1556 while (Tcl_DoOneEvent (TCL_DONT_WAIT
|TCL_ALL_EVENTS
) != 0);
1561 /* For Cygwin32, we use a timer to periodically check for Windows
1562 messages. FIXME: It would be better to not poll, but to instead
1563 rewrite the target_wait routines to serve as input sources.
1564 Unfortunately, that will be a lot of work. */
1567 gdbtk_start_timer ()
1569 sigset_t nullsigmask
;
1570 struct sigaction action
;
1571 struct itimerval it
;
1573 sigemptyset (&nullsigmask
);
1575 action
.sa_handler
= x_event
;
1576 action
.sa_mask
= nullsigmask
;
1577 action
.sa_flags
= 0;
1578 sigaction (SIGALRM
, &action
, NULL
);
1580 it
.it_interval
.tv_sec
= 0;
1581 /* Check for messages twice a second. */
1582 it
.it_interval
.tv_usec
= 500 * 1000;
1583 it
.it_value
.tv_sec
= 0;
1584 it
.it_value
.tv_usec
= 500 * 1000;
1586 setitimer (ITIMER_REAL
, &it
, NULL
);
1592 sigset_t nullsigmask
;
1593 struct sigaction action
;
1594 struct itimerval it
;
1596 sigemptyset (&nullsigmask
);
1598 action
.sa_handler
= SIG_IGN
;
1599 action
.sa_mask
= nullsigmask
;
1600 action
.sa_flags
= 0;
1601 sigaction (SIGALRM
, &action
, NULL
);
1603 it
.it_interval
.tv_sec
= 0;
1604 it
.it_interval
.tv_usec
= 0;
1605 it
.it_value
.tv_sec
= 0;
1606 it
.it_value
.tv_usec
= 0;
1607 setitimer (ITIMER_REAL
, &it
, NULL
);
1612 /* This hook function is called whenever we want to wait for the
1616 gdbtk_wait (pid
, ourstatus
)
1618 struct target_waitstatus
*ourstatus
;
1621 struct sigaction action
;
1622 static sigset_t nullsigmask
= {0};
1626 /* Needed for SunOS 4.1.x */
1627 #define SA_RESTART 0
1630 action
.sa_handler
= x_event
;
1631 action
.sa_mask
= nullsigmask
;
1632 action
.sa_flags
= SA_RESTART
;
1633 sigaction(SIGIO
, &action
, NULL
);
1637 gdbtk_start_timer ();
1640 pid
= target_wait (pid
, ourstatus
);
1643 gdbtk_stop_timer ();
1647 action
.sa_handler
= SIG_IGN
;
1648 sigaction(SIGIO
, &action
, NULL
);
1654 /* This is called from execute_command, and provides a wrapper around
1655 various command routines in a place where both protocol messages and
1656 user input both flow through. Mostly this is used for indicating whether
1657 the target process is running or not.
1661 gdbtk_call_command (cmdblk
, arg
, from_tty
)
1662 struct cmd_list_element
*cmdblk
;
1667 if (cmdblk
->class == class_run
|| cmdblk
->class == class_trace
)
1670 Tcl_Eval (interp
, "gdbtk_tcl_busy");
1671 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1673 Tcl_Eval (interp
, "gdbtk_tcl_idle");
1676 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1679 /* This function is called instead of gdb's internal command loop. This is the
1680 last chance to do anything before entering the main Tk event loop. */
1685 extern GDB_FILE
*instream
;
1687 /* We no longer want to use stdin as the command input stream */
1690 if (Tcl_Eval (interp
, "gdbtk_tcl_preloop") != TCL_OK
)
1694 /* Force errorInfo to be set up propertly. */
1695 Tcl_AddErrorInfo (interp
, "");
1697 msg
= Tcl_GetVar (interp
, "errorInfo", TCL_GLOBAL_ONLY
);
1699 MessageBox (NULL
, msg
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
1701 fputs_unfiltered (msg
, gdb_stderr
);
1712 /* gdbtk_init installs this function as a final cleanup. */
1715 gdbtk_cleanup (dummy
)
1721 /* Initialize gdbtk. */
1724 gdbtk_init ( argv0
)
1727 struct cleanup
*old_chain
;
1728 char *lib
, *gdbtk_lib
, *gdbtk_lib_tmp
, *gdbtk_file
;
1731 struct sigaction action
;
1732 static sigset_t nullsigmask
= {0};
1735 /* start-sanitize-ide */
1736 struct ide_event_handle
*h
;
1739 /* end-sanitize-ide */
1742 /* If there is no DISPLAY environment variable, Tk_Init below will fail,
1743 causing gdb to abort. If instead we simply return here, gdb will
1744 gracefully degrade to using the command line interface. */
1747 if (getenv ("DISPLAY") == NULL
)
1751 old_chain
= make_cleanup (cleanup_init
, 0);
1753 /* First init tcl and tk. */
1754 Tcl_FindExecutable (argv0
);
1755 interp
= Tcl_CreateInterp ();
1758 error ("Tcl_CreateInterp failed");
1760 if (Tcl_Init(interp
) != TCL_OK
)
1761 error ("Tcl_Init failed: %s", interp
->result
);
1763 make_final_cleanup (gdbtk_cleanup
, NULL
);
1765 /* Initialize the Paths variable. */
1766 if (ide_initialize_paths (interp
, "gdbtcl") != TCL_OK
)
1767 error ("ide_initialize_paths failed: %s", interp
->result
);
1770 /* start-sanitize-ide */
1771 /* Find the directory where we expect to find idemanager. We ignore
1772 errors since it doesn't really matter if this fails. */
1773 libexecdir
= Tcl_GetVar2 (interp
, "Paths", "libexecdir", TCL_GLOBAL_ONLY
);
1777 h
= ide_event_init_from_environment (&errmsg
, libexecdir
);
1780 Tcl_AppendResult (interp
, "can't initialize event system: ", errmsg
,
1782 fprintf(stderr
, "WARNING: ide_event_init_client failed: %s\n", interp
->result
);
1784 Tcl_SetVar (interp
, "GDBTK_IDE", "0", 0);
1788 if (ide_create_tclevent_command (interp
, h
) != TCL_OK
)
1789 error ("ide_create_tclevent_command failed: %s", interp
->result
);
1791 if (ide_create_edit_command (interp
, h
) != TCL_OK
)
1792 error ("ide_create_edit_command failed: %s", interp
->result
);
1794 if (ide_create_property_command (interp
, h
) != TCL_OK
)
1795 error ("ide_create_property_command failed: %s", interp
->result
);
1797 if (ide_create_build_command (interp
, h
) != TCL_OK
)
1798 error ("ide_create_build_command failed: %s", interp
->result
);
1800 if (ide_create_window_register_command (interp
, h
, "gdb-restore")
1802 error ("ide_create_window_register_command failed: %s",
1805 if (ide_create_window_command (interp
, h
) != TCL_OK
)
1806 error ("ide_create_window_command failed: %s", interp
->result
);
1808 if (ide_create_exit_command (interp
, h
) != TCL_OK
)
1809 error ("ide_create_exit_command failed: %s", interp
->result
);
1811 if (ide_create_help_command (interp
) != TCL_OK
)
1812 error ("ide_create_help_command failed: %s", interp
->result
);
1815 if (ide_initialize (interp, "gdb") != TCL_OK)
1816 error ("ide_initialize failed: %s", interp->result);
1819 Tcl_SetVar (interp
, "GDBTK_IDE", "1", 0);
1820 Tcl_SetVar (interp
, "IDE", "1", TCL_GLOBAL_ONLY
);
1822 /* end-sanitize-ide */
1824 Tcl_SetVar (interp
, "GDBTK_IDE", "0", 0);
1827 /* We don't want to open the X connection until we've done all the
1828 IDE initialization. Otherwise, goofy looking unfinished windows
1829 pop up when ILU drops into the TCL event loop. */
1831 if (Tk_Init(interp
) != TCL_OK
)
1832 error ("Tk_Init failed: %s", interp
->result
);
1834 if (Itcl_Init(interp
) == TCL_ERROR
)
1835 error ("Itcl_Init failed: %s", interp
->result
);
1837 if (Tix_Init(interp
) != TCL_OK
)
1838 error ("Tix_Init failed: %s", interp
->result
);
1841 /* On Windows, create a sizebox widget command */
1842 if (ide_create_sizebox_command (interp
) != TCL_OK
)
1843 error ("sizebox creation failed");
1844 if (ide_create_winprint_command (interp
) != TCL_OK
)
1845 error ("windows print code initialization failed");
1846 /* start-sanitize-ide */
1847 /* An interface to ShellExecute. */
1848 if (ide_create_shell_execute_command (interp
) != TCL_OK
)
1849 error ("shell execute command initialization failed");
1850 /* end-sanitize-ide */
1853 Tcl_CreateCommand (interp
, "gdb_cmd", call_wrapper
, gdb_cmd
, NULL
);
1854 Tcl_CreateCommand (interp
, "gdb_loc", call_wrapper
, gdb_loc
, NULL
);
1855 Tcl_CreateCommand (interp
, "gdb_path_conv", call_wrapper
, gdb_path_conv
, NULL
);
1856 Tcl_CreateCommand (interp
, "gdb_sourcelines", call_wrapper
, gdb_sourcelines
,
1858 Tcl_CreateCommand (interp
, "gdb_listfiles", call_wrapper
, gdb_listfiles
,
1860 Tcl_CreateCommand (interp
, "gdb_listfuncs", call_wrapper
, gdb_listfuncs
,
1862 Tcl_CreateCommand (interp
, "gdb_get_mem", call_wrapper
, gdb_get_mem
,
1864 Tcl_CreateCommand (interp
, "gdb_stop", call_wrapper
, gdb_stop
, NULL
);
1865 Tcl_CreateCommand (interp
, "gdb_regnames", call_wrapper
, gdb_regnames
, NULL
);
1866 Tcl_CreateCommand (interp
, "gdb_fetch_registers", call_wrapper
,
1867 gdb_fetch_registers
, NULL
);
1868 Tcl_CreateCommand (interp
, "gdb_changed_register_list", call_wrapper
,
1869 gdb_changed_register_list
, NULL
);
1870 Tcl_CreateCommand (interp
, "gdb_disassemble", call_wrapper
,
1871 gdb_disassemble
, NULL
);
1872 Tcl_CreateCommand (interp
, "gdb_eval", call_wrapper
, gdb_eval
, NULL
);
1873 Tcl_CreateCommand (interp
, "gdb_get_breakpoint_list", call_wrapper
,
1874 gdb_get_breakpoint_list
, NULL
);
1875 Tcl_CreateCommand (interp
, "gdb_get_breakpoint_info", call_wrapper
,
1876 gdb_get_breakpoint_info
, NULL
);
1877 Tcl_CreateCommand (interp
, "gdb_clear_file", call_wrapper
,
1878 gdb_clear_file
, NULL
);
1879 Tcl_CreateCommand (interp
, "gdb_confirm_quit", call_wrapper
,
1880 gdb_confirm_quit
, NULL
);
1881 Tcl_CreateCommand (interp
, "gdb_force_quit", call_wrapper
,
1882 gdb_force_quit
, NULL
);
1883 Tcl_CreateCommand (interp
, "gdb_target_has_execution",
1884 gdb_target_has_execution_command
,
1886 Tcl_CreateObjCommand (interp
, "gdb_load_info", gdb_load_info
, NULL
, NULL
);
1887 Tcl_CreateObjCommand (interp
, "gdb_get_locals", gdb_get_vars_command
,
1888 (ClientData
) 0, NULL
);
1889 Tcl_CreateObjCommand (interp
, "gdb_get_args", gdb_get_vars_command
,
1890 (ClientData
) 1, NULL
);
1891 Tcl_CreateObjCommand (interp
, "gdb_get_function", gdb_get_function_command
,
1893 Tcl_CreateObjCommand (interp
, "gdb_get_line", gdb_get_line_command
,
1895 Tcl_CreateObjCommand (interp
, "gdb_get_file", gdb_get_file_command
,
1897 Tcl_CreateObjCommand (interp
, "gdb_tracepoint_exists",
1898 gdb_tracepoint_exists_command
, NULL
, NULL
);
1899 Tcl_CreateObjCommand (interp
, "gdb_get_tracepoint_info",
1900 gdb_get_tracepoint_info
, NULL
, NULL
);
1901 Tcl_CreateObjCommand (interp
, "gdb_actions",
1902 gdb_actions_command
, NULL
, NULL
);
1903 Tcl_CreateObjCommand (interp
, "gdb_prompt",
1904 gdb_prompt_command
, NULL
, NULL
);
1905 Tcl_CreateObjCommand (interp
, "gdb_find_file",
1906 gdb_find_file_command
, NULL
, NULL
);
1907 Tcl_CreateObjCommand (interp
, "gdb_get_tracepoint_list",
1908 gdb_get_tracepoint_list
, NULL
, NULL
);
1910 command_loop_hook
= tk_command_loop
;
1911 print_frame_info_listing_hook
=
1912 (void (*) PARAMS ((struct symtab
*, int, int, int))) null_routine
;
1913 query_hook
= gdbtk_query
;
1914 flush_hook
= gdbtk_flush
;
1915 create_breakpoint_hook
= gdbtk_create_breakpoint
;
1916 delete_breakpoint_hook
= gdbtk_delete_breakpoint
;
1917 modify_breakpoint_hook
= gdbtk_modify_breakpoint
;
1918 interactive_hook
= gdbtk_interactive
;
1919 target_wait_hook
= gdbtk_wait
;
1920 call_command_hook
= gdbtk_call_command
;
1921 readline_begin_hook
= gdbtk_readline_begin
;
1922 readline_hook
= gdbtk_readline
;
1923 readline_end_hook
= gdbtk_readline_end
;
1924 ui_load_progress_hook
= gdbtk_load_hash
;
1925 create_tracepoint_hook
= gdbtk_create_tracepoint
;
1926 delete_tracepoint_hook
= gdbtk_delete_tracepoint
;
1929 /* Get the file descriptor for the X server */
1931 x_fd
= ConnectionNumber (Tk_Display (Tk_MainWindow (interp
)));
1933 /* Setup for I/O interrupts */
1935 action
.sa_mask
= nullsigmask
;
1936 action
.sa_flags
= 0;
1937 action
.sa_handler
= SIG_IGN
;
1938 sigaction(SIGIO
, &action
, NULL
);
1942 if (ioctl (x_fd
, FIOASYNC
, &i
))
1943 perror_with_name ("gdbtk_init: ioctl FIOASYNC failed");
1947 if (ioctl (x_fd
, SIOCSPGRP
, &i
))
1948 perror_with_name ("gdbtk_init: ioctl SIOCSPGRP failed");
1953 if (fcntl (x_fd
, F_SETOWN
, i
))
1954 perror_with_name ("gdbtk_init: fcntl F_SETOWN failed");
1955 #endif /* F_SETOWN */
1956 #endif /* !SIOCSPGRP */
1959 if (ioctl (x_fd
, I_SETSIG
, S_INPUT
|S_RDNORM
) < 0)
1960 perror_with_name ("gdbtk_init: ioctl I_SETSIG failed");
1963 #endif /* ifndef FIOASYNC */
1966 add_com ("tk", class_obscure
, tk_command
,
1967 "Send a command directly into tk.");
1969 Tcl_LinkVar (interp
, "disassemble-from-exec", (char *)&disassemble_from_exec
,
1972 /* find the gdb tcl library and source main.tcl */
1974 gdbtk_lib
= getenv ("GDBTK_LIBRARY");
1976 if (access ("gdbtcl/main.tcl", R_OK
) == 0)
1977 gdbtk_lib
= "gdbtcl";
1979 gdbtk_lib
= GDBTK_LIBRARY
;
1981 gdbtk_lib_tmp
= xstrdup (gdbtk_lib
);
1984 /* see if GDBTK_LIBRARY is a path list */
1985 lib
= strtok (gdbtk_lib_tmp
, GDBTK_PATH_SEP
);
1988 if (Tcl_VarEval (interp
, "lappend auto_path ", lib
, NULL
) != TCL_OK
)
1990 fputs_unfiltered (Tcl_GetVar (interp
, "errorInfo", 0), gdb_stderr
);
1995 gdbtk_file
= concat (lib
, "/main.tcl", (char *) NULL
);
1996 if (access (gdbtk_file
, R_OK
) == 0)
1999 Tcl_SetVar (interp
, "GDBTK_LIBRARY", lib
, 0);
2003 while ((lib
= strtok (NULL
, ":")) != NULL
);
2005 free (gdbtk_lib_tmp
);
2009 /* Try finding it with the auto path. */
2011 static const char script
[] ="\
2012 proc gdbtk_find_main {} {\n\
2013 global auto_path GDBTK_LIBRARY\n\
2014 foreach dir $auto_path {\n\
2015 set f [file join $dir main.tcl]\n\
2016 if {[file exists $f]} then {\n\
2017 set GDBTK_LIBRARY $dir\n\
2025 if (Tcl_GlobalEval (interp
, (char *) script
) != TCL_OK
)
2027 fputs_unfiltered (Tcl_GetVar (interp
, "errorInfo", 0), gdb_stderr
);
2031 if (interp
->result
[0] != '\0')
2033 gdbtk_file
= xstrdup (interp
->result
);
2040 fputs_unfiltered_hook
= NULL
; /* Force errors to stdout/stderr */
2041 if (getenv("GDBTK_LIBRARY"))
2043 fprintf_unfiltered (stderr
, "Unable to find main.tcl in %s\n",getenv("GDBTK_LIBRARY"));
2044 fprintf_unfiltered (stderr
,
2045 "Please set GDBTK_LIBRARY to a path that includes the GDB tcl files.\n");
2049 fprintf_unfiltered (stderr
, "Unable to find main.tcl in %s\n", GDBTK_LIBRARY
);
2050 fprintf_unfiltered (stderr
, "You might want to set GDBTK_LIBRARY\n");
2055 /* Defer setup of fputs_unfiltered_hook to near the end so that error messages
2056 prior to this point go to stdout/stderr. */
2058 fputs_unfiltered_hook
= gdbtk_fputs
;
2060 if (Tcl_EvalFile (interp
, gdbtk_file
) != TCL_OK
)
2064 /* Force errorInfo to be set up propertly. */
2065 Tcl_AddErrorInfo (interp
, "");
2067 msg
= Tcl_GetVar (interp
, "errorInfo", TCL_GLOBAL_ONLY
);
2069 fputs_unfiltered_hook
= NULL
; /* Force errors to stdout/stderr */
2072 MessageBox (NULL
, msg
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
2074 fputs_unfiltered (msg
, gdb_stderr
);
2081 /* start-sanitize-ide */
2082 /* Don't do this until we have initialized. Otherwise, we may get a
2083 run command before we are ready for one. */
2084 if (ide_run_server_init (interp
, h
) != TCL_OK
)
2085 error ("ide_run_server_init failed: %s", interp
->result
);
2086 /* end-sanitize-ide */
2091 discard_cleanups (old_chain
);
2095 gdb_target_has_execution_command (clientData
, interp
, argc
, argv
)
2096 ClientData clientData
;
2103 if (target_has_execution
&& inferior_pid
!= 0)
2106 Tcl_SetIntObj (Tcl_GetObjResult (interp
), result
);
2110 /* gdb_load_info - returns information about the file about to be downloaded */
2113 gdb_load_info (clientData
, interp
, objc
, objv
)
2114 ClientData clientData
;
2117 Tcl_Obj
*CONST objv
[];
2120 struct cleanup
*old_cleanups
;
2126 char *filename
= Tcl_GetStringFromObj (objv
[1], NULL
);
2128 loadfile_bfd
= bfd_openr (filename
, gnutarget
);
2129 if (loadfile_bfd
== NULL
)
2131 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("Open failed", -1));
2134 old_cleanups
= make_cleanup (bfd_close
, loadfile_bfd
);
2136 if (!bfd_check_format (loadfile_bfd
, bfd_object
))
2138 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("Bad Object File", -1));
2142 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
2144 if (s
->flags
& SEC_LOAD
)
2146 bfd_size_type size
= bfd_get_section_size_before_reloc (s
);
2149 ob
[0] = Tcl_NewStringObj((char *)bfd_get_section_name(loadfile_bfd
, s
), -1);
2150 ob
[1] = Tcl_NewLongObj ((long)size
);
2151 res
[i
++] = Tcl_NewListObj (2, ob
);
2156 Tcl_SetObjResult (interp
, Tcl_NewListObj (i
, res
));
2157 do_cleanups (old_cleanups
);
2163 gdbtk_load_hash (section
, num
)
2169 sprintf (buf
, "download_hash %s %ld", section
, num
);
2170 result
= Tcl_Eval (interp
, buf
);
2174 /* gdb_get_vars_command -
2176 * Implements the "gdb_get_locals" and "gdb_get_args" tcl commands. This
2177 * function sets the Tcl interpreter's result to a list of variable names
2178 * depending on clientData. If clientData is one, the result is a list of
2179 * arguments; zero returns a list of locals -- all relative to the block
2180 * specified as an argument to the command. Valid commands include
2181 * anything decode_line_1 can handle (like "main.c:2", "*0x02020202",
2185 gdb_get_vars_command (clientData
, interp
, objc
, objv
)
2186 ClientData clientData
;
2189 Tcl_Obj
*CONST objv
[];
2192 struct symtabs_and_lines sals
;
2194 struct block
*block
;
2195 char **canonical
, *args
;
2196 int i
, nsyms
, arguments
;
2200 Tcl_AppendResult (interp
,
2201 "wrong # of args: should be \"",
2202 Tcl_GetStringFromObj (objv
[0], NULL
),
2203 " function:line|function|line|*addr\"");
2207 arguments
= (int) clientData
;
2208 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2209 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2210 if (sals
.nelts
== 0)
2212 Tcl_AppendResult (interp
,
2213 "error decoding line", NULL
);
2217 /* Initialize a list that will hold the results */
2218 result
= Tcl_NewListObj (0, NULL
);
2220 /* Resolve all line numbers to PC's */
2221 for (i
= 0; i
< sals
.nelts
; i
++)
2222 resolve_sal_pc (&sals
.sals
[i
]);
2224 block
= block_for_pc (sals
.sals
[0].pc
);
2227 nsyms
= BLOCK_NSYMS (block
);
2228 for (i
= 0; i
< nsyms
; i
++)
2230 sym
= BLOCK_SYM (block
, i
);
2231 switch (SYMBOL_CLASS (sym
)) {
2233 case LOC_UNDEF
: /* catches errors */
2234 case LOC_CONST
: /* constant */
2235 case LOC_STATIC
: /* static */
2236 case LOC_REGISTER
: /* register */
2237 case LOC_TYPEDEF
: /* local typedef */
2238 case LOC_LABEL
: /* local label */
2239 case LOC_BLOCK
: /* local function */
2240 case LOC_CONST_BYTES
: /* loc. byte seq. */
2241 case LOC_UNRESOLVED
: /* unresolved static */
2242 case LOC_OPTIMIZED_OUT
: /* optimized out */
2244 case LOC_ARG
: /* argument */
2245 case LOC_REF_ARG
: /* reference arg */
2246 case LOC_REGPARM
: /* register arg */
2247 case LOC_REGPARM_ADDR
: /* indirect register arg */
2248 case LOC_LOCAL_ARG
: /* stack arg */
2249 case LOC_BASEREG_ARG
: /* basereg arg */
2251 Tcl_ListObjAppendElement (interp
, result
,
2252 Tcl_NewStringObj (SYMBOL_NAME (sym
), -1));
2254 case LOC_LOCAL
: /* stack local */
2255 case LOC_BASEREG
: /* basereg local */
2257 Tcl_ListObjAppendElement (interp
, result
,
2258 Tcl_NewStringObj (SYMBOL_NAME (sym
), -1));
2262 if (BLOCK_FUNCTION (block
))
2265 block
= BLOCK_SUPERBLOCK (block
);
2268 Tcl_SetObjResult (interp
, result
);
2273 gdb_get_line_command (clientData
, interp
, objc
, objv
)
2274 ClientData clientData
;
2277 Tcl_Obj
*CONST objv
[];
2280 struct symtabs_and_lines sals
;
2281 char *args
, **canonical
;
2285 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2286 Tcl_GetStringFromObj (objv
[0], NULL
),
2291 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2292 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2293 if (sals
.nelts
== 1)
2295 Tcl_SetObjResult (interp
, Tcl_NewIntObj (sals
.sals
[0].line
));
2299 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2304 gdb_get_file_command (clientData
, interp
, objc
, objv
)
2305 ClientData clientData
;
2308 Tcl_Obj
*CONST objv
[];
2311 struct symtabs_and_lines sals
;
2312 char *args
, **canonical
;
2316 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2317 Tcl_GetStringFromObj (objv
[0], NULL
),
2322 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2323 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2324 if (sals
.nelts
== 1)
2326 Tcl_SetResult (interp
, sals
.sals
[0].symtab
->filename
, TCL_VOLATILE
);
2330 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2335 gdb_get_function_command (clientData
, interp
, objc
, objv
)
2336 ClientData clientData
;
2339 Tcl_Obj
*CONST objv
[];
2343 struct symtabs_and_lines sals
;
2344 char *args
, **canonical
;
2348 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2349 Tcl_GetStringFromObj (objv
[0], NULL
),
2354 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2355 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2356 if (sals
.nelts
== 1)
2358 resolve_sal_pc (&sals
.sals
[0]);
2359 find_pc_partial_function (sals
.sals
[0].pc
, &function
, NULL
, NULL
);
2360 if (function
!= NULL
)
2362 Tcl_SetResult (interp
, function
, TCL_VOLATILE
);
2367 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2372 gdb_get_tracepoint_info (clientData
, interp
, objc
, objv
)
2373 ClientData clientData
;
2376 Tcl_Obj
*CONST objv
[];
2378 struct symtab_and_line sal
;
2380 struct tracepoint
*tp
;
2381 struct action_line
*al
;
2382 Tcl_Obj
*list
, *action_list
;
2383 char *filename
, *funcname
;
2387 error ("wrong # args");
2389 Tcl_GetIntFromObj (NULL
, objv
[1], &tpnum
);
2391 ALL_TRACEPOINTS (tp
)
2392 if (tp
->number
== tpnum
)
2396 error ("Tracepoint #%d does not exist", tpnum
);
2398 list
= Tcl_NewListObj (0, NULL
);
2399 sal
= find_pc_line (tp
->address
, 0);
2400 filename
= symtab_to_filename (sal
.symtab
);
2401 if (filename
== NULL
)
2403 Tcl_ListObjAppendElement (interp
, list
,
2404 Tcl_NewStringObj (filename
, -1));
2405 find_pc_partial_function (tp
->address
, &funcname
, NULL
, NULL
);
2406 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj (funcname
, -1));
2407 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (sal
.line
));
2408 sprintf (tmp
, "0x%08x", tp
->address
);
2409 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj (tmp
, -1));
2410 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->enabled
));
2411 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->pass_count
));
2412 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->step_count
));
2413 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->thread
));
2414 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->hit_count
));
2416 /* Append a list of actions */
2417 action_list
= Tcl_NewListObj (0, NULL
);
2418 for (al
= tp
->actions
; al
!= NULL
; al
= al
->next
)
2420 Tcl_ListObjAppendElement (interp
, action_list
,
2421 Tcl_NewStringObj (al
->action
, -1));
2423 Tcl_ListObjAppendElement (interp
, list
, action_list
);
2425 Tcl_SetObjResult (interp
, list
);
2430 gdbtk_create_tracepoint (tp
)
2431 struct tracepoint
*tp
;
2433 tracepoint_notify (tp
, "create");
2437 gdbtk_delete_tracepoint (tp
)
2438 struct tracepoint
*tp
;
2440 tracepoint_notify (tp
, "delete");
2444 tracepoint_notify(tp
, action
)
2445 struct tracepoint
*tp
;
2450 struct symtab_and_line sal
;
2453 /* We ensure that ACTION contains no special Tcl characters, so we
2455 sal
= find_pc_line (tp
->address
, 0);
2457 filename
= symtab_to_filename (sal
.symtab
);
2458 if (filename
== NULL
)
2460 sprintf (buf
, "gdbtk_tcl_tracepoint %s %d 0x%lx %d {%s}", action
, tp
->number
,
2461 (long)tp
->address
, sal
.line
, filename
);
2463 v
= Tcl_Eval (interp
, buf
);
2467 gdbtk_fputs (interp
->result
, gdb_stdout
);
2468 gdbtk_fputs ("\n", gdb_stdout
);
2472 /* returns -1 if not found, tracepoint # if found */
2474 tracepoint_exists (char * args
)
2476 struct tracepoint
*tp
;
2478 struct symtabs_and_lines sals
;
2482 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2483 if (sals
.nelts
== 1)
2485 resolve_sal_pc (&sals
.sals
[0]);
2486 file
= xmalloc (strlen (sals
.sals
[0].symtab
->dirname
)
2487 + strlen (sals
.sals
[0].symtab
->filename
) + 1);
2490 strcpy (file
, sals
.sals
[0].symtab
->dirname
);
2491 strcat (file
, sals
.sals
[0].symtab
->filename
);
2493 ALL_TRACEPOINTS (tp
)
2495 if (tp
->address
== sals
.sals
[0].pc
)
2496 result
= tp
->number
;
2497 else if (tp
->source_file
!= NULL
2498 && strcmp (tp
->source_file
, file
) == 0
2499 && sals
.sals
[0].line
== tp
->line_number
)
2501 result
= tp
->number
;
2511 gdb_actions_command (clientData
, interp
, objc
, objv
)
2512 ClientData clientData
;
2515 Tcl_Obj
*CONST objv
[];
2517 struct tracepoint
*tp
;
2519 int nactions
, i
, len
;
2520 char *number
, *args
, *action
;
2521 struct action_line
*next
= NULL
, *temp
;
2525 Tcl_AppendResult (interp
, "wrong # args: should be: \"",
2526 Tcl_GetStringFromObj (objv
[0], NULL
),
2527 " number actions\"");
2531 args
= number
= Tcl_GetStringFromObj (objv
[1], NULL
);
2532 tp
= get_tracepoint_by_number (&args
);
2535 Tcl_AppendResult (interp
, "Tracepoint \"", number
, "\" does not exist");
2539 /* Free any existing actions */
2540 for (temp
= tp
->actions
; temp
!= NULL
; temp
= temp
->next
)
2543 free (temp
->action
);
2547 Tcl_ListObjGetElements (interp
, objv
[2], &nactions
, &actions
);
2548 for (i
= 0; i
< nactions
; i
++)
2550 temp
= xmalloc (sizeof (struct action_line
));
2552 action
= Tcl_GetStringFromObj (actions
[i
], &len
);
2553 temp
->action
= savestring (action
, len
);
2570 gdb_tracepoint_exists_command (clientData
, interp
, objc
, objv
)
2571 ClientData clientData
;
2574 Tcl_Obj
*CONST objv
[];
2580 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2581 Tcl_GetStringFromObj (objv
[0], NULL
),
2582 " function:line|function|line|*addr\"");
2586 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2588 Tcl_SetObjResult (interp
, Tcl_NewIntObj (tracepoint_exists (args
)));
2592 /* Return the prompt to the interpreter */
2594 gdb_prompt_command (clientData
, interp
, objc
, objv
)
2595 ClientData clientData
;
2598 Tcl_Obj
*CONST objv
[];
2600 Tcl_SetResult (interp
, get_prompt (), TCL_VOLATILE
);
2604 /* return a list of all tracepoint numbers in interpreter */
2606 gdb_get_tracepoint_list (clientData
, interp
, objc
, objv
)
2607 ClientData clientData
;
2610 Tcl_Obj
*CONST objv
[];
2613 struct tracepoint
*tp
;
2615 list
= Tcl_NewListObj (0, NULL
);
2617 ALL_TRACEPOINTS (tp
)
2618 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->number
));
2620 Tcl_SetObjResult (interp
, list
);
2624 /* This is stolen from source.c */
2625 #ifdef CRLF_SOURCE_FILES
2627 /* Define CRLF_SOURCE_FILES in an xm-*.h file if source files on the
2628 host use \r\n rather than just \n. Defining CRLF_SOURCE_FILES is
2629 much faster than defining LSEEK_NOT_LINEAR. */
2635 #define OPEN_MODE (O_RDONLY | O_BINARY)
2637 #else /* ! defined (CRLF_SOURCE_FILES) */
2639 #define OPEN_MODE O_RDONLY
2641 #endif /* ! defined (CRLF_SOURCE_FILES) */
2643 /* Find the pathname to a file, searching the source_dir */
2644 /* we may actually need to use openp to find the the full pathname
2645 so we don't have any "../" et al in it. */
2647 gdb_find_file_command (clientData
, interp
, objc
, objv
)
2648 ClientData clientData
;
2651 Tcl_Obj
*CONST objv
[];
2653 char *file
, *filename
;
2654 struct symtab
*st
= NULL
;
2658 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2659 Tcl_GetStringFromObj (objv
[0], NULL
),
2664 /* try something simple first */
2665 file
= Tcl_GetStringFromObj (objv
[1], NULL
);
2666 if (access (file
, R_OK
) == 0)
2668 Tcl_SetObjResult (interp
, Tcl_NewStringObj (file
, -1));
2672 /* We really need a symtab for this to work... */
2673 st
= lookup_symtab (file
);
2676 filename
= symtab_to_filename (st
);
2677 if (filename
!= NULL
)
2679 Tcl_SetObjResult (interp
, Tcl_NewStringObj (filename
, -1));
2684 Tcl_SetResult (interp
, "", TCL_STATIC
);
2688 /* Come here during initialize_all_files () */
2691 _initialize_gdbtk ()
2695 /* Tell the rest of the world that Gdbtk is now set up. */
2697 init_ui_hook
= gdbtk_init
;