forked from gbenson/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfcmd.c
3395 lines (2768 loc) · 95.1 KB
/
infcmd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Memory-access and commands for "inferior" process, for GDB.
Copyright (C) 1986-2015 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "arch-utils.h"
#include <signal.h>
#include "symtab.h"
#include "gdbtypes.h"
#include "frame.h"
#include "inferior.h"
#include "infrun.h"
#include "environ.h"
#include "value.h"
#include "gdbcmd.h"
#include "symfile.h"
#include "gdbcore.h"
#include "target.h"
#include "language.h"
#include "objfiles.h"
#include "completer.h"
#include "ui-out.h"
#include "event-top.h"
#include "parser-defs.h"
#include "regcache.h"
#include "reggroups.h"
#include "block.h"
#include "solib.h"
#include <ctype.h>
#include "observer.h"
#include "target-descriptions.h"
#include "user-regs.h"
#include "cli/cli-decode.h"
#include "gdbthread.h"
#include "valprint.h"
#include "inline-frame.h"
#include "tracepoint.h"
#include "inf-loop.h"
#include "continuations.h"
#include "linespec.h"
#include "cli/cli-utils.h"
#include "infcall.h"
#include "thread-fsm.h"
/* Local functions: */
static void nofp_registers_info (char *, int);
static void until_next_command (int);
static void until_command (char *, int);
static void path_info (char *, int);
static void path_command (char *, int);
static void unset_command (char *, int);
static void float_info (char *, int);
static void disconnect_command (char *, int);
static void unset_environment_command (char *, int);
static void set_environment_command (char *, int);
static void environment_info (char *, int);
static void program_info (char *, int);
static void finish_command (char *, int);
static void signal_command (char *, int);
static void jump_command (char *, int);
static void step_1 (int, int, char *);
static void next_command (char *, int);
static void step_command (char *, int);
static void run_command (char *, int);
void _initialize_infcmd (void);
#define ERROR_NO_INFERIOR \
if (!target_has_execution) error (_("The program is not being run."));
/* Scratch area where string containing arguments to give to the
program will be stored by 'set args'. As soon as anything is
stored, notice_args_set will move it into per-inferior storage.
Arguments are separated by spaces. Empty string (pointer to '\0')
means no args. */
static char *inferior_args_scratch;
/* Scratch area where 'set inferior-tty' will store user-provided value.
We'll immediate copy it into per-inferior storage. */
static char *inferior_io_terminal_scratch;
/* Pid of our debugged inferior, or 0 if no inferior now.
Since various parts of infrun.c test this to see whether there is a program
being debugged it should be nonzero (currently 3 is used) for remote
debugging. */
ptid_t inferior_ptid;
/* Address at which inferior stopped. */
CORE_ADDR stop_pc;
/* Nonzero if stopped due to completion of a stack dummy routine. */
enum stop_stack_kind stop_stack_dummy;
/* Nonzero if stopped due to a random (unexpected) signal in inferior
process. */
int stopped_by_random_signal;
/* See inferior.h. */
int startup_with_shell = 1;
/* Accessor routines. */
/* Set the io terminal for the current inferior. Ownership of
TERMINAL_NAME is not transferred. */
void
set_inferior_io_terminal (const char *terminal_name)
{
xfree (current_inferior ()->terminal);
current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
}
const char *
get_inferior_io_terminal (void)
{
return current_inferior ()->terminal;
}
static void
set_inferior_tty_command (char *args, int from_tty,
struct cmd_list_element *c)
{
/* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
Now route it to current inferior. */
set_inferior_io_terminal (inferior_io_terminal_scratch);
}
static void
show_inferior_tty_command (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
/* Note that we ignore the passed-in value in favor of computing it
directly. */
const char *inferior_io_terminal = get_inferior_io_terminal ();
if (inferior_io_terminal == NULL)
inferior_io_terminal = "";
fprintf_filtered (gdb_stdout,
_("Terminal for future runs of program being debugged "
"is \"%s\".\n"), inferior_io_terminal);
}
char *
get_inferior_args (void)
{
if (current_inferior ()->argc != 0)
{
char *n;
n = construct_inferior_arguments (current_inferior ()->argc,
current_inferior ()->argv);
set_inferior_args (n);
xfree (n);
}
if (current_inferior ()->args == NULL)
current_inferior ()->args = xstrdup ("");
return current_inferior ()->args;
}
/* Set the arguments for the current inferior. Ownership of
NEWARGS is not transferred. */
void
set_inferior_args (char *newargs)
{
xfree (current_inferior ()->args);
current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
current_inferior ()->argc = 0;
current_inferior ()->argv = 0;
}
void
set_inferior_args_vector (int argc, char **argv)
{
current_inferior ()->argc = argc;
current_inferior ()->argv = argv;
}
/* Notice when `set args' is run. */
static void
set_args_command (char *args, int from_tty, struct cmd_list_element *c)
{
/* CLI has assigned the user-provided value to inferior_args_scratch.
Now route it to current inferior. */
set_inferior_args (inferior_args_scratch);
}
/* Notice when `show args' is run. */
static void
show_args_command (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
/* Note that we ignore the passed-in value in favor of computing it
directly. */
deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
}
/* Compute command-line string given argument vector. This does the
same shell processing as fork_inferior. */
char *
construct_inferior_arguments (int argc, char **argv)
{
char *result;
if (startup_with_shell)
{
#ifdef __MINGW32__
/* This holds all the characters considered special to the
Windows shells. */
char *special = "\"!&*|[]{}<>?`~^=;, \t\n";
const char quote = '"';
#else
/* This holds all the characters considered special to the
typical Unix shells. We include `^' because the SunOS
/bin/sh treats it as a synonym for `|'. */
char *special = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
const char quote = '\'';
#endif
int i;
int length = 0;
char *out, *cp;
/* We over-compute the size. It shouldn't matter. */
for (i = 0; i < argc; ++i)
length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
result = (char *) xmalloc (length);
out = result;
for (i = 0; i < argc; ++i)
{
if (i > 0)
*out++ = ' ';
/* Need to handle empty arguments specially. */
if (argv[i][0] == '\0')
{
*out++ = quote;
*out++ = quote;
}
else
{
#ifdef __MINGW32__
int quoted = 0;
if (strpbrk (argv[i], special))
{
quoted = 1;
*out++ = quote;
}
#endif
for (cp = argv[i]; *cp; ++cp)
{
if (*cp == '\n')
{
/* A newline cannot be quoted with a backslash (it
just disappears), only by putting it inside
quotes. */
*out++ = quote;
*out++ = '\n';
*out++ = quote;
}
else
{
#ifdef __MINGW32__
if (*cp == quote)
#else
if (strchr (special, *cp) != NULL)
#endif
*out++ = '\\';
*out++ = *cp;
}
}
#ifdef __MINGW32__
if (quoted)
*out++ = quote;
#endif
}
}
*out = '\0';
}
else
{
/* In this case we can't handle arguments that contain spaces,
tabs, or newlines -- see breakup_args(). */
int i;
int length = 0;
for (i = 0; i < argc; ++i)
{
char *cp = strchr (argv[i], ' ');
if (cp == NULL)
cp = strchr (argv[i], '\t');
if (cp == NULL)
cp = strchr (argv[i], '\n');
if (cp != NULL)
error (_("can't handle command-line "
"argument containing whitespace"));
length += strlen (argv[i]) + 1;
}
result = (char *) xmalloc (length);
result[0] = '\0';
for (i = 0; i < argc; ++i)
{
if (i > 0)
strcat (result, " ");
strcat (result, argv[i]);
}
}
return result;
}
/* This function strips the '&' character (indicating background
execution) that is added as *the last* of the arguments ARGS of a
command. A copy of the incoming ARGS without the '&' is returned,
unless the resulting string after stripping is empty, in which case
NULL is returned. *BG_CHAR_P is an output boolean that indicates
whether the '&' character was found. */
static char *
strip_bg_char (const char *args, int *bg_char_p)
{
const char *p;
if (args == NULL || *args == '\0')
{
*bg_char_p = 0;
return NULL;
}
p = args + strlen (args);
if (p[-1] == '&')
{
p--;
while (p > args && isspace (p[-1]))
p--;
*bg_char_p = 1;
if (p != args)
return savestring (args, p - args);
else
return NULL;
}
*bg_char_p = 0;
return xstrdup (args);
}
/* Common actions to take after creating any sort of inferior, by any
means (running, attaching, connecting, et cetera). The target
should be stopped. */
void
post_create_inferior (struct target_ops *target, int from_tty)
{
/* Be sure we own the terminal in case write operations are performed. */
target_terminal_ours ();
/* If the target hasn't taken care of this already, do it now.
Targets which need to access registers during to_open,
to_create_inferior, or to_attach should do it earlier; but many
don't need to. */
target_find_description ();
/* Now that we know the register layout, retrieve current PC. But
if the PC is unavailable (e.g., we're opening a core file with
missing registers info), ignore it. */
stop_pc = 0;
TRY
{
stop_pc = regcache_read_pc (get_current_regcache ());
}
CATCH (ex, RETURN_MASK_ERROR)
{
if (ex.error != NOT_AVAILABLE_ERROR)
throw_exception (ex);
}
END_CATCH
if (exec_bfd)
{
const unsigned solib_add_generation
= current_program_space->solib_add_generation;
/* Create the hooks to handle shared library load and unload
events. */
solib_create_inferior_hook (from_tty);
if (current_program_space->solib_add_generation == solib_add_generation)
{
/* The platform-specific hook should load initial shared libraries,
but didn't. FROM_TTY will be incorrectly 0 but such solib
targets should be fixed anyway. Call it only after the solib
target has been initialized by solib_create_inferior_hook. */
if (info_verbose)
warning (_("platform-specific solib_create_inferior_hook did "
"not load initial shared libraries."));
/* If the solist is global across processes, there's no need to
refetch it here. */
if (!gdbarch_has_global_solist (target_gdbarch ()))
solib_add (NULL, 0, target, auto_solib_add);
}
}
/* If the user sets watchpoints before execution having started,
then she gets software watchpoints, because GDB can't know which
target will end up being pushed, or if it supports hardware
watchpoints or not. breakpoint_re_set takes care of promoting
watchpoints to hardware watchpoints if possible, however, if this
new inferior doesn't load shared libraries or we don't pull in
symbols from any other source on this target/arch,
breakpoint_re_set is never called. Call it now so that software
watchpoints get a chance to be promoted to hardware watchpoints
if the now pushed target supports hardware watchpoints. */
breakpoint_re_set ();
observer_notify_inferior_created (target, from_tty);
}
/* Kill the inferior if already running. This function is designed
to be called when we are about to start the execution of the program
from the beginning. Ask the user to confirm that he wants to restart
the program being debugged when FROM_TTY is non-null. */
static void
kill_if_already_running (int from_tty)
{
if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
{
/* Bail out before killing the program if we will not be able to
restart it. */
target_require_runnable ();
if (from_tty
&& !query (_("The program being debugged has been started already.\n\
Start it from the beginning? ")))
error (_("Program not restarted."));
target_kill ();
}
}
/* See inferior.h. */
void
prepare_execution_command (struct target_ops *target, int background)
{
/* If we get a request for running in the bg but the target
doesn't support it, error out. */
if (background && !target->to_can_async_p (target))
error (_("Asynchronous execution not supported on this target."));
if (!background)
{
/* If we get a request for running in the fg, then we need to
simulate synchronous (fg) execution. Note no cleanup is
necessary for this. stdin is re-enabled whenever an error
reaches the top level. */
async_disable_stdin ();
}
}
/* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
a temporary breakpoint at the begining of the main program before
running the program. */
static void
run_command_1 (char *args, int from_tty, int tbreak_at_main)
{
char *exec_file;
struct cleanup *old_chain;
ptid_t ptid;
struct ui_out *uiout = current_uiout;
struct target_ops *run_target;
int async_exec;
struct cleanup *args_chain;
dont_repeat ();
kill_if_already_running (from_tty);
init_wait_for_inferior ();
clear_breakpoint_hit_counts ();
/* Clean up any leftovers from other runs. Some other things from
this function should probably be moved into target_pre_inferior. */
target_pre_inferior (from_tty);
/* The comment here used to read, "The exec file is re-read every
time we do a generic_mourn_inferior, so we just have to worry
about the symbol file." The `generic_mourn_inferior' function
gets called whenever the program exits. However, suppose the
program exits, and *then* the executable file changes? We need
to check again here. Since reopen_exec_file doesn't do anything
if the timestamp hasn't changed, I don't see the harm. */
reopen_exec_file ();
reread_symbols ();
args = strip_bg_char (args, &async_exec);
args_chain = make_cleanup (xfree, args);
/* Do validation and preparation before possibly changing anything
in the inferior. */
run_target = find_run_target ();
prepare_execution_command (run_target, async_exec);
if (non_stop && !run_target->to_supports_non_stop (run_target))
error (_("The target does not support running in non-stop mode."));
/* Done. Can now set breakpoints, change inferior args, etc. */
/* Insert the temporary breakpoint if a location was specified. */
if (tbreak_at_main)
tbreak_command (main_name (), 0);
exec_file = (char *) get_exec_file (0);
/* We keep symbols from add-symbol-file, on the grounds that the
user might want to add some symbols before running the program
(right?). But sometimes (dynamic loading where the user manually
introduces the new symbols with add-symbol-file), the code which
the symbols describe does not persist between runs. Currently
the user has to manually nuke all symbols between runs if they
want them to go away (PR 2207). This is probably reasonable. */
/* If there were other args, beside '&', process them. */
if (args != NULL)
set_inferior_args (args);
if (from_tty)
{
ui_out_field_string (uiout, NULL, "Starting program");
ui_out_text (uiout, ": ");
if (exec_file)
ui_out_field_string (uiout, "execfile", exec_file);
ui_out_spaces (uiout, 1);
/* We call get_inferior_args() because we might need to compute
the value now. */
ui_out_field_string (uiout, "infargs", get_inferior_args ());
ui_out_text (uiout, "\n");
ui_out_flush (uiout);
}
/* Done with ARGS. */
do_cleanups (args_chain);
/* We call get_inferior_args() because we might need to compute
the value now. */
run_target->to_create_inferior (run_target, exec_file, get_inferior_args (),
environ_vector (current_inferior ()->environment),
from_tty);
/* to_create_inferior should push the target, so after this point we
shouldn't refer to run_target again. */
run_target = NULL;
/* We're starting off a new process. When we get out of here, in
non-stop mode, finish the state of all threads of that process,
but leave other threads alone, as they may be stopped in internal
events --- the frontend shouldn't see them as stopped. In
all-stop, always finish the state of all threads, as we may be
resuming more than just the new process. */
if (non_stop)
ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
else
ptid = minus_one_ptid;
old_chain = make_cleanup (finish_thread_state_cleanup, &ptid);
/* Pass zero for FROM_TTY, because at this point the "run" command
has done its thing; now we are setting up the running program. */
post_create_inferior (¤t_target, 0);
/* Start the target running. Do not use -1 continuation as it would skip
breakpoint right at the entry point. */
proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0);
/* Since there was no error, there's no need to finish the thread
states here. */
discard_cleanups (old_chain);
}
static void
run_command (char *args, int from_tty)
{
run_command_1 (args, from_tty, 0);
}
/* Start the execution of the program up until the beginning of the main
program. */
static void
start_command (char *args, int from_tty)
{
/* Some languages such as Ada need to search inside the program
minimal symbols for the location where to put the temporary
breakpoint before starting. */
if (!have_minimal_symbols ())
error (_("No symbol table loaded. Use the \"file\" command."));
/* Run the program until reaching the main procedure... */
run_command_1 (args, from_tty, 1);
}
static int
proceed_thread_callback (struct thread_info *thread, void *arg)
{
/* We go through all threads individually instead of compressing
into a single target `resume_all' request, because some threads
may be stopped in internal breakpoints/events, or stopped waiting
for its turn in the displaced stepping queue (that is, they are
running && !executing). The target side has no idea about why
the thread is stopped, so a `resume_all' command would resume too
much. If/when GDB gains a way to tell the target `hold this
thread stopped until I say otherwise', then we can optimize
this. */
if (!is_stopped (thread->ptid))
return 0;
switch_to_thread (thread->ptid);
clear_proceed_status (0);
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
return 0;
}
static void
ensure_valid_thread (void)
{
if (ptid_equal (inferior_ptid, null_ptid)
|| is_exited (inferior_ptid))
error (_("Cannot execute this command without a live selected thread."));
}
/* If the user is looking at trace frames, any resumption of execution
is likely to mix up recorded and live target data. So simply
disallow those commands. */
static void
ensure_not_tfind_mode (void)
{
if (get_traceframe_number () >= 0)
error (_("Cannot execute this command while looking at trace frames."));
}
/* Throw an error indicating the current thread is running. */
static void
error_is_running (void)
{
error (_("Cannot execute this command while "
"the selected thread is running."));
}
/* Calls error_is_running if the current thread is running. */
static void
ensure_not_running (void)
{
if (is_running (inferior_ptid))
error_is_running ();
}
void
continue_1 (int all_threads)
{
ERROR_NO_INFERIOR;
ensure_not_tfind_mode ();
if (non_stop && all_threads)
{
/* Don't error out if the current thread is running, because
there may be other stopped threads. */
struct cleanup *old_chain;
/* Backup current thread and selected frame. */
old_chain = make_cleanup_restore_current_thread ();
iterate_over_threads (proceed_thread_callback, NULL);
if (sync_execution)
{
/* If all threads in the target were already running,
proceed_thread_callback ends up never calling proceed,
and so nothing calls this to put the inferior's terminal
settings in effect and remove stdin from the event loop,
which we must when running a foreground command. E.g.:
(gdb) c -a&
Continuing.
<all threads are running now>
(gdb) c -a
Continuing.
<no thread was resumed, but the inferior now owns the terminal>
*/
target_terminal_inferior ();
}
/* Restore selected ptid. */
do_cleanups (old_chain);
}
else
{
ensure_valid_thread ();
ensure_not_running ();
clear_proceed_status (0);
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
}
}
/* continue [-a] [proceed-count] [&] */
static void
continue_command (char *args, int from_tty)
{
int async_exec;
int all_threads = 0;
struct cleanup *args_chain;
ERROR_NO_INFERIOR;
/* Find out whether we must run in the background. */
args = strip_bg_char (args, &async_exec);
args_chain = make_cleanup (xfree, args);
prepare_execution_command (¤t_target, async_exec);
if (args != NULL)
{
if (startswith (args, "-a"))
{
all_threads = 1;
args += sizeof ("-a") - 1;
if (*args == '\0')
args = NULL;
}
}
if (!non_stop && all_threads)
error (_("`-a' is meaningless in all-stop mode."));
if (args != NULL && all_threads)
error (_("Can't resume all threads and specify "
"proceed count simultaneously."));
/* If we have an argument left, set proceed count of breakpoint we
stopped at. */
if (args != NULL)
{
bpstat bs = NULL;
int num, stat;
int stopped = 0;
struct thread_info *tp;
if (non_stop)
tp = find_thread_ptid (inferior_ptid);
else
{
ptid_t last_ptid;
struct target_waitstatus ws;
get_last_target_status (&last_ptid, &ws);
tp = find_thread_ptid (last_ptid);
}
if (tp != NULL)
bs = tp->control.stop_bpstat;
while ((stat = bpstat_num (&bs, &num)) != 0)
if (stat > 0)
{
set_ignore_count (num,
parse_and_eval_long (args) - 1,
from_tty);
/* set_ignore_count prints a message ending with a period.
So print two spaces before "Continuing.". */
if (from_tty)
printf_filtered (" ");
stopped = 1;
}
if (!stopped && from_tty)
{
printf_filtered
("Not stopped at any breakpoint; argument ignored.\n");
}
}
/* Done with ARGS. */
do_cleanups (args_chain);
if (from_tty)
printf_filtered (_("Continuing.\n"));
continue_1 (all_threads);
}
/* Record the starting point of a "step" or "next" command. */
static void
set_step_frame (void)
{
struct symtab_and_line sal;
CORE_ADDR pc;
struct frame_info *frame = get_current_frame ();
struct thread_info *tp = inferior_thread ();
find_frame_sal (frame, &sal);
set_step_info (frame, sal);
pc = get_frame_pc (frame);
tp->control.step_start_function = find_pc_function (pc);
}
/* Step until outside of current statement. */
static void
step_command (char *count_string, int from_tty)
{
step_1 (0, 0, count_string);
}
/* Likewise, but skip over subroutine calls as if single instructions. */
static void
next_command (char *count_string, int from_tty)
{
step_1 (1, 0, count_string);
}
/* Likewise, but step only one instruction. */
static void
stepi_command (char *count_string, int from_tty)
{
step_1 (0, 1, count_string);
}
static void
nexti_command (char *count_string, int from_tty)
{
step_1 (1, 1, count_string);
}
void
delete_longjmp_breakpoint_cleanup (void *arg)
{
int thread = * (int *) arg;
delete_longjmp_breakpoint (thread);
}
/* Data for the FSM that manages the step/next/stepi/nexti
commands. */
struct step_command_fsm
{
/* The base class. */
struct thread_fsm thread_fsm;
/* How many steps left in a "step N"-like command. */
int count;
/* If true, this is a next/nexti, otherwise a step/stepi. */
int skip_subroutines;
/* If true, this is a stepi/nexti, otherwise a step/step. */
int single_inst;
/* The thread that the command was run on. */
int thread;
};
static void step_command_fsm_clean_up (struct thread_fsm *self);
static int step_command_fsm_should_stop (struct thread_fsm *self);
static enum async_reply_reason
step_command_fsm_async_reply_reason (struct thread_fsm *self);
/* step_command_fsm's vtable. */
static struct thread_fsm_ops step_command_fsm_ops =
{
NULL,
step_command_fsm_clean_up,
step_command_fsm_should_stop,
NULL, /* return_value */
step_command_fsm_async_reply_reason,
};
/* Allocate a new step_command_fsm. */
static struct step_command_fsm *
new_step_command_fsm (void)
{
struct step_command_fsm *sm;
sm = XCNEW (struct step_command_fsm);
thread_fsm_ctor (&sm->thread_fsm, &step_command_fsm_ops);
return sm;
}
/* Prepare for a step/next/etc. command. Any target resource
allocated here is undone in the FSM's clean_up method. */
static void
step_command_fsm_prepare (struct step_command_fsm *sm,
int skip_subroutines, int single_inst,
int count, struct thread_info *thread)
{
sm->skip_subroutines = skip_subroutines;
sm->single_inst = single_inst;
sm->count = count;
sm->thread = thread->num;
/* Leave the si command alone. */
if (!sm->single_inst || sm->skip_subroutines)
set_longjmp_breakpoint (thread, get_frame_id (get_current_frame ()));
thread->control.stepping_command = 1;
}
static int prepare_one_step (struct step_command_fsm *sm);
static void
step_1 (int skip_subroutines, int single_inst, char *count_string)
{
int count;
int async_exec;
struct cleanup *args_chain;
struct thread_info *thr;
struct step_command_fsm *step_sm;
ERROR_NO_INFERIOR;
ensure_not_tfind_mode ();
ensure_valid_thread ();
ensure_not_running ();
count_string = strip_bg_char (count_string, &async_exec);
args_chain = make_cleanup (xfree, count_string);
prepare_execution_command (¤t_target, async_exec);
count = count_string ? parse_and_eval_long (count_string) : 1;
/* Done with ARGS. */
do_cleanups (args_chain);
clear_proceed_status (1);
/* Setup the execution command state machine to handle all the COUNT