OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [gdb/] [infcmd.c] - Blame information for rev 816

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
/* Memory-access and commands for "inferior" process, for GDB.
2
 
3
   Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4
   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5
   2008, 2009, 2010 Free Software Foundation, Inc.
6
 
7
   This file is part of GDB.
8
 
9
   This program is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation; either version 3 of the License, or
12
   (at your option) any later version.
13
 
14
   This program is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18
 
19
   You should have received a copy of the GNU General Public License
20
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21
 
22
#include "defs.h"
23
#include "arch-utils.h"
24
#include <signal.h>
25
#include "gdb_string.h"
26
#include "symtab.h"
27
#include "gdbtypes.h"
28
#include "frame.h"
29
#include "inferior.h"
30
#include "environ.h"
31
#include "value.h"
32
#include "gdbcmd.h"
33
#include "symfile.h"
34
#include "gdbcore.h"
35
#include "target.h"
36
#include "language.h"
37
#include "symfile.h"
38
#include "objfiles.h"
39
#include "completer.h"
40
#include "ui-out.h"
41
#include "event-top.h"
42
#include "parser-defs.h"
43
#include "regcache.h"
44
#include "reggroups.h"
45
#include "block.h"
46
#include "solib.h"
47
#include <ctype.h>
48
#include "gdb_assert.h"
49
#include "observer.h"
50
#include "target-descriptions.h"
51
#include "user-regs.h"
52
#include "exceptions.h"
53
#include "cli/cli-decode.h"
54
#include "gdbthread.h"
55
#include "valprint.h"
56
#include "inline-frame.h"
57
#include "tracepoint.h"
58
 
59
/* Functions exported for general use, in inferior.h: */
60
 
61
void all_registers_info (char *, int);
62
 
63
void registers_info (char *, int);
64
 
65
void nexti_command (char *, int);
66
 
67
void stepi_command (char *, int);
68
 
69
void continue_command (char *, int);
70
 
71
void interrupt_target_command (char *args, int from_tty);
72
 
73
/* Local functions: */
74
 
75
static void nofp_registers_info (char *, int);
76
 
77
static void print_return_value (struct type *func_type,
78
                                struct type *value_type);
79
 
80
static void until_next_command (int);
81
 
82
static void until_command (char *, int);
83
 
84
static void path_info (char *, int);
85
 
86
static void path_command (char *, int);
87
 
88
static void unset_command (char *, int);
89
 
90
static void float_info (char *, int);
91
 
92
static void disconnect_command (char *, int);
93
 
94
static void unset_environment_command (char *, int);
95
 
96
static void set_environment_command (char *, int);
97
 
98
static void environment_info (char *, int);
99
 
100
static void program_info (char *, int);
101
 
102
static void finish_command (char *, int);
103
 
104
static void signal_command (char *, int);
105
 
106
static void jump_command (char *, int);
107
 
108
static void step_1 (int, int, char *);
109
static void step_once (int skip_subroutines, int single_inst, int count, int thread);
110
 
111
static void next_command (char *, int);
112
 
113
static void step_command (char *, int);
114
 
115
static void run_command (char *, int);
116
 
117
static void run_no_args_command (char *args, int from_tty);
118
 
119
static void go_command (char *line_no, int from_tty);
120
 
121
static int strip_bg_char (char **);
122
 
123
void _initialize_infcmd (void);
124
 
125
#define ERROR_NO_INFERIOR \
126
   if (!target_has_execution) error (_("The program is not being run."));
127
 
128
/* Scratch area where string containing arguments to give to the program will be
129
   stored by 'set args'.  As soon as anything is stored, notice_args_set will
130
   move it into per-inferior storage.  Arguments are separated by spaces. Empty
131
   string (pointer to '\0') means no args.  */
132
 
133
static char *inferior_args_scratch;
134
 
135
/* Scratch area where 'set inferior-tty' will store user-provided value.
136
   We'll immediate copy it into per-inferior storage.  */
137
 
138
static char *inferior_io_terminal_scratch;
139
 
140
/* Pid of our debugged inferior, or 0 if no inferior now.
141
   Since various parts of infrun.c test this to see whether there is a program
142
   being debugged it should be nonzero (currently 3 is used) for remote
143
   debugging.  */
144
 
145
ptid_t inferior_ptid;
146
 
147
/* Address at which inferior stopped.  */
148
 
149
CORE_ADDR stop_pc;
150
 
151
/* Flag indicating that a command has proceeded the inferior past the
152
   current breakpoint.  */
153
 
154
int breakpoint_proceeded;
155
 
156
/* Nonzero if stopped due to completion of a stack dummy routine.  */
157
 
158
enum stop_stack_kind stop_stack_dummy;
159
 
160
/* Nonzero if stopped due to a random (unexpected) signal in inferior
161
   process.  */
162
 
163
int stopped_by_random_signal;
164
 
165
 
166
/* Accessor routines. */
167
 
168
/* Set the io terminal for the current inferior.  Ownership of
169
   TERMINAL_NAME is not transferred.  */
170
 
171
void
172
set_inferior_io_terminal (const char *terminal_name)
173
{
174
  xfree (current_inferior ()->terminal);
175
  current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
176
}
177
 
178
const char *
179
get_inferior_io_terminal (void)
180
{
181
  return current_inferior ()->terminal;
182
}
183
 
184
static void
185
set_inferior_tty_command (char *args, int from_tty,
186
                          struct cmd_list_element *c)
187
{
188
  /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
189
     Now route it to current inferior.  */
190
  set_inferior_io_terminal (inferior_io_terminal_scratch);
191
}
192
 
193
static void
194
show_inferior_tty_command (struct ui_file *file, int from_tty,
195
                           struct cmd_list_element *c, const char *value)
196
{
197
  /* Note that we ignore the passed-in value in favor of computing it
198
     directly.  */
199
  const char *inferior_io_terminal = get_inferior_io_terminal ();
200
 
201
  if (inferior_io_terminal == NULL)
202
    inferior_io_terminal = "";
203
  fprintf_filtered (gdb_stdout,
204
                    _("Terminal for future runs of program being debugged "
205
                      "is \"%s\".\n"), inferior_io_terminal);
206
}
207
 
208
char *
209
get_inferior_args (void)
210
{
211
  if (current_inferior ()->argc != 0)
212
    {
213
      char *n;
214
 
215
      n = construct_inferior_arguments (current_inferior ()->argc,
216
                                        current_inferior ()->argv);
217
      set_inferior_args (n);
218
      xfree (n);
219
    }
220
 
221
  if (current_inferior ()->args == NULL)
222
    current_inferior ()->args = xstrdup ("");
223
 
224
  return current_inferior ()->args;
225
}
226
 
227
/* Set the arguments for the current inferior.  Ownership of
228
   NEWARGS is not transferred.  */
229
 
230
void
231
set_inferior_args (char *newargs)
232
{
233
  xfree (current_inferior ()->args);
234
  current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
235
  current_inferior ()->argc = 0;
236
  current_inferior ()->argv = 0;
237
}
238
 
239
void
240
set_inferior_args_vector (int argc, char **argv)
241
{
242
  current_inferior ()->argc = argc;
243
  current_inferior ()->argv = argv;
244
}
245
 
246
/* Notice when `set args' is run.  */
247
static void
248
set_args_command (char *args, int from_tty, struct cmd_list_element *c)
249
{
250
  /* CLI has assigned the user-provided value to inferior_args_scratch.
251
     Now route it to current inferior.  */
252
  set_inferior_args (inferior_args_scratch);
253
}
254
 
255
/* Notice when `show args' is run.  */
256
static void
257
show_args_command (struct ui_file *file, int from_tty,
258
                   struct cmd_list_element *c, const char *value)
259
{
260
  /* Note that we ignore the passed-in value in favor of computing it
261
     directly.  */
262
  deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
263
}
264
 
265
 
266
/* Compute command-line string given argument vector.  This does the
267
   same shell processing as fork_inferior.  */
268
char *
269
construct_inferior_arguments (int argc, char **argv)
270
{
271
  char *result;
272
 
273
  if (STARTUP_WITH_SHELL)
274
    {
275
      /* This holds all the characters considered special to the
276
         typical Unix shells.  We include `^' because the SunOS
277
         /bin/sh treats it as a synonym for `|'.  */
278
      char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
279
      int i;
280
      int length = 0;
281
      char *out, *cp;
282
 
283
      /* We over-compute the size.  It shouldn't matter.  */
284
      for (i = 0; i < argc; ++i)
285
        length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
286
 
287
      result = (char *) xmalloc (length);
288
      out = result;
289
 
290
      for (i = 0; i < argc; ++i)
291
        {
292
          if (i > 0)
293
            *out++ = ' ';
294
 
295
          /* Need to handle empty arguments specially.  */
296
          if (argv[i][0] == '\0')
297
            {
298
              *out++ = '\'';
299
              *out++ = '\'';
300
            }
301
          else
302
            {
303
              for (cp = argv[i]; *cp; ++cp)
304
                {
305
                  if (*cp == '\n')
306
                    {
307
                      /* A newline cannot be quoted with a backslash (it
308
                         just disappears), only by putting it inside
309
                         quotes.  */
310
                      *out++ = '\'';
311
                      *out++ = '\n';
312
                      *out++ = '\'';
313
                    }
314
                  else
315
                    {
316
                      if (strchr (special, *cp) != NULL)
317
                        *out++ = '\\';
318
                      *out++ = *cp;
319
                    }
320
                }
321
            }
322
        }
323
      *out = '\0';
324
    }
325
  else
326
    {
327
      /* In this case we can't handle arguments that contain spaces,
328
         tabs, or newlines -- see breakup_args().  */
329
      int i;
330
      int length = 0;
331
 
332
      for (i = 0; i < argc; ++i)
333
        {
334
          char *cp = strchr (argv[i], ' ');
335
          if (cp == NULL)
336
            cp = strchr (argv[i], '\t');
337
          if (cp == NULL)
338
            cp = strchr (argv[i], '\n');
339
          if (cp != NULL)
340
            error (_("can't handle command-line argument containing whitespace"));
341
          length += strlen (argv[i]) + 1;
342
        }
343
 
344
      result = (char *) xmalloc (length);
345
      result[0] = '\0';
346
      for (i = 0; i < argc; ++i)
347
        {
348
          if (i > 0)
349
            strcat (result, " ");
350
          strcat (result, argv[i]);
351
        }
352
    }
353
 
354
  return result;
355
}
356
 
357
 
358
/* This function detects whether or not a '&' character (indicating
359
   background execution) has been added as *the last* of the arguments ARGS
360
   of a command. If it has, it removes it and returns 1. Otherwise it
361
   does nothing and returns 0. */
362
static int
363
strip_bg_char (char **args)
364
{
365
  char *p = NULL;
366
 
367
  p = strchr (*args, '&');
368
 
369
  if (p)
370
    {
371
      if (p == (*args + strlen (*args) - 1))
372
        {
373
          if (strlen (*args) > 1)
374
            {
375
              do
376
                p--;
377
              while (*p == ' ' || *p == '\t');
378
              *(p + 1) = '\0';
379
            }
380
          else
381
            *args = 0;
382
          return 1;
383
        }
384
    }
385
  return 0;
386
}
387
 
388
/* Common actions to take after creating any sort of inferior, by any
389
   means (running, attaching, connecting, et cetera).  The target
390
   should be stopped.  */
391
 
392
void
393
post_create_inferior (struct target_ops *target, int from_tty)
394
{
395
  /* Be sure we own the terminal in case write operations are performed.  */
396
  target_terminal_ours ();
397
 
398
  /* If the target hasn't taken care of this already, do it now.
399
     Targets which need to access registers during to_open,
400
     to_create_inferior, or to_attach should do it earlier; but many
401
     don't need to.  */
402
  target_find_description ();
403
 
404
  /* Now that we know the register layout, retrieve current PC.  */
405
  stop_pc = regcache_read_pc (get_current_regcache ());
406
 
407
  if (exec_bfd)
408
    {
409
      /* Create the hooks to handle shared library load and unload
410
         events.  */
411
#ifdef SOLIB_CREATE_INFERIOR_HOOK
412
      SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
413
#else
414
      solib_create_inferior_hook (from_tty);
415
#endif
416
    }
417
 
418
  /* If the solist is global across processes, there's no need to
419
     refetch it here.  */
420
  if (exec_bfd && !gdbarch_has_global_solist (target_gdbarch))
421
    {
422
      /* Sometimes the platform-specific hook loads initial shared
423
         libraries, and sometimes it doesn't.  If it doesn't FROM_TTY will be
424
         incorrectly 0 but such solib targets should be fixed anyway.  If we
425
         made all the inferior hook methods consistent, this call could be
426
         removed.  Call it only after the solib target has been initialized by
427
         solib_create_inferior_hook.  */
428
 
429
#ifdef SOLIB_ADD
430
      SOLIB_ADD (NULL, 0, target, auto_solib_add);
431
#else
432
      solib_add (NULL, 0, target, auto_solib_add);
433
#endif
434
    }
435
 
436
  /* If the user sets watchpoints before execution having started,
437
     then she gets software watchpoints, because GDB can't know which
438
     target will end up being pushed, or if it supports hardware
439
     watchpoints or not.  breakpoint_re_set takes care of promoting
440
     watchpoints to hardware watchpoints if possible, however, if this
441
     new inferior doesn't load shared libraries or we don't pull in
442
     symbols from any other source on this target/arch,
443
     breakpoint_re_set is never called.  Call it now so that software
444
     watchpoints get a chance to be promoted to hardware watchpoints
445
     if the now pushed target supports hardware watchpoints.  */
446
  breakpoint_re_set ();
447
 
448
  observer_notify_inferior_created (target, from_tty);
449
}
450
 
451
/* Kill the inferior if already running.  This function is designed
452
   to be called when we are about to start the execution of the program
453
   from the beginning.  Ask the user to confirm that he wants to restart
454
   the program being debugged when FROM_TTY is non-null.  */
455
 
456
static void
457
kill_if_already_running (int from_tty)
458
{
459
  if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
460
    {
461
      /* Bail out before killing the program if we will not be able to
462
         restart it.  */
463
      target_require_runnable ();
464
 
465
      if (from_tty
466
          && !query (_("The program being debugged has been started already.\n\
467
Start it from the beginning? ")))
468
        error (_("Program not restarted."));
469
      target_kill ();
470
    }
471
}
472
 
473
/* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
474
   a temporary breakpoint at the begining of the main program before
475
   running the program.  */
476
 
477
static void
478
run_command_1 (char *args, int from_tty, int tbreak_at_main)
479
{
480
  char *exec_file;
481
  struct cleanup *old_chain;
482
  ptid_t ptid;
483
 
484
  dont_repeat ();
485
 
486
  kill_if_already_running (from_tty);
487
 
488
  init_wait_for_inferior ();
489
  clear_breakpoint_hit_counts ();
490
 
491
  /* Clean up any leftovers from other runs.  Some other things from
492
     this function should probably be moved into target_pre_inferior.  */
493
  target_pre_inferior (from_tty);
494
 
495
  /* The comment here used to read, "The exec file is re-read every
496
     time we do a generic_mourn_inferior, so we just have to worry
497
     about the symbol file."  The `generic_mourn_inferior' function
498
     gets called whenever the program exits.  However, suppose the
499
     program exits, and *then* the executable file changes?  We need
500
     to check again here.  Since reopen_exec_file doesn't do anything
501
     if the timestamp hasn't changed, I don't see the harm.  */
502
  reopen_exec_file ();
503
  reread_symbols ();
504
 
505
  /* Insert the temporary breakpoint if a location was specified.  */
506
  if (tbreak_at_main)
507
    tbreak_command (main_name (), 0);
508
 
509
  exec_file = (char *) get_exec_file (0);
510
 
511
  if (non_stop && !target_supports_non_stop ())
512
    error (_("The target does not support running in non-stop mode."));
513
 
514
  /* We keep symbols from add-symbol-file, on the grounds that the
515
     user might want to add some symbols before running the program
516
     (right?).  But sometimes (dynamic loading where the user manually
517
     introduces the new symbols with add-symbol-file), the code which
518
     the symbols describe does not persist between runs.  Currently
519
     the user has to manually nuke all symbols between runs if they
520
     want them to go away (PR 2207).  This is probably reasonable.  */
521
 
522
  if (!args)
523
    {
524
      if (target_can_async_p ())
525
        async_disable_stdin ();
526
    }
527
  else
528
    {
529
      int async_exec = strip_bg_char (&args);
530
 
531
      /* If we get a request for running in the bg but the target
532
         doesn't support it, error out. */
533
      if (async_exec && !target_can_async_p ())
534
        error (_("Asynchronous execution not supported on this target."));
535
 
536
      /* If we don't get a request of running in the bg, then we need
537
         to simulate synchronous (fg) execution. */
538
      if (!async_exec && target_can_async_p ())
539
        {
540
          /* Simulate synchronous execution */
541
          async_disable_stdin ();
542
        }
543
 
544
      /* If there were other args, beside '&', process them. */
545
      if (args)
546
        set_inferior_args (args);
547
    }
548
 
549
  if (from_tty)
550
    {
551
      ui_out_field_string (uiout, NULL, "Starting program");
552
      ui_out_text (uiout, ": ");
553
      if (exec_file)
554
        ui_out_field_string (uiout, "execfile", exec_file);
555
      ui_out_spaces (uiout, 1);
556
      /* We call get_inferior_args() because we might need to compute
557
         the value now.  */
558
      ui_out_field_string (uiout, "infargs", get_inferior_args ());
559
      ui_out_text (uiout, "\n");
560
      ui_out_flush (uiout);
561
    }
562
 
563
  /* We call get_inferior_args() because we might need to compute
564
     the value now.  */
565
  target_create_inferior (exec_file, get_inferior_args (),
566
                          environ_vector (current_inferior ()->environment), from_tty);
567
 
568
  /* We're starting off a new process.  When we get out of here, in
569
     non-stop mode, finish the state of all threads of that process,
570
     but leave other threads alone, as they may be stopped in internal
571
     events --- the frontend shouldn't see them as stopped.  In
572
     all-stop, always finish the state of all threads, as we may be
573
     resuming more than just the new process.  */
574
  if (non_stop)
575
    ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
576
  else
577
    ptid = minus_one_ptid;
578
  old_chain = make_cleanup (finish_thread_state_cleanup, &ptid);
579
 
580
  /* Pass zero for FROM_TTY, because at this point the "run" command
581
     has done its thing; now we are setting up the running program.  */
582
  post_create_inferior (&current_target, 0);
583
 
584
  /* Start the target running.  Do not use -1 continuation as it would skip
585
     breakpoint right at the entry point.  */
586
  proceed (regcache_read_pc (get_current_regcache ()), TARGET_SIGNAL_0, 0);
587
 
588
  /* Since there was no error, there's no need to finish the thread
589
     states here.  */
590
  discard_cleanups (old_chain);
591
}
592
 
593
static void
594
run_command (char *args, int from_tty)
595
{
596
  run_command_1 (args, from_tty, 0);
597
}
598
 
599
static void
600
run_no_args_command (char *args, int from_tty)
601
{
602
  set_inferior_args ("");
603
}
604
 
605
 
606
/* Start the execution of the program up until the beginning of the main
607
   program.  */
608
 
609
static void
610
start_command (char *args, int from_tty)
611
{
612
  /* Some languages such as Ada need to search inside the program
613
     minimal symbols for the location where to put the temporary
614
     breakpoint before starting.  */
615
  if (!have_minimal_symbols ())
616
    error (_("No symbol table loaded.  Use the \"file\" command."));
617
 
618
  /* Run the program until reaching the main procedure...  */
619
  run_command_1 (args, from_tty, 1);
620
}
621
 
622
static int
623
proceed_thread_callback (struct thread_info *thread, void *arg)
624
{
625
  /* We go through all threads individually instead of compressing
626
     into a single target `resume_all' request, because some threads
627
     may be stopped in internal breakpoints/events, or stopped waiting
628
     for its turn in the displaced stepping queue (that is, they are
629
     running && !executing).  The target side has no idea about why
630
     the thread is stopped, so a `resume_all' command would resume too
631
     much.  If/when GDB gains a way to tell the target `hold this
632
     thread stopped until I say otherwise', then we can optimize
633
     this.  */
634
  if (!is_stopped (thread->ptid))
635
    return 0;
636
 
637
  switch_to_thread (thread->ptid);
638
  clear_proceed_status ();
639
  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
640
  return 0;
641
}
642
 
643
void
644
ensure_valid_thread (void)
645
{
646
  if (ptid_equal (inferior_ptid, null_ptid)
647
      || is_exited (inferior_ptid))
648
    error (_("\
649
Cannot execute this command without a live selected thread."));
650
}
651
 
652
/* If the user is looking at trace frames, any resumption of execution
653
   is likely to mix up recorded and live target data. So simply
654
   disallow those commands.  */
655
 
656
void
657
ensure_not_tfind_mode (void)
658
{
659
  if (get_traceframe_number () >= 0)
660
    error (_("\
661
Cannot execute this command while looking at trace frames."));
662
}
663
 
664
void
665
continue_1 (int all_threads)
666
{
667
  ERROR_NO_INFERIOR;
668
  ensure_not_tfind_mode ();
669
 
670
  if (non_stop && all_threads)
671
    {
672
      /* Don't error out if the current thread is running, because
673
         there may be other stopped threads.  */
674
      struct cleanup *old_chain;
675
 
676
      /* Backup current thread and selected frame.  */
677
      old_chain = make_cleanup_restore_current_thread ();
678
 
679
      iterate_over_threads (proceed_thread_callback, NULL);
680
 
681
      /* Restore selected ptid.  */
682
      do_cleanups (old_chain);
683
    }
684
  else
685
    {
686
      ensure_valid_thread ();
687
      ensure_not_running ();
688
      clear_proceed_status ();
689
      proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
690
    }
691
}
692
 
693
/* continue [-a] [proceed-count] [&]  */
694
void
695
continue_command (char *args, int from_tty)
696
{
697
  int async_exec = 0;
698
  int all_threads = 0;
699
  ERROR_NO_INFERIOR;
700
 
701
  /* Find out whether we must run in the background. */
702
  if (args != NULL)
703
    async_exec = strip_bg_char (&args);
704
 
705
  /* If we must run in the background, but the target can't do it,
706
     error out. */
707
  if (async_exec && !target_can_async_p ())
708
    error (_("Asynchronous execution not supported on this target."));
709
 
710
  /* If we are not asked to run in the bg, then prepare to run in the
711
     foreground, synchronously. */
712
  if (!async_exec && target_can_async_p ())
713
    {
714
      /* Simulate synchronous execution */
715
      async_disable_stdin ();
716
    }
717
 
718
  if (args != NULL)
719
    {
720
      if (strncmp (args, "-a", sizeof ("-a") - 1) == 0)
721
        {
722
          all_threads = 1;
723
          args += sizeof ("-a") - 1;
724
          if (*args == '\0')
725
            args = NULL;
726
        }
727
    }
728
 
729
  if (!non_stop && all_threads)
730
    error (_("`-a' is meaningless in all-stop mode."));
731
 
732
  if (args != NULL && all_threads)
733
    error (_("\
734
Can't resume all threads and specify proceed count simultaneously."));
735
 
736
  /* If we have an argument left, set proceed count of breakpoint we
737
     stopped at.  */
738
  if (args != NULL)
739
    {
740
      bpstat bs = NULL;
741
      int num, stat;
742
      int stopped = 0;
743
      struct thread_info *tp;
744
 
745
      if (non_stop)
746
        tp = find_thread_ptid (inferior_ptid);
747
      else
748
        {
749
          ptid_t last_ptid;
750
          struct target_waitstatus ws;
751
 
752
          get_last_target_status (&last_ptid, &ws);
753
          tp = find_thread_ptid (last_ptid);
754
        }
755
      if (tp != NULL)
756
        bs = tp->stop_bpstat;
757
 
758
      while ((stat = bpstat_num (&bs, &num)) != 0)
759
        if (stat > 0)
760
          {
761
            set_ignore_count (num,
762
                              parse_and_eval_long (args) - 1,
763
                              from_tty);
764
            /* set_ignore_count prints a message ending with a period.
765
               So print two spaces before "Continuing.".  */
766
            if (from_tty)
767
              printf_filtered ("  ");
768
            stopped = 1;
769
          }
770
 
771
      if (!stopped && from_tty)
772
        {
773
          printf_filtered
774
            ("Not stopped at any breakpoint; argument ignored.\n");
775
        }
776
    }
777
 
778
  if (from_tty)
779
    printf_filtered (_("Continuing.\n"));
780
 
781
  continue_1 (all_threads);
782
}
783
 
784
/* Record the starting point of a "step" or "next" command.  */
785
 
786
static void
787
set_step_frame (void)
788
{
789
  struct symtab_and_line sal;
790
 
791
  find_frame_sal (get_current_frame (), &sal);
792
  set_step_info (get_current_frame (), sal);
793
}
794
 
795
/* Step until outside of current statement.  */
796
 
797
static void
798
step_command (char *count_string, int from_tty)
799
{
800
  step_1 (0, 0, count_string);
801
}
802
 
803
/* Likewise, but skip over subroutine calls as if single instructions.  */
804
 
805
static void
806
next_command (char *count_string, int from_tty)
807
{
808
  step_1 (1, 0, count_string);
809
}
810
 
811
/* Likewise, but step only one instruction.  */
812
 
813
void
814
stepi_command (char *count_string, int from_tty)
815
{
816
  step_1 (0, 1, count_string);
817
}
818
 
819
void
820
nexti_command (char *count_string, int from_tty)
821
{
822
  step_1 (1, 1, count_string);
823
}
824
 
825
static void
826
delete_longjmp_breakpoint_cleanup (void *arg)
827
{
828
  int thread = * (int *) arg;
829
  delete_longjmp_breakpoint (thread);
830
}
831
 
832
static void
833
step_1 (int skip_subroutines, int single_inst, char *count_string)
834
{
835
  int count = 1;
836
  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
837
  int async_exec = 0;
838
  int thread = -1;
839
 
840
  ERROR_NO_INFERIOR;
841
  ensure_not_tfind_mode ();
842
  ensure_valid_thread ();
843
  ensure_not_running ();
844
 
845
  if (count_string)
846
    async_exec = strip_bg_char (&count_string);
847
 
848
  /* If we get a request for running in the bg but the target
849
     doesn't support it, error out. */
850
  if (async_exec && !target_can_async_p ())
851
    error (_("Asynchronous execution not supported on this target."));
852
 
853
  /* If we don't get a request of running in the bg, then we need
854
     to simulate synchronous (fg) execution. */
855
  if (!async_exec && target_can_async_p ())
856
    {
857
      /* Simulate synchronous execution */
858
      async_disable_stdin ();
859
    }
860
 
861
  count = count_string ? parse_and_eval_long (count_string) : 1;
862
 
863
  if (!single_inst || skip_subroutines)         /* leave si command alone */
864
    {
865
      if (in_thread_list (inferior_ptid))
866
        thread = pid_to_thread_id (inferior_ptid);
867
 
868
      set_longjmp_breakpoint (thread);
869
 
870
      make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
871
    }
872
 
873
  /* In synchronous case, all is well; each step_once call will step once.  */
874
  if (!target_can_async_p ())
875
    {
876
      for (; count > 0; count--)
877
        {
878
          struct thread_info *tp;
879
 
880
          step_once (skip_subroutines, single_inst, count, thread);
881
 
882
          if (target_has_execution
883
              && !ptid_equal (inferior_ptid, null_ptid))
884
            tp = inferior_thread ();
885
          else
886
            tp = NULL;
887
 
888
          if (!tp || !tp->stop_step || !tp->step_multi)
889
            {
890
              /* If we stopped for some reason that is not stepping
891
                 there are no further steps to make.  */
892
              if (tp)
893
                tp->step_multi = 0;
894
              break;
895
            }
896
        }
897
 
898
      do_cleanups (cleanups);
899
    }
900
  else
901
    {
902
      /* In the case of an asynchronous target things get complicated;
903
         do only one step for now, before returning control to the
904
         event loop.  Let the continuation figure out how many other
905
         steps we need to do, and handle them one at the time, through
906
         step_once.  */
907
      step_once (skip_subroutines, single_inst, count, thread);
908
 
909
      /* We are running, and the continuation is installed.  It will
910
         disable the longjmp breakpoint as appropriate.  */
911
      discard_cleanups (cleanups);
912
    }
913
}
914
 
915
struct step_1_continuation_args
916
{
917
  int count;
918
  int skip_subroutines;
919
  int single_inst;
920
  int thread;
921
};
922
 
923
/* Called after we are done with one step operation, to check whether
924
   we need to step again, before we print the prompt and return control
925
   to the user. If count is > 1, we will need to do one more call to
926
   proceed(), via step_once(). Basically it is like step_once and
927
   step_1_continuation are co-recursive. */
928
static void
929
step_1_continuation (void *args)
930
{
931
  struct step_1_continuation_args *a = args;
932
 
933
  if (target_has_execution)
934
    {
935
      struct thread_info *tp;
936
 
937
      tp = inferior_thread ();
938
      if (tp->step_multi && tp->stop_step)
939
        {
940
          /* There are more steps to make, and we did stop due to
941
             ending a stepping range.  Do another step.  */
942
          step_once (a->skip_subroutines, a->single_inst,
943
                     a->count - 1, a->thread);
944
          return;
945
        }
946
      tp->step_multi = 0;
947
    }
948
 
949
  /* We either stopped for some reason that is not stepping, or there
950
     are no further steps to make.  Cleanup.  */
951
  if (!a->single_inst || a->skip_subroutines)
952
    delete_longjmp_breakpoint (a->thread);
953
}
954
 
955
/* Do just one step operation.  This is useful to implement the 'step
956
   n' kind of commands.  In case of asynchronous targets, we will have
957
   to set up a continuation to be done after the target stops (after
958
   this one step).  For synch targets, the caller handles further
959
   stepping.  */
960
 
961
static void
962
step_once (int skip_subroutines, int single_inst, int count, int thread)
963
{
964
  struct frame_info *frame = get_current_frame ();
965
 
966
  if (count > 0)
967
    {
968
      /* Don't assume THREAD is a valid thread id.  It is set to -1 if
969
         the longjmp breakpoint was not required.  Use the
970
         INFERIOR_PTID thread instead, which is the same thread when
971
         THREAD is set.  */
972
      struct thread_info *tp = inferior_thread ();
973
 
974
      clear_proceed_status ();
975
      set_step_frame ();
976
 
977
      if (!single_inst)
978
        {
979
          CORE_ADDR pc;
980
 
981
          /* Step at an inlined function behaves like "down".  */
982
          if (!skip_subroutines && !single_inst
983
              && inline_skipped_frames (inferior_ptid))
984
            {
985
              step_into_inline_frame (inferior_ptid);
986
              if (count > 1)
987
                step_once (skip_subroutines, single_inst, count - 1, thread);
988
              else
989
                /* Pretend that we've stopped.  */
990
                normal_stop ();
991
              return;
992
            }
993
 
994
          pc = get_frame_pc (frame);
995
          find_pc_line_pc_range (pc,
996
                                 &tp->step_range_start, &tp->step_range_end);
997
 
998
          /* If we have no line info, switch to stepi mode.  */
999
          if (tp->step_range_end == 0 && step_stop_if_no_debug)
1000
            tp->step_range_start = tp->step_range_end = 1;
1001
          else if (tp->step_range_end == 0)
1002
            {
1003
              char *name;
1004
 
1005
              if (find_pc_partial_function (pc, &name,
1006
                                            &tp->step_range_start,
1007
                                            &tp->step_range_end) == 0)
1008
                error (_("Cannot find bounds of current function"));
1009
 
1010
              target_terminal_ours ();
1011
              printf_filtered (_("\
1012
Single stepping until exit from function %s,\n\
1013
which has no line number information.\n"), name);
1014
            }
1015
        }
1016
      else
1017
        {
1018
          /* Say we are stepping, but stop after one insn whatever it does.  */
1019
          tp->step_range_start = tp->step_range_end = 1;
1020
          if (!skip_subroutines)
1021
            /* It is stepi.
1022
               Don't step over function calls, not even to functions lacking
1023
               line numbers.  */
1024
            tp->step_over_calls = STEP_OVER_NONE;
1025
        }
1026
 
1027
      if (skip_subroutines)
1028
        tp->step_over_calls = STEP_OVER_ALL;
1029
 
1030
      tp->step_multi = (count > 1);
1031
      proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1032
 
1033
      /* For async targets, register a continuation to do any
1034
         additional steps.  For sync targets, the caller will handle
1035
         further stepping.  */
1036
      if (target_can_async_p ())
1037
        {
1038
          struct step_1_continuation_args *args;
1039
 
1040
          args = xmalloc (sizeof (*args));
1041
          args->skip_subroutines = skip_subroutines;
1042
          args->single_inst = single_inst;
1043
          args->count = count;
1044
          args->thread = thread;
1045
 
1046
          add_intermediate_continuation (tp, step_1_continuation, args, xfree);
1047
        }
1048
    }
1049
}
1050
 
1051
 
1052
/* Continue program at specified address.  */
1053
 
1054
static void
1055
jump_command (char *arg, int from_tty)
1056
{
1057
  struct gdbarch *gdbarch = get_current_arch ();
1058
  CORE_ADDR addr;
1059
  struct symtabs_and_lines sals;
1060
  struct symtab_and_line sal;
1061
  struct symbol *fn;
1062
  struct symbol *sfn;
1063
  int async_exec = 0;
1064
 
1065
  ERROR_NO_INFERIOR;
1066
  ensure_not_tfind_mode ();
1067
  ensure_valid_thread ();
1068
  ensure_not_running ();
1069
 
1070
  /* Find out whether we must run in the background. */
1071
  if (arg != NULL)
1072
    async_exec = strip_bg_char (&arg);
1073
 
1074
  /* If we must run in the background, but the target can't do it,
1075
     error out. */
1076
  if (async_exec && !target_can_async_p ())
1077
    error (_("Asynchronous execution not supported on this target."));
1078
 
1079
  if (!arg)
1080
    error_no_arg (_("starting address"));
1081
 
1082
  sals = decode_line_spec_1 (arg, 1);
1083
  if (sals.nelts != 1)
1084
    {
1085
      error (_("Unreasonable jump request"));
1086
    }
1087
 
1088
  sal = sals.sals[0];
1089
  xfree (sals.sals);
1090
 
1091
  if (sal.symtab == 0 && sal.pc == 0)
1092
    error (_("No source file has been specified."));
1093
 
1094
  resolve_sal_pc (&sal);        /* May error out */
1095
 
1096
  /* See if we are trying to jump to another function. */
1097
  fn = get_frame_function (get_current_frame ());
1098
  sfn = find_pc_function (sal.pc);
1099
  if (fn != NULL && sfn != fn)
1100
    {
1101
      if (!query (_("Line %d is not in `%s'.  Jump anyway? "), sal.line,
1102
                  SYMBOL_PRINT_NAME (fn)))
1103
        {
1104
          error (_("Not confirmed."));
1105
          /* NOTREACHED */
1106
        }
1107
    }
1108
 
1109
  if (sfn != NULL)
1110
    {
1111
      fixup_symbol_section (sfn, 0);
1112
      if (section_is_overlay (SYMBOL_OBJ_SECTION (sfn)) &&
1113
          !section_is_mapped (SYMBOL_OBJ_SECTION (sfn)))
1114
        {
1115
          if (!query (_("WARNING!!!  Destination is in unmapped overlay!  Jump anyway? ")))
1116
            {
1117
              error (_("Not confirmed."));
1118
              /* NOTREACHED */
1119
            }
1120
        }
1121
    }
1122
 
1123
  addr = sal.pc;
1124
 
1125
  if (from_tty)
1126
    {
1127
      printf_filtered (_("Continuing at "));
1128
      fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
1129
      printf_filtered (".\n");
1130
    }
1131
 
1132
  /* If we are not asked to run in the bg, then prepare to run in the
1133
     foreground, synchronously. */
1134
  if (!async_exec && target_can_async_p ())
1135
    {
1136
      /* Simulate synchronous execution */
1137
      async_disable_stdin ();
1138
    }
1139
 
1140
  clear_proceed_status ();
1141
  proceed (addr, TARGET_SIGNAL_0, 0);
1142
}
1143
 
1144
 
1145
/* Go to line or address in current procedure */
1146
static void
1147
go_command (char *line_no, int from_tty)
1148
{
1149
  if (line_no == (char *) NULL || !*line_no)
1150
    printf_filtered (_("Usage: go <location>\n"));
1151
  else
1152
    {
1153
      tbreak_command (line_no, from_tty);
1154
      jump_command (line_no, from_tty);
1155
    }
1156
}
1157
 
1158
 
1159
/* Continue program giving it specified signal.  */
1160
 
1161
static void
1162
signal_command (char *signum_exp, int from_tty)
1163
{
1164
  enum target_signal oursig;
1165
  int async_exec = 0;
1166
 
1167
  dont_repeat ();               /* Too dangerous.  */
1168
  ERROR_NO_INFERIOR;
1169
  ensure_not_tfind_mode ();
1170
  ensure_valid_thread ();
1171
  ensure_not_running ();
1172
 
1173
  /* Find out whether we must run in the background.  */
1174
  if (signum_exp != NULL)
1175
    async_exec = strip_bg_char (&signum_exp);
1176
 
1177
  /* If we must run in the background, but the target can't do it,
1178
     error out.  */
1179
  if (async_exec && !target_can_async_p ())
1180
    error (_("Asynchronous execution not supported on this target."));
1181
 
1182
  /* If we are not asked to run in the bg, then prepare to run in the
1183
     foreground, synchronously.  */
1184
  if (!async_exec && target_can_async_p ())
1185
    {
1186
      /* Simulate synchronous execution.  */
1187
      async_disable_stdin ();
1188
    }
1189
 
1190
  if (!signum_exp)
1191
    error_no_arg (_("signal number"));
1192
 
1193
  /* It would be even slicker to make signal names be valid expressions,
1194
     (the type could be "enum $signal" or some such), then the user could
1195
     assign them to convenience variables.  */
1196
  oursig = target_signal_from_name (signum_exp);
1197
 
1198
  if (oursig == TARGET_SIGNAL_UNKNOWN)
1199
    {
1200
      /* No, try numeric.  */
1201
      int num = parse_and_eval_long (signum_exp);
1202
 
1203
      if (num == 0)
1204
        oursig = TARGET_SIGNAL_0;
1205
      else
1206
        oursig = target_signal_from_command (num);
1207
    }
1208
 
1209
  if (from_tty)
1210
    {
1211
      if (oursig == TARGET_SIGNAL_0)
1212
        printf_filtered (_("Continuing with no signal.\n"));
1213
      else
1214
        printf_filtered (_("Continuing with signal %s.\n"),
1215
                         target_signal_to_name (oursig));
1216
    }
1217
 
1218
  clear_proceed_status ();
1219
  proceed ((CORE_ADDR) -1, oursig, 0);
1220
}
1221
 
1222
/* Proceed until we reach a different source line with pc greater than
1223
   our current one or exit the function.  We skip calls in both cases.
1224
 
1225
   Note that eventually this command should probably be changed so
1226
   that only source lines are printed out when we hit the breakpoint
1227
   we set.  This may involve changes to wait_for_inferior and the
1228
   proceed status code.  */
1229
 
1230
static void
1231
until_next_command (int from_tty)
1232
{
1233
  struct frame_info *frame;
1234
  CORE_ADDR pc;
1235
  struct symbol *func;
1236
  struct symtab_and_line sal;
1237
  struct thread_info *tp = inferior_thread ();
1238
 
1239
  clear_proceed_status ();
1240
  set_step_frame ();
1241
 
1242
  frame = get_current_frame ();
1243
 
1244
  /* Step until either exited from this function or greater
1245
     than the current line (if in symbolic section) or pc (if
1246
     not). */
1247
 
1248
  pc = get_frame_pc (frame);
1249
  func = find_pc_function (pc);
1250
 
1251
  if (!func)
1252
    {
1253
      struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
1254
 
1255
      if (msymbol == NULL)
1256
        error (_("Execution is not within a known function."));
1257
 
1258
      tp->step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
1259
      tp->step_range_end = pc;
1260
    }
1261
  else
1262
    {
1263
      sal = find_pc_line (pc, 0);
1264
 
1265
      tp->step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1266
      tp->step_range_end = sal.end;
1267
    }
1268
 
1269
  tp->step_over_calls = STEP_OVER_ALL;
1270
 
1271
  tp->step_multi = 0;            /* Only one call to proceed */
1272
 
1273
  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1274
}
1275
 
1276
static void
1277
until_command (char *arg, int from_tty)
1278
{
1279
  int async_exec = 0;
1280
 
1281
  ERROR_NO_INFERIOR;
1282
  ensure_not_tfind_mode ();
1283
  ensure_valid_thread ();
1284
  ensure_not_running ();
1285
 
1286
  /* Find out whether we must run in the background. */
1287
  if (arg != NULL)
1288
    async_exec = strip_bg_char (&arg);
1289
 
1290
  /* If we must run in the background, but the target can't do it,
1291
     error out. */
1292
  if (async_exec && !target_can_async_p ())
1293
    error (_("Asynchronous execution not supported on this target."));
1294
 
1295
  /* If we are not asked to run in the bg, then prepare to run in the
1296
     foreground, synchronously. */
1297
  if (!async_exec && target_can_async_p ())
1298
    {
1299
      /* Simulate synchronous execution */
1300
      async_disable_stdin ();
1301
    }
1302
 
1303
  if (arg)
1304
    until_break_command (arg, from_tty, 0);
1305
  else
1306
    until_next_command (from_tty);
1307
}
1308
 
1309
static void
1310
advance_command (char *arg, int from_tty)
1311
{
1312
  int async_exec = 0;
1313
 
1314
  ERROR_NO_INFERIOR;
1315
  ensure_not_tfind_mode ();
1316
  ensure_valid_thread ();
1317
  ensure_not_running ();
1318
 
1319
  if (arg == NULL)
1320
    error_no_arg (_("a location"));
1321
 
1322
  /* Find out whether we must run in the background.  */
1323
  if (arg != NULL)
1324
    async_exec = strip_bg_char (&arg);
1325
 
1326
  /* If we must run in the background, but the target can't do it,
1327
     error out.  */
1328
  if (async_exec && !target_can_async_p ())
1329
    error (_("Asynchronous execution not supported on this target."));
1330
 
1331
  /* If we are not asked to run in the bg, then prepare to run in the
1332
     foreground, synchronously.  */
1333
  if (!async_exec && target_can_async_p ())
1334
    {
1335
      /* Simulate synchronous execution.  */
1336
      async_disable_stdin ();
1337
    }
1338
 
1339
  until_break_command (arg, from_tty, 1);
1340
}
1341
 
1342
/* Print the result of a function at the end of a 'finish' command.  */
1343
 
1344
static void
1345
print_return_value (struct type *func_type, struct type *value_type)
1346
{
1347
  struct gdbarch *gdbarch = get_regcache_arch (stop_registers);
1348
  struct cleanup *old_chain;
1349
  struct ui_stream *stb;
1350
  struct value *value;
1351
 
1352
  CHECK_TYPEDEF (value_type);
1353
  gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1354
 
1355
  /* FIXME: 2003-09-27: When returning from a nested inferior function
1356
     call, it's possible (with no help from the architecture vector)
1357
     to locate and return/print a "struct return" value.  This is just
1358
     a more complicated case of what is already being done in in the
1359
     inferior function call code.  In fact, when inferior function
1360
     calls are made async, this will likely be made the norm.  */
1361
 
1362
  switch (gdbarch_return_value (gdbarch, func_type, value_type,
1363
                                NULL, NULL, NULL))
1364
    {
1365
    case RETURN_VALUE_REGISTER_CONVENTION:
1366
    case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1367
    case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1368
      value = allocate_value (value_type);
1369
      gdbarch_return_value (gdbarch, func_type, value_type, stop_registers,
1370
                            value_contents_raw (value), NULL);
1371
      break;
1372
    case RETURN_VALUE_STRUCT_CONVENTION:
1373
      value = NULL;
1374
      break;
1375
    default:
1376
      internal_error (__FILE__, __LINE__, _("bad switch"));
1377
    }
1378
 
1379
  if (value)
1380
    {
1381
      struct value_print_options opts;
1382
 
1383
      /* Print it.  */
1384
      stb = ui_out_stream_new (uiout);
1385
      old_chain = make_cleanup_ui_out_stream_delete (stb);
1386
      ui_out_text (uiout, "Value returned is ");
1387
      ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1388
                        record_latest_value (value));
1389
      ui_out_text (uiout, " = ");
1390
      get_raw_print_options (&opts);
1391
      value_print (value, stb->stream, &opts);
1392
      ui_out_field_stream (uiout, "return-value", stb);
1393
      ui_out_text (uiout, "\n");
1394
      do_cleanups (old_chain);
1395
    }
1396
  else
1397
    {
1398
      ui_out_text (uiout, "Value returned has type: ");
1399
      ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
1400
      ui_out_text (uiout, ".");
1401
      ui_out_text (uiout, " Cannot determine contents\n");
1402
    }
1403
}
1404
 
1405
/* Stuff that needs to be done by the finish command after the target
1406
   has stopped.  In asynchronous mode, we wait for the target to stop
1407
   in the call to poll or select in the event loop, so it is
1408
   impossible to do all the stuff as part of the finish_command
1409
   function itself.  The only chance we have to complete this command
1410
   is in fetch_inferior_event, which is called by the event loop as
1411
   soon as it detects that the target has stopped. This function is
1412
   called via the cmd_continuation pointer.  */
1413
 
1414
struct finish_command_continuation_args
1415
{
1416
  struct breakpoint *breakpoint;
1417
  struct symbol *function;
1418
};
1419
 
1420
static void
1421
finish_command_continuation (void *arg)
1422
{
1423
  struct finish_command_continuation_args *a = arg;
1424
  struct thread_info *tp = NULL;
1425
  bpstat bs = NULL;
1426
 
1427
  if (!ptid_equal (inferior_ptid, null_ptid)
1428
      && target_has_execution
1429
      && is_stopped (inferior_ptid))
1430
    {
1431
      tp = inferior_thread ();
1432
      bs = tp->stop_bpstat;
1433
    }
1434
 
1435
  if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL
1436
      && a->function != NULL)
1437
    {
1438
      struct type *value_type;
1439
 
1440
      value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function));
1441
      if (!value_type)
1442
        internal_error (__FILE__, __LINE__,
1443
                        _("finish_command: function has no target type"));
1444
 
1445
      if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1446
        {
1447
          volatile struct gdb_exception ex;
1448
 
1449
          TRY_CATCH (ex, RETURN_MASK_ALL)
1450
            {
1451
              /* print_return_value can throw an exception in some
1452
                 circumstances.  We need to catch this so that we still
1453
                 delete the breakpoint.  */
1454
              print_return_value (SYMBOL_TYPE (a->function), value_type);
1455
            }
1456
          if (ex.reason < 0)
1457
            exception_print (gdb_stdout, ex);
1458
        }
1459
    }
1460
 
1461
  /* We suppress normal call of normal_stop observer and do it here so
1462
     that the *stopped notification includes the return value.  */
1463
  if (bs != NULL && tp->proceed_to_finish)
1464
    observer_notify_normal_stop (bs, 1 /* print frame */);
1465
  delete_breakpoint (a->breakpoint);
1466
}
1467
 
1468
static void
1469
finish_command_continuation_free_arg (void *arg)
1470
{
1471
  xfree (arg);
1472
}
1473
 
1474
/* finish_backward -- helper function for finish_command.  */
1475
 
1476
static void
1477
finish_backward (struct symbol *function)
1478
{
1479
  struct symtab_and_line sal;
1480
  struct thread_info *tp = inferior_thread ();
1481
  struct breakpoint *breakpoint;
1482
  struct cleanup *old_chain;
1483
  CORE_ADDR pc;
1484
  CORE_ADDR func_addr;
1485
  int back_up;
1486
 
1487
  pc = get_frame_pc (get_current_frame ());
1488
 
1489
  if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
1490
    internal_error (__FILE__, __LINE__,
1491
                    _("Finish: couldn't find function."));
1492
 
1493
  sal = find_pc_line (func_addr, 0);
1494
 
1495
  /* We don't need a return value.  */
1496
  tp->proceed_to_finish = 0;
1497
  /* Special case: if we're sitting at the function entry point,
1498
     then all we need to do is take a reverse singlestep.  We
1499
     don't need to set a breakpoint, and indeed it would do us
1500
     no good to do so.
1501
 
1502
     Note that this can only happen at frame #0, since there's
1503
     no way that a function up the stack can have a return address
1504
     that's equal to its entry point.  */
1505
 
1506
  if (sal.pc != pc)
1507
    {
1508
      struct frame_info *frame = get_selected_frame (NULL);
1509
      struct gdbarch *gdbarch = get_frame_arch (frame);
1510
 
1511
      /* Set breakpoint and continue.  */
1512
      breakpoint =
1513
        set_momentary_breakpoint (gdbarch, sal,
1514
                                  get_stack_frame_id (frame),
1515
                                  bp_breakpoint);
1516
      /* Tell the breakpoint to keep quiet.  We won't be done
1517
         until we've done another reverse single-step.  */
1518
      make_breakpoint_silent (breakpoint);
1519
      old_chain = make_cleanup_delete_breakpoint (breakpoint);
1520
      proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1521
      /* We will be stopped when proceed returns.  */
1522
      back_up = bpstat_find_breakpoint (tp->stop_bpstat, breakpoint) != NULL;
1523
      do_cleanups (old_chain);
1524
    }
1525
  else
1526
    back_up = 1;
1527
  if (back_up)
1528
    {
1529
      /* If in fact we hit the step-resume breakpoint (and not
1530
         some other breakpoint), then we're almost there --
1531
         we just need to back up by one more single-step.  */
1532
      tp->step_range_start = tp->step_range_end = 1;
1533
      proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1534
    }
1535
  return;
1536
}
1537
 
1538
/* finish_forward -- helper function for finish_command.  */
1539
 
1540
static void
1541
finish_forward (struct symbol *function, struct frame_info *frame)
1542
{
1543
  struct gdbarch *gdbarch = get_frame_arch (frame);
1544
  struct symtab_and_line sal;
1545
  struct thread_info *tp = inferior_thread ();
1546
  struct breakpoint *breakpoint;
1547
  struct cleanup *old_chain;
1548
  struct finish_command_continuation_args *cargs;
1549
 
1550
  sal = find_pc_line (get_frame_pc (frame), 0);
1551
  sal.pc = get_frame_pc (frame);
1552
 
1553
  breakpoint = set_momentary_breakpoint (gdbarch, sal,
1554
                                         get_stack_frame_id (frame),
1555
                                         bp_finish);
1556
 
1557
  old_chain = make_cleanup_delete_breakpoint (breakpoint);
1558
 
1559
  tp->proceed_to_finish = 1;    /* We want stop_registers, please...  */
1560
  cargs = xmalloc (sizeof (*cargs));
1561
 
1562
  cargs->breakpoint = breakpoint;
1563
  cargs->function = function;
1564
  add_continuation (tp, finish_command_continuation, cargs,
1565
                    finish_command_continuation_free_arg);
1566
  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1567
 
1568
  discard_cleanups (old_chain);
1569
  if (!target_can_async_p ())
1570
    do_all_continuations ();
1571
}
1572
 
1573
/* "finish": Set a temporary breakpoint at the place the selected
1574
   frame will return to, then continue.  */
1575
 
1576
static void
1577
finish_command (char *arg, int from_tty)
1578
{
1579
  struct frame_info *frame;
1580
  struct symbol *function;
1581
 
1582
  int async_exec = 0;
1583
 
1584
  ERROR_NO_INFERIOR;
1585
  ensure_not_tfind_mode ();
1586
  ensure_valid_thread ();
1587
  ensure_not_running ();
1588
 
1589
  /* Find out whether we must run in the background.  */
1590
  if (arg != NULL)
1591
    async_exec = strip_bg_char (&arg);
1592
 
1593
  /* If we must run in the background, but the target can't do it,
1594
     error out.  */
1595
  if (async_exec && !target_can_async_p ())
1596
    error (_("Asynchronous execution not supported on this target."));
1597
 
1598
  /* Don't try to async in reverse.  */
1599
  if (async_exec && execution_direction == EXEC_REVERSE)
1600
    error (_("Asynchronous 'finish' not supported in reverse."));
1601
 
1602
  /* If we are not asked to run in the bg, then prepare to run in the
1603
     foreground, synchronously.  */
1604
  if (!async_exec && target_can_async_p ())
1605
    {
1606
      /* Simulate synchronous execution.  */
1607
      async_disable_stdin ();
1608
    }
1609
 
1610
  if (arg)
1611
    error (_("The \"finish\" command does not take any arguments."));
1612
 
1613
  frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
1614
  if (frame == 0)
1615
    error (_("\"finish\" not meaningful in the outermost frame."));
1616
 
1617
  clear_proceed_status ();
1618
 
1619
  /* Finishing from an inline frame is completely different.  We don't
1620
     try to show the "return value" - no way to locate it.  So we do
1621
     not need a completion.  */
1622
  if (get_frame_type (get_selected_frame (_("No selected frame.")))
1623
      == INLINE_FRAME)
1624
    {
1625
      /* Claim we are stepping in the calling frame.  An empty step
1626
         range means that we will stop once we aren't in a function
1627
         called by that frame.  We don't use the magic "1" value for
1628
         step_range_end, because then infrun will think this is nexti,
1629
         and not step over the rest of this inlined function call.  */
1630
      struct thread_info *tp = inferior_thread ();
1631
      struct symtab_and_line empty_sal;
1632
 
1633
      init_sal (&empty_sal);
1634
      set_step_info (frame, empty_sal);
1635
      tp->step_range_start = tp->step_range_end = get_frame_pc (frame);
1636
      tp->step_over_calls = STEP_OVER_ALL;
1637
 
1638
      /* Print info on the selected frame, including level number but not
1639
         source.  */
1640
      if (from_tty)
1641
        {
1642
          printf_filtered (_("Run till exit from "));
1643
          print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
1644
        }
1645
 
1646
      proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1647
      return;
1648
    }
1649
 
1650
  /* Find the function we will return from.  */
1651
 
1652
  function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
1653
 
1654
  /* Print info on the selected frame, including level number but not
1655
     source.  */
1656
  if (from_tty)
1657
    {
1658
      if (execution_direction == EXEC_REVERSE)
1659
        printf_filtered (_("Run back to call of "));
1660
      else
1661
        printf_filtered (_("Run till exit from "));
1662
 
1663
      print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
1664
    }
1665
 
1666
  if (execution_direction == EXEC_REVERSE)
1667
    finish_backward (function);
1668
  else
1669
    finish_forward (function, frame);
1670
}
1671
 
1672
 
1673
static void
1674
program_info (char *args, int from_tty)
1675
{
1676
  bpstat bs;
1677
  int num, stat;
1678
  struct thread_info *tp;
1679
  ptid_t ptid;
1680
 
1681
  if (!target_has_execution)
1682
    {
1683
      printf_filtered (_("The program being debugged is not being run.\n"));
1684
      return;
1685
    }
1686
 
1687
  if (non_stop)
1688
    ptid = inferior_ptid;
1689
  else
1690
    {
1691
      struct target_waitstatus ws;
1692
 
1693
      get_last_target_status (&ptid, &ws);
1694
    }
1695
 
1696
  if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
1697
    error (_("Invalid selected thread."));
1698
  else if (is_running (ptid))
1699
    error (_("Selected thread is running."));
1700
 
1701
  tp = find_thread_ptid (ptid);
1702
  bs = tp->stop_bpstat;
1703
  stat = bpstat_num (&bs, &num);
1704
 
1705
  target_files_info ();
1706
  printf_filtered (_("Program stopped at %s.\n"),
1707
                   paddress (target_gdbarch, stop_pc));
1708
  if (tp->stop_step)
1709
    printf_filtered (_("It stopped after being stepped.\n"));
1710
  else if (stat != 0)
1711
    {
1712
      /* There may be several breakpoints in the same place, so this
1713
         isn't as strange as it seems.  */
1714
      while (stat != 0)
1715
        {
1716
          if (stat < 0)
1717
            {
1718
              printf_filtered (_("\
1719
It stopped at a breakpoint that has since been deleted.\n"));
1720
            }
1721
          else
1722
            printf_filtered (_("It stopped at breakpoint %d.\n"), num);
1723
          stat = bpstat_num (&bs, &num);
1724
        }
1725
    }
1726
  else if (tp->stop_signal != TARGET_SIGNAL_0)
1727
    {
1728
      printf_filtered (_("It stopped with signal %s, %s.\n"),
1729
                       target_signal_to_name (tp->stop_signal),
1730
                       target_signal_to_string (tp->stop_signal));
1731
    }
1732
 
1733
  if (!from_tty)
1734
    {
1735
      printf_filtered (_("\
1736
Type \"info stack\" or \"info registers\" for more information.\n"));
1737
    }
1738
}
1739
 
1740
static void
1741
environment_info (char *var, int from_tty)
1742
{
1743
  if (var)
1744
    {
1745
      char *val = get_in_environ (current_inferior ()->environment, var);
1746
 
1747
      if (val)
1748
        {
1749
          puts_filtered (var);
1750
          puts_filtered (" = ");
1751
          puts_filtered (val);
1752
          puts_filtered ("\n");
1753
        }
1754
      else
1755
        {
1756
          puts_filtered ("Environment variable \"");
1757
          puts_filtered (var);
1758
          puts_filtered ("\" not defined.\n");
1759
        }
1760
    }
1761
  else
1762
    {
1763
      char **vector = environ_vector (current_inferior ()->environment);
1764
 
1765
      while (*vector)
1766
        {
1767
          puts_filtered (*vector++);
1768
          puts_filtered ("\n");
1769
        }
1770
    }
1771
}
1772
 
1773
static void
1774
set_environment_command (char *arg, int from_tty)
1775
{
1776
  char *p, *val, *var;
1777
  int nullset = 0;
1778
 
1779
  if (arg == 0)
1780
    error_no_arg (_("environment variable and value"));
1781
 
1782
  /* Find seperation between variable name and value */
1783
  p = (char *) strchr (arg, '=');
1784
  val = (char *) strchr (arg, ' ');
1785
 
1786
  if (p != 0 && val != 0)
1787
    {
1788
      /* We have both a space and an equals.  If the space is before the
1789
         equals, walk forward over the spaces til we see a nonspace
1790
         (possibly the equals). */
1791
      if (p > val)
1792
        while (*val == ' ')
1793
          val++;
1794
 
1795
      /* Now if the = is after the char following the spaces,
1796
         take the char following the spaces.  */
1797
      if (p > val)
1798
        p = val - 1;
1799
    }
1800
  else if (val != 0 && p == 0)
1801
    p = val;
1802
 
1803
  if (p == arg)
1804
    error_no_arg (_("environment variable to set"));
1805
 
1806
  if (p == 0 || p[1] == 0)
1807
    {
1808
      nullset = 1;
1809
      if (p == 0)
1810
        p = arg + strlen (arg); /* So that savestring below will work */
1811
    }
1812
  else
1813
    {
1814
      /* Not setting variable value to null */
1815
      val = p + 1;
1816
      while (*val == ' ' || *val == '\t')
1817
        val++;
1818
    }
1819
 
1820
  while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1821
    p--;
1822
 
1823
  var = savestring (arg, p - arg);
1824
  if (nullset)
1825
    {
1826
      printf_filtered (_("\
1827
Setting environment variable \"%s\" to null value.\n"),
1828
                       var);
1829
      set_in_environ (current_inferior ()->environment, var, "");
1830
    }
1831
  else
1832
    set_in_environ (current_inferior ()->environment, var, val);
1833
  xfree (var);
1834
}
1835
 
1836
static void
1837
unset_environment_command (char *var, int from_tty)
1838
{
1839
  if (var == 0)
1840
    {
1841
      /* If there is no argument, delete all environment variables.
1842
         Ask for confirmation if reading from the terminal.  */
1843
      if (!from_tty || query (_("Delete all environment variables? ")))
1844
        {
1845
          free_environ (current_inferior ()->environment);
1846
          current_inferior ()->environment = make_environ ();
1847
        }
1848
    }
1849
  else
1850
    unset_in_environ (current_inferior ()->environment, var);
1851
}
1852
 
1853
/* Handle the execution path (PATH variable) */
1854
 
1855
static const char path_var_name[] = "PATH";
1856
 
1857
static void
1858
path_info (char *args, int from_tty)
1859
{
1860
  puts_filtered ("Executable and object file path: ");
1861
  puts_filtered (get_in_environ (current_inferior ()->environment, path_var_name));
1862
  puts_filtered ("\n");
1863
}
1864
 
1865
/* Add zero or more directories to the front of the execution path.  */
1866
 
1867
static void
1868
path_command (char *dirname, int from_tty)
1869
{
1870
  char *exec_path;
1871
  char *env;
1872
 
1873
  dont_repeat ();
1874
  env = get_in_environ (current_inferior ()->environment, path_var_name);
1875
  /* Can be null if path is not set */
1876
  if (!env)
1877
    env = "";
1878
  exec_path = xstrdup (env);
1879
  mod_path (dirname, &exec_path);
1880
  set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
1881
  xfree (exec_path);
1882
  if (from_tty)
1883
    path_info ((char *) NULL, from_tty);
1884
}
1885
 
1886
 
1887
/* Print out the machine register regnum. If regnum is -1, print all
1888
   registers (print_all == 1) or all non-float and non-vector
1889
   registers (print_all == 0).
1890
 
1891
   For most machines, having all_registers_info() print the
1892
   register(s) one per line is good enough.  If a different format is
1893
   required, (eg, for MIPS or Pyramid 90x, which both have lots of
1894
   regs), or there is an existing convention for showing all the
1895
   registers, define the architecture method PRINT_REGISTERS_INFO to
1896
   provide that format.  */
1897
 
1898
void
1899
default_print_registers_info (struct gdbarch *gdbarch,
1900
                              struct ui_file *file,
1901
                              struct frame_info *frame,
1902
                              int regnum, int print_all)
1903
{
1904
  int i;
1905
  const int numregs = gdbarch_num_regs (gdbarch)
1906
                      + gdbarch_num_pseudo_regs (gdbarch);
1907
  gdb_byte buffer[MAX_REGISTER_SIZE];
1908
 
1909
  for (i = 0; i < numregs; i++)
1910
    {
1911
      /* Decide between printing all regs, non-float / vector regs, or
1912
         specific reg.  */
1913
      if (regnum == -1)
1914
        {
1915
          if (print_all)
1916
            {
1917
              if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
1918
                continue;
1919
            }
1920
          else
1921
            {
1922
              if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
1923
                continue;
1924
            }
1925
        }
1926
      else
1927
        {
1928
          if (i != regnum)
1929
            continue;
1930
        }
1931
 
1932
      /* If the register name is empty, it is undefined for this
1933
         processor, so don't display anything.  */
1934
      if (gdbarch_register_name (gdbarch, i) == NULL
1935
          || *(gdbarch_register_name (gdbarch, i)) == '\0')
1936
        continue;
1937
 
1938
      fputs_filtered (gdbarch_register_name (gdbarch, i), file);
1939
      print_spaces_filtered (15 - strlen (gdbarch_register_name
1940
                                          (gdbarch, i)), file);
1941
 
1942
      /* Get the data in raw format.  */
1943
      if (! frame_register_read (frame, i, buffer))
1944
        {
1945
          fprintf_filtered (file, "*value not available*\n");
1946
          continue;
1947
        }
1948
 
1949
      /* If virtual format is floating, print it that way, and in raw
1950
         hex.  */
1951
      if (TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_FLT
1952
          || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT)
1953
        {
1954
          int j;
1955
          struct value_print_options opts;
1956
 
1957
          get_user_print_options (&opts);
1958
          opts.deref_ref = 1;
1959
          val_print (register_type (gdbarch, i), buffer, 0, 0,
1960
                     file, 0, NULL, &opts, current_language);
1961
 
1962
          fprintf_filtered (file, "\t(raw 0x");
1963
          for (j = 0; j < register_size (gdbarch, i); j++)
1964
            {
1965
              int idx;
1966
 
1967
              if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1968
                idx = j;
1969
              else
1970
                idx = register_size (gdbarch, i) - 1 - j;
1971
              fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
1972
            }
1973
          fprintf_filtered (file, ")");
1974
        }
1975
      else
1976
        {
1977
          struct value_print_options opts;
1978
 
1979
          /* Print the register in hex.  */
1980
          get_formatted_print_options (&opts, 'x');
1981
          opts.deref_ref = 1;
1982
          val_print (register_type (gdbarch, i), buffer, 0, 0,
1983
                     file, 0, NULL, &opts, current_language);
1984
          /* If not a vector register, print it also according to its
1985
             natural format.  */
1986
          if (TYPE_VECTOR (register_type (gdbarch, i)) == 0)
1987
            {
1988
              get_user_print_options (&opts);
1989
              opts.deref_ref = 1;
1990
              fprintf_filtered (file, "\t");
1991
              val_print (register_type (gdbarch, i), buffer, 0, 0,
1992
                         file, 0, NULL, &opts, current_language);
1993
            }
1994
        }
1995
 
1996
      fprintf_filtered (file, "\n");
1997
    }
1998
}
1999
 
2000
void
2001
registers_info (char *addr_exp, int fpregs)
2002
{
2003
  struct frame_info *frame;
2004
  struct gdbarch *gdbarch;
2005
 
2006
  if (!target_has_registers)
2007
    error (_("The program has no registers now."));
2008
  frame = get_selected_frame (NULL);
2009
  gdbarch = get_frame_arch (frame);
2010
 
2011
  if (!addr_exp)
2012
    {
2013
      gdbarch_print_registers_info (gdbarch, gdb_stdout,
2014
                                    frame, -1, fpregs);
2015
      return;
2016
    }
2017
 
2018
  while (*addr_exp != '\0')
2019
    {
2020
      char *start;
2021
      const char *end;
2022
 
2023
      /* Keep skipping leading white space.  */
2024
      if (isspace ((*addr_exp)))
2025
        {
2026
          addr_exp++;
2027
          continue;
2028
        }
2029
 
2030
      /* Discard any leading ``$''.  Check that there is something
2031
         resembling a register following it.  */
2032
      if (addr_exp[0] == '$')
2033
        addr_exp++;
2034
      if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
2035
        error (_("Missing register name"));
2036
 
2037
      /* Find the start/end of this register name/num/group.  */
2038
      start = addr_exp;
2039
      while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
2040
        addr_exp++;
2041
      end = addr_exp;
2042
 
2043
      /* Figure out what we've found and display it.  */
2044
 
2045
      /* A register name?  */
2046
      {
2047
        int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
2048
 
2049
        if (regnum >= 0)
2050
          {
2051
            /* User registers lie completely outside of the range of
2052
               normal registers.  Catch them early so that the target
2053 524 jeremybenn
               never sees them.
2054
 
2055
               13-Apr-11 Jeremy Bennett: Formatting works for multiple
2056
               register names on the command line and matches the default
2057
               register printing. */
2058 330 jeremybenn
            if (regnum >= gdbarch_num_regs (gdbarch)
2059
                          + gdbarch_num_pseudo_regs (gdbarch))
2060
              {
2061
                struct value_print_options opts;
2062
                struct value *val = value_of_user_reg (regnum, frame);
2063 524 jeremybenn
                int regname_len = (int) (end - start);
2064 330 jeremybenn
 
2065 524 jeremybenn
                printf_filtered ("%.*s", regname_len, start);
2066
                print_spaces_filtered (15 - regname_len, gdb_stdout);
2067 330 jeremybenn
                get_formatted_print_options (&opts, 'x');
2068
                print_scalar_formatted (value_contents (val),
2069
                                        check_typedef (value_type (val)),
2070
                                        &opts, 0, gdb_stdout);
2071
                printf_filtered ("\n");
2072
              }
2073
            else
2074
              gdbarch_print_registers_info (gdbarch, gdb_stdout,
2075
                                            frame, regnum, fpregs);
2076
            continue;
2077
          }
2078
      }
2079
 
2080
      /* A register group?  */
2081
      {
2082
        struct reggroup *group;
2083
 
2084
        for (group = reggroup_next (gdbarch, NULL);
2085
             group != NULL;
2086
             group = reggroup_next (gdbarch, group))
2087
          {
2088
            /* Don't bother with a length check.  Should the user
2089
               enter a short register group name, go with the first
2090
               group that matches.  */
2091
            if (strncmp (start, reggroup_name (group), end - start) == 0)
2092
              break;
2093
          }
2094
        if (group != NULL)
2095
          {
2096
            int regnum;
2097
 
2098
            for (regnum = 0;
2099
                 regnum < gdbarch_num_regs (gdbarch)
2100
                          + gdbarch_num_pseudo_regs (gdbarch);
2101
                 regnum++)
2102
              {
2103
                if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
2104
                  gdbarch_print_registers_info (gdbarch,
2105
                                                gdb_stdout, frame,
2106
                                                regnum, fpregs);
2107
              }
2108
            continue;
2109
          }
2110
      }
2111
 
2112
      /* Nothing matched.  */
2113
      error (_("Invalid register `%.*s'"), (int) (end - start), start);
2114
    }
2115
}
2116
 
2117
void
2118
all_registers_info (char *addr_exp, int from_tty)
2119
{
2120
  registers_info (addr_exp, 1);
2121
}
2122
 
2123
static void
2124
nofp_registers_info (char *addr_exp, int from_tty)
2125
{
2126
  registers_info (addr_exp, 0);
2127
}
2128
 
2129
static void
2130
print_vector_info (struct ui_file *file,
2131
                   struct frame_info *frame, const char *args)
2132
{
2133
  struct gdbarch *gdbarch = get_frame_arch (frame);
2134
 
2135
  if (gdbarch_print_vector_info_p (gdbarch))
2136
    gdbarch_print_vector_info (gdbarch, file, frame, args);
2137
  else
2138
    {
2139
      int regnum;
2140
      int printed_something = 0;
2141
 
2142
      for (regnum = 0;
2143
           regnum < gdbarch_num_regs (gdbarch)
2144
                    + gdbarch_num_pseudo_regs (gdbarch);
2145
           regnum++)
2146
        {
2147
          if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
2148
            {
2149
              printed_something = 1;
2150
              gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2151
            }
2152
        }
2153
      if (!printed_something)
2154
        fprintf_filtered (file, "No vector information\n");
2155
    }
2156
}
2157
 
2158
static void
2159
vector_info (char *args, int from_tty)
2160
{
2161
  if (!target_has_registers)
2162
    error (_("The program has no registers now."));
2163
 
2164
  print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
2165
}
2166
 
2167
/* Kill the inferior process.  Make us have no inferior.  */
2168
 
2169
static void
2170
kill_command (char *arg, int from_tty)
2171
{
2172
  /* FIXME:  This should not really be inferior_ptid (or target_has_execution).
2173
     It should be a distinct flag that indicates that a target is active, cuz
2174
     some targets don't have processes! */
2175
 
2176
  if (ptid_equal (inferior_ptid, null_ptid))
2177
    error (_("The program is not being run."));
2178
  if (!query (_("Kill the program being debugged? ")))
2179
    error (_("Not confirmed."));
2180
  target_kill ();
2181
 
2182
  /* If we still have other inferiors to debug, then don't mess with
2183
     with their threads.  */
2184
  if (!have_inferiors ())
2185
    {
2186
      init_thread_list ();              /* Destroy thread info */
2187
 
2188
      /* Killing off the inferior can leave us with a core file.  If
2189
         so, print the state we are left in.  */
2190
      if (target_has_stack)
2191
        {
2192
          printf_filtered (_("In %s,\n"), target_longname);
2193
          print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
2194
        }
2195
    }
2196
  bfd_cache_close_all ();
2197
}
2198
 
2199
/* Used in `attach&' command.  ARG is a point to an integer
2200
   representing a process id.  Proceed threads of this process iff
2201
   they stopped due to debugger request, and when they did, they
2202
   reported a clean stop (TARGET_SIGNAL_0).  Do not proceed threads
2203
   that have been explicitly been told to stop.  */
2204
 
2205
static int
2206
proceed_after_attach_callback (struct thread_info *thread,
2207
                               void *arg)
2208
{
2209
  int pid = * (int *) arg;
2210
 
2211
  if (ptid_get_pid (thread->ptid) == pid
2212
      && !is_exited (thread->ptid)
2213
      && !is_executing (thread->ptid)
2214
      && !thread->stop_requested
2215
      && thread->stop_signal == TARGET_SIGNAL_0)
2216
    {
2217
      switch_to_thread (thread->ptid);
2218
      clear_proceed_status ();
2219
      proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
2220
    }
2221
 
2222
  return 0;
2223
}
2224
 
2225
static void
2226
proceed_after_attach (int pid)
2227
{
2228
  /* Don't error out if the current thread is running, because
2229
     there may be other stopped threads.  */
2230
  struct cleanup *old_chain;
2231
 
2232
  /* Backup current thread and selected frame.  */
2233
  old_chain = make_cleanup_restore_current_thread ();
2234
 
2235
  iterate_over_threads (proceed_after_attach_callback, &pid);
2236
 
2237
  /* Restore selected ptid.  */
2238
  do_cleanups (old_chain);
2239
}
2240
 
2241
/*
2242
 * TODO:
2243
 * Should save/restore the tty state since it might be that the
2244
 * program to be debugged was started on this tty and it wants
2245
 * the tty in some state other than what we want.  If it's running
2246
 * on another terminal or without a terminal, then saving and
2247
 * restoring the tty state is a harmless no-op.
2248
 * This only needs to be done if we are attaching to a process.
2249
 */
2250
 
2251
/*
2252
   attach_command --
2253
   takes a program started up outside of gdb and ``attaches'' to it.
2254
   This stops it cold in its tracks and allows us to start debugging it.
2255
   and wait for the trace-trap that results from attaching.  */
2256
 
2257
static void
2258
attach_command_post_wait (char *args, int from_tty, int async_exec)
2259
{
2260
  char *exec_file;
2261
  char *full_exec_path = NULL;
2262
  struct inferior *inferior;
2263
 
2264
  inferior = current_inferior ();
2265
  inferior->stop_soon = NO_STOP_QUIETLY;
2266
 
2267
  /* If no exec file is yet known, try to determine it from the
2268
     process itself.  */
2269
  exec_file = (char *) get_exec_file (0);
2270
  if (!exec_file)
2271
    {
2272
      exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
2273
      if (exec_file)
2274
        {
2275
          /* It's possible we don't have a full path, but rather just a
2276
             filename.  Some targets, such as HP-UX, don't provide the
2277
             full path, sigh.
2278
 
2279
             Attempt to qualify the filename against the source path.
2280
             (If that fails, we'll just fall back on the original
2281
             filename.  Not much more we can do...)
2282
           */
2283
          if (!source_full_path_of (exec_file, &full_exec_path))
2284
            full_exec_path = xstrdup (exec_file);
2285
 
2286
          exec_file_attach (full_exec_path, from_tty);
2287
          symbol_file_add_main (full_exec_path, from_tty);
2288
        }
2289
    }
2290
  else
2291
    {
2292
      reopen_exec_file ();
2293
      reread_symbols ();
2294
    }
2295
 
2296
  /* Take any necessary post-attaching actions for this platform.  */
2297
  target_post_attach (PIDGET (inferior_ptid));
2298
 
2299
  post_create_inferior (&current_target, from_tty);
2300
 
2301
  /* Install inferior's terminal modes.  */
2302
  target_terminal_inferior ();
2303
 
2304
  if (async_exec)
2305
    {
2306
      /* The user requested an `attach&', so be sure to leave threads
2307
         that didn't get a signal running.  */
2308
 
2309
      /* Immediatelly resume all suspended threads of this inferior,
2310
         and this inferior only.  This should have no effect on
2311
         already running threads.  If a thread has been stopped with a
2312
         signal, leave it be.  */
2313
      if (non_stop)
2314
        proceed_after_attach (inferior->pid);
2315
      else
2316
        {
2317
          if (inferior_thread ()->stop_signal == TARGET_SIGNAL_0)
2318
            {
2319
              clear_proceed_status ();
2320
              proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
2321
            }
2322
        }
2323
    }
2324
  else
2325
    {
2326
      /* The user requested a plain `attach', so be sure to leave
2327
         the inferior stopped.  */
2328
 
2329
      if (target_can_async_p ())
2330
        async_enable_stdin ();
2331
 
2332
      /* At least the current thread is already stopped.  */
2333
 
2334
      /* In all-stop, by definition, all threads have to be already
2335
         stopped at this point.  In non-stop, however, although the
2336
         selected thread is stopped, others may still be executing.
2337
         Be sure to explicitly stop all threads of the process.  This
2338
         should have no effect on already stopped threads.  */
2339
      if (non_stop)
2340
        target_stop (pid_to_ptid (inferior->pid));
2341
 
2342
      /* Tell the user/frontend where we're stopped.  */
2343
      normal_stop ();
2344
      if (deprecated_attach_hook)
2345
        deprecated_attach_hook ();
2346
    }
2347
}
2348
 
2349
struct attach_command_continuation_args
2350
{
2351
  char *args;
2352
  int from_tty;
2353
  int async_exec;
2354
};
2355
 
2356
static void
2357
attach_command_continuation (void *args)
2358
{
2359
  struct attach_command_continuation_args *a = args;
2360
 
2361
  attach_command_post_wait (a->args, a->from_tty, a->async_exec);
2362
}
2363
 
2364
static void
2365
attach_command_continuation_free_args (void *args)
2366
{
2367
  struct attach_command_continuation_args *a = args;
2368
 
2369
  xfree (a->args);
2370
  xfree (a);
2371
}
2372
 
2373
void
2374
attach_command (char *args, int from_tty)
2375
{
2376
  int async_exec = 0;
2377
  struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
2378
 
2379
  dont_repeat ();               /* Not for the faint of heart */
2380
 
2381
  if (gdbarch_has_global_solist (target_gdbarch))
2382
    /* Don't complain if all processes share the same symbol
2383
       space.  */
2384
    ;
2385
  else if (target_has_execution)
2386
    {
2387
      if (query (_("A program is being debugged already.  Kill it? ")))
2388
        target_kill ();
2389
      else
2390
        error (_("Not killed."));
2391
    }
2392
 
2393
  /* Clean up any leftovers from other runs.  Some other things from
2394
     this function should probably be moved into target_pre_inferior.  */
2395
  target_pre_inferior (from_tty);
2396
 
2397
  if (non_stop && !target_supports_non_stop ())
2398
    error (_("Cannot attach to this target in non-stop mode"));
2399
 
2400
  if (args)
2401
    {
2402
      async_exec = strip_bg_char (&args);
2403
 
2404
      /* If we get a request for running in the bg but the target
2405
         doesn't support it, error out. */
2406
      if (async_exec && !target_can_async_p ())
2407
        error (_("Asynchronous execution not supported on this target."));
2408
    }
2409
 
2410
  /* If we don't get a request of running in the bg, then we need
2411
     to simulate synchronous (fg) execution.  */
2412
  if (!async_exec && target_can_async_p ())
2413
    {
2414
      /* Simulate synchronous execution */
2415
      async_disable_stdin ();
2416
      make_cleanup ((make_cleanup_ftype *)async_enable_stdin, NULL);
2417
    }
2418
 
2419
  target_attach (args, from_tty);
2420
 
2421
  /* Set up the "saved terminal modes" of the inferior
2422
     based on what modes we are starting it with.  */
2423
  target_terminal_init ();
2424
 
2425
  /* Set up execution context to know that we should return from
2426
     wait_for_inferior as soon as the target reports a stop.  */
2427
  init_wait_for_inferior ();
2428
  clear_proceed_status ();
2429
 
2430
  if (non_stop)
2431
    {
2432
      /* If we find that the current thread isn't stopped, explicitly
2433
         do so now, because we're going to install breakpoints and
2434
         poke at memory.  */
2435
 
2436
      if (async_exec)
2437
        /* The user requested an `attach&'; stop just one thread.  */
2438
        target_stop (inferior_ptid);
2439
      else
2440
        /* The user requested an `attach', so stop all threads of this
2441
           inferior.  */
2442
        target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid)));
2443
    }
2444
 
2445
  /* Some system don't generate traps when attaching to inferior.
2446
     E.g. Mach 3 or GNU hurd.  */
2447
  if (!target_attach_no_wait)
2448
    {
2449
      struct inferior *inferior = current_inferior ();
2450
 
2451
      /* Careful here. See comments in inferior.h.  Basically some
2452
         OSes don't ignore SIGSTOPs on continue requests anymore.  We
2453
         need a way for handle_inferior_event to reset the stop_signal
2454
         variable after an attach, and this is what
2455
         STOP_QUIETLY_NO_SIGSTOP is for.  */
2456
      inferior->stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2457
 
2458
      if (target_can_async_p ())
2459
        {
2460
          /* sync_execution mode.  Wait for stop.  */
2461
          struct attach_command_continuation_args *a;
2462
 
2463
          a = xmalloc (sizeof (*a));
2464
          a->args = xstrdup (args);
2465
          a->from_tty = from_tty;
2466
          a->async_exec = async_exec;
2467
          add_inferior_continuation (attach_command_continuation, a,
2468
                                     attach_command_continuation_free_args);
2469
          discard_cleanups (back_to);
2470
          return;
2471
        }
2472
 
2473
      wait_for_inferior (0);
2474
    }
2475
 
2476
  attach_command_post_wait (args, from_tty, async_exec);
2477
  discard_cleanups (back_to);
2478
}
2479
 
2480
/* We had just found out that the target was already attached to an
2481
   inferior.  PTID points at a thread of this new inferior, that is
2482
   the most likely to be stopped right now, but not necessarily so.
2483
   The new inferior is assumed to be already added to the inferior
2484
   list at this point.  If LEAVE_RUNNING, then leave the threads of
2485
   this inferior running, except those we've explicitly seen reported
2486
   as stopped.  */
2487
 
2488
void
2489
notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
2490
{
2491
  struct cleanup* old_chain;
2492
  int async_exec;
2493
 
2494
  old_chain = make_cleanup (null_cleanup, NULL);
2495
 
2496
  /* If in non-stop, leave threads as running as they were.  If
2497
     they're stopped for some reason other than us telling it to, the
2498
     target reports a signal != TARGET_SIGNAL_0.  We don't try to
2499
     resume threads with such a stop signal.  */
2500
  async_exec = non_stop;
2501
 
2502
  if (!ptid_equal (inferior_ptid, null_ptid))
2503
    make_cleanup_restore_current_thread ();
2504
 
2505
  switch_to_thread (ptid);
2506
 
2507
  /* When we "notice" a new inferior we need to do all the things we
2508
     would normally do if we had just attached to it.  */
2509
 
2510
  if (is_executing (inferior_ptid))
2511
    {
2512
      struct inferior *inferior = current_inferior ();
2513
 
2514
      /* We're going to install breakpoints, and poke at memory,
2515
         ensure that the inferior is stopped for a moment while we do
2516
         that.  */
2517
      target_stop (inferior_ptid);
2518
 
2519
      inferior->stop_soon = STOP_QUIETLY_REMOTE;
2520
 
2521
      /* Wait for stop before proceeding.  */
2522
      if (target_can_async_p ())
2523
        {
2524
          struct attach_command_continuation_args *a;
2525
 
2526
          a = xmalloc (sizeof (*a));
2527
          a->args = xstrdup ("");
2528
          a->from_tty = from_tty;
2529
          a->async_exec = async_exec;
2530
          add_inferior_continuation (attach_command_continuation, a,
2531
                                     attach_command_continuation_free_args);
2532
 
2533
          do_cleanups (old_chain);
2534
          return;
2535
        }
2536
      else
2537
        wait_for_inferior (0);
2538
    }
2539
 
2540
  async_exec = leave_running;
2541
  attach_command_post_wait ("" /* args */, from_tty, async_exec);
2542
 
2543
  do_cleanups (old_chain);
2544
}
2545
 
2546
/*
2547
 * detach_command --
2548
 * takes a program previously attached to and detaches it.
2549
 * The program resumes execution and will no longer stop
2550
 * on signals, etc.  We better not have left any breakpoints
2551
 * in the program or it'll die when it hits one.  For this
2552
 * to work, it may be necessary for the process to have been
2553
 * previously attached.  It *might* work if the program was
2554
 * started via the normal ptrace (PTRACE_TRACEME).
2555
 */
2556
 
2557
void
2558
detach_command (char *args, int from_tty)
2559
{
2560
  dont_repeat ();               /* Not for the faint of heart.  */
2561
 
2562
  if (ptid_equal (inferior_ptid, null_ptid))
2563
    error (_("The program is not being run."));
2564
 
2565
  disconnect_tracing (from_tty);
2566
 
2567
  target_detach (args, from_tty);
2568
 
2569
  /* If the solist is global across inferiors, don't clear it when we
2570
     detach from a single inferior.  */
2571
  if (!gdbarch_has_global_solist (target_gdbarch))
2572
    no_shared_libraries (NULL, from_tty);
2573
 
2574
  /* If we still have inferiors to debug, then don't mess with their
2575
     threads.  */
2576
  if (!have_inferiors ())
2577
    init_thread_list ();
2578
 
2579
  if (deprecated_detach_hook)
2580
    deprecated_detach_hook ();
2581
}
2582
 
2583
/* Disconnect from the current target without resuming it (leaving it
2584
   waiting for a debugger).
2585
 
2586
   We'd better not have left any breakpoints in the program or the
2587
   next debugger will get confused.  Currently only supported for some
2588
   remote targets, since the normal attach mechanisms don't work on
2589
   stopped processes on some native platforms (e.g. GNU/Linux).  */
2590
 
2591
static void
2592
disconnect_command (char *args, int from_tty)
2593
{
2594
  dont_repeat ();               /* Not for the faint of heart */
2595
  target_disconnect (args, from_tty);
2596
  no_shared_libraries (NULL, from_tty);
2597
  init_thread_list ();
2598
  if (deprecated_detach_hook)
2599
    deprecated_detach_hook ();
2600
}
2601
 
2602
void
2603
interrupt_target_1 (int all_threads)
2604
{
2605
  ptid_t ptid;
2606
 
2607
  if (all_threads)
2608
    ptid = minus_one_ptid;
2609
  else
2610
    ptid = inferior_ptid;
2611
  target_stop (ptid);
2612
 
2613
  /* Tag the thread as having been explicitly requested to stop, so
2614
     other parts of gdb know not to resume this thread automatically,
2615
     if it was stopped due to an internal event.  Limit this to
2616
     non-stop mode, as when debugging a multi-threaded application in
2617
     all-stop mode, we will only get one stop event --- it's undefined
2618
     which thread will report the event.  */
2619
  if (non_stop)
2620
    set_stop_requested (ptid, 1);
2621
}
2622
 
2623
/* Stop the execution of the target while running in async mode, in
2624
   the backgound.  In all-stop, stop the whole process.  In non-stop
2625
   mode, stop the current thread only by default, or stop all threads
2626
   if the `-a' switch is used.  */
2627
 
2628
/* interrupt [-a]  */
2629
void
2630
interrupt_target_command (char *args, int from_tty)
2631
{
2632
  if (target_can_async_p ())
2633
    {
2634
      int all_threads = 0;
2635
 
2636
      dont_repeat ();           /* Not for the faint of heart */
2637
 
2638
      if (args != NULL
2639
          && strncmp (args, "-a", sizeof ("-a") - 1) == 0)
2640
        all_threads = 1;
2641
 
2642
      if (!non_stop && all_threads)
2643
        error (_("-a is meaningless in all-stop mode."));
2644
 
2645
      interrupt_target_1 (all_threads);
2646
    }
2647
}
2648
 
2649
static void
2650
print_float_info (struct ui_file *file,
2651
                  struct frame_info *frame, const char *args)
2652
{
2653
  struct gdbarch *gdbarch = get_frame_arch (frame);
2654
 
2655
  if (gdbarch_print_float_info_p (gdbarch))
2656
    gdbarch_print_float_info (gdbarch, file, frame, args);
2657
  else
2658
    {
2659
      int regnum;
2660
      int printed_something = 0;
2661
 
2662
      for (regnum = 0;
2663
           regnum < gdbarch_num_regs (gdbarch)
2664
                    + gdbarch_num_pseudo_regs (gdbarch);
2665
           regnum++)
2666
        {
2667
          if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2668
            {
2669
              printed_something = 1;
2670
              gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2671
            }
2672
        }
2673
      if (!printed_something)
2674
        fprintf_filtered (file, "\
2675
No floating-point info available for this processor.\n");
2676
    }
2677
}
2678
 
2679
static void
2680
float_info (char *args, int from_tty)
2681
{
2682
  if (!target_has_registers)
2683
    error (_("The program has no registers now."));
2684
 
2685
  print_float_info (gdb_stdout, get_selected_frame (NULL), args);
2686
}
2687
 
2688
static void
2689
unset_command (char *args, int from_tty)
2690
{
2691
  printf_filtered (_("\
2692
\"unset\" must be followed by the name of an unset subcommand.\n"));
2693
  help_list (unsetlist, "unset ", -1, gdb_stdout);
2694
}
2695
 
2696
void
2697
_initialize_infcmd (void)
2698
{
2699
  struct cmd_list_element *c = NULL;
2700
 
2701
  /* add the filename of the terminal connected to inferior I/O */
2702
  add_setshow_filename_cmd ("inferior-tty", class_run,
2703
                            &inferior_io_terminal_scratch, _("\
2704
Set terminal for future runs of program being debugged."), _("\
2705
Show terminal for future runs of program being debugged."), _("\
2706
Usage: set inferior-tty /dev/pts/1"),
2707
                            set_inferior_tty_command,
2708
                            show_inferior_tty_command,
2709
                            &setlist, &showlist);
2710
  add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2711
 
2712
  add_setshow_optional_filename_cmd ("args", class_run,
2713
                                     &inferior_args_scratch, _("\
2714
Set argument list to give program being debugged when it is started."), _("\
2715
Show argument list to give program being debugged when it is started."), _("\
2716
Follow this command with any number of args, to be passed to the program."),
2717
                                     set_args_command,
2718
                                     show_args_command,
2719
                                     &setlist, &showlist);
2720
 
2721
  c = add_cmd ("environment", no_class, environment_info, _("\
2722
The environment to give the program, or one variable's value.\n\
2723
With an argument VAR, prints the value of environment variable VAR to\n\
2724
give the program being debugged.  With no arguments, prints the entire\n\
2725
environment to be given to the program."), &showlist);
2726
  set_cmd_completer (c, noop_completer);
2727
 
2728
  add_prefix_cmd ("unset", no_class, unset_command,
2729
                  _("Complement to certain \"set\" commands."),
2730
                  &unsetlist, "unset ", 0, &cmdlist);
2731
 
2732
  c = add_cmd ("environment", class_run, unset_environment_command, _("\
2733
Cancel environment variable VAR for the program.\n\
2734
This does not affect the program until the next \"run\" command."),
2735
               &unsetlist);
2736
  set_cmd_completer (c, noop_completer);
2737
 
2738
  c = add_cmd ("environment", class_run, set_environment_command, _("\
2739
Set environment variable value to give the program.\n\
2740
Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2741
VALUES of environment variables are uninterpreted strings.\n\
2742
This does not affect the program until the next \"run\" command."),
2743
               &setlist);
2744
  set_cmd_completer (c, noop_completer);
2745
 
2746
  c = add_com ("path", class_files, path_command, _("\
2747
Add directory DIR(s) to beginning of search path for object files.\n\
2748
$cwd in the path means the current working directory.\n\
2749
This path is equivalent to the $PATH shell variable.  It is a list of\n\
2750
directories, separated by colons.  These directories are searched to find\n\
2751
fully linked executable files and separately compiled object files as needed."));
2752
  set_cmd_completer (c, filename_completer);
2753
 
2754
  c = add_cmd ("paths", no_class, path_info, _("\
2755
Current search path for finding object files.\n\
2756
$cwd in the path means the current working directory.\n\
2757
This path is equivalent to the $PATH shell variable.  It is a list of\n\
2758
directories, separated by colons.  These directories are searched to find\n\
2759
fully linked executable files and separately compiled object files as needed."),
2760
               &showlist);
2761
  set_cmd_completer (c, noop_completer);
2762
 
2763
  add_prefix_cmd ("kill", class_run, kill_command,
2764
                  _("Kill execution of program being debugged."),
2765
                  &killlist, "kill ", 0, &cmdlist);
2766
 
2767
  add_com ("attach", class_run, attach_command, _("\
2768
Attach to a process or file outside of GDB.\n\
2769
This command attaches to another target, of the same type as your last\n\
2770
\"target\" command (\"info files\" will show your target stack).\n\
2771
The command may take as argument a process id or a device file.\n\
2772
For a process id, you must have permission to send the process a signal,\n\
2773
and it must have the same effective uid as the debugger.\n\
2774
When using \"attach\" with a process id, the debugger finds the\n\
2775
program running in the process, looking first in the current working\n\
2776
directory, or (if not found there) using the source file search path\n\
2777
(see the \"directory\" command).  You can also use the \"file\" command\n\
2778
to specify the program, and to load its symbol table."));
2779
 
2780
  add_prefix_cmd ("detach", class_run, detach_command, _("\
2781
Detach a process or file previously attached.\n\
2782
If a process, it is no longer traced, and it continues its execution.  If\n\
2783
you were debugging a file, the file is closed and gdb no longer accesses it."),
2784
                  &detachlist, "detach ", 0, &cmdlist);
2785
 
2786
  add_com ("disconnect", class_run, disconnect_command, _("\
2787
Disconnect from a target.\n\
2788
The target will wait for another debugger to connect.  Not available for\n\
2789
all targets."));
2790
 
2791
  add_com ("signal", class_run, signal_command, _("\
2792
Continue program giving it signal specified by the argument.\n\
2793
An argument of \"0\" means continue program without giving it a signal."));
2794
 
2795
  add_com ("stepi", class_run, stepi_command, _("\
2796
Step one instruction exactly.\n\
2797
Argument N means do this N times (or till program stops for another reason)."));
2798
  add_com_alias ("si", "stepi", class_alias, 0);
2799
 
2800
  add_com ("nexti", class_run, nexti_command, _("\
2801
Step one instruction, but proceed through subroutine calls.\n\
2802
Argument N means do this N times (or till program stops for another reason)."));
2803
  add_com_alias ("ni", "nexti", class_alias, 0);
2804
 
2805
  add_com ("finish", class_run, finish_command, _("\
2806
Execute until selected stack frame returns.\n\
2807
Upon return, the value returned is printed and put in the value history."));
2808
  add_com_alias ("fin", "finish", class_run, 1);
2809
 
2810
  add_com ("next", class_run, next_command, _("\
2811
Step program, proceeding through subroutine calls.\n\
2812
Like the \"step\" command as long as subroutine calls do not happen;\n\
2813
when they do, the call is treated as one instruction.\n\
2814
Argument N means do this N times (or till program stops for another reason)."));
2815
  add_com_alias ("n", "next", class_run, 1);
2816
  if (xdb_commands)
2817
    add_com_alias ("S", "next", class_run, 1);
2818
 
2819
  add_com ("step", class_run, step_command, _("\
2820
Step program until it reaches a different source line.\n\
2821
Argument N means do this N times (or till program stops for another reason)."));
2822
  add_com_alias ("s", "step", class_run, 1);
2823
 
2824
  c = add_com ("until", class_run, until_command, _("\
2825
Execute until the program reaches a source line greater than the current\n\
2826
or a specified location (same args as break command) within the current frame."));
2827
  set_cmd_completer (c, location_completer);
2828
  add_com_alias ("u", "until", class_run, 1);
2829
 
2830
  c = add_com ("advance", class_run, advance_command, _("\
2831
Continue the program up to the given location (same form as args for break command).\n\
2832
Execution will also stop upon exit from the current stack frame."));
2833
  set_cmd_completer (c, location_completer);
2834
 
2835
  c = add_com ("jump", class_run, jump_command, _("\
2836
Continue program being debugged at specified line or address.\n\
2837
Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2838
for an address to start at."));
2839
  set_cmd_completer (c, location_completer);
2840
 
2841
  if (xdb_commands)
2842
    {
2843
      c = add_com ("go", class_run, go_command, _("\
2844
Usage: go <location>\n\
2845
Continue program being debugged, stopping at specified line or \n\
2846
address.\n\
2847
Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2848
expression for an address to start at.\n\
2849
This command is a combination of tbreak and jump."));
2850
      set_cmd_completer (c, location_completer);
2851
    }
2852
 
2853
  if (xdb_commands)
2854
    add_com_alias ("g", "go", class_run, 1);
2855
 
2856
  c = add_com ("continue", class_run, continue_command, _("\
2857
Continue program being debugged, after signal or breakpoint.\n\
2858
If proceeding from breakpoint, a number N may be used as an argument,\n\
2859
which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2860
the breakpoint won't break until the Nth time it is reached).\n\
2861
\n\
2862
If non-stop mode is enabled, continue only the current thread,\n\
2863
otherwise all the threads in the program are continued.  To \n\
2864
continue all stopped threads in non-stop mode, use the -a option.\n\
2865
Specifying -a and an ignore count simultaneously is an error."));
2866
  add_com_alias ("c", "cont", class_run, 1);
2867
  add_com_alias ("fg", "cont", class_run, 1);
2868
 
2869
  c = add_com ("run", class_run, run_command, _("\
2870
Start debugged program.  You may specify arguments to give it.\n\
2871
Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2872
Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2873
With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2874
To cancel previous arguments and run with no arguments,\n\
2875
use \"set args\" without arguments."));
2876
  set_cmd_completer (c, filename_completer);
2877
  add_com_alias ("r", "run", class_run, 1);
2878
  if (xdb_commands)
2879
    add_com ("R", class_run, run_no_args_command,
2880
             _("Start debugged program with no arguments."));
2881
 
2882
  c = add_com ("start", class_run, start_command, _("\
2883
Run the debugged program until the beginning of the main procedure.\n\
2884
You may specify arguments to give to your program, just as with the\n\
2885
\"run\" command."));
2886
  set_cmd_completer (c, filename_completer);
2887
 
2888
  c = add_com ("interrupt", class_run, interrupt_target_command,
2889
               _("Interrupt the execution of the debugged program.\n\
2890
If non-stop mode is enabled, interrupt only the current thread,\n\
2891
otherwise all the threads in the program are stopped.  To \n\
2892
interrupt all running threads in non-stop mode, use the -a option."));
2893
 
2894
  add_info ("registers", nofp_registers_info, _("\
2895
List of integer registers and their contents, for selected stack frame.\n\
2896
Register name as argument means describe only that register."));
2897
  add_info_alias ("r", "registers", 1);
2898
 
2899
  if (xdb_commands)
2900
    add_com ("lr", class_info, nofp_registers_info, _("\
2901
List of integer registers and their contents, for selected stack frame.\n\
2902
Register name as argument means describe only that register."));
2903
  add_info ("all-registers", all_registers_info, _("\
2904
List of all registers and their contents, for selected stack frame.\n\
2905
Register name as argument means describe only that register."));
2906
 
2907
  add_info ("program", program_info,
2908
            _("Execution status of the program."));
2909
 
2910
  add_info ("float", float_info,
2911
            _("Print the status of the floating point unit\n"));
2912
 
2913
  add_info ("vector", vector_info,
2914
            _("Print the status of the vector unit\n"));
2915
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.