~ubuntu-branches/debian/jessie/gdb/jessie

« back to all changes in this revision

Viewing changes to gdb/infcmd.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2010-03-20 01:21:29 UTC
  • mfrom: (1.3.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100320012129-t7h25y8zgr8c2369
Tags: 7.1-1
* New upstream release, including:
  - PIE support (Closes: #346409).
  - C++ improvements, including static_cast<> et al, namespace imports,
    and bug fixes in printing virtual base classes.
  - Multi-program debugging.  One GDB can now debug multiple programs
    at the same time.
  - Python scripting improvements, including gdb.parse_and_eval.
  - Updated MIPS Linux signal frame layout (Closes: #570875).
  - No internal error stepping over _dl_debug_state (Closes: #569551).
* Update to Standards-Version: 3.8.4 (no changes required).
* Include more relevant (and smaller) docs in the gdbserver package
  (Closes: #571132).
* Do not duplicate documentation in gdb64, gdb-source, and libgdb-dev.
* Fix crash when switching into TUI mode (Closes: #568489).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
   Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4
4
   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5
 
   2008, 2009 Free Software Foundation, Inc.
 
5
   2008, 2009, 2010 Free Software Foundation, Inc.
6
6
 
7
7
   This file is part of GDB.
8
8
 
55
55
#include "valprint.h"
56
56
#include "inline-frame.h"
57
57
 
 
58
extern void disconnect_or_stop_tracing (int from_tty);
 
59
 
58
60
/* Functions exported for general use, in inferior.h: */
59
61
 
60
62
void all_registers_info (char *, int);
124
126
#define ERROR_NO_INFERIOR \
125
127
   if (!target_has_execution) error (_("The program is not being run."));
126
128
 
127
 
/* String containing arguments to give to the program, separated by spaces.
128
 
   Empty string (pointer to '\0') means no args.  */
129
 
 
130
 
static char *inferior_args;
131
 
 
132
 
/* The inferior arguments as a vector.  If INFERIOR_ARGC is nonzero,
133
 
   then we must compute INFERIOR_ARGS from this (via the target).  */
134
 
 
135
 
static int inferior_argc;
136
 
static char **inferior_argv;
137
 
 
138
 
/* File name for default use for standard in/out in the inferior.  */
139
 
 
140
 
static char *inferior_io_terminal;
 
129
/* Scratch area where string containing arguments to give to the program will be
 
130
   stored by 'set args'.  As soon as anything is stored, notice_args_set will
 
131
   move it into per-inferior storage.  Arguments are separated by spaces. Empty
 
132
   string (pointer to '\0') means no args.  */
 
133
 
 
134
static char *inferior_args_scratch;
 
135
 
 
136
/* Scratch area where 'set inferior-tty' will store user-provided value.
 
137
   We'll immediate copy it into per-inferior storage.  */
 
138
 
 
139
static char *inferior_io_terminal_scratch;
141
140
 
142
141
/* Pid of our debugged inferior, or 0 if no inferior now.
143
142
   Since various parts of infrun.c test this to see whether there is a program
164
163
 
165
164
int stopped_by_random_signal;
166
165
 
167
 
/* Environment to use for running inferior,
168
 
   in format described in environ.h.  */
169
 
 
170
 
struct gdb_environ *inferior_environ;
171
166
 
172
167
/* Accessor routines. */
173
168
 
 
169
/* Set the io terminal for the current inferior.  Ownership of
 
170
   TERMINAL_NAME is not transferred.  */
 
171
 
174
172
void 
175
173
set_inferior_io_terminal (const char *terminal_name)
176
174
{
177
 
  if (inferior_io_terminal)
178
 
    xfree (inferior_io_terminal);
179
 
 
180
 
  if (!terminal_name)
181
 
    inferior_io_terminal = NULL;
182
 
  else
183
 
    inferior_io_terminal = xstrdup (terminal_name);
 
175
  xfree (current_inferior ()->terminal);
 
176
  current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
184
177
}
185
178
 
186
179
const char *
187
180
get_inferior_io_terminal (void)
188
181
{
189
 
  return inferior_io_terminal;
 
182
  return current_inferior ()->terminal;
 
183
}
 
184
 
 
185
static void
 
186
set_inferior_tty_command (char *args, int from_tty,
 
187
                          struct cmd_list_element *c)
 
188
{
 
189
  /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
 
190
     Now route it to current inferior.  */
 
191
  set_inferior_io_terminal (inferior_io_terminal_scratch);
 
192
}
 
193
 
 
194
static void
 
195
show_inferior_tty_command (struct ui_file *file, int from_tty,
 
196
                           struct cmd_list_element *c, const char *value)
 
197
{
 
198
  /* Note that we ignore the passed-in value in favor of computing it
 
199
     directly.  */
 
200
  const char *inferior_io_terminal = get_inferior_io_terminal ();
 
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);
190
206
}
191
207
 
192
208
char *
193
209
get_inferior_args (void)
194
210
{
195
 
  if (inferior_argc != 0)
 
211
  if (current_inferior ()->argc != 0)
196
212
    {
197
 
      char *n, *old;
 
213
      char *n;
198
214
 
199
 
      n = construct_inferior_arguments (inferior_argc, inferior_argv);
200
 
      old = set_inferior_args (n);
201
 
      xfree (old);
 
215
      n = construct_inferior_arguments (current_inferior ()->argc,
 
216
                                        current_inferior ()->argv);
 
217
      set_inferior_args (n);
 
218
      xfree (n);
202
219
    }
203
220
 
204
 
  if (inferior_args == NULL)
205
 
    inferior_args = xstrdup ("");
 
221
  if (current_inferior ()->args == NULL)
 
222
    current_inferior ()->args = xstrdup ("");
206
223
 
207
 
  return inferior_args;
 
224
  return current_inferior ()->args;
208
225
}
209
226
 
210
 
char *
 
227
/* Set the arguments for the current inferior.  Ownership of
 
228
   NEWARGS is not transferred.  */
 
229
 
 
230
void
211
231
set_inferior_args (char *newargs)
212
232
{
213
 
  char *saved_args = inferior_args;
214
 
 
215
 
  inferior_args = newargs;
216
 
  inferior_argc = 0;
217
 
  inferior_argv = 0;
218
 
 
219
 
  return saved_args;
 
233
  xfree (current_inferior ()->args);
 
234
  current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
 
235
  current_inferior ()->argc = 0;
 
236
  current_inferior ()->argv = 0;
220
237
}
221
238
 
222
239
void
223
240
set_inferior_args_vector (int argc, char **argv)
224
241
{
225
 
  inferior_argc = argc;
226
 
  inferior_argv = argv;
 
242
  current_inferior ()->argc = argc;
 
243
  current_inferior ()->argv = argv;
227
244
}
228
245
 
229
246
/* Notice when `set args' is run.  */
230
247
static void
231
 
notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
 
248
set_args_command (char *args, int from_tty, struct cmd_list_element *c)
232
249
{
233
 
  inferior_argc = 0;
234
 
  inferior_argv = 0;
 
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);
235
253
}
236
254
 
237
255
/* Notice when `show args' is run.  */
238
256
static void
239
 
notice_args_read (struct ui_file *file, int from_tty,
240
 
                  struct cmd_list_element *c, const char *value)
 
257
show_args_command (struct ui_file *file, int from_tty,
 
258
                   struct cmd_list_element *c, const char *value)
241
259
{
242
260
  /* Note that we ignore the passed-in value in favor of computing it
243
261
     directly.  */
367
385
  return 0;
368
386
}
369
387
 
370
 
void
371
 
tty_command (char *file, int from_tty)
372
 
{
373
 
  if (file == 0)
374
 
    error_no_arg (_("terminal name for running target process"));
375
 
 
376
 
  set_inferior_io_terminal (file);
377
 
}
378
 
 
379
388
/* Common actions to take after creating any sort of inferior, by any
380
389
   means (running, attaching, connecting, et cetera).  The target
381
390
   should be stopped.  */
395
404
  /* Now that we know the register layout, retrieve current PC.  */
396
405
  stop_pc = regcache_read_pc (get_current_regcache ());
397
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
 
398
418
  /* If the solist is global across processes, there's no need to
399
419
     refetch it here.  */
400
420
  if (exec_bfd && !gdbarch_has_global_solist (target_gdbarch))
401
421
    {
402
422
      /* Sometimes the platform-specific hook loads initial shared
403
 
         libraries, and sometimes it doesn't.  Try to do so first, so
404
 
         that we can add them with the correct value for FROM_TTY.
405
 
         If we made all the inferior hook methods consistent,
406
 
         this call could be removed.  */
 
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
 
407
429
#ifdef SOLIB_ADD
408
 
      SOLIB_ADD (NULL, from_tty, target, auto_solib_add);
409
 
#else
410
 
      solib_add (NULL, from_tty, target, auto_solib_add);
411
 
#endif
412
 
    }
413
 
 
414
 
  if (exec_bfd)
415
 
    {
416
 
      /* Create the hooks to handle shared library load and unload
417
 
         events.  */
418
 
#ifdef SOLIB_CREATE_INFERIOR_HOOK
419
 
      SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
420
 
#else
421
 
      solib_create_inferior_hook ();
 
430
      SOLIB_ADD (NULL, 0, target, auto_solib_add);
 
431
#else
 
432
      solib_add (NULL, 0, target, auto_solib_add);
422
433
#endif
423
434
    }
424
435
 
532
543
 
533
544
      /* If there were other args, beside '&', process them. */
534
545
      if (args)
535
 
        {
536
 
          char *old_args = set_inferior_args (xstrdup (args));
537
 
          xfree (old_args);
538
 
        }
 
546
        set_inferior_args (args);
539
547
    }
540
548
 
541
549
  if (from_tty)
555
563
  /* We call get_inferior_args() because we might need to compute
556
564
     the value now.  */
557
565
  target_create_inferior (exec_file, get_inferior_args (),
558
 
                          environ_vector (inferior_environ), from_tty);
 
566
                          environ_vector (current_inferior ()->environment), from_tty);
559
567
 
560
568
  /* We're starting off a new process.  When we get out of here, in
561
569
     non-stop mode, finish the state of all threads of that process,
590
598
static void
591
599
run_no_args_command (char *args, int from_tty)
592
600
{
593
 
  char *old_args = set_inferior_args (xstrdup (""));
594
 
  xfree (old_args);
 
601
  set_inferior_args ("");
595
602
}
596
603
 
597
604
 
1515
1522
  old_chain = make_cleanup_delete_breakpoint (breakpoint);
1516
1523
 
1517
1524
  tp->proceed_to_finish = 1;    /* We want stop_registers, please...  */
1518
 
  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1519
 
 
1520
1525
  cargs = xmalloc (sizeof (*cargs));
1521
1526
 
1522
1527
  cargs->breakpoint = breakpoint;
1523
1528
  cargs->function = function;
1524
1529
  add_continuation (tp, finish_command_continuation, cargs,
1525
1530
                    finish_command_continuation_free_arg);
 
1531
  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1526
1532
 
1527
1533
  discard_cleanups (old_chain);
1528
1534
  if (!target_can_async_p ())
1696
1702
{
1697
1703
  if (var)
1698
1704
    {
1699
 
      char *val = get_in_environ (inferior_environ, var);
 
1705
      char *val = get_in_environ (current_inferior ()->environment, var);
1700
1706
      if (val)
1701
1707
        {
1702
1708
          puts_filtered (var);
1713
1719
    }
1714
1720
  else
1715
1721
    {
1716
 
      char **vector = environ_vector (inferior_environ);
 
1722
      char **vector = environ_vector (current_inferior ()->environment);
1717
1723
      while (*vector)
1718
1724
        {
1719
1725
          puts_filtered (*vector++);
1778
1784
      printf_filtered (_("\
1779
1785
Setting environment variable \"%s\" to null value.\n"),
1780
1786
                       var);
1781
 
      set_in_environ (inferior_environ, var, "");
 
1787
      set_in_environ (current_inferior ()->environment, var, "");
1782
1788
    }
1783
1789
  else
1784
 
    set_in_environ (inferior_environ, var, val);
 
1790
    set_in_environ (current_inferior ()->environment, var, val);
1785
1791
  xfree (var);
1786
1792
}
1787
1793
 
1794
1800
         Ask for confirmation if reading from the terminal.  */
1795
1801
      if (!from_tty || query (_("Delete all environment variables? ")))
1796
1802
        {
1797
 
          free_environ (inferior_environ);
1798
 
          inferior_environ = make_environ ();
 
1803
          free_environ (current_inferior ()->environment);
 
1804
          current_inferior ()->environment = make_environ ();
1799
1805
        }
1800
1806
    }
1801
1807
  else
1802
 
    unset_in_environ (inferior_environ, var);
 
1808
    unset_in_environ (current_inferior ()->environment, var);
1803
1809
}
1804
1810
 
1805
1811
/* Handle the execution path (PATH variable) */
1810
1816
path_info (char *args, int from_tty)
1811
1817
{
1812
1818
  puts_filtered ("Executable and object file path: ");
1813
 
  puts_filtered (get_in_environ (inferior_environ, path_var_name));
 
1819
  puts_filtered (get_in_environ (current_inferior ()->environment, path_var_name));
1814
1820
  puts_filtered ("\n");
1815
1821
}
1816
1822
 
1822
1828
  char *exec_path;
1823
1829
  char *env;
1824
1830
  dont_repeat ();
1825
 
  env = get_in_environ (inferior_environ, path_var_name);
 
1831
  env = get_in_environ (current_inferior ()->environment, path_var_name);
1826
1832
  /* Can be null if path is not set */
1827
1833
  if (!env)
1828
1834
    env = "";
1829
1835
  exec_path = xstrdup (env);
1830
1836
  mod_path (dirname, &exec_path);
1831
 
  set_in_environ (inferior_environ, path_var_name, exec_path);
 
1837
  set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
1832
1838
  xfree (exec_path);
1833
1839
  if (from_tty)
1834
1840
    path_info ((char *) NULL, from_tty);
2506
2512
  if (ptid_equal (inferior_ptid, null_ptid))
2507
2513
    error (_("The program is not being run."));
2508
2514
 
 
2515
  disconnect_or_stop_tracing (from_tty);
 
2516
 
2509
2517
  target_detach (args, from_tty);
2510
2518
 
2511
2519
  /* If the solist is global across inferiors, don't clear it when we
2641
2649
 
2642
2650
  /* add the filename of the terminal connected to inferior I/O */
2643
2651
  add_setshow_filename_cmd ("inferior-tty", class_run,
2644
 
                            &inferior_io_terminal, _("\
 
2652
                            &inferior_io_terminal_scratch, _("\
2645
2653
Set terminal for future runs of program being debugged."), _("\
2646
2654
Show terminal for future runs of program being debugged."), _("\
2647
 
Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
 
2655
Usage: set inferior-tty /dev/pts/1"),
 
2656
                            set_inferior_tty_command,
 
2657
                            show_inferior_tty_command,
 
2658
                            &setlist, &showlist);
2648
2659
  add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2649
2660
 
2650
2661
  add_setshow_optional_filename_cmd ("args", class_run,
2651
 
                                     &inferior_args, _("\
 
2662
                                     &inferior_args_scratch, _("\
2652
2663
Set argument list to give program being debugged when it is started."), _("\
2653
2664
Show argument list to give program being debugged when it is started."), _("\
2654
2665
Follow this command with any number of args, to be passed to the program."),
2655
 
                                     notice_args_set,
2656
 
                                     notice_args_read,
 
2666
                                     set_args_command,
 
2667
                                     show_args_command,
2657
2668
                                     &setlist, &showlist);
2658
2669
 
2659
2670
  c = add_cmd ("environment", no_class, environment_info, _("\
2850
2861
 
2851
2862
  add_info ("vector", vector_info,
2852
2863
            _("Print the status of the vector unit\n"));
2853
 
 
2854
 
  inferior_environ = make_environ ();
2855
 
  init_environ (inferior_environ);
2856
2864
}