* lib/gdb.exp(default_gdb_exit): Add a catch to the
[binutils-gdb.git] / gdb / testsuite / lib / gdb.exp
1 # Copyright (C) 1992, 1994, 1995 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Fred Fish. (fnf@cygnus.com)
21
22 # Generic gdb subroutines that should work for any target. If these
23 # need to be modified for any target, it can be done with a variable
24 # or by passing arguments.
25
26 load_lib libgloss.exp
27
28 global GDB
29 global CHILL_LIB
30 global CHILL_RT0
31
32 if ![info exists CHILL_LIB] {
33 set CHILL_LIB [findfile $base_dir/../../gcc/ch/runtime/libchill.a "$base_dir/../../gcc/ch/runtime/libchill.a" [transform -lchill]]
34 }
35 verbose "using CHILL_LIB = $CHILL_LIB" 2
36 if ![info exists CHILL_RT0] {
37 set CHILL_RT0 [findfile $base_dir/../../gcc/ch/runtime/chillrt0.o "$base_dir/../../gcc/ch/runtime/chillrt0.o" ""]
38 }
39 verbose "using CHILL_RT0 = $CHILL_RT0" 2
40
41 if ![info exists GDB] {
42 if ![is_remote host] {
43 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
44 } else {
45 set GDB gdb
46 }
47 }
48 verbose "using GDB = $GDB" 2
49
50 global GDBFLAGS
51 if ![info exists GDBFLAGS] {
52 set GDBFLAGS "-nx"
53 }
54 verbose "using GDBFLAGS = $GDBFLAGS" 2
55
56 # The variable prompt is a regexp which matches the gdb prompt. Set it if it
57 # is not already set.
58 global prompt
59 if ![info exists prompt] then {
60 set prompt "\[(\]gdb\[)\]"
61 }
62
63 if ![info exists noargs] then {
64 set noargs 0
65 }
66
67 if ![info exists nosignals] then {
68 set nosignals 0
69 }
70
71 if ![info exists noinferiorio] then {
72 set noinferiorio 0
73 }
74
75 if ![info exists noresults] then {
76 set noresults 0
77 }
78
79 #
80 # gdb_version -- extract and print the version number of GDB
81 #
82 proc default_gdb_version {} {
83 global GDB
84 global GDBFLAGS
85 global prompt
86 set fileid [open "gdb_cmd" w];
87 puts $fileid "q";
88 close $fileid;
89 set cmdfile [remote_download host "gdb_cmd"];
90 set output [remote_exec host "$GDB -nw --command $cmdfile"]
91 remote_file build delete "gdb_cmd";
92 remote_file host delete "$cmdfile";
93 set tmp [lindex $output 1];
94 set version ""
95 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
96 if ![is_remote host] {
97 clone_output "[which $GDB] version $version $GDBFLAGS\n"
98 } else {
99 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
100 }
101 }
102
103 proc gdb_version { } {
104 return [default_gdb_version];
105 }
106
107 #
108 # gdb_unload -- unload a file if one is loaded
109 #
110
111 proc gdb_unload {} {
112 global verbose
113 global GDB
114 global prompt
115 send_gdb "file\n"
116 expect {
117 -re "No exec file now.*\r" { exp_continue }
118 -re "No symbol file now.*\r" { exp_continue }
119 -re "A program is being debugged already..*Kill it.*y or n. $"\
120 { send_gdb "y\n"
121 verbose "\t\tKilling previous program being debugged"
122 exp_continue
123 }
124 -re "Discard symbol table from .*y or n. $" {
125 send_gdb "y\n"
126 exp_continue
127 }
128 -re "$prompt $" {}
129 timeout {
130 perror "couldn't unload file in $GDB (timed out)."
131 return -1
132 }
133 }
134 }
135
136 # Many of the tests depend on setting breakpoints at various places and
137 # running until that breakpoint is reached. At times, we want to start
138 # with a clean-slate with respect to breakpoints, so this utility proc
139 # lets us do this without duplicating this code everywhere.
140 #
141
142 proc delete_breakpoints {} {
143 global prompt
144 global gdb_spawn_id
145
146 send_gdb "delete breakpoints\n"
147 expect {
148 -i $gdb_spawn_id -re ".*Delete all breakpoints.*y or n.*$" {
149 send_gdb "y\n";
150 exp_continue
151 }
152 -i $gdb_spawn_id -re ".*$prompt $" { # This happens if there were no breakpoints
153 }
154 -i $gdb_spawn_id timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
155 }
156 send_gdb "info breakpoints\n"
157 expect {
158 -i $gdb_spawn_id -re "No breakpoints or watchpoints..*$prompt $" {}
159 -i $gdb_spawn_id -re ".*$prompt $" { perror "breakpoints not deleted" ; return }
160 -i $gdb_spawn_id -re "Delete all breakpoints.*or n.*$" {
161 send_gdb "y\n";
162 exp_continue
163 }
164 -i $gdb_spawn_id timeout { perror "info breakpoints (timeout)" ; return }
165 }
166 }
167
168
169 #
170 # Generic run command.
171 #
172 # The second pattern below matches up to the first newline *only*.
173 # Using ``.*$'' could swallow up output that we attempt to match
174 # elsewhere.
175 #
176 proc gdb_run_cmd {args} {
177 global prompt
178 global gdb_spawn_id
179
180 set spawn_id $gdb_spawn_id
181
182 if [target_info exists use_gdb_stub] {
183 send_gdb "jump *start\n"
184 expect {
185 -re "Line.* Jump anyway.*y or n. $" {
186 send_gdb "y\n"
187 expect {
188 -re "Continuing.*$prompt $" {}
189 timeout { perror "Jump to start() failed (timeout)"; return }
190 }
191 }
192 -re "No symbol.*context.*$prompt $" {}
193 -re "The program is not being run.*$prompt $" {
194 gdb_load "";
195 }
196 timeout { perror "Jump to start() failed (timeout)"; return }
197 }
198 send_gdb "continue\n"
199 return
200 }
201 send_gdb "run $args\n"
202 # This doesn't work quite right yet.
203 expect {
204 -re "The program .* has been started already.*y or n. $" {
205 send_gdb "y\n"
206 exp_continue
207 }
208 -re "Starting program: \[^\n\]*" {}
209 }
210 }
211
212 proc gdb_breakpoint { function } {
213 global prompt
214 global decimal
215 global gdb_spawn_id
216
217 set spawn_id $gdb_spawn_id
218
219 send_gdb "break $function\n"
220 # The first two regexps are what we get with -g, the third is without -g.
221 expect {
222 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$prompt $" {}
223 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$prompt $" {}
224 -re "Breakpoint \[0-9\]* at .*$prompt $" {}
225 -re "$prompt $" { fail "setting breakpoint at $function" ; return 0 }
226 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
227 }
228 return 1;
229 }
230
231 # Set breakpoint at function and run gdb until it breaks there.
232 # Since this is the only breakpoint that will be set, if it stops
233 # at a breakpoint, we will assume it is the one we want. We can't
234 # just compare to "function" because it might be a fully qualified,
235 # single quoted C++ function specifier.
236
237 proc runto { function } {
238 global prompt
239 global decimal
240 global gdb_spawn_id
241
242 set spawn_id $gdb_spawn_id
243
244 delete_breakpoints
245
246 if ![gdb_breakpoint $function] {
247 return 0;
248 }
249
250 gdb_run_cmd
251
252 # the "at foo.c:36" output we get with -g.
253 # the "in func" output we get without -g.
254 expect {
255 -re "Break.* at .*:$decimal.*$prompt $" {
256 return 1
257 }
258 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in $function.*$prompt $" {
259 return 1
260 }
261 -re "$prompt $" {
262 fail "running to $function in runto"
263 return 0
264 }
265 timeout {
266 fail "running to $function in runto (timeout)"
267 return 0
268 }
269 }
270 }
271
272 #
273 # runto_main -- ask gdb to run until we hit a breakpoint at main.
274 # The case where the target uses stubs has to be handled
275 # specially--if it uses stubs, assuming we hit
276 # breakpoint() and just step out of the function.
277 #
278 proc runto_main {} {
279 global prompt
280 global decimal
281
282 if ![target_info exists gdb_stub] {
283 return [runto main]
284 }
285
286 delete_breakpoints
287
288 send_gdb "step\n"
289 # if use stubs step out of the breakpoint() function.
290 expect {
291 -re "main.* at .*$prompt $" {}
292 -re "_start.*$prompt $" {}
293 timeout { fail "single step at breakpoint() (timeout)" ; return 0 }
294 }
295 return 1
296 }
297
298 #
299 # gdb_test -- send_gdb a command to gdb and test the result.
300 # Takes three parameters.
301 # Parameters:
302 # First one is the command to execute. If this is the null string
303 # then no command is sent.
304 # Second one is the pattern to match for a PASS, and must NOT include
305 # the \r\n sequence immediately before the gdb prompt.
306 # Third one is an optional message to be printed. If this
307 # a null string "", then the pass/fail messages use the command
308 # string as the message.
309 # Returns:
310 # 1 if the test failed,
311 # 0 if the test passes,
312 # -1 if there was an internal error.
313 #
314 proc gdb_test { args } {
315 global verbose
316 global prompt
317 global GDB
318 global expect_out
319 upvar timeout timeout
320
321 if [llength $args]>2 then {
322 set message [lindex $args 2]
323 } else {
324 set message [lindex $args 0]
325 }
326 set command [lindex $args 0]
327 set pattern [lindex $args 1]
328
329 if [llength $args]==5 {
330 set question_string [lindex $args 3];
331 set response_string [lindex $args 4];
332 } else {
333 set question_string "^FOOBAR$"
334 }
335
336 if $verbose>2 then {
337 send_user "Sending \"$command\" to gdb\n"
338 send_user "Looking to match \"$pattern\"\n"
339 send_user "Message is \"$message\"\n"
340 }
341
342 set result -1
343 if ![string match $command ""] {
344 send_gdb "$command\n"
345 }
346
347 expect {
348 -re ".*Ending remote debugging.*$prompt$" {
349 if ![isnative] then {
350 warning "Can`t communicate to remote target."
351 }
352 gdb_exit
353 gdb_start
354 set result -1
355 }
356 -re "\[\r\n\]*$pattern\[\r\n\]+$prompt $" {
357 if ![string match "" $message] then {
358 pass "$message"
359 }
360 set result 0
361 }
362 -re "${question_string}$" {
363 send_gdb "$response_string\n";
364 exp_continue;
365 }
366 -re "Undefined command:.*$prompt" {
367 perror "Undefined command \"$command\"."
368 set result 1
369 }
370 -re "Ambiguous command.*$prompt $" {
371 perror "\"$command\" is not a unique command name."
372 set result 1
373 }
374 -re ".*Program exited with code \[0-9\]+.*$prompt $" {
375 if ![string match "" $message] then {
376 set errmsg "$message: the program exited"
377 } else {
378 set errmsg "$command: the program exited"
379 }
380 fail "$errmsg"
381 return -1
382 }
383 -re "The program is not being run.*$prompt $" {
384 if ![string match "" $message] then {
385 set errmsg "$message: the program is no longer running"
386 } else {
387 set errmsg "$command: the program is no longer running"
388 }
389 fail "$errmsg"
390 return -1
391 }
392 -re ".*$prompt $" {
393 if ![string match "" $message] then {
394 fail "$message"
395 }
396 set result 1
397 }
398 "<return>" {
399 send_gdb "\n"
400 perror "Window too small."
401 }
402 -re "\\(y or n\\) " {
403 send_gdb "n\n"
404 perror "Got interactive prompt."
405 }
406 eof {
407 perror "Process no longer exists"
408 return -1
409 }
410 full_buffer {
411 perror "internal buffer is full."
412 }
413 timeout {
414 if ![string match "" $message] then {
415 fail "(timeout) $message"
416 }
417 set result 1
418 }
419 }
420 return $result
421 }
422 \f
423 # Test that a command gives an error. For pass or fail, return
424 # a 1 to indicate that more tests can proceed. However a timeout
425 # is a serious error, generates a special fail message, and causes
426 # a 0 to be returned to indicate that more tests are likely to fail
427 # as well.
428
429 proc test_print_reject { args } {
430 global prompt
431 global verbose
432
433 if [llength $args]==2 then {
434 set expectthis [lindex $args 1]
435 } else {
436 set expectthis "should never match this bogus string"
437 }
438 set sendthis [lindex $args 0]
439 if $verbose>2 then {
440 send_user "Sending \"$sendthis\" to gdb\n"
441 send_user "Looking to match \"$expectthis\"\n"
442 }
443 send_gdb "$sendthis\n"
444 expect {
445 -re ".*A .* in expression.*\\.*$prompt $" {
446 pass "reject $sendthis"
447 return 1
448 }
449 -re ".*Invalid syntax in expression.*$prompt $" {
450 pass "reject $sendthis"
451 return 1
452 }
453 -re ".*Junk after end of expression.*$prompt $" {
454 pass "reject $sendthis"
455 return 1
456 }
457 -re ".*Invalid number.*$prompt $" {
458 pass "reject $sendthis"
459 return 1
460 }
461 -re ".*Invalid character constant.*$prompt $" {
462 pass "reject $sendthis"
463 return 1
464 }
465 -re ".*No symbol table is loaded.*$prompt $" {
466 pass "reject $sendthis"
467 return 1
468 }
469 -re ".*No symbol .* in current context.*$prompt $" {
470 pass "reject $sendthis"
471 return 1
472 }
473 -re ".*$expectthis.*$prompt $" {
474 pass "reject $sendthis"
475 return 1
476 }
477 -re ".*$prompt $" {
478 fail "reject $sendthis"
479 return 1
480 }
481 default {
482 fail "reject $sendthis (eof or timeout)"
483 return 0
484 }
485 }
486 }
487 \f
488 # Given an input string, adds backslashes as needed to create a
489 # regexp that will match the string.
490
491 proc string_to_regexp {str} {
492 set result $str
493 regsub -all {[]*+.|()^$\[]} $str {\\&} result
494 return $result
495 }
496
497 # Same as gdb_test, but the second parameter is not a regexp,
498 # but a string that must match exactly.
499
500 proc gdb_test_exact { args } {
501 upvar timeout timeout
502
503 set command [lindex $args 0]
504
505 # This applies a special meaning to a null string pattern. Without
506 # this, "$pattern\r\n$prompt $" will match anything, including error
507 # messages from commands that should have no output except a new
508 # prompt. With this, only results of a null string will match a null
509 # string pattern.
510
511 set pattern [lindex $args 1]
512 if [string match $pattern ""] {
513 set pattern [string_to_regexp [lindex $args 0]]
514 } else {
515 set pattern [string_to_regexp [lindex $args 1]]
516 }
517
518 # It is most natural to write the pattern argument with only
519 # embedded \n's, especially if you are trying to avoid Tcl quoting
520 # problems. But expect really wants to see \r\n in patterns. So
521 # transform the pattern here. First transform \r\n back to \n, in
522 # case some users of gdb_test_exact already do the right thing.
523 regsub -all "\r\n" $pattern "\n" pattern
524 regsub -all "\n" $pattern "\r\n" pattern
525 if [llength $args]==3 then {
526 set message [lindex $args 2]
527 } else {
528 set message $command
529 }
530
531 return [gdb_test $command $pattern $message]
532 }
533 \f
534 proc gdb_reinitialize_dir { subdir } {
535 global prompt
536 global gdb_spawn_id
537 set spawn_id $gdb_spawn_id
538
539 if [is_remote host] {
540 return "";
541 }
542 send_gdb "dir\n"
543 expect {
544 -re "Reinitialize source path to empty.*y or n. " {
545 send_gdb "y\n"
546 expect {
547 -re "Source directories searched.*$prompt $" {
548 send_gdb "dir $subdir\n"
549 expect {
550 -re "Source directories searched.*$prompt $" {
551 verbose "Dir set to $subdir"
552 }
553 -re ".*$prompt $" {
554 perror "Dir \"$subdir\" failed."
555 }
556 }
557 }
558 -re ".*$prompt $" {
559 perror "Dir \"$subdir\" failed."
560 }
561 }
562 }
563 -re ".*$prompt $" {
564 perror "Dir \"$subdir\" failed."
565 }
566 }
567 }
568
569 #
570 # gdb_exit -- exit the GDB, killing the target program if necessary
571 #
572 proc default_gdb_exit {} {
573 global GDB
574 global GDBFLAGS
575 global verbose
576 global gdb_spawn_id
577
578 if ![info exists gdb_spawn_id] {
579 return;
580 }
581
582 verbose "Quitting $GDB $GDBFLAGS"
583
584 # This used to be 1 for unix-gdb.exp
585 set timeout 5
586 verbose "Timeout is now $timeout seconds" 2
587
588 if [is_remote host] {
589 send_gdb "quit\n";
590 expect {
591 -i $gdb_spawn_id -re ".*and kill it.*y or n. " {
592 send_gdb "y\n";
593 exp_continue;
594 }
595 -i $gdb_spawn_id timeout { }
596 }
597 } else {
598 # We used to try to send_gdb "quit" to GDB, and wait for it to die.
599 # Dealing with all the cases and errors got pretty hairy. Just close it,
600 # that is simpler.
601 catch "close -i $gdb_spawn_id"
602
603 # Omitting this probably would cause strange timing-dependent failures.
604 catch "wait -i $gdb_spawn_id"
605 }
606
607 remote_close host;
608 unset gdb_spawn_id
609 }
610
611 #
612 # load a file into the debugger.
613 # return a -1 if anything goes wrong.
614 #
615 proc gdb_file_cmd { arg } {
616 global verbose
617 global loadpath
618 global loadfile
619 global GDB
620 global prompt
621 upvar timeout timeout
622 global gdb_spawn_id
623 set spawn_id $gdb_spawn_id
624
625 if [is_remote host] {
626 set arg [remote_download host $arg];
627 if { $arg == "" } {
628 error "download failed"
629 return -1;
630 }
631 }
632
633 send_gdb "file $arg\n"
634 expect {
635 -re "Reading symbols from.*done.*$prompt $" {
636 verbose "\t\tLoaded $arg into the $GDB"
637 return 0
638 }
639 -re "has no symbol-table.*$prompt $" {
640 perror "$arg wasn't compiled with \"-g\""
641 return -1
642 }
643 -re "A program is being debugged already.*Kill it.*y or n. $" {
644 send_gdb "y\n"
645 verbose "\t\tKilling previous program being debugged"
646 exp_continue
647 }
648 -re "Load new symbol table from \".*\".*y or n. $" {
649 send_gdb "y\n"
650 expect {
651 -re "Reading symbols from.*done.*$prompt $" {
652 verbose "\t\tLoaded $arg with new symbol table into $GDB"
653 return 0
654 }
655 timeout {
656 perror "(timeout) Couldn't load $arg, other program already l
657 oaded."
658 return -1
659 }
660 }
661 }
662 -re ".*No such file or directory.*$prompt $" {
663 perror "($arg) No such file or directory\n"
664 return -1
665 }
666 -re "$prompt $" {
667 perror "couldn't load $arg into $GDB."
668 return -1
669 }
670 timeout {
671 perror "couldn't load $arg into $GDB (timed out)."
672 return -1
673 }
674 eof {
675 # This is an attempt to detect a core dump, but seems not to
676 # work. Perhaps we need to match .* followed by eof, in which
677 # expect does not seem to have a way to do that.
678 perror "couldn't load $arg into $GDB (end of file)."
679 return -1
680 }
681 }
682 }
683
684 #
685 # start gdb -- start gdb running, default procedure
686 #
687 # When running over NFS, particularly if running many simultaneous
688 # tests on different hosts all using the same server, things can
689 # get really slow. Give gdb at least 3 minutes to start up.
690 #
691 proc default_gdb_start { } {
692 global verbose
693 global GDB
694 global GDBFLAGS
695 global prompt
696 global timeout
697 global gdb_spawn_id
698 global spawn_id
699 verbose "Spawning $GDB -nw $GDBFLAGS"
700
701 if [info exists gdb_spawn_id] {
702 return 0;
703 }
704
705 set oldtimeout $timeout
706 set timeout [expr "$timeout + 180"]
707 if [is_remote host] {
708 set shell_id [remote_spawn host "$GDB -nw $GDBFLAGS --command gdbinit"]
709 } else {
710 if { [which $GDB] == 0 } then {
711 perror "$GDB does not exist."
712 exit 1
713 }
714
715 set shell_id [remote_spawn host "$GDB -nw $GDBFLAGS"]
716 }
717 verbose $shell_id
718 set timeout 10
719 expect {
720 -i $shell_id -re ".*\[\r\n\]$prompt $" {
721 verbose "GDB initialized."
722 }
723 -i $shell_id -re "$prompt $" {
724 perror "GDB never initialized."
725 set timeout $oldtimeout
726 verbose "Timeout restored to $timeout seconds" 2
727 return -1
728 }
729 -i $shell_id timeout {
730 perror "(timeout) GDB never initialized after $timeout seconds."
731 set timeout $oldtimeout
732 verbose "Timeout restored to $timeout seconds" 2
733 return -1
734 }
735 }
736 set timeout $oldtimeout
737 verbose "Timeout restored to $timeout seconds" 2
738 set gdb_spawn_id $shell_id
739 set spawn_id $gdb_spawn_id
740 # force the height to "unlimited", so no pagers get used
741 send_gdb "set height 0\n"
742 expect {
743 -i $shell_id -re ".*$prompt $" {
744 verbose "Setting height to 0." 2
745 }
746 -i $shell_id timeout {
747 warning "Couldn't set the height to 0"
748 }
749 }
750 # force the width to "unlimited", so no wraparound occurs
751 send_gdb "set width 0\n"
752 expect {
753 -i $shell_id -re ".*$prompt $" {
754 verbose "Setting width to 0." 2
755 }
756 -i $shell_id timeout {
757 warning "Couldn't set the width to 0."
758 }
759 }
760 return 0;
761 }
762
763 #
764 # FIXME: this is a copy of the new library procedure, but it's here too
765 # till the new dejagnu gets installed everywhere. I'd hate to break the
766 # gdb testsuite.
767 #
768 global argv0
769 if ![info exists argv0] then {
770 proc exp_continue { } {
771 continue -expect
772 }
773 }
774
775 # * For crosses, the CHILL runtime doesn't build because it can't find
776 # setjmp.h, stdio.h, etc.
777 # * For AIX (as of 16 Mar 95), (a) there is no language code for
778 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
779 # does not get along with AIX's too-clever linker.
780 # * On Irix5, there is a bug whereby set of bool, etc., don't get
781 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
782 # work with stub types.
783 # Lots of things seem to fail on the PA, and since it's not a supported
784 # chill target at the moment, don't run the chill tests.
785
786 proc skip_chill_tests {} {
787 if ![info exists do_chill_tests] {
788 return 1;
789 }
790 eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
791 verbose "Skip chill tests is $skip_chill"
792 return $skip_chill
793 }
794
795 proc get_compiler_info {binfile} {
796 # Create and source the file that provides information about the compiler
797 # used to compile the test case.
798 global srcdir
799 global subdir
800 # These two come from compiler.c.
801 global signed_keyword_not_used
802 global gcc_compiled
803
804 if { [gdb_compile "${srcdir}/${subdir}/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
805 perror "Couldn't make ${binfile}.ci file"
806 return 1;
807 }
808 source ${binfile}.ci
809 return 0;
810 }
811
812 proc gdb_compile {source dest type options} {
813 if [target_info exists gdb_stub] {
814 set options2 { "additional_flags=-Dusestubs" }
815 lappend options "libs=[target_info gdb_stub]";
816 set options [concat $options2 $options]
817 }
818 verbose "options are $options"
819 verbose "source is $source $dest $type $options"
820 set result [target_compile $source $dest $type $options];
821 regsub "\[\r\n\]*$" "$result" "" result;
822 regsub "^\[\r\n\]*" "$result" "" result;
823 if { $result != "" } {
824 clone_output "gdb compile failed, $result"
825 }
826 return $result;
827 }
828
829 proc send_gdb { string } {
830 return [remote_send host "$string"];
831 }
832
833 proc gdb_start { } {
834 default_gdb_start
835 }
836
837 proc gdb_exit { } {
838 catch default_gdb_exit
839 }
840
841 #
842 # gdb_load -- load a file into the debugger.
843 # return a -1 if anything goes wrong.
844 #
845 proc gdb_load { arg } {
846 return [gdb_file_cmd $arg]
847 }
848
849 proc gdb_continue { function } {
850 global decimal
851
852 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
853 }
854
855 proc gdb_finish { } {
856 gdb_exit;
857 }