]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-archer.patch
- update to 6.8.91.20090930-1 from fedora
[packages/gdb.git] / gdb-archer.patch
1 http://sourceware.org/gdb/wiki/ProjectArcher
2 http://sourceware.org/gdb/wiki/ArcherBranchManagement
3
4 GIT snapshot:
5 commit 7cb860f03e2437c97239334ebe240d06f45723e0
6
7 branch `archer' - the merge of branches:
8 archer-tromey-call-frame-cfa
9 archer-tromey-delayed-symfile
10 archer-tromey-dw-op-value
11 archer-jankratochvil-vla
12 archer-jankratochvil-misc
13 archer-keiths-expr-cumulative
14 archer-tromey-python
15 archer-jankratochvil-fortran-module
16 archer-jankratochvil-watchpoint
17 archer-jankratochvil-bp_location-accel
18 archer-pmuldoon-next-over-throw
19
20
21 diff --git a/gdb/Makefile.in b/gdb/Makefile.in
22 index f5e1dde..73ee55c 100644
23 --- a/gdb/Makefile.in
24 +++ b/gdb/Makefile.in
25 @@ -169,6 +169,10 @@ TARGET_SYSTEM_ROOT_DEFINE = @TARGET_SYSTEM_ROOT_DEFINE@
26  # Did the user give us a --with-gdb-datadir option?
27  GDB_DATADIR_PATH = @GDB_DATADIR_PATH@
28  
29 +# The argument to --with-pythondir.  If not given, this is
30 +# GDB_DATADIR_PATH/python.
31 +pythondir = @pythondir@
32 +
33  # Helper code from gnulib.
34  LIBGNU = gnulib/libgnu.a
35  INCGNU = -I$(srcdir)/gnulib -Ignulib
36 @@ -267,21 +271,37 @@ SUBDIR_TUI_CFLAGS= \
37  #
38  SUBDIR_PYTHON_OBS = \
39         python.o \
40 +       py-block.o \
41 +       py-breakpoint.o \
42         py-cmd.o \
43         py-frame.o \
44         py-function.o \
45 +       py-hooks.o \
46 +       py-inferior.o \
47 +       py-infthread.o \
48         py-objfile.o \
49 +       py-param.o \
50         py-prettyprint.o \
51 +       py-symbol.o \
52 +       py-symtab.o \
53         py-type.o \
54         py-utils.o \
55         py-value.o
56  SUBDIR_PYTHON_SRCS = \
57         python/python.c \
58 +       python/py-block.c \
59 +       python/py-breakpoint.c \
60         python/py-cmd.c \
61         python/py-frame.c \
62         python/py-function.c \
63 +       python/py-hooks.c \
64 +       python/py-inferior.c \
65 +       python/py-infthread.c \
66         python/py-objfile.c \
67 +       python/py-param.c \
68         python/py-prettyprint.c \
69 +       python/py-symbol.c \
70 +       python/py-symtab.c \
71         python/py-type.c \
72         python/py-utils.c \
73         python/py-value.c
74 @@ -750,7 +770,7 @@ config/rs6000/nm-rs6000.h top.h bsd-kvm.h gdb-stabs.h reggroups.h \
75  annotate.h sim-regno.h dictionary.h dfp.h main.h frame-unwind.h        \
76  remote-fileio.h i386-linux-tdep.h vax-tdep.h objc-lang.h \
77  sentinel-frame.h bcache.h symfile.h windows-tdep.h linux-tdep.h \
78 -gdb_usleep.h jit.h xml-syscall.h ada-operator.inc
79 +gdb_usleep.h jit.h xml-syscall.h ada-operator.inc python/python.h python/python-internal.h
80  
81  # Header files that already have srcdir in them, or which are in objdir.
82  
83 @@ -874,7 +894,7 @@ generated_files = config.h observer.h observer.inc ada-lex.c \
84         $(COMPILE) $<
85         $(POSTCOMPILE)
86  
87 -all: gdb$(EXEEXT) $(CONFIG_ALL) xml-syscall-copy
88 +all: gdb$(EXEEXT) $(CONFIG_ALL) xml-syscall-copy .gdbinit
89         @$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do
90  .PHONY: all-tui
91  all-tui: $(TUI)$(EXEEXT)
92 @@ -1264,6 +1284,12 @@ stamp-h: $(srcdir)/config.in config.status
93           CONFIG_LINKS= \
94           $(SHELL) config.status
95  
96 +.gdbinit: $(srcdir)/gdbinit.in config.status
97 +       CONFIG_FILES=".gdbinit:gdbinit.in" \
98 +         CONFIG_COMMANDS= \
99 +         CONFIG_HEADERS= \
100 +         $(SHELL) config.status
101 +
102  config.status: $(srcdir)/configure configure.tgt configure.host
103         $(SHELL) config.status --recheck
104  
105 @@ -1963,6 +1989,14 @@ python.o: $(srcdir)/python/python.c
106         $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/python.c
107         $(POSTCOMPILE)
108  
109 +py-block.o: $(srcdir)/python/py-block.c
110 +       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-block.c
111 +       $(POSTCOMPILE)
112 +
113 +py-breakpoint.o: $(srcdir)/python/py-breakpoint.c
114 +       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-breakpoint.c
115 +       $(POSTCOMPILE)
116 +
117  py-cmd.o: $(srcdir)/python/py-cmd.c
118         $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-cmd.c
119         $(POSTCOMPILE)
120 @@ -1975,14 +2009,38 @@ py-function.o: $(srcdir)/python/py-function.c
121         $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-function.c
122         $(POSTCOMPILE)
123  
124 +py-hooks.o: $(srcdir)/python/py-hooks.c
125 +       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-hooks.c
126 +       $(POSTCOMPILE)
127 +
128 +py-inferior.o: $(srcdir)/python/py-inferior.c
129 +       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-inferior.c
130 +       $(POSTCOMPILE)
131 +
132 +py-infthread.o: $(srcdir)/python/py-infthread.c
133 +       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-infthread.c
134 +       $(POSTCOMPILE)
135 +
136  py-objfile.o: $(srcdir)/python/py-objfile.c
137         $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-objfile.c
138         $(POSTCOMPILE)
139  
140 +py-param.o: $(srcdir)/python/py-param.c
141 +       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-param.c
142 +       $(POSTCOMPILE)
143 +
144  py-prettyprint.o: $(srcdir)/python/py-prettyprint.c
145         $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-prettyprint.c
146         $(POSTCOMPILE)
147  
148 +py-symbol.o: $(srcdir)/python/py-symbol.c
149 +       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-symbol.c
150 +       $(POSTCOMPILE)
151 +
152 +py-symtab.o: $(srcdir)/python/py-symtab.c
153 +       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-symtab.c
154 +       $(POSTCOMPILE)
155 +
156  py-type.o: $(srcdir)/python/py-type.c
157         $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-type.c
158         $(POSTCOMPILE)
159 @@ -1995,6 +2053,36 @@ py-value.o: $(srcdir)/python/py-value.c
160         $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-value.c
161         $(POSTCOMPILE)
162  
163 +# All python library files, with the "python/lib" stripped off.
164 +# Note that we should only install files in the "gdb" module.
165 +PY_FILES = gdb/FrameIterator.py gdb/FrameWrapper.py gdb/command/alias.py \
166 +    gdb/command/backtrace.py gdb/command/require.py \
167 +    gdb/command/pahole.py gdb/command/upto.py gdb/command/__init__.py \
168 +    gdb/command/ignore_errors.py gdb/command/save_breakpoints.py \
169 +    gdb/function/caller_is.py gdb/function/in_scope.py \
170 +    gdb/function/__init__.py gdb/backtrace.py gdb/__init__.py
171 +
172 +# Install the Python library.  Python library files go under
173 +# $(pythondir).
174 +install-python:
175 +       files='$(PY_FILES)'; for file in $$files; do \
176 +         dir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
177 +         $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(pythondir)/$$dir; \
178 +         $(INSTALL_DATA) $(srcdir)/python/lib/$$file $(DESTDIR)$(pythondir)/$$file; \
179 +       done
180 +
181 +# Other packages may have their files installed in $(pythondir).
182 +uninstall-python:
183 +       files='$(PY_FILES)'; for file in $$files; do \
184 +         slashdir=`echo "/$$file" | sed 's,/[^/]*$$,,'`; \
185 +         rm -f $(DESTDIR)$(pythondir)/$$file; \
186 +         while test "x$$file" != "x$$slashdir"; do \
187 +           rmdir 2>/dev/null "$(DESTDIR)$(pythondir)$$slashdir"; \
188 +           file="$$slashdir"; \
189 +           slashdir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
190 +         done \
191 +       done
192 +
193  #
194  # Dependency tracking.  Most of this is conditional on GNU Make being
195  # found by configure; if GNU Make is not found, we fall back to a
196 diff --git a/gdb/NEWS b/gdb/NEWS
197 index 4fc6dcd..6744b23 100644
198 --- a/gdb/NEWS
199 +++ b/gdb/NEWS
200 @@ -462,6 +462,13 @@ x86/x86_64 Darwin          i[34567]86-*-darwin*
201  
202  x86_64 MinGW                   x86_64-*-mingw*
203  
204 +* New native configurations
205 +
206 +x86/x86_64 Darwin              i[34567]86-*-darwin*
207 +
208 +info os processes
209 +  Show operating system information about processes.
210 +
211  * New targets
212  
213  Lattice Mico32                  lm32-*
214 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
215 index 9b5d2c6..61676a9 100644
216 --- a/gdb/ada-lang.c
217 +++ b/gdb/ada-lang.c
218 @@ -1621,7 +1621,7 @@ ada_type_of_array (struct value *arr, int bounds)
219          return NULL;
220        while (arity > 0)
221          {
222 -          struct type *range_type = alloc_type_copy (value_type (arr));
223 +         struct type *range_type = alloc_type_copy (value_type (arr));
224            struct type *array_type = alloc_type_copy (value_type (arr));
225            struct value *low = desc_one_bound (descriptor, arity, 0);
226            struct value *high = desc_one_bound (descriptor, arity, 1);
227 @@ -4727,14 +4727,10 @@ ada_lookup_symbol (const char *name, const struct block *block0,
228  
229  static struct symbol *
230  ada_lookup_symbol_nonlocal (const char *name,
231 -                            const char *linkage_name,
232                              const struct block *block,
233                              const domain_enum domain)
234  {
235 -  if (linkage_name == NULL)
236 -    linkage_name = name;
237 -  return ada_lookup_symbol (linkage_name, block_static_block (block), domain,
238 -                            NULL);
239 +  return ada_lookup_symbol (name, block_static_block (block), domain, NULL);
240  }
241  
242  
243 @@ -10839,6 +10835,40 @@ ada_operator_length (struct expression *exp, int pc, int *oplenp, int *argsp)
244      }
245  }
246  
247 +/* Implementation of the exp_descriptor method operator_check.  */
248 +
249 +static int
250 +ada_operator_check (struct expression *exp, int pos,
251 +                   int (*type_func) (struct type *type, void *data),
252 +                   int (*objfile_func) (struct objfile *objfile, void *data),
253 +                   void *data)
254 +{
255 +  const union exp_element *const elts = exp->elts;
256 +  struct type *type = NULL;
257 +
258 +  switch (elts[pos].opcode)
259 +    {
260 +      case UNOP_IN_RANGE:
261 +      case UNOP_QUAL:
262 +       type = elts[pos + 1].type;
263 +       break;
264 +
265 +      default:
266 +       return operator_check_standard (exp, pos, type_func, objfile_func,
267 +                                       data);
268 +    }
269 +
270 +  /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL.  */
271 +
272 +  if (type && type_func && (*type_func) (type, data))
273 +    return 1;
274 +  if (type && TYPE_OBJFILE (type) && objfile_func
275 +      && (*objfile_func) (TYPE_OBJFILE (type), data))
276 +    return 1;
277 +
278 +  return 0;
279 +}
280 +
281  static char *
282  ada_op_name (enum exp_opcode opcode)
283  {
284 @@ -11227,6 +11257,7 @@ parse (void)
285  static const struct exp_descriptor ada_exp_descriptor = {
286    ada_print_subexp,
287    ada_operator_length,
288 +  ada_operator_check,
289    ada_op_name,
290    ada_dump_subexp_body,
291    ada_evaluate_subexp
292 diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
293 index 7d8461c..a6d35d7 100644
294 --- a/gdb/amd64-linux-nat.c
295 +++ b/gdb/amd64-linux-nat.c
296 @@ -270,6 +270,8 @@ amd64_linux_dr_get (ptid_t ptid, int regnum)
297    return value;
298  }
299  
300 +/* Set debug register REGNUM to VALUE in only the one LWP of PTID.  */
301 +
302  static void
303  amd64_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
304  {
305 @@ -286,6 +288,8 @@ amd64_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
306      perror_with_name (_("Couldn't write debug register"));
307  }
308  
309 +/* Set DR_CONTROL to ADDR in all LWPs of LWP_LIST.  */
310 +
311  static void
312  amd64_linux_dr_set_control (unsigned long control)
313  {
314 @@ -297,6 +301,8 @@ amd64_linux_dr_set_control (unsigned long control)
315      amd64_linux_dr_set (ptid, DR_CONTROL, control);
316  }
317  
318 +/* Set address REGNUM (zero based) to ADDR in all LWPs of LWP_LIST.  */
319 +
320  static void
321  amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr)
322  {
323 @@ -310,18 +316,55 @@ amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr)
324      amd64_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr);
325  }
326  
327 +/* Set address REGNUM (zero based) to zero in all LWPs of LWP_LIST.  */
328 +
329  static void
330  amd64_linux_dr_reset_addr (int regnum)
331  {
332    amd64_linux_dr_set_addr (regnum, 0);
333  }
334  
335 +/* Get DR_STATUS from only the one LWP of INFERIOR_PTID.  */
336 +
337  static unsigned long
338  amd64_linux_dr_get_status (void)
339  {
340    return amd64_linux_dr_get (inferior_ptid, DR_STATUS);
341  }
342  
343 +/* Unset VALUE bits in DR_STATUS in all LWPs of LWP_LIST.  */
344 +
345 +static void
346 +amd64_linux_dr_unset_status (unsigned long mask)
347 +{
348 +  struct lwp_info *lp;
349 +  ptid_t ptid;
350 +
351 +  ALL_LWPS (lp, ptid)
352 +    {
353 +      unsigned long value;
354 +      
355 +      value = amd64_linux_dr_get (ptid, DR_STATUS);
356 +      value &= ~mask;
357 +      amd64_linux_dr_set (ptid, DR_STATUS, value);
358 +    }
359 +}
360 +
361 +/* See i386_dr_low_type.detach.  Do not use wrappers amd64_linux_dr_set_control
362 +   or amd64_linux_dr_reset_addr as they would modify the register cache
363 +   (amd64_linux_dr).  */
364 +
365 +static void
366 +amd64_linux_dr_detach (void)
367 +{
368 +  int regnum;
369 +
370 +  amd64_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
371 +  amd64_linux_dr_unset_status (~0UL);
372 +  for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
373 +    amd64_linux_dr_set (inferior_ptid, regnum, 0);
374 +}
375 +
376  static void
377  amd64_linux_new_thread (ptid_t ptid)
378  {
379 @@ -672,6 +715,8 @@ _initialize_amd64_linux_nat (void)
380    i386_dr_low.set_addr = amd64_linux_dr_set_addr;
381    i386_dr_low.reset_addr = amd64_linux_dr_reset_addr;
382    i386_dr_low.get_status = amd64_linux_dr_get_status;
383 +  i386_dr_low.unset_status = amd64_linux_dr_unset_status;
384 +  i386_dr_low.detach = amd64_linux_dr_detach;
385    i386_set_debug_register_length (8);
386  
387    /* Override the GNU/Linux inferior startup hook.  */
388 diff --git a/gdb/block.c b/gdb/block.c
389 index 97ea67a..b20beeb 100644
390 --- a/gdb/block.c
391 +++ b/gdb/block.c
392 @@ -227,8 +227,9 @@ block_set_scope (struct block *block, const char *scope,
393    BLOCK_NAMESPACE (block)->scope = scope;
394  }
395  
396 -/* This returns the using directives list associated with BLOCK, if
397 -   any.  */
398 +/* This returns the first using directives associated with BLOCK, if
399 +   any.  Each BLOCK_NAMESPACE()->USING already contains all the namespaces
400 +   imported at that code point - even those from its parent blocks.  */
401  
402  struct using_direct *
403  block_using (const struct block *block)
404 @@ -318,6 +319,25 @@ allocate_block (struct obstack *obstack)
405    BLOCK_SUPERBLOCK (bl) = NULL;
406    BLOCK_DICT (bl) = NULL;
407    BLOCK_NAMESPACE (bl) = NULL;
408 +  BLOCK_FORTRAN_USE (bl) = NULL;
409  
410    return bl;
411  }
412 +
413 +/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for
414 +   whatever reason.  */
415 +
416 +struct objfile *
417 +block_objfile (const struct block *block)
418 +{
419 +  struct symbol *func;
420 +
421 +  if (block == NULL)
422 +    return NULL;
423 +
424 +  func = block_linkage_function (block);
425 +  if (func == NULL)
426 +    return NULL;
427 +
428 +  return SYMBOL_SYMTAB (func)->objfile;
429 +}
430 diff --git a/gdb/block.h b/gdb/block.h
431 index 53e7371..d373f8a 100644
432 --- a/gdb/block.h
433 +++ b/gdb/block.h
434 @@ -96,6 +96,15 @@ struct block
435      cplus_specific;
436    }
437    language_specific;
438 +
439 +  /* FIXME: It should be in the LANGUAGE_SPECIFIC region but the
440 +     BLOCK_NAMESPACE accessor is not protected by the C language check.  */
441 +
442 +  struct
443 +    {
444 +      struct fortran_using *use;
445 +    }
446 +  fortran_specific;
447  };
448  
449  #define BLOCK_START(bl)                (bl)->startaddr
450 @@ -104,6 +113,7 @@ struct block
451  #define BLOCK_SUPERBLOCK(bl)   (bl)->superblock
452  #define BLOCK_DICT(bl)         (bl)->dict
453  #define BLOCK_NAMESPACE(bl)   (bl)->language_specific.cplus_specific.namespace
454 +#define BLOCK_FORTRAN_USE(bl)  (bl)->fortran_specific.use
455  
456  /* Macro to loop through all symbols in a block BL, in no particular
457     order.  ITER helps keep track of the iteration, and should be a
458 @@ -166,4 +176,6 @@ extern const struct block *block_global_block (const struct block *block);
459  
460  extern struct block *allocate_block (struct obstack *obstack);
461  
462 +extern struct objfile *block_objfile (const struct block *block);
463 +
464  #endif /* BLOCK_H */
465 diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
466 index 811cdfb..b0bf314 100644
467 --- a/gdb/breakpoint.c
468 +++ b/gdb/breakpoint.c
469 @@ -61,6 +61,7 @@
470  #include "valprint.h"
471  #include "jit.h"
472  #include "xml-syscall.h"
473 +#include "parser-defs.h"
474  
475  /* readline include files */
476  #include "readline/readline.h"
477 @@ -112,8 +113,6 @@ struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
478                                               struct symtab_and_line,
479                                               enum bptype);
480  
481 -static void check_duplicates (struct breakpoint *);
482 -
483  static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
484  
485  static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
486 @@ -337,14 +336,14 @@ static int executing_startup;
487              B ? (TMP=B->next, 1): 0;   \
488              B = TMP)
489  
490 -/* Similar iterators for the low-level breakpoints.  */
491 -
492 -#define ALL_BP_LOCATIONS(B)  for (B = bp_location_chain; B; B = B->global_next)
493 +/* Similar iterator for the low-level breakpoints.  SAFE variant is not
494 +   provided so update_global_location_list must not be called while executing
495 +   the block of ALL_BP_LOCATIONS.  */
496  
497 -#define ALL_BP_LOCATIONS_SAFE(B,TMP)   \
498 -       for (B = bp_location_chain;     \
499 -            B ? (TMP=B->global_next, 1): 0;    \
500 -            B = TMP)
501 +#define ALL_BP_LOCATIONS(B,BP_TMP)                                     \
502 +       for (BP_TMP = bp_location;                                      \
503 +            BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
504 +            BP_TMP++)
505  
506  /* Iterator for tracepoints only.  */
507  
508 @@ -356,10 +355,31 @@ static int executing_startup;
509  
510  struct breakpoint *breakpoint_chain;
511  
512 -struct bp_location *bp_location_chain;
513 +/* Array is sorted by bp_location_compare - primarily by the ADDRESS.  */
514 +
515 +static struct bp_location **bp_location;
516 +
517 +/* Number of elements of BP_LOCATION.  */
518 +
519 +static unsigned bp_location_count;
520 +
521 +/* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
522 +   for the current elements of BP_LOCATION which get a valid result from
523 +   bp_location_has_shadow.  You can use it for roughly limiting the subrange of
524 +   BP_LOCATION to scan for shadow bytes for an address you need to read.  */
525 +
526 +static CORE_ADDR bp_location_placed_address_before_address_max;
527 +
528 +/* Maximum offset plus alignment between
529 +   bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
530 +   the current elements of BP_LOCATION which get a valid result from
531 +   bp_location_has_shadow.  You can use it for roughly limiting the subrange of
532 +   BP_LOCATION to scan for shadow bytes for an address you need to read.  */
533 +
534 +static CORE_ADDR bp_location_shadow_len_after_address_max;
535  
536  /* The locations that no longer correspond to any breakpoint,
537 -   unlinked from bp_location_chain, but for which a hit
538 +   unlinked from bp_location array, but for which a hit
539     may still be reported by a target.  */
540  VEC(bp_location_p) *moribund_locations = NULL;
541  
542 @@ -582,6 +602,53 @@ get_breakpoint (int num)
543  }
544  
545  \f
546 +/* Set break condition of breakpoint B to EXP.  */
547 +
548 +void
549 +set_breakpoint_condition (struct breakpoint *b, char *exp, int from_tty)
550 +{
551 +  struct bp_location *loc = b->loc;
552 +
553 +  for (; loc; loc = loc->next)
554 +    {
555 +      if (loc->cond)
556 +       {
557 +         xfree (loc->cond);
558 +         loc->cond = 0;
559 +       }
560 +    }
561 +
562 +  if (b->cond_string != NULL)
563 +    xfree (b->cond_string);
564 +
565 +  if (*exp == 0)
566 +    {
567 +      b->cond_string = NULL;
568 +      if (from_tty)
569 +       printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
570 +    }
571 +  else
572 +    {
573 +      char *arg = exp;
574 +
575 +      /* I don't know if it matters whether this is the string the user
576 +        typed in or the decompiled expression.  */
577 +      b->cond_string = xstrdup (arg);
578 +      b->condition_not_parsed = 0;
579 +      for (loc = b->loc; loc; loc = loc->next)
580 +       {
581 +         arg = exp;
582 +         loc->cond =
583 +           parse_exp_1 (&arg, block_for_pc (loc->address), 0);
584 +         if (*arg)
585 +           error (_("Junk at end of expression"));
586 +       }
587 +    }
588 +
589 +  breakpoints_changed ();
590 +  observer_notify_breakpoint_modified (b->number);
591 +}
592 +
593  /* condition N EXP -- set break condition of breakpoint N to EXP.  */
594  
595  static void
596 @@ -602,42 +669,7 @@ condition_command (char *arg, int from_tty)
597    ALL_BREAKPOINTS (b)
598      if (b->number == bnum)
599        {
600 -       struct bp_location *loc = b->loc;
601 -       for (; loc; loc = loc->next)
602 -         {
603 -           if (loc->cond)
604 -             {
605 -               xfree (loc->cond);
606 -               loc->cond = 0;
607 -             }
608 -         }
609 -       if (b->cond_string != NULL)
610 -         xfree (b->cond_string);
611 -
612 -       if (*p == 0)
613 -         {
614 -           b->cond_string = NULL;
615 -           if (from_tty)
616 -             printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
617 -         }
618 -       else
619 -         {
620 -           arg = p;
621 -           /* I don't know if it matters whether this is the string the user
622 -              typed in or the decompiled expression.  */
623 -           b->cond_string = xstrdup (arg);
624 -           b->condition_not_parsed = 0;
625 -           for (loc = b->loc; loc; loc = loc->next)
626 -             {
627 -               arg = p;
628 -               loc->cond =
629 -                 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
630 -               if (*arg)
631 -                 error (_("Junk at end of expression"));
632 -             }
633 -         }
634 -       breakpoints_changed ();
635 -       observer_notify_breakpoint_modified (b->number);
636 +       set_breakpoint_condition (b, p, from_tty);
637         return;
638        }
639  
640 @@ -735,35 +767,88 @@ commands_from_control_command (char *arg, struct command_line *cmd)
641        }
642    error (_("No breakpoint number %d."), bnum);
643  }
644 -\f
645 +
646 +/* Return non-zero if BL->TARGET_INFO contains valid information.  */
647 +
648 +static int
649 +bp_location_has_shadow (struct bp_location *bl)
650 +{
651 +  if (bl->loc_type != bp_loc_software_breakpoint)
652 +    return 0;
653 +  if (!bl->inserted)
654 +    return 0;
655 +  if (bl->target_info.shadow_len == 0)
656 +    /* bp isn't valid, or doesn't shadow memory.  */
657 +    return 0;
658 +  return 1;
659 +}
660 +
661  /* Update BUF, which is LEN bytes read from the target address MEMADDR,
662 -   by replacing any memory breakpoints with their shadowed contents.  */
663 +   by replacing any memory breakpoints with their shadowed contents.
664 +
665 +   The range of shadowed area by each bp_location is:
666 +     b->address - bp_location_placed_address_before_address_max
667 +     up to b->address + bp_location_shadow_len_after_address_max
668 +   The range we were requested to resolve shadows for is:
669 +     memaddr ... memaddr + le
670 +   Thus the safe cutoff boundaries for performance optimization are
671 +     memaddr + len <= b->address - bp_location_placed_address_before_address_max
672 +   and:
673 +     b->address + bp_location_shadow_len_after_address_max <= memaddr  */
674  
675  void
676  breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
677  {
678 -  struct bp_location *b;
679 -  CORE_ADDR bp_addr = 0;
680 -  int bp_size = 0;
681 -  int bptoffset = 0;
682 +  /* Left boundary, right boundary and media element of our binary search.  */
683 +  unsigned bc_l, bc_r, bc;
684 +
685 +  /* Find BC_L which is a leftmost element which may affect BUF content.  It is
686 +     safe to report lower value but a failure to report higher one.  */
687 +
688 +  bc_l = 0;
689 +  bc_r = bp_location_count;
690 +  while (bc_l + 1 < bc_r)
691 +    {
692 +      struct bp_location *b;
693  
694 -  ALL_BP_LOCATIONS (b)
695 +      bc = (bc_l + bc_r) / 2;
696 +      b = bp_location[bc];
697 +
698 +      if (b->address + bp_location_shadow_len_after_address_max >= b->address
699 +         && b->address + bp_location_shadow_len_after_address_max <= memaddr)
700 +       bc_l = bc;
701 +      else
702 +       bc_r = bc;
703 +    }
704 +
705 +  /* Now do full processing of the found relevant range of elements.  */
706 +
707 +  for (bc = bc_l; bc < bp_location_count; bc++)
708    {
709 +    struct bp_location *b = bp_location[bc];
710 +    CORE_ADDR bp_addr = 0;
711 +    int bp_size = 0;
712 +    int bptoffset = 0;
713 +
714      if (b->owner->type == bp_none)
715        warning (_("reading through apparently deleted breakpoint #%d?"),
716                b->owner->number);
717  
718 -    if (b->loc_type != bp_loc_software_breakpoint)
719 -      continue;
720 -    if (!b->inserted)
721 +    /* Performance optimization: any futher element can no longer affect BUF
722 +       content.  */
723 +
724 +    if (b->address >= bp_location_placed_address_before_address_max
725 +        && memaddr + len <= b->address
726 +                           - bp_location_placed_address_before_address_max)
727 +      break;
728 +
729 +    if (!bp_location_has_shadow (b))
730        continue;
731 +
732      /* Addresses and length of the part of the breakpoint that
733         we need to copy.  */
734      bp_addr = b->target_info.placed_address;
735      bp_size = b->target_info.shadow_len;
736 -    if (bp_size == 0)
737 -      /* bp isn't valid, or doesn't shadow memory.  */
738 -      continue;
739  
740      if (bp_addr + bp_size <= memaddr)
741        /* The breakpoint is entirely before the chunk of memory we
742 @@ -912,7 +997,7 @@ update_watchpoint (struct breakpoint *b, int reparse)
743    struct bp_location *loc;
744    bpstat bs;
745  
746 -  /* We don't free locations.  They are stored in bp_location_chain and
747 +  /* We don't free locations.  They are stored in bp_location array and
748       update_global_locations will eventually delete them and remove
749       breakpoints if needed.  */
750    b->loc = NULL;
751 @@ -1347,7 +1432,7 @@ static void
752  insert_breakpoint_locations (void)
753  {
754    struct breakpoint *bpt;
755 -  struct bp_location *b, *temp;
756 +  struct bp_location *b, **bp_tmp;
757    int error = 0;
758    int val = 0;
759    int disabled_breaks = 0;
760 @@ -1360,7 +1445,7 @@ insert_breakpoint_locations (void)
761       there was an error.  */
762    fprintf_unfiltered (tmp_error_stream, "Warning:\n");
763         
764 -  ALL_BP_LOCATIONS_SAFE (b, temp)
765 +  ALL_BP_LOCATIONS (b, bp_tmp)
766      {
767        if (!should_be_inserted (b) || b->inserted)
768         continue;
769 @@ -1434,10 +1519,10 @@ You may have requested too many hardware breakpoints/watchpoints.\n");
770  int
771  remove_breakpoints (void)
772  {
773 -  struct bp_location *b;
774 +  struct bp_location *b, **bp_tmp;
775    int val = 0;
776  
777 -  ALL_BP_LOCATIONS (b)
778 +  ALL_BP_LOCATIONS (b, bp_tmp)
779    {
780      if (b->inserted)
781        val |= remove_breakpoint (b, mark_uninserted);
782 @@ -1448,10 +1533,10 @@ remove_breakpoints (void)
783  int
784  remove_hw_watchpoints (void)
785  {
786 -  struct bp_location *b;
787 +  struct bp_location *b, **bp_tmp;
788    int val = 0;
789  
790 -  ALL_BP_LOCATIONS (b)
791 +  ALL_BP_LOCATIONS (b, bp_tmp)
792    {
793      if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
794        val |= remove_breakpoint (b, mark_uninserted);
795 @@ -1462,7 +1547,7 @@ remove_hw_watchpoints (void)
796  int
797  reattach_breakpoints (int pid)
798  {
799 -  struct bp_location *b;
800 +  struct bp_location *b, **bp_tmp;
801    int val;
802    struct cleanup *old_chain = save_inferior_ptid ();
803    struct ui_file *tmp_error_stream = mem_fileopen ();
804 @@ -1471,7 +1556,7 @@ reattach_breakpoints (int pid)
805    make_cleanup_ui_file_delete (tmp_error_stream);
806  
807    inferior_ptid = pid_to_ptid (pid);
808 -  ALL_BP_LOCATIONS (b)
809 +  ALL_BP_LOCATIONS (b, bp_tmp)
810    {
811      if (b->inserted)
812        {
813 @@ -1569,12 +1654,42 @@ create_longjmp_master_breakpoint (char *func_name)
814    update_global_location_list (1);
815  }
816  
817 +/* Install a master breakpoint on the unwinder's debug hook.  */
818 +
819 +void
820 +create_exception_master_breakpoint (void)
821 +{
822 +  struct objfile *objfile;
823 +
824 +  ALL_OBJFILES (objfile)
825 +    {
826 +      struct minimal_symbol *debug_hook;
827 +
828 +      debug_hook = lookup_minimal_symbol_text ("_Unwind_DebugHook", objfile);
829 +      if (debug_hook != NULL)
830 +       {
831 +         CORE_ADDR pc;
832 +         struct breakpoint *b;
833 +
834 +         pc = find_function_start_pc (get_objfile_arch (objfile),
835 +                                      SYMBOL_VALUE_ADDRESS (debug_hook),
836 +                                      SYMBOL_OBJ_SECTION (debug_hook));
837 +         b = create_internal_breakpoint (get_objfile_arch (objfile),
838 +                                         pc, bp_exception_master);
839 +         b->addr_string = xstrdup ("_Unwind_DebugHook");
840 +         b->enable_state = bp_disabled;
841 +       }
842 +    }
843 +
844 +  update_global_location_list (1);
845 +}
846 +
847  void
848  update_breakpoints_after_exec (void)
849  {
850    struct breakpoint *b;
851    struct breakpoint *temp;
852 -  struct bp_location *bploc;
853 +  struct bp_location *bploc, **bplocp_tmp;
854  
855    /* We're about to delete breakpoints from GDB's lists.  If the
856       INSERTED flag is true, GDB will try to lift the breakpoints by
857 @@ -1584,7 +1699,7 @@ update_breakpoints_after_exec (void)
858       breakpoints out as soon as it detects an exec.  We don't do that
859       here instead, because there may be other attempts to delete
860       breakpoints after detecting an exec and before reaching here.  */
861 -  ALL_BP_LOCATIONS (bploc)
862 +  ALL_BP_LOCATIONS (bploc, bplocp_tmp)
863      gdb_assert (!bploc->inserted);
864  
865    ALL_BREAKPOINTS_SAFE (b, temp)
866 @@ -1606,7 +1721,7 @@ update_breakpoints_after_exec (void)
867      /* Thread event breakpoints must be set anew after an exec(),
868         as must overlay event and longjmp master breakpoints.  */
869      if (b->type == bp_thread_event || b->type == bp_overlay_event
870 -       || b->type == bp_longjmp_master)
871 +       || b->type == bp_longjmp_master || b->type == bp_exception_master)
872        {
873         delete_breakpoint (b);
874         continue;
875 @@ -1621,7 +1736,8 @@ update_breakpoints_after_exec (void)
876  
877      /* Longjmp and longjmp-resume breakpoints are also meaningless
878         after an exec.  */
879 -    if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
880 +    if (b->type == bp_longjmp || b->type == bp_longjmp_resume
881 +       || b->type == bp_exception || b->type == bp_exception_resume)
882        {
883         delete_breakpoint (b);
884         continue;
885 @@ -1682,12 +1798,13 @@ update_breakpoints_after_exec (void)
886    create_longjmp_master_breakpoint ("_longjmp");
887    create_longjmp_master_breakpoint ("siglongjmp");
888    create_longjmp_master_breakpoint ("_siglongjmp");
889 +  create_exception_master_breakpoint ();
890  }
891  
892  int
893  detach_breakpoints (int pid)
894  {
895 -  struct bp_location *b;
896 +  struct bp_location *b, **bp_tmp;
897    int val = 0;
898    struct cleanup *old_chain = save_inferior_ptid ();
899  
900 @@ -1696,11 +1813,12 @@ detach_breakpoints (int pid)
901  
902    /* Set inferior_ptid; remove_breakpoint uses this global.  */
903    inferior_ptid = pid_to_ptid (pid);
904 -  ALL_BP_LOCATIONS (b)
905 +  ALL_BP_LOCATIONS (b, bp_tmp)
906    {
907      if (b->inserted)
908        val |= remove_breakpoint (b, mark_inserted);
909    }
910 +  val |= target_detach_watchpoints ();
911    do_cleanups (old_chain);
912    return val;
913  }
914 @@ -1793,12 +1911,14 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
915         return val;
916        b->inserted = (is == mark_inserted);
917      }
918 -  else if (b->loc_type == bp_loc_hardware_watchpoint)
919 +  /* bp_loc_hardware_watchpoint with mark_inserted is being handled by
920 +     target_detach_watchpoints.  */
921 +  else if (b->loc_type == bp_loc_hardware_watchpoint && is == mark_uninserted)
922      {
923        struct value *v;
924        struct value *n;
925  
926 -      b->inserted = (is == mark_inserted);
927 +      b->inserted = 0;
928        val = target_remove_watchpoint (b->address, b->length, 
929                                       b->watchpoint_type);
930  
931 @@ -1827,9 +1947,9 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
932  void
933  mark_breakpoints_out (void)
934  {
935 -  struct bp_location *bpt;
936 +  struct bp_location *bpt, **bptp_tmp;
937  
938 -  ALL_BP_LOCATIONS (bpt)
939 +  ALL_BP_LOCATIONS (bpt, bptp_tmp)
940      bpt->inserted = 0;
941  }
942  
943 @@ -1849,7 +1969,7 @@ void
944  breakpoint_init_inferior (enum inf_context context)
945  {
946    struct breakpoint *b, *temp;
947 -  struct bp_location *bpt;
948 +  struct bp_location *bpt, **bptp_tmp;
949    int ix;
950  
951    /* If breakpoint locations are shared across processes, then there's
952 @@ -1857,7 +1977,7 @@ breakpoint_init_inferior (enum inf_context context)
953    if (gdbarch_has_global_breakpoints (target_gdbarch))
954      return;
955  
956 -  ALL_BP_LOCATIONS (bpt)
957 +  ALL_BP_LOCATIONS (bpt, bptp_tmp)
958      if (bpt->owner->enable_state != bp_permanent)
959        bpt->inserted = 0;
960  
961 @@ -1918,10 +2038,10 @@ breakpoint_init_inferior (enum inf_context context)
962  enum breakpoint_here
963  breakpoint_here_p (CORE_ADDR pc)
964  {
965 -  const struct bp_location *bpt;
966 +  struct bp_location *bpt, **bptp_tmp;
967    int any_breakpoint_here = 0;
968  
969 -  ALL_BP_LOCATIONS (bpt)
970 +  ALL_BP_LOCATIONS (bpt, bptp_tmp)
971      {
972        if (bpt->loc_type != bp_loc_software_breakpoint
973           && bpt->loc_type != bp_loc_hardware_breakpoint)
974 @@ -1961,16 +2081,16 @@ moribund_breakpoint_here_p (CORE_ADDR pc)
975  }
976  
977  /* Returns non-zero if there's a breakpoint inserted at PC, which is
978 -   inserted using regular breakpoint_chain/bp_location_chain mechanism.
979 +   inserted using regular breakpoint_chain / bp_location array mechanism.
980     This does not check for single-step breakpoints, which are
981     inserted and removed using direct target manipulation.  */
982  
983  int
984  regular_breakpoint_inserted_here_p (CORE_ADDR pc)
985  {
986 -  const struct bp_location *bpt;
987 +  struct bp_location *bpt, **bptp_tmp;
988  
989 -  ALL_BP_LOCATIONS (bpt)
990 +  ALL_BP_LOCATIONS (bpt, bptp_tmp)
991      {
992        if (bpt->loc_type != bp_loc_software_breakpoint
993           && bpt->loc_type != bp_loc_hardware_breakpoint)
994 @@ -2011,10 +2131,10 @@ breakpoint_inserted_here_p (CORE_ADDR pc)
995  int
996  software_breakpoint_inserted_here_p (CORE_ADDR pc)
997  {
998 -  const struct bp_location *bpt;
999 +  struct bp_location *bpt, **bptp_tmp;
1000    int any_breakpoint_here = 0;
1001  
1002 -  ALL_BP_LOCATIONS (bpt)
1003 +  ALL_BP_LOCATIONS (bpt, bptp_tmp)
1004      {
1005        if (bpt->loc_type != bp_loc_software_breakpoint)
1006         continue;
1007 @@ -2044,12 +2164,12 @@ software_breakpoint_inserted_here_p (CORE_ADDR pc)
1008  int
1009  breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1010  {
1011 -  const struct bp_location *bpt;
1012 +  struct bp_location *bpt, **bptp_tmp;
1013    /* The thread and task IDs associated to PTID, computed lazily.  */
1014    int thread = -1;
1015    int task = 0;
1016    
1017 -  ALL_BP_LOCATIONS (bpt)
1018 +  ALL_BP_LOCATIONS (bpt, bptp_tmp)
1019      {
1020        if (bpt->loc_type != bp_loc_software_breakpoint
1021           && bpt->loc_type != bp_loc_hardware_breakpoint)
1022 @@ -2503,6 +2623,12 @@ print_it_typical (bpstat bs)
1023        result = PRINT_NOTHING;
1024        break;
1025  
1026 +    case bp_exception_master:
1027 +      /* These should never be enabled.  */
1028 +      printf_filtered (_("Exception Master Breakpoint: gdb should not stop!\n"));
1029 +      result = PRINT_NOTHING;
1030 +      break;
1031 +
1032      case bp_watchpoint:
1033      case bp_hardware_watchpoint:
1034        annotate_watchpoint (b->number);
1035 @@ -2590,6 +2716,8 @@ print_it_typical (bpstat bs)
1036      case bp_none:
1037      case bp_longjmp:
1038      case bp_longjmp_resume:
1039 +    case bp_exception:
1040 +    case bp_exception_resume:
1041      case bp_step_resume:
1042      case bp_watchpoint_scope:
1043      case bp_call_dummy:
1044 @@ -2973,8 +3101,12 @@ bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
1045  
1046  /* If BS refers to a watchpoint, determine if the watched values
1047     has actually changed, and we should stop.  If not, set BS->stop
1048 -   to 0.  */
1049 -static void
1050 +   to 0.
1051 +   Return 0 for watchpoints which could not be the cause of this trap.
1052 +   In such case PRINT_IT will be print_it_noop and STOP will be 0.
1053 +   Otherwise return 1 but in such case it is not guaranteed whether this
1054 +   breakpoint did or did not trigger this trap.  */
1055 +static int
1056  bpstat_check_watchpoint (bpstat bs)
1057  {
1058    const struct bp_location *bl = bs->breakpoint_at;
1059 @@ -3063,8 +3195,10 @@ bpstat_check_watchpoint (bpstat bs)
1060              anything for this watchpoint.  */
1061           bs->print_it = print_it_noop;
1062           bs->stop = 0;
1063 +         return 0;
1064         }
1065      }
1066 +  return 1;
1067  }
1068  
1069  
1070 @@ -3157,17 +3291,19 @@ bpstat
1071  bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
1072  {
1073    struct breakpoint *b = NULL;
1074 -  const struct bp_location *bl;
1075 +  struct bp_location *bl, **blp_tmp;
1076    struct bp_location *loc;
1077    /* Root of the chain of bpstat's */
1078    struct bpstats root_bs[1];
1079    /* Pointer to the last thing in the chain currently.  */
1080    bpstat bs = root_bs;
1081    int ix;
1082 -  int need_remove_insert;
1083 +  int need_remove_insert, update_locations = 0;
1084  
1085 -  ALL_BP_LOCATIONS (bl)
1086 +  ALL_BP_LOCATIONS (bl, blp_tmp)
1087    {
1088 +    bpstat bs_prev = bs;
1089 +
1090      b = bl->owner;
1091      gdb_assert (b);
1092      if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
1093 @@ -3188,6 +3324,7 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
1094      /* Come here if it's a watchpoint, or if the break address matches */
1095  
1096      bs = bpstat_alloc (bl, bs);        /* Alloc a bpstat to explain stop */
1097 +    gdb_assert (bs_prev->next == bs);
1098  
1099      /* Assume we stop.  Should we find watchpoint that is not actually
1100         triggered, or if condition of breakpoint is false, we'll reset
1101 @@ -3195,12 +3332,21 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
1102      bs->stop = 1;
1103      bs->print = 1;
1104  
1105 -    bpstat_check_watchpoint (bs);
1106 -    if (!bs->stop)
1107 -      continue;
1108 +    if (!bpstat_check_watchpoint (bs))
1109 +      {
1110 +       /* Ensure bpstat_explains_signal stays false if this BL could not be
1111 +          the cause of this trap.  */
1112 +
1113 +       gdb_assert (bs->print_it == print_it_noop);
1114 +       gdb_assert (!bs->stop);
1115 +       xfree (bs);
1116 +       bs = bs_prev;
1117 +       bs->next = NULL;
1118 +       continue;
1119 +      }
1120  
1121      if (b->type == bp_thread_event || b->type == bp_overlay_event
1122 -       || b->type == bp_longjmp_master)
1123 +       || b->type == bp_longjmp_master || b->type == bp_exception_master)
1124        /* We do not stop for these.  */
1125        bs->stop = 0;
1126      else
1127 @@ -3208,14 +3354,15 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
1128    
1129      if (bs->stop)
1130        {
1131 -       ++(b->hit_count);
1132 +       if (b->enable_state != bp_disabled)
1133 +         ++(b->hit_count);
1134  
1135         /* We will stop here */
1136         if (b->disposition == disp_disable)
1137           {
1138             if (b->enable_state != bp_permanent)
1139               b->enable_state = bp_disabled;
1140 -           update_global_location_list (0);
1141 +           update_locations = 1;
1142           }
1143         if (b->silent)
1144           bs->print = 0;
1145 @@ -3235,6 +3382,10 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
1146        bs->print_it = print_it_noop;
1147    }
1148  
1149 +  /* Delay this call which would break the ALL_BP_LOCATIONS iteration above.  */
1150 +  if (update_locations)
1151 +    update_global_location_list (0);
1152 +
1153    for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
1154      {
1155        if (loc->address == bp_addr)
1156 @@ -3412,6 +3563,7 @@ bpstat_what (bpstat bs)
1157    struct bpstat_what retval;
1158  
1159    retval.call_dummy = 0;
1160 +  retval.is_longjmp = 0;
1161    for (; bs != NULL; bs = bs->next)
1162      {
1163        enum class bs_class = no_effect;
1164 @@ -3458,10 +3610,15 @@ bpstat_what (bpstat bs)
1165             bs_class = no_effect;
1166           break;
1167         case bp_longjmp:
1168 +       case bp_exception:
1169           bs_class = long_jump;
1170 +         retval.is_longjmp = bs->breakpoint_at->owner->type == bp_longjmp;
1171           break;
1172         case bp_longjmp_resume:
1173 +       case bp_exception_resume:
1174           bs_class = long_resume;
1175 +         retval.is_longjmp
1176 +           = bs->breakpoint_at->owner->type == bp_longjmp_resume;
1177           break;
1178         case bp_step_resume:
1179           if (bs->stop)
1180 @@ -3484,6 +3641,7 @@ bpstat_what (bpstat bs)
1181         case bp_thread_event:
1182         case bp_overlay_event:
1183         case bp_longjmp_master:
1184 +       case bp_exception_master:
1185           bs_class = bp_nostop;
1186           break;
1187         case bp_catchpoint:
1188 @@ -3605,6 +3763,8 @@ print_one_breakpoint_location (struct breakpoint *b,
1189      {bp_access_watchpoint, "acc watchpoint"},
1190      {bp_longjmp, "longjmp"},
1191      {bp_longjmp_resume, "longjmp resume"},
1192 +    {bp_exception, "exception"},
1193 +    {bp_exception_resume, "exception resume"},
1194      {bp_step_resume, "step resume"},
1195      {bp_watchpoint_scope, "watchpoint scope"},
1196      {bp_call_dummy, "call dummy"},
1197 @@ -3612,6 +3772,7 @@ print_one_breakpoint_location (struct breakpoint *b,
1198      {bp_thread_event, "thread events"},
1199      {bp_overlay_event, "overlay events"},
1200      {bp_longjmp_master, "longjmp master"},
1201 +    {bp_exception_master, "exception master"},
1202      {bp_catchpoint, "catchpoint"},
1203      {bp_tracepoint, "tracepoint"},
1204      {bp_jit_event, "jit events"},
1205 @@ -3735,6 +3896,8 @@ print_one_breakpoint_location (struct breakpoint *b,
1206        case bp_finish:
1207        case bp_longjmp:
1208        case bp_longjmp_resume:
1209 +      case bp_exception:
1210 +      case bp_exception_resume:
1211        case bp_step_resume:
1212        case bp_watchpoint_scope:
1213        case bp_call_dummy:
1214 @@ -3742,6 +3905,7 @@ print_one_breakpoint_location (struct breakpoint *b,
1215        case bp_thread_event:
1216        case bp_overlay_event:
1217        case bp_longjmp_master:
1218 +      case bp_exception_master:
1219        case bp_tracepoint:
1220        case bp_jit_event:
1221         if (opts.addressprint)
1222 @@ -4197,9 +4361,8 @@ set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
1223     (or use it for any other purpose either).
1224  
1225     More specifically, each of the following breakpoint types will always
1226 -   have a zero valued address and we don't want check_duplicates() to mark
1227 -   breakpoints of any of these types to be a duplicate of an actual
1228 -   breakpoint at address zero:
1229 +   have a zero valued address and we don't want to mark breakpoints of any of
1230 +   these types to be a duplicate of an actual breakpoint at address zero:
1231  
1232        bp_watchpoint
1233        bp_hardware_watchpoint
1234 @@ -4219,88 +4382,6 @@ breakpoint_address_is_meaningful (struct breakpoint *bpt)
1235           && type != bp_catchpoint);
1236  }
1237  
1238 -/* Rescan breakpoints at the same address and section as BPT,
1239 -   marking the first one as "first" and any others as "duplicates".
1240 -   This is so that the bpt instruction is only inserted once.
1241 -   If we have a permanent breakpoint at the same place as BPT, make
1242 -   that one the official one, and the rest as duplicates.  */
1243 -
1244 -static void
1245 -check_duplicates_for (CORE_ADDR address, struct obj_section *section)
1246 -{
1247 -  struct bp_location *b;
1248 -  int count = 0;
1249 -  struct bp_location *perm_bp = 0;
1250 -
1251 -  ALL_BP_LOCATIONS (b)
1252 -    if (b->owner->enable_state != bp_disabled
1253 -       && b->owner->enable_state != bp_call_disabled
1254 -       && b->owner->enable_state != bp_startup_disabled
1255 -       && b->enabled
1256 -       && !b->shlib_disabled
1257 -       && b->address == address        /* address / overlay match */
1258 -       && (!overlay_debugging || b->section == section)
1259 -       && breakpoint_address_is_meaningful (b->owner))
1260 -    {
1261 -      /* Have we found a permanent breakpoint?  */
1262 -      if (b->owner->enable_state == bp_permanent)
1263 -       {
1264 -         perm_bp = b;
1265 -         break;
1266 -       }
1267 -       
1268 -      count++;
1269 -      b->duplicate = count > 1;
1270 -    }
1271 -
1272 -  /* If we found a permanent breakpoint at this address, go over the
1273 -     list again and declare all the other breakpoints there (except
1274 -     other permanent breakpoints) to be the duplicates.  */
1275 -  if (perm_bp)
1276 -    {
1277 -      perm_bp->duplicate = 0;
1278 -
1279 -      /* Permanent breakpoint should always be inserted.  */
1280 -      if (! perm_bp->inserted)
1281 -       internal_error (__FILE__, __LINE__,
1282 -                       _("allegedly permanent breakpoint is not "
1283 -                       "actually inserted"));
1284 -
1285 -      ALL_BP_LOCATIONS (b)
1286 -       if (b != perm_bp)
1287 -         {
1288 -           if (b->owner->enable_state != bp_permanent
1289 -               && b->owner->enable_state != bp_disabled
1290 -               && b->owner->enable_state != bp_call_disabled
1291 -               && b->owner->enable_state != bp_startup_disabled
1292 -               && b->enabled && !b->shlib_disabled             
1293 -               && b->address == address        /* address / overlay match */
1294 -               && (!overlay_debugging || b->section == section)
1295 -               && breakpoint_address_is_meaningful (b->owner))
1296 -             {
1297 -               if (b->inserted)
1298 -                 internal_error (__FILE__, __LINE__,
1299 -                                 _("another breakpoint was inserted on top of "
1300 -                                 "a permanent breakpoint"));
1301 -
1302 -               b->duplicate = 1;
1303 -             }
1304 -         }
1305 -    }
1306 -}
1307 -
1308 -static void
1309 -check_duplicates (struct breakpoint *bpt)
1310 -{
1311 -  struct bp_location *bl = bpt->loc;
1312 -
1313 -  if (! breakpoint_address_is_meaningful (bpt))
1314 -    return;
1315 -
1316 -  for (; bl; bl = bl->next)
1317 -    check_duplicates_for (bl->address, bl->section);    
1318 -}
1319 -
1320  static void
1321  breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
1322                                 int bnum, int have_bnum)
1323 @@ -4382,6 +4463,8 @@ allocate_bp_location (struct breakpoint *bpt)
1324      case bp_finish:
1325      case bp_longjmp:
1326      case bp_longjmp_resume:
1327 +    case bp_exception:
1328 +    case bp_exception_resume:
1329      case bp_step_resume:
1330      case bp_watchpoint_scope:
1331      case bp_call_dummy:
1332 @@ -4390,6 +4473,7 @@ allocate_bp_location (struct breakpoint *bpt)
1333      case bp_overlay_event:
1334      case bp_jit_event:
1335      case bp_longjmp_master:
1336 +    case bp_exception_master:
1337        loc->loc_type = bp_loc_software_breakpoint;
1338        break;
1339      case bp_hardware_breakpoint:
1340 @@ -4568,8 +4652,7 @@ make_breakpoint_permanent (struct breakpoint *b)
1341  }
1342  
1343  /* Call this routine when stepping and nexting to enable a breakpoint
1344 -   if we do a longjmp() in THREAD.  When we hit that breakpoint, call
1345 -   set_longjmp_resume_breakpoint() to figure out where we are going. */
1346 +   if we do a longjmp() or 'throw' in THREAD.  */
1347  
1348  void
1349  set_longjmp_breakpoint (int thread)
1350 @@ -4581,10 +4664,10 @@ set_longjmp_breakpoint (int thread)
1351       longjmp "master" breakpoints.  Here, we simply create momentary
1352       clones of those and enable them for the requested thread.  */
1353    ALL_BREAKPOINTS_SAFE (b, temp)
1354 -    if (b->type == bp_longjmp_master)
1355 +    if (b->type == bp_longjmp_master || b->type == bp_exception_master)
1356        {
1357         struct breakpoint *clone = clone_momentary_breakpoint (b);
1358 -       clone->type = bp_longjmp;
1359 +       clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
1360         clone->thread = thread;
1361        }
1362  }
1363 @@ -4596,7 +4679,7 @@ delete_longjmp_breakpoint (int thread)
1364    struct breakpoint *b, *temp;
1365  
1366    ALL_BREAKPOINTS_SAFE (b, temp)
1367 -    if (b->type == bp_longjmp)
1368 +    if (b->type == bp_longjmp || b->type == bp_exception)
1369        {
1370         if (b->thread == thread)
1371           delete_breakpoint (b);
1372 @@ -4710,9 +4793,9 @@ create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
1373  void
1374  disable_breakpoints_in_shlibs (void)
1375  {
1376 -  struct bp_location *loc;
1377 +  struct bp_location *loc, **locp_tmp;
1378  
1379 -  ALL_BP_LOCATIONS (loc)
1380 +  ALL_BP_LOCATIONS (loc, locp_tmp)
1381    {
1382      struct breakpoint *b = loc->owner;
1383      /* We apply the check to all breakpoints, including disabled
1384 @@ -4742,7 +4825,7 @@ disable_breakpoints_in_shlibs (void)
1385  static void
1386  disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
1387  {
1388 -  struct bp_location *loc;
1389 +  struct bp_location *loc, **locp_tmp;
1390    int disabled_shlib_breaks = 0;
1391  
1392    /* SunOS a.out shared libraries are always mapped, so do not
1393 @@ -4753,7 +4836,7 @@ disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
1394        && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
1395      return;
1396  
1397 -  ALL_BP_LOCATIONS (loc)
1398 +  ALL_BP_LOCATIONS (loc, locp_tmp)
1399    {
1400      struct breakpoint *b = loc->owner;
1401      if ((loc->loc_type == bp_loc_hardware_breakpoint
1402 @@ -5648,6 +5731,8 @@ mention (struct breakpoint *b)
1403        case bp_finish:
1404        case bp_longjmp:
1405        case bp_longjmp_resume:
1406 +      case bp_exception:
1407 +      case bp_exception_resume:
1408        case bp_step_resume:
1409        case bp_call_dummy:
1410        case bp_watchpoint_scope:
1411 @@ -5656,6 +5741,7 @@ mention (struct breakpoint *b)
1412        case bp_overlay_event:
1413        case bp_jit_event:
1414        case bp_longjmp_master:
1415 +      case bp_exception_master:
1416         break;
1417        }
1418  
1419 @@ -6958,6 +7044,7 @@ struct until_break_command_continuation_args
1420  {
1421    struct breakpoint *breakpoint;
1422    struct breakpoint *breakpoint2;
1423 +  int thread_num;
1424  };
1425  
1426  /* This function is called by fetch_inferior_event via the
1427 @@ -6972,6 +7059,7 @@ until_break_command_continuation (void *arg)
1428    delete_breakpoint (a->breakpoint);
1429    if (a->breakpoint2)
1430      delete_breakpoint (a->breakpoint2);
1431 +  delete_longjmp_breakpoint (a->thread_num);
1432  }
1433  
1434  void
1435 @@ -6983,6 +7071,8 @@ until_break_command (char *arg, int from_tty, int anywhere)
1436    struct breakpoint *breakpoint;
1437    struct breakpoint *breakpoint2 = NULL;
1438    struct cleanup *old_chain;
1439 +  int thread;
1440 +  struct thread_info *tp;
1441  
1442    clear_proceed_status ();
1443  
1444 @@ -7021,6 +7111,9 @@ until_break_command (char *arg, int from_tty, int anywhere)
1445  
1446    old_chain = make_cleanup_delete_breakpoint (breakpoint);
1447  
1448 +  tp = inferior_thread ();
1449 +  thread = tp->num;
1450 +
1451    /* Keep within the current frame, or in frames called by the current
1452       one.  */
1453  
1454 @@ -7033,6 +7126,10 @@ until_break_command (char *arg, int from_tty, int anywhere)
1455                                               frame_unwind_caller_id (frame),
1456                                               bp_until);
1457        make_cleanup_delete_breakpoint (breakpoint2);
1458 +
1459 +      set_longjmp_breakpoint (thread);
1460 +      tp->initiating_frame = frame_unwind_caller_id (frame);
1461 +      make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1462      }
1463  
1464    proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
1465 @@ -7049,6 +7146,7 @@ until_break_command (char *arg, int from_tty, int anywhere)
1466  
1467        args->breakpoint = breakpoint;
1468        args->breakpoint2 = breakpoint2;
1469 +      args->thread_num = thread;
1470  
1471        discard_cleanups (old_chain);
1472        add_continuation (inferior_thread (),
1473 @@ -7758,6 +7856,82 @@ do_vec_free (void *p)
1474      VEC_free (bp_location_p, *vec);
1475  }
1476  
1477 +/* A comparison function for bp_location A and B being interfaced to qsort.
1478 +   Sort elements primarily by their ADDRESS (no matter what does
1479 +   breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
1480 +   first bp_permanent OWNERed elements and terciarily just ensuring the array
1481 +   is sorted stable way despite qsort being an instable algorithm.  */
1482 +
1483 +static int
1484 +bp_location_compare (struct bp_location *a, struct bp_location *b)
1485 +{
1486 +  int a_perm = a->owner->enable_state == bp_permanent;
1487 +  int b_perm = b->owner->enable_state == bp_permanent;
1488 +
1489 +  if (a->address != b->address)
1490 +    return (a->address > b->address) - (a->address < b->address);
1491 +
1492 +  /* Sort permanent breakpoints first.  */
1493 +  if (a_perm != b_perm)
1494 +    return (a_perm < b_perm) - (a_perm > b_perm);
1495 +
1496 +  /* Make the user-visible order stable across GDB runs.  Locations of the same
1497 +     breakpoint can be sorted in arbitrary order.  */
1498 +
1499 +  if (a->owner->number != b->owner->number)
1500 +    return (a->owner->number > b->owner->number)
1501 +           - (a->owner->number < b->owner->number);
1502 +
1503 +  return (a > b) - (a < b);
1504 +}
1505 +
1506 +/* Interface bp_location_compare as the COMPAR parameter of qsort function.  */
1507 +
1508 +static int
1509 +bp_location_compare_for_qsort (const void *ap, const void *bp)
1510 +{
1511 +  struct bp_location *a = *(void **) ap;
1512 +  struct bp_location *b = *(void **) bp;
1513 +
1514 +  return bp_location_compare (a, b);
1515 +}
1516 +
1517 +/* Set bp_location_placed_address_before_address_max and
1518 +   bp_location_shadow_len_after_address_max according to the current content of
1519 +   the bp_location array.  */
1520 +
1521 +static void
1522 +bp_location_target_extensions_update (void)
1523 +{
1524 +  struct bp_location *bl, **blp_tmp;
1525 +
1526 +  bp_location_placed_address_before_address_max = 0;
1527 +  bp_location_shadow_len_after_address_max = 0;
1528 +
1529 +  ALL_BP_LOCATIONS (bl, blp_tmp)
1530 +    {
1531 +      CORE_ADDR start, end, addr;
1532 +
1533 +      if (!bp_location_has_shadow (bl))
1534 +       continue;
1535 +
1536 +      start = bl->target_info.placed_address;
1537 +      end = start + bl->target_info.shadow_len;
1538 +
1539 +      gdb_assert (bl->address >= start);
1540 +      addr = bl->address - start;
1541 +      if (addr > bp_location_placed_address_before_address_max)
1542 +       bp_location_placed_address_before_address_max = addr;
1543 +
1544 +      /* Zero SHADOW_LEN would not pass bp_location_has_shadow.  */
1545 +
1546 +      gdb_assert (bl->address < end);
1547 +      addr = end - bl->address;
1548 +      if (addr > bp_location_shadow_len_after_address_max)
1549 +       bp_location_shadow_len_after_address_max = addr;
1550 +    }
1551 +}
1552 +
1553  /* If SHOULD_INSERT is false, do not insert any breakpoint locations
1554     into the inferior, only remove already-inserted locations that no
1555     longer should be inserted.  Functions that delete a breakpoint or
1556 @@ -7777,49 +7951,66 @@ static void
1557  update_global_location_list (int should_insert)
1558  {
1559    struct breakpoint *b;
1560 -  struct bp_location **next = &bp_location_chain;
1561 -  struct bp_location *loc;
1562 -  struct bp_location *loc2;
1563 -  VEC(bp_location_p) *old_locations = NULL;
1564 -  int ret;
1565 -  int ix;
1566 +  struct bp_location **locp, *loc;
1567    struct cleanup *cleanups;
1568  
1569 -  cleanups = make_cleanup (do_vec_free, &old_locations);
1570 -  /* Store old locations for future reference.  */
1571 -  for (loc = bp_location_chain; loc; loc = loc->global_next)
1572 -    VEC_safe_push (bp_location_p, old_locations, loc);
1573 +  /* The first bp_location being the only one non-DUPLICATE for the current run
1574 +     of the same ADDRESS.  */
1575 +  struct bp_location *loc_first;
1576 +
1577 +  /* Saved former bp_location array which we compare against the newly built
1578 +     bp_location from the current state of ALL_BREAKPOINTS.  */
1579 +  struct bp_location **old_location, **old_locp;
1580 +  unsigned old_location_count;
1581 +
1582 +  old_location = bp_location;
1583 +  old_location_count = bp_location_count;
1584 +  bp_location = NULL;
1585 +  bp_location_count = 0;
1586 +  cleanups = make_cleanup (xfree, old_location);
1587  
1588 -  bp_location_chain = NULL;
1589    ALL_BREAKPOINTS (b)
1590 -    {
1591 -      for (loc = b->loc; loc; loc = loc->next)
1592 -       {
1593 -         *next = loc;
1594 -         next = &(loc->global_next);
1595 -         *next = NULL;
1596 -       }
1597 -    }
1598 +    for (loc = b->loc; loc; loc = loc->next)
1599 +      bp_location_count++;
1600 +
1601 +  bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
1602 +  locp = bp_location;
1603 +  ALL_BREAKPOINTS (b)
1604 +    for (loc = b->loc; loc; loc = loc->next)
1605 +      *locp++ = loc;
1606 +  qsort (bp_location, bp_location_count, sizeof (*bp_location),
1607 +        bp_location_compare_for_qsort);
1608 +
1609 +  bp_location_target_extensions_update ();
1610  
1611    /* Identify bp_location instances that are no longer present in the new
1612       list, and therefore should be freed.  Note that it's not necessary that
1613       those locations should be removed from inferior -- if there's another
1614       location at the same address (previously marked as duplicate),
1615 -     we don't need to remove/insert the location.  */
1616 -  for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
1617 +     we don't need to remove/insert the location.
1618 +     
1619 +     LOCP is kept in sync with OLD_LOCP, each pointing to the current and
1620 +     former bp_location array state respectively.  */
1621 +
1622 +  locp = bp_location;
1623 +  for (old_locp = old_location; old_locp < old_location + old_location_count;
1624 +       old_locp++)
1625      {
1626 -      /* Tells if 'loc' is found amoung the new locations.  If not, we
1627 +      struct bp_location *old_loc = *old_locp;
1628 +
1629 +      /* Tells if 'old_loc' is found amoung the new locations.  If not, we
1630          have to free it.  */
1631 -      int found_object = 0;
1632 +      int found_object;
1633        /* Tells if the location should remain inserted in the target.  */
1634        int keep_in_target = 0;
1635        int removed = 0;
1636 -      for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
1637 -       if (loc2 == loc)
1638 -         {
1639 -           found_object = 1;
1640 -           break;
1641 -         }
1642 +
1643 +      /* Skip LOCP entries which will definitely never be needed.  Stop either
1644 +        at or being the one matching OLD_LOC.  */
1645 +      while (locp < bp_location + bp_location_count
1646 +            && bp_location_compare (*locp, old_loc) < 0)
1647 +       locp++;
1648 +      found_object = locp < bp_location + bp_location_count && *locp == old_loc;
1649  
1650        /* If this location is no longer present, and inserted, look if there's
1651          maybe a new location at the same address.  If so, mark that one 
1652 @@ -7827,11 +8018,11 @@ update_global_location_list (int should_insert)
1653          don't have a time window where a breakpoint at certain location is not
1654          inserted.  */
1655  
1656 -      if (loc->inserted)
1657 +      if (old_loc->inserted)
1658         {
1659           /* If the location is inserted now, we might have to remove it.  */
1660  
1661 -         if (found_object && should_be_inserted (loc))
1662 +         if (found_object && should_be_inserted (old_loc))
1663             {
1664               /* The location is still present in the location list, and still
1665                  should be inserted.  Don't do anything.  */
1666 @@ -7842,37 +8033,46 @@ update_global_location_list (int should_insert)
1667               /* The location is either no longer present, or got disabled.
1668                  See if there's another location at the same address, in which 
1669                  case we don't need to remove this one from the target.  */
1670 -             if (breakpoint_address_is_meaningful (loc->owner))
1671 -               for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
1672 -                 {
1673 -                   /* For the sake of should_insert_location.  The
1674 -                      call to check_duplicates will fix up this later.  */
1675 -                   loc2->duplicate = 0;
1676 -                   if (should_be_inserted (loc2)
1677 -                       && loc2 != loc && loc2->address == loc->address)
1678 -                     {           
1679 -                       loc2->inserted = 1;
1680 -                       loc2->target_info = loc->target_info;
1681 -                       keep_in_target = 1;
1682 -                       break;
1683 -                     }
1684 -                 }
1685 +
1686 +             if (breakpoint_address_is_meaningful (old_loc->owner))
1687 +               {
1688 +                 struct bp_location **loc2p;
1689 +
1690 +                 for (loc2p = locp;
1691 +                      loc2p < bp_location + bp_location_count
1692 +                      && (*loc2p)->address == old_loc->address;
1693 +                      loc2p++)
1694 +                   {
1695 +                     struct bp_location *loc2 = *loc2p;
1696 +
1697 +                     /* For the sake of should_be_inserted.
1698 +                        Duplicates check below will fix up this later.  */
1699 +                     loc2->duplicate = 0;
1700 +                     if (loc2 != old_loc && should_be_inserted (loc2))
1701 +                       {                 
1702 +                         loc2->inserted = 1;
1703 +                         loc2->target_info = old_loc->target_info;
1704 +                         keep_in_target = 1;
1705 +                         break;
1706 +                       }
1707 +                   }
1708 +               }
1709             }
1710  
1711           if (!keep_in_target)
1712             {
1713 -             if (remove_breakpoint (loc, mark_uninserted))
1714 +             if (remove_breakpoint (old_loc, mark_uninserted))
1715                 {
1716                   /* This is just about all we can do.  We could keep this
1717                      location on the global list, and try to remove it next
1718                      time, but there's no particular reason why we will
1719                      succeed next time.  
1720                      
1721 -                    Note that at this point, loc->owner is still valid,
1722 +                    Note that at this point, old_loc->owner is still valid,
1723                      as delete_breakpoint frees the breakpoint only
1724                      after calling us.  */
1725                   printf_filtered (_("warning: Error removing breakpoint %d\n"), 
1726 -                                  loc->owner->number);
1727 +                                  old_loc->owner->number);
1728                 }
1729               removed = 1;
1730             }
1731 @@ -7894,19 +8094,59 @@ update_global_location_list (int should_insert)
1732                  longer need to keep this breakpoint.  This is just a
1733                  heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
1734                  which is usability issue, but not a correctness problem.  */
1735 -             loc->events_till_retirement = 3 * (thread_count () + 1);
1736 -             loc->owner = NULL;
1737 +             old_loc->events_till_retirement = 3 * (thread_count () + 1);
1738 +             old_loc->owner = NULL;
1739  
1740 -             VEC_safe_push (bp_location_p, moribund_locations, loc);
1741 +             VEC_safe_push (bp_location_p, moribund_locations, old_loc);
1742             }
1743           else
1744 -           free_bp_location (loc);
1745 +           free_bp_location (old_loc);
1746         }
1747      }
1748  
1749 -  ALL_BREAKPOINTS (b)
1750 +  /* Rescan breakpoints at the same address and section,
1751 +     marking the first one as "first" and any others as "duplicates".
1752 +     This is so that the bpt instruction is only inserted once.
1753 +     If we have a permanent breakpoint at the same place as BPT, make
1754 +     that one the official one, and the rest as duplicates.  Permanent
1755 +     breakpoints are sorted first for the same address.  */
1756 +
1757 +  loc_first = NULL;
1758 +  ALL_BP_LOCATIONS (loc, locp)
1759      {
1760 -      check_duplicates (b);
1761 +      struct breakpoint *b = loc->owner;
1762 +
1763 +      if (b->enable_state == bp_disabled
1764 +         || b->enable_state == bp_call_disabled
1765 +         || b->enable_state == bp_startup_disabled
1766 +         || !loc->enabled
1767 +         || loc->shlib_disabled
1768 +         || !breakpoint_address_is_meaningful (b))
1769 +       continue;
1770 +
1771 +      /* Permanent breakpoint should always be inserted.  */
1772 +      if (b->enable_state == bp_permanent && ! loc->inserted)
1773 +       internal_error (__FILE__, __LINE__,
1774 +                       _("allegedly permanent breakpoint is not "
1775 +                       "actually inserted"));
1776 +
1777 +      if (loc_first == NULL
1778 +         /* address / overlay match */
1779 +         || loc->address != loc_first->address
1780 +         || (overlay_debugging && loc->section != loc_first->section))
1781 +       {
1782 +         loc_first = loc;
1783 +         loc->duplicate = 0;
1784 +         continue;
1785 +       }
1786 +
1787 +      loc->duplicate = 1;
1788 +
1789 +      if (loc_first->owner->enable_state == bp_permanent && loc->inserted
1790 +          && b->enable_state != bp_permanent)
1791 +       internal_error (__FILE__, __LINE__,
1792 +                       _("another breakpoint was inserted on top of "
1793 +                       "a permanent breakpoint"));
1794      }
1795  
1796    if (breakpoints_always_inserted_mode () && should_insert
1797 @@ -8083,6 +8323,7 @@ delete_command (char *arg, int from_tty)
1798             && b->type != bp_thread_event
1799             && b->type != bp_overlay_event
1800             && b->type != bp_longjmp_master
1801 +           && b->type != bp_exception_master
1802             && b->number >= 0)
1803           {
1804             breaks_to_delete = 1;
1805 @@ -8102,6 +8343,7 @@ delete_command (char *arg, int from_tty)
1806                 && b->type != bp_jit_event
1807                 && b->type != bp_overlay_event
1808                 && b->type != bp_longjmp_master
1809 +               && b->type != bp_exception_master
1810                 && b->number >= 0)
1811               delete_breakpoint (b);
1812           }
1813 @@ -8404,6 +8646,7 @@ breakpoint_re_set_one (void *bint)
1814          reset later by breakpoint_re_set.  */
1815      case bp_overlay_event:
1816      case bp_longjmp_master:
1817 +    case bp_exception_master:
1818        delete_breakpoint (b);
1819        break;
1820  
1821 @@ -8427,6 +8670,8 @@ breakpoint_re_set_one (void *bint)
1822      case bp_longjmp:
1823      case bp_longjmp_resume:
1824      case bp_jit_event:
1825 +    case bp_exception:
1826 +    case bp_exception_resume:
1827        break;
1828      }
1829  
1830 @@ -8462,6 +8707,7 @@ breakpoint_re_set (void)
1831    create_longjmp_master_breakpoint ("_longjmp");
1832    create_longjmp_master_breakpoint ("siglongjmp");
1833    create_longjmp_master_breakpoint ("_siglongjmp");
1834 +  create_exception_master_breakpoint ();
1835  }
1836  \f
1837  /* Reset the thread number of this breakpoint:
1838 @@ -9327,6 +9573,22 @@ all_tracepoints ()
1839    return tp_vec;
1840  }
1841  
1842 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
1843 +
1844 +static void
1845 +breakpoint_types_mark_used (void)
1846 +{
1847 +  struct breakpoint *b;
1848 +
1849 +  ALL_BREAKPOINTS (b)
1850 +    {
1851 +      if (b->exp)
1852 +       exp_types_mark_used (b->exp);
1853 +      if (b->val)
1854 +       type_mark_used (value_type (b->val));
1855 +    }
1856 +}
1857 +
1858  \f
1859  /* This help string is used for the break, hbreak, tbreak and thbreak commands.
1860     It is defined as a macro to prevent duplication.
1861 @@ -9850,4 +10112,5 @@ inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
1862    automatic_hardware_breakpoints = 1;
1863  
1864    observer_attach_about_to_proceed (breakpoint_about_to_proceed);
1865 +  observer_attach_mark_used (breakpoint_types_mark_used);
1866  }
1867 diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
1868 index ba499c6..80f702f 100644
1869 --- a/gdb/breakpoint.h
1870 +++ b/gdb/breakpoint.h
1871 @@ -56,6 +56,13 @@ enum bptype
1872      bp_longjmp,                        /* secret breakpoint to find longjmp() */
1873      bp_longjmp_resume,         /* secret breakpoint to escape longjmp() */
1874  
1875 +    /* An internal breakpoint that is installed on the unwinder's
1876 +       debug hook.  */
1877 +    bp_exception,
1878 +    /* An internal breakpoint that is set at the point where an
1879 +       exception will land.  */
1880 +    bp_exception_resume,
1881 +
1882      /* Used by wait_for_inferior for stepping over subroutine calls, for
1883         stepping over signal handlers, and for skipping prologues.  */
1884      bp_step_resume,
1885 @@ -118,6 +125,9 @@ enum bptype
1886  
1887      bp_longjmp_master,
1888  
1889 +    /* Like bp_longjmp_master, but for exceptions.  */
1890 +    bp_exception_master,
1891 +
1892      bp_catchpoint,
1893  
1894      bp_tracepoint,
1895 @@ -228,10 +238,6 @@ struct bp_location
1896       the same parent breakpoint.  */
1897    struct bp_location *next;
1898  
1899 -  /* Pointer to the next breakpoint location, in a global
1900 -     list of all breakpoint locations.  */
1901 -  struct bp_location *global_next;
1902
1903    /* Type of this breakpoint location.  */
1904    enum bp_loc_type loc_type;
1905  
1906 @@ -583,6 +589,10 @@ struct bpstat_what
1907         continuing from a call dummy without popping the frame is not a
1908         useful one).  */
1909      int call_dummy;
1910 +
1911 +    /* Used for BPSTAT_WHAT_SET_LONGJMP_RESUME.  True if we are
1912 +       handling a longjmp, false if we are handling an exception.  */
1913 +    int is_longjmp;
1914    };
1915  
1916  /* The possible return values for print_bpstat, print_it_normal,
1917 @@ -946,6 +956,9 @@ extern int catching_syscall_number (int syscall_number);
1918  /* Tell a breakpoint to be quiet.  */
1919  extern void make_breakpoint_silent (struct breakpoint *);
1920  
1921 +/* Set break condition of breakpoint B to EXP.  */
1922 +extern void set_breakpoint_condition (struct breakpoint *b, char *exp, int from_tty);
1923 +
1924  /* Return a tracepoint with the given number if found.  */
1925  extern struct breakpoint *get_tracepoint (int num);
1926  
1927 diff --git a/gdb/c-exp.y b/gdb/c-exp.y
1928 index f8e4f12..5b47e2e 100644
1929 --- a/gdb/c-exp.y
1930 +++ b/gdb/c-exp.y
1931 @@ -117,6 +117,8 @@ static int yylex (void);
1932  
1933  void yyerror (char *);
1934  
1935 +/* Cleanup for 'nonempty_typelist' */
1936 +static struct cleanup *typelist_cleanup;
1937  %}
1938  
1939  /* Although the yacc "value" of an expression is not used,
1940 @@ -157,6 +159,7 @@ void yyerror (char *);
1941  %{
1942  /* YYSTYPE gets defined by %union */
1943  static int parse_number (char *, int, int, YYSTYPE *);
1944 +static struct stoken operator_stoken (const char *);
1945  %}
1946  
1947  %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
1948 @@ -199,9 +202,12 @@ static int parse_number (char *, int, int, YYSTYPE *);
1949  
1950  %token <ssym> NAME_OR_INT 
1951  
1952 +%token OPERATOR
1953  %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
1954  %token TEMPLATE
1955  %token ERROR
1956 +%token NEW DELETE
1957 +%type <sval> operator
1958  
1959  /* Special type cases, put in to allow the parser to distinguish different
1960     legal basetypes.  */
1961 @@ -401,6 +407,36 @@ arglist    :       arglist ',' exp   %prec ABOVE_COMMA
1962                         { arglist_len++; }
1963         ;
1964  
1965 +exp     :       exp '(' nonempty_typelist ')' const_or_volatile
1966 +                       { int i;
1967 +                         write_exp_elt_opcode (TYPE_INSTANCE);
1968 +                         write_exp_elt_longcst ((LONGEST) $<ivec>3[0]);
1969 +                         for (i = 0; i < $<ivec>3[0]; ++i)
1970 +                           write_exp_elt_type ($<tvec>3[i + 1]);
1971 +                         write_exp_elt_longcst((LONGEST) $<ivec>3[0]);
1972 +                         write_exp_elt_opcode (TYPE_INSTANCE);
1973 +                         do_cleanups (typelist_cleanup);
1974 +                       }
1975 +       ;
1976 +
1977 +/*
1978 +exp     :       BLOCKNAME '(' nonempty_typelist ')'
1979 +                       { int i;
1980 +                         write_exp_elt_opcode (TYPE_INSTANCE_LOOKUP);
1981 +                         write_exp_elt_sym ($1.sym);
1982 +                         write_exp_elt_opcode (TYPE_INSTANCE_LOOKUP);
1983 +
1984 +                         write_exp_elt_opcode (TYPE_INSTANCE);
1985 +                         write_exp_elt_longcst ((LONGEST) $<ivec>3[0]);
1986 +                         for (i = 0; i < $<ivec>3[0]; ++i)
1987 +                           write_exp_elt_type ($<tvec>3[i + 1]);
1988 +                         write_exp_elt_longcst((LONGEST) $<ivec>3[0]);
1989 +                         write_exp_elt_opcode (TYPE_INSTANCE);
1990 +                         do_cleanups (typelist_cleanup);
1991 +                       }
1992 +       ;
1993 +*/
1994 +
1995  rcurly :       '}'
1996                         { $$ = end_arglist () - 1; }
1997         ;
1998 @@ -703,6 +739,7 @@ variable:   block COLONCOLON name
1999  qualified_name:        typebase COLONCOLON name
2000                         {
2001                           struct type *type = $1;
2002 +                         CHECK_TYPEDEF (type);
2003                           if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2004                               && TYPE_CODE (type) != TYPE_CODE_UNION
2005                               && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2006 @@ -718,6 +755,7 @@ qualified_name:     typebase COLONCOLON name
2007                         {
2008                           struct type *type = $1;
2009                           struct stoken tmp_token;
2010 +                         CHECK_TYPEDEF (type);
2011                           if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2012                               && TYPE_CODE (type) != TYPE_CODE_UNION
2013                               && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2014 @@ -740,12 +778,13 @@ qualified_name:   typebase COLONCOLON name
2015         ;
2016  
2017  variable:      qualified_name
2018 +       |       COLONCOLON qualified_name
2019         |       COLONCOLON name
2020                         {
2021                           char *name = copy_name ($2);
2022                           struct symbol *sym;
2023                           struct minimal_symbol *msymbol;
2024 -
2025 +                         
2026                           sym =
2027                             lookup_symbol (name, (const struct block *) NULL,
2028                                            VAR_DOMAIN, (int *) NULL);
2029 @@ -883,7 +922,7 @@ array_mod:  '[' ']'
2030  func_mod:      '(' ')'
2031                         { $$ = 0; }
2032         |       '(' nonempty_typelist ')'
2033 -                       { free ($2); $$ = 0; }
2034 +                       { do_cleanups (typelist_cleanup); $$ = 0; }
2035         ;
2036  
2037  /* We used to try to recognize pointer to member types here, but
2038 @@ -1088,12 +1127,15 @@ typename:       TYPENAME
2039  nonempty_typelist
2040         :       type
2041                 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
2042 +                 typelist_cleanup = make_cleanup (free, $$);
2043                   $<ivec>$[0] = 1;      /* Number of types in vector */
2044                   $$[1] = $1;
2045                 }
2046         |       nonempty_typelist ',' type
2047                 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
2048                   $$ = (struct type **) realloc ((char *) $1, len);
2049 +                 discard_cleanups (typelist_cleanup);
2050 +                 typelist_cleanup = make_cleanup (free, $$);
2051                   $$[$<ivec>$[0]] = $3;
2052                 }
2053         ;
2054 @@ -1117,10 +1159,135 @@ const_or_volatile_noopt:       const_and_volatile
2055                         { push_type (tp_volatile); }
2056         ;
2057  
2058 +operator:      OPERATOR NEW
2059 +                       { $$ = operator_stoken (" new"); }
2060 +       |       OPERATOR DELETE
2061 +                       { $$ = operator_stoken (" delete"); }
2062 +       |       OPERATOR NEW '[' ']'
2063 +                       { $$ = operator_stoken (" new[]"); }
2064 +       |       OPERATOR DELETE '[' ']'
2065 +                       { $$ = operator_stoken (" delete[]"); }
2066 +       |       OPERATOR '+'
2067 +                       { $$ = operator_stoken ("+"); }
2068 +       |       OPERATOR '-'
2069 +                       { $$ = operator_stoken ("-"); }
2070 +       |       OPERATOR '*'
2071 +                       { $$ = operator_stoken ("*"); }
2072 +       |       OPERATOR '/'
2073 +                       { $$ = operator_stoken ("/"); }
2074 +       |       OPERATOR '%'
2075 +                       { $$ = operator_stoken ("%"); }
2076 +       |       OPERATOR '^'
2077 +                       { $$ = operator_stoken ("^"); }
2078 +       |       OPERATOR '&'
2079 +                       { $$ = operator_stoken ("&"); }
2080 +       |       OPERATOR '|'
2081 +                       { $$ = operator_stoken ("|"); }
2082 +       |       OPERATOR '~'
2083 +                       { $$ = operator_stoken ("~"); }
2084 +       |       OPERATOR '!'
2085 +                       { $$ = operator_stoken ("!"); }
2086 +       |       OPERATOR '='
2087 +                       { $$ = operator_stoken ("="); }
2088 +       |       OPERATOR '<'
2089 +                       { $$ = operator_stoken ("<"); }
2090 +       |       OPERATOR '>'
2091 +                       { $$ = operator_stoken (">"); }
2092 +       |       OPERATOR ASSIGN_MODIFY
2093 +                       { const char *op = "unknown";
2094 +                         switch ($2)
2095 +                           {
2096 +                           case BINOP_RSH:
2097 +                             op = ">>=";
2098 +                             break;
2099 +                           case BINOP_LSH:
2100 +                             op = "<<=";
2101 +                             break;
2102 +                           case BINOP_ADD:
2103 +                             op = "+=";
2104 +                             break;
2105 +                           case BINOP_SUB:
2106 +                             op = "-=";
2107 +                             break;
2108 +                           case BINOP_MUL:
2109 +                             op = "*=";
2110 +                             break;
2111 +                           case BINOP_DIV:
2112 +                             op = "/=";
2113 +                             break;
2114 +                           case BINOP_REM:
2115 +                             op = "%=";
2116 +                             break;
2117 +                           case BINOP_BITWISE_IOR:
2118 +                             op = "|=";
2119 +                             break;
2120 +                           case BINOP_BITWISE_AND:
2121 +                             op = "&=";
2122 +                             break;
2123 +                           case BINOP_BITWISE_XOR:
2124 +                             op = "^=";
2125 +                             break;
2126 +                           default:
2127 +                             break;
2128 +                           }
2129 +
2130 +                         $$ = operator_stoken (op);
2131 +                       }
2132 +       |       OPERATOR LSH
2133 +                       { $$ = operator_stoken ("<<"); }
2134 +       |       OPERATOR RSH
2135 +                       { $$ = operator_stoken (">>"); }
2136 +       |       OPERATOR EQUAL
2137 +                       { $$ = operator_stoken ("=="); }
2138 +       |       OPERATOR NOTEQUAL
2139 +                       { $$ = operator_stoken ("!="); }
2140 +       |       OPERATOR LEQ
2141 +                       { $$ = operator_stoken ("<="); }
2142 +       |       OPERATOR GEQ
2143 +                       { $$ = operator_stoken (">="); }
2144 +       |       OPERATOR ANDAND
2145 +                       { $$ = operator_stoken ("&&"); }
2146 +       |       OPERATOR OROR
2147 +                       { $$ = operator_stoken ("||"); }
2148 +       |       OPERATOR INCREMENT
2149 +                       { $$ = operator_stoken ("++"); }
2150 +       |       OPERATOR DECREMENT
2151 +                       { $$ = operator_stoken ("--"); }
2152 +       |       OPERATOR ','
2153 +                       { $$ = operator_stoken (","); }
2154 +       |       OPERATOR ARROW_STAR
2155 +                       { $$ = operator_stoken ("->*"); }
2156 +       |       OPERATOR ARROW
2157 +                       { $$ = operator_stoken ("->"); }
2158 +       |       OPERATOR '(' ')'
2159 +                       { $$ = operator_stoken ("()"); }
2160 +       |       OPERATOR '[' ']'
2161 +                       { $$ = operator_stoken ("[]"); }
2162 +       |       OPERATOR ptype
2163 +                       { char *name, *canon;
2164 +                         long length;
2165 +                         struct ui_file *buf = mem_fileopen ();
2166 +
2167 +                         c_print_type ($2, NULL, buf, -1, 0);
2168 +                         name = ui_file_xstrdup (buf, &length);
2169 +                         canon = cp_canonicalize_string (name);
2170 +                         if (canon != NULL)
2171 +                           {
2172 +                             xfree (name);
2173 +                             name = canon;
2174 +                           }
2175 +                         ui_file_delete (buf);
2176 +                         $$ = operator_stoken (name);
2177 +                       }
2178 +       ;
2179 +
2180 +
2181 +
2182  name   :       NAME { $$ = $1.stoken; }
2183         |       BLOCKNAME { $$ = $1.stoken; }
2184         |       TYPENAME { $$ = $1.stoken; }
2185         |       NAME_OR_INT  { $$ = $1.stoken; }
2186 +       |       operator { $$ = $1; }
2187         ;
2188  
2189  name_not_typename :    NAME
2190 @@ -1136,6 +1303,20 @@ name_not_typename :      NAME
2191  
2192  %%
2193  
2194 +/* Returns a stoken of the operator name given by OP (which does not
2195 +   include the string "operator").  The result is xmalloc'd.  */
2196 +static struct stoken
2197 +operator_stoken (const char *op)
2198 +{
2199 +  static const char *operator_string = "operator";
2200 +  struct stoken st = { NULL, 0 };
2201 +  st.length = strlen (operator_string) + strlen (op);
2202 +  st.ptr = xmalloc (st.length + 1);
2203 +  strcpy (st.ptr, operator_string);
2204 +  strcat (st.ptr, op);
2205 +  return st;
2206 +};
2207 +
2208  /* Take care of parsing a number (anything that starts with a digit).
2209     Set yylval and return the token type; update lexptr.
2210     LEN is the number of characters in it.  */
2211 @@ -1714,6 +1895,9 @@ static const struct token ident_tokens[] =
2212      {"long", LONG, OP_NULL, 0},
2213      {"true", TRUEKEYWORD, OP_NULL, 1},
2214      {"int", INT_KEYWORD, OP_NULL, 0},
2215 +    {"new", NEW, OP_NULL, 1},
2216 +    {"delete", DELETE, OP_NULL, 1},
2217 +    {"operator", OPERATOR, OP_NULL, 1},
2218  
2219      {"and", ANDAND, BINOP_END, 1},
2220      {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, 1},
2221 @@ -1822,6 +2006,13 @@ static int last_was_structop;
2222  static int
2223  yylex (void)
2224  {
2225 +  /* name_prefix stores the full qualification of a variable that is
2226 +     specified in the expression. It is used to eleminate confusion 
2227 +     during lookup.*/
2228 +  static char *name_prefix = NULL;
2229 +  static int name_prefix_len = 0;
2230 +  static int terminate_prefix = 0;
2231 +  
2232    int c;
2233    int namelen;
2234    unsigned int i;
2235 @@ -1830,9 +2021,19 @@ yylex (void)
2236    char *copy;
2237  
2238    last_was_structop = 0;
2239 -
2240 +  
2241   retry:
2242 -
2243 +  
2244 +  if (terminate_prefix
2245 +      || lexptr != name_prefix + name_prefix_len)
2246 +    {
2247 +      /* Some token was skipped, so clear name_prefix. */
2248 +      name_prefix = NULL;
2249 +      name_prefix_len = 0;
2250 +    }
2251 +    
2252 +  terminate_prefix = 1;
2253 +                 
2254    /* Check if this is a macro invocation that we need to expand.  */
2255    if (! scanning_macro_expansion ())
2256      {
2257 @@ -1868,10 +2069,19 @@ yylex (void)
2258             && parse_language->la_language != language_cplus)
2259           break;
2260  
2261 +       if (tokentab2[i].token == COLONCOLON)
2262 +         {
2263 +           name_prefix_len += 2;
2264 +           terminate_prefix = 0;
2265 +           if (name_prefix == NULL)
2266 +             name_prefix = lexptr;
2267 +         }
2268 +
2269         lexptr += 2;
2270         yylval.opcode = tokentab2[i].opcode;
2271         if (in_parse_field && tokentab2[i].token == ARROW)
2272           last_was_structop = 1;
2273 +       
2274         return tokentab2[i].token;
2275        }
2276  
2277 @@ -1900,6 +2110,8 @@ yylex (void)
2278          return 0;
2279  
2280      case ' ':
2281 +      name_prefix_len++;
2282 +      terminate_prefix = 0;
2283      case '\t':
2284      case '\n':
2285        lexptr++;
2286 @@ -2057,11 +2269,13 @@ yylex (void)
2287      error ("Invalid character '%c' in expression.", c);
2288  
2289    /* It's a name.  See how long it is.  */
2290 +  
2291    namelen = 0;
2292    for (c = tokstart[namelen];
2293         (c == '_' || c == '$' || (c >= '0' && c <= '9')
2294         || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
2295      {
2296 +    
2297        /* Template parameter lists are part of the name.
2298          FIXME: This mishandles `print $a<4&&$a>3'.  */
2299  
2300 @@ -2125,14 +2339,29 @@ yylex (void)
2301       currently as names of types; NAME for other symbols.
2302       The caller is not constrained to care about the distinction.  */
2303    {
2304 +    char *tmp = copy;
2305      struct symbol *sym;
2306      int is_a_field_of_this = 0;
2307      int hextype;
2308  
2309 -    sym = lookup_symbol (copy, expression_context_block,
2310 +    if (name_prefix != NULL)
2311 +      tmp = savestring (name_prefix, name_prefix_len+namelen);
2312 +
2313 +    sym = lookup_symbol (tmp, expression_context_block,
2314                          VAR_DOMAIN,
2315                          parse_language->la_language == language_cplus
2316                          ? &is_a_field_of_this : (int *) NULL);
2317 +                        
2318 +    /* Keep this name as the prefix for the next name. */
2319 +    if (sym)
2320 +      {
2321 +       if (name_prefix == NULL)
2322 +         name_prefix = tokstart;
2323 +
2324 +       name_prefix_len += namelen;
2325 +       terminate_prefix = 0;
2326 +      }
2327 +
2328      /* Call lookup_symtab, not lookup_partial_symtab, in case there are
2329         no psymtabs (coff, xcoff, or some future change to blow away the
2330         psymtabs once once symbols are read).  */
2331 @@ -2191,6 +2420,7 @@ yylex (void)
2332      yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2333      if (in_parse_field && *lexptr == '\0')
2334        saw_name_at_eof = 1;
2335 +        
2336      return NAME;
2337    }
2338  }
2339 diff --git a/gdb/c-lang.c b/gdb/c-lang.c
2340 index d01490c..bc35a3e 100644
2341 --- a/gdb/c-lang.c
2342 +++ b/gdb/c-lang.c
2343 @@ -715,7 +715,7 @@ c_get_string (struct value *value, gdb_byte **buffer, int *length,
2344       If length returned from read_string was > 0, return the number of
2345       characters read by dividing the number of bytes by width.  */
2346    if (*length != 0)
2347 -     *length = *length / width;
2348 +    *length = *length / width;
2349  
2350    *charset = target_charset ();
2351  
2352 @@ -1038,6 +1038,9 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
2353    return evaluate_subexp_standard (expect_type, exp, pos, noside);
2354  }
2355  
2356 +\f
2357 +/* Preprocessing and parsing C and C++ expressions.  */
2358 +
2359  
2360  \f
2361  /* Table mapping opcodes into strings for printing operators
2362 @@ -1138,6 +1141,7 @@ static const struct exp_descriptor exp_descriptor_c =
2363  {
2364    print_subexp_standard,
2365    operator_length_standard,
2366 +  operator_check_standard,
2367    op_name_standard,
2368    dump_subexp_body_standard,
2369    evaluate_subexp_c
2370 diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
2371 index b193080..04cf3bc 100644
2372 --- a/gdb/c-typeprint.c
2373 +++ b/gdb/c-typeprint.c
2374 @@ -32,6 +32,7 @@
2375  #include "c-lang.h"
2376  #include "typeprint.h"
2377  #include "cp-abi.h"
2378 +#include "jv-lang.h"
2379  
2380  #include "gdb_string.h"
2381  #include <errno.h>
2382 @@ -40,8 +41,6 @@ static void cp_type_print_method_args (struct type *mtype, char *prefix,
2383                                        char *varstring, int staticp,
2384                                        struct ui_file *stream);
2385  
2386 -static void c_type_print_args (struct type *, struct ui_file *);
2387 -
2388  static void cp_type_print_derivation_info (struct ui_file *, struct type *);
2389  
2390  static void c_type_print_varspec_prefix (struct type *, struct ui_file *, int,
2391 @@ -199,6 +198,23 @@ cp_type_print_method_args (struct type *mtype, char *prefix, char *varstring,
2392      fprintf_filtered (stream, "void");
2393  
2394    fprintf_filtered (stream, ")");
2395 +
2396 +  /* For non-static methods, read qualifiers from the type of
2397 +     THIS.  */
2398 +  if (!staticp)
2399 +    {
2400 +      struct type *domain;
2401 +
2402 +      gdb_assert (nargs > 0);
2403 +      gdb_assert (TYPE_CODE (args[0].type) == TYPE_CODE_PTR);
2404 +      domain = TYPE_TARGET_TYPE (args[0].type);
2405 +
2406 +      if (TYPE_CONST (domain))
2407 +       fprintf_filtered (stream, " const");
2408 +
2409 +      if (TYPE_VOLATILE (domain))
2410 +       fprintf_filtered (stream, " volatile");
2411 +    }
2412  }
2413  
2414  
2415 @@ -355,10 +371,14 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
2416  
2417  /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
2418     or TYPE_CODE_FUNC, to STREAM.  Artificial arguments, such as "this"
2419 -   in non-static methods, are displayed.  */
2420 +   in non-static methods, are displayed if SHOW_ARTIFICIAL is
2421 +   non-zero. LANGUAGE is the language in which TYPE was defined.  This is
2422 +   a necessary evil since this code is used by the C, C++, and Java
2423 +   backends. */
2424  
2425 -static void
2426 -c_type_print_args (struct type *type, struct ui_file *stream)
2427 +void
2428 +c_type_print_args (struct type *type, struct ui_file *stream,
2429 +                  int show_artificial, enum language language)
2430  {
2431    int i, len;
2432    struct field *args;
2433 @@ -370,13 +390,19 @@ c_type_print_args (struct type *type, struct ui_file *stream)
2434  
2435    for (i = 0; i < TYPE_NFIELDS (type); i++)
2436      {
2437 +      if (TYPE_FIELD_ARTIFICIAL (type, i) && !show_artificial)
2438 +       continue;
2439 +
2440        if (printed_any)
2441         {
2442           fprintf_filtered (stream, ", ");
2443           wrap_here ("    ");
2444         }
2445  
2446 -      c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
2447 +      if (language == language_java)
2448 +       java_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
2449 +      else
2450 +       c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
2451        printed_any = 1;
2452      }
2453  
2454 @@ -560,7 +586,12 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
2455         fprintf_filtered (stream, ")");
2456  
2457        fprintf_filtered (stream, "[");
2458 -      if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
2459 +      if (TYPE_ARRAY_BOUND_IS_DWARF_BLOCK (type, 1))
2460 +       {
2461 +         /* No _() - printed sources should not be locale dependent.  */
2462 +         fprintf_filtered (stream, "variable");
2463 +       }
2464 +      else if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
2465         && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
2466         fprintf_filtered (stream, "%d",
2467                           (TYPE_LENGTH (type)
2468 @@ -593,7 +624,7 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
2469        if (passed_a_ptr)
2470         fprintf_filtered (stream, ")");
2471        if (!demangled_args)
2472 -       c_type_print_args (type, stream);
2473 +       c_type_print_args (type, stream, 1, language_c);
2474        c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show,
2475                                    passed_a_ptr, 0);
2476        break;
2477 diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
2478 index ce7c2a6..6380fec 100644
2479 --- a/gdb/cli/cli-cmds.c
2480 +++ b/gdb/cli/cli-cmds.c
2481 @@ -46,6 +46,8 @@
2482  #include "cli/cli-setshow.h"
2483  #include "cli/cli-cmds.h"
2484  
2485 +#include "python/python.h"
2486 +
2487  #ifdef TUI
2488  #include "tui/tui.h"           /* For tui_active et.al.   */
2489  #endif
2490 @@ -183,6 +185,7 @@ struct cmd_list_element *showchecklist;
2491  
2492  /* Command tracing state.  */
2493  
2494 +static int source_python = 0;
2495  int source_verbose = 0;
2496  int trace_commands = 0;
2497  \f
2498 @@ -444,6 +447,7 @@ source_script (char *file, int from_tty)
2499    struct cleanup *old_cleanups;
2500    char *full_pathname = NULL;
2501    int fd;
2502 +  int is_python;
2503  
2504    if (file == NULL || *file == 0)
2505      {
2506 @@ -476,8 +480,16 @@ source_script (char *file, int from_tty)
2507         }
2508      }
2509  
2510 +  is_python = source_python;
2511 +  if (strlen (file) > 3 && !strcmp (&file[strlen (file) - 3], ".py"))
2512 +    is_python = 1;
2513 +
2514    stream = fdopen (fd, FOPEN_RT);
2515 -  script_from_file (stream, file);
2516 +
2517 +  if (is_python)
2518 +    source_python_script (stream, file);
2519 +  else
2520 +    script_from_file (stream, file);
2521  
2522    do_cleanups (old_cleanups);
2523  }
2524 @@ -491,15 +503,30 @@ source_verbose_cleanup (void *old_value)
2525    xfree (old_value);
2526  }
2527  
2528 +/* A helper for source_command.  Look for an argument in *ARGS.
2529 +   Update *ARGS by stripping leading whitespace.  If an argument is
2530 +   found, return it (a character).  Otherwise, return 0.  */
2531 +static int
2532 +find_argument (char **args)
2533 +{
2534 +  int result = 0;
2535 +  while (isspace ((*args)[0]))
2536 +    ++*args;
2537 +  if ((*args)[0] == '-' && isalpha ((*args)[1]))
2538 +    {
2539 +      result = (*args)[1];
2540 +      *args += 3;
2541 +    }
2542 +  return result;
2543 +}
2544 +
2545  static void
2546  source_command (char *args, int from_tty)
2547  {
2548    struct cleanup *old_cleanups;
2549 -  char *file = args;
2550 -  int *old_source_verbose = xmalloc (sizeof(int));
2551  
2552 -  *old_source_verbose = source_verbose;
2553 -  old_cleanups = make_cleanup (source_verbose_cleanup, old_source_verbose);
2554 +  old_cleanups = make_cleanup_restore_integer (&source_verbose);
2555 +  make_cleanup_restore_integer (&source_python);
2556  
2557    /* -v causes the source command to run in verbose mode.
2558       We still have to be able to handle filenames with spaces in a
2559 @@ -507,23 +534,28 @@ source_command (char *args, int from_tty)
2560  
2561    if (args)
2562      {
2563 -      /* Make sure leading white space does not break the comparisons.  */
2564 -      while (isspace(args[0]))
2565 -       args++;
2566 -
2567 -      /* Is -v the first thing in the string?  */
2568 -      if (args[0] == '-' && args[1] == 'v' && isspace (args[2]))
2569 +      while (1)
2570         {
2571 -         source_verbose = 1;
2572 -
2573 -         /* Trim -v and whitespace from the filename.  */
2574 -         file = &args[3];
2575 -         while (isspace (file[0]))
2576 -           file++;
2577 +         int arg = find_argument (&args);
2578 +         if (!arg)
2579 +           break;
2580 +         switch (arg)
2581 +           {
2582 +           case 'v':
2583 +             source_verbose = 1;
2584 +             break;
2585 +           case 'p':
2586 +             source_python = 1;
2587 +             break;
2588 +           default:
2589 +             error (_("unrecognized option -%c"), arg);
2590 +           }
2591         }
2592      }
2593  
2594 -  source_script (file, from_tty);
2595 +  source_script (args, from_tty);
2596 +
2597 +  do_cleanups (old_cleanups);
2598  }
2599  
2600  
2601 @@ -1307,7 +1339,9 @@ Read commands from a file named FILE.\n\
2602  Optional -v switch (before the filename) causes each command in\n\
2603  FILE to be echoed as it is executed.\n\
2604  Note that the file \"%s\" is read automatically in this way\n\
2605 -when GDB is started."), gdbinit);
2606 +when GDB is started.\n\
2607 +Optional -p switch (before the filename) causes FILE to be evaluated\n\
2608 +as Python code."), gdbinit);
2609    c = add_cmd ("source", class_support, source_command,
2610                source_help_text, &cmdlist);
2611    set_cmd_completer (c, filename_completer);
2612 diff --git a/gdb/coffread.c b/gdb/coffread.c
2613 index 888f8b4..65494b8 100644
2614 --- a/gdb/coffread.c
2615 +++ b/gdb/coffread.c
2616 @@ -346,7 +346,7 @@ coff_alloc_type (int index)
2617       We will fill it in later if we find out how.  */
2618    if (type == NULL)
2619      {
2620 -      type = alloc_type (current_objfile);
2621 +      type = alloc_type (current_objfile, NULL);
2622        *type_addr = type;
2623      }
2624    return type;
2625 @@ -2121,6 +2121,7 @@ static struct sym_fns coff_sym_fns =
2626    coff_new_init,               /* sym_new_init: init anything gbl to entire symtab */
2627    coff_symfile_init,           /* sym_init: read initial info, setup for sym_read() */
2628    coff_symfile_read,           /* sym_read: read a symbol file into symtab */
2629 +  NULL,                                /* sym_read_psymbols */
2630    coff_symfile_finish,         /* sym_finish: finished with file, cleanup */
2631    default_symfile_offsets,     /* sym_offsets:  xlate external to internal form */
2632    default_symfile_segments,    /* sym_segments: Get segment information from
2633 diff --git a/gdb/config.in b/gdb/config.in
2634 index 4716524..0745c65 100644
2635 --- a/gdb/config.in
2636 +++ b/gdb/config.in
2637 @@ -46,11 +46,10 @@
2638     language is requested. */
2639  #undef ENABLE_NLS
2640  
2641 -/* look for global separate data files in this path [DATADIR/gdb] */
2642 +/* Global directory for GDB data files. */
2643  #undef GDB_DATADIR
2644  
2645 -/* Define if the gdb-datadir directory should be relocated when GDB is moved.
2646 -   */
2647 +/* Define if GDB datadir should be relocated when GDB is moved. */
2648  #undef GDB_DATADIR_RELOCATABLE
2649  
2650  /* Define to be a string naming the default host character set. */
2651 @@ -647,6 +646,9 @@
2652     'ptrdiff_t'. */
2653  #undef PTRDIFF_T_SUFFIX
2654  
2655 +/* Define to install path for Python sources */
2656 +#undef PYTHONDIR
2657 +
2658  /* Relocated directory for source files. */
2659  #undef RELOC_SRCDIR
2660  
2661 diff --git a/gdb/config/i386/nm-i386.h b/gdb/config/i386/nm-i386.h
2662 new file mode 100644
2663 index 0000000..5f237cc
2664 --- /dev/null
2665 +++ b/gdb/config/i386/nm-i386.h
2666 @@ -0,0 +1,125 @@
2667 +/* Native macro definitions for GDB on an Intel i[3456]86.
2668 +   Copyright 2001, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
2669 +
2670 +   This file is part of GDB.
2671 +
2672 +   This program is free software; you can redistribute it and/or modify
2673 +   it under the terms of the GNU General Public License as published by
2674 +   the Free Software Foundation; either version 3 of the License, or
2675 +   (at your option) any later version.
2676 +
2677 +   This program is distributed in the hope that it will be useful,
2678 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
2679 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2680 +   GNU General Public License for more details.
2681 +
2682 +   You should have received a copy of the GNU General Public License
2683 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2684 +
2685 +#ifndef NM_I386_H
2686 +#define NM_I386_H 1
2687 +
2688 +/* Hardware-assisted breakpoints and watchpoints.  */
2689 +
2690 +/* Targets should define this to use the generic x86 watchpoint support.  */
2691 +#ifdef I386_USE_GENERIC_WATCHPOINTS
2692 +
2693 +/* Add watchpoint methods to the provided target_ops.  Targets which call
2694 +   this should also define I386_WATCHPOINTS_IN_TARGET_VECTOR.  */
2695 +struct target_ops;
2696 +void i386_use_watchpoints (struct target_ops *);
2697 +
2698 +/* Clear the reference counts and forget everything we knew about DRi.  */
2699 +extern void i386_cleanup_dregs (void);
2700 +
2701 +/* Insert a watchpoint to watch a memory region which starts at
2702 +   address ADDR and whose length is LEN bytes.  Watch memory accesses
2703 +   of the type TYPE.  Return 0 on success, -1 on failure.  */
2704 +extern int i386_insert_watchpoint (CORE_ADDR addr, int len, int type);
2705 +
2706 +/* Remove a watchpoint that watched the memory region which starts at
2707 +   address ADDR, whose length is LEN bytes, and for accesses of the
2708 +   type TYPE.  Return 0 on success, -1 on failure.  */
2709 +extern int i386_remove_watchpoint (CORE_ADDR addr, int len, int type);
2710 +
2711 +/* Return non-zero if we can watch a memory region that starts at
2712 +   address ADDR and whose length is LEN bytes.  */
2713 +extern int i386_region_ok_for_watchpoint (CORE_ADDR addr, int len);
2714 +
2715 +/* Return non-zero if the inferior has some break/watchpoint that
2716 +   triggered.  */
2717 +extern int i386_stopped_by_hwbp (void);
2718 +
2719 +/* If the inferior has some break/watchpoint that triggered, set
2720 +   the address associated with that break/watchpoint and return
2721 +   true.  Otherwise, return false.  */
2722 +extern int i386_stopped_data_address (struct target_ops *, CORE_ADDR *);
2723 +
2724 +/* Insert a hardware-assisted breakpoint at BP_TGT->placed_address.
2725 +   Return 0 on success, EBUSY on failure.  */
2726 +struct bp_target_info;
2727 +extern int i386_insert_hw_breakpoint (struct bp_target_info *bp_tgt);
2728 +
2729 +/* Remove a hardware-assisted breakpoint at BP_TGT->placed_address.
2730 +   Return 0 on success, -1 on failure.  */
2731 +extern int  i386_remove_hw_breakpoint (struct bp_target_info *bp_tgt);
2732 +
2733 +extern int i386_stopped_by_watchpoint (void);
2734 +
2735 +#ifndef I386_WATCHPOINTS_IN_TARGET_VECTOR
2736 +
2737 +/* Returns the number of hardware watchpoints of type TYPE that we can
2738 +   set.  Value is positive if we can set CNT watchpoints, zero if
2739 +   setting watchpoints of type TYPE is not supported, and negative if
2740 +   CNT is more than the maximum number of watchpoints of type TYPE
2741 +   that we can support.  TYPE is one of bp_hardware_watchpoint,
2742 +   bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
2743 +   CNT is the number of such watchpoints used so far (including this
2744 +   one).  OTHERTYPE is non-zero if other types of watchpoints are
2745 +   currently enabled.
2746 +
2747 +   We always return 1 here because we don't have enough information
2748 +   about possible overlap of addresses that they want to watch.  As an
2749 +   extreme example, consider the case where all the watchpoints watch
2750 +   the same address and the same region length: then we can handle a
2751 +   virtually unlimited number of watchpoints, due to debug register
2752 +   sharing implemented via reference counts in i386-nat.c.  */
2753 +
2754 +#define TARGET_CAN_USE_HARDWARE_WATCHPOINT(type, cnt, ot) 1
2755 +
2756 +/* Returns non-zero if we can use hardware watchpoints to watch a
2757 +   region whose address is ADDR and whose length is LEN.  */
2758 +
2759 +#define TARGET_REGION_OK_FOR_HW_WATCHPOINT(addr, len) \
2760 +  i386_region_ok_for_watchpoint (addr, len)
2761 +
2762 +/* After a watchpoint trap, the PC points to the instruction after the
2763 +   one that caused the trap.  Therefore we don't need to step over it.
2764 +   But we do need to reset the status register to avoid another trap.  */
2765 +
2766 +#define HAVE_CONTINUABLE_WATCHPOINT 1
2767 +
2768 +#define STOPPED_BY_WATCHPOINT(W)       (i386_stopped_by_watchpoint () != 0)
2769 +
2770 +#define target_stopped_data_address(target, x) \
2771 +  i386_stopped_data_address(target, x)
2772 +
2773 +/* Use these macros for watchpoint insertion/removal.  */
2774 +
2775 +#define target_insert_watchpoint(addr, len, type) \
2776 +  i386_insert_watchpoint (addr, len, type)
2777 +
2778 +#define target_remove_watchpoint(addr, len, type) \
2779 +  i386_remove_watchpoint (addr, len, type)
2780 +
2781 +#define target_insert_hw_breakpoint(bp_tgt) \
2782 +  i386_insert_hw_breakpoint (bp_tgt)
2783 +
2784 +#define target_remove_hw_breakpoint(bp_tgt) \
2785 +  i386_remove_hw_breakpoint (bp_tgt)
2786 +
2787 +#endif /* I386_WATCHPOINTS_IN_TARGET_VECTOR */
2788 +
2789 +#endif /* I386_USE_GENERIC_WATCHPOINTS */
2790 +
2791 +#endif /* NM_I386_H */
2792 diff --git a/gdb/config/i386/nm-linux64.h b/gdb/config/i386/nm-linux64.h
2793 new file mode 100644
2794 index 0000000..19d710a
2795 --- /dev/null
2796 +++ b/gdb/config/i386/nm-linux64.h
2797 @@ -0,0 +1,54 @@
2798 +/* Native support for GNU/Linux x86-64.
2799 +
2800 +   Copyright 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
2801 +   Free Software Foundation, Inc.
2802 +
2803 +   Contributed by Jiri Smid, SuSE Labs.
2804 +
2805 +   This file is part of GDB.
2806 +
2807 +   This program is free software; you can redistribute it and/or modify
2808 +   it under the terms of the GNU General Public License as published by
2809 +   the Free Software Foundation; either version 3 of the License, or
2810 +   (at your option) any later version.
2811 +
2812 +   This program is distributed in the hope that it will be useful,
2813 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
2814 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2815 +   GNU General Public License for more details.
2816 +
2817 +   You should have received a copy of the GNU General Public License
2818 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2819 +
2820 +#ifndef NM_LINUX64_H
2821 +#define NM_LINUX64_H
2822 +
2823 +/* GNU/Linux supports the i386 hardware debugging registers.  */
2824 +#define I386_USE_GENERIC_WATCHPOINTS
2825 +#define I386_WATCHPOINTS_IN_TARGET_VECTOR
2826 +
2827 +#include "i386/nm-i386.h"
2828 +#include "config/nm-linux.h"
2829 +
2830 +/* Support for 8-byte wide hardware watchpoints.  */
2831 +#define TARGET_HAS_DR_LEN_8 1
2832 +
2833 +/* Provide access to the i386 hardware debugging registers.  */
2834 +
2835 +extern void amd64_linux_dr_set_control (unsigned long control);
2836 +#define I386_DR_LOW_SET_CONTROL(control) \
2837 +  amd64_linux_dr_set_control (control)
2838 +
2839 +extern void amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr);
2840 +#define I386_DR_LOW_SET_ADDR(regnum, addr) \
2841 +  amd64_linux_dr_set_addr (regnum, addr)
2842 +
2843 +extern void amd64_linux_dr_reset_addr (int regnum);
2844 +#define I386_DR_LOW_RESET_ADDR(regnum) \
2845 +  amd64_linux_dr_reset_addr (regnum)
2846 +
2847 +extern unsigned long amd64_linux_dr_get_status (void);
2848 +#define I386_DR_LOW_GET_STATUS() \
2849 +  amd64_linux_dr_get_status ()
2850 +
2851 +#endif /* nm-linux64.h */
2852 diff --git a/gdb/config/mips/nm-irix5.h b/gdb/config/mips/nm-irix5.h
2853 new file mode 100644
2854 index 0000000..49ac420
2855 --- /dev/null
2856 +++ b/gdb/config/mips/nm-irix5.h
2857 @@ -0,0 +1,44 @@
2858 +/* Definitions for native support of irix5.
2859 +
2860 +   Copyright 1993, 1996, 1998, 1999, 2000, 2007, 2008, 2009
2861 +   Free Software Foundation, Inc.
2862 +
2863 +   This file is part of GDB.
2864 +
2865 +   This program is free software; you can redistribute it and/or modify
2866 +   it under the terms of the GNU General Public License as published by
2867 +   the Free Software Foundation; either version 3 of the License, or
2868 +   (at your option) any later version.
2869 +
2870 +   This program is distributed in the hope that it will be useful,
2871 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
2872 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2873 +   GNU General Public License for more details.
2874 +
2875 +   You should have received a copy of the GNU General Public License
2876 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2877 +
2878 +#define TARGET_HAS_HARDWARE_WATCHPOINTS
2879 +
2880 +/* TARGET_CAN_USE_HARDWARE_WATCHPOINT is now defined to go through
2881 +   the target vector.  For Irix5, procfs_can_use_hw_watchpoint()
2882 +   should be invoked.  */
2883 +
2884 +/* When a hardware watchpoint fires off the PC will be left at the
2885 +   instruction which caused the watchpoint.  It will be necessary for
2886 +   GDB to step over the watchpoint. */
2887 +
2888 +#define STOPPED_BY_WATCHPOINT(W) \
2889 +     procfs_stopped_by_watchpoint(inferior_ptid)
2890 +extern int procfs_stopped_by_watchpoint (ptid_t);
2891 +
2892 +/* Use these macros for watchpoint insertion/deletion.  */
2893 +/* type can be 0: write watch, 1: read watch, 2: access watch (read/write) */
2894 +#define target_insert_watchpoint(ADDR, LEN, TYPE) \
2895 +     procfs_set_watchpoint (inferior_ptid, ADDR, LEN, TYPE, 0)
2896 +#define target_remove_watchpoint(ADDR, LEN, TYPE) \
2897 +     procfs_set_watchpoint (inferior_ptid, ADDR, 0, 0, 0)
2898 +extern int procfs_set_watchpoint (ptid_t, CORE_ADDR, int, int, int);
2899 +
2900 +#define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(SIZE) 1
2901 +
2902 diff --git a/gdb/configure b/gdb/configure
2903 index 99acc2f..a2ea1ae 100755
2904 --- a/gdb/configure
2905 +++ b/gdb/configure
2906 @@ -676,6 +676,8 @@ REPORT_BUGS_TO
2907  PKGVERSION
2908  TARGET_OBS
2909  subdirs
2910 +pythondir
2911 +GDB_DATADIR_PATH
2912  GDB_DATADIR
2913  DEBUGDIR
2914  am__fastdepCC_FALSE
2915 @@ -883,6 +885,7 @@ enable_dependency_tracking
2916  with_separate_debug_dir
2917  with_gdb_datadir
2918  with_relocated_sources
2919 +with_pythondir
2920  enable_targets
2921  enable_64_bit_bfd
2922  enable_gdbcli
2923 @@ -1581,6 +1584,10 @@ Optional Packages:
2924                            [DATADIR/gdb]
2925    --with-relocated-sources=PATH
2926                            automatically relocate this path for source files
2927 +  --with-gdb-datadir      look for global separate data files in this path
2928 +                          [DATADIR/gdb]
2929 +  --with-pythondir        install Python data files in this path
2930 +                          [DATADIR/gdb/python]
2931    --with-libunwind        use libunwind frame unwinding support
2932    --with-curses           use the curses library instead of the termcap
2933                            library
2934 @@ -6602,6 +6609,73 @@ _ACEOF
2935  fi
2936  
2937  
2938 +# GDB's datadir relocation
2939 +
2940 +gdbdatadir=${datadir}/gdb
2941 +
2942 +
2943 +# Check whether --with-gdb-datadir was given.
2944 +if test "${with_gdb_datadir+set}" = set; then :
2945 +  withval=$with_gdb_datadir; gdbdatadir="${withval}"
2946 +fi
2947 +
2948 +
2949 +
2950 +  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
2951 +  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
2952 +  ac_define_dir=`eval echo $gdbdatadir`
2953 +  ac_define_dir=`eval echo $ac_define_dir`
2954 +
2955 +cat >>confdefs.h <<_ACEOF
2956 +#define GDB_DATADIR "$ac_define_dir"
2957 +_ACEOF
2958 +
2959 +
2960 +
2961 +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
2962 +  if test "x$prefix" = xNONE; then
2963 +    test_prefix=/usr/local
2964 +  else
2965 +    test_prefix=$prefix
2966 +  fi
2967 +else
2968 +  test_prefix=$exec_prefix
2969 +fi
2970 +
2971 +case ${gdbdatadir} in
2972 +  "${test_prefix}"|"${test_prefix}/"*|\
2973 +  '${exec_prefix}'|'${exec_prefix}/'*)
2974 +
2975 +$as_echo "#define GDB_DATADIR_RELOCATABLE 1" >>confdefs.h
2976 +
2977 +  ;;
2978 +esac
2979 +GDB_DATADIR_PATH=${gdbdatadir}
2980 +
2981 +
2982 +
2983 +# Check whether --with-pythondir was given.
2984 +if test "${with_pythondir+set}" = set; then :
2985 +  withval=$with_pythondir; pythondir="${withval}"
2986 +else
2987 +  pythondir=no
2988 +fi
2989 +
2990 +
2991 +# If the user passed in a path, define it.  Otherwise, compute it at
2992 +# runtime based on the possibly-relocatable datadir.
2993 +if test "$pythondir" = "no"; then
2994 +  pythondir='$(GDB_DATADIR_PATH)/python'
2995 +else
2996 +
2997 +cat >>confdefs.h <<_ACEOF
2998 +#define PYTHONDIR "$pythondir"
2999 +_ACEOF
3000 +
3001 +fi
3002 +
3003 +
3004 +
3005  
3006  
3007  subdirs="$subdirs doc testsuite"
3008 @@ -9282,6 +9356,8 @@ $as_echo "#define HAVE_PYTHON 1" >>confdefs.h
3009    CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_PYTHON_OBS)"
3010    CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
3011    CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
3012 +  CONFIG_INSTALL="$CONFIG_INSTALL install-python"
3013 +  CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
3014    ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
3015  
3016    # Flags needed to compile Python code (taken from python-config --cflags).
3017 diff --git a/gdb/configure.ac b/gdb/configure.ac
3018 index b31d9b7..a1969bc 100644
3019 --- a/gdb/configure.ac
3020 +++ b/gdb/configure.ac
3021 @@ -107,6 +107,51 @@ AS_HELP_STRING([--with-relocated-sources=PATH], [automatically relocate this pat
3022                [Relocated directory for source files. ])
3023  ])
3024  
3025 +# GDB's datadir relocation
3026 +
3027 +gdbdatadir=${datadir}/gdb
3028 +
3029 +AC_ARG_WITH([gdb-datadir],
3030 +  [AS_HELP_STRING([--with-gdb-datadir],
3031 +                  [look for global separate data files in this path [DATADIR/gdb]])], [gdbdatadir="${withval}"])
3032 +
3033 +AC_DEFINE_DIR(GDB_DATADIR, gdbdatadir,
3034 +              [Global directory for GDB data files. ])
3035 +
3036 +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
3037 +  if test "x$prefix" = xNONE; then
3038 +    test_prefix=/usr/local
3039 +  else
3040 +    test_prefix=$prefix
3041 +  fi
3042 +else
3043 +  test_prefix=$exec_prefix
3044 +fi
3045 +
3046 +case ${gdbdatadir} in
3047 +  "${test_prefix}"|"${test_prefix}/"*|\
3048 +  '${exec_prefix}'|'${exec_prefix}/'*)
3049 +    AC_DEFINE(GDB_DATADIR_RELOCATABLE, 1, [Define if GDB datadir should be relocated when GDB is moved.])
3050 +  ;;
3051 +esac
3052 +GDB_DATADIR_PATH=${gdbdatadir}
3053 +AC_SUBST(GDB_DATADIR_PATH)
3054 +
3055 +AC_ARG_WITH([pythondir],
3056 +  [AS_HELP_STRING([--with-pythondir],
3057 +                  [install Python data files in this path [DATADIR/gdb/python]])], [pythondir="${withval}"], [pythondir=no])
3058 +
3059 +# If the user passed in a path, define it.  Otherwise, compute it at
3060 +# runtime based on the possibly-relocatable datadir.
3061 +if test "$pythondir" = "no"; then
3062 +  pythondir='$(GDB_DATADIR_PATH)/python'
3063 +else
3064 +  AC_DEFINE_UNQUOTED(PYTHONDIR, "$pythondir",
3065 +      [Define to install path for Python sources])
3066 +fi
3067 +AC_SUBST(pythondir)
3068 +
3069 +
3070  AC_CONFIG_SUBDIRS(doc testsuite)
3071  
3072  # Check whether to support alternative target configurations
3073 @@ -658,6 +703,8 @@ if test "${have_libpython}" = yes; then
3074    CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_PYTHON_OBS)"
3075    CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
3076    CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
3077 +  CONFIG_INSTALL="$CONFIG_INSTALL install-python"
3078 +  CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
3079    ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
3080  
3081    # Flags needed to compile Python code (taken from python-config --cflags).
3082 diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
3083 index 62800b8..97d587b 100644
3084 --- a/gdb/cp-name-parser.y
3085 +++ b/gdb/cp-name-parser.y
3086 @@ -1,7 +1,6 @@
3087  /* YACC parser for C++ names, for GDB.
3088  
3089 -   Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009
3090 -   Free Software Foundation, Inc.
3091 +   Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
3092  
3093     Parts of the lexer are based on c-exp.y from GDB.
3094  
3095 @@ -389,7 +388,7 @@ function
3096                 |       colon_ext_only function_arglist start_opt
3097                         { $$ = fill_comp (DEMANGLE_COMPONENT_TYPED_NAME, $1, $2.comp);
3098                           if ($3) $$ = fill_comp (DEMANGLE_COMPONENT_LOCAL_NAME, $$, $3); }
3099 -
3100 +               |       colon_ext_only
3101                 |       conversion_op_name start_opt
3102                         { $$ = $1.comp;
3103                           if ($2) $$ = fill_comp (DEMANGLE_COMPONENT_LOCAL_NAME, $$, $2); }
3104 diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
3105 index d2d8f2e..af0ba28 100644
3106 --- a/gdb/cp-namespace.c
3107 +++ b/gdb/cp-namespace.c
3108 @@ -36,14 +36,17 @@ static struct using_direct *cp_copy_usings (struct using_direct *using,
3109                                             struct obstack *obstack);
3110  
3111  static struct symbol *lookup_namespace_scope (const char *name,
3112 -                                             const char *linkage_name,
3113                                               const struct block *block,
3114                                               const domain_enum domain,
3115                                               const char *scope,
3116                                               int scope_len);
3117  
3118 +static struct symbol *cp_lookup_symbol_in_namespace (const char *namespace,
3119 +                                                     const char *name,
3120 +                                                     const struct block *block,
3121 +                                                     const domain_enum domain);
3122 +
3123  static struct symbol *lookup_symbol_file (const char *name,
3124 -                                         const char *linkage_name,
3125                                           const struct block *block,
3126                                           const domain_enum domain,
3127                                           int anonymous_namespace);
3128 @@ -119,7 +122,7 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
3129                  anonymous namespace.  So add symbols in it to the
3130                  namespace given by the previous component if there is
3131                  one, or to the global namespace if there isn't.  */
3132 -             cp_add_using_directive (dest, src);
3133 +             cp_add_using_directive (dest, src, "", "", 0);
3134             }
3135           /* The "+ 2" is for the "::".  */
3136           previous_component = next_component + 2;
3137 @@ -134,7 +137,8 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
3138     has already been added, don't add it twice.  */
3139  
3140  void
3141 -cp_add_using_directive (const char *dest, const char *src)
3142 +cp_add_using_directive (const char *dest, const char *src, const char* alias,
3143 +                       const char *declaration, const int line_number)
3144  {
3145    struct using_direct *current;
3146    struct using_direct *new;
3147 @@ -148,7 +152,8 @@ cp_add_using_directive (const char *dest, const char *src)
3148         return;
3149      }
3150  
3151 -  using_directives = cp_add_using (dest, src, using_directives);
3152 +  using_directives = cp_add_using (dest, src, alias, declaration,
3153 +                                  line_number, using_directives);
3154  
3155  }
3156  
3157 @@ -201,7 +206,10 @@ cp_is_anonymous (const char *namespace)
3158  }
3159  
3160  /* Create a new struct using direct which imports the namespace SRC
3161 -   into the scope DEST.
3162 +   into the scope DEST.  ALIAS is the name of the imported namespace
3163 +   in the current scope.  If ALIAS is an empty string  then the
3164 +   namespace is known by its original name.
3165 +
3166     Set its next member in the linked list to NEXT; allocate all memory
3167     using xmalloc.  It copies the strings, so NAME can be a temporary
3168     string.  */
3169 @@ -209,14 +217,21 @@ cp_is_anonymous (const char *namespace)
3170  struct using_direct *
3171  cp_add_using (const char *dest,
3172                const char *src,
3173 +              const char *alias,
3174 +              const char *declaration,
3175 +              const int line_number,
3176               struct using_direct *next)
3177  {
3178    struct using_direct *retval;
3179  
3180    retval = xmalloc (sizeof (struct using_direct));
3181 -  retval->import_src = savestring (src, strlen(src));
3182 -  retval->import_dest = savestring (dest, strlen(dest));
3183 +  retval->import_src = savestring (src, strlen (src));
3184 +  retval->import_dest = savestring (dest, strlen (dest));
3185 +  retval->alias = savestring (alias, strlen (alias));
3186 +  retval->declaration = savestring (declaration, strlen (declaration));
3187 +  retval->line_number = line_number;
3188    retval->next = next;
3189 +  retval->searched = 0;
3190  
3191    return retval;
3192  }
3193 @@ -241,10 +256,18 @@ cp_copy_usings (struct using_direct *using,
3194                                     obstack);
3195        retval->import_dest = obsavestring (using->import_dest, strlen (using->import_dest),
3196                                     obstack);
3197 +      retval->alias = obsavestring (using->alias, strlen (using->alias),
3198 +                                    obstack);
3199 +      retval->declaration = obsavestring (using->declaration, strlen (using->declaration),
3200 +                                    obstack);
3201        retval->next = cp_copy_usings (using->next, obstack);
3202  
3203 +      retval->searched = using->searched;
3204 +
3205        xfree (using->import_src);
3206        xfree (using->import_dest);
3207 +      xfree (using->alias);
3208 +      xfree (using->declaration);
3209        xfree (using);
3210  
3211        return retval;
3212 @@ -261,12 +284,48 @@ cp_copy_usings (struct using_direct *using,
3213  
3214  struct symbol *
3215  cp_lookup_symbol_nonlocal (const char *name,
3216 -                          const char *linkage_name,
3217                            const struct block *block,
3218                            const domain_enum domain)
3219  {
3220 -  return lookup_namespace_scope (name, linkage_name, block, domain,
3221 -                                block_scope (block), 0);
3222 +  struct symbol *sym; 
3223 +  const char *scope = block_scope (block);
3224 +
3225 +  sym = lookup_namespace_scope (name, block, domain, scope, 0);
3226 +  if (sym != NULL)
3227 +    return sym;
3228 +
3229 +  return cp_lookup_symbol_namespace(scope, name, block, domain);
3230 +}
3231 +
3232 +/* Searches for NAME in the current namespace, and by applying relevant import
3233 +   statements belonging to BLOCK and its parents.  SCOPE is the namespace
3234 +   scope of the context in which the search is being evaluated.  */
3235 +
3236 +struct symbol*
3237 +cp_lookup_symbol_namespace (const char *scope,
3238 +                            const char *name,
3239 +                            const struct block *block,
3240 +                            const domain_enum domain)
3241 +{
3242 +  struct symbol *sym;
3243 +
3244 +  /* First, try to find the symbol in the given namespace.  */
3245 +  sym = cp_lookup_symbol_in_namespace (scope, name, block, domain);
3246 +  if ( sym != NULL)
3247 +    return sym;
3248 +    
3249 +  /* Search for name in namespaces imported to this and parent blocks.  */
3250 +  while (block != NULL)
3251 +    {
3252 +      sym = cp_lookup_symbol_imports(scope,name, block, domain,0,1);
3253 +
3254 +      if (sym)
3255 +        return sym;
3256 +
3257 +      block = BLOCK_SUPERBLOCK(block);
3258 +    }
3259 +
3260 +  return NULL;
3261  }
3262  
3263  /* Lookup NAME at namespace scope (or, in C terms, in static and
3264 @@ -284,9 +343,8 @@ cp_lookup_symbol_nonlocal (const char *name,
3265     "A::x", and if that call fails, then the first call looks for
3266     "x".  */
3267  
3268 -static struct symbol *
3269 +struct symbol *
3270  lookup_namespace_scope (const char *name,
3271 -                       const char *linkage_name,
3272                         const struct block *block,
3273                         const domain_enum domain,
3274                         const char *scope,
3275 @@ -308,8 +366,7 @@ lookup_namespace_scope (const char *name,
3276           new_scope_len += 2;
3277         }
3278        new_scope_len += cp_find_first_component (scope + new_scope_len);
3279 -      sym = lookup_namespace_scope (name, linkage_name, block,
3280 -                                   domain, scope, new_scope_len);
3281 +      sym = lookup_namespace_scope (name, block, domain, scope, new_scope_len);
3282        if (sym != NULL)
3283         return sym;
3284      }
3285 @@ -320,25 +377,87 @@ lookup_namespace_scope (const char *name,
3286    namespace = alloca (scope_len + 1);
3287    strncpy (namespace, scope, scope_len);
3288    namespace[scope_len] = '\0';
3289 -  return cp_lookup_symbol_namespace (namespace, name, linkage_name,
3290 -                                    block, domain);
3291 +  return cp_lookup_symbol_in_namespace (namespace, name,block, domain);
3292  }
3293  
3294 -/* Look up NAME in the C++ namespace NAMESPACE, applying the using
3295 -   directives that are active in BLOCK.  Other arguments are as in
3296 +/* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in
3297     cp_lookup_symbol_nonlocal.  */
3298  
3299 +static struct symbol *
3300 +cp_lookup_symbol_in_namespace (const char *namespace,
3301 +                              const char *name,
3302 +                              const struct block *block,
3303 +                              const domain_enum domain)
3304 +{
3305 +
3306 +  if (namespace[0] == '\0')
3307 +    {
3308 +      return lookup_symbol_file (name, block,domain, 0);
3309 +    }
3310 +  else
3311 +    {
3312 +      char *concatenated_name
3313 +       = alloca (strlen (namespace) + 2 + strlen (name) + 1);
3314 +      strcpy (concatenated_name, namespace);
3315 +      strcat (concatenated_name, "::");
3316 +      strcat (concatenated_name, name);
3317 +      return lookup_symbol_file (concatenated_name, block, domain,
3318 +                               cp_is_anonymous (namespace));
3319 +    }
3320 +}
3321 +
3322 +/* Search for NAME by applying all import statements belonging
3323 +   to BLOCK which are applicable in SCOPE. If DECLARATION_ONLY the search
3324 +   is restricted to using declarations.
3325 +   Example:
3326 +
3327 +     namespace A{
3328 +       int x;
3329 +     }
3330 +     using A::x;
3331 +
3332 +   If SEARCH_PARENTS the search will include imports which are applicable in
3333 +   parents of scopes.
3334 +   Example:
3335 +
3336 +     namespace A{
3337 +       using namespace X;
3338 +       namespace B{
3339 +         using namespace Y;
3340 +       }
3341 +     }
3342 +
3343 +   If SCOPE is "A::B" and SEARCH_PARENTS is true the imports of namespaces X
3344 +   and Y will be considered. If SEARCH_PARENTS is false only the import of Y
3345 +   is considered.  */
3346 +
3347  struct symbol *
3348 -cp_lookup_symbol_namespace (const char *namespace,
3349 -                           const char *name,
3350 -                           const char *linkage_name,
3351 -                           const struct block *block,
3352 -                           const domain_enum domain)
3353 +cp_lookup_symbol_imports (const char *scope,
3354 +                            const char *name,
3355 +                            const struct block *block,
3356 +                            const domain_enum domain,
3357 +                            int declaration_only,
3358 +                            int search_parents)
3359  {
3360 -  const struct using_direct *current;
3361 -  struct symbol *sym;
3362 +  struct using_direct *current;
3363 +  struct symbol *sym = NULL;
3364 +  int directive_match;
3365 +  int current_line;
3366 +
3367 +  if(!declaration_only)
3368 +    /* First, try to find the symbol in the given namespace.  */
3369 +    sym = cp_lookup_symbol_in_namespace (scope, name, block, domain);
3370  
3371 -  /* First, go through the using directives.  If any of them add new
3372 +  if ( sym != NULL)
3373 +    return sym;
3374 +
3375 +  if (has_stack_frames ())
3376 +    current_line = find_pc_line (get_frame_pc (get_selected_frame (NULL)),
3377 +                                              0).line;
3378 +  else
3379 +    current_line = 0;
3380 +
3381 +  /* Go through the using directives.  If any of them add new
3382       names to the namespace we're searching in, see if we can find a
3383       match by applying them.  */
3384  
3385 @@ -346,39 +465,74 @@ cp_lookup_symbol_namespace (const char *namespace,
3386         current != NULL;
3387         current = current->next)
3388      {
3389 -      if (strcmp (namespace, current->import_dest) == 0)
3390 +  
3391 +      /* If the import destination is the current scope or one of its ancestors then
3392 +         it is applicable.  */
3393 +      directive_match = search_parents ?
3394 +                        strncmp (scope, current->import_dest,
3395 +                                 strlen(current->import_dest)) == 0 :
3396 +                        strcmp (scope, current->import_dest) == 0;
3397 +
3398 +      if (directive_match &&
3399 +          current->line_number < current_line &&
3400 +          !current->searched)
3401         {
3402 -         sym = cp_lookup_symbol_namespace (current->import_src,
3403 -                                           name,
3404 -                                           linkage_name,
3405 -                                           block,
3406 -                                           domain);
3407 +         current->searched = 1;
3408 +         /* If there is an import of a single declaration, compare the imported
3409 +            declaration with the sought out name. If there is a match pass
3410 +            current->import_src as NAMESPACE to direct the search towards the
3411 +            imported namespace.  */
3412 +         if (strcmp ("", current->declaration) != 0)
3413 +           {
3414 +           if (strcmp (name, current->declaration) == 0)
3415 +             {
3416 +               sym = cp_lookup_symbol_in_namespace (current->import_src,
3417 +                                                 name,
3418 +                                                 block,
3419 +                                                 domain);
3420 +             }
3421 +           }
3422 +          
3423 +         if (declaration_only)
3424 +            {
3425 +              current->searched = 0;
3426 +              if (sym)
3427 +                {
3428 +                  return sym;
3429 +                } else {
3430 +                  continue;
3431 +                }
3432 +            }
3433 +
3434 +         if (strcmp (name, current->alias) == 0)
3435 +           /* If the import is creating an alias and the alias matches the
3436 +              sought name. Pass current->inner as the NAME to direct the
3437 +              search towards the aliased namespace */
3438 +           {
3439 +           sym = cp_lookup_symbol_in_namespace (scope,
3440 +                                             current->import_src,
3441 +                                             block,
3442 +                                             domain);
3443 +           } else if (strcmp ("", current->alias) == 0){
3444 +           /* If this import statement creates no alias, pass current->inner as
3445 +              NAMESPACE to direct the search towards the imported namespace. */
3446 +             sym = cp_lookup_symbol_imports (current->import_src,
3447 +                                               name,
3448 +                                               block,
3449 +                                               domain,
3450 +                                               0,
3451 +                                               0);
3452 +           }
3453 +
3454 +         current->searched = 0;
3455           if (sym != NULL)
3456 -           return sym;
3457 +           {
3458 +             return sym;
3459 +           }
3460         }
3461      }
3462  
3463 -  /* We didn't find anything by applying any of the using directives
3464 -     that are still applicable; so let's see if we've got a match
3465 -     using the current namespace.  */
3466 -  
3467 -  if (namespace[0] == '\0')
3468 -    {
3469 -      return lookup_symbol_file (name, linkage_name, block,
3470 -                                domain, 0);
3471 -    }
3472 -  else
3473 -    {
3474 -      char *concatenated_name
3475 -       = alloca (strlen (namespace) + 2 + strlen (name) + 1);
3476 -      strcpy (concatenated_name, namespace);
3477 -      strcat (concatenated_name, "::");
3478 -      strcat (concatenated_name, name);
3479 -      sym = lookup_symbol_file (concatenated_name, linkage_name,
3480 -                               block, domain, 
3481 -                               cp_is_anonymous (namespace));
3482 -      return sym;
3483 -    }
3484 +  return NULL;
3485  }
3486  
3487  /* Look up NAME in BLOCK's static block and in global blocks.  If
3488 @@ -388,17 +542,15 @@ cp_lookup_symbol_namespace (const char *namespace,
3489  
3490  static struct symbol *
3491  lookup_symbol_file (const char *name,
3492 -                   const char *linkage_name,
3493                     const struct block *block,
3494                     const domain_enum domain,
3495                     int anonymous_namespace)
3496  {
3497    struct symbol *sym = NULL;
3498  
3499 -  sym = lookup_symbol_static (name, linkage_name, block, domain);
3500 +  sym = lookup_symbol_static (name, block, domain);
3501    if (sym != NULL)
3502      return sym;
3503 -
3504    if (anonymous_namespace)
3505      {
3506        /* Symbols defined in anonymous namespaces have external linkage
3507 @@ -408,12 +560,11 @@ lookup_symbol_file (const char *name,
3508        const struct block *global_block = block_global_block (block);
3509        
3510        if (global_block != NULL)
3511 -       sym = lookup_symbol_aux_block (name, linkage_name, global_block,
3512 -                                      domain);
3513 +       sym = lookup_symbol_aux_block (name, global_block, domain);
3514      }
3515    else
3516      {
3517 -      sym = lookup_symbol_global (name, linkage_name, block, domain);
3518 +      sym = lookup_symbol_global (name, block, domain);
3519      }
3520  
3521    if (sym != NULL)
3522 @@ -434,6 +585,7 @@ lookup_symbol_file (const char *name,
3523        sym = lookup_possible_namespace_symbol (name);
3524        if (sym != NULL)
3525         return sym;
3526 +
3527      }
3528  
3529    return NULL;
3530 @@ -461,9 +613,8 @@ cp_lookup_nested_type (struct type *parent_type,
3531            lookup_symbol_namespace works when looking them up.  */
3532  
3533         const char *parent_name = TYPE_TAG_NAME (parent_type);
3534 -       struct symbol *sym = cp_lookup_symbol_namespace (parent_name,
3535 +       struct symbol *sym = cp_lookup_symbol_in_namespace (parent_name,
3536                                                          nested_name,
3537 -                                                        NULL,
3538                                                          block,
3539                                                          VAR_DOMAIN);
3540         if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
3541 @@ -709,7 +860,7 @@ check_one_possible_namespace_symbol (const char *name, int len,
3542  
3543    memcpy (name_copy, name, len);
3544    name_copy[len] = '\0';
3545 -  sym = lookup_block_symbol (block, name_copy, NULL, VAR_DOMAIN);
3546 +  sym = lookup_block_symbol (block, name_copy, VAR_DOMAIN);
3547  
3548    if (sym == NULL)
3549      {
3550 @@ -749,7 +900,7 @@ lookup_possible_namespace_symbol (const char *name)
3551        struct symbol *sym;
3552  
3553        sym = lookup_block_symbol (get_possible_namespace_block (objfile),
3554 -                                name, NULL, VAR_DOMAIN);
3555 +                                name, VAR_DOMAIN);
3556  
3557        if (sym != NULL)
3558         return sym;
3559 diff --git a/gdb/cp-support.c b/gdb/cp-support.c
3560 index f12d785..23b34c1 100644
3561 --- a/gdb/cp-support.c
3562 +++ b/gdb/cp-support.c
3563 @@ -32,6 +32,9 @@
3564  #include "block.h"
3565  #include "complaints.h"
3566  #include "gdbtypes.h"
3567 +#include "exceptions.h"
3568 +#include "expression.h"
3569 +#include "value.h"
3570  
3571  #include "safe-ctype.h"
3572  
3573 @@ -70,6 +73,18 @@ struct cmd_list_element *maint_cplus_cmd_list = NULL;
3574  static void maint_cplus_command (char *arg, int from_tty);
3575  static void first_component_command (char *arg, int from_tty);
3576  
3577 +/* Operator validation.
3578 +   NOTE: Multi-byte operators (usually the assignment variety operator)
3579 +   must appear before the single byte version, i.e., "+=" before "+".  */
3580 +static const char *operator_tokens[] =
3581 +  {
3582 +    "++", "+=", "+", "->*", "->", "--", "-=", "-", "*=", "*", "/=", "/",
3583 +    "%=", "%", "!=", "==", "!", "&&", "<<=", "<<", ">>=", ">>",
3584 +    "<=", "<", ">=", ">", "~", "&=", "&", "|=", "||", "|", "^=", "^",
3585 +    "=", "()", "[]", ",", "new", "delete"
3586 +    /* new[] and delete[] require special whitespace handling */
3587 +  };
3588 +
3589  /* Return 1 if STRING is clearly already in canonical form.  This
3590     function is conservative; things which it does not recognize are
3591     assumed to be non-canonical, and the parser will sort them out
3592 @@ -175,7 +190,8 @@ mangled_name_to_comp (const char *mangled_name, int options,
3593    return ret;
3594  }
3595  
3596 -/* Return the name of the class containing method PHYSNAME.  */
3597 +/* Return the name of the class or namespace containing
3598 +   function, method, or variable PHYSNAME.  */
3599  
3600  char *
3601  cp_class_name_from_physname (const char *physname)
3602 @@ -825,9 +841,9 @@ read_in_psymtabs (const char *func_name)
3603      if (ps->readin)
3604        continue;
3605  
3606 -    if ((lookup_partial_symbol (ps, func_name, NULL, 1, VAR_DOMAIN)
3607 +    if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
3608          != NULL)
3609 -       || (lookup_partial_symbol (ps, func_name, NULL, 0, VAR_DOMAIN)
3610 +       || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
3611             != NULL))
3612        psymtab_to_symtab (ps);
3613    }
3614 @@ -909,6 +925,107 @@ first_component_command (char *arg, int from_tty)
3615  
3616  extern initialize_file_ftype _initialize_cp_support; /* -Wmissing-prototypes */
3617  
3618 +#define SKIP_SPACE(P)                          \
3619 +  do                                           \
3620 +  {                                            \
3621 +    while (*(P) == ' ' || *(P) == '\t')                \
3622 +      ++(P);                                   \
3623 +  }                                            \
3624 +  while (0)
3625 +
3626 +/* Returns the length of the operator name or 0 if INPUT does not
3627 +   point to a valid C++ operator.  INPUT should start with "operator".  */
3628 +int
3629 +cp_validate_operator (const char *input)
3630 +{
3631 +  int i;
3632 +  char *copy;
3633 +  const char *p;
3634 +  struct expression *expr;
3635 +  struct value *val;
3636 +  struct gdb_exception except;
3637 +  struct cleanup *old_chain;
3638 +
3639 +  p = input;
3640 +
3641 +  if (strncmp (p, "operator", 8) == 0)
3642 +    {
3643 +      int valid = 0;
3644 +      p += 8;
3645 +
3646 +      SKIP_SPACE (p);
3647 +      for (i = 0; i < sizeof (operator_tokens) / sizeof (operator_tokens[0]);
3648 +          ++i)
3649 +       {
3650 +         int length = strlen (operator_tokens[i]);
3651 +         /* By using strncmp here, we MUST have operator_tokens ordered!
3652 +            See additional notes where operator_tokens is defined above.  */
3653 +         if (strncmp (p, operator_tokens[i], length) == 0)
3654 +           {
3655 +             const char *op = p;
3656 +             valid = 1;
3657 +             p += length;
3658 +
3659 +             if (strncmp (op, "new", 3) == 0
3660 +                 || strncmp (op, "delete", 6) == 0)
3661 +               {
3662 +
3663 +                 /* Special case: new[] and delete[].  We must be careful
3664 +                    to swallow whitespace before/in "[]".  */
3665 +                 SKIP_SPACE (p);
3666 +
3667 +                 if (*p == '[')
3668 +                   {
3669 +                     ++p;
3670 +                     SKIP_SPACE (p);
3671 +                     if (*p == ']')
3672 +                       ++p;
3673 +                     else
3674 +                       valid = 0;
3675 +                   }
3676 +               }
3677 +
3678 +             if (valid)
3679 +               return (p - input);
3680 +           }
3681 +       }
3682 +
3683 +      /* Check input for a conversion operator.  */
3684 +
3685 +      /* Skip past base typename */
3686 +      while (*p != '*' && *p != '&' && *p != 0 && *p != ' ')
3687 +       ++p;
3688 +      SKIP_SPACE (p);
3689 +
3690 +      /* Add modifiers '*'/'&' */
3691 +      while (*p == '*' || *p == '&')
3692 +       {
3693 +         ++p;
3694 +         SKIP_SPACE (p);
3695 +       }
3696 +
3697 +      /* Check for valid type.  [Remember: input starts with 
3698 +        "operator".]  */
3699 +      copy = savestring (input + 8, p - input - 8);
3700 +      expr = NULL;
3701 +      val = NULL;
3702 +      TRY_CATCH (except, RETURN_MASK_ALL)
3703 +       {
3704 +         expr = parse_expression (copy);
3705 +         val = evaluate_type (expr);
3706 +       }
3707 +
3708 +      xfree (copy);
3709 +      if (expr)
3710 +       xfree (expr);
3711 +
3712 +      if (val != NULL && value_type (val) != NULL)
3713 +       return (p - input);
3714 +    }
3715 +
3716 +  return 0;
3717 +}
3718 +
3719  void
3720  _initialize_cp_support (void)
3721  {
3722 diff --git a/gdb/cp-support.h b/gdb/cp-support.h
3723 index b5a5c5f..3f48f98 100644
3724 --- a/gdb/cp-support.h
3725 +++ b/gdb/cp-support.h
3726 @@ -38,15 +38,33 @@ struct demangle_component;
3727  
3728  /* This struct is designed to store data from using directives.  It
3729     says that names from namespace IMPORT_SRC should be visible within
3730 -   namespace IMPORT_DEST. IMPORT_DEST should always be a strict initial
3731 -   substring of IMPORT_SRC. These form a linked list; NEXT is the next element
3732 -   of the list.  */
3733 +   namespace IMPORT_DEST.  IMPORT_DEST should always be a strict initial
3734 +   substring of IMPORT_SRC.  These form a linked list; NEXT is the next
3735 +   element of the list.  ALIAS is set to a non empty string if the imported
3736 +   namespace has been aliased.Eg:
3737 +       namespace C=A::B;
3738 +   ALIAS = "C"
3739 +   DECLARATION is the name of the imported declaration, if this import 
3740 +   statement represents one. Eg:
3741 +       using A::x;
3742 +   Where x is variable in namespace A. declaration is set to x.  
3743 +*/
3744  
3745  struct using_direct
3746  {
3747    char *import_src;
3748    char *import_dest;
3749 +
3750 +  char *alias;
3751 +
3752 +  char *declaration;
3753 +
3754 +  int line_number;
3755 +
3756    struct using_direct *next;
3757 +
3758 +  /* Used during import search to temporarly mark this node as searced.  */
3759 +  int searched;
3760  };
3761  
3762  
3763 @@ -54,6 +72,7 @@ struct using_direct
3764  
3765  extern char *cp_canonicalize_string (const char *string);
3766  
3767 +
3768  extern char *cp_class_name_from_physname (const char *physname);
3769  
3770  extern char *method_name_from_physname (const char *physname);
3771 @@ -72,15 +91,23 @@ extern struct symbol **make_symbol_overload_list (const char *,
3772  extern struct type *cp_lookup_rtti_type (const char *name,
3773                                          struct block *block);
3774  
3775 +extern int cp_validate_operator (const char *input);
3776 +
3777  /* Functions/variables from cp-namespace.c.  */
3778  
3779  extern int cp_is_anonymous (const char *namespace);
3780  
3781  extern void cp_add_using_directive (const char *dest,
3782 -                                    const char *src);
3783 +                                    const char *src,
3784 +                                    const char *alias,
3785 +                                    const char *declaration,
3786 +                                    const int line_number);
3787  
3788  extern struct using_direct *cp_add_using (const char *dest,
3789                                            const char *src,
3790 +                                          const char *alias,
3791 +                                          const char *declaration,
3792 +                                          const int line_number,
3793                                           struct using_direct *next);
3794  
3795  extern void cp_initialize_namespace (void);
3796 @@ -97,15 +124,20 @@ extern void cp_set_block_scope (const struct symbol *symbol,
3797  extern void cp_scan_for_anonymous_namespaces (const struct symbol *symbol);
3798  
3799  extern struct symbol *cp_lookup_symbol_nonlocal (const char *name,
3800 -                                                const char *linkage_name,
3801                                                  const struct block *block,
3802                                                  const domain_enum domain);
3803  
3804 +struct symbol *cp_lookup_symbol_imports (const char *scope,
3805 +                                         const char *name,
3806 +                                         const struct block *block,
3807 +                                         const domain_enum domain,
3808 +                                         int declaration_only,
3809 +                                         int search_parents);
3810 +
3811  extern struct symbol *cp_lookup_symbol_namespace (const char *namespace,
3812 -                                                 const char *name,
3813 -                                                 const char *linkage_name,
3814 -                                                 const struct block *block,
3815 -                                                 const domain_enum domain);
3816 +                                                  const char *name,
3817 +                                                  const struct block *block,
3818 +                                                  const domain_enum domain);
3819  
3820  extern struct type *cp_lookup_nested_type (struct type *parent_type,
3821                                            const char *nested_name,
3822 diff --git a/gdb/dbxread.c b/gdb/dbxread.c
3823 index 7cb016d..bb9e35a 100644
3824 --- a/gdb/dbxread.c
3825 +++ b/gdb/dbxread.c
3826 @@ -3581,6 +3581,7 @@ static struct sym_fns aout_sym_fns =
3827    dbx_new_init,                /* sym_new_init: init anything gbl to entire symtab */
3828    dbx_symfile_init,    /* sym_init: read initial info, setup for sym_read() */
3829    dbx_symfile_read,            /* sym_read: read a symbol file into symtab */
3830 +  NULL,                                /* sym_read_psymbols */
3831    dbx_symfile_finish,          /* sym_finish: finished with file, cleanup */
3832    default_symfile_offsets, /* sym_offsets: parse user's offsets to
3833                               internal form */
3834 diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
3835 index f16b6e2..fe328c7 100644
3836 --- a/gdb/doc/gdb.texinfo
3837 +++ b/gdb/doc/gdb.texinfo
3838 @@ -959,8 +959,10 @@ Connect to process ID @var{number}, as with the @code{attach} command.
3839  @itemx -x @var{file}
3840  @cindex @code{--command}
3841  @cindex @code{-x}
3842 -Execute @value{GDBN} commands from file @var{file}.  @xref{Command
3843 -Files,, Command files}.
3844 +Execute commands from file @var{file}.  If @var{file} ends in
3845 +@samp{.py}, then the file is evaluated as Python code.  If Python
3846 +support is not enabled in this @value{GDBN}, then an error occurs.
3847 +@xref{Command Files,, Command files}.
3848  
3849  @item -eval-command @var{command}
3850  @itemx -ex @var{command}
3851 @@ -1152,6 +1154,16 @@ for remote debugging.
3852  Run using @var{device} for your program's standard input and output.
3853  @c FIXME: kingdon thinks there is more to -tty.  Investigate.
3854  
3855 +@item -P
3856 +@cindex @code{-P}
3857 +@itemx --python
3858 +@cindex @code{--python}
3859 +Change interpretation of command line so that the argument immediately
3860 +following this switch is taken to be the name of a Python script file.
3861 +This option stops option processing; subsequent options are passed to
3862 +Python as @code{sys.argv}.  This option is only available if Python
3863 +scripting support was enabled when @value{GDBN} was configured.
3864 +
3865  @c resolve the situation of these eventually
3866  @item -tui
3867  @cindex @code{--tui}
3868 @@ -18650,7 +18662,7 @@ command:
3869  @table @code
3870  @kindex source
3871  @cindex execute commands from a file
3872 -@item source [@code{-v}] @var{filename}
3873 +@item source [@code{-v}] [@code{-p}] @var{filename}
3874  Execute the command file @var{filename}.
3875  @end table
3876  
3877 @@ -18667,6 +18679,11 @@ If @code{-v}, for verbose mode, is given then @value{GDBN} displays
3878  each command as it is executed.  The option must be given before
3879  @var{filename}, and is interpreted as part of the filename anywhere else.
3880  
3881 +If @var{filename} ends in @samp{.py}, or if @code{-p}, for Python, is
3882 +given then @value{GDBN} evaluates the contents of the file as Python
3883 +code.  If Python support is not compiled in to @value{GDBN}, then an
3884 +error occurs.
3885 +
3886  Commands that would ask for confirmation if used interactively proceed
3887  without asking when used in a command file.  Many @value{GDBN} commands that
3888  normally print messages to say what they are doing omit the messages
3889 @@ -18928,8 +18945,6 @@ containing @code{end}.  For example:
3890  
3891  @smallexample
3892  (@value{GDBP}) python
3893 -Type python script
3894 -End with a line saying just "end".
3895  >print 23
3896  >end
3897  23
3898 @@ -18942,6 +18957,14 @@ in a Python script.  This can be controlled using @code{maint set
3899  python print-stack}: if @code{on}, the default, then Python stack
3900  printing is enabled; if @code{off}, then Python stack printing is
3901  disabled.
3902 +
3903 +@kindex maint set python auto-load
3904 +@item maint set python auto-load
3905 +By default, @value{GDBN} will attempt to automatically load Python
3906 +code when an object file is opened.  This can be controlled using
3907 +@code{maint set python auto-load}: if @code{on}, the default, then
3908 +Python auto-loading is enabled; if @code{off}, then Python
3909 +auto-loading is disabled.
3910  @end table
3911  
3912  @node Python API
3913 @@ -18949,6 +18972,14 @@ disabled.
3914  @cindex python api
3915  @cindex programming in python
3916  
3917 +You can get quick online help for @value{GDBN}'s Python API by issuing
3918 +the command @w{@kbd{python help (gdb)}}.
3919 +
3920 +Functions and methods which have two or more optional arguments allow
3921 +them to be specified using keyword syntax.  This allows passing some
3922 +optional arguments while skipping others.  Example:
3923 +@w{@code{gdb.some_function ('foo', bar = 1, baz = 2)}}.
3924 +
3925  @cindex python stdout
3926  @cindex python pagination
3927  At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
3928 @@ -18961,13 +18992,17 @@ situation, a Python @code{KeyboardInterrupt} exception is thrown.
3929  * Basic Python::                Basic Python Functions.
3930  * Exception Handling::
3931  * Auto-loading::                Automatically loading Python code.
3932 -* Values From Inferior::
3933 +* Values From Inferior::       Python representation of values.
3934  * Types In Python::            Python representation of types.
3935  * Pretty Printing::            Pretty-printing values.
3936  * Selecting Pretty-Printers::   How GDB chooses a pretty-printer.
3937 +* Inferiors In Python::                Python representation of inferiors (processes)
3938 +* Threads In Python::           Accessing inferior threads from Python.
3939  * Commands In Python::          Implementing new commands in Python.
3940 +* Parameters In Python::        Adding new @value{GDBN} parameters.
3941  * Functions In Python::         Writing new convenience functions.
3942  * Objfiles In Python::          Object files.
3943 +* Breakpoints In Python::       Manipulating breakpoints using Python.
3944  * Frames In Python::            Acessing inferior stack frames from Python.
3945  @end menu
3946  
3947 @@ -18994,6 +19029,12 @@ command as having originated from the user invoking it interactively.
3948  It must be a boolean value.  If omitted, it defaults to @code{False}.
3949  @end defun
3950  
3951 +@findex gdb.breakpoints
3952 +@defun breakpoints
3953 +Return a sequence holding all of @value{GDBN}'s breakpoints.
3954 +@xref{Breakpoints In Python}, for more information.
3955 +@end defun
3956 +
3957  @findex gdb.parameter
3958  @defun parameter parameter
3959  Return the value of a @value{GDBN} parameter.  @var{parameter} is a
3960 @@ -19010,6 +19051,7 @@ a Python value of the appropriate type, and returned.
3961  @defun history number
3962  Return a value from @value{GDBN}'s value history (@pxref{Value
3963  History}).  @var{number} indicates which history element to return.
3964 +
3965  If @var{number} is negative, then @value{GDBN} will take its absolute value
3966  and count backward from the last element (i.e., the most recent element) to
3967  find the value to return.  If @var{number} is zero, then @value{GDBN} will
3968 @@ -19021,6 +19063,28 @@ If no exception is raised, the return value is always an instance of
3969  @code{gdb.Value} (@pxref{Values From Inferior}).
3970  @end defun
3971  
3972 +@findex gdb.parse_and_eval
3973 +@defun parse_and_eval expression
3974 +Parse @var{expression} as an expression in the current language,
3975 +evaluate it, and return the result as a @code{gdb.Value}.
3976 +@var{expression} must be a string.
3977 +@end defun
3978 +
3979 +@findex gdb.post_event
3980 +@defun post_event event
3981 +Put @var{event}, a callable object taking no arguments, into
3982 +@value{GDBN}'s internal event queue.  This callable will be invoked at
3983 +some later point, during @value{GDBN}'s event processing.  Events
3984 +posted using @code{post_event} will be run in the order in which they
3985 +were posted; however, there is no way to know when they will be
3986 +processed relative to other events inside @value{GDBN}.
3987 +
3988 +@value{GDBN} is not thread-safe.  If your Python program uses multiple
3989 +threads, you must be careful to only call @value{GDBN}-specific
3990 +functions in the main @value{GDBN} thread.  @code{post_event} ensures
3991 +this.
3992 +@end defun
3993 +
3994  @findex gdb.write
3995  @defun write string
3996  Print a string to @value{GDBN}'s paginated standard output stream.
3997 @@ -19035,6 +19099,11 @@ Flush @value{GDBN}'s paginated standard output stream.  Flushing
3998  function.
3999  @end defun
4000  
4001 +@findex gdb.solib_address
4002 +@defun solib_address @var{address}
4003 +Return the name of the shared library holding the given address, or None.
4004 +@end defun
4005 +
4006  @node Exception Handling
4007  @subsubsection Exception Handling
4008  @cindex python exceptions
4009 @@ -19171,6 +19240,13 @@ The type of this @code{gdb.Value}.  The value of this attribute is a
4010  The following methods are provided:
4011  
4012  @table @code
4013 +@defmethod Value cast type
4014 +Cast the @code{gdb.Value} to the type represented by @var{type}, and
4015 +return a new @code{gdb.Value}.  @var{type} must be a @code{gdb.Type}
4016 +object.  If the cast cannot be performed for some reason, an exception
4017 +is thrown.
4018 +@end defmethod
4019 +
4020  @defmethod Value dereference
4021  For pointer data types, this method returns a new @code{gdb.Value} object
4022  whose contents is the object pointed to by the pointer.  For example, if
4023 @@ -19242,6 +19318,9 @@ module:
4024  This function looks up a type by name.  @var{name} is the name of the
4025  type to look up.  It must be a string.
4026  
4027 +If @var{block} is given, then @var{name} is looked up in that scope.
4028 +Otherwise, it is searched for globally.
4029 +
4030  Ordinarily, this function will return an instance of @code{gdb.Type}.
4031  If the named type cannot be found, it will throw an exception.
4032  @end defun
4033 @@ -19294,6 +19373,12 @@ This is @code{True} if the field is artificial, usually meaning that
4034  it was provided by the compiler and not the user.  This attribute is
4035  always provided, and is @code{False} if the field is not artificial.
4036  
4037 +@item is_base_class
4038 +This is @code{True} if the field represents a base class of a C@t{++}
4039 +structure.  This attribute is always provided, and is @code{False}
4040 +if the field is not a base class of the type on which @code{fields} was
4041 +called, or if that type was not a C@t{++} class.
4042 +
4043  @item bitsize
4044  If the field is packed, or is a bitfield, then this will have a
4045  non-zero value, which is the size of the field in bits.  Otherwise,
4046 @@ -19346,7 +19431,7 @@ If the type does not have a target, this method will throw an
4047  exception.
4048  @end defmethod
4049  
4050 -@defmethod Type template_argument n
4051 +@defmethod Type template_argument n [block]
4052  If this @code{gdb.Type} is an instantiation of a template, this will
4053  return a new @code{gdb.Type} which represents the type of the
4054  @var{n}th template argument.
4055 @@ -19354,7 +19439,8 @@ return a new @code{gdb.Type} which represents the type of the
4056  If this @code{gdb.Type} is not a template type, this will throw an
4057  exception.  Ordinarily, only C@t{++} code will have template types.
4058  
4059 -@var{name} is searched for globally.
4060 +If @var{block} is given, then @var{name} is looked up in that scope.
4061 +Otherwise, it is searched for globally.
4062  @end defmethod
4063  @end table
4064  
4065 @@ -19708,6 +19794,121 @@ import gdb.libstdcxx.v6
4066  gdb.libstdcxx.v6.register_printers (gdb.current_objfile ())
4067  @end smallexample
4068  
4069 +@node Inferiors In Python
4070 +@subsubsection Inferiors In Python
4071 +
4072 +Programs which are being run under @value{GDBN} are called inferiors
4073 +(@pxref{Inferiors}).  Python scripts can access information about and
4074 +manipulate inferiors controlled by @value{GDBN} via objects of the
4075 +@code{gdb.Inferior} class.
4076 +
4077 +The following inferior-related functions are available in the @code{gdb}
4078 +module:
4079 +
4080 +@defun inferiors
4081 +Return a tuple containing all inferior objects.
4082 +@end defun
4083 +
4084 +A @code{gdb.Inferior} object has the following attributes:
4085 +
4086 +@table @code
4087 +@defivar Inferior num 
4088 +ID of inferior, as assigned by GDB.
4089 +@end defivar
4090 +
4091 +@defivar Inferior pid 
4092 +Process ID of the inferior, assigned by the underlying OS.
4093 +@end defivar
4094 +
4095 +@defivar Inferior was_attached
4096 +Boolean signaling whether the inferior was created using `attach', or
4097 +started by @value{GDBN} itself.
4098 +@end defivar
4099 +@end table
4100 +
4101 +A @code{gdb.Inferior} object has the following methods:
4102 +
4103 +@table @code
4104 +@defmethod Inferior threads 
4105 +This method returns a tuple holding all the threads which are valid
4106 +when it is called.  If there are no valid threads, the method will
4107 +return an empty list.
4108 +@end defmethod
4109 +
4110 +@findex gdb.read_memory
4111 +@defmethod Inferior read_memory @var{address} @var{length}
4112 +Read @var{length} bytes of memory from the inferior, starting at
4113 +@var{address}.  Returns a buffer object, which behaves much like an array
4114 +or a string. It can be modified and given to the @code{gdb.write_memory}
4115 +function.
4116 +@end defmethod
4117 +
4118 +@findex gdb.write_memory
4119 +@defmethod Inferior write_memory @var{address} @var{buffer} @r{[}@var{length}@r{]}
4120 +Write the contents of @var{buffer} (a Python object which supports the
4121 +buffer protocol, i.e., a string, an array or the object returned from
4122 +@code{gdb.read_memory}) to the inferior, starting at @var{address}.
4123 +If given, @var{length} determines the number of bytes from @var{buffer} to
4124 +be written.
4125 +@end defmethod
4126 +
4127 +@findex gdb.search_memory
4128 +@defmethod Inferior search_memory @var{address} @var{length} @var{pattern} @r{[}@var{size}@r{]} @r{[}@var{max_count}@r{]}
4129 +Search a region of the inferior memory starting at @var{address} with the
4130 +given @var{length}.  @var{pattern} can be a string, a byte array, a buffer
4131 +object, a number, a @code{gdb.Value} object (@pxref{Values From Inferior})
4132 +or a list or tuple with elements in any combination of those types.  If
4133 +@var{size} is given and is non-zero, it specifies the size in bytes of a
4134 +Python scalar or @code{gdb.Value} in the search pattern.  If @var{size} is
4135 +zero or not specified, it is taken from the value's type in the current
4136 +language.  This is useful when one wants to specify the search pattern as
4137 +a mixture of types.  Note that this means, for example, that in the case of
4138 +C-like languages a search for an untyped 0x42 will search for
4139 +@samp{(int) 0x42} which is typically four bytes.  @var{max_count} is the
4140 +highest number of matches to search for.
4141 +@end defmethod
4142 +@end table
4143 +
4144 +@node Threads In Python
4145 +@subsubsection Threads In Python
4146 +
4147 +Python scripts can access information about and manipulate inferior threads
4148 +controlled by @value{GDBN} via objects of the @code{gdb.InferiorThread} class.
4149 +
4150 +The following inferior-related functions are available in the @code{gdb}
4151 +module:
4152 +
4153 +@findex gdb.selected_thread
4154 +@defun selected_thread
4155 +This function returns the thread object for the selected thread.  If there
4156 +is no selected thread, this will return @code{None}.
4157 +@end defun
4158 +
4159 +A @code{gdb.InferiorThread} object has the following attributes:
4160 +
4161 +@table @code
4162 +@defivar InferiorThread num 
4163 +ID of the thread, as assigned by GDB.
4164 +@end defivar
4165 +@end table
4166 +
4167 +A @code{gdb.InferiorThread} object has the following methods:
4168 +
4169 +@table @code
4170 +@defmethod InferiorThread frames
4171 +Return a tuple containing all frames in the thread.
4172 +@end defmethod
4173 +
4174 +@defmethod InferiorThread newest_frame
4175 +Return the newest frame thread's stack.
4176 +@end defmethod
4177 +
4178 +@defmethod InferiorThread switch_to_thread 
4179 +This changes @value{GDBN}'s currently selected thread to the one represented
4180 +by this object.
4181 +@end defmethod
4182 +@end table
4183 +
4184  @node Commands In Python
4185  @subsubsection Commands In Python
4186  
4187 @@ -19960,6 +20161,135 @@ registration of the command with @value{GDBN}.  Depending on how the
4188  Python code is read into @value{GDBN}, you may need to import the
4189  @code{gdb} module explicitly.
4190  
4191 +@node Parameters In Python
4192 +@subsubsection Parameters In Python
4193 +
4194 +@cindex parameters in python
4195 +@cindex python parameters
4196 +@tindex gdb.Parameter
4197 +@tindex Parameter
4198 +You can implement new @value{GDBN} parameters using Python.  A new
4199 +parameter is implemented as an instance of the @code{gdb.Parameter}
4200 +class.  Parameters are exposed to the user via the @code{set} and
4201 +@code{show} commands.
4202 +
4203 +@defmethod Parameter __init__ name @var{command-class} @var{parameter-class} @r{[}@var{enum-sequence}@r{]}
4204 +The object initializer for @code{Parameter} registers the new
4205 +parameter with @value{GDBN}.  This initializer is normally invoked
4206 +from the subclass' own @code{__init__} method.
4207 +
4208 +@var{name} is the name of the new parameter.  If @var{name} consists
4209 +of multiple words, then the initial words are looked for as prefix
4210 +commands.  In this case, if one of the prefix commands does not exist,
4211 +an exception is raised.
4212 +
4213 +@var{command-class} should be one of the @samp{COMMAND_} constants
4214 +(@pxref{Commands In Python}).  This argument tells @value{GDBN} how to
4215 +categorize the new parameter in the help system.
4216 +
4217 +@var{parameter-class} should be one of the @samp{PARAM_} constants
4218 +defined below.  This argument tells @value{GDBN} the type of the new
4219 +parameter; this information is used for input validation and
4220 +completion.
4221 +
4222 +If @var{parameter-class} is @code{PARAM_ENUM}, then
4223 +@var{enum-sequence} must be a sequence of strings.  These strings
4224 +represent the possible values for the parameter.
4225 +
4226 +If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
4227 +of a fourth argument will cause an exception to be thrown.
4228 +
4229 +The help text for the new parameter is taken from the Python
4230 +documentation string for the parameter's class, if there is one.  If
4231 +there is no documentation string, a default value is used.
4232 +@end defmethod
4233 +
4234 +@defivar Parameter set_doc
4235 +If this attribute exists, and is a string, then its value is used as
4236 +the help text for this parameter's @code{set} command.  The value is
4237 +examined when @code{Parameter.__init__} is invoked; subsequent changes
4238 +have no effect.
4239 +@end defivar
4240 +
4241 +@defivar Parameter show_doc
4242 +If this attribute exists, and is a string, then its value is used as
4243 +the help text for this parameter's @code{show} command.  The value is
4244 +examined when @code{Parameter.__init__} is invoked; subsequent changes
4245 +have no effect.
4246 +@end defivar
4247 +
4248 +@defivar Parameter value
4249 +The @code{value} attribute holds the underlying value of the
4250 +parameter.  It can be read and assigned to just as any other
4251 +attribute.  @value{GDBN} does validation when assignments are made.
4252 +@end defivar
4253 +
4254 +
4255 +When a new parameter is defined, its type must be specified.  The
4256 +available types are represented by constants defined in the @code{gdb}
4257 +module:
4258 +
4259 +@table @code
4260 +@findex PARAM_BOOLEAN
4261 +@findex gdb.PARAM_BOOLEAN
4262 +@item PARAM_BOOLEAN
4263 +The value is a plain boolean.  The Python boolean values, @code{True}
4264 +and @code{False} are the only valid values.
4265 +
4266 +@findex PARAM_AUTO_BOOLEAN
4267 +@findex gdb.PARAM_AUTO_BOOLEAN
4268 +@item PARAM_AUTO_BOOLEAN
4269 +The value has three possible states: true, false, and @samp{auto}.  In
4270 +Python, true and false are represented using boolean constants, and
4271 +@samp{auto} is represented using @code{None}.
4272 +
4273 +@findex PARAM_UINTEGER
4274 +@findex gdb.PARAM_UINTEGER
4275 +@item PARAM_UINTEGER
4276 +The value is an unsigned integer.  The value of 0 should be
4277 +interpreted to mean ``unlimited''.
4278 +
4279 +@findex PARAM_INTEGER
4280 +@findex gdb.PARAM_INTEGER
4281 +@item PARAM_INTEGER
4282 +The value is a signed integer.  The value of 0 should be interpreted
4283 +to mean ``unlimited''.
4284 +
4285 +@findex PARAM_STRING
4286 +@findex gdb.PARAM_STRING
4287 +@item PARAM_STRING
4288 +The value is a string.  When the user modifies the string, escapes are
4289 +translated.
4290 +
4291 +@findex PARAM_STRING_NOESCAPE
4292 +@findex gdb.PARAM_STRING_NOESCAPE
4293 +@item PARAM_STRING_NOESCAPE
4294 +The value is a string.  When the user modifies the string, escapes are
4295 +passed through untranslated.
4296 +
4297 +@findex PARAM_OPTIONAL_FILENAME
4298 +@findex gdb.PARAM_OPTIONAL_FILENAME
4299 +@item PARAM_OPTIONAL_FILENAME
4300 +The value is a either a filename (a string), or @code{None}.
4301 +
4302 +@findex PARAM_FILENAME
4303 +@findex gdb.PARAM_FILENAME
4304 +@item PARAM_FILENAME
4305 +The value is a filename (a string).
4306 +
4307 +@findex PARAM_ZINTEGER
4308 +@findex gdb.PARAM_ZINTEGER
4309 +@item PARAM_ZINTEGER
4310 +The value is an integer.  This is like @code{PARAM_INTEGER}, except 0
4311 +is interpreted as itself.
4312 +
4313 +@findex PARAM_ENUM
4314 +@findex gdb.PARAM_ENUM
4315 +@item PARAM_ENUM
4316 +The value is a string, which must be one of a collection string
4317 +constants provided when the parameter is created.
4318 +@end table
4319 +
4320  @node Functions In Python
4321  @subsubsection Writing new convenience functions
4322  
4323 @@ -20064,6 +20394,82 @@ which is used to format the value.  @xref{Pretty Printing}, for more
4324  information.
4325  @end defivar
4326  
4327 +@node Breakpoints In Python
4328 +@subsubsection Manipulating breakpoints using Python
4329 +
4330 +@cindex breakpoints in python
4331 +@cindex python breakpoints
4332 +@tindex gdb.Breakpoint
4333 +@tindex Breakpoint
4334 +Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
4335 +class.
4336 +
4337 +@defmethod Breakpoint __init__ location
4338 +Create a new breakpoint.  @var{location} is a string naming the
4339 +location of the breakpoint.  The contents can be any location
4340 +recognized by the @code{break} command.
4341 +@end defmethod
4342 +
4343 +@defmethod Breakpoint is_valid
4344 +Return @code{True} if this @code{Breakpoint} object is valid,
4345 +@code{False} otherwise.  A @code{Breakpoint} object can become invalid
4346 +if the user deletes the breakpoint.  In this case, the object still
4347 +exists, but the underlying breakpoint does not.
4348 +@end defmethod
4349 +
4350 +@defivar Breakpoint enabled
4351 +This attribute is @code{True} if the breakpoint is enabled, and
4352 +@code{False} otherwise.  This attribute is writable.
4353 +@end defivar
4354 +
4355 +@defivar Breakpoint silent
4356 +This attribute is @code{True} if the breakpoint is silent, and
4357 +@code{False} otherwise.  This attribute is writable.
4358 +
4359 +Note that a breakpoint can also be silent if it has commands and the
4360 +first command is @code{silent}.  This is not reported by the
4361 +@code{silent} attribute.
4362 +@end defivar
4363 +
4364 +@defivar Breakpoint thread
4365 +If the breakpoint is thread-specific, this attribute holds the thread
4366 +id.  If the breakpoint is not thread-specific, this attribute is
4367 +@code{None}.  This attribute is writable.
4368 +@end defivar
4369 +
4370 +@defivar Breakpoint ignore_count
4371 +This attribute holds the ignore count for the breakpoint, an integer.
4372 +This attribute is writable.
4373 +@end defivar
4374 +
4375 +@defivar Breakpoint number
4376 +This attribute holds the breakpoint's number -- the identifier used by
4377 +the user to manipulate the breakpoint.  This attribute is not writable.
4378 +@end defivar
4379 +
4380 +@defivar Breakpoint hit_count
4381 +This attribute holds the hit count for the breakpoint, an integer.
4382 +This attribute is writable, but currently it can only be set to zero.
4383 +@end defivar
4384 +
4385 +@defivar Breakpoint location
4386 +This attribute holds the location of the breakpoint, as specified by
4387 +the user.  It is a string.  This attribute is not writable.
4388 +@end defivar
4389 +
4390 +@defivar Breakpoint condition
4391 +This attribute holds the condition of the breakpoint, as specified by
4392 +the user.  It is a string.  If there is no condition, this attribute's
4393 +value is @code{None}.  This attribute is writable.
4394 +@end defivar
4395 +
4396 +@defivar Breakpoint commands
4397 +This attribute holds the commands attached to the breakpoint.  If
4398 +there are commands, this returns a string holding all the commands,
4399 +separated by newlines.  If there are no commands, this attribute is
4400 +@code{None}.  This attribute is not writable.
4401 +@end defivar
4402 +
4403  @node Frames In Python
4404  @subsubsection Acessing inferior stack frames from Python.
4405  
4406 @@ -20128,6 +20534,14 @@ function to a string.
4407  Returns the frame's resume address.
4408  @end defmethod
4409  
4410 +@defmethod Frame block
4411 +Returns the frame's code block. @c (@pxref{Block,,Code Blocks and Scopes}).
4412 +@end defmethod
4413 +
4414 +@defmethod Frame function
4415 +Returns the symbol for the function corresponding to this frame. @c (@pxref{Symbols In Python}).
4416 +@end defmethod
4417 +
4418  @defmethod Frame older
4419  Return the frame that called this frame.
4420  @end defmethod
4421 @@ -20136,10 +20550,18 @@ Return the frame that called this frame.
4422  Return the frame called by this frame.
4423  @end defmethod
4424  
4425 +@defmethod Frame find_sal
4426 +Return the frame's symtab and line object. @c (@pxref{Symtab_and_line,, Symtab and line}).
4427 +@end defmethod
4428 +
4429  @defmethod Frame read_var variable
4430  Return the value of the given variable in this frame.  @var{variable} must
4431  be a string.
4432  @end defmethod
4433 +
4434 +@defmethod Frame select
4435 +Set this frame to be the user's selected frame.
4436 +@end defmethod
4437  @end table
4438  
4439  @node Interpreters
4440 diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo
4441 index c2be3f7..a7811ab 100644
4442 --- a/gdb/doc/gdbint.texinfo
4443 +++ b/gdb/doc/gdbint.texinfo
4444 @@ -2114,6 +2114,18 @@ time, and so we attempt to handle symbols incrementally.  For instance,
4445  we create @dfn{partial symbol tables} consisting of only selected
4446  symbols, and only expand them to full symbol tables when necessary.
4447  
4448 +@menu
4449 +* Symbol Reading::
4450 +* Partial Symbol Tables::
4451 +* Types::
4452 +* Object File Formats::
4453 +* Debugging File Formats::
4454 +* Adding a New Symbol Reader to GDB::
4455 +* Memory Management for Symbol Files::
4456 +* Memory Management for Types::
4457 +@end menu
4458 +
4459 +@node Symbol Reading
4460  @section Symbol Reading
4461  
4462  @cindex symbol reading
4463 @@ -2206,6 +2218,7 @@ symtab.  Upon return, @code{pst->readin} should have been set to 1, and
4464  zero if there were no symbols in that part of the symbol file.
4465  @end table
4466  
4467 +@node Partial Symbol Tables
4468  @section Partial Symbol Tables
4469  
4470  @value{GDBN} has three types of symbol tables:
4471 @@ -2301,6 +2314,7 @@ and all the psymbols themselves are allocated in a pair of large arrays
4472  on an obstack, so there is little to be gained by trying to free them
4473  unless you want to do a lot more work.
4474  
4475 +@node Types
4476  @section Types
4477  
4478  @unnumberedsubsec Fundamental Types (e.g., @code{FT_VOID}, @code{FT_BOOLEAN}).
4479 @@ -2323,6 +2337,7 @@ types map to one @code{TYPE_CODE_*} type, and are distinguished by
4480  other members of the type struct, such as whether the type is signed
4481  or unsigned, and how many bits it uses.
4482  
4483 +@anchor{Builtin Types}
4484  @unnumberedsubsec Builtin Types (e.g., @code{builtin_type_void}, @code{builtin_type_char}).
4485  
4486  These are instances of type structs that roughly correspond to
4487 @@ -2337,6 +2352,7 @@ only one instance exists, while @file{c-lang.c} builds as many
4488  @code{TYPE_CODE_INT} types as needed, with each one associated with
4489  some particular objfile.
4490  
4491 +@node Object File Formats
4492  @section Object File Formats
4493  @cindex object file formats
4494  
4495 @@ -2422,6 +2438,7 @@ SOM, which is a cross-language ABI).
4496  
4497  The SOM reader is in @file{somread.c}.
4498  
4499 +@node Debugging File Formats
4500  @section Debugging File Formats
4501  
4502  This section describes characteristics of debugging information that
4503 @@ -2493,6 +2510,7 @@ DWARF 3 is an improved version of DWARF 2.
4504  @cindex SOM debugging info
4505  Like COFF, the SOM definition includes debugging information.
4506  
4507 +@node Adding a New Symbol Reader to GDB
4508  @section Adding a New Symbol Reader to @value{GDBN}
4509  
4510  @cindex adding debugging info reader
4511 @@ -2515,6 +2533,7 @@ will only ever be implemented by one object file format may be called
4512  directly.  This interface should be described in a file
4513  @file{bfd/lib@var{xyz}.h}, which is included by @value{GDBN}.
4514  
4515 +@node Memory Management for Symbol Files
4516  @section Memory Management for Symbol Files
4517  
4518  Most memory associated with a loaded symbol file is stored on
4519 @@ -2526,10 +2545,45 @@ released when the objfile is unloaded or reloaded.  Therefore one
4520  objfile must not reference symbol or type data from another objfile;
4521  they could be unloaded at different times.
4522  
4523 -User convenience variables, et cetera, have associated types.  Normally
4524 -these types live in the associated objfile.  However, when the objfile
4525 -is unloaded, those types are deep copied to global memory, so that
4526 -the values of the user variables and history items are not lost.
4527 +@node Memory Management for Types
4528 +@section Memory Management for Types
4529 +@cindex memory management for types
4530 +
4531 +@findex TYPE_OBJFILE
4532 +@code{TYPE_OBJFILE} macro indicates the current memory owner of the type.
4533 +Non-@code{NULL} value indicates it is owned by an objfile (specifically by its
4534 +obstack) and in such case the type remains valid till the objfile is unloaded
4535 +or reloaded.  For such types with an associated objfile no reference counting
4536 +is being made.
4537 +
4538 +User convenience variables, et cetera, have associated types.  Normally these
4539 +types live in the associated objfile.  However, when the objfile is unloaded,
4540 +those types are deep copied to global memory, so that the values of the user
4541 +variables and history items are not lost.  During the copy they will get their
4542 +@code{TYPE_OBJFILE} set to @code{NULL} and become so-called @dfn{reclaimable}
4543 +types.
4544 +
4545 +Types with null @code{TYPE_OBJFILE} can be either permanent types
4546 +(@pxref{Builtin Types}) or reclaimable types which will be deallocated at the
4547 +first idle @value{GDBN} moment if the last object referencing them is removed.
4548 +Permanent types are allocated by the function @code{alloc_type} (and its
4549 +derivations like @code{init_type}) specifying objfile as @code{NULL}.  The
4550 +reclaimable types are created the same way but moreover they need to have
4551 +@code{type_init_group} called to start their tracking as being possibly
4552 +deallocatable.
4553 +
4554 +@findex free_all_types
4555 +When @value{GDBN} gets idle it always calls the @code{free_all_types} function
4556 +which deallocates any unused types.  All types currently not owned by an
4557 +objfile must be marked as used on each @code{free_all_types} call as they would
4558 +get deallocated as unused otherwise.
4559 +
4560 +@code{free_all_types} automatically checks for any cross-type references such
4561 +as through @code{TYPE_TARGET_TYPE}, @code{TYPE_POINTER_TYPE} etc.@: and
4562 +prevents early deallocation for any such existing references.  Reclaimable
4563 +types may reference any other reclaimable types or even permanent types.  But
4564 +permanent types must not reference reclaimable types (nor an objfile associated
4565 +type).
4566  
4567  
4568  @node Language Support
4569 diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
4570 index 4984f31..fcf1b5d 100644
4571 --- a/gdb/doc/observer.texi
4572 +++ b/gdb/doc/observer.texi
4573 @@ -206,6 +206,11 @@ Either @value{GDBN} detached from the inferior, or the inferior
4574  exited.  The argument @var{pid} identifies the inferior.
4575  @end deftypefun
4576  
4577 +@deftypefun void mark_used (void)
4578 +Mark any possibly reclaimable objects as used during a mark-and-sweep garbage
4579 +collector pass.  Currently only @code{type_mark_used} marker is supported.
4580 +@end deftypefun
4581 +
4582   @deftypefun void test_notification (int @var{somearg})
4583  This observer is used for internal testing.  Do not use.  
4584  See testsuite/gdb.gdb/observer.exp.
4585 diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
4586 index 668c434..c29c3a5 100644
4587 --- a/gdb/dwarf2-frame.c
4588 +++ b/gdb/dwarf2-frame.c
4589 @@ -38,6 +38,7 @@
4590  
4591  #include "complaints.h"
4592  #include "dwarf2-frame.h"
4593 +#include "addrmap.h"
4594  
4595  struct comp_unit;
4596  
4597 @@ -1574,6 +1575,14 @@ dwarf2_frame_find_fde (CORE_ADDR *pc)
4598        CORE_ADDR offset;
4599        CORE_ADDR seek_pc;
4600  
4601 +      if (objfile->quick_addrmap)
4602 +       {
4603 +         if (!addrmap_find (objfile->quick_addrmap, *pc))
4604 +           continue;
4605 +       }
4606 +      /* FIXME: Read-in only .debug_frame/.eh_frame without .debug_info?  */
4607 +      require_partial_symbols (objfile);
4608 +
4609        fde_table = objfile_data (objfile, dwarf2_frame_objfile_data);
4610        if (fde_table == NULL)
4611         continue;
4612 diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
4613 index 46bc9d7..e675575 100644
4614 --- a/gdb/dwarf2expr.c
4615 +++ b/gdb/dwarf2expr.c
4616 @@ -848,6 +848,13 @@ execute_stack_op (struct dwarf_expr_context *ctx,
4617           ctx->initialized = 0;
4618           goto no_push;
4619  
4620 +       case DW_OP_push_object_address:
4621 +         if (ctx->get_object_address == NULL)
4622 +           error (_("DWARF-2 expression error: DW_OP_push_object_address must "
4623 +                  "have a value to push."));
4624 +         result = (ctx->get_object_address) (ctx->baton);
4625 +         break;
4626 +
4627         default:
4628           error (_("Unhandled dwarf expression opcode 0x%x"), op);
4629         }
4630 diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
4631 index a9a8a05..d449012 100644
4632 --- a/gdb/dwarf2expr.h
4633 +++ b/gdb/dwarf2expr.h
4634 @@ -102,10 +102,10 @@ struct dwarf_expr_context
4635       The result must be live until the current expression evaluation
4636       is complete.  */
4637    unsigned char *(*get_subr) (void *baton, off_t offset, size_t *length);
4638 +#endif
4639  
4640    /* Return the `object address' for DW_OP_push_object_address.  */
4641    CORE_ADDR (*get_object_address) (void *baton);
4642 -#endif
4643  
4644    /* The current depth of dwarf expression recursion, via DW_OP_call*,
4645       DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum
4646 diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
4647 index 3a81202..85f4487 100644
4648 --- a/gdb/dwarf2loc.c
4649 +++ b/gdb/dwarf2loc.c
4650 @@ -116,6 +116,9 @@ struct dwarf_expr_baton
4651  {
4652    struct frame_info *frame;
4653    struct objfile *objfile;
4654 +  /* From DW_TAG_variable's DW_AT_location (not DW_TAG_type's
4655 +     DW_AT_data_location) for DW_OP_push_object_address.  */
4656 +  CORE_ADDR object_address;
4657  };
4658  
4659  /* Helper functions for dwarf2_evaluate_loc_desc.  */
4660 @@ -177,22 +180,33 @@ dwarf_expr_frame_base (void *baton, gdb_byte **start, size_t * length)
4661        *start = find_location_expression (symbaton, length,
4662                                          get_frame_address_in_block (frame));
4663      }
4664 -  else
4665 +  else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_locexpr_funcs)
4666      {
4667        struct dwarf2_locexpr_baton *symbaton;
4668 +
4669        symbaton = SYMBOL_LOCATION_BATON (framefunc);
4670 -      if (symbaton != NULL)
4671 -       {
4672 -         *length = symbaton->size;
4673 -         *start = symbaton->data;
4674 -       }
4675 -      else
4676 -       *start = NULL;
4677 +      gdb_assert (symbaton != NULL);
4678 +      *start = symbaton->data;
4679 +      *length = symbaton->size;
4680      }
4681 +  else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_missing_funcs)
4682 +    {
4683 +      struct dwarf2_locexpr_baton *symbaton;
4684 +
4685 +      symbaton = SYMBOL_LOCATION_BATON (framefunc);
4686 +      gdb_assert (symbaton == NULL);
4687 +      *start = NULL;
4688 +      *length = 0;     /* unused */
4689 +    }
4690 +  else
4691 +    internal_error (__FILE__, __LINE__,
4692 +                   _("Unsupported SYMBOL_COMPUTED_OPS %p for \"%s\""),
4693 +                   SYMBOL_COMPUTED_OPS (framefunc),
4694 +                   SYMBOL_PRINT_NAME (framefunc));
4695  
4696    if (*start == NULL)
4697      error (_("Could not find the frame base for \"%s\"."),
4698 -          SYMBOL_NATURAL_NAME (framefunc));
4699 +          SYMBOL_PRINT_NAME (framefunc));
4700  }
4701  
4702  /* Helper function for dwarf2_evaluate_loc_desc.  Computes the CFA for
4703 @@ -215,6 +229,129 @@ dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
4704    return target_translate_tls_address (debaton->objfile, offset);
4705  }
4706  
4707 +static CORE_ADDR
4708 +dwarf_expr_object_address (void *baton)
4709 +{
4710 +  struct dwarf_expr_baton *debaton = baton;
4711 +
4712 +  /* The message is suppressed in DWARF_BLOCK_EXEC.  */
4713 +  if (debaton->object_address == 0)
4714 +    error (_("Cannot resolve DW_OP_push_object_address for a missing object"));
4715 +
4716 +  return debaton->object_address;
4717 +}
4718 +
4719 +/* Address of the variable we are currently referring to.  It is set from
4720 +   DW_TAG_variable's DW_AT_location (not DW_TAG_type's DW_AT_data_location) for
4721 +   DW_OP_push_object_address.  */
4722 +
4723 +static CORE_ADDR object_address;
4724 +
4725 +/* Callers use object_address_set while their callers use the result set so we
4726 +   cannot run the cleanup at the local block of our direct caller.  Still we
4727 +   should reset OBJECT_ADDRESS at least for the next GDB command.  */
4728 +
4729 +static void
4730 +object_address_cleanup (void *prev_save_voidp)
4731 +{
4732 +  CORE_ADDR *prev_save = prev_save_voidp;
4733 +
4734 +  object_address = *prev_save;
4735 +  xfree (prev_save);
4736 +}
4737 +
4738 +/* Set the base address - DW_AT_location - of a variable.  It is being later
4739 +   used to derive other object addresses by DW_OP_push_object_address.
4740 +
4741 +   It would be useful to sanity check ADDRESS - such as for some objects with
4742 +   unset value_raw_address - but some valid addresses may be zero (such as first
4743 +   objects in relocatable .o files).  */
4744 +
4745 +void
4746 +object_address_set (CORE_ADDR address)
4747 +{
4748 +  CORE_ADDR *prev_save;
4749 +
4750 +  prev_save = xmalloc (sizeof *prev_save);
4751 +  *prev_save = object_address;
4752 +  make_cleanup (object_address_cleanup, prev_save);
4753 +
4754 +  object_address = address;
4755 +}
4756 +
4757 +/* Evaluate DWARF expression at DATA ... DATA + SIZE with its result readable
4758 +   by dwarf_expr_fetch (RETVAL, 0).  FRAME parameter can be NULL to call
4759 +   get_selected_frame to find it.  Returned dwarf_expr_context freeing is
4760 +   pushed on the cleanup chain.  */
4761 +
4762 +static struct dwarf_expr_context *
4763 +dwarf_expr_prep_ctx (struct frame_info *frame, gdb_byte *data,
4764 +                    unsigned short size, struct dwarf2_per_cu_data *per_cu)
4765 +{
4766 +  struct dwarf_expr_context *ctx;
4767 +  struct dwarf_expr_baton baton;
4768 +
4769 +  if (!frame)
4770 +    frame = get_selected_frame (NULL);
4771 +
4772 +  baton.frame = frame;
4773 +  baton.objfile = dwarf2_per_cu_objfile (per_cu);
4774 +  baton.object_address = object_address;
4775 +
4776 +  ctx = new_dwarf_expr_context ();
4777 +  make_cleanup_free_dwarf_expr_context (ctx);
4778 +
4779 +  ctx->gdbarch = get_objfile_arch (baton.objfile);
4780 +  ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
4781 +  ctx->baton = &baton;
4782 +  ctx->read_reg = dwarf_expr_read_reg;
4783 +  ctx->read_mem = dwarf_expr_read_mem;
4784 +  ctx->get_frame_base = dwarf_expr_frame_base;
4785 +  ctx->get_frame_cfa = dwarf_expr_frame_cfa;
4786 +  ctx->get_tls_address = dwarf_expr_tls_address;
4787 +  ctx->get_object_address = dwarf_expr_object_address;
4788 +
4789 +  dwarf_expr_eval (ctx, data, size);
4790 +
4791 +  /* It was used only during dwarf_expr_eval.  */
4792 +  ctx->baton = NULL;
4793 +
4794 +  return ctx;
4795 +}
4796 +
4797 +/* Evaluate DWARF expression at DLBATON expecting it produces exactly one
4798 +   CORE_ADDR result on the DWARF stack stack.  */
4799 +
4800 +CORE_ADDR
4801 +dwarf_locexpr_baton_eval (struct dwarf2_locexpr_baton *dlbaton)
4802 +{
4803 +  struct dwarf_expr_context *ctx;
4804 +  CORE_ADDR retval;
4805 +  struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4806 +
4807 +  ctx = dwarf_expr_prep_ctx (NULL, dlbaton->data, dlbaton->size,
4808 +                            dlbaton->per_cu);
4809 +  if (ctx->num_pieces > 0)
4810 +    error (_("DW_OP_*piece is unsupported for DW_FORM_block"));
4811 +
4812 +  retval = dwarf_expr_fetch (ctx, 0);
4813 +
4814 +  if (ctx->location == DWARF_VALUE_REGISTER)
4815 +    {
4816 +      /* Inlined dwarf_expr_read_reg as we no longer have the baton. */
4817 +
4818 +      int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (ctx->gdbarch, retval);
4819 +      struct type *type = builtin_type (ctx->gdbarch)->builtin_data_ptr;
4820 +      struct frame_info *frame = get_selected_frame (NULL);
4821 +
4822 +      retval = address_from_register (type, gdb_regnum, frame);
4823 +    }
4824 +
4825 +  do_cleanups (back_to);
4826 +
4827 +  return retval;
4828 +}
4829 +
4830  struct piece_closure
4831  {
4832    /* The number of pieces used to describe this variable.  */
4833 @@ -382,9 +519,8 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
4834                           struct dwarf2_per_cu_data *per_cu)
4835  {
4836    struct value *retval;
4837 -  struct dwarf_expr_baton baton;
4838    struct dwarf_expr_context *ctx;
4839 -  struct cleanup *old_chain;
4840 +  struct cleanup *old_chain = make_cleanup (null_cleanup, 0);
4841  
4842    if (size == 0)
4843      {
4844 @@ -394,22 +530,8 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
4845        return retval;
4846      }
4847  
4848 -  baton.frame = frame;
4849 -  baton.objfile = dwarf2_per_cu_objfile (per_cu);
4850 +  ctx = dwarf_expr_prep_ctx (frame, data, size, per_cu);
4851  
4852 -  ctx = new_dwarf_expr_context ();
4853 -  old_chain = make_cleanup_free_dwarf_expr_context (ctx);
4854 -
4855 -  ctx->gdbarch = get_objfile_arch (baton.objfile);
4856 -  ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
4857 -  ctx->baton = &baton;
4858 -  ctx->read_reg = dwarf_expr_read_reg;
4859 -  ctx->read_mem = dwarf_expr_read_mem;
4860 -  ctx->get_frame_base = dwarf_expr_frame_base;
4861 -  ctx->get_frame_cfa = dwarf_expr_frame_cfa;
4862 -  ctx->get_tls_address = dwarf_expr_tls_address;
4863 -
4864 -  dwarf_expr_eval (ctx, data, size);
4865    if (ctx->num_pieces > 0)
4866      {
4867        struct piece_closure *c;
4868 @@ -439,6 +561,11 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
4869             CORE_ADDR address = dwarf_expr_fetch (ctx, 0);
4870             int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
4871  
4872 +           /* object_address_set called here is required in ALLOCATE_VALUE's
4873 +              CHECK_TYPEDEF for the object's possible
4874 +              DW_OP_push_object_address.  */
4875 +           object_address_set (address);
4876 +
4877             retval = allocate_value (SYMBOL_TYPE (var));
4878             VALUE_LVAL (retval) = lval_memory;
4879             set_value_lazy (retval, 1);
4880 @@ -815,7 +942,7 @@ static int
4881  loclist_describe_location (struct symbol *symbol, struct ui_file *stream)
4882  {
4883    /* FIXME: Could print the entire list of locations.  */
4884 -  fprintf_filtered (stream, "a variable with multiple locations");
4885 +  fprintf_filtered (stream, _("a variable with multiple locations"));
4886    return 1;
4887  }
4888  
4889 @@ -831,16 +958,56 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
4890  
4891    data = find_location_expression (dlbaton, &size, ax->scope);
4892    if (data == NULL)
4893 -    error (_("Variable \"%s\" is not available."), SYMBOL_NATURAL_NAME (symbol));
4894 +    error (_("Variable \"%s\" is not available."), SYMBOL_PRINT_NAME (symbol));
4895  
4896    dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value, data, size);
4897  }
4898  
4899 -/* The set of location functions used with the DWARF-2 expression
4900 -   evaluator and location lists.  */
4901 +/* The set of location functions used with the DWARF-2 location lists.  */
4902  const struct symbol_computed_ops dwarf2_loclist_funcs = {
4903    loclist_read_variable,
4904    loclist_read_needs_frame,
4905    loclist_describe_location,
4906    loclist_tracepoint_var_ref
4907  };
4908 +
4909 +static struct value *
4910 +missing_read_variable (struct symbol *symbol, struct frame_info *frame)
4911 +{
4912 +  struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4913 +
4914 +  gdb_assert (dlbaton == NULL);
4915 +  error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
4916 +}
4917 +
4918 +static int
4919 +missing_read_needs_frame (struct symbol *symbol)
4920 +{
4921 +  return 0;
4922 +}
4923 +
4924 +static int
4925 +missing_describe_location (struct symbol *symbol, struct ui_file *stream)
4926 +{
4927 +  fprintf_filtered (stream, _("a variable we are unable to resolve"));
4928 +  return 1;
4929 +}
4930 +
4931 +static void
4932 +missing_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
4933 +                           struct agent_expr *ax, struct axs_value *value)
4934 +{
4935 +  struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4936 +
4937 +  gdb_assert (dlbaton == NULL);
4938 +  error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
4939 +}
4940 +
4941 +/* The set of location functions used with the DWARF-2 evaluator when we are
4942 +   unable to resolve the symbols.  */
4943 +const struct symbol_computed_ops dwarf2_missing_funcs = {
4944 +  missing_read_variable,
4945 +  missing_read_needs_frame,
4946 +  missing_describe_location,
4947 +  missing_tracepoint_var_ref
4948 +};
4949 diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
4950 index 0bfcfca..01018d6 100644
4951 --- a/gdb/dwarf2loc.h
4952 +++ b/gdb/dwarf2loc.h
4953 @@ -71,5 +71,11 @@ struct dwarf2_loclist_baton
4954  
4955  extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
4956  extern const struct symbol_computed_ops dwarf2_loclist_funcs;
4957 +extern const struct symbol_computed_ops dwarf2_missing_funcs;
4958 +
4959 +extern void object_address_set (CORE_ADDR address);
4960 +
4961 +extern CORE_ADDR dwarf_locexpr_baton_eval
4962 +  (struct dwarf2_locexpr_baton *dlbaton);
4963  
4964  #endif /* dwarf2loc.h */
4965 diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
4966 index 4cce36b..c2f5f23 100644
4967 --- a/gdb/dwarf2read.c
4968 +++ b/gdb/dwarf2read.c
4969 @@ -48,6 +48,12 @@
4970  #include "gdbcmd.h"
4971  #include "block.h"
4972  #include "addrmap.h"
4973 +#include "f-lang.h"
4974 +#include "c-lang.h"
4975 +#include "typeprint.h"
4976 +#include "jv-lang.h"
4977 +#include "vec.h"
4978 +#include "block.h"
4979  
4980  #include <fcntl.h>
4981  #include "gdb_string.h"
4982 @@ -93,7 +99,7 @@ typedef struct pubnames_header
4983  _PUBNAMES_HEADER;
4984  #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
4985  
4986 -/* .debug_pubnames header
4987 +/* .debug_aranges header
4988     Because of alignment constraints, this structure has padding and cannot
4989     be mapped directly onto the beginning of the .debug_info section.  */
4990  typedef struct aranges_header
4991 @@ -150,7 +156,10 @@ struct dwarf2_section_info
4992    asection *asection;
4993    gdb_byte *buffer;
4994    bfd_size_type size;
4995 -  int was_mmapped;
4996 +  /* A function to call to deallocate BUFFER.  If NULL, no
4997 +     deallocation is needed.  A pointer to this structure is passed as
4998 +     the only argument.  */
4999 +  void (*destructor) (struct dwarf2_section_info *);
5000  };
5001  
5002  struct dwarf2_per_objfile
5003 @@ -336,6 +345,19 @@ struct dwarf2_cu
5004  
5005    /* Field `ranges_offset' is filled in; flag as the value may be zero.  */
5006    unsigned int has_ranges_offset : 1;
5007 +
5008 +  /* Fields are valid according to the LANGUAGE field.  */
5009 +  union
5010 +    {
5011 +      /* language_fortran */
5012 +      struct
5013 +        {
5014 +         /* Module names imported to the block being currently read in.  */
5015 +         struct fortran_using *use;
5016 +       }
5017 +      fortran;
5018 +    }
5019 +  language_specific;
5020  };
5021  
5022  /* Persistent data held for a compilation unit, even when not
5023 @@ -495,8 +517,7 @@ struct partial_die_info
5024      unsigned int has_byte_size : 1;
5025  
5026      /* The name of this DIE.  Normally the value of DW_AT_name, but
5027 -       sometimes DW_TAG_MIPS_linkage_name or a string computed in some
5028 -       other fashion.  */
5029 +       sometimes a default name for unnamed DIEs.  */
5030      char *name;
5031      char *dirname;
5032  
5033 @@ -689,6 +710,11 @@ struct field_info
5034      int nfnfields;
5035    };
5036  
5037 +/* A vector used during linkage name generation.  */
5038 +typedef struct die_info *die_info_p;
5039 +DEF_VEC_P (die_info_p);
5040 +static VEC(die_info_p) *die_list;
5041 +
5042  /* One item on the queue of compilation units to read in full symbols
5043     for.  */
5044  struct dwarf2_queue_item
5045 @@ -800,7 +826,10 @@ static void scan_partial_symbols (struct partial_die_info *,
5046  static void add_partial_symbol (struct partial_die_info *,
5047                                 struct dwarf2_cu *);
5048  
5049 -static int pdi_needs_namespace (enum dwarf_tag tag);
5050 +static gdb_byte *read_comp_unit_head (struct comp_unit_head *, gdb_byte *,
5051 +                                     bfd *);
5052 +
5053 +static int die_needs_namespace (struct die_info *, struct dwarf2_cu *);
5054  
5055  static void add_partial_namespace (struct partial_die_info *pdi,
5056                                    CORE_ADDR *lowpc, CORE_ADDR *highpc,
5057 @@ -825,6 +854,10 @@ static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
5058  
5059  static void psymtab_to_symtab_1 (struct partial_symtab *);
5060  
5061 +static void dwarf2_read_section_1 (struct objfile *objfile,
5062 +                                  struct obstack *obstack,
5063 +                                  struct dwarf2_section_info *info);
5064 +
5065  static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
5066  
5067  static void dwarf2_free_abbrev_table (void *);
5068 @@ -945,6 +978,11 @@ static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
5069  
5070  static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
5071  
5072 +static char *physname_prefix (struct die_info *die, struct dwarf2_cu *);
5073 +
5074 +static void physname_prefix_1 (struct ui_file *, struct die_info *,
5075 +                              struct dwarf2_cu *);
5076 +
5077  static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
5078  
5079  static char *typename_concat (struct obstack *,
5080 @@ -964,7 +1002,8 @@ static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
5081                                struct dwarf2_cu *, struct partial_symtab *);
5082  
5083  static int dwarf2_get_pc_bounds (struct die_info *,
5084 -                                CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
5085 +                                CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
5086 +                                struct partial_symtab *pst);
5087  
5088  static void get_scope_pc_bounds (struct die_info *,
5089                                  CORE_ADDR *, CORE_ADDR *,
5090 @@ -988,17 +1027,25 @@ static void dwarf2_attach_fn_fields_to_type (struct field_info *,
5091  
5092  static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
5093  
5094 -static const char *determine_class_name (struct die_info *die,
5095 -                                        struct dwarf2_cu *cu);
5096 -
5097  static void read_common_block (struct die_info *, struct dwarf2_cu *);
5098  
5099  static void read_namespace (struct die_info *die, struct dwarf2_cu *);
5100  
5101 +static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
5102 +
5103  static void read_module (struct die_info *die, struct dwarf2_cu *cu);
5104  
5105  static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
5106  
5107 +static struct type *read_module_type (struct die_info *die,
5108 +                                     struct dwarf2_cu *cu);
5109 +
5110 +static void read_fortran_imported_module (struct die_info *die,
5111 +                                         struct dwarf2_cu *cu);
5112 +
5113 +static void read_fortran_imported_declaration (struct die_info *die,
5114 +                                              struct dwarf2_cu *cu);
5115 +
5116  static const char *namespace_name (struct die_info *die,
5117                                    int *is_anonymous, struct dwarf2_cu *);
5118  
5119 @@ -1032,7 +1079,10 @@ static gdb_byte *read_full_die (const struct die_reader_specs *reader,
5120  
5121  static void process_die (struct die_info *, struct dwarf2_cu *);
5122  
5123 -static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
5124 +static char *dwarf2_physname (struct die_info *, struct dwarf2_cu *);
5125 +
5126 +static char *fortran_module_linkage_name (struct die_info *die,
5127 +                                         struct dwarf2_cu *cu);
5128  
5129  static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
5130                                        struct obstack *);
5131 @@ -1076,7 +1126,7 @@ static int is_ref_attr (struct attribute *);
5132  
5133  static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
5134  
5135 -static int dwarf2_get_attr_constant_value (struct attribute *, int);
5136 +static CORE_ADDR dwarf2_get_attr_constant_value (struct attribute *, CORE_ADDR);
5137  
5138  static struct die_info *follow_die_ref_or_sig (struct die_info *,
5139                                                struct attribute *,
5140 @@ -1148,6 +1198,9 @@ static void age_cached_comp_units (void);
5141  
5142  static void free_one_cached_comp_unit (void *);
5143  
5144 +static void fetch_die_type_attrs (struct die_info *die, struct type *type,
5145 +                                 struct dwarf2_cu *cu);
5146 +
5147  static struct type *set_die_type (struct die_info *, struct type *,
5148                                   struct dwarf2_cu *);
5149  
5150 @@ -1167,22 +1220,31 @@ static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
5151  
5152  static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
5153  
5154 +static void destroy_section (struct dwarf2_section_info *info);
5155 +
5156 +static struct dwarf2_locexpr_baton *dwarf2_attr_to_locexpr_baton
5157 +  (struct attribute *attr, struct dwarf2_cu *cu);
5158 +
5159  /* Try to locate the sections we need for DWARF 2 debugging
5160     information and return true if we have enough to do something.  */
5161  
5162  int
5163  dwarf2_has_info (struct objfile *objfile)
5164  {
5165 -  struct dwarf2_per_objfile *data;
5166 -
5167 -  /* Initialize per-objfile state.  */
5168 -  data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
5169 -  memset (data, 0, sizeof (*data));
5170 -  set_objfile_data (objfile, dwarf2_objfile_data_key, data);
5171 -  dwarf2_per_objfile = data;
5172 +  dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
5173 +  if (!dwarf2_per_objfile)
5174 +    {
5175 +      /* Initialize per-objfile state.  */
5176 +      struct dwarf2_per_objfile *data
5177 +       = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
5178 +      memset (data, 0, sizeof (*data));
5179 +      set_objfile_data (objfile, dwarf2_objfile_data_key, data);
5180 +      dwarf2_per_objfile = data;
5181  
5182 -  bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
5183 -  return (data->info.asection != NULL && data->abbrev.asection != NULL);
5184 +      bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
5185 +    }
5186 +  return (dwarf2_per_objfile->info.asection != NULL
5187 +         && dwarf2_per_objfile->abbrev.asection != NULL);
5188  }
5189  
5190  /* When loading sections, we can either look for ".<name>", or for
5191 @@ -1275,10 +1337,13 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
5192  }
5193  
5194  /* Decompress a section that was compressed using zlib.  Store the
5195 -   decompressed buffer, and its size, in OUTBUF and OUTSIZE.  */
5196 +   decompressed buffer, and its size, in OUTBUF and OUTSIZE.  The
5197 +   result is allocated on OBSTACK; if OBSTACK is NULL, xmalloc is
5198 +   used.  */
5199  
5200  static void
5201 -zlib_decompress_section (struct objfile *objfile, asection *sectp,
5202 +zlib_decompress_section (struct objfile *objfile, struct obstack *obstack,
5203 +                        asection *sectp,
5204                           gdb_byte **outbuf, bfd_size_type *outsize)
5205  {
5206    bfd *abfd = objfile->obfd;
5207 @@ -1295,6 +1360,7 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
5208    z_stream strm;
5209    int rc;
5210    int header_size = 12;
5211 +  struct cleanup *old = NULL;
5212  
5213    if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
5214        || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
5215 @@ -1324,8 +1390,13 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
5216    strm.avail_in = compressed_size - header_size;
5217    strm.next_in = (Bytef*) compressed_buffer + header_size;
5218    strm.avail_out = uncompressed_size;
5219 -  uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
5220 -                                       uncompressed_size);
5221 +  if (obstack)
5222 +    uncompressed_buffer = obstack_alloc (obstack, uncompressed_size);
5223 +  else
5224 +    {
5225 +      uncompressed_buffer = xmalloc (uncompressed_size);
5226 +      old = make_cleanup (xfree, uncompressed_buffer);
5227 +    }
5228    rc = inflateInit (&strm);
5229    while (strm.avail_in > 0)
5230      {
5231 @@ -1346,26 +1417,176 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
5232      error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5233             bfd_get_filename (abfd), rc);
5234  
5235 +  if (old)
5236 +    discard_cleanups (old);
5237    do_cleanups (cleanup);
5238    *outbuf = uncompressed_buffer;
5239    *outsize = uncompressed_size;
5240  #endif
5241  }
5242  
5243 -/* Read the contents of the section SECTP from object file specified by
5244 -   OBJFILE, store info about the section into INFO.
5245 -   If the section is compressed, uncompress it before returning.  */
5246 +/* A cleanup that calls destroy_section.  */
5247  
5248  static void
5249 -dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5250 +destroy_section_cleanup (void *arg)
5251 +{
5252 +  destroy_section (arg);
5253 +}
5254 +
5255 +/* Read the .debug_aranges section and construct an address map.  */
5256 +
5257 +void
5258 +dwarf2_create_quick_addrmap (struct objfile *objfile)
5259 +{
5260 +  char *aranges_buffer, *aranges_ptr;
5261 +  bfd *abfd = objfile->obfd;
5262 +  CORE_ADDR baseaddr;
5263 +  struct cleanup *old;
5264 +  struct obstack temp_obstack;
5265 +  struct addrmap *mutable_map;
5266 +
5267 +  if (!dwarf2_per_objfile->aranges.asection)
5268 +    return;
5269 +
5270 +  baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5271 +
5272 +  dwarf2_read_section_1 (objfile, NULL, &dwarf2_per_objfile->aranges);
5273 +  aranges_buffer = dwarf2_per_objfile->aranges.buffer;
5274 +  aranges_ptr = aranges_buffer;
5275 +  old = make_cleanup (destroy_section_cleanup, &dwarf2_per_objfile->aranges);
5276 +
5277 +  obstack_init (&temp_obstack);
5278 +  make_cleanup_obstack_free (&temp_obstack);
5279 +  mutable_map = addrmap_create_mutable (&temp_obstack);
5280 +
5281 +  while ((aranges_ptr - aranges_buffer) < dwarf2_per_objfile->aranges.size)
5282 +    {
5283 +      struct comp_unit_head cu_header;
5284 +      unsigned int bytes_read, segment_size, delta;
5285 +      LONGEST info_offset;
5286 +      struct dwarf2_cu cu;
5287 +      char *end_ptr;
5288 +
5289 +      cu_header.initial_length_size = 0;
5290 +      end_ptr = aranges_ptr;
5291 +      aranges_ptr = read_comp_unit_head (&cu_header, aranges_ptr, abfd);
5292 +      end_ptr += cu_header.initial_length_size + cu_header.length;
5293 +
5294 +      /* Sanity check.  */
5295 +      if (end_ptr - aranges_ptr >= dwarf2_per_objfile->aranges.size)
5296 +       {
5297 +         do_cleanups (old);
5298 +         complaint (&symfile_complaints,
5299 +                    _("aranges entry runs off end of `.debug_aranges' section, ignored"));
5300 +         return;
5301 +       }
5302 +      if (cu_header.addr_size == 0)
5303 +       {
5304 +         do_cleanups (old);
5305 +         complaint (&symfile_complaints,
5306 +                    _("aranges entry has zero addr_size, ignored"));
5307 +         return;
5308 +       }
5309 +
5310 +      segment_size = read_1_byte (abfd, aranges_ptr);
5311 +      aranges_ptr += 1;
5312 +
5313 +      /* Align the pointer to twice the pointer size.  I didn't see
5314 +        this in the spec but it appears to be required.  */
5315 +      delta = (aranges_ptr - aranges_buffer) % (2 * cu_header.addr_size);
5316 +      delta = (2 * cu_header.addr_size - delta) % (2 * cu_header.addr_size);
5317 +      aranges_ptr += delta;
5318 +
5319 +      memset (&cu, 0, sizeof (cu));
5320 +      cu.header.addr_size = cu_header.addr_size;
5321 +
5322 +      while (1)
5323 +       {
5324 +         CORE_ADDR address, length;
5325 +
5326 +         address = read_address (abfd, aranges_ptr, &cu, &bytes_read);
5327 +         aranges_ptr += bytes_read;
5328 +
5329 +         length = read_address (abfd, aranges_ptr, &cu, &bytes_read);
5330 +         aranges_ptr += bytes_read;
5331 +
5332 +         if (address == 0 && length == 0)
5333 +           break;
5334 +
5335 +         if (length == 0)
5336 +           {
5337 +             do_cleanups (old);
5338 +             complaint (&symfile_complaints,
5339 +                        _("aranges entry has zero length, ignored"));
5340 +             return;
5341 +           }
5342 +
5343 +         address += baseaddr;
5344 +
5345 +         addrmap_set_empty (mutable_map, address, address + length - 1,
5346 +                            objfile);
5347 +       }
5348 +
5349 +      /* Some older versions of GCC incorrectly started the arange
5350 +        with a (0,0) pair.  If we encounter any oddity while reading
5351 +        the section, just abandon the attempt; falling back to the
5352 +        slower code is always safe.  */
5353 +      if (aranges_ptr != end_ptr)
5354 +       {
5355 +         do_cleanups (old);
5356 +         complaint (&symfile_complaints,
5357 +                    _("aranges entry ends early, ignored"));
5358 +         return;
5359 +       }
5360 +    }
5361 +
5362 +  objfile->quick_addrmap = addrmap_create_fixed (mutable_map,
5363 +                                                &objfile->objfile_obstack);
5364 +  do_cleanups (old);
5365 +}
5366 +
5367 +/* Free a section buffer allocated with xmalloc.  */
5368 +
5369 +static void
5370 +xfree_section_buffer (struct dwarf2_section_info *info)
5371 +{
5372 +  xfree (info->buffer);
5373 +}
5374 +
5375 +/* If section described by INFO was mmapped, munmap it now.  */
5376 +
5377 +static void
5378 +munmap_section_buffer (struct dwarf2_section_info *info)
5379 +{
5380 +#ifdef HAVE_MMAP
5381 +  intptr_t begin = (intptr_t) info->buffer;
5382 +  intptr_t map_begin = begin & ~(pagesize - 1);
5383 +  size_t map_length = info->size + begin - map_begin;
5384 +  gdb_assert (munmap ((void *) map_begin, map_length) == 0);
5385 +#else
5386 +  /* Without HAVE_MMAP, we should never be here to begin with.  */
5387 +  gdb_assert (0);
5388 +#endif
5389 +}
5390 +
5391 +/* Read the contents of the section at OFFSET and of size SIZE from
5392 +   the object file specified by OBJFILE into OBSTACK and store it into
5393 +   INFO.  If OBSTACK is NULL, xmalloc is used instead.  If the section
5394 +   is compressed, uncompress it before returning.  */
5395 +
5396 +static void
5397 +dwarf2_read_section_1 (struct objfile *objfile,
5398 +                      struct obstack *obstack,
5399 +                      struct dwarf2_section_info *info)
5400  {
5401    bfd *abfd = objfile->obfd;
5402    asection *sectp = info->asection;
5403    gdb_byte *buf, *retbuf;
5404    unsigned char header[4];
5405 +  struct cleanup *old = NULL;
5406  
5407    info->buffer = NULL;
5408 -  info->was_mmapped = 0;
5409 +  info->destructor = 0;
5410  
5411    if (info->asection == NULL || info->size == 0)
5412      return;
5413 @@ -1378,7 +1599,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5414        /* Upon decompression, update the buffer and its size.  */
5415        if (strncmp (header, "ZLIB", sizeof (header)) == 0)
5416          {
5417 -          zlib_decompress_section (objfile, sectp, &info->buffer,
5418 +          zlib_decompress_section (objfile, obstack, sectp, &info->buffer,
5419                                    &info->size);
5420            return;
5421          }
5422 @@ -1401,7 +1622,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5423  
5424        if (retbuf != MAP_FAILED)
5425         {
5426 -         info->was_mmapped = 1;
5427 +         info->destructor = munmap_section_buffer;
5428           info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
5429           return;
5430         }
5431 @@ -1409,8 +1630,15 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5432  #endif
5433  
5434    /* If we get here, we are a normal, not-compressed section.  */
5435 -  info->buffer = buf
5436 -    = obstack_alloc (&objfile->objfile_obstack, info->size);
5437 +  if (obstack)
5438 +    buf = obstack_alloc (obstack, info->size);
5439 +  else
5440 +    {
5441 +      buf = xmalloc (info->size);
5442 +      old = make_cleanup (xfree, buf);
5443 +      info->destructor = xfree_section_buffer;
5444 +    }
5445 +  info->buffer = buf;
5446  
5447    /* When debugging .o files, we may need to apply relocations; see
5448       http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5449 @@ -1419,6 +1647,8 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5450    retbuf = symfile_relocate_debug_section (abfd, sectp, buf);
5451    if (retbuf != NULL)
5452      {
5453 +      if (old)
5454 +       discard_cleanups (old);
5455        info->buffer = retbuf;
5456        return;
5457      }
5458 @@ -1427,6 +1657,19 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5459        || bfd_bread (buf, info->size, abfd) != info->size)
5460      error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5461            bfd_get_filename (abfd));
5462 +
5463 +  if (old)
5464 +    discard_cleanups (old);
5465 +}
5466 +
5467 +/* Read the contents of the section SECTP from object file specified by
5468 +   OBJFILE, store info about the section into INFO.
5469 +   If the section is compressed, uncompress it before returning.  */
5470 +
5471 +static void
5472 +dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5473 +{
5474 +  dwarf2_read_section_1 (objfile, &objfile->objfile_obstack, info);
5475  }
5476  
5477  /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
5478 @@ -1810,6 +2053,37 @@ lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
5479    return entry;
5480  }
5481  
5482 +/* Find the base address of the compilation unit for range lists and
5483 +   location lists.  It will normally be specified by DW_AT_low_pc.
5484 +   In DWARF-3 draft 4, the base address could be overridden by
5485 +   DW_AT_entry_pc.  It's been removed, but GCC still uses this for
5486 +   compilation units with discontinuous ranges.  */
5487 +
5488 +static void
5489 +dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
5490 +{
5491 +  struct attribute *attr;
5492 +
5493 +  cu->base_known = 0;
5494 +  cu->base_address = 0;
5495 +
5496 +  attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
5497 +  if (attr)
5498 +    {
5499 +      cu->base_address = DW_ADDR (attr);
5500 +      cu->base_known = 1;
5501 +    }
5502 +  else
5503 +    {
5504 +      attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5505 +      if (attr)
5506 +       {
5507 +         cu->base_address = DW_ADDR (attr);
5508 +         cu->base_known = 1;
5509 +       }
5510 +    }
5511 +}
5512 +
5513  /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
5514     to combine the common parts.
5515     Process a compilation unit for a psymtab.
5516 @@ -2359,7 +2633,7 @@ partial_die_parent_scope (struct partial_die_info *pdi,
5517          ignoring them.  */
5518        complaint (&symfile_complaints,
5519                  _("unhandled containing DIE tag %d for DIE at %d"),
5520 -                parent->tag, pdi->offset);
5521 +                parent->tag, real_pdi->offset);
5522        parent->scope = grandparent_scope;
5523      }
5524  
5525 @@ -2374,12 +2648,22 @@ partial_die_full_name (struct partial_die_info *pdi,
5526                        struct dwarf2_cu *cu)
5527  {
5528    char *parent_scope;
5529 +  struct partial_die_info *real_pdi;
5530  
5531 -  parent_scope = partial_die_parent_scope (pdi, cu);
5532 -  if (parent_scope == NULL)
5533 -    return NULL;
5534 -  else
5535 +  /* We need to look at our parent DIE; if we have a DW_AT_specification,
5536 +     then this means the parent of the specification DIE.
5537 +     partial_die_parent_scope does this loop also, but we do it here
5538 +     since we need to examine real_pdi->parent ourselves.  */
5539 +
5540 +  real_pdi = pdi;
5541 +  while (real_pdi->has_specification)
5542 +    real_pdi = find_partial_die (real_pdi->spec_offset, cu);
5543 +
5544 +  parent_scope = partial_die_parent_scope (real_pdi, cu);
5545 +  if (parent_scope != NULL)
5546      return typename_concat (NULL, parent_scope, pdi->name, cu);
5547 +
5548 +  return NULL;
5549  }
5550  
5551  static void
5552 @@ -2395,12 +2679,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
5553  
5554    baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5555  
5556 -  if (pdi_needs_namespace (pdi->tag))
5557 -    {
5558 -      actual_name = partial_die_full_name (pdi, cu);
5559 -      if (actual_name)
5560 -       built_actual_name = 1;
5561 -    }
5562 +  actual_name = partial_die_full_name (pdi, cu);
5563 +  if (actual_name)
5564 +    built_actual_name = 1;
5565  
5566    if (actual_name == NULL)
5567      actual_name = pdi->name;
5568 @@ -2491,6 +2772,12 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
5569                            &objfile->global_psymbols,
5570                            0, (CORE_ADDR) 0, cu->language, objfile);
5571        break;
5572 +    case DW_TAG_module:
5573 +      add_psymbol_to_list (actual_name, strlen (actual_name),
5574 +                          MODULE_DOMAIN, LOC_STATIC,
5575 +                          &objfile->global_psymbols,
5576 +                          0, (CORE_ADDR) 0, cu->language, objfile);
5577 +      break;
5578      case DW_TAG_class_type:
5579      case DW_TAG_interface_type:
5580      case DW_TAG_structure_type:
5581 @@ -2532,34 +2819,17 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
5582        break;
5583      }
5584  
5585 -  /* Check to see if we should scan the name for possible namespace
5586 -     info.  Only do this if this is C++, if we don't have namespace
5587 -     debugging info in the file, if the psym is of an appropriate type
5588 -     (otherwise we'll have psym == NULL), and if we actually had a
5589 -     mangled name to begin with.  */
5590 -
5591 -  /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
5592 -     cases which do not set PSYM above?  */
5593 -
5594 -  if (cu->language == language_cplus
5595 -      && cu->has_namespace_info == 0
5596 -      && psym != NULL
5597 -      && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
5598 -    cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
5599 -                                        objfile);
5600 -
5601    if (built_actual_name)
5602      xfree (actual_name);
5603  }
5604  
5605 -/* Determine whether a die of type TAG living in a C++ class or
5606 -   namespace needs to have the name of the scope prepended to the
5607 -   name listed in the die.  */
5608 +/* Determine whether DIE needs to have the name of the scope prepended
5609 +   to the name listed in the die.  */
5610  
5611  static int
5612 -pdi_needs_namespace (enum dwarf_tag tag)
5613 +die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
5614  {
5615 -  switch (tag)
5616 +  switch (die->tag)
5617      {
5618      case DW_TAG_namespace:
5619      case DW_TAG_typedef:
5620 @@ -2569,7 +2839,23 @@ pdi_needs_namespace (enum dwarf_tag tag)
5621      case DW_TAG_union_type:
5622      case DW_TAG_enumeration_type:
5623      case DW_TAG_enumerator:
5624 +    case DW_TAG_subprogram:
5625 +    case DW_TAG_member:
5626        return 1;
5627 +
5628 +    case DW_TAG_variable:
5629 +      {
5630 +       struct attribute *attr;
5631 +       attr = dwarf2_attr (die, DW_AT_specification, cu);
5632 +       if (attr)
5633 +         return 1;
5634 +       attr = dwarf2_attr (die, DW_AT_external, cu);
5635 +       if (attr == NULL && die->parent->tag != DW_TAG_namespace)
5636 +         return 0;
5637 +       return 1;
5638 +      }
5639 +      break;
5640 +
5641      default:
5642        return 0;
5643      }
5644 @@ -2602,12 +2888,12 @@ static void
5645  add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
5646                     CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
5647  {
5648 -  /* Now scan partial symbols in that module.
5649 +  /* Add a symbol for the module.  */
5650  
5651 -     FIXME: Support the separate Fortran module namespaces.  */
5652 +  add_partial_symbol (pdi, cu);
5653  
5654 -  if (pdi->has_children)
5655 -    scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
5656 +  /* Partial symbols in that module are not scanned as they are never globally
5657 +     visible.  They get imported to the specific scopes on the full read.  */
5658  }
5659  
5660  /* Read a partial die corresponding to a subprogram and create a partial
5661 @@ -2698,27 +2984,6 @@ guess_structure_name (struct partial_die_info *struct_pdi,
5662  
5663        if (real_pdi->die_parent != NULL)
5664         return;
5665 -
5666 -      while (child_pdi != NULL)
5667 -       {
5668 -         if (child_pdi->tag == DW_TAG_subprogram)
5669 -           {
5670 -             char *actual_class_name
5671 -               = language_class_name_from_physname (cu->language_defn,
5672 -                                                    child_pdi->name);
5673 -             if (actual_class_name != NULL)
5674 -               {
5675 -                 struct_pdi->name
5676 -                   = obsavestring (actual_class_name,
5677 -                                   strlen (actual_class_name),
5678 -                                   &cu->comp_unit_obstack);
5679 -                 xfree (actual_class_name);
5680 -               }
5681 -             break;
5682 -           }
5683 -
5684 -         child_pdi = child_pdi->die_sibling;
5685 -       }
5686      }
5687  }
5688  
5689 @@ -3295,6 +3560,14 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
5690      case DW_TAG_imported_declaration:
5691      case DW_TAG_imported_module:
5692        processing_has_namespace_info = 1;
5693 +      if (cu->language == language_fortran)
5694 +       {
5695 +         if (die->tag == DW_TAG_imported_declaration)
5696 +           read_fortran_imported_declaration (die, cu);
5697 +         else
5698 +           read_fortran_imported_module (die, cu);
5699 +         break;
5700 +       }
5701        if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
5702                                  || cu->language != language_fortran))
5703         complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
5704 @@ -3310,41 +3583,68 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
5705  /* Return the fully qualified name of DIE, based on its DW_AT_name.
5706     If scope qualifiers are appropriate they will be added.  The result
5707     will be allocated on the objfile_obstack, or NULL if the DIE does
5708 -   not have a name.  */
5709 +   not have a name.
5710 +
5711 +   The output string will be canonicalized (if C++/Java). */
5712  
5713  static const char *
5714  dwarf2_full_name (struct die_info *die, struct dwarf2_cu *cu)
5715  {
5716 -  struct attribute *attr;
5717 -  char *prefix, *name;
5718 -  struct ui_file *buf = NULL;
5719 +  char *name;
5720  
5721    name = dwarf2_name (die, cu);
5722 -  if (!name)
5723 -    return NULL;
5724  
5725    /* These are the only languages we know how to qualify names in.  */
5726 -  if (cu->language != language_cplus
5727 -      && cu->language != language_java)
5728 -    return name;
5729 +  if (name != NULL
5730 +      && (cu->language == language_cplus || cu->language == language_java))
5731 +    {
5732 +      if (die_needs_namespace (die, cu))
5733 +       {
5734 +         long length;
5735 +         char *prefix;
5736 +         struct ui_file *buf;
5737  
5738 -  /* If no prefix is necessary for this type of DIE, return the
5739 -     unqualified name.  The other three tags listed could be handled
5740 -     in pdi_needs_namespace, but that requires broader changes.  */
5741 -  if (!pdi_needs_namespace (die->tag)
5742 -      && die->tag != DW_TAG_subprogram
5743 -      && die->tag != DW_TAG_variable
5744 -      && die->tag != DW_TAG_member)
5745 -    return name;
5746 +         buf = mem_fileopen ();
5747 +         prefix = determine_prefix (die, cu);
5748 +         if (*prefix != '\0')
5749 +           {
5750 +             char *prefixed_name = typename_concat (NULL, prefix, name, cu);
5751 +             fputs_unfiltered (prefixed_name, buf);
5752 +             xfree (prefixed_name);
5753 +           }
5754 +         else
5755 +           fputs_unfiltered (name, buf);
5756  
5757 -  prefix = determine_prefix (die, cu);
5758 -  if (*prefix != '\0')
5759 -    name = typename_concat (&cu->objfile->objfile_obstack, prefix,
5760 -                           name, cu);
5761 +         name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
5762 +                                      &length);
5763 +         ui_file_delete (buf);
5764 +
5765 +         if (cu->language == language_cplus)
5766 +           {
5767 +             char *cname
5768 +               = dwarf2_canonicalize_name (name, cu,
5769 +                                           &cu->objfile->objfile_obstack);
5770 +             if (cname != NULL)
5771 +               name = cname;
5772 +           }
5773 +       }
5774 +    }
5775  
5776    return name;
5777  }
5778  
5779 +/* read the given die's decl_line number. Return -1 if in case of an error */
5780 +static const int dwarf2_read_decl_line (struct die_info *die, struct dwarf2_cu *cu){
5781 +  struct attribute *line_attr;
5782 +
5783 +  line_attr = dwarf2_attr (die, DW_AT_decl_line, cu);
5784 +  if (line_attr){
5785 +    return  DW_UNSND (line_attr);
5786 +  }
5787 +
5788 +  return -1;
5789 +}
5790 +
5791  /* Read the import statement specified by the given die and record it.  */
5792  
5793  static void
5794 @@ -3354,9 +3654,15 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5795    struct die_info *imported_die;
5796    const char *imported_name;
5797    const char *imported_name_prefix;
5798 -  const char *import_prefix;
5799    char *canonical_name;
5800 -
5801 +  const char *import_alias;
5802 +  const char *imported_declaration = "";
5803 +  const char *import_prefix;
5804 +  
5805 +  int line_number = -1;
5806 +  
5807 +  int is_anonymous = 0;
5808 +  
5809    import_attr = dwarf2_attr (die, DW_AT_import, cu);
5810    if (import_attr == NULL)
5811      {
5812 @@ -3404,17 +3710,27 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5813        return;
5814      }
5815  
5816 -  /* FIXME: dwarf2_name (die); for the local name after import.  */
5817 -
5818 -  /* Figure out where the statement is being imported to.  */
5819 +  /* Figure out the local name after import.  */
5820 +  import_alias = dwarf2_name(die, cu);
5821 +  if(import_alias == NULL){
5822 +    import_alias = "";
5823 +  }
5824 +  
5825 +  /* Determine the line number at which the import was made */
5826 +  line_number = dwarf2_read_decl_line(die, cu);
5827 +  
5828 +  /* Figure out where the statement is being imported to */
5829    import_prefix = determine_prefix (die, cu);
5830  
5831    /* Figure out what the scope of the imported die is and prepend it
5832       to the name of the imported die.  */
5833    imported_name_prefix = determine_prefix (imported_die, cu);
5834 -
5835 -  if (strlen (imported_name_prefix) > 0)
5836 -    {
5837 +  
5838 +  if(imported_die->tag != DW_TAG_namespace){
5839 +    imported_declaration = imported_name;
5840 +    canonical_name = (char*)imported_name_prefix;
5841 +  }else{
5842 +    if(strlen (imported_name_prefix) > 0){
5843        canonical_name = alloca (strlen (imported_name_prefix) + 2 + strlen (imported_name) + 1);
5844        strcpy (canonical_name, imported_name_prefix);
5845        strcat (canonical_name, "::");
5846 @@ -3425,8 +3741,14 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5847        canonical_name = alloca (strlen (imported_name) + 1);
5848        strcpy (canonical_name, imported_name);
5849      }
5850 -
5851 -  using_directives = cp_add_using (import_prefix,canonical_name, using_directives);
5852 +  }
5853 +  
5854 +  using_directives = cp_add_using (import_prefix,
5855 +                                   canonical_name,
5856 +                                   import_alias,
5857 +                                   imported_declaration,
5858 +                                   line_number,
5859 +                                   using_directives);
5860  }
5861  
5862  static void
5863 @@ -3695,6 +4017,14 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5864    struct attribute *attr;
5865  
5866    attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5867 +  
5868 +  /* GCC 4.3 incorrectly uses DW_AT_specification to indicate die inheritence
5869 +     in the case of import statements. The following is to accommodate 
5870 +     that.  */
5871 +  if(!attr){
5872 +    attr = dwarf2_attr (die, DW_AT_specification, cu);
5873 +  }
5874 +  
5875    if (!attr)
5876      return;
5877  
5878 @@ -3793,6 +4123,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5879    char *name;
5880    CORE_ADDR baseaddr;
5881    struct block *block;
5882 +  unsigned die_children = 0;
5883    int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5884  
5885    if (inlined_func)
5886 @@ -3811,13 +4142,23 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5887  
5888    baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5889  
5890 -  name = dwarf2_linkage_name (die, cu);
5891 +  name = dwarf2_name (die, cu);
5892  
5893    /* Ignore functions with missing or empty names and functions with
5894       missing or invalid low and high pc attributes.  */
5895 -  if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
5896 +  if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)){
5897 +    /* explore abstract origins if present. They might contain useful information
5898 +     such as import statements. */
5899 +    child_die = die->child;
5900 +    while (child_die && child_die->tag)
5901 +      {
5902 +       child_die = sibling_die (child_die);
5903 +       die_children++;
5904 +      }
5905 +    inherit_abstract_dies(die, cu);
5906      return;
5907 -
5908 +  }
5909 +  
5910    lowpc += baseaddr;
5911    highpc += baseaddr;
5912  
5913 @@ -3844,14 +4185,19 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5914  
5915    cu->list_in_scope = &local_symbols;
5916  
5917 -  if (die->child != NULL)
5918 +  switch (cu->language)
5919      {
5920 -      child_die = die->child;
5921 -      while (child_die && child_die->tag)
5922 -       {
5923 -         process_die (child_die, cu);
5924 -         child_die = sibling_die (child_die);
5925 -       }
5926 +    case language_fortran:
5927 +      cu->language_specific.fortran.use = NULL;
5928 +      break;
5929 +    }
5930 +
5931 +  child_die = die->child;
5932 +  while (child_die && child_die->tag)
5933 +    {
5934 +      process_die (child_die, cu);
5935 +      child_die = sibling_die (child_die);
5936 +      die_children++;
5937      }
5938  
5939    inherit_abstract_dies (die, cu);
5940 @@ -3867,6 +4213,13 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5941                         determine_prefix (die, cu),
5942                         processing_has_namespace_info);
5943  
5944 +  switch (cu->language)
5945 +    {
5946 +    case language_fortran:
5947 +      BLOCK_FORTRAN_USE (block) = cu->language_specific.fortran.use;
5948 +      break;
5949 +    }
5950 +
5951    /* If we have address ranges, record them.  */
5952    dwarf2_record_block_ranges (die, block, baseaddr, cu);
5953    
5954 @@ -3903,7 +4256,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5955       as multiple lexical blocks?  Handling children in a sane way would
5956       be nasty.  Might be easier to properly extend generic blocks to 
5957       describe ranges.  */
5958 -  if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
5959 +  if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5960      return;
5961    lowpc += baseaddr;
5962    highpc += baseaddr;
5963 @@ -3920,7 +4273,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5964      }
5965    new = pop_context ();
5966  
5967 -  if (local_symbols != NULL)
5968 +  if (local_symbols != NULL || using_directives != NULL)
5969      {
5970        struct block *block
5971          = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
5972 @@ -4075,7 +4428,8 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
5973     discontinuous, i.e. derived from DW_AT_ranges information.  */
5974  static int
5975  dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
5976 -                     CORE_ADDR *highpc, struct dwarf2_cu *cu)
5977 +                     CORE_ADDR *highpc, struct dwarf2_cu *cu,
5978 +                     struct partial_symtab *pst)
5979  {
5980    struct attribute *attr;
5981    CORE_ADDR low = 0;
5982 @@ -4103,7 +4457,7 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
5983         {
5984           /* Value of the DW_AT_ranges attribute is the offset in the
5985              .debug_ranges section.  */
5986 -         if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, NULL))
5987 +         if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
5988             return 0;
5989           /* Found discontinuous range of addresses.  */
5990           ret = -1;
5991 @@ -4142,7 +4496,7 @@ dwarf2_get_subprogram_pc_bounds (struct die_info *die,
5992    CORE_ADDR low, high;
5993    struct die_info *child = die->child;
5994  
5995 -  if (dwarf2_get_pc_bounds (die, &low, &high, cu))
5996 +  if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
5997      {
5998        *lowpc = min (*lowpc, low);
5999        *highpc = max (*highpc, high);
6000 @@ -4179,7 +4533,7 @@ get_scope_pc_bounds (struct die_info *die,
6001    CORE_ADDR best_high = (CORE_ADDR) 0;
6002    CORE_ADDR current_low, current_high;
6003  
6004 -  if (dwarf2_get_pc_bounds (die, &current_low, &current_high, cu))
6005 +  if (dwarf2_get_pc_bounds (die, &current_low, &current_high, cu, NULL))
6006      {
6007        best_low = current_low;
6008        best_high = current_high;
6009 @@ -4474,7 +4828,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
6010         return;
6011  
6012        /* Get physical name.  */
6013 -      physname = dwarf2_linkage_name (die, cu);
6014 +      physname = dwarf2_physname (die, cu);
6015  
6016        /* The name is already allocated along with this objfile, so we don't
6017          need to duplicate it for the type.  */
6018 @@ -4617,7 +4971,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6019      return;
6020  
6021    /* Get the mangled name.  */
6022 -  physname = dwarf2_linkage_name (die, cu);
6023 +  physname = dwarf2_physname (die, cu);
6024  
6025    /* Look up member function name in fieldlist.  */
6026    for (i = 0; i < fip->nfnfields; i++)
6027 @@ -4661,7 +5015,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6028    /* The name is already allocated along with this objfile, so we don't
6029       need to duplicate it for the type.  */
6030    fnp->physname = physname ? physname : "";
6031 -  fnp->type = alloc_type (objfile);
6032 +  fnp->type = alloc_type (objfile, NULL);
6033    this_type = read_type_die (die, cu);
6034    if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
6035      {
6036 @@ -4721,18 +5075,18 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6037      {
6038        /* Support the .debug_loc offsets */
6039        if (attr_form_is_block (attr))
6040 -        {
6041 -          fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6042 -        }
6043 +       {
6044 +         fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6045 +       }
6046        else if (attr_form_is_section_offset (attr))
6047 -        {
6048 +       {
6049           dwarf2_complex_location_expr_complaint ();
6050 -        }
6051 +       }
6052        else
6053 -        {
6054 +       {
6055           dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6056                                                  fieldname);
6057 -        }
6058 +       }
6059     }
6060  }
6061  
6062 @@ -4845,7 +5199,7 @@ quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu)
6063      return NULL;
6064  
6065    domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
6066 -  type = alloc_type (objfile);
6067 +  type = alloc_type (objfile, NULL);
6068    smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type),
6069                         TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
6070                         TYPE_VARARGS (pfn_type));
6071 @@ -4898,7 +5252,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
6072        return set_die_type (die, type, cu);
6073      }
6074  
6075 -  type = alloc_type (objfile);
6076 +  type = alloc_type (objfile, NULL);
6077    INIT_CPLUS_SPECIFIC (type);
6078  
6079    name = dwarf2_name (die, cu);
6080 @@ -4907,14 +5261,18 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
6081        if (cu->language == language_cplus
6082           || cu->language == language_java)
6083         {
6084 -         const char *new_prefix = determine_class_name (die, cu);
6085 -         TYPE_TAG_NAME (type) = (char *) new_prefix;
6086 +         TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (die, cu);
6087 +         if (die->tag == DW_TAG_structure_type
6088 +             || die->tag == DW_TAG_class_type)
6089 +           TYPE_NAME (type) = TYPE_TAG_NAME (type);
6090         }
6091        else
6092         {
6093           /* The name is already allocated along with this objfile, so
6094              we don't need to duplicate it for the type.  */
6095 -         TYPE_TAG_NAME (type) = name;
6096 +         TYPE_TAG_NAME (type) = (char *) name;
6097 +         if (die->tag == DW_TAG_class_type)
6098 +           TYPE_NAME (type) = TYPE_TAG_NAME (type);
6099         }
6100      }
6101  
6102 @@ -5124,7 +5482,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
6103        return set_die_type (die, type, cu);
6104      }
6105  
6106 -  type = alloc_type (objfile);
6107 +  type = alloc_type (objfile, NULL);
6108  
6109    TYPE_CODE (type) = TYPE_CODE_ENUM;
6110    name = dwarf2_full_name (die, cu);
6111 @@ -5152,51 +5510,6 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
6112    return set_die_type (die, type, cu);
6113  }
6114  
6115 -/* Determine the name of the type represented by DIE, which should be
6116 -   a named C++ or Java compound type.  Return the name in question,
6117 -   allocated on the objfile obstack.  */
6118 -
6119 -static const char *
6120 -determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
6121 -{
6122 -  const char *new_prefix = NULL;
6123 -
6124 -  /* If we don't have namespace debug info, guess the name by trying
6125 -     to demangle the names of members, just like we did in
6126 -     guess_structure_name.  */
6127 -  if (!processing_has_namespace_info)
6128 -    {
6129 -      struct die_info *child;
6130 -
6131 -      for (child = die->child;
6132 -          child != NULL && child->tag != 0;
6133 -          child = sibling_die (child))
6134 -       {
6135 -         if (child->tag == DW_TAG_subprogram)
6136 -           {
6137 -             char *phys_prefix
6138 -               = language_class_name_from_physname (cu->language_defn,
6139 -                                                    dwarf2_linkage_name
6140 -                                                    (child, cu));
6141 -
6142 -             if (phys_prefix != NULL)
6143 -               {
6144 -                 new_prefix
6145 -                   = obsavestring (phys_prefix, strlen (phys_prefix),
6146 -                                   &cu->objfile->objfile_obstack);
6147 -                 xfree (phys_prefix);
6148 -                 break;
6149 -               }
6150 -           }
6151 -       }
6152 -    }
6153 -
6154 -  if (new_prefix == NULL)
6155 -    new_prefix = dwarf2_full_name (die, cu);
6156 -
6157 -  return new_prefix;
6158 -}
6159 -
6160  /* Given a pointer to a die which begins an enumeration, process all
6161     the dies that define the members of the enumeration, and create the
6162     symbol for the enumeration type.
6163 @@ -5274,6 +5587,29 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
6164    new_symbol (die, this_type, cu);
6165  }
6166  
6167 +/* Create a new array dimension referencing its target type TYPE.
6168 +
6169 +   Multidimensional arrays are internally represented as a stack of
6170 +   singledimensional arrays being referenced by their TYPE_TARGET_TYPE.  */
6171 +
6172 +static struct type *
6173 +create_single_array_dimension (struct type *type, struct type *range_type,
6174 +                              struct die_info *die, struct dwarf2_cu *cu)
6175 +{
6176 +  type = create_array_type (NULL, type, range_type);
6177 +
6178 +  /* These generic type attributes need to be fetched by
6179 +     evaluate_subexp_standard <multi_f77_subscript>'s call of
6180 +     value_subscripted_rvalue only for the innermost array type.  */
6181 +  fetch_die_type_attrs (die, type, cu);
6182 +
6183 +  /* These generic type attributes are checked for allocated/associated
6184 +     validity while accessing FIELD_LOC_KIND_DWARF_BLOCK.  */
6185 +  fetch_die_type_attrs (die, range_type, cu);
6186 +
6187 +  return type;
6188 +}
6189 +
6190  /* Extract all information from a DW_TAG_array_type DIE and put it in
6191     the DIE's type field.  For now, this only handles one dimensional
6192     arrays.  */
6193 @@ -5287,7 +5623,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
6194    struct type *element_type, *range_type, *index_type;
6195    struct type **range_types = NULL;
6196    struct attribute *attr;
6197 -  int ndim = 0;
6198 +  int ndim = 0, i;
6199    struct cleanup *back_to;
6200    char *name;
6201  
6202 @@ -5334,16 +5670,11 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
6203    type = element_type;
6204  
6205    if (read_array_order (die, cu) == DW_ORD_col_major)
6206 -    {
6207 -      int i = 0;
6208 -      while (i < ndim)
6209 -       type = create_array_type (NULL, type, range_types[i++]);
6210 -    }
6211 -  else
6212 -    {
6213 -      while (ndim-- > 0)
6214 -       type = create_array_type (NULL, type, range_types[ndim]);
6215 -    }
6216 +    for (i = 0; i < ndim; i++)
6217 +      type = create_single_array_dimension (type, range_types[i], die, cu);
6218 +  else /* (read_array_order (die, cu) == DW_ORD_row_major) */
6219 +    for (i = ndim - 1; i >= 0; i--)
6220 +      type = create_single_array_dimension (type, range_types[i], die, cu);
6221  
6222    /* Understand Dwarf2 support for vector types (like they occur on
6223       the PowerPC w/ AltiVec).  Gcc just adds another attribute to the
6224 @@ -5410,12 +5741,14 @@ read_set_type (struct die_info *die, struct dwarf2_cu *cu)
6225    return set_die_type (die, set_type, cu);
6226  }
6227  
6228 -/* First cut: install each common block member as a global variable.  */
6229 +/* Create appropriate locally-scoped variables for all the DW_TAG_common_block
6230 +   entries.  Create also TYPE_CODE_STRUCT listing all such variables to be
6231 +   available for `info common'.  COMMON_BLOCK_DOMAIN is used to sepate the
6232 +   common blocks name namespace from regular variable names.  */
6233  
6234  static void
6235  read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6236  {
6237 -  struct die_info *child_die;
6238    struct attribute *attr;
6239    struct symbol *sym;
6240    CORE_ADDR base = (CORE_ADDR) 0;
6241 @@ -5425,25 +5758,55 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6242      {
6243        /* Support the .debug_loc offsets */
6244        if (attr_form_is_block (attr))
6245 -        {
6246 -          base = decode_locdesc (DW_BLOCK (attr), cu);
6247 -        }
6248 +       {
6249 +         base = decode_locdesc (DW_BLOCK (attr), cu);
6250 +       }
6251        else if (attr_form_is_section_offset (attr))
6252 -        {
6253 +       {
6254           dwarf2_complex_location_expr_complaint ();
6255 -        }
6256 +       }
6257        else
6258 -        {
6259 +       {
6260           dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6261                                                  "common block member");
6262 -        }
6263 +       }
6264      }
6265    if (die->child != NULL)
6266      {
6267 +      struct objfile *objfile = cu->objfile;
6268 +      struct die_info *child_die;
6269 +      struct type *type;
6270 +      struct field *field;
6271 +      char *name;
6272 +      struct symbol *sym;
6273 +
6274 +      type = alloc_type (objfile, NULL);
6275 +      TYPE_CODE (type) = TYPE_CODE_STRUCT;
6276 +      /* Artificial type to be used only by `info common'.  */
6277 +      TYPE_NAME (type) = "<common>";
6278 +
6279        child_die = die->child;
6280        while (child_die && child_die->tag)
6281         {
6282 +         TYPE_NFIELDS (type)++;
6283 +         child_die = sibling_die (child_die);
6284 +       }
6285 +
6286 +      TYPE_FIELDS (type) = obstack_alloc (&objfile->objfile_obstack,
6287 +                                         sizeof (*TYPE_FIELDS (type))
6288 +                                         * TYPE_NFIELDS (type));
6289 +      memset (TYPE_FIELDS (type), 0, sizeof (*TYPE_FIELDS (type))
6290 +                                    * TYPE_NFIELDS (type));
6291 +      
6292 +      field = TYPE_FIELDS (type);
6293 +      child_die = die->child;
6294 +      while (child_die && child_die->tag)
6295 +       {
6296 +         /* Create the symbol in the DW_TAG_common_block block in the current
6297 +            symbol scope.  */
6298           sym = new_symbol (child_die, NULL, cu);
6299 +
6300 +         /* Undocumented in DWARF3, when it can be present?  */
6301           attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
6302           if (attr)
6303             {
6304 @@ -5461,8 +5824,25 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6305               SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
6306               add_symbol_to_list (sym, &global_symbols);
6307             }
6308 +
6309 +         if (SYMBOL_CLASS (sym) == LOC_STATIC)
6310 +           SET_FIELD_PHYSADDR (*field, SYMBOL_VALUE_ADDRESS (sym));
6311 +         else
6312 +           SET_FIELD_PHYSNAME (*field, SYMBOL_LINKAGE_NAME (sym));
6313 +         FIELD_TYPE (*field) = SYMBOL_TYPE (sym);
6314 +         FIELD_NAME (*field) = SYMBOL_NATURAL_NAME (sym);
6315 +         field++;
6316           child_die = sibling_die (child_die);
6317         }
6318 +
6319 +      /* TYPE_LENGTH (type) is left 0 - it is only a virtual structure even
6320 +        with no consecutive address space.  */
6321 +
6322 +      sym = new_symbol (die, type, cu);
6323 +      /* SYMBOL_VALUE_ADDRESS never gets used as all its fields are static.  */
6324 +      SYMBOL_VALUE_ADDRESS (sym) = base;
6325 +
6326 +      set_die_type (die, type, cu);
6327      }
6328  }
6329  
6330 @@ -5530,7 +5910,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
6331        if (is_anonymous)
6332         {
6333           const char *previous_prefix = determine_prefix (die, cu);
6334 -         cp_add_using_directive (previous_prefix, TYPE_NAME (type));
6335 +         cp_add_using_directive (previous_prefix, TYPE_NAME (type), "", "", dwarf2_read_decl_line(die, cu));
6336         }
6337      }
6338  
6339 @@ -5546,20 +5926,155 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
6340      }
6341  }
6342  
6343 -/* Read a Fortran module.  */
6344 +/* Read a Fortran module as global symbol which can be later looked up by
6345 +   f_lookup_symbol_nonlocal.  */
6346  
6347  static void
6348  read_module (struct die_info *die, struct dwarf2_cu *cu)
6349  {
6350 -  struct die_info *child_die = die->child;
6351 +  struct type *type;
6352 +
6353 +  type = read_module_type (die, cu);
6354 +
6355 +  if (type)
6356 +    new_symbol (die, type, cu);
6357 +}
6358 +
6359 +/* Read a Fortran module as type.
6360 +
6361 +   Modules present only as declarations - being used only for DW_AT_import of
6362 +   DW_TAG_imported_module - are ignored here.  They are read in only in form of
6363 +   the module name by read_fortran_imported_module.  */
6364 +
6365 +static struct type *
6366 +read_module_type (struct die_info *die, struct dwarf2_cu *cu)
6367 +{
6368 +  struct objfile *objfile = cu->objfile;
6369 +  struct die_info *child_die;
6370 +  struct type *type;
6371 +  char *module_name;
6372 +  struct context_stack *new;
6373 +  struct pending *save_file_symbols;
6374 +  struct pending *save_global_symbols;
6375 +  struct pending **save_list_in_scope;
6376 +
6377 +  if (die_is_declaration (die, cu))
6378 +    return NULL;
6379  
6380 -  /* FIXME: Support the separate Fortran module namespaces.  */
6381 +  module_name = dwarf2_name (die, cu);
6382 +  if (!module_name)
6383 +    complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"),
6384 +               die->offset);
6385 +  type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
6386  
6387 +  /* Create a context for reading the module variables.  */
6388 +
6389 +  new = push_context (0, 0);
6390 +
6391 +  save_file_symbols = file_symbols;
6392 +  file_symbols = NULL;
6393 +  save_global_symbols = global_symbols;
6394 +  global_symbols = NULL;
6395 +  save_list_in_scope = cu->list_in_scope;
6396 +
6397 +  /* Process the child DIEs.  */
6398 +
6399 +  child_die = die->child;
6400    while (child_die && child_die->tag)
6401      {
6402 +      /* Any DW_TAG_subprogram will reset LIST_IN_SCOPE to LOCAL_SYMBOLS.  */
6403 +      cu->list_in_scope = &global_symbols;
6404 +
6405        process_die (child_die, cu);
6406        child_die = sibling_die (child_die);
6407      }
6408 +
6409 +  /* Finish this module and restore the context.  */
6410 +
6411 +  TYPE_MODULE_BLOCK (type) = finish_block (NULL, &global_symbols,
6412 +                                           new->old_blocks, 0, 0, objfile);
6413 +
6414 +  if (file_symbols)
6415 +    complaint (&symfile_complaints, _("DW_TAG_module contains static symbols"));
6416 +  if (local_symbols)
6417 +    complaint (&symfile_complaints, _("DW_TAG_module contains local symbols"));
6418 +  if (param_symbols)
6419 +    complaint (&symfile_complaints, _("DW_TAG_module contains function "
6420 +                                     "parameters"));
6421 +
6422 +  file_symbols = save_file_symbols;
6423 +  global_symbols = save_global_symbols;
6424 +  cu->list_in_scope = save_list_in_scope;
6425 +
6426 +  pop_context ();
6427 +
6428 +  set_die_type (die, type, cu);
6429 +
6430 +  return type;
6431 +}
6432 +
6433 +/* Import a Fortran module.  Only store the module name for its later lookup by
6434 +   f_lookup_symbol_nonlocal.  */
6435 +
6436 +static void
6437 +read_fortran_imported_module (struct die_info *die, struct dwarf2_cu *cu)
6438 +{
6439 +  struct objfile *objfile = cu->objfile;
6440 +  struct attribute *attr;
6441 +  struct die_info *module_die;
6442 +  char *module_name;
6443 +  struct fortran_using *use;
6444 +
6445 +  attr = dwarf2_attr (die, DW_AT_import, cu);
6446 +  if (attr == NULL)
6447 +    return;
6448 +
6449 +  module_die = follow_die_ref (die, attr, &cu);
6450 +  module_name = dwarf2_name (module_die, cu);
6451 +  if (module_name == NULL)
6452 +    {
6453 +      complaint (&symfile_complaints,
6454 +                _("Imported DIE at offset 0x%x has no name"), die->offset);
6455 +      return;
6456 +    }
6457 +
6458 +  /* Fortran does not allow any duplicity between local and any of the imported
6459 +     symbols.  Therefore the order of the USE statements is not portant.
6460 +     gfortran prints:
6461 +     Error: Name 'X' at (1) is an ambiguous reference to 'X' from module 'Y'  */
6462 +
6463 +  use = obstack_alloc (&objfile->objfile_obstack, sizeof (*use)
6464 +                                                 + strlen (module_name));
6465 +  strcpy (use->module_name, module_name);
6466 +  gdb_assert (cu->language == language_fortran);
6467 +  use->next = cu->language_specific.fortran.use;
6468 +  cu->language_specific.fortran.use = use;
6469 +}
6470 +
6471 +/* Import a single Fortran declaration and possibly rename it.  */
6472 +
6473 +static void
6474 +read_fortran_imported_declaration (struct die_info *die, struct dwarf2_cu *cu)
6475 +{
6476 +  struct attribute *attr;
6477 +  struct die_info *imported_die;
6478 +  struct symbol *sym;
6479 +  char *rename = dwarf2_name (die, cu);
6480 +
6481 +  attr = dwarf2_attr (die, DW_AT_import, cu);
6482 +  if (attr == NULL)
6483 +    {
6484 +      complaint (&symfile_complaints,
6485 +                _("Fortran DW_TAG_imported_declaration is missing "
6486 +                  "DW_AT_import at offset 0x%x"), die->offset);
6487 +      return;
6488 +    }
6489 +  imported_die = follow_die_ref (die, attr, &cu);
6490 +
6491 +  sym = new_symbol (imported_die, NULL, cu);
6492 +
6493 +  if (sym && rename)
6494 +    (sym)->ginfo.language_specific.cplus_specific.demangled_name = rename;
6495  }
6496  
6497  /* Return the name of the namespace represented by DIE.  Set
6498 @@ -5724,29 +6239,113 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
6499    struct gdbarch *gdbarch = get_objfile_arch (objfile);
6500    struct type *type, *range_type, *index_type, *char_type;
6501    struct attribute *attr;
6502 -  unsigned int length;
6503 +  int length;
6504 +
6505 +  index_type = objfile_type (objfile)->builtin_int;
6506 +  /* RANGE_TYPE is allocated from OBJFILE, not as a permanent type.  */
6507 +  range_type = alloc_type (objfile, NULL);
6508 +  /* LOW_BOUND and HIGH_BOUND are set for real below.  */
6509 +  range_type = create_range_type (range_type, index_type, 0, -1);
6510 +
6511 +  /* C/C++ should probably have the low bound 0 but C/C++ does not use
6512 +     DW_TAG_string_type.  */
6513 +  TYPE_LOW_BOUND (range_type) = 1;
6514  
6515    attr = dwarf2_attr (die, DW_AT_string_length, cu);
6516 -  if (attr)
6517 -    {
6518 -      length = DW_UNSND (attr);
6519 +  if (attr && attr_form_is_block (attr))
6520 +    {
6521 +      /* Security check for a size overflow.  */
6522 +      if (DW_BLOCK (attr)->size + 2 < DW_BLOCK (attr)->size)
6523 +       TYPE_HIGH_BOUND (range_type) = 1;
6524 +      /* Extend the DWARF block by a new DW_OP_deref/DW_OP_deref_size
6525 +        instruction as DW_AT_string_length specifies the length location, not
6526 +        its value.  */
6527 +      else
6528 +       {
6529 +         struct dwarf2_locexpr_baton *length_baton = NULL;
6530 +         struct dwarf_block *blk = DW_BLOCK (attr);
6531 +
6532 +         /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing
6533 +            DW_OP_deref* in such case.  */
6534 +
6535 +         if (blk->size == 1 && blk->data[0] >= DW_OP_reg0
6536 +             && blk->data[0] <= DW_OP_reg31)
6537 +           length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
6538 +         else if (blk->size > 1 && blk->data[0] == DW_OP_regx)
6539 +           {
6540 +             ULONGEST ulongest;
6541 +             gdb_byte *end;
6542 +
6543 +             end = read_uleb128 (&blk->data[1], &blk->data[blk->size],
6544 +                                 &ulongest);
6545 +             if (end == &blk->data[blk->size])
6546 +               length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
6547 +           }
6548 +
6549 +         if (length_baton == NULL)
6550 +           {
6551 +             struct attribute *size_attr;
6552 +
6553 +             length_baton = obstack_alloc (&cu->comp_unit_obstack,
6554 +                                           sizeof (*length_baton));
6555 +             length_baton->per_cu = cu->per_cu;
6556 +             length_baton->size = DW_BLOCK (attr)->size + 2;
6557 +             length_baton->data = obstack_alloc (&cu->comp_unit_obstack,
6558 +                                                 length_baton->size);
6559 +             memcpy (length_baton->data, DW_BLOCK (attr)->data,
6560 +                     DW_BLOCK (attr)->size);
6561 +
6562 +             /* DW_AT_BYTE_SIZE existing together with DW_AT_STRING_LENGTH
6563 +                specifies the size of an integer to fetch.  */
6564 +             size_attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6565 +             if (size_attr)
6566 +               {
6567 +                 length_baton->data[DW_BLOCK (attr)->size] = DW_OP_deref_size;
6568 +                 length_baton->data[DW_BLOCK (attr)->size + 1] =
6569 +                                                          DW_UNSND (size_attr);
6570 +                 if (length_baton->data[DW_BLOCK (attr)->size + 1]
6571 +                     != DW_UNSND (size_attr))
6572 +                   complaint (&symfile_complaints,
6573 +                              _("DW_AT_string_length's DW_AT_byte_size "
6574 +                                "integer exceeds the byte size storage"));
6575 +               }
6576 +             else
6577 +               {
6578 +                 length_baton->data[DW_BLOCK (attr)->size] = DW_OP_deref;
6579 +                 length_baton->data[DW_BLOCK (attr)->size + 1] = DW_OP_nop;
6580 +               }
6581 +           }
6582 +
6583 +         TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 1);
6584 +         TYPE_FIELD_DWARF_BLOCK (range_type, 1) = length_baton;
6585 +         TYPE_DYNAMIC (range_type) = 1;
6586 +       }
6587      }
6588    else
6589      {
6590 -      /* check for the DW_AT_byte_size attribute */
6591 +      if (attr && attr_form_is_constant (attr))
6592 +       {
6593 +         /* We currently do not support a constant address where the location
6594 +            should be read from - attr_form_is_block is expected instead.  See
6595 +            DWARF for the DW_AT_STRING_LENGTH vs. DW_AT_BYTE_SIZE difference.
6596 +            */
6597 +         /* PASSTHRU */
6598 +       }
6599 +
6600        attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6601 -      if (attr)
6602 -        {
6603 -          length = DW_UNSND (attr);
6604 -        }
6605 +      if (attr && attr_form_is_block (attr))
6606 +       {
6607 +         TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 1);
6608 +         TYPE_FIELD_DWARF_BLOCK (range_type, 1) =
6609 +                                       dwarf2_attr_to_locexpr_baton (attr, cu);
6610 +         TYPE_DYNAMIC (range_type) = 1;
6611 +       }
6612 +      else if (attr && attr_form_is_constant (attr))
6613 +       TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
6614        else
6615 -        {
6616 -          length = 1;
6617 -        }
6618 +       TYPE_HIGH_BOUND (range_type) = 1;
6619      }
6620  
6621 -  index_type = objfile_type (objfile)->builtin_int;
6622 -  range_type = create_range_type (NULL, index_type, 1, length);
6623    char_type = language_string_char_type (cu->language_defn, gdbarch);
6624    type = create_string_type (NULL, char_type, range_type);
6625  
6626 @@ -5841,7 +6440,6 @@ static struct type *
6627  read_typedef (struct die_info *die, struct dwarf2_cu *cu)
6628  {
6629    struct objfile *objfile = cu->objfile;
6630 -  struct attribute *attr;
6631    const char *name = NULL;
6632    struct type *this_type;
6633  
6634 @@ -5949,8 +6547,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
6635    struct type *base_type;
6636    struct type *range_type;
6637    struct attribute *attr;
6638 -  int low = 0;
6639 -  int high = -1;
6640 +  int low;
6641    char *name;
6642    
6643    base_type = die_type (die, cu);
6644 @@ -5963,42 +6560,89 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
6645                      0, NULL, cu->objfile);
6646      }
6647  
6648 -  if (cu->language == language_fortran)
6649 -    { 
6650 -      /* FORTRAN implies a lower bound of 1, if not given.  */
6651 -      low = 1;
6652 -    }
6653 +  /* LOW_BOUND and HIGH_BOUND are set for real below.  */
6654 +  range_type = create_range_type (NULL, base_type, 0, -1);
6655  
6656 -  /* FIXME: For variable sized arrays either of these could be
6657 -     a variable rather than a constant value.  We'll allow it,
6658 -     but we don't know how to handle it.  */
6659    attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
6660 -  if (attr)
6661 -    low = dwarf2_get_attr_constant_value (attr, 0);
6662 +  if (attr && attr_form_is_block (attr))
6663 +    {
6664 +      TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 0);
6665 +      TYPE_FIELD_DWARF_BLOCK (range_type, 0) = dwarf2_attr_to_locexpr_baton
6666 +                                                                    (attr, cu);
6667 +      TYPE_DYNAMIC (range_type) = 1;
6668 +      /* For setting a default if DW_AT_UPPER_BOUND would be missing.  */
6669 +      low = 0;
6670 +    }
6671 +  else
6672 +    {
6673 +      if (attr && attr_form_is_constant (attr))
6674 +       low = dwarf2_get_attr_constant_value (attr, 0);
6675 +      else
6676 +       {
6677 +         if (cu->language == language_fortran)
6678 +           {
6679 +             /* FORTRAN implies a lower bound of 1, if not given.  */
6680 +             low = 1;
6681 +           }
6682 +         else
6683 +           {
6684 +             /* According to DWARF we should assume the value 0 only for
6685 +                LANGUAGE_C and LANGUAGE_CPLUS.  */
6686 +             low = 0;
6687 +           }
6688 +       }
6689 +      TYPE_LOW_BOUND (range_type) = low;
6690 +      if (low >= 0)
6691 +       TYPE_UNSIGNED (range_type) = 1;
6692 +    }
6693  
6694    attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
6695 -  if (attr)
6696 -    {       
6697 -      if (attr->form == DW_FORM_block1)
6698 -        {
6699 -          /* GCC encodes arrays with unspecified or dynamic length
6700 -             with a DW_FORM_block1 attribute.
6701 -             FIXME: GDB does not yet know how to handle dynamic
6702 -             arrays properly, treat them as arrays with unspecified
6703 -             length for now.
6704 -
6705 -             FIXME: jimb/2003-09-22: GDB does not really know
6706 -             how to handle arrays of unspecified length
6707 -             either; we just represent them as zero-length
6708 -             arrays.  Choose an appropriate upper bound given
6709 -             the lower bound we've computed above.  */
6710 -          high = low - 1;
6711 -        }
6712 +  if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr)))
6713 +    {
6714 +      attr = dwarf2_attr (die, DW_AT_count, cu);
6715 +      /* It does not hurt but it is needlessly ineffective in check_typedef.  */
6716 +      if (attr && (attr_form_is_block (attr) || attr_form_is_constant (attr)))
6717 +       {
6718 +         TYPE_RANGE_HIGH_BOUND_IS_COUNT (range_type) = 1;
6719 +         TYPE_DYNAMIC (range_type) = 1;
6720 +       }
6721 +      /* Pass it now as the regular DW_AT_upper_bound.  */
6722 +    }
6723 +
6724 +  if (attr && attr_form_is_block (attr))
6725 +    {
6726 +      TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 1);
6727 +      TYPE_FIELD_DWARF_BLOCK (range_type, 1) = dwarf2_attr_to_locexpr_baton
6728 +                                                                    (attr, cu);
6729 +      TYPE_DYNAMIC (range_type) = 1;
6730 +    }
6731 +  else
6732 +    {
6733 +      if (attr && attr_form_is_constant (attr))
6734 +       TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
6735        else
6736 -        high = dwarf2_get_attr_constant_value (attr, 1);
6737 +       {
6738 +         TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (range_type) = 1;
6739 +         TYPE_HIGH_BOUND (range_type) = low - 1;
6740 +       }
6741      }
6742  
6743 -  range_type = create_range_type (NULL, base_type, low, high);
6744 +  /* DW_AT_bit_stride is currently unsupported as we count in bytes.  */
6745 +  attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
6746 +  if (attr && attr_form_is_block (attr))
6747 +    {
6748 +      TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 2);
6749 +      TYPE_FIELD_DWARF_BLOCK (range_type, 2) = dwarf2_attr_to_locexpr_baton
6750 +                                                                    (attr, cu);
6751 +      TYPE_DYNAMIC (range_type) = 1;
6752 +    }
6753 +  else if (attr && attr_form_is_constant (attr))
6754 +    {
6755 +      TYPE_BYTE_STRIDE (range_type) = dwarf2_get_attr_constant_value (attr, 0);
6756 +      if (TYPE_BYTE_STRIDE (range_type) == 0)
6757 +       complaint (&symfile_complaints,
6758 +                  _("Found DW_AT_byte_stride with unsupported value 0"));
6759 +    }
6760  
6761    name = dwarf2_name (die, cu);
6762    if (name)
6763 @@ -6469,6 +7113,7 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
6764           && abbrev->tag != DW_TAG_lexical_block
6765           && abbrev->tag != DW_TAG_variable
6766           && abbrev->tag != DW_TAG_namespace
6767 +         && abbrev->tag != DW_TAG_module
6768           && abbrev->tag != DW_TAG_member)
6769         {
6770           /* Otherwise we skip to the next sibling, if any.  */
6771 @@ -6689,9 +7334,6 @@ read_partial_die (struct partial_die_info *part_die,
6772           if (part_die->dirname == NULL)
6773             part_die->dirname = DW_STRING (&attr);
6774           break;
6775 -       case DW_AT_MIPS_linkage_name:
6776 -         part_die->name = DW_STRING (&attr);
6777 -         break;
6778         case DW_AT_low_pc:
6779           has_low_pc_attr = 1;
6780           part_die->lowpc = DW_ADDR (&attr);
6781 @@ -6923,7 +7565,8 @@ fixup_partial_die (struct partial_die_info *part_die,
6782    /* If we found a reference attribute and the DIE has no name, try
6783       to find a name in the referred to DIE.  */
6784  
6785 -  if (part_die->name == NULL && part_die->has_specification)
6786 +  if (part_die->has_specification
6787 +      && (part_die->name == NULL || !part_die->is_external))
6788      {
6789        struct partial_die_info *spec_die;
6790  
6791 @@ -8265,10 +8908,12 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
6792       (i.e. when the value of a register or memory location is
6793       referenced, or a thread-local block, etc.).  Then again, it might
6794       not be worthwhile.  I'm assuming that it isn't unless performance
6795 -     or memory numbers show me otherwise.  */
6796 +     or memory numbers show me otherwise.
6797 +     
6798 +     SYMBOL_CLASS may get overriden by dwarf2_symbol_mark_computed.  */
6799  
6800 -  dwarf2_symbol_mark_computed (attr, sym, cu);
6801    SYMBOL_CLASS (sym) = LOC_COMPUTED;
6802 +  dwarf2_symbol_mark_computed (attr, sym, cu);
6803  }
6804  
6805  /* Given a pointer to a DWARF information entry, figure out if we need
6806 @@ -8290,21 +8935,30 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6807  
6808    baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6809  
6810 -  if (die->tag != DW_TAG_namespace)
6811 -    name = dwarf2_linkage_name (die, cu);
6812 -  else
6813 -    name = TYPE_NAME (type);
6814 -
6815 +  name = dwarf2_name (die, cu);
6816    if (name)
6817      {
6818 +      const char *linkagename;
6819 +
6820        sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
6821                                              sizeof (struct symbol));
6822        OBJSTAT (objfile, n_syms++);
6823        memset (sym, 0, sizeof (struct symbol));
6824 +      /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity.  */
6825 +      SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
6826  
6827 -      /* Cache this symbol's name and the name's demangled form (if any).  */
6828        SYMBOL_LANGUAGE (sym) = cu->language;
6829 -      SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
6830 +
6831 +      /* Cache this symbol's name and the name's demangled form (if any).  */
6832 +
6833 +      linkagename = dwarf2_physname (die, cu);
6834 +      SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), objfile);
6835 +      if (cu->language == language_fortran)
6836 +       {
6837 +         (sym)->ginfo.language_specific.cplus_specific.demangled_name =
6838 +           SYMBOL_LINKAGE_NAME (sym);
6839 +         SYMBOL_LINKAGE_NAME (sym) = fortran_module_linkage_name (die, cu);
6840 +       }
6841  
6842        /* Default assumptions.
6843           Use the passed type or decode it from the die.  */
6844 @@ -8402,9 +9056,28 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6845           if (attr)
6846             {
6847               var_decode_location (attr, sym, cu);
6848 +
6849               attr2 = dwarf2_attr (die, DW_AT_external, cu);
6850 +
6851 +             /* Fortran explicitely imports any global symbols to the local
6852 +                scope by DW_TAG_common_block.  */
6853 +             if (cu->language == language_fortran && die->parent
6854 +                 && die->parent->tag == DW_TAG_common_block)
6855 +               attr2 = NULL;
6856 +
6857               if (attr2 && (DW_UNSND (attr2) != 0))
6858 -               add_symbol_to_list (sym, &global_symbols);
6859 +               {
6860 +                 /* Workaround gfortran PR debug/40040 - it uses
6861 +                    DW_AT_location for variables in -fPIC libraries which may
6862 +                    get overriden by other libraries/executable and get
6863 +                    a different address.  Resolve it by .dynsym instead.  */
6864 +
6865 +                 if (cu->language == language_fortran && die->parent
6866 +                     && die->parent->tag == DW_TAG_module)
6867 +                   SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
6868 +
6869 +                 add_symbol_to_list (sym, &global_symbols);
6870 +               }
6871               else
6872                 add_symbol_to_list (sym, cu->list_in_scope);
6873             }
6874 @@ -8534,7 +9207,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6875           add_symbol_to_list (sym, cu->list_in_scope);
6876           break;
6877         case DW_TAG_enumerator:
6878 -         SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu);
6879 +         SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_name (die, cu);
6880           attr = dwarf2_attr (die, DW_AT_const_value, cu);
6881           if (attr)
6882             {
6883 @@ -8558,6 +9231,16 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6884           SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6885           add_symbol_to_list (sym, &global_symbols);
6886           break;
6887 +       case DW_TAG_common_block:
6888 +         SYMBOL_CLASS (sym) = LOC_STATIC;
6889 +         SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
6890 +         add_symbol_to_list (sym, cu->list_in_scope);
6891 +         break;
6892 +       case DW_TAG_module:
6893 +         SYMBOL_CLASS (sym) = LOC_STATIC;
6894 +         SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
6895 +         add_symbol_to_list (sym, &global_symbols);
6896 +         break;
6897         default:
6898           /* Not a tag we recognize.  Hopefully we aren't processing
6899              trash data, but since we must specifically ignore things
6900 @@ -8571,8 +9254,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6901        /* For the benefit of old versions of GCC, check for anonymous
6902          namespaces based on the demangled name.  */
6903        if (!processing_has_namespace_info
6904 -         && cu->language == language_cplus
6905 -         && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL)
6906 +         && cu->language == language_cplus)
6907         cp_scan_for_anonymous_namespaces (sym);
6908      }
6909    return (sym);
6910 @@ -8823,12 +9505,18 @@ read_type_die (struct die_info *die, struct dwarf2_cu *cu)
6911      case DW_TAG_namespace:
6912        this_type = read_namespace_type (die, cu);
6913        break;
6914 +    case DW_TAG_module:
6915 +      this_type = read_module_type (die, cu);
6916 +      break;
6917      default:
6918        complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
6919                  dwarf_tag_name (die->tag));
6920        break;
6921      }
6922  
6923 +  if (this_type)
6924 +    finalize_type (this_type);
6925 +
6926    return this_type;
6927  }
6928  
6929 @@ -8910,10 +9598,100 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
6930              So it does not need a prefix.  */
6931           return "";
6932        default:
6933 -       return determine_prefix (parent, cu);
6934 +        return determine_prefix (parent, cu);
6935        }
6936  }
6937  
6938 +/* Determines the prefix for a symbol's physname.  Unlike determine_prefix,
6939 +   this method does not simply look at the DIE's immediate parent.
6940 +   It will compute the symbol's physname by scanning through all parent
6941 +   DIEs until it gets to the compilation unit's DIE.  */
6942 +
6943 +static char *
6944 +physname_prefix (struct die_info *die, struct dwarf2_cu *cu)
6945 +{
6946 +  long length;
6947 +  struct ui_file *buf;
6948 +  struct die_info *d, *spec_die;
6949 +  struct dwarf2_cu *spec_cu;
6950 +  char *name;
6951 +
6952 +  /* Construct a stack containing all of the DIE's parents.  Caution
6953 +     must be observed for dealing with DW_AT_specification. */
6954 +  spec_cu = cu;
6955 +  spec_die = die_specification (die, &spec_cu);
6956 +  if (spec_die != NULL)
6957 +    d = spec_die->parent;
6958 +  else
6959 +    d = die->parent;
6960 +  while (d != NULL && d->tag != DW_TAG_compile_unit)
6961 +    {
6962 +      struct attribute *attr;
6963 +
6964 +      spec_die = die_specification (d, &spec_cu);
6965 +      if (spec_die != NULL)
6966 +       d = spec_die;
6967 +
6968 +      VEC_quick_push (die_info_p, die_list, d);
6969 +      d = d->parent;
6970 +    }
6971 +
6972 +  /* Now pop all the elements, printing their names as we go.  */
6973 +  buf = mem_fileopen ();
6974 +  while (!VEC_empty (die_info_p, die_list))
6975 +    {
6976 +      d = VEC_pop (die_info_p, die_list);
6977 +      physname_prefix_1 (buf, d, cu);
6978 +
6979 +      if (!VEC_empty (die_info_p, die_list))
6980 +       {
6981 +         if (cu->language == language_cplus)
6982 +           fputs_unfiltered ("::", buf);
6983 +         else
6984 +           fputs_unfiltered (".", buf);
6985 +       }
6986 +    }
6987 +
6988 +  name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, &length);
6989 +  ui_file_delete (buf);
6990 +  return name;
6991 +}
6992 +
6993 +static void
6994 +physname_prefix_1 (struct ui_file *buf, struct die_info *die,
6995 +                  struct dwarf2_cu *cu)
6996 +{
6997 +  const char *name = NULL;
6998 +  gdb_assert (buf != NULL);
6999 +
7000 +  if (die != NULL)
7001 +    {
7002 +      switch (die->tag)
7003 +       {
7004 +       case DW_TAG_namespace:
7005 +         name = dwarf2_name (die, cu);
7006 +         if (name == NULL)
7007 +           name = "(anonymous namespace)";
7008 +         break;
7009 +
7010 +       case DW_TAG_class_type:
7011 +       case DW_TAG_structure_type:
7012 +       case DW_TAG_union_type:
7013 +       case DW_TAG_enumeration_type:
7014 +       case DW_TAG_interface_type:
7015 +       case DW_TAG_subprogram:
7016 +         name = dwarf2_name (die, cu);
7017 +         break;
7018 +
7019 +       default:
7020 +         break;
7021 +       }
7022 +    }
7023 +
7024 +  if (name != NULL)
7025 +    fputs_unfiltered (name, buf);
7026 +}
7027 +
7028  /* Return a newly-allocated string formed by concatenating PREFIX and
7029     SUFFIX with appropriate separator.  If PREFIX or SUFFIX is NULL or empty, then
7030     simply copy the SUFFIX or PREFIX, respectively.  If OBS is non-null,
7031 @@ -8963,17 +9741,111 @@ sibling_die (struct die_info *die)
7032    return die->sibling;
7033  }
7034  
7035 -/* Get linkage name of a die, return NULL if not found.  */
7036 +/* Construct a physname for the given DIE in CU. */
7037  
7038  static char *
7039 -dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
7040 +dwarf2_physname (struct die_info *die, struct dwarf2_cu *cu)
7041  {
7042    struct attribute *attr;
7043 +  char *name;
7044 +
7045 +  name = dwarf2_name (die, cu);
7046 +
7047 +  /* These are the only languages we know how to qualify names in.  */
7048 +  if (cu->language != language_cplus
7049 +      && cu->language != language_java)
7050 +    return name;
7051 +
7052 +  if (die_needs_namespace (die, cu))
7053 +    {
7054 +      long length;
7055 +      char *prefix;
7056 +      struct ui_file *buf;
7057 +
7058 +      prefix = physname_prefix (die, cu);
7059 +      buf = mem_fileopen ();
7060 +      if (*prefix != '\0')
7061 +       {
7062 +         char *prefixed_name = typename_concat (NULL, prefix, name, cu);
7063 +         fputs_unfiltered (prefixed_name, buf);
7064 +         xfree (prefixed_name);
7065 +       }
7066 +      else
7067 +       fputs_unfiltered (name ? name : "", buf);
7068 +
7069 +      /* For Java and C++ methods, append formal parameter type
7070 +        information. */
7071 +      if ((cu->language == language_cplus || cu->language == language_java)
7072 +         && die->tag == DW_TAG_subprogram)
7073 +       {
7074 +         struct type *type = read_type_die (die, cu);
7075 +
7076 +         c_type_print_args (type, buf, 0, cu->language);
7077 +
7078 +         if (cu->language == language_java)
7079 +           {
7080 +             /* For java, we must append the return type to method names. */
7081 +             if (die->tag == DW_TAG_subprogram)
7082 +               java_print_type (TYPE_TARGET_TYPE (type), "", buf, 0, 0);
7083 +           }
7084 +         else if (cu->language == language_cplus)
7085 +           {
7086 +             /* c_type_print_args adds argument types, but it does
7087 +                not add any necessary "const". */
7088 +             if (TYPE_NFIELDS (type) > 0 && TYPE_FIELD_ARTIFICIAL (type, 0)
7089 +                 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0))))
7090 +               fputs_unfiltered (" const", buf);
7091 +           }
7092 +       }
7093 +
7094 +      name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
7095 +                                  &length);
7096 +      ui_file_delete (buf);
7097 +
7098 +      if (cu->language == language_cplus)
7099 +       {
7100 +         char *cname
7101 +           = dwarf2_canonicalize_name (name, cu,
7102 +                                       &cu->objfile->objfile_obstack);
7103 +         if (cname != NULL)
7104 +           name = cname;
7105 +       }
7106 +    }
7107 +
7108 +  return name;
7109 +}
7110 +
7111 +/* Return the fully qualified .symtab name for symbols contained in Fortran
7112 +   modules.  Return DWARF2_NAME otherwise.  */
7113 +
7114 +static char *
7115 +fortran_module_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
7116 +{
7117 +  char *name;
7118 +
7119 +  gdb_assert (cu->language == language_fortran);
7120 +
7121 +  name = dwarf2_name (die, cu);
7122 +
7123 +  if (name && die->parent && die->parent->tag == DW_TAG_module)
7124 +    {
7125 +      char *module_name = dwarf2_name (die->parent, cu);
7126 +
7127 +      if (module_name)
7128 +       {
7129 +         char *retval;
7130  
7131 -  attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7132 -  if (attr && DW_STRING (attr))
7133 -    return DW_STRING (attr);
7134 -  return dwarf2_name (die, cu);
7135 +         /* `__modulename_MOD_variablename0'.  */
7136 +         retval = obstack_alloc (&cu->objfile->objfile_obstack,
7137 +                                 2 + strlen (module_name) + 5 + strlen (name)
7138 +                                 + 1);
7139 +         sprintf (retval, "__%s_MOD_%s", module_name, name);
7140 +
7141 +         return retval;
7142 +       }
7143 +    }
7144 +
7145 +  return name;
7146  }
7147  
7148  /* Get name of a die, return NULL if not found.  */
7149 @@ -10200,11 +11072,11 @@ dwarf2_get_ref_die_offset (struct attribute *attr)
7150    return 0;
7151  }
7152  
7153 -/* Return the constant value held by the given attribute.  Return -1
7154 +/* Return the constant value held by the given attribute.  Return DEFAULT_VALUE
7155     if the value held by the attribute is not constant.  */
7156  
7157 -static int
7158 -dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
7159 +static CORE_ADDR
7160 +dwarf2_get_attr_constant_value (struct attribute *attr, CORE_ADDR default_value)
7161  {
7162    if (attr->form == DW_FORM_sdata)
7163      return DW_SND (attr);
7164 @@ -11009,8 +11881,6 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7165  {
7166    gdb_byte *mac_ptr, *mac_end;
7167    struct macro_source_file *current_file = 0;
7168 -  enum dwarf_macinfo_record_type macinfo_type;
7169 -  int at_commandline;
7170  
7171    if (dwarf2_per_objfile->macinfo.buffer == NULL)
7172      {
7173 @@ -11018,29 +11888,19 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7174        return;
7175      }
7176  
7177 -  /* First pass: Find the name of the base filename.
7178 -     This filename is needed in order to process all macros whose definition
7179 -     (or undefinition) comes from the command line.  These macros are defined
7180 -     before the first DW_MACINFO_start_file entry, and yet still need to be
7181 -     associated to the base file.
7182 -
7183 -     To determine the base file name, we scan the macro definitions until we
7184 -     reach the first DW_MACINFO_start_file entry.  We then initialize
7185 -     CURRENT_FILE accordingly so that any macro definition found before the
7186 -     first DW_MACINFO_start_file can still be associated to the base file.  */
7187 -
7188    mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
7189    mac_end = dwarf2_per_objfile->macinfo.buffer
7190      + dwarf2_per_objfile->macinfo.size;
7191  
7192 -  do
7193 +  for (;;)
7194      {
7195 +      enum dwarf_macinfo_record_type macinfo_type;
7196 +
7197        /* Do we at least have room for a macinfo type byte?  */
7198        if (mac_ptr >= mac_end)
7199          {
7200 -         /* Complaint is printed during the second pass as GDB will probably
7201 -            stop the first pass earlier upon finding DW_MACINFO_start_file.  */
7202 -         break;
7203 +         dwarf2_macros_too_long_complaint ();
7204 +          return;
7205          }
7206  
7207        macinfo_type = read_1_byte (abfd, mac_ptr);
7208 @@ -11051,92 +11911,7 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7209            /* A zero macinfo type indicates the end of the macro
7210               information.  */
7211          case 0:
7212 -         break;
7213 -
7214 -       case DW_MACINFO_define:
7215 -       case DW_MACINFO_undef:
7216 -         /* Only skip the data by MAC_PTR.  */
7217 -         {
7218 -           unsigned int bytes_read;
7219 -
7220 -           read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7221 -           mac_ptr += bytes_read;
7222 -           read_string (abfd, mac_ptr, &bytes_read);
7223 -           mac_ptr += bytes_read;
7224 -         }
7225 -         break;
7226 -
7227 -       case DW_MACINFO_start_file:
7228 -         {
7229 -           unsigned int bytes_read;
7230 -           int line, file;
7231 -
7232 -           line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7233 -           mac_ptr += bytes_read;
7234 -           file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7235 -           mac_ptr += bytes_read;
7236 -
7237 -           current_file = macro_start_file (file, line, current_file, comp_dir,
7238 -                                            lh, cu->objfile);
7239 -         }
7240 -         break;
7241 -
7242 -       case DW_MACINFO_end_file:
7243 -         /* No data to skip by MAC_PTR.  */
7244 -         break;
7245 -
7246 -       case DW_MACINFO_vendor_ext:
7247 -         /* Only skip the data by MAC_PTR.  */
7248 -         {
7249 -           unsigned int bytes_read;
7250 -
7251 -           read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7252 -           mac_ptr += bytes_read;
7253 -           read_string (abfd, mac_ptr, &bytes_read);
7254 -           mac_ptr += bytes_read;
7255 -         }
7256 -         break;
7257 -
7258 -       default:
7259 -         break;
7260 -       }
7261 -    } while (macinfo_type != 0 && current_file == NULL);
7262 -
7263 -  /* Second pass: Process all entries.
7264 -
7265 -     Use the AT_COMMAND_LINE flag to determine whether we are still processing
7266 -     command-line macro definitions/undefinitions.  This flag is unset when we
7267 -     reach the first DW_MACINFO_start_file entry.  */
7268 -
7269 -  mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
7270 -
7271 -  /* Determines if GDB is still before first DW_MACINFO_start_file.  If true
7272 -     GDB is still reading the definitions from command line.  First
7273 -     DW_MACINFO_start_file will need to be ignored as it was already executed
7274 -     to create CURRENT_FILE for the main source holding also the command line
7275 -     definitions.  On first met DW_MACINFO_start_file this flag is reset to
7276 -     normally execute all the remaining DW_MACINFO_start_file macinfos.  */
7277 -
7278 -  at_commandline = 1;
7279 -
7280 -  do
7281 -    {
7282 -      /* Do we at least have room for a macinfo type byte?  */
7283 -      if (mac_ptr >= mac_end)
7284 -       {
7285 -         dwarf2_macros_too_long_complaint ();
7286 -         break;
7287 -       }
7288 -
7289 -      macinfo_type = read_1_byte (abfd, mac_ptr);
7290 -      mac_ptr++;
7291 -
7292 -      switch (macinfo_type)
7293 -       {
7294 -         /* A zero macinfo type indicates the end of the macro
7295 -            information.  */
7296 -       case 0:
7297 -         break;
7298 +          return;
7299  
7300          case DW_MACINFO_define:
7301          case DW_MACINFO_undef:
7302 @@ -11151,31 +11926,19 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7303              mac_ptr += bytes_read;
7304  
7305              if (! current_file)
7306 -             {
7307 -               /* DWARF violation as no main source is present.  */
7308 -               complaint (&symfile_complaints,
7309 -                          _("debug info with no main source gives macro %s "
7310 -                            "on line %d: %s"),
7311 -                          macinfo_type ==
7312 -                          DW_MACINFO_define ? _("definition") : macinfo_type ==
7313 -                          DW_MACINFO_undef ? _("undefinition") :
7314 -                          "something-or-other", line, body);
7315 -               break;
7316 -             }
7317 -           if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
7318               complaint (&symfile_complaints,
7319 -                        _("debug info gives %s macro %s with %s line %d: %s"),
7320 -                        at_commandline ? _("command-line") : _("in-file"),
7321 +                        _("debug info gives macro %s outside of any file: %s"),
7322                          macinfo_type ==
7323 -                        DW_MACINFO_define ? _("definition") : macinfo_type ==
7324 -                        DW_MACINFO_undef ? _("undefinition") :
7325 -                        "something-or-other",
7326 -                        line == 0 ? _("zero") : _("non-zero"), line, body);
7327 -
7328 -           if (macinfo_type == DW_MACINFO_define)
7329 -             parse_macro_definition (current_file, line, body);
7330 -           else if (macinfo_type == DW_MACINFO_undef)
7331 -             macro_undef (current_file, line, body);
7332 +                        DW_MACINFO_define ? "definition" : macinfo_type ==
7333 +                        DW_MACINFO_undef ? "undefinition" :
7334 +                        "something-or-other", body);
7335 +            else
7336 +              {
7337 +                if (macinfo_type == DW_MACINFO_define)
7338 +                  parse_macro_definition (current_file, line, body);
7339 +                else if (macinfo_type == DW_MACINFO_undef)
7340 +                  macro_undef (current_file, line, body);
7341 +              }
7342            }
7343            break;
7344  
7345 @@ -11189,22 +11952,9 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7346              file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7347              mac_ptr += bytes_read;
7348  
7349 -           if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
7350 -             complaint (&symfile_complaints,
7351 -                        _("debug info gives source %d included "
7352 -                          "from %s at %s line %d"),
7353 -                        file, at_commandline ? _("command-line") : _("file"),
7354 -                        line == 0 ? _("zero") : _("non-zero"), line);
7355 -
7356 -           if (at_commandline)
7357 -             {
7358 -               /* This DW_MACINFO_start_file was executed in the pass one.  */
7359 -               at_commandline = 0;
7360 -             }
7361 -           else
7362 -             current_file = macro_start_file (file, line,
7363 -                                              current_file, comp_dir,
7364 -                                              lh, cu->objfile);
7365 +            current_file = macro_start_file (file, line,
7366 +                                             current_file, comp_dir,
7367 +                                             lh, cu->objfile);
7368            }
7369            break;
7370  
7371 @@ -11258,7 +12008,7 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7372            }
7373            break;
7374          }
7375 -    } while (macinfo_type != 0);
7376 +    }
7377  }
7378  
7379  /* Check if the attribute's form is a DW_FORM_block*
7380 @@ -11318,6 +12068,34 @@ attr_form_is_constant (struct attribute *attr)
7381      }
7382  }
7383  
7384 +/* Convert DW_BLOCK into struct dwarf2_locexpr_baton.  ATTR must be a DW_BLOCK
7385 +   attribute type.  */
7386 +
7387 +static struct dwarf2_locexpr_baton *
7388 +dwarf2_attr_to_locexpr_baton (struct attribute *attr, struct dwarf2_cu *cu)
7389 +{
7390 +  struct dwarf2_locexpr_baton *baton;
7391 +
7392 +  gdb_assert (attr_form_is_block (attr));
7393 +
7394 +  baton = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (*baton));
7395 +  baton->per_cu = cu->per_cu;
7396 +  gdb_assert (baton->per_cu);
7397 +
7398 +  /* Note that we're just copying the block's data pointer
7399 +     here, not the actual data.  We're still pointing into the
7400 +     info_buffer for SYM's objfile; right now we never release
7401 +     that buffer, but when we do clean up properly this may
7402 +     need to change.  */
7403 +  baton->size = DW_BLOCK (attr)->size;
7404 +  baton->data = DW_BLOCK (attr)->data;
7405 +  gdb_assert (baton->size == 0 || baton->data != NULL);
7406 +
7407 +  return baton;
7408 +}
7409 +
7410 +/* SYM may get its SYMBOL_CLASS overriden on invalid ATTR content.  */
7411 +
7412  static void
7413  dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
7414                              struct dwarf2_cu *cu)
7415 @@ -11347,35 +12125,25 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
7416        SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
7417        SYMBOL_LOCATION_BATON (sym) = baton;
7418      }
7419 +  else if (attr_form_is_block (attr))
7420 +    {
7421 +      SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
7422 +      SYMBOL_LOCATION_BATON (sym) = dwarf2_attr_to_locexpr_baton (attr, cu);
7423 +    }
7424    else
7425      {
7426 -      struct dwarf2_locexpr_baton *baton;
7427 +      dwarf2_invalid_attrib_class_complaint ("location description",
7428 +                                            SYMBOL_NATURAL_NAME (sym));
7429  
7430 -      baton = obstack_alloc (&cu->objfile->objfile_obstack,
7431 -                            sizeof (struct dwarf2_locexpr_baton));
7432 -      baton->per_cu = cu->per_cu;
7433 -      gdb_assert (baton->per_cu);
7434 +      /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity.  */
7435  
7436 -      if (attr_form_is_block (attr))
7437 -       {
7438 -         /* Note that we're just copying the block's data pointer
7439 -            here, not the actual data.  We're still pointing into the
7440 -            info_buffer for SYM's objfile; right now we never release
7441 -            that buffer, but when we do clean up properly this may
7442 -            need to change.  */
7443 -         baton->size = DW_BLOCK (attr)->size;
7444 -         baton->data = DW_BLOCK (attr)->data;
7445 -       }
7446 -      else
7447 -       {
7448 -         dwarf2_invalid_attrib_class_complaint ("location description",
7449 -                                                SYMBOL_NATURAL_NAME (sym));
7450 -         baton->size = 0;
7451 -         baton->data = NULL;
7452 -       }
7453 -      
7454 -      SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
7455 -      SYMBOL_LOCATION_BATON (sym) = baton;
7456 +      SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
7457 +      SYMBOL_LOCATION_BATON (sym) = NULL;
7458 +
7459 +      /* For functions a missing DW_AT_frame_base does not optimize out the
7460 +        whole function definition, only its frame base resolving.  */
7461 +      if (attr->name == DW_AT_location)
7462 +       SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
7463      }
7464  }
7465  
7466 @@ -11663,6 +12431,31 @@ offset_and_type_eq (const void *item_lhs, const void *item_rhs)
7467    return ofs_lhs->offset == ofs_rhs->offset;
7468  }
7469  
7470 +/* Fill in generic attributes applicable for type DIEs.  */
7471 +
7472 +static void
7473 +fetch_die_type_attrs (struct die_info *die, struct type *type,
7474 +                     struct dwarf2_cu *cu)
7475 +{
7476 +  struct attribute *attr;
7477 +
7478 +  attr = dwarf2_attr (die, DW_AT_data_location, cu);
7479 +  if (attr_form_is_block (attr))
7480 +    TYPE_DATA_LOCATION_DWARF_BLOCK (type) = dwarf2_attr_to_locexpr_baton (attr,
7481 +                                                                         cu);
7482 +  gdb_assert (!TYPE_DATA_LOCATION_IS_ADDR (type));
7483 +
7484 +  attr = dwarf2_attr (die, DW_AT_allocated, cu);
7485 +  if (attr_form_is_block (attr))
7486 +    TYPE_ALLOCATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
7487 +  gdb_assert (!TYPE_NOT_ALLOCATED (type));
7488 +
7489 +  attr = dwarf2_attr (die, DW_AT_associated, cu);
7490 +  if (attr_form_is_block (attr))
7491 +    TYPE_ASSOCIATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
7492 +  gdb_assert (!TYPE_NOT_ASSOCIATED (type));
7493 +}
7494 +
7495  /* Set the type associated with DIE to TYPE.  Save it in CU's hash
7496     table if necessary.  For convenience, return TYPE.  */
7497  
7498 @@ -11671,6 +12464,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
7499  {
7500    struct dwarf2_offset_and_type **slot, ofs;
7501  
7502 +  fetch_die_type_attrs (die, type, cu);
7503 +
7504    if (cu->type_hash == NULL)
7505      {
7506        gdb_assert (cu->per_cu != NULL);
7507 @@ -11813,23 +12608,13 @@ show_dwarf2_cmd (char *args, int from_tty)
7508    cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
7509  }
7510  
7511 -/* If section described by INFO was mmapped, munmap it now.  */
7512 +/* A helper function to destroy a debug section.  */
7513  
7514  static void
7515 -munmap_section_buffer (struct dwarf2_section_info *info)
7516 +destroy_section (struct dwarf2_section_info *info)
7517  {
7518 -  if (info->was_mmapped)
7519 -    {
7520 -#ifdef HAVE_MMAP
7521 -      intptr_t begin = (intptr_t) info->buffer;
7522 -      intptr_t map_begin = begin & ~(pagesize - 1);
7523 -      size_t map_length = info->size + begin - map_begin;
7524 -      gdb_assert (munmap ((void *) map_begin, map_length) == 0);
7525 -#else
7526 -      /* Without HAVE_MMAP, we should never be here to begin with.  */
7527 -      gdb_assert (0);
7528 -#endif
7529 -    }
7530 +  if (info->destructor)
7531 +    (*info->destructor) (info);
7532  }
7533  
7534  /* munmap debug sections for OBJFILE, if necessary.  */
7535 @@ -11838,15 +12623,15 @@ static void
7536  dwarf2_per_objfile_free (struct objfile *objfile, void *d)
7537  {
7538    struct dwarf2_per_objfile *data = d;
7539 -  munmap_section_buffer (&data->info);
7540 -  munmap_section_buffer (&data->abbrev);
7541 -  munmap_section_buffer (&data->line);
7542 -  munmap_section_buffer (&data->str);
7543 -  munmap_section_buffer (&data->macinfo);
7544 -  munmap_section_buffer (&data->ranges);
7545 -  munmap_section_buffer (&data->loc);
7546 -  munmap_section_buffer (&data->frame);
7547 -  munmap_section_buffer (&data->eh_frame);
7548 +  destroy_section (&data->info);
7549 +  destroy_section (&data->abbrev);
7550 +  destroy_section (&data->line);
7551 +  destroy_section (&data->str);
7552 +  destroy_section (&data->macinfo);
7553 +  destroy_section (&data->ranges);
7554 +  destroy_section (&data->loc);
7555 +  destroy_section (&data->frame);
7556 +  destroy_section (&data->eh_frame);
7557  }
7558  
7559  void _initialize_dwarf2_read (void);
7560 @@ -11854,6 +12639,7 @@ void _initialize_dwarf2_read (void);
7561  void
7562  _initialize_dwarf2_read (void)
7563  {
7564 +  die_list = VEC_alloc (die_info_p, 32);
7565    dwarf2_objfile_data_key
7566      = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
7567  
7568 diff --git a/gdb/elfread.c b/gdb/elfread.c
7569 index 6e79d4a..198bae3 100644
7570 --- a/gdb/elfread.c
7571 +++ b/gdb/elfread.c
7572 @@ -728,10 +728,18 @@ elf_symfile_read (struct objfile *objfile, int mainline)
7573                                 str_sect->filepos,
7574                                 bfd_section_size (abfd, str_sect));
7575      }
7576 +
7577 +  if (dwarf2_has_info (objfile))
7578 +    dwarf2_create_quick_addrmap (objfile);
7579 +}
7580 +
7581 +static void
7582 +read_psyms (struct objfile *objfile)
7583 +{
7584    if (dwarf2_has_info (objfile))
7585      {
7586        /* DWARF 2 sections */
7587 -      dwarf2_build_psymtabs (objfile, mainline);
7588 +      dwarf2_build_psymtabs (objfile, 0);
7589      }
7590  
7591    /* FIXME: kettenis/20030504: This still needs to be integrated with
7592 @@ -881,6 +889,7 @@ static struct sym_fns elf_sym_fns =
7593    elf_new_init,                        /* sym_new_init: init anything gbl to entire symtab */
7594    elf_symfile_init,            /* sym_init: read initial info, setup for sym_read() */
7595    elf_symfile_read,            /* sym_read: read a symbol file into symtab */
7596 +  read_psyms,                  /* sym_read_psymbols */
7597    elf_symfile_finish,          /* sym_finish: finished with file, cleanup */
7598    default_symfile_offsets,     /* sym_offsets:  Translate ext. to int. relocation */
7599    elf_symfile_segments,                /* sym_segments: Get segment information from
7600 diff --git a/gdb/eval.c b/gdb/eval.c
7601 index 2926465..4c6de78 100644
7602 --- a/gdb/eval.c
7603 +++ b/gdb/eval.c
7604 @@ -39,8 +39,12 @@
7605  #include "exceptions.h"
7606  #include "regcache.h"
7607  #include "user-regs.h"
7608 +#include "python/python.h"
7609  #include "valprint.h"
7610 +#include "gdb_obstack.h"
7611 +#include "objfiles.h"
7612  #include "python/python.h"
7613 +#include "dwarf2loc.h"
7614  
7615  #include "gdb_assert.h"
7616  
7617 @@ -651,6 +655,36 @@ ptrmath_type_p (struct type *type)
7618      }
7619  }
7620  
7621 +/* Constructs a fake method with the given parameter types. */
7622 +static void
7623 +free_param_types (void *arg)
7624 +{
7625 +  struct type *type = (struct type *) arg;
7626 +  xfree (TYPE_FIELDS (type));
7627 +  xfree (TYPE_MAIN_TYPE (type));
7628 +  xfree (type);
7629 +}
7630 +
7631 +static struct type *
7632 +make_params (int num_types, struct type **param_types)
7633 +{
7634 +  struct type *type = XZALLOC (struct type);
7635 +  TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
7636 +  TYPE_LENGTH (type) = 1;
7637 +  TYPE_CODE (type) = TYPE_CODE_METHOD;
7638 +  TYPE_VPTR_FIELDNO (type) = -1;
7639 +  TYPE_CHAIN (type) = type;
7640 +  TYPE_NFIELDS (type) = num_types;
7641 +  TYPE_FIELDS (type) = (struct field *)
7642 +    TYPE_ZALLOC (type, sizeof (struct field) * num_types);
7643 +
7644 +  while (num_types-- > 0)
7645 +    TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
7646 +
7647 +  make_cleanup (free_param_types, type);
7648 +  return type;
7649 +}
7650 +
7651  struct value *
7652  evaluate_subexp_standard (struct type *expect_type,
7653                           struct expression *exp, int *pos,
7654 @@ -671,6 +705,7 @@ evaluate_subexp_standard (struct type *expect_type,
7655    long mem_offset;
7656    struct type **arg_types;
7657    int save_pos1;
7658 +  struct cleanup *old_chain;
7659  
7660    pc = (*pos)++;
7661    op = exp->elts[pc].opcode;
7662 @@ -684,7 +719,7 @@ evaluate_subexp_standard (struct type *expect_type,
7663         goto nosideret;
7664        arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
7665                                   &exp->elts[pc + 3].string,
7666 -                                 0, noside);
7667 +                                 expect_type, 0, noside);
7668        if (arg1 == NULL)
7669         error (_("There is no field named %s"), &exp->elts[pc + 3].string);
7670        return arg1;
7671 @@ -1293,7 +1328,6 @@ evaluate_subexp_standard (struct type *expect_type,
7672        argvec = (struct value **) alloca (sizeof (struct value *) * (nargs + 3));
7673        if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
7674         {
7675 -         nargs++;
7676           /* First, evaluate the structure into arg2 */
7677           pc2 = (*pos)++;
7678  
7679 @@ -1317,21 +1351,40 @@ evaluate_subexp_standard (struct type *expect_type,
7680  
7681           arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7682  
7683 -         if (TYPE_CODE (check_typedef (value_type (arg1)))
7684 -             != TYPE_CODE_METHODPTR)
7685 -           error (_("Non-pointer-to-member value used in pointer-to-member "
7686 -                    "construct"));
7687 -
7688 -         if (noside == EVAL_AVOID_SIDE_EFFECTS)
7689 +         type = check_typedef (value_type (arg1));
7690 +         switch (TYPE_CODE (type))
7691             {
7692 -             struct type *method_type = check_typedef (value_type (arg1));
7693 -             arg1 = value_zero (method_type, not_lval);
7694 +           case TYPE_CODE_METHODPTR:
7695 +             if (noside == EVAL_AVOID_SIDE_EFFECTS)
7696 +               arg1 = value_zero (TYPE_TARGET_TYPE (type), not_lval);
7697 +             else
7698 +               arg1 = cplus_method_ptr_to_value (&arg2, arg1);
7699 +
7700 +             /* Now, say which argument to start evaluating from */
7701 +             nargs++;
7702 +             tem = 2;
7703 +             argvec[1] = arg2;
7704 +             break;
7705 +
7706 +           case TYPE_CODE_MEMBERPTR:
7707 +             /* Now, convert these values to an address.  */
7708 +             arg2 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
7709 +                                arg2);
7710 +
7711 +             mem_offset = value_as_long (arg1);
7712 +
7713 +             arg1 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
7714 +                                        value_as_long (arg2) + mem_offset);
7715 +             arg1 = value_ind (arg1);
7716 +             tem = 1;
7717 +             break;
7718 +
7719 +           default:
7720 +             error (_("Non-pointer-to-member value used in pointer-to-member "
7721 +                      "construct"));
7722             }
7723 -         else
7724 -           arg1 = cplus_method_ptr_to_value (&arg2, arg1);
7725  
7726 -         /* Now, say which argument to start evaluating from */
7727 -         tem = 2;
7728 +         argvec[0] = arg1;
7729         }
7730        else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
7731         {
7732 @@ -1457,8 +1510,7 @@ evaluate_subexp_standard (struct type *expect_type,
7733         }
7734        else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
7735         {
7736 -         argvec[1] = arg2;
7737 -         argvec[0] = arg1;
7738 +         /* Pointer to member.  argvec is already set up.  */
7739         }
7740        else if (op == OP_VAR_VALUE)
7741         {
7742 @@ -1549,7 +1601,10 @@ evaluate_subexp_standard (struct type *expect_type,
7743  
7744        /* First determine the type code we are dealing with.  */
7745        arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7746 +      old_chain = make_cleanup (null_cleanup, 0);
7747 +      object_address_set (value_raw_address (arg1));
7748        type = check_typedef (value_type (arg1));
7749 +      do_cleanups (old_chain);
7750        code = TYPE_CODE (type);
7751  
7752        if (code == TYPE_CODE_PTR)
7753 @@ -1716,6 +1771,37 @@ evaluate_subexp_standard (struct type *expect_type,
7754           error (_("non-pointer-to-member value used in pointer-to-member construct"));
7755         }
7756  
7757 +    case TYPE_INSTANCE:
7758 +      nargs = longest_to_int (exp->elts[pc + 1].longconst);
7759 +      arg_types = (struct type **) alloca (nargs * sizeof (struct type *));
7760 +      for (ix = 0; ix < nargs; ++ix)
7761 +       arg_types[ix] = exp->elts[pc + 1 + ix + 1].type;
7762 +
7763 +      expect_type = make_params (nargs, arg_types);
7764 +      *(pos) += 3 + nargs;
7765 +      return evaluate_subexp_standard (expect_type, exp, pos, noside);
7766 +
7767 +    case TYPE_INSTANCE_LOOKUP:
7768 +      {
7769 +       int i;
7770 +       struct symbol *sym;
7771 +       struct type **arg_types;
7772 +       (*pos) += 3;
7773 +       printf ("TYPE_INSTANCE_LOOKUP\n");
7774 +       arg_types = (struct type **) alloca (TYPE_NFIELDS (expect_type)
7775 +                                            * sizeof (struct type *));
7776 +       for (i = 0; i < TYPE_NFIELDS (expect_type); ++i)
7777 +         arg_types[i] = TYPE_FIELD_TYPE (expect_type, i);
7778 +       (void) find_overload_match (arg_types, TYPE_NFIELDS (expect_type),
7779 +                                   NULL /* no need for name */,
7780 +                                   0 /* not method */,
7781 +                                   0 /* strict match */,
7782 +                                   NULL, exp->elts[pc + 1].symbol, NULL,
7783 +                                   &sym, NULL);
7784 +       i = 0;
7785 +      }
7786 +      break;
7787 +
7788      case BINOP_CONCAT:
7789        arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
7790        arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
7791 @@ -1987,13 +2073,19 @@ evaluate_subexp_standard (struct type *expect_type,
7792        {
7793         int subscript_array[MAX_FORTRAN_DIMS];
7794         int array_size_array[MAX_FORTRAN_DIMS];
7795 +       int byte_stride_array[MAX_FORTRAN_DIMS];
7796         int ndimensions = 1, i;
7797         struct type *tmp_type;
7798         int offset_item;        /* The array offset where the item lives */
7799 +       CORE_ADDR offset_byte;  /* byte_stride based offset  */
7800 +       unsigned element_size;
7801  
7802         if (nargs > MAX_FORTRAN_DIMS)
7803           error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
7804  
7805 +       old_chain = make_cleanup (null_cleanup, 0);
7806 +       object_address_set (value_raw_address (arg1));
7807 +
7808         tmp_type = check_typedef (value_type (arg1));
7809         ndimensions = calc_f77_array_dims (type);
7810  
7811 @@ -2023,6 +2115,9 @@ evaluate_subexp_standard (struct type *expect_type,
7812             upper = f77_get_upperbound (tmp_type);
7813             lower = f77_get_lowerbound (tmp_type);
7814  
7815 +           byte_stride_array[nargs - i - 1] =
7816 +                                       TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
7817 +
7818             array_size_array[nargs - i - 1] = upper - lower + 1;
7819  
7820             /* Zero-normalize subscripts so that offsetting will work. */
7821 @@ -2041,13 +2136,25 @@ evaluate_subexp_standard (struct type *expect_type,
7822               tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
7823           }
7824  
7825 +       /* Kept for the f77_get_upperbound / f77_get_lowerbound calls above.  */
7826 +       do_cleanups (old_chain);
7827 +
7828         /* Now let us calculate the offset for this item */
7829  
7830 -       offset_item = subscript_array[ndimensions - 1];
7831 +       offset_item = 0;
7832 +       offset_byte = 0;
7833 +
7834 +       for (i = ndimensions - 1; i >= 0; --i)
7835 +         {
7836 +           offset_item *= array_size_array[i];
7837 +           if (byte_stride_array[i] == 0)
7838 +             offset_item += subscript_array[i];
7839 +           else
7840 +             offset_byte += subscript_array[i] * byte_stride_array[i];
7841 +         }
7842  
7843 -       for (i = ndimensions - 1; i > 0; --i)
7844 -         offset_item =
7845 -           array_size_array[i - 1] * offset_item + subscript_array[i - 1];
7846 +       element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tmp_type));
7847 +       offset_byte += offset_item * element_size;
7848  
7849         /* Let us now play a dirty trick: we will take arg1 
7850            which is a value node pointing to the topmost level
7851 @@ -2057,7 +2164,7 @@ evaluate_subexp_standard (struct type *expect_type,
7852            returns the correct type value */
7853  
7854         deprecated_set_value_type (arg1, tmp_type);
7855 -       return value_subscripted_rvalue (arg1, offset_item, 0);
7856 +       return value_subscripted_rvalue (arg1, offset_byte);
7857        }
7858  
7859      case BINOP_LOGICAL_AND:
7860 @@ -2598,7 +2705,7 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
7861        (*pos) += 5 + BYTES_TO_EXP_ELEM (tem + 1);
7862        x = value_aggregate_elt (exp->elts[pc + 1].type,
7863                                &exp->elts[pc + 3].string,
7864 -                              1, noside);
7865 +                              NULL, 1, noside);
7866        if (x == NULL)
7867         error (_("There is no field named %s"), &exp->elts[pc + 3].string);
7868        return x;
7869 @@ -2643,7 +2750,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
7870  {
7871    enum exp_opcode op;
7872    int pc;
7873 -  struct value *val;
7874 +  struct value *val = NULL;
7875    struct symbol *var;
7876    struct type *type;
7877  
7878 @@ -2654,12 +2761,17 @@ evaluate_subexp_with_coercion (struct expression *exp,
7879      {
7880      case OP_VAR_VALUE:
7881        var = exp->elts[pc + 2].symbol;
7882 +      /* address_of_variable will call object_address_set for check_typedef.
7883 +        Call it only if required as it can error-out on VAR in register.  */
7884 +      if (TYPE_DYNAMIC (SYMBOL_TYPE (var)))
7885 +       val = address_of_variable (var, exp->elts[pc + 1].block);
7886        type = check_typedef (SYMBOL_TYPE (var));
7887        if (TYPE_CODE (type) == TYPE_CODE_ARRAY
7888           && CAST_IS_CONVERSION)
7889         {
7890           (*pos) += 4;
7891 -         val = address_of_variable (var, exp->elts[pc + 1].block);
7892 +         if (!val)
7893 +           val = address_of_variable (var, exp->elts[pc + 1].block);
7894           return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
7895                              val);
7896         }
7897 @@ -2711,9 +2823,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
7898  
7899      case OP_VAR_VALUE:
7900        (*pos) += 4;
7901 -      type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
7902 -      return
7903 -       value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
7904 +      /* We do not need to call read_var_value but the object evaluation may
7905 +        need to have executed object_address_set which needs valid
7906 +        SYMBOL_VALUE_ADDRESS of the symbol.  Still VALUE returned by
7907 +        read_var_value we left as lazy.  */
7908 +      type = value_type (read_var_value (exp->elts[pc + 2].symbol,
7909 +                                       deprecated_safe_get_selected_frame ()));
7910 +      return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
7911  
7912      default:
7913        val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
7914 diff --git a/gdb/expression.h b/gdb/expression.h
7915 index effe1f0..3e083ca 100644
7916 --- a/gdb/expression.h
7917 +++ b/gdb/expression.h
7918 @@ -88,6 +88,16 @@ enum exp_opcode
7919         when X is a pointer instead of an aggregate.  */
7920      STRUCTOP_MPTR,
7921  
7922 +    /* TYPE_INSTANCE is used when the user specifies a specific
7923 +       type instantiation for overloaded methods/functions. The format
7924 +       is: TYPE_INSTANCE num_types type0 ... typeN num_types TYPE_INSTANCE*/
7925 +    TYPE_INSTANCE,
7926 +
7927 +    /* TYPE_INSTANCE_LOOKUP is used when the user specifies a specific
7928 +       type instantiation of a function (not a method). In this case,
7929 +       we must toss the results of the parser and manually do the lookup. */
7930 +    TYPE_INSTANCE_LOOKUP,
7931 +
7932      /* end of C++.  */
7933  
7934      /* For Modula-2 integer division DIV */
7935 @@ -438,4 +448,5 @@ extern char *op_string (enum exp_opcode);
7936  extern void dump_raw_expression (struct expression *, struct ui_file *, char *);
7937  extern void dump_prefix_expression (struct expression *, struct ui_file *);
7938  
7939 +
7940  #endif /* !defined (EXPRESSION_H) */
7941 diff --git a/gdb/f-exp.y b/gdb/f-exp.y
7942 index c04c8f4..ddcd460 100644
7943 --- a/gdb/f-exp.y
7944 +++ b/gdb/f-exp.y
7945 @@ -196,6 +196,7 @@ static int parse_number (char *, int, int, YYSTYPE *);
7946  /* Special type cases, put in to allow the parser to distinguish different
7947     legal basetypes.  */
7948  %token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD 
7949 +%token LOGICAL_S8_KEYWORD 
7950  %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD 
7951  %token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD 
7952  %token BOOL_AND BOOL_OR BOOL_NOT   
7953 @@ -606,6 +607,8 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
7954                         { $$ = parse_f_type->builtin_integer_s2; }
7955         |       CHARACTER 
7956                         { $$ = parse_f_type->builtin_character; }
7957 +       |       LOGICAL_S8_KEYWORD
7958 +                       { $$ = parse_f_type->builtin_logical_s8;}
7959         |       LOGICAL_KEYWORD 
7960                         { $$ = parse_f_type->builtin_logical; }
7961         |       LOGICAL_S2_KEYWORD
7962 @@ -858,6 +861,7 @@ static const struct token f77_keywords[] =
7963    { "integer_2", INT_S2_KEYWORD, BINOP_END },
7964    { "logical_1", LOGICAL_S1_KEYWORD, BINOP_END },
7965    { "logical_2", LOGICAL_S2_KEYWORD, BINOP_END },
7966 +  { "logical_8", LOGICAL_S8_KEYWORD, BINOP_END },
7967    { "complex_8", COMPLEX_S8_KEYWORD, BINOP_END },
7968    { "integer", INT_KEYWORD, BINOP_END },
7969    { "logical", LOGICAL_KEYWORD, BINOP_END },
7970 diff --git a/gdb/f-lang.c b/gdb/f-lang.c
7971 index 19c1316..4cc2a40 100644
7972 --- a/gdb/f-lang.c
7973 +++ b/gdb/f-lang.c
7974 @@ -31,6 +31,8 @@
7975  #include "f-lang.h"
7976  #include "valprint.h"
7977  #include "value.h"
7978 +#include "block.h"
7979 +#include "gdb_assert.h"
7980  
7981  
7982  /* Following is dubious stuff that had been in the xcoff reader. */
7983 @@ -55,20 +57,6 @@ typedef struct saved_bf_symnum SAVED_BF, *SAVED_BF_PTR;
7984  /* Local functions */
7985  
7986  extern void _initialize_f_language (void);
7987 -#if 0
7988 -static void clear_function_list (void);
7989 -static long get_bf_for_fcn (long);
7990 -static void clear_bf_list (void);
7991 -static void patch_all_commons_by_name (char *, CORE_ADDR, int);
7992 -static SAVED_F77_COMMON_PTR find_first_common_named (char *);
7993 -static void add_common_entry (struct symbol *);
7994 -static void add_common_block (char *, CORE_ADDR, int, char *);
7995 -static SAVED_FUNCTION *allocate_saved_function_node (void);
7996 -static SAVED_BF_PTR allocate_saved_bf_node (void);
7997 -static COMMON_ENTRY_PTR allocate_common_entry_node (void);
7998 -static SAVED_F77_COMMON_PTR allocate_saved_f77_common_node (void);
7999 -static void patch_common_entries (SAVED_F77_COMMON_PTR, CORE_ADDR, int);
8000 -#endif
8001  
8002  static void f_printchar (int c, struct type *type, struct ui_file * stream);
8003  static void f_emit_char (int c, struct type *type,
8004 @@ -259,6 +247,7 @@ enum f_primitive_types {
8005    f_primitive_type_logical,
8006    f_primitive_type_logical_s1,
8007    f_primitive_type_logical_s2,
8008 +  f_primitive_type_logical_s8,
8009    f_primitive_type_integer,
8010    f_primitive_type_integer_s2,
8011    f_primitive_type_real,
8012 @@ -289,6 +278,8 @@ f_language_arch_info (struct gdbarch *gdbarch,
8013      = builtin->builtin_logical_s1;
8014    lai->primitive_type_vector [f_primitive_type_logical_s2]
8015      = builtin->builtin_logical_s2;
8016 +  lai->primitive_type_vector [f_primitive_type_logical_s8]
8017 +    = builtin->builtin_logical_s8;
8018    lai->primitive_type_vector [f_primitive_type_real]
8019      = builtin->builtin_real;
8020    lai->primitive_type_vector [f_primitive_type_real_s8]
8021 @@ -306,6 +297,46 @@ f_language_arch_info (struct gdbarch *gdbarch,
8022    lai->bool_type_default = builtin->builtin_logical_s2;
8023  }
8024  
8025 +/* Find if NAME is not contained in any of the Fortran modules imported by the
8026 +   Fortran USE statement.
8027 +
8028 +   As Fortran has no nested blocks such lookup can be processed from
8029 +   lookup_symbol_nonlocal - when no local blocks could satisfy the lookup.  */
8030 +
8031 +static struct symbol *
8032 +f_lookup_symbol_nonlocal (const char *name,
8033 +                         const struct block *block,
8034 +                         const domain_enum domain)
8035 +{
8036 +  struct fortran_using *use;
8037 +
8038 +  if (!block)
8039 +    return NULL;
8040 +
8041 +  for (use = BLOCK_FORTRAN_USE (block); use; use = use->next)
8042 +    {
8043 +      struct symbol *sym;
8044 +      struct type *type;
8045 +      struct symbol *retval;
8046 +
8047 +      sym = lookup_symbol_global (use->module_name, block, MODULE_DOMAIN);
8048 +
8049 +      /* Module name lookup should not fail with correct debug info.  */
8050 +      if (sym == NULL)
8051 +       continue;
8052 +
8053 +      type = SYMBOL_TYPE (sym);
8054 +      gdb_assert (TYPE_CODE (type) == TYPE_CODE_MODULE);
8055 +      gdb_assert (TYPE_MODULE_BLOCK (type) != NULL);
8056 +
8057 +      retval = lookup_block_symbol (TYPE_MODULE_BLOCK (type), name, domain);
8058 +      if (retval)
8059 +       return retval;
8060 +    }
8061 +
8062 +  return NULL;
8063 +}
8064 +
8065  /* This is declared in c-lang.h but it is silly to import that file for what
8066     is already just a hack. */
8067  extern int c_value_print (struct value *, struct ui_file *,
8068 @@ -333,7 +364,7 @@ const struct language_defn f_language_defn =
8069    c_value_print,               /* FIXME */
8070    NULL,                                /* Language specific skip_trampoline */
8071    NULL,                        /* name_of_this */
8072 -  basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
8073 +  f_lookup_symbol_nonlocal,    /* lookup_symbol_nonlocal */
8074    basic_lookup_transparent_type,/* lookup_transparent_type */
8075    NULL,                                /* Language specific symbol demangler */
8076    NULL,                                /* Language specific class_name_from_physname */
8077 @@ -372,6 +403,10 @@ build_fortran_types (struct gdbarch *gdbarch)
8078      = arch_boolean_type (gdbarch, gdbarch_short_bit (gdbarch), 1,
8079                          "logical*2");
8080  
8081 +  builtin_f_type->builtin_logical_s8
8082 +    = arch_boolean_type (gdbarch, gdbarch_long_long_bit (gdbarch), 1,
8083 +                        "logical*8");
8084 +
8085    builtin_f_type->builtin_integer
8086      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0,
8087                          "integer");
8088 @@ -418,395 +453,3 @@ _initialize_f_language (void)
8089  
8090    add_language (&f_language_defn);
8091  }
8092 -
8093 -#if 0
8094 -static SAVED_BF_PTR
8095 -allocate_saved_bf_node (void)
8096 -{
8097 -  SAVED_BF_PTR new;
8098 -
8099 -  new = (SAVED_BF_PTR) xmalloc (sizeof (SAVED_BF));
8100 -  return (new);
8101 -}
8102 -
8103 -static SAVED_FUNCTION *
8104 -allocate_saved_function_node (void)
8105 -{
8106 -  SAVED_FUNCTION *new;
8107 -
8108 -  new = (SAVED_FUNCTION *) xmalloc (sizeof (SAVED_FUNCTION));
8109 -  return (new);
8110 -}
8111 -
8112 -static SAVED_F77_COMMON_PTR
8113 -allocate_saved_f77_common_node (void)
8114 -{
8115 -  SAVED_F77_COMMON_PTR new;
8116 -
8117 -  new = (SAVED_F77_COMMON_PTR) xmalloc (sizeof (SAVED_F77_COMMON));
8118 -  return (new);
8119 -}
8120 -
8121 -static COMMON_ENTRY_PTR
8122 -allocate_common_entry_node (void)
8123 -{
8124 -  COMMON_ENTRY_PTR new;
8125 -
8126 -  new = (COMMON_ENTRY_PTR) xmalloc (sizeof (COMMON_ENTRY));
8127 -  return (new);
8128 -}
8129 -#endif
8130 -
8131 -SAVED_F77_COMMON_PTR head_common_list = NULL;  /* Ptr to 1st saved COMMON  */
8132 -SAVED_F77_COMMON_PTR tail_common_list = NULL;  /* Ptr to last saved COMMON  */
8133 -SAVED_F77_COMMON_PTR current_common = NULL;    /* Ptr to current COMMON */
8134 -
8135 -#if 0
8136 -static SAVED_BF_PTR saved_bf_list = NULL;      /* Ptr to (.bf,function) 
8137 -                                                  list */
8138 -static SAVED_BF_PTR saved_bf_list_end = NULL;  /* Ptr to above list's end */
8139 -static SAVED_BF_PTR current_head_bf_list = NULL;       /* Current head of above list
8140 -                                                        */
8141 -
8142 -static SAVED_BF_PTR tmp_bf_ptr;        /* Generic temporary for use 
8143 -                                  in macros */
8144 -
8145 -/* The following function simply enters a given common block onto 
8146 -   the global common block chain */
8147 -
8148 -static void
8149 -add_common_block (char *name, CORE_ADDR offset, int secnum, char *func_stab)
8150 -{
8151 -  SAVED_F77_COMMON_PTR tmp;
8152 -  char *c, *local_copy_func_stab;
8153 -
8154 -  /* If the COMMON block we are trying to add has a blank 
8155 -     name (i.e. "#BLNK_COM") then we set it to __BLANK
8156 -     because the darn "#" character makes GDB's input 
8157 -     parser have fits. */
8158 -
8159 -
8160 -  if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
8161 -      || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
8162 -    {
8163 -
8164 -      xfree (name);
8165 -      name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
8166 -      strcpy (name, BLANK_COMMON_NAME_LOCAL);
8167 -    }
8168 -
8169 -  tmp = allocate_saved_f77_common_node ();
8170 -
8171 -  local_copy_func_stab = xmalloc (strlen (func_stab) + 1);
8172 -  strcpy (local_copy_func_stab, func_stab);
8173 -
8174 -  tmp->name = xmalloc (strlen (name) + 1);
8175 -
8176 -  /* local_copy_func_stab is a stabstring, let us first extract the 
8177 -     function name from the stab by NULLing out the ':' character. */
8178 -
8179 -
8180 -  c = NULL;
8181 -  c = strchr (local_copy_func_stab, ':');
8182 -
8183 -  if (c)
8184 -    *c = '\0';
8185 -  else
8186 -    error (_("Malformed function STAB found in add_common_block()"));
8187 -
8188 -
8189 -  tmp->owning_function = xmalloc (strlen (local_copy_func_stab) + 1);
8190 -
8191 -  strcpy (tmp->owning_function, local_copy_func_stab);
8192 -
8193 -  strcpy (tmp->name, name);
8194 -  tmp->offset = offset;
8195 -  tmp->next = NULL;
8196 -  tmp->entries = NULL;
8197 -  tmp->secnum = secnum;
8198 -
8199 -  current_common = tmp;
8200 -
8201 -  if (head_common_list == NULL)
8202 -    {
8203 -      head_common_list = tail_common_list = tmp;
8204 -    }
8205 -  else
8206 -    {
8207 -      tail_common_list->next = tmp;
8208 -      tail_common_list = tmp;
8209 -    }
8210 -}
8211 -#endif
8212 -
8213 -/* The following function simply enters a given common entry onto 
8214 -   the "current_common" block that has been saved away. */
8215 -
8216 -#if 0
8217 -static void
8218 -add_common_entry (struct symbol *entry_sym_ptr)
8219 -{
8220 -  COMMON_ENTRY_PTR tmp;
8221 -
8222 -
8223 -
8224 -  /* The order of this list is important, since 
8225 -     we expect the entries to appear in decl.
8226 -     order when we later issue "info common" calls */
8227 -
8228 -  tmp = allocate_common_entry_node ();
8229 -
8230 -  tmp->next = NULL;
8231 -  tmp->symbol = entry_sym_ptr;
8232 -
8233 -  if (current_common == NULL)
8234 -    error (_("Attempt to add COMMON entry with no block open!"));
8235 -  else
8236 -    {
8237 -      if (current_common->entries == NULL)
8238 -       {
8239 -         current_common->entries = tmp;
8240 -         current_common->end_of_entries = tmp;
8241 -       }
8242 -      else
8243 -       {
8244 -         current_common->end_of_entries->next = tmp;
8245 -         current_common->end_of_entries = tmp;
8246 -       }
8247 -    }
8248 -}
8249 -#endif
8250 -
8251 -/* This routine finds the first encountred COMMON block named "name" */
8252 -
8253 -#if 0
8254 -static SAVED_F77_COMMON_PTR
8255 -find_first_common_named (char *name)
8256 -{
8257 -
8258 -  SAVED_F77_COMMON_PTR tmp;
8259 -
8260 -  tmp = head_common_list;
8261 -
8262 -  while (tmp != NULL)
8263 -    {
8264 -      if (strcmp (tmp->name, name) == 0)
8265 -       return (tmp);
8266 -      else
8267 -       tmp = tmp->next;
8268 -    }
8269 -  return (NULL);
8270 -}
8271 -#endif
8272 -
8273 -/* This routine finds the first encountred COMMON block named "name" 
8274 -   that belongs to function funcname */
8275 -
8276 -SAVED_F77_COMMON_PTR
8277 -find_common_for_function (char *name, char *funcname)
8278 -{
8279 -
8280 -  SAVED_F77_COMMON_PTR tmp;
8281 -
8282 -  tmp = head_common_list;
8283 -
8284 -  while (tmp != NULL)
8285 -    {
8286 -      if (strcmp (tmp->name, name) == 0
8287 -         && strcmp (tmp->owning_function, funcname) == 0)
8288 -       return (tmp);
8289 -      else
8290 -       tmp = tmp->next;
8291 -    }
8292 -  return (NULL);
8293 -}
8294 -
8295 -
8296 -#if 0
8297 -
8298 -/* The following function is called to patch up the offsets 
8299 -   for the statics contained in the COMMON block named
8300 -   "name."  */
8301 -
8302 -static void
8303 -patch_common_entries (SAVED_F77_COMMON_PTR blk, CORE_ADDR offset, int secnum)
8304 -{
8305 -  COMMON_ENTRY_PTR entry;
8306 -
8307 -  blk->offset = offset;                /* Keep this around for future use. */
8308 -
8309 -  entry = blk->entries;
8310 -
8311 -  while (entry != NULL)
8312 -    {
8313 -      SYMBOL_VALUE (entry->symbol) += offset;
8314 -      SYMBOL_SECTION (entry->symbol) = secnum;
8315 -
8316 -      entry = entry->next;
8317 -    }
8318 -  blk->secnum = secnum;
8319 -}
8320 -
8321 -/* Patch all commons named "name" that need patching.Since COMMON
8322 -   blocks occur with relative infrequency, we simply do a linear scan on
8323 -   the name.  Eventually, the best way to do this will be a
8324 -   hashed-lookup.  Secnum is the section number for the .bss section
8325 -   (which is where common data lives). */
8326 -
8327 -static void
8328 -patch_all_commons_by_name (char *name, CORE_ADDR offset, int secnum)
8329 -{
8330 -
8331 -  SAVED_F77_COMMON_PTR tmp;
8332 -
8333 -  /* For blank common blocks, change the canonical reprsentation 
8334 -     of a blank name */
8335 -
8336 -  if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
8337 -      || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
8338 -    {
8339 -      xfree (name);
8340 -      name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
8341 -      strcpy (name, BLANK_COMMON_NAME_LOCAL);
8342 -    }
8343 -
8344 -  tmp = head_common_list;
8345 -
8346 -  while (tmp != NULL)
8347 -    {
8348 -      if (COMMON_NEEDS_PATCHING (tmp))
8349 -       if (strcmp (tmp->name, name) == 0)
8350 -         patch_common_entries (tmp, offset, secnum);
8351 -
8352 -      tmp = tmp->next;
8353 -    }
8354 -}
8355 -#endif
8356 -
8357 -/* This macro adds the symbol-number for the start of the function 
8358 -   (the symbol number of the .bf) referenced by symnum_fcn to a 
8359 -   list.  This list, in reality should be a FIFO queue but since 
8360 -   #line pragmas sometimes cause line ranges to get messed up 
8361 -   we simply create a linear list.  This list can then be searched 
8362 -   first by a queueing algorithm and upon failure fall back to 
8363 -   a linear scan. */
8364 -
8365 -#if 0
8366 -#define ADD_BF_SYMNUM(bf_sym,fcn_sym) \
8367 -  \
8368 -  if (saved_bf_list == NULL) \
8369 -{ \
8370 -    tmp_bf_ptr = allocate_saved_bf_node(); \
8371 -      \
8372 -       tmp_bf_ptr->symnum_bf = (bf_sym); \
8373 -         tmp_bf_ptr->symnum_fcn = (fcn_sym);  \
8374 -           tmp_bf_ptr->next = NULL; \
8375 -             \
8376 -               current_head_bf_list = saved_bf_list = tmp_bf_ptr; \
8377 -                 saved_bf_list_end = tmp_bf_ptr; \
8378 -                 } \
8379 -else \
8380 -{  \
8381 -     tmp_bf_ptr = allocate_saved_bf_node(); \
8382 -       \
8383 -         tmp_bf_ptr->symnum_bf = (bf_sym);  \
8384 -          tmp_bf_ptr->symnum_fcn = (fcn_sym);  \
8385 -            tmp_bf_ptr->next = NULL;  \
8386 -              \
8387 -                saved_bf_list_end->next = tmp_bf_ptr;  \
8388 -                  saved_bf_list_end = tmp_bf_ptr; \
8389 -                  }
8390 -#endif
8391 -
8392 -/* This function frees the entire (.bf,function) list */
8393 -
8394 -#if 0
8395 -static void
8396 -clear_bf_list (void)
8397 -{
8398 -
8399 -  SAVED_BF_PTR tmp = saved_bf_list;
8400 -  SAVED_BF_PTR next = NULL;
8401 -
8402 -  while (tmp != NULL)
8403 -    {
8404 -      next = tmp->next;
8405 -      xfree (tmp);
8406 -      tmp = next;
8407 -    }
8408 -  saved_bf_list = NULL;
8409 -}
8410 -#endif
8411 -
8412 -int global_remote_debug;
8413 -
8414 -#if 0
8415 -
8416 -static long
8417 -get_bf_for_fcn (long the_function)
8418 -{
8419 -  SAVED_BF_PTR tmp;
8420 -  int nprobes = 0;
8421 -
8422 -  /* First use a simple queuing algorithm (i.e. look and see if the 
8423 -     item at the head of the queue is the one you want)  */
8424 -
8425 -  if (saved_bf_list == NULL)
8426 -    internal_error (__FILE__, __LINE__,
8427 -                   _("cannot get .bf node off empty list"));
8428 -
8429 -  if (current_head_bf_list != NULL)
8430 -    if (current_head_bf_list->symnum_fcn == the_function)
8431 -      {
8432 -       if (global_remote_debug)
8433 -         fprintf_unfiltered (gdb_stderr, "*");
8434 -
8435 -       tmp = current_head_bf_list;
8436 -       current_head_bf_list = current_head_bf_list->next;
8437 -       return (tmp->symnum_bf);
8438 -      }
8439 -
8440 -  /* If the above did not work (probably because #line directives were 
8441 -     used in the sourcefile and they messed up our internal tables) we now do
8442 -     the ugly linear scan */
8443 -
8444 -  if (global_remote_debug)
8445 -    fprintf_unfiltered (gdb_stderr, "\ndefaulting to linear scan\n");
8446 -
8447 -  nprobes = 0;
8448 -  tmp = saved_bf_list;
8449 -  while (tmp != NULL)
8450 -    {
8451 -      nprobes++;
8452 -      if (tmp->symnum_fcn == the_function)
8453 -       {
8454 -         if (global_remote_debug)
8455 -           fprintf_unfiltered (gdb_stderr, "Found in %d probes\n", nprobes);
8456 -         current_head_bf_list = tmp->next;
8457 -         return (tmp->symnum_bf);
8458 -       }
8459 -      tmp = tmp->next;
8460 -    }
8461 -
8462 -  return (-1);
8463 -}
8464 -
8465 -static SAVED_FUNCTION_PTR saved_function_list = NULL;
8466 -static SAVED_FUNCTION_PTR saved_function_list_end = NULL;
8467 -
8468 -static void
8469 -clear_function_list (void)
8470 -{
8471 -  SAVED_FUNCTION_PTR tmp = saved_function_list;
8472 -  SAVED_FUNCTION_PTR next = NULL;
8473 -
8474 -  while (tmp != NULL)
8475 -    {
8476 -      next = tmp->next;
8477 -      xfree (tmp);
8478 -      tmp = next;
8479 -    }
8480 -
8481 -  saved_function_list = NULL;
8482 -}
8483 -#endif
8484 diff --git a/gdb/f-lang.h b/gdb/f-lang.h
8485 index 711bdba..9d7d92b 100644
8486 --- a/gdb/f-lang.h
8487 +++ b/gdb/f-lang.h
8488 @@ -28,6 +28,10 @@ extern void f_error (char *);        /* Defined in f-exp.y */
8489  extern void f_print_type (struct type *, char *, struct ui_file *, int,
8490                           int);
8491  
8492 +extern const char *f_object_address_data_valid_print_to_stream
8493 +  (struct type *type, struct ui_file *stream);
8494 +extern void f_object_address_data_valid_or_error (struct type *type);
8495 +
8496  extern int f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
8497                         struct ui_file *, int,
8498                         const struct value_print_options *);
8499 @@ -47,41 +51,8 @@ enum f90_range_type
8500      NONE_BOUND_DEFAULT         /* "(low:high)"  */
8501    };
8502  
8503 -struct common_entry
8504 -  {
8505 -    struct symbol *symbol;     /* The symbol node corresponding
8506 -                                  to this component */
8507 -    struct common_entry *next; /* The next component */
8508 -  };
8509 -
8510 -struct saved_f77_common
8511 -  {
8512 -    char *name;                        /* Name of COMMON */
8513 -    char *owning_function;     /* Name of parent function */
8514 -    int secnum;                        /* Section # of .bss */
8515 -    CORE_ADDR offset;          /* Offset from .bss for 
8516 -                                  this block */
8517 -    struct common_entry *entries;      /* List of block's components */
8518 -    struct common_entry *end_of_entries;       /* ptr. to end of components */
8519 -    struct saved_f77_common *next;     /* Next saved COMMON block */
8520 -  };
8521 -
8522 -typedef struct saved_f77_common SAVED_F77_COMMON, *SAVED_F77_COMMON_PTR;
8523 -
8524 -typedef struct common_entry COMMON_ENTRY, *COMMON_ENTRY_PTR;
8525 -
8526 -extern SAVED_F77_COMMON_PTR head_common_list;  /* Ptr to 1st saved COMMON  */
8527 -extern SAVED_F77_COMMON_PTR tail_common_list;  /* Ptr to last saved COMMON  */
8528 -extern SAVED_F77_COMMON_PTR current_common;    /* Ptr to current COMMON */
8529 -
8530 -extern SAVED_F77_COMMON_PTR find_common_for_function (char *, char *);
8531 -
8532 -#define UNINITIALIZED_SECNUM -1
8533 -#define COMMON_NEEDS_PATCHING(blk) ((blk)->secnum == UNINITIALIZED_SECNUM)
8534 -
8535  #define BLANK_COMMON_NAME_ORIGINAL "#BLNK_COM" /* XLF assigned  */
8536  #define BLANK_COMMON_NAME_MF77     "__BLNK__"  /* MF77 assigned  */
8537 -#define BLANK_COMMON_NAME_LOCAL    "__BLANK"   /* Local GDB */
8538  
8539  /* When reasonable array bounds cannot be fetched, such as when 
8540     you ask to 'mt print symbols' and there is no stack frame and 
8541 @@ -113,6 +84,7 @@ struct builtin_f_type
8542    struct type *builtin_logical;
8543    struct type *builtin_logical_s1;
8544    struct type *builtin_logical_s2;
8545 +  struct type *builtin_logical_s8;
8546    struct type *builtin_real;
8547    struct type *builtin_real_s8;
8548    struct type *builtin_real_s16;
8549 @@ -125,3 +97,10 @@ struct builtin_f_type
8550  /* Return the Fortran type table for the specified architecture.  */
8551  extern const struct builtin_f_type *builtin_f_type (struct gdbarch *gdbarch);
8552  
8553 +/* List of module names being imported by a block though BLOCK_FORTRAN_USE.  */
8554 +
8555 +struct fortran_using
8556 +  {
8557 +    struct fortran_using *next;
8558 +    char module_name[1];
8559 +  };
8560 diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
8561 index 6c9668f..852b9a8 100644
8562 --- a/gdb/f-typeprint.c
8563 +++ b/gdb/f-typeprint.c
8564 @@ -31,7 +31,7 @@
8565  #include "gdbcore.h"
8566  #include "target.h"
8567  #include "f-lang.h"
8568 -
8569 +#include "dwarf2loc.h"
8570  #include "gdb_string.h"
8571  #include <errno.h>
8572  
8573 @@ -48,6 +48,34 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
8574  void f_type_print_base (struct type *, struct ui_file *, int, int);
8575  \f
8576  
8577 +const char *
8578 +f_object_address_data_valid_print_to_stream (struct type *type,
8579 +                                            struct ui_file *stream)
8580 +{
8581 +  const char *msg;
8582 +
8583 +  msg = object_address_data_not_valid (type);
8584 +  if (msg != NULL)
8585 +    {
8586 +      /* Assuming the content printed to STREAM should not be localized.  */
8587 +      fprintf_filtered (stream, "<%s>", msg);
8588 +    }
8589 +
8590 +  return msg;
8591 +}
8592 +
8593 +void
8594 +f_object_address_data_valid_or_error (struct type *type)
8595 +{
8596 +  const char *msg;
8597 +
8598 +  msg = object_address_data_not_valid (type);
8599 +  if (msg != NULL)
8600 +    {
8601 +      error (_("Cannot access it because the %s."), _(msg));
8602 +    }
8603 +}
8604 +
8605  /* LEVEL is the depth to indent lines by.  */
8606  
8607  void
8608 @@ -57,6 +85,9 @@ f_print_type (struct type *type, char *varstring, struct ui_file *stream,
8609    enum type_code code;
8610    int demangled_args;
8611  
8612 +  if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
8613 +    return;
8614 +
8615    f_type_print_base (type, stream, show, level);
8616    code = TYPE_CODE (type);
8617    if ((varstring != NULL && *varstring != '\0')
8618 @@ -166,6 +197,9 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
8619  
8620    QUIT;
8621  
8622 +  if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
8623 +    CHECK_TYPEDEF (type);
8624 +
8625    switch (TYPE_CODE (type))
8626      {
8627      case TYPE_CODE_ARRAY:
8628 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
8629 index 0a57404..a9ccc77 100644
8630 --- a/gdb/f-valprint.c
8631 +++ b/gdb/f-valprint.c
8632 @@ -34,10 +34,8 @@
8633  #include "gdbcore.h"
8634  #include "command.h"
8635  #include "block.h"
8636 -
8637 -#if 0
8638 -static int there_is_a_visible_common_named (char *);
8639 -#endif
8640 +#include "dictionary.h"
8641 +#include "gdb_assert.h"
8642  
8643  extern void _initialize_f_valprint (void);
8644  static void info_common_command (char *, int);
8645 @@ -54,15 +52,17 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
8646  /* The following macro gives us the size of the nth dimension, Where 
8647     n is 1 based. */
8648  
8649 -#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
8650 +#define F77_DIM_COUNT(n) (f77_array_offset_tbl[n][1])
8651  
8652 -/* The following gives us the offset for row n where n is 1-based. */
8653 +/* The following gives us the element size for row n where n is 1-based. */
8654  
8655 -#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
8656 +#define F77_DIM_BYTE_STRIDE(n) (f77_array_offset_tbl[n][0])
8657  
8658  int
8659  f77_get_lowerbound (struct type *type)
8660  {
8661 +  f_object_address_data_valid_or_error (type);
8662 +
8663    if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
8664      error (_("Lower bound may not be '*' in F77"));
8665  
8666 @@ -72,14 +72,17 @@ f77_get_lowerbound (struct type *type)
8667  int
8668  f77_get_upperbound (struct type *type)
8669  {
8670 +  f_object_address_data_valid_or_error (type);
8671 +
8672    if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
8673      {
8674 -      /* We have an assumed size array on our hands.  Assume that
8675 -        upper_bound == lower_bound so that we show at least 1 element.
8676 -        If the user wants to see more elements, let him manually ask for 'em
8677 -        and we'll subscript the array and show him.  */
8678 +      /* We have an assumed size array on our hands.  As type_length_get
8679 +        already assumes a length zero of arrays with underfined bounds VALADDR
8680 +        passed to the Fortran functions does not contained the real inferior
8681 +        memory content.  User should request printing of specific array
8682 +        elements instead.  */
8683  
8684 -      return f77_get_lowerbound (type);
8685 +      return f77_get_lowerbound (type) - 1;
8686      }
8687  
8688    return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
8689 @@ -135,24 +138,29 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
8690        upper = f77_get_upperbound (tmp_type);
8691        lower = f77_get_lowerbound (tmp_type);
8692  
8693 -      F77_DIM_SIZE (ndimen) = upper - lower + 1;
8694 +      F77_DIM_COUNT (ndimen) = upper - lower + 1;
8695 +
8696 +      F77_DIM_BYTE_STRIDE (ndimen) =
8697 +        TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
8698  
8699        tmp_type = TYPE_TARGET_TYPE (tmp_type);
8700        ndimen++;
8701      }
8702  
8703 -  /* Now we multiply eltlen by all the offsets, so that later we 
8704 +  /* Now we multiply eltlen by all the BYTE_STRIDEs, so that later we
8705       can print out array elements correctly.  Up till now we 
8706 -     know an offset to apply to get the item but we also 
8707 +     know an eltlen to apply to get the item but we also
8708       have to know how much to add to get to the next item */
8709  
8710    ndimen--;
8711    eltlen = TYPE_LENGTH (tmp_type);
8712 -  F77_DIM_OFFSET (ndimen) = eltlen;
8713 +  if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
8714 +    F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
8715    while (--ndimen > 0)
8716      {
8717 -      eltlen *= F77_DIM_SIZE (ndimen + 1);
8718 -      F77_DIM_OFFSET (ndimen) = eltlen;
8719 +      eltlen *= F77_DIM_COUNT (ndimen + 1);
8720 +      if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
8721 +       F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
8722      }
8723  }
8724  
8725 @@ -172,34 +180,34 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
8726  
8727    if (nss != ndimensions)
8728      {
8729 -      for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max); i++)
8730 +      for (i = 0; (i < F77_DIM_COUNT (nss) && (*elts) < options->print_max); i++)
8731         {
8732           fprintf_filtered (stream, "( ");
8733           f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
8734 -                            valaddr + i * F77_DIM_OFFSET (nss),
8735 -                            address + i * F77_DIM_OFFSET (nss),
8736 +                            valaddr + i * F77_DIM_BYTE_STRIDE (nss),
8737 +                            address + i * F77_DIM_BYTE_STRIDE (nss),
8738                              stream, recurse, options, elts);
8739           fprintf_filtered (stream, ") ");
8740         }
8741 -      if (*elts >= options->print_max && i < F77_DIM_SIZE (nss)) 
8742 +      if (*elts >= options->print_max && i < F77_DIM_COUNT (nss))
8743         fprintf_filtered (stream, "...");
8744      }
8745    else
8746      {
8747 -      for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max;
8748 +      for (i = 0; i < F77_DIM_COUNT (nss) && (*elts) < options->print_max;
8749            i++, (*elts)++)
8750         {
8751           val_print (TYPE_TARGET_TYPE (type),
8752 -                    valaddr + i * F77_DIM_OFFSET (ndimensions),
8753 +                    valaddr + i * F77_DIM_BYTE_STRIDE (ndimensions),
8754                      0,
8755 -                    address + i * F77_DIM_OFFSET (ndimensions),
8756 +                    address + i * F77_DIM_BYTE_STRIDE (ndimensions),
8757                      stream, recurse, options, current_language);
8758  
8759 -         if (i != (F77_DIM_SIZE (nss) - 1))
8760 +         if (i != (F77_DIM_COUNT (nss) - 1))
8761             fprintf_filtered (stream, ", ");
8762  
8763           if ((*elts == options->print_max - 1)
8764 -             && (i != (F77_DIM_SIZE (nss) - 1)))
8765 +             && (i != (F77_DIM_COUNT (nss) - 1)))
8766             fprintf_filtered (stream, "...");
8767         }
8768      }
8769 @@ -253,6 +261,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
8770    CORE_ADDR addr;
8771    int index;
8772  
8773 +  if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
8774 +    return 0;
8775 +
8776    CHECK_TYPEDEF (type);
8777    switch (TYPE_CODE (type))
8778      {
8779 @@ -467,22 +478,54 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
8780    return 0;
8781  }
8782  
8783 -static void
8784 -list_all_visible_commons (char *funname)
8785 +static int
8786 +info_common_command_for_block (struct block *block, struct frame_info *frame,
8787 +                              const char *comname)
8788  {
8789 -  SAVED_F77_COMMON_PTR tmp;
8790 -
8791 -  tmp = head_common_list;
8792 -
8793 -  printf_filtered (_("All COMMON blocks visible at this level:\n\n"));
8794 -
8795 -  while (tmp != NULL)
8796 -    {
8797 -      if (strcmp (tmp->owning_function, funname) == 0)
8798 -       printf_filtered ("%s\n", tmp->name);
8799 -
8800 -      tmp = tmp->next;
8801 -    }
8802 +  struct dict_iterator iter;
8803 +  struct symbol *sym;
8804 +  int values_printed = 0;
8805 +  const char *name;
8806 +  struct value_print_options opts;
8807 +
8808 +  get_user_print_options (&opts);
8809 +
8810 +  ALL_BLOCK_SYMBOLS (block, iter, sym)
8811 +    if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
8812 +      {
8813 +       struct type *type = SYMBOL_TYPE (sym);
8814 +       int index;
8815 +
8816 +       gdb_assert (SYMBOL_CLASS (sym) == LOC_STATIC);
8817 +       gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
8818 +
8819 +       if (comname && (!SYMBOL_LINKAGE_NAME (sym)
8820 +                       || strcmp (comname, SYMBOL_LINKAGE_NAME (sym)) != 0))
8821 +         continue;
8822 +
8823 +       values_printed = 1;
8824 +       if (SYMBOL_PRINT_NAME (sym))
8825 +         printf_filtered (_("Contents of F77 COMMON block '%s':\n"),
8826 +                          SYMBOL_PRINT_NAME (sym));
8827 +       else
8828 +         printf_filtered (_("Contents of blank COMMON block:\n"));
8829 +       
8830 +       for (index = 0; index < TYPE_NFIELDS (type); index++)
8831 +         {
8832 +           struct value *val;
8833 +
8834 +           gdb_assert (field_is_static (&TYPE_FIELD (type, index)));
8835 +           val = value_static_field (type, index);
8836 +
8837 +           printf_filtered ("%s = ", TYPE_FIELD_NAME (type, index));
8838 +           value_print (val, gdb_stdout, &opts);
8839 +           putchar_filtered ('\n');
8840 +         }
8841 +
8842 +       putchar_filtered ('\n');
8843 +      }
8844 +
8845 +  return values_printed;
8846  }
8847  
8848  /* This function is used to print out the values in a given COMMON 
8849 @@ -492,11 +535,9 @@ list_all_visible_commons (char *funname)
8850  static void
8851  info_common_command (char *comname, int from_tty)
8852  {
8853 -  SAVED_F77_COMMON_PTR the_common;
8854 -  COMMON_ENTRY_PTR entry;
8855    struct frame_info *fi;
8856 -  char *funname = 0;
8857 -  struct symbol *func;
8858 +  struct block *block;
8859 +  int values_printed = 0;
8860  
8861    /* We have been told to display the contents of F77 COMMON 
8862       block supposedly visible in this function.  Let us 
8863 @@ -508,136 +549,32 @@ info_common_command (char *comname, int from_tty)
8864    /* The following is generally ripped off from stack.c's routine 
8865       print_frame_info() */
8866  
8867 -  func = find_pc_function (get_frame_pc (fi));
8868 -  if (func)
8869 -    {
8870 -      /* In certain pathological cases, the symtabs give the wrong
8871 -         function (when we are in the first function in a file which
8872 -         is compiled without debugging symbols, the previous function
8873 -         is compiled with debugging symbols, and the "foo.o" symbol
8874 -         that is supposed to tell us where the file with debugging symbols
8875 -         ends has been truncated by ar because it is longer than 15
8876 -         characters).
8877 -
8878 -         So look in the minimal symbol tables as well, and if it comes
8879 -         up with a larger address for the function use that instead.
8880 -         I don't think this can ever cause any problems; there shouldn't
8881 -         be any minimal symbols in the middle of a function.
8882 -         FIXME:  (Not necessarily true.  What about text labels) */
8883 -
8884 -      struct minimal_symbol *msymbol = 
8885 -       lookup_minimal_symbol_by_pc (get_frame_pc (fi));
8886 -
8887 -      if (msymbol != NULL
8888 -         && (SYMBOL_VALUE_ADDRESS (msymbol)
8889 -             > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
8890 -       funname = SYMBOL_LINKAGE_NAME (msymbol);
8891 -      else
8892 -       funname = SYMBOL_LINKAGE_NAME (func);
8893 -    }
8894 -  else
8895 -    {
8896 -      struct minimal_symbol *msymbol =
8897 -      lookup_minimal_symbol_by_pc (get_frame_pc (fi));
8898 -
8899 -      if (msymbol != NULL)
8900 -       funname = SYMBOL_LINKAGE_NAME (msymbol);
8901 -      else /* Got no 'funname', code below will fail.  */
8902 -       error (_("No function found for frame."));
8903 -    }
8904 -
8905 -  /* If comname is NULL, we assume the user wishes to see the 
8906 -     which COMMON blocks are visible here and then return */
8907 -
8908 -  if (comname == 0)
8909 +  block = get_frame_block (fi, 0);
8910 +  if (block == NULL)
8911      {
8912 -      list_all_visible_commons (funname);
8913 +      printf_filtered (_("No symbol table info available.\n"));
8914        return;
8915      }
8916  
8917 -  the_common = find_common_for_function (comname, funname);
8918 -
8919 -  if (the_common)
8920 +  while (block)
8921      {
8922 -      if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0)
8923 -       printf_filtered (_("Contents of blank COMMON block:\n"));
8924 -      else
8925 -       printf_filtered (_("Contents of F77 COMMON block '%s':\n"), comname);
8926 -
8927 -      printf_filtered ("\n");
8928 -      entry = the_common->entries;
8929 -
8930 -      while (entry != NULL)
8931 -       {
8932 -         print_variable_and_value (NULL, entry->symbol, fi, gdb_stdout, 0);
8933 -         entry = entry->next;
8934 -       }
8935 +      if (info_common_command_for_block (block, fi, comname))
8936 +       values_printed = 1;
8937 +      /* After handling the function's top-level block, stop.  Don't
8938 +         continue to its superblock, the block of per-file symbols.  */
8939 +      if (BLOCK_FUNCTION (block))
8940 +       break;
8941 +      block = BLOCK_SUPERBLOCK (block);
8942      }
8943 -  else
8944 -    printf_filtered (_("Cannot locate the common block %s in function '%s'\n"),
8945 -                    comname, funname);
8946 -}
8947 -
8948 -/* This function is used to determine whether there is a
8949 -   F77 common block visible at the current scope called 'comname'. */
8950 -
8951 -#if 0
8952 -static int
8953 -there_is_a_visible_common_named (char *comname)
8954 -{
8955 -  SAVED_F77_COMMON_PTR the_common;
8956 -  struct frame_info *fi;
8957 -  char *funname = 0;
8958 -  struct symbol *func;
8959 -
8960 -  if (comname == NULL)
8961 -    error (_("Cannot deal with NULL common name!"));
8962  
8963 -  fi = get_selected_frame (_("No frame selected"));
8964 -
8965 -  /* The following is generally ripped off from stack.c's routine 
8966 -     print_frame_info() */
8967 -
8968 -  func = find_pc_function (fi->pc);
8969 -  if (func)
8970 +  if (!values_printed)
8971      {
8972 -      /* In certain pathological cases, the symtabs give the wrong
8973 -         function (when we are in the first function in a file which
8974 -         is compiled without debugging symbols, the previous function
8975 -         is compiled with debugging symbols, and the "foo.o" symbol
8976 -         that is supposed to tell us where the file with debugging symbols
8977 -         ends has been truncated by ar because it is longer than 15
8978 -         characters).
8979 -
8980 -         So look in the minimal symbol tables as well, and if it comes
8981 -         up with a larger address for the function use that instead.
8982 -         I don't think this can ever cause any problems; there shouldn't
8983 -         be any minimal symbols in the middle of a function.
8984 -         FIXME:  (Not necessarily true.  What about text labels) */
8985 -
8986 -      struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
8987 -
8988 -      if (msymbol != NULL
8989 -         && (SYMBOL_VALUE_ADDRESS (msymbol)
8990 -             > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
8991 -       funname = SYMBOL_LINKAGE_NAME (msymbol);
8992 +      if (comname)
8993 +       printf_filtered (_("No common block '%s'.\n"), comname);
8994        else
8995 -       funname = SYMBOL_LINKAGE_NAME (func);
8996 +       printf_filtered (_("No common blocks.\n"));
8997      }
8998 -  else
8999 -    {
9000 -      struct minimal_symbol *msymbol =
9001 -      lookup_minimal_symbol_by_pc (fi->pc);
9002 -
9003 -      if (msymbol != NULL)
9004 -       funname = SYMBOL_LINKAGE_NAME (msymbol);
9005 -    }
9006 -
9007 -  the_common = find_common_for_function (comname, funname);
9008 -
9009 -  return (the_common ? 1 : 0);
9010  }
9011 -#endif
9012  
9013  void
9014  _initialize_f_valprint (void)
9015 diff --git a/gdb/findcmd.c b/gdb/findcmd.c
9016 index 1d28914..d176341 100644
9017 --- a/gdb/findcmd.c
9018 +++ b/gdb/findcmd.c
9019 @@ -27,7 +27,7 @@
9020  
9021  /* Copied from bfd_put_bits.  */
9022  
9023 -static void
9024 +void
9025  put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
9026  {
9027    int i;
9028 @@ -45,6 +45,41 @@ put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
9029      }
9030  }
9031  
9032 +/* Allocates a buffer in *PATTERN_BUF, with a hard-coded initial size which
9033 +   will be returned in *PATTERN_BUF_SIZE. *PATTERN_BUF_END points to the same
9034 +   place as *PATTERN_BUF, indicating that the buffer is initially empty.  */
9035 +
9036 +void
9037 +allocate_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
9038 +                        ULONGEST *pattern_buf_size)
9039 +{
9040 +#define INITIAL_PATTERN_BUF_SIZE 100
9041 +  *pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
9042 +  *pattern_buf = xmalloc (*pattern_buf_size);
9043 +  *pattern_buf_end = *pattern_buf;
9044 +}
9045 +
9046 +/* Grows *PATTERN_BUF by a factor of two if it's not large enough to hold
9047 +   VAL_BYTES more bytes  or a 64-bit value, whichever is larger.
9048 +   *PATTERN_BUF_END is updated as necessary.  */
9049 +
9050 +void
9051 +increase_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
9052 +                        ULONGEST *pattern_buf_size, int val_bytes)
9053 +{
9054 +    /* Keep it simple and assume size == 'g' when watching for when we
9055 +       need to grow the pattern buf.  */
9056 +    if ((*pattern_buf_end - *pattern_buf + max (val_bytes, sizeof (int64_t)))
9057 +       > *pattern_buf_size)
9058 +      {
9059 +       size_t current_offset = *pattern_buf_end - *pattern_buf;
9060 +
9061 +       *pattern_buf_size *= 2;
9062 +       *pattern_buf = xrealloc (*pattern_buf, *pattern_buf_size);
9063 +       *pattern_buf_end = *pattern_buf + current_offset;
9064 +      }
9065 +}
9066 +
9067  /* Subroutine of find_command to simplify it.
9068     Parse the arguments of the "find" command.  */
9069  
9070 @@ -61,8 +96,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
9071    char *pattern_buf;
9072    /* Current size of search pattern buffer.
9073       We realloc space as needed.  */
9074 -#define INITIAL_PATTERN_BUF_SIZE 100
9075 -  ULONGEST pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
9076 +  ULONGEST pattern_buf_size;
9077    /* Pointer to one past the last in-use part of pattern_buf.  */
9078    char *pattern_buf_end;
9079    ULONGEST pattern_len;
9080 @@ -75,8 +109,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
9081    if (args == NULL)
9082      error (_("Missing search parameters."));
9083  
9084 -  pattern_buf = xmalloc (pattern_buf_size);
9085 -  pattern_buf_end = pattern_buf;
9086 +  allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
9087    old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
9088  
9089    /* Get search granularity and/or max count if specified.
9090 @@ -173,16 +206,8 @@ parse_find_args (char *args, ULONGEST *max_countp,
9091        v = parse_to_comma_and_eval (&s);
9092        val_bytes = TYPE_LENGTH (value_type (v));
9093  
9094 -      /* Keep it simple and assume size == 'g' when watching for when we
9095 -        need to grow the pattern buf.  */
9096 -      if ((pattern_buf_end - pattern_buf + max (val_bytes, sizeof (int64_t)))
9097 -         > pattern_buf_size)
9098 -       {
9099 -         size_t current_offset = pattern_buf_end - pattern_buf;
9100 -         pattern_buf_size *= 2;
9101 -         pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
9102 -         pattern_buf_end = pattern_buf + current_offset;
9103 -       }
9104 +      increase_pattern_buffer (&pattern_buf, &pattern_buf_end,
9105 +                              &pattern_buf_size, val_bytes);
9106  
9107        if (size != '\0')
9108         {
9109 @@ -237,6 +262,45 @@ parse_find_args (char *args, ULONGEST *max_countp,
9110    discard_cleanups (old_cleanups);
9111  }
9112  
9113 +/* Drives target_search_memory to sweep through the specified search space,
9114 +   possibly in several iterations (with one call to this function for each
9115 +   iteration).  *START_ADDR is the address where the search starts, and is
9116 +   updated to the next starting address to continue the search.
9117 +   *SEARCH_SPACE_LEN is the amount of bytes which will be searched, and is
9118 +   updated for the next iteration. PATTERN_BUF holds the pattern to be searched
9119 +   for, PATTERN_LEN is the size of the pattern in bytes.  If a match is found,
9120 +   it's address is put in *FOUND_ADDR.
9121 +
9122 +   Returns 1 if found, 0 if not found, and -1 if there was an error requiring
9123 +   halting of the search (e.g. memory read error).  */
9124 +
9125 +int
9126 +search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
9127 +              const char *pattern_buf, ULONGEST pattern_len,
9128 +              CORE_ADDR *found_addr)
9129 +{
9130 +  /* Offset from start of this iteration to the next iteration.  */
9131 +  ULONGEST next_iter_incr;
9132 +  int found;
9133 +    
9134 +  found = target_search_memory (*start_addr, *search_space_len,
9135 +                               pattern_buf, pattern_len, found_addr);
9136 +  if (found <= 0)
9137 +    return found;
9138 +
9139 +  /* Begin next iteration at one byte past this match.  */
9140 +  next_iter_incr = (*found_addr - *start_addr) + 1;
9141 +
9142 +  /* For robustness, we don't let search_space_len go -ve here.  */
9143 +  if (*search_space_len >= next_iter_incr)
9144 +    *search_space_len -= next_iter_incr;
9145 +  else
9146 +    *search_space_len = 0;
9147 +  *start_addr += next_iter_incr;
9148 +
9149 +  return found;
9150 +}
9151 +
9152  static void
9153  find_command (char *args, int from_tty)
9154  {
9155 @@ -267,12 +331,11 @@ find_command (char *args, int from_tty)
9156    while (search_space_len >= pattern_len
9157          && found_count < max_count)
9158      {
9159 -      /* Offset from start of this iteration to the next iteration.  */
9160 -      ULONGEST next_iter_incr;
9161        CORE_ADDR found_addr;
9162 -      int found = target_search_memory (start_addr, search_space_len,
9163 -                                       pattern_buf, pattern_len, &found_addr);
9164 +      int found;
9165  
9166 +      found = search_memory (&start_addr, &search_space_len, pattern_buf,
9167 +                            pattern_len, &found_addr);
9168        if (found <= 0)
9169         break;
9170  
9171 @@ -280,16 +343,6 @@ find_command (char *args, int from_tty)
9172        printf_filtered ("\n");
9173        ++found_count;
9174        last_found_addr = found_addr;
9175 -
9176 -      /* Begin next iteration at one byte past this match.  */
9177 -      next_iter_incr = (found_addr - start_addr) + 1;
9178 -
9179 -      /* For robustness, we don't let search_space_len go -ve here.  */
9180 -      if (search_space_len >= next_iter_incr)
9181 -       search_space_len -= next_iter_incr;
9182 -      else
9183 -       search_space_len = 0;
9184 -      start_addr += next_iter_incr;
9185      }
9186  
9187    /* Record and print the results.  */
9188 diff --git a/gdb/findvar.c b/gdb/findvar.c
9189 index 8c027c9..d201f76 100644
9190 --- a/gdb/findvar.c
9191 +++ b/gdb/findvar.c
9192 @@ -35,6 +35,7 @@
9193  #include "user-regs.h"
9194  #include "block.h"
9195  #include "objfiles.h"
9196 +#include "dwarf2loc.h"
9197  
9198  /* Basic byte-swapping routines.  GDB has needed these for a long time...
9199     All extract a target-format integer at ADDR which is LEN bytes long.  */
9200 @@ -394,27 +395,16 @@ symbol_read_needs_frame (struct symbol *sym)
9201  /* Given a struct symbol for a variable,
9202     and a stack frame id, read the value of the variable
9203     and return a (pointer to a) struct value containing the value. 
9204 -   If the variable cannot be found, return a zero pointer.  */
9205 +   If the variable cannot be found, return a zero pointer.
9206 +   We have to first find the address of the variable before allocating struct
9207 +   value to return as its size may depend on DW_OP_PUSH_OBJECT_ADDRESS possibly
9208 +   used by its type.  */
9209  
9210  struct value *
9211  read_var_value (struct symbol *var, struct frame_info *frame)
9212  {
9213 -  struct value *v;
9214    struct type *type = SYMBOL_TYPE (var);
9215    CORE_ADDR addr;
9216 -  int len;
9217 -
9218 -  if (SYMBOL_CLASS (var) == LOC_COMPUTED
9219 -      || SYMBOL_CLASS (var) == LOC_REGISTER)
9220 -    /* These cases do not use V.  */
9221 -    v = NULL;
9222 -  else
9223 -    {
9224 -      v = allocate_value (type);
9225 -      VALUE_LVAL (v) = lval_memory;    /* The most likely possibility.  */
9226 -    }
9227 -
9228 -  len = TYPE_LENGTH (type);
9229  
9230    if (symbol_read_needs_frame (var))
9231      gdb_assert (frame);
9232 @@ -422,32 +412,40 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9233    switch (SYMBOL_CLASS (var))
9234      {
9235      case LOC_CONST:
9236 -      /* Put the constant back in target format.  */
9237 -      store_signed_integer (value_contents_raw (v), len,
9238 -                           gdbarch_byte_order (get_type_arch (type)),
9239 -                           (LONGEST) SYMBOL_VALUE (var));
9240 -      VALUE_LVAL (v) = not_lval;
9241 -      return v;
9242 +      {
9243 +       /* Put the constant back in target format.  */
9244 +       struct value *v = allocate_value (type);
9245 +       VALUE_LVAL (v) = not_lval;
9246 +       store_signed_integer (value_contents_raw (v), TYPE_LENGTH (type),
9247 +                             gdbarch_byte_order (get_type_arch (type)),
9248 +                             (LONGEST) SYMBOL_VALUE (var));
9249 +       return v;
9250 +      }
9251  
9252      case LOC_LABEL:
9253 -      /* Put the constant back in target format.  */
9254 -      if (overlay_debugging)
9255 -       {
9256 -         CORE_ADDR addr
9257 -           = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
9258 -                                       SYMBOL_OBJ_SECTION (var));
9259 -         store_typed_address (value_contents_raw (v), type, addr);
9260 -       }
9261 -      else
9262 -       store_typed_address (value_contents_raw (v), type,
9263 -                             SYMBOL_VALUE_ADDRESS (var));
9264 -      VALUE_LVAL (v) = not_lval;
9265 -      return v;
9266 +      {
9267 +       /* Put the constant back in target format.  */
9268 +       struct value *v = allocate_value (type);
9269 +       VALUE_LVAL (v) = not_lval;
9270 +       if (overlay_debugging)
9271 +         {
9272 +           CORE_ADDR addr
9273 +             = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
9274 +                                         SYMBOL_OBJ_SECTION (var));
9275 +           store_typed_address (value_contents_raw (v), type, addr);
9276 +         }
9277 +       else
9278 +         store_typed_address (value_contents_raw (v), type,
9279 +                               SYMBOL_VALUE_ADDRESS (var));
9280 +       return v;
9281 +      }
9282  
9283      case LOC_CONST_BYTES:
9284        {
9285 -       memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var), len);
9286 +       struct value *v = allocate_value (type);
9287         VALUE_LVAL (v) = not_lval;
9288 +       memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var),
9289 +               TYPE_LENGTH (type));
9290         return v;
9291        }
9292  
9293 @@ -489,12 +487,23 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9294        break;
9295  
9296      case LOC_BLOCK:
9297 -      if (overlay_debugging)
9298 -       set_value_address (v, symbol_overlayed_address
9299 -         (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var)));
9300 -      else
9301 -       set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (var)));
9302 -      return v;
9303 +      {
9304 +        CORE_ADDR addr;
9305 +       struct value *v;
9306 +
9307 +       if (overlay_debugging)
9308 +         addr = symbol_overlayed_address
9309 +           (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var));
9310 +       else
9311 +         addr = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
9312 +       /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
9313 +          DW_OP_push_object_address.  */
9314 +       object_address_set (addr);
9315 +       v = allocate_value (type);
9316 +       VALUE_LVAL (v) = lval_memory;
9317 +       set_value_address (v, addr);
9318 +       return v;
9319 +      }
9320  
9321      case LOC_REGISTER:
9322      case LOC_REGPARM_ADDR:
9323 @@ -513,7 +522,6 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9324               error (_("Value of register variable not available."));
9325  
9326             addr = value_as_address (regval);
9327 -           VALUE_LVAL (v) = lval_memory;
9328           }
9329         else
9330           {
9331 @@ -556,18 +564,33 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9332        break;
9333  
9334      case LOC_OPTIMIZED_OUT:
9335 -      VALUE_LVAL (v) = not_lval;
9336 -      set_value_optimized_out (v, 1);
9337 -      return v;
9338 +      {
9339 +        struct value *v = allocate_value (type);
9340 +
9341 +       VALUE_LVAL (v) = not_lval;
9342 +       set_value_optimized_out (v, 1);
9343 +       return v;
9344 +      }
9345  
9346      default:
9347        error (_("Cannot look up value of a botched symbol."));
9348        break;
9349      }
9350  
9351 -  set_value_address (v, addr);
9352 -  set_value_lazy (v, 1);
9353 -  return v;
9354 +  {
9355 +    struct value *v;
9356 +
9357 +    /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
9358 +       DW_OP_PUSH_OBJECT_ADDRESS.  */
9359 +    object_address_set (addr);
9360 +    v = allocate_value (type);
9361 +    VALUE_LVAL (v) = lval_memory;
9362 +    set_value_address (v, addr);
9363 +
9364 +    set_value_lazy (v, 1);
9365 +
9366 +    return v;
9367 +  }
9368  }
9369  
9370  /* Install default attributes for register values.  */
9371 @@ -604,10 +627,11 @@ struct value *
9372  value_from_register (struct type *type, int regnum, struct frame_info *frame)
9373  {
9374    struct gdbarch *gdbarch = get_frame_arch (frame);
9375 -  struct type *type1 = check_typedef (type);
9376    struct value *v;
9377  
9378 -  if (gdbarch_convert_register_p (gdbarch, regnum, type1))
9379 +  type = check_typedef (type);
9380 +
9381 +  if (gdbarch_convert_register_p (gdbarch, regnum, type))
9382      {
9383        /* The ISA/ABI need to something weird when obtaining the
9384           specified value from this register.  It might need to
9385 @@ -621,7 +645,7 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
9386        VALUE_FRAME_ID (v) = get_frame_id (frame);
9387        VALUE_REGNUM (v) = regnum;
9388        gdbarch_register_to_value (gdbarch,
9389 -                                frame, regnum, type1, value_contents_raw (v));
9390 +                                frame, regnum, type, value_contents_raw (v));
9391      }
9392    else
9393      {
9394 diff --git a/gdb/frame.c b/gdb/frame.c
9395 index 7932b48..4e7c434 100644
9396 --- a/gdb/frame.c
9397 +++ b/gdb/frame.c
9398 @@ -1171,6 +1171,14 @@ has_stack_frames (void)
9399    if (ptid_equal (inferior_ptid, null_ptid))
9400      return 0;
9401  
9402 +  /* FIXME: Workaround archer-tromey-python crash in
9403 +     add_inferior_object->get_current_arch on FSF GDB update:
9404 +     is_thread_state would assertion check here as
9405 +     remote_start_remote->add_inferior_silent->observer_notify_new_inferior is
9406 +     before remote_start_remote->add_thread_silent.  */
9407 +  if (find_thread_ptid (inferior_ptid) == NULL)
9408 +    return 0;
9409 +
9410    /* Don't try to read from a dead thread.  */
9411    if (is_exited (inferior_ptid))
9412      return 0;
9413 diff --git a/gdb/gdbinit.in b/gdb/gdbinit.in
9414 index ffb7f53..a2e7e94 100644
9415 --- a/gdb/gdbinit.in
9416 +++ b/gdb/gdbinit.in
9417 @@ -1,5 +1,15 @@
9418  echo Setting up the environment for debugging gdb.\n
9419  
9420 +# Set up the Python library and "require" command.
9421 +python
9422 +from os.path import abspath
9423 +gdb.datadir = abspath ('@srcdir@/python/lib')
9424 +gdb.pythonlibdir = gdb.datadir
9425 +gdb.__path__ = [gdb.datadir + '/gdb']
9426 +sys.path.insert(0, gdb.datadir)
9427 +end
9428 +source @srcdir@/python/lib/gdb/__init__.py
9429 +
9430  set complaints 1
9431  
9432  b internal_error
9433 diff --git a/gdb/gdbserver/linux-i386-low.c b/gdb/gdbserver/linux-i386-low.c
9434 new file mode 100644
9435 index 0000000..b95c1b1
9436 --- /dev/null
9437 +++ b/gdb/gdbserver/linux-i386-low.c
9438 @@ -0,0 +1,210 @@
9439 +/* GNU/Linux/i386 specific low level interface, for the remote server for GDB.
9440 +   Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
9441 +   2007, 2008, 2009 Free Software Foundation, Inc.
9442 +
9443 +   This file is part of GDB.
9444 +
9445 +   This program is free software; you can redistribute it and/or modify
9446 +   it under the terms of the GNU General Public License as published by
9447 +   the Free Software Foundation; either version 3 of the License, or
9448 +   (at your option) any later version.
9449 +
9450 +   This program is distributed in the hope that it will be useful,
9451 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
9452 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9453 +   GNU General Public License for more details.
9454 +
9455 +   You should have received a copy of the GNU General Public License
9456 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
9457 +
9458 +#include "server.h"
9459 +#include "linux-low.h"
9460 +#include "i387-fp.h"
9461 +
9462 +#include "gdb_proc_service.h"
9463 +
9464 +#include <sys/ptrace.h>
9465 +
9466 +#ifdef HAVE_SYS_REG_H
9467 +#include <sys/reg.h>
9468 +#endif
9469 +
9470 +#ifndef PTRACE_GET_THREAD_AREA
9471 +#define PTRACE_GET_THREAD_AREA 25
9472 +#endif
9473 +
9474 +/* Defined in auto-generated file reg-i386-linux.c.  */
9475 +void init_registers_i386_linux (void);
9476 +
9477 +
9478 +/* This module only supports access to the general purpose registers.  */
9479 +
9480 +#define i386_num_regs 16
9481 +
9482 +/* This stuff comes from i386-linux-nat.c.  */
9483 +
9484 +/* Mapping between the general-purpose registers in `struct user'
9485 +   format and GDB's register array layout.  */
9486 +static int i386_regmap[] = 
9487 +{
9488 +  EAX * 4, ECX * 4, EDX * 4, EBX * 4,
9489 +  UESP * 4, EBP * 4, ESI * 4, EDI * 4,
9490 +  EIP * 4, EFL * 4, CS * 4, SS * 4,
9491 +  DS * 4, ES * 4, FS * 4, GS * 4
9492 +};
9493 +
9494 +/* Called by libthread_db.  */
9495 +
9496 +ps_err_e
9497 +ps_get_thread_area (const struct ps_prochandle *ph, 
9498 +                   lwpid_t lwpid, int idx, void **base)
9499 +{
9500 +  unsigned int desc[4];
9501 +
9502 +  if (ptrace (PTRACE_GET_THREAD_AREA, lwpid,
9503 +             (void *) idx, (unsigned long) &desc) < 0)
9504 +    return PS_ERR;
9505 +
9506 +  *(int *)base = desc[1];
9507 +  return PS_OK;
9508 +}
9509 +
9510 +static int
9511 +i386_cannot_store_register (int regno)
9512 +{
9513 +  return (regno >= i386_num_regs);
9514 +}
9515 +
9516 +static int
9517 +i386_cannot_fetch_register (int regno)
9518 +{
9519 +  return (regno >= i386_num_regs);
9520 +}
9521 +
9522 +
9523 +#ifdef HAVE_PTRACE_GETREGS
9524 +#include <sys/procfs.h>
9525 +#include <sys/ptrace.h>
9526 +
9527 +static void
9528 +i386_fill_gregset (void *buf)
9529 +{
9530 +  int i;
9531 +
9532 +  for (i = 0; i < i386_num_regs; i++)
9533 +    collect_register (i, ((char *) buf) + i386_regmap[i]);
9534 +
9535 +  collect_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
9536 +}
9537 +
9538 +static void
9539 +i386_store_gregset (const void *buf)
9540 +{
9541 +  int i;
9542 +
9543 +  for (i = 0; i < i386_num_regs; i++)
9544 +    supply_register (i, ((char *) buf) + i386_regmap[i]);
9545 +
9546 +  supply_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
9547 +}
9548 +
9549 +static void
9550 +i386_fill_fpregset (void *buf)
9551 +{
9552 +  i387_cache_to_fsave (buf);
9553 +}
9554 +
9555 +static void
9556 +i386_store_fpregset (const void *buf)
9557 +{
9558 +  i387_fsave_to_cache (buf);
9559 +}
9560 +
9561 +static void
9562 +i386_fill_fpxregset (void *buf)
9563 +{
9564 +  i387_cache_to_fxsave (buf);
9565 +}
9566 +
9567 +static void
9568 +i386_store_fpxregset (const void *buf)
9569 +{
9570 +  i387_fxsave_to_cache (buf);
9571 +}
9572 +
9573 +#endif /* HAVE_PTRACE_GETREGS */
9574 +
9575 +struct regset_info target_regsets[] = {
9576 +#ifdef HAVE_PTRACE_GETREGS
9577 +  { PTRACE_GETREGS, PTRACE_SETREGS, sizeof (elf_gregset_t),
9578 +    GENERAL_REGS,
9579 +    i386_fill_gregset, i386_store_gregset },
9580 +# ifdef HAVE_PTRACE_GETFPXREGS
9581 +  { PTRACE_GETFPXREGS, PTRACE_SETFPXREGS, sizeof (elf_fpxregset_t),
9582 +    EXTENDED_REGS,
9583 +    i386_fill_fpxregset, i386_store_fpxregset },
9584 +# endif
9585 +  { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof (elf_fpregset_t),
9586 +    FP_REGS,
9587 +    i386_fill_fpregset, i386_store_fpregset },
9588 +#endif /* HAVE_PTRACE_GETREGS */
9589 +  { 0, 0, -1, -1, NULL, NULL }
9590 +};
9591 +
9592 +static const unsigned char i386_breakpoint[] = { 0xCC };
9593 +#define i386_breakpoint_len 1
9594 +
9595 +extern int debug_threads;
9596 +
9597 +static CORE_ADDR
9598 +i386_get_pc ()
9599 +{
9600 +  unsigned long pc;
9601 +
9602 +  collect_register_by_name ("eip", &pc);
9603 +
9604 +  if (debug_threads)
9605 +    fprintf (stderr, "stop pc (before any decrement) is %08lx\n", pc);
9606 +  return pc;
9607 +}
9608 +
9609 +static void
9610 +i386_set_pc (CORE_ADDR newpc)
9611 +{
9612 +  if (debug_threads)
9613 +    fprintf (stderr, "set pc to %08lx\n", (long) newpc);
9614 +  supply_register_by_name ("eip", &newpc);
9615 +}
9616 +
9617 +static int
9618 +i386_breakpoint_at (CORE_ADDR pc)
9619 +{
9620 +  unsigned char c;
9621 +
9622 +  read_inferior_memory (pc, &c, 1);
9623 +  if (c == 0xCC)
9624 +    return 1;
9625 +
9626 +  return 0;
9627 +}
9628 +
9629 +struct linux_target_ops the_low_target = {
9630 +  init_registers_i386_linux,
9631 +  i386_num_regs,
9632 +  i386_regmap,
9633 +  i386_cannot_fetch_register,
9634 +  i386_cannot_store_register,
9635 +  i386_get_pc,
9636 +  i386_set_pc,
9637 +  i386_breakpoint,
9638 +  i386_breakpoint_len,
9639 +  NULL,
9640 +  1,
9641 +  i386_breakpoint_at,
9642 +  NULL,
9643 +  NULL,
9644 +  NULL,
9645 +  NULL,
9646 +  NULL,
9647 +  NULL,
9648 +};
9649 diff --git a/gdb/gdbserver/linux-x86-64-low.c b/gdb/gdbserver/linux-x86-64-low.c
9650 new file mode 100644
9651 index 0000000..b8213f5
9652 --- /dev/null
9653 +++ b/gdb/gdbserver/linux-x86-64-low.c
9654 @@ -0,0 +1,184 @@
9655 +/* GNU/Linux/x86-64 specific low level interface, for the remote server
9656 +   for GDB.
9657 +   Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009
9658 +   Free Software Foundation, Inc.
9659 +
9660 +   This file is part of GDB.
9661 +
9662 +   This program is free software; you can redistribute it and/or modify
9663 +   it under the terms of the GNU General Public License as published by
9664 +   the Free Software Foundation; either version 3 of the License, or
9665 +   (at your option) any later version.
9666 +
9667 +   This program is distributed in the hope that it will be useful,
9668 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
9669 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9670 +   GNU General Public License for more details.
9671 +
9672 +   You should have received a copy of the GNU General Public License
9673 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
9674 +
9675 +#include "server.h"
9676 +#include "linux-low.h"
9677 +#include "i387-fp.h"
9678 +
9679 +#include "gdb_proc_service.h"
9680 +
9681 +/* Defined in auto-generated file reg-x86-64-linux.c.  */
9682 +void init_registers_x86_64_linux (void);
9683 +
9684 +#include <sys/reg.h>
9685 +#include <sys/procfs.h>
9686 +#include <sys/ptrace.h>
9687 +
9688 +/* This definition comes from prctl.h, but some kernels may not have it.  */
9689 +#ifndef PTRACE_ARCH_PRCTL
9690 +#define PTRACE_ARCH_PRCTL      30
9691 +#endif
9692 +
9693 +/* The following definitions come from prctl.h, but may be absent
9694 +   for certain configurations.  */
9695 +#ifndef ARCH_GET_FS
9696 +#define ARCH_SET_GS 0x1001
9697 +#define ARCH_SET_FS 0x1002
9698 +#define ARCH_GET_FS 0x1003
9699 +#define ARCH_GET_GS 0x1004
9700 +#endif
9701 +
9702 +static int x86_64_regmap[] = {
9703 +  RAX * 8, RBX * 8, RCX * 8, RDX * 8,
9704 +  RSI * 8, RDI * 8, RBP * 8, RSP * 8,
9705 +  R8 * 8, R9 * 8, R10 * 8, R11 * 8,
9706 +  R12 * 8, R13 * 8, R14 * 8, R15 * 8,
9707 +  RIP * 8, EFLAGS * 8, CS * 8, SS * 8, 
9708 +  DS * 8, ES * 8, FS * 8, GS * 8,
9709 +  -1, -1, -1, -1, -1, -1, -1, -1,
9710 +  -1, -1, -1, -1, -1, -1, -1, -1,
9711 +  -1, -1, -1, -1, -1, -1, -1, -1,
9712 +  -1, -1, -1, -1, -1, -1, -1, -1, -1,
9713 +  ORIG_RAX * 8
9714 +};
9715 +
9716 +#define X86_64_NUM_GREGS (sizeof(x86_64_regmap)/sizeof(int))
9717 +
9718 +/* Called by libthread_db.  */
9719 +
9720 +ps_err_e
9721 +ps_get_thread_area (const struct ps_prochandle *ph,
9722 +                    lwpid_t lwpid, int idx, void **base)
9723 +{
9724 +  switch (idx)
9725 +    {
9726 +    case FS:
9727 +      if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0)
9728 +       return PS_OK;
9729 +      break;
9730 +    case GS:
9731 +      if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0)
9732 +       return PS_OK;
9733 +      break;
9734 +    default:
9735 +      return PS_BADADDR;
9736 +    }
9737 +  return PS_ERR;
9738 +}
9739 +
9740 +static void
9741 +x86_64_fill_gregset (void *buf)
9742 +{
9743 +  int i;
9744 +
9745 +  for (i = 0; i < X86_64_NUM_GREGS; i++)
9746 +    if (x86_64_regmap[i] != -1)
9747 +      collect_register (i, ((char *) buf) + x86_64_regmap[i]);
9748 +}
9749 +
9750 +static void
9751 +x86_64_store_gregset (const void *buf)
9752 +{
9753 +  int i;
9754 +
9755 +  for (i = 0; i < X86_64_NUM_GREGS; i++)
9756 +    if (x86_64_regmap[i] != -1)
9757 +      supply_register (i, ((char *) buf) + x86_64_regmap[i]);
9758 +}
9759 +
9760 +static void
9761 +x86_64_fill_fpregset (void *buf)
9762 +{
9763 +  i387_cache_to_fxsave (buf);
9764 +}
9765 +
9766 +static void
9767 +x86_64_store_fpregset (const void *buf)
9768 +{
9769 +  i387_fxsave_to_cache (buf);
9770 +}
9771 +
9772 +struct regset_info target_regsets[] = {
9773 +  { PTRACE_GETREGS, PTRACE_SETREGS, sizeof (elf_gregset_t),
9774 +    GENERAL_REGS,
9775 +    x86_64_fill_gregset, x86_64_store_gregset },
9776 +  { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof (elf_fpregset_t),
9777 +    FP_REGS,
9778 +    x86_64_fill_fpregset, x86_64_store_fpregset },
9779 +  { 0, 0, -1, -1, NULL, NULL }
9780 +};
9781 +
9782 +static const unsigned char x86_64_breakpoint[] = { 0xCC };
9783 +#define x86_64_breakpoint_len 1
9784 +                
9785 +extern int debug_threads;
9786 +
9787 +static CORE_ADDR
9788 +x86_64_get_pc ()
9789 +{
9790 +  unsigned long pc;
9791 +
9792 +  collect_register_by_name ("rip", &pc);
9793 +
9794 +  if (debug_threads)
9795 +    fprintf (stderr, "stop pc (before any decrement) is %08lx\n", pc);
9796 +  return pc;
9797 +}
9798 +
9799 +static void
9800 +x86_64_set_pc (CORE_ADDR newpc)
9801 +{
9802 +  if (debug_threads)
9803 +    fprintf (stderr, "set pc to %08lx\n", (long) newpc);
9804 +  supply_register_by_name ("rip", &newpc);
9805 +}
9806 +
9807 +static int
9808 +x86_64_breakpoint_at (CORE_ADDR pc)
9809 +{
9810 +  unsigned char c;
9811 +
9812 +  read_inferior_memory (pc, &c, 1);
9813 +  if (c == 0xCC)
9814 +    return 1;
9815 +
9816 +  return 0;
9817 +}
9818 +
9819 +struct linux_target_ops the_low_target = {
9820 +  init_registers_x86_64_linux,
9821 +  -1,
9822 +  NULL,
9823 +  NULL,
9824 +  NULL,
9825 +  x86_64_get_pc,
9826 +  x86_64_set_pc,
9827 +  x86_64_breakpoint,  
9828 +  x86_64_breakpoint_len,
9829 +  NULL,                                 
9830 +  1,
9831 +  x86_64_breakpoint_at,
9832 +  NULL,
9833 +  NULL,
9834 +  NULL,
9835 +  NULL,
9836 +  NULL,
9837 +  NULL,
9838 +};
9839 diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
9840 index 79d33fe..d3b4fa1 100644
9841 --- a/gdb/gdbthread.h
9842 +++ b/gdb/gdbthread.h
9843 @@ -185,6 +185,10 @@ struct thread_info
9844    /* True if this thread has been explicitly requested to stop.  */
9845    int stop_requested;
9846  
9847 +  /* The initiating frame of a nexting operation, used for deciding
9848 +     which exceptions to intercept.  */
9849 +  struct frame_id initiating_frame;
9850 +
9851    /* Private data used by the target vector implementation.  */
9852    struct private_thread_info *private;
9853  };
9854 @@ -249,6 +253,9 @@ extern struct thread_info *any_thread_of_process (int pid);
9855  /* Change the ptid of thread OLD_PTID to NEW_PTID.  */
9856  void thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid);
9857  
9858 +/* Prune dead threads from the list of threads.  */
9859 +extern void prune_threads (void);
9860 +
9861  /* Iterator function to call a user-provided callback function
9862     once for each known thread.  */
9863  typedef int (*thread_callback_func) (struct thread_info *, void *);
9864 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
9865 index 2f77dca..90abf2c 100644
9866 --- a/gdb/gdbtypes.c
9867 +++ b/gdb/gdbtypes.c
9868 @@ -38,6 +38,9 @@
9869  #include "cp-abi.h"
9870  #include "gdb_assert.h"
9871  #include "hashtab.h"
9872 +#include "observer.h"
9873 +#include "dwarf2expr.h"
9874 +#include "dwarf2loc.h"
9875  
9876  
9877  /* Floatformat pairs.  */
9878 @@ -118,13 +121,31 @@ static void print_arg_types (struct field *, int, int);
9879  static void dump_fn_fieldlists (struct type *, int);
9880  static void print_cplus_stuff (struct type *, int);
9881  
9882 +/* A reference count structure for the type reference count map.  Each
9883 +   type in a hierarchy of types is mapped to the same reference
9884 +   count.  */
9885 +struct type_refc_entry
9886 +{
9887 +  /* One type in the hierarchy.  Each type in the hierarchy gets its
9888 +     own slot.  */
9889 +  struct type *type;
9890 +
9891 +  /* A pointer to the shared reference count.  */
9892 +  int *refc;
9893 +};
9894 +
9895 +/* The hash table holding all discardable `struct type *' references.  */
9896 +static htab_t type_discardable_table;
9897 +
9898 +/* Current type_discardable_check pass used for TYPE_DISCARDABLE_AGE.  */
9899 +static int type_discardable_age_current;
9900  
9901  /* Allocate a new OBJFILE-associated type structure and fill it
9902     with some defaults.  Space for the type structure is allocated
9903     on the objfile's objfile_obstack.  */
9904  
9905  struct type *
9906 -alloc_type (struct objfile *objfile)
9907 +alloc_type (struct objfile *objfile, struct type *parent)
9908  {
9909    struct type *type;
9910  
9911 @@ -148,6 +169,39 @@ alloc_type (struct objfile *objfile)
9912    return type;
9913  }
9914  
9915 +/* Declare TYPE as discardable on next garbage collection by free_all_types.
9916 +   You must call type_mark_used during each free_all_types to protect TYPE from
9917 +   being deallocated.  */
9918 +
9919 +static void
9920 +set_type_as_discardable (struct type *type)
9921 +{
9922 +  void **slot;
9923 +
9924 +  gdb_assert (!TYPE_DISCARDABLE (type));
9925 +
9926 +  TYPE_DISCARDABLE (type) = 1;
9927 +  TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
9928 +
9929 +  slot = htab_find_slot (type_discardable_table, type, INSERT);
9930 +  gdb_assert (!*slot);
9931 +  *slot = type;
9932 +}
9933 +
9934 +/* Allocate a new type like alloc_type but preserve for it the discardability
9935 +   state of PARENT_TYPE.  */
9936 +
9937 +static struct type *
9938 +alloc_type_as_parent (struct type *parent_type)
9939 +{
9940 +  struct type *new_type = alloc_type_copy (parent_type);
9941 +
9942 +  if (TYPE_DISCARDABLE (parent_type))
9943 +    set_type_as_discardable (new_type);
9944 +
9945 +  return new_type;
9946 +}
9947 +
9948  /* Allocate a new GDBARCH-associated type structure and fill it
9949     with some defaults.  Space for the type structure is allocated
9950     on the heap.  */
9951 @@ -184,7 +238,7 @@ struct type *
9952  alloc_type_copy (const struct type *type)
9953  {
9954    if (TYPE_OBJFILE_OWNED (type))
9955 -    return alloc_type (TYPE_OWNER (type).objfile);
9956 +    return alloc_type (TYPE_OWNER (type).objfile, (struct type *) type);
9957    else
9958      return alloc_type_arch (TYPE_OWNER (type).gdbarch);
9959  }
9960 @@ -273,7 +327,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
9961  
9962    if (typeptr == 0 || *typeptr == 0)   /* We'll need to allocate one.  */
9963      {
9964 -      ntype = alloc_type_copy (type);
9965 +      ntype = alloc_type_as_parent (type);
9966        if (typeptr)
9967         *typeptr = ntype;
9968      }
9969 @@ -350,7 +404,7 @@ make_reference_type (struct type *type, struct type **typeptr)
9970  
9971    if (typeptr == 0 || *typeptr == 0)   /* We'll need to allocate one.  */
9972      {
9973 -      ntype = alloc_type_copy (type);
9974 +      ntype = alloc_type_as_parent (type);
9975        if (typeptr)
9976         *typeptr = ntype;
9977      }
9978 @@ -721,12 +775,13 @@ create_range_type (struct type *result_type, struct type *index_type,
9979      TYPE_TARGET_STUB (result_type) = 1;
9980    else
9981      TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
9982 -  TYPE_NFIELDS (result_type) = 2;
9983 +  TYPE_NFIELDS (result_type) = 3;
9984    TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type,
9985                                            TYPE_NFIELDS (result_type)
9986                                            * sizeof (struct field));
9987    TYPE_LOW_BOUND (result_type) = low_bound;
9988    TYPE_HIGH_BOUND (result_type) = high_bound;
9989 +  TYPE_BYTE_STRIDE (result_type) = 0;
9990  
9991    if (low_bound >= 0)
9992      TYPE_UNSIGNED (result_type) = 1;
9993 @@ -826,26 +881,45 @@ create_array_type (struct type *result_type,
9994  
9995    TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
9996    TYPE_TARGET_TYPE (result_type) = element_type;
9997 -  if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
9998 -    low_bound = high_bound = 0;
9999 -  CHECK_TYPEDEF (element_type);
10000 -  /* Be careful when setting the array length.  Ada arrays can be
10001 -     empty arrays with the high_bound being smaller than the low_bound.
10002 -     In such cases, the array length should be zero.  */
10003 -  if (high_bound < low_bound)
10004 -    TYPE_LENGTH (result_type) = 0;
10005 -  else
10006 -    TYPE_LENGTH (result_type) =
10007 -      TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
10008    TYPE_NFIELDS (result_type) = 1;
10009    TYPE_FIELDS (result_type) =
10010      (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
10011    TYPE_INDEX_TYPE (result_type) = range_type;
10012    TYPE_VPTR_FIELDNO (result_type) = -1;
10013  
10014 -  /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
10015 +  /* DWARF blocks may depend on runtime information like
10016 +     DW_OP_PUSH_OBJECT_ADDRESS not being available during the
10017 +     CREATE_ARRAY_TYPE time.  */
10018 +  if (TYPE_RANGE_BOUND_IS_DWARF_BLOCK (range_type, 0)
10019 +      || TYPE_RANGE_BOUND_IS_DWARF_BLOCK (range_type, 1)
10020 +      || TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (range_type) 
10021 +      || TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED (range_type) 
10022 +      || get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
10023 +    {
10024 +      low_bound = 0;
10025 +      high_bound = -1;
10026 +    }
10027 +
10028 +  /* Be careful when setting the array length.  Ada arrays can be
10029 +     empty arrays with the high_bound being smaller than the low_bound.
10030 +     In such cases, the array length should be zero.  TYPE_TARGET_STUB needs to
10031 +     be checked as it may have dependencies on DWARF blocks depending on
10032 +     runtime information not available during the CREATE_ARRAY_TYPE time.  */
10033 +  if (high_bound < low_bound || TYPE_TARGET_STUB (element_type))
10034 +    TYPE_LENGTH (result_type) = 0;
10035 +  else
10036 +    {
10037 +      CHECK_TYPEDEF (element_type);
10038 +      TYPE_LENGTH (result_type) =
10039 +       TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
10040 +    }
10041 +
10042    if (TYPE_LENGTH (result_type) == 0)
10043 -    TYPE_TARGET_STUB (result_type) = 1;
10044 +    {
10045 +      /* The real size will be computed for specific instances by
10046 +        CHECK_TYPEDEF.  */
10047 +      TYPE_TARGET_STUB (result_type) = 1;
10048 +    }
10049  
10050    return result_type;
10051  }
10052 @@ -1331,6 +1405,84 @@ stub_noname_complaint (void)
10053    complaint (&symfile_complaints, _("stub type has NULL name"));
10054  }
10055  
10056 +/* Calculate the memory length of array TYPE.
10057 +
10058 +   TARGET_TYPE should be set to `check_typedef (TYPE_TARGET_TYPE (type))' as
10059 +   a performance hint.  Feel free to pass NULL.  Set FULL_SPAN to return the
10060 +   size incl. the possible padding of the last element - it may differ from the
10061 +   cleared FULL_SPAN return value (the expected SIZEOF) for non-zero
10062 +   TYPE_BYTE_STRIDE values.  */
10063 +
10064 +static CORE_ADDR
10065 +type_length_get (struct type *type, struct type *target_type, int full_span)
10066 +{
10067 +  struct type *range_type;
10068 +  int count;
10069 +  CORE_ADDR byte_stride = 0;   /* `= 0' for a false GCC warning.  */
10070 +  CORE_ADDR element_size;
10071 +
10072 +  if (TYPE_CODE (type) != TYPE_CODE_ARRAY
10073 +      && TYPE_CODE (type) != TYPE_CODE_STRING)
10074 +    return TYPE_LENGTH (type);
10075 +
10076 +  /* Avoid executing TYPE_HIGH_BOUND for invalid (unallocated/unassociated)
10077 +     Fortran arrays.  The allocated data will never be used so they can be
10078 +     zero-length.  */
10079 +  if (object_address_data_not_valid (type))
10080 +    return 0;
10081 +
10082 +  range_type = TYPE_INDEX_TYPE (type);
10083 +  if (TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED (range_type)
10084 +      || TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (range_type))
10085 +    return 0;
10086 +  count = TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type) + 1;
10087 +  /* It may happen for wrong DWARF annotations returning garbage data.  */
10088 +  if (count < 0)
10089 +    warning (_("Range for type %s has invalid bounds %d..%d"),
10090 +            TYPE_NAME (type), TYPE_LOW_BOUND (range_type),
10091 +            TYPE_HIGH_BOUND (range_type));
10092 +  /* The code below does not handle count == 0 right.  */
10093 +  if (count <= 0)
10094 +    return 0;
10095 +  if (full_span || count > 1)
10096 +    {
10097 +      /* We do not use TYPE_ARRAY_BYTE_STRIDE_VALUE (type) here as we want to
10098 +         force FULL_SPAN to 1.  */
10099 +      byte_stride = TYPE_BYTE_STRIDE (range_type);
10100 +      if (byte_stride == 0)
10101 +        {
10102 +         if (target_type == NULL)
10103 +           target_type = check_typedef (TYPE_TARGET_TYPE (type));
10104 +         byte_stride = type_length_get (target_type, NULL, 1);
10105 +       }
10106 +    }
10107 +  if (full_span)
10108 +    return count * byte_stride;
10109 +  if (target_type == NULL)
10110 +    target_type = check_typedef (TYPE_TARGET_TYPE (type));
10111 +  element_size = type_length_get (target_type, NULL, 1);
10112 +  return (count - 1) * byte_stride + element_size;
10113 +}
10114 +
10115 +/* Prepare TYPE after being read in by the backend.  Currently this function
10116 +   only propagates the TYPE_DYNAMIC flag.  */
10117 +
10118 +void
10119 +finalize_type (struct type *type)
10120 +{
10121 +  int i;
10122 +
10123 +  for (i = 0; i < TYPE_NFIELDS (type); ++i)
10124 +    if (TYPE_FIELD_TYPE (type, i) && TYPE_DYNAMIC (TYPE_FIELD_TYPE (type, i)))
10125 +      break;
10126 +
10127 +  /* FIXME: cplus_stuff is ignored here.  */
10128 +  if (i < TYPE_NFIELDS (type)
10129 +      || (TYPE_VPTR_BASETYPE (type) && TYPE_DYNAMIC (TYPE_VPTR_BASETYPE (type)))
10130 +      || (TYPE_TARGET_TYPE (type) && TYPE_DYNAMIC (TYPE_TARGET_TYPE (type))))
10131 +    TYPE_DYNAMIC (type) = 1;
10132 +}
10133 +
10134  /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
10135  
10136     If this is a stubbed struct (i.e. declared as struct foo *), see if
10137 @@ -1347,7 +1499,8 @@ stub_noname_complaint (void)
10138  /* Find the real type of TYPE.  This function returns the real type,
10139     after removing all layers of typedefs and completing opaque or stub
10140     types.  Completion changes the TYPE argument, but stripping of
10141 -   typedefs does not.  */
10142 +   typedefs does not.  Still original passed TYPE will have TYPE_LENGTH
10143 +   updated.  FIXME: Remove this dependency (only ada_to_fixed_type?).  */
10144  
10145  struct type *
10146  check_typedef (struct type *type)
10147 @@ -1457,34 +1610,37 @@ check_typedef (struct type *type)
10148          }
10149      }
10150  
10151 -  if (TYPE_TARGET_STUB (type))
10152 +  /* copy_type_recursive automatically makes the resulting type containing only
10153 +     constant values expected by the callers of this function.  */
10154 +  if (TYPE_DYNAMIC (type))
10155 +    {
10156 +      htab_t copied_types;
10157 +      struct type *type_old = type;
10158 +
10159 +      copied_types = create_copied_types_hash (NULL);
10160 +      type = copy_type_recursive (type, copied_types);
10161 +      htab_delete (copied_types);
10162 +
10163 +      gdb_assert (TYPE_DYNAMIC (type) == 0);
10164 +    }
10165 +
10166 +  if (!currently_reading_symtab
10167 +      && (TYPE_TARGET_STUB (type) || TYPE_DYNAMIC (type)))
10168      {
10169 -      struct type *range_type;
10170        struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
10171  
10172 +      if (TYPE_DYNAMIC (type))
10173 +       TYPE_TARGET_TYPE (type) = target_type;
10174        if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
10175         {
10176           /* Empty.  */
10177         }
10178        else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
10179 -              && TYPE_NFIELDS (type) == 1
10180 -              && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
10181 -                  == TYPE_CODE_RANGE))
10182 +              || TYPE_CODE (type) == TYPE_CODE_STRING)
10183         {
10184           /* Now recompute the length of the array type, based on its
10185 -            number of elements and the target type's length.
10186 -            Watch out for Ada null Ada arrays where the high bound
10187 -            is smaller than the low bound.  */
10188 -         const int low_bound = TYPE_LOW_BOUND (range_type);
10189 -         const int high_bound = TYPE_HIGH_BOUND (range_type);
10190 -         int nb_elements;
10191 -       
10192 -         if (high_bound < low_bound)
10193 -           nb_elements = 0;
10194 -         else
10195 -           nb_elements = high_bound - low_bound + 1;
10196 -       
10197 -         TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
10198 +            number of elements and the target type's length.  */
10199 +         TYPE_LENGTH (type) = type_length_get (type, target_type, 0);
10200           TYPE_TARGET_STUB (type) = 0;
10201         }
10202        else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
10203 @@ -1492,9 +1648,12 @@ check_typedef (struct type *type)
10204           TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
10205           TYPE_TARGET_STUB (type) = 0;
10206         }
10207 +      TYPE_DYNAMIC (type) = 0;
10208      }
10209 +
10210    /* Cache TYPE_LENGTH for future use.  */
10211    TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
10212 +
10213    return type;
10214  }
10215  
10216 @@ -1716,7 +1875,7 @@ init_type (enum type_code code, int length, int flags,
10217  {
10218    struct type *type;
10219  
10220 -  type = alloc_type (objfile);
10221 +  type = alloc_type (objfile, NULL);
10222    TYPE_CODE (type) = code;
10223    TYPE_LENGTH (type) = length;
10224  
10225 @@ -1760,6 +1919,10 @@ init_type (enum type_code code, int length, int flags,
10226      {
10227        INIT_CPLUS_SPECIFIC (type);
10228      }
10229 +
10230 +  if (!objfile)
10231 +    type_incref (type);
10232 +
10233    return type;
10234  }
10235  
10236 @@ -2004,7 +2167,8 @@ rank_one_type (struct type *parm, struct type *arg)
10237        switch (TYPE_CODE (arg))
10238         {
10239         case TYPE_CODE_PTR:
10240 -         if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
10241 +         if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID
10242 +             && TYPE_CODE (TYPE_TARGET_TYPE (arg)) != TYPE_CODE_VOID)
10243             return VOID_PTR_CONVERSION_BADNESS;
10244           else
10245             return rank_one_type (TYPE_TARGET_TYPE (parm), 
10246 @@ -2820,33 +2984,42 @@ type_pair_eq (const void *item_lhs, const void *item_rhs)
10247  }
10248  
10249  /* Allocate the hash table used by copy_type_recursive to walk
10250 -   types without duplicates.  We use OBJFILE's obstack, because
10251 -   OBJFILE is about to be deleted.  */
10252 +   types without duplicates.   */
10253  
10254  htab_t
10255  create_copied_types_hash (struct objfile *objfile)
10256  {
10257 -  return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
10258 -                              NULL, &objfile->objfile_obstack,
10259 -                              hashtab_obstack_allocate,
10260 -                              dummy_obstack_deallocate);
10261 +  if (objfile == NULL)
10262 +    {
10263 +      /* NULL OBJFILE is for TYPE_DYNAMIC types already contained in
10264 +        OBJFILE_MALLOC memory, such as those from VALUE_HISTORY_CHAIN.  Table
10265 +        element entries get allocated by xmalloc - so use xfree.  */
10266 +      return htab_create (1, type_pair_hash, type_pair_eq, xfree);
10267 +    }
10268 +  else
10269 +    {
10270 +      /* Use OBJFILE's obstack, because OBJFILE is about to be deleted.  Table
10271 +        element entries get allocated by xmalloc - so use xfree.  */
10272 +      return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
10273 +                                  xfree, &objfile->objfile_obstack,
10274 +                                  hashtab_obstack_allocate,
10275 +                                  dummy_obstack_deallocate);
10276 +    }
10277  }
10278  
10279 -/* Recursively copy (deep copy) TYPE, if it is associated with
10280 -   OBJFILE.  Return a new type allocated using malloc, a saved type if
10281 -   we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
10282 -   not associated with OBJFILE.  */
10283 +/* A helper for copy_type_recursive.  This does all the work.  OBJFILE is used
10284 +   only for an assertion checking.  */
10285  
10286 -struct type *
10287 -copy_type_recursive (struct objfile *objfile, 
10288 -                    struct type *type,
10289 -                    htab_t copied_types)
10290 +static struct type *
10291 +copy_type_recursive_1 (struct objfile *objfile, 
10292 +                      struct type *type,
10293 +                      htab_t copied_types)
10294  {
10295    struct type_pair *stored, pair;
10296    void **slot;
10297    struct type *new_type;
10298  
10299 -  if (! TYPE_OBJFILE_OWNED (type))
10300 +  if (! TYPE_OBJFILE_OWNED (type) && !TYPE_DYNAMIC (type))
10301      return type;
10302  
10303    /* This type shouldn't be pointing to any types in other objfiles;
10304 @@ -2861,8 +3034,10 @@ copy_type_recursive (struct objfile *objfile,
10305    new_type = alloc_type_arch (get_type_arch (type));
10306  
10307    /* We must add the new type to the hash table immediately, in case
10308 -     we encounter this type again during a recursive call below.  */
10309 -  stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
10310 +     we encounter this type again during a recursive call below.  Memory could
10311 +     be allocated from OBJFILE in the case we will be removing OBJFILE, this
10312 +     optimization is missed and xfree is called for it from COPIED_TYPES.  */
10313 +  stored = xmalloc (sizeof (*stored));
10314    stored->old = type;
10315    stored->new = new_type;
10316    *slot = stored;
10317 @@ -2873,6 +3048,19 @@ copy_type_recursive (struct objfile *objfile,
10318    TYPE_OBJFILE_OWNED (new_type) = 0;
10319    TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
10320  
10321 +  /* TYPE_MAIN_TYPE memory copy above rewrote the TYPE_DISCARDABLE flag so we
10322 +     need to initialize it again.  And even if TYPE was already discardable
10323 +     NEW_TYPE so far is not registered in TYPE_DISCARDABLE_TABLE.  */
10324 +  TYPE_DISCARDABLE (new_type) = 0;
10325 +  set_type_as_discardable (new_type);
10326 +
10327 +  /* Pre-clear the fields processed by delete_main_type.  If DWARF block
10328 +     evaluations below call error we would leave an unfreeable TYPE.  */
10329 +  TYPE_TARGET_TYPE (new_type) = NULL;
10330 +  TYPE_VPTR_BASETYPE (new_type) = NULL;
10331 +  TYPE_NFIELDS (new_type) = 0;
10332 +  TYPE_FIELDS (new_type) = NULL;
10333 +
10334    if (TYPE_NAME (type))
10335      TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
10336    if (TYPE_TAG_NAME (type))
10337 @@ -2881,12 +3069,45 @@ copy_type_recursive (struct objfile *objfile,
10338    TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
10339    TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
10340  
10341 +  if (TYPE_ALLOCATED (new_type))
10342 +    {
10343 +      gdb_assert (!TYPE_NOT_ALLOCATED (new_type));
10344 +
10345 +      if (!dwarf_locexpr_baton_eval (TYPE_ALLOCATED (new_type)))
10346 +        TYPE_NOT_ALLOCATED (new_type) = 1;
10347 +      TYPE_ALLOCATED (new_type) = NULL;
10348 +    }
10349 +
10350 +  if (TYPE_ASSOCIATED (new_type))
10351 +    {
10352 +      gdb_assert (!TYPE_NOT_ASSOCIATED (new_type));
10353 +
10354 +      if (!dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (new_type)))
10355 +        TYPE_NOT_ASSOCIATED (new_type) = 1;
10356 +      TYPE_ASSOCIATED (new_type) = NULL;
10357 +    }
10358 +
10359 +  if (!TYPE_DATA_LOCATION_IS_ADDR (new_type)
10360 +      && TYPE_DATA_LOCATION_DWARF_BLOCK (new_type))
10361 +    {
10362 +      if (TYPE_NOT_ALLOCATED (new_type)
10363 +          || TYPE_NOT_ASSOCIATED (new_type))
10364 +       TYPE_DATA_LOCATION_DWARF_BLOCK (new_type) = NULL;
10365 +      else
10366 +       {
10367 +         TYPE_DATA_LOCATION_IS_ADDR (new_type) = 1;
10368 +         TYPE_DATA_LOCATION_ADDR (new_type) = dwarf_locexpr_baton_eval
10369 +                                   (TYPE_DATA_LOCATION_DWARF_BLOCK (new_type));
10370 +       }
10371 +    }
10372 +
10373    /* Copy the fields.  */
10374    if (TYPE_NFIELDS (type))
10375      {
10376        int i, nfields;
10377  
10378        nfields = TYPE_NFIELDS (type);
10379 +      TYPE_NFIELDS (new_type) = nfields;
10380        TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
10381        for (i = 0; i < nfields; i++)
10382         {
10383 @@ -2895,8 +3116,8 @@ copy_type_recursive (struct objfile *objfile,
10384           TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
10385           if (TYPE_FIELD_TYPE (type, i))
10386             TYPE_FIELD_TYPE (new_type, i)
10387 -             = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
10388 -                                    copied_types);
10389 +             = copy_type_recursive_1 (objfile, TYPE_FIELD_TYPE (type, i),
10390 +                                      copied_types);
10391           if (TYPE_FIELD_NAME (type, i))
10392             TYPE_FIELD_NAME (new_type, i) = 
10393               xstrdup (TYPE_FIELD_NAME (type, i));
10394 @@ -2915,6 +3136,16 @@ copy_type_recursive (struct objfile *objfile,
10395                                   xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
10396                                                                        i)));
10397               break;
10398 +           case FIELD_LOC_KIND_DWARF_BLOCK:
10399 +             /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
10400 +                it is expected to be made constant by CHECK_TYPEDEF.  */
10401 +             if (TYPE_NOT_ALLOCATED (new_type)
10402 +                 || TYPE_NOT_ASSOCIATED (new_type))
10403 +               SET_FIELD_DWARF_BLOCK (TYPE_FIELD (new_type, i), NULL);
10404 +             else
10405 +               SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
10406 +                  dwarf_locexpr_baton_eval (TYPE_FIELD_DWARF_BLOCK (type, i)));
10407 +             break;
10408             default:
10409               internal_error (__FILE__, __LINE__,
10410                               _("Unexpected type field location kind: %d"),
10411 @@ -2923,17 +3154,30 @@ copy_type_recursive (struct objfile *objfile,
10412         }
10413      }
10414  
10415 +  /* Convert TYPE_RANGE_HIGH_BOUND_IS_COUNT into a regular bound.  */
10416 +  if (TYPE_CODE (type) == TYPE_CODE_RANGE
10417 +      && TYPE_RANGE_HIGH_BOUND_IS_COUNT (type))
10418 +    {
10419 +      TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type) = 0;
10420 +      TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (type)
10421 +                                  + TYPE_HIGH_BOUND (type) - 1;
10422 +    }
10423 +
10424 +  /* Both FIELD_LOC_KIND_DWARF_BLOCK and TYPE_RANGE_HIGH_BOUND_IS_COUNT were
10425 +     possibly converted.  */
10426 +  TYPE_DYNAMIC (new_type) = 0;
10427 +
10428    /* Copy pointers to other types.  */
10429    if (TYPE_TARGET_TYPE (type))
10430      TYPE_TARGET_TYPE (new_type) = 
10431 -      copy_type_recursive (objfile, 
10432 -                          TYPE_TARGET_TYPE (type),
10433 -                          copied_types);
10434 +      copy_type_recursive_1 (objfile, 
10435 +                            TYPE_TARGET_TYPE (type),
10436 +                            copied_types);
10437    if (TYPE_VPTR_BASETYPE (type))
10438      TYPE_VPTR_BASETYPE (new_type) = 
10439 -      copy_type_recursive (objfile,
10440 -                          TYPE_VPTR_BASETYPE (type),
10441 -                          copied_types);
10442 +      copy_type_recursive_1 (objfile,
10443 +                            TYPE_VPTR_BASETYPE (type),
10444 +                            copied_types);
10445    /* Maybe copy the type_specific bits.
10446  
10447       NOTE drow/2005-12-09: We do not copy the C++-specific bits like
10448 @@ -2951,6 +3195,17 @@ copy_type_recursive (struct objfile *objfile,
10449    return new_type;
10450  }
10451  
10452 +/* Recursively copy (deep copy) TYPE.  Return a new type allocated using
10453 +   malloc, a saved type if we have already visited TYPE (using COPIED_TYPES),
10454 +   or TYPE if it is not associated with OBJFILE.  */
10455 +
10456 +struct type *
10457 +copy_type_recursive (struct type *type,
10458 +                    htab_t copied_types)
10459 +{
10460 +  return copy_type_recursive_1 (TYPE_OBJFILE (type), type, copied_types);
10461 +}
10462 +
10463  /* Make a copy of the given TYPE, except that the pointer & reference
10464     types are not preserved.
10465     
10466 @@ -2973,6 +3228,217 @@ copy_type (const struct type *type)
10467    return new_type;
10468  }
10469  
10470 +/* Callback type for main_type_crawl.  */
10471 +typedef int (*main_type_crawl_iter) (struct type *type, void *data);
10472 +
10473 +/* Iterate all main_type structures reachable through any `struct type *' from
10474 +   TYPE.  ITER will be called only for one type of each main_type, use
10475 +   TYPE_CHAIN traversal to find all the type instances.  ITER is being called
10476 +   for each main_type found.  ITER returns non-zero if main_type_crawl should
10477 +   depth-first enter the specific type.  ITER must provide some detection for
10478 +   reentering the same main_type as this function would otherwise endlessly
10479 +   loop.  */
10480 +
10481 +static void
10482 +main_type_crawl (struct type *type, main_type_crawl_iter iter, void *data)
10483 +{
10484 +  struct type *type_iter;
10485 +  int i;
10486 +
10487 +  if (!type)
10488 +    return;
10489 +
10490 +  gdb_assert (TYPE_OBJFILE (type) == NULL);
10491 +
10492 +  /* `struct cplus_struct_type' handling is unsupported by this function.  */
10493 +  gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
10494 +              && TYPE_CODE (type) != TYPE_CODE_UNION)
10495 +             || !HAVE_CPLUS_STRUCT (type) || !TYPE_CPLUS_SPECIFIC (type));
10496 +
10497 +  if (!(*iter) (type, data))
10498 +    return;
10499 +
10500 +  /* Iterate all the type instances of this main_type.  */
10501 +  type_iter = type;
10502 +  do
10503 +    {
10504 +      gdb_assert (TYPE_MAIN_TYPE (type_iter) == TYPE_MAIN_TYPE (type));
10505 +
10506 +      main_type_crawl (TYPE_POINTER_TYPE (type), iter, data);
10507 +      main_type_crawl (TYPE_REFERENCE_TYPE (type), iter, data);
10508 +
10509 +      type_iter = TYPE_CHAIN (type_iter);
10510 +    }
10511 +  while (type_iter != type);
10512 +
10513 +  for (i = 0; i < TYPE_NFIELDS (type); i++)
10514 +    main_type_crawl (TYPE_FIELD_TYPE (type, i), iter, data);
10515 +
10516 +  main_type_crawl (TYPE_TARGET_TYPE (type), iter, data);
10517 +  main_type_crawl (TYPE_VPTR_BASETYPE (type), iter, data);
10518 +}
10519 +
10520 +/* A helper for delete_type which deletes a main_type and the things to which
10521 +   it refers.  TYPE is a type whose main_type we wish to destroy.  */
10522 +
10523 +static void
10524 +delete_main_type (struct type *type)
10525 +{
10526 +  int i;
10527 +
10528 +  gdb_assert (TYPE_DISCARDABLE (type));
10529 +  gdb_assert (TYPE_OBJFILE (type) == NULL);
10530 +
10531 +  xfree (TYPE_NAME (type));
10532 +  xfree (TYPE_TAG_NAME (type));
10533 +
10534 +  for (i = 0; i < TYPE_NFIELDS (type); ++i)
10535 +    {
10536 +      xfree (TYPE_FIELD_NAME (type, i));
10537 +
10538 +      if (TYPE_FIELD_LOC_KIND (type, i) == FIELD_LOC_KIND_PHYSNAME)
10539 +       xfree (TYPE_FIELD_STATIC_PHYSNAME (type, i));
10540 +    }
10541 +  xfree (TYPE_FIELDS (type));
10542 +
10543 +  /* `struct cplus_struct_type' handling is unsupported by this function.  */
10544 +  gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
10545 +              && TYPE_CODE (type) != TYPE_CODE_UNION)
10546 +             || !HAVE_CPLUS_STRUCT (type) || !TYPE_CPLUS_SPECIFIC (type));
10547 +
10548 +  xfree (TYPE_MAIN_TYPE (type));
10549 +}
10550 +
10551 +/* Delete all the instances on TYPE_CHAIN of TYPE, including their referenced
10552 +   main_type.  TYPE must be a reclaimable type - neither permanent nor objfile
10553 +   associated.  */
10554 +
10555 +static void
10556 +delete_type_chain (struct type *type)
10557 +{
10558 +  struct type *type_iter, *type_iter_to_free;
10559 +
10560 +  gdb_assert (TYPE_DISCARDABLE (type));
10561 +  gdb_assert (TYPE_OBJFILE (type) == NULL);
10562 +
10563 +  delete_main_type (type);
10564 +
10565 +  type_iter = type;
10566 +  do
10567 +    {
10568 +      type_iter_to_free = type_iter;
10569 +      type_iter = TYPE_CHAIN (type_iter);
10570 +      xfree (type_iter_to_free);
10571 +    }
10572 +  while (type_iter != type);
10573 +}
10574 +
10575 +/* Hash function for type_discardable_table.  */
10576 +
10577 +static hashval_t
10578 +type_discardable_hash (const void *p)
10579 +{
10580 +  const struct type *type = p;
10581 +
10582 +  return htab_hash_pointer (TYPE_MAIN_TYPE (type));
10583 +}
10584 +
10585 +/* Equality function for type_discardable_table.  */
10586 +
10587 +static int
10588 +type_discardable_equal (const void *a, const void *b)
10589 +{
10590 +  const struct type *left = a;
10591 +  const struct type *right = b;
10592 +
10593 +  return TYPE_MAIN_TYPE (left) == TYPE_MAIN_TYPE (right);
10594 +}
10595 +
10596 +/* A helper for type_mark_used.  */
10597 +
10598 +static int
10599 +type_mark_used_crawl (struct type *type, void *unused)
10600 +{
10601 +  if (!TYPE_DISCARDABLE (type))
10602 +    return 0;
10603 +
10604 +  if (TYPE_DISCARDABLE_AGE (type) == type_discardable_age_current)
10605 +    return 0;
10606 +
10607 +  TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
10608 +
10609 +  /* Continue the traversal.  */
10610 +  return 1;
10611 +}
10612 +
10613 +/* Mark TYPE and its connected types as used in this free_all_types pass.  */
10614 +
10615 +void
10616 +type_mark_used (struct type *type)
10617 +{
10618 +  if (type == NULL)
10619 +    return;
10620 +
10621 +  if (!TYPE_DISCARDABLE (type))
10622 +    return;
10623 +
10624 +  main_type_crawl (type, type_mark_used_crawl, NULL);
10625 +}
10626 +
10627 +/* Increment the reference count for TYPE.  */
10628 +
10629 +void
10630 +type_incref (struct type *type)
10631 +{
10632 +}
10633 +
10634 +/* Decrement the reference count for TYPE.  If TYPE has no more
10635 +   references, delete it.  */
10636 +
10637 +void
10638 +type_decref (struct type *type)
10639 +{
10640 +}
10641 +
10642 +/* A traverse callback for type_discardable_table which removes any
10643 +   type_discardable whose reference count is now zero (unused link).  */
10644 +
10645 +static int
10646 +type_discardable_remove (void **slot, void *unused)
10647 +{
10648 +  struct type *type = *slot;
10649 +
10650 +  gdb_assert (TYPE_DISCARDABLE (type));
10651 +
10652 +  if (TYPE_DISCARDABLE_AGE (type) != type_discardable_age_current)
10653 +    {
10654 +      delete_type_chain (type);
10655 +
10656 +      htab_clear_slot (type_discardable_table, slot);
10657 +    }
10658 +
10659 +  return 1;
10660 +}
10661 +
10662 +/* Free all the reclaimable types that have been allocated and that have
10663 +   currently zero reference counter.
10664 +
10665 +   This function is called after each command, successful or not.  Use this
10666 +   cleanup only in the GDB idle state as GDB only marks those types used by
10667 +   globally tracked objects (with no autovariable references tracking).  */
10668 +
10669 +void
10670 +free_all_types (void)
10671 +{
10672 +  /* Mark a new pass.  As GDB checks all the entries were visited after each
10673 +     pass there cannot be any stale entries already containing the changed
10674 +     value.  */
10675 +  type_discardable_age_current ^= 1;
10676 +
10677 +  observer_notify_mark_used ();
10678 +
10679 +  htab_traverse (type_discardable_table, type_discardable_remove, NULL);
10680 +}
10681  
10682  /* Helper functions to initialize architecture-specific types.  */
10683  
10684 @@ -3463,6 +3929,11 @@ void
10685  _initialize_gdbtypes (void)
10686  {
10687    gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
10688 +
10689 +  type_discardable_table = htab_create_alloc (20, type_discardable_hash,
10690 +                                            type_discardable_equal, NULL,
10691 +                                            xcalloc, xfree);
10692 +
10693    objfile_type_data = register_objfile_data ();
10694  
10695    add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
10696 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
10697 index be6ed55..6a51a4e 100644
10698 --- a/gdb/gdbtypes.h
10699 +++ b/gdb/gdbtypes.h
10700 @@ -137,6 +137,8 @@ enum type_code
10701  
10702      TYPE_CODE_DECFLOAT,                /* Decimal floating point.  */
10703  
10704 +    TYPE_CODE_MODULE,          /* Fortran module.  */
10705 +
10706      /* Internal function type.  */
10707      TYPE_CODE_INTERNAL_FUNCTION
10708    };
10709 @@ -213,6 +215,11 @@ enum type_instance_flag_value
10710  
10711  #define TYPE_TARGET_STUB(t)    (TYPE_MAIN_TYPE (t)->flag_target_stub)
10712  
10713 +/* Type needs to be evaluated on each CHECK_TYPEDEF and its results must not be
10714 +   sticky.  */
10715 +
10716 +#define TYPE_DYNAMIC(t)                (TYPE_MAIN_TYPE (t)->flag_dynamic)
10717 +
10718  /* Static type.  If this is set, the corresponding type had 
10719   * a static modifier.
10720   * Note: This may be unnecessary, since static data members
10721 @@ -278,6 +285,48 @@ enum type_instance_flag_value
10722  #define TYPE_OWNER(t) TYPE_MAIN_TYPE(t)->owner
10723  #define TYPE_OBJFILE(t) (TYPE_OBJFILE_OWNED(t)? TYPE_OWNER(t).objfile : NULL)
10724  
10725 +/* Define this type as being reclaimable during free_all_types.  Type is
10726 +   required to be have TYPE_OBJFILE set to NULL.  Setting this flag requires
10727 +   initializing TYPE_DISCARDABLE_AGE, see alloc_type_discardable.  */
10728 +
10729 +#define TYPE_DISCARDABLE(t)    (TYPE_MAIN_TYPE (t)->flag_discardable)
10730 +
10731 +/* Marker this type has been visited by the type_mark_used by this
10732 +   mark-and-sweep types garbage collecting pass.  Current pass is represented
10733 +   by TYPE_DISCARDABLE_AGE_CURRENT.  */
10734 +
10735 +#define TYPE_DISCARDABLE_AGE(t)        (TYPE_MAIN_TYPE (t)->flag_discardable_age)
10736 +
10737 +/* Is HIGH_BOUND a low-bound relative count (1) or the high bound itself (0)?  */
10738 +
10739 +#define TYPE_RANGE_HIGH_BOUND_IS_COUNT(range_type) \
10740 +  (TYPE_MAIN_TYPE (range_type)->flag_range_high_bound_is_count)
10741 +
10742 +/* Not allocated.  TYPE_ALLOCATED(t) must be NULL in such case.  If this flag
10743 +   is unset and TYPE_ALLOCATED(t) is NULL then the type is allocated.  If this
10744 +   flag is unset and TYPE_ALLOCATED(t) is not NULL then its DWARF block
10745 +   determines the actual allocation state.  */
10746 +
10747 +#define TYPE_NOT_ALLOCATED(t)  (TYPE_MAIN_TYPE (t)->flag_not_allocated)
10748 +
10749 +/* Not associated.  TYPE_ASSOCIATED(t) must be NULL in such case.  If this flag
10750 +   is unset and TYPE_ASSOCIATED(t) is NULL then the type is associated.  If
10751 +   this flag is unset and TYPE_ASSOCIATED(t) is not NULL then its DWARF block
10752 +   determines the actual association state.  */
10753 +
10754 +#define TYPE_NOT_ASSOCIATED(t) (TYPE_MAIN_TYPE (t)->flag_not_associated)
10755 +
10756 +/* Address of the actual data as for DW_AT_data_location.  Its dwarf block must
10757 +   not be evaluated unless both TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are
10758 +   false.  If TYPE_DATA_LOCATION_IS_ADDR set then TYPE_DATA_LOCATION_ADDR value
10759 +   is the actual data address value.  If unset and
10760 +   TYPE_DATA_LOCATION_DWARF_BLOCK is NULL then the value is the normal
10761 +   value_raw_address.  If unset and TYPE_DATA_LOCATION_DWARF_BLOCK is not NULL
10762 +   then its DWARF block determines the actual data address.  */
10763 +
10764 +#define TYPE_DATA_LOCATION_IS_ADDR(t) \
10765 +  (TYPE_MAIN_TYPE (t)->flag_data_location_is_addr)
10766 +
10767  /* Constant type.  If this is set, the corresponding type has a
10768   * const modifier.
10769   */
10770 @@ -365,6 +414,13 @@ struct main_type
10771    unsigned int flag_nottext : 1;
10772    unsigned int flag_fixed_instance : 1;
10773    unsigned int flag_objfile_owned : 1;
10774 +  unsigned int flag_discardable : 1;
10775 +  unsigned int flag_discardable_age : 1;
10776 +  unsigned int flag_dynamic : 1;
10777 +  unsigned int flag_range_high_bound_is_count : 1;
10778 +  unsigned int flag_not_allocated : 1;
10779 +  unsigned int flag_not_associated : 1;
10780 +  unsigned int flag_data_location_is_addr : 1;
10781  
10782    /* Number of fields described for this type.  This field appears at
10783       this location because it packs nicely here.  */
10784 @@ -431,6 +487,20 @@ struct main_type
10785  
10786    struct type *target_type;
10787  
10788 +  /* For DW_AT_data_location.  */
10789 +  union
10790 +    {
10791 +      struct dwarf2_locexpr_baton *dwarf_block;
10792 +      CORE_ADDR addr;
10793 +    }
10794 +  data_location;
10795 +
10796 +  /* For DW_AT_allocated.  */
10797 +  struct dwarf2_locexpr_baton *allocated;
10798 +
10799 +  /* For DW_AT_associated.  */
10800 +  struct dwarf2_locexpr_baton *associated;
10801 +
10802    /* For structure and union types, a description of each field.
10803       For set and pascal array types, there is one "field",
10804       whose type is the domain type of the set or array.
10805 @@ -538,6 +608,9 @@ struct main_type
10806         supporting multiple ABIs.  Right now this is only fetched from
10807         the Dwarf-2 DW_AT_calling_convention attribute.  */
10808      unsigned calling_convention;
10809 +
10810 +    /* For TYPE_CODE_MODULE, the list of symbols contained in the module.  */
10811 +    struct block *module_block;
10812    } type_specific;
10813  };
10814  
10815 @@ -812,9 +885,9 @@ extern void allocate_cplus_struct_type (struct type *);
10816  #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
10817  #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
10818  #define TYPE_CHAIN(thistype) (thistype)->chain
10819 -/* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
10820 -   But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
10821 -   so you only have to call check_typedef once.  Since allocate_value
10822 +/* Note that if thistype is a TYPEDEF, ARRAY or STRING type, you have to call
10823 +   check_typedef.  But check_typedef does set the TYPE_LENGTH of the TYPEDEF
10824 +   type, so you only have to call check_typedef once.  Since allocate_value
10825     calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe.  */
10826  #define TYPE_LENGTH(thistype) (thistype)->length
10827  /* Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
10828 @@ -823,23 +896,44 @@ extern void allocate_cplus_struct_type (struct type *);
10829  #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
10830  #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->fields
10831  #define TYPE_TEMPLATE_ARGS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->template_args
10832 +#define TYPE_DATA_LOCATION_DWARF_BLOCK(thistype) TYPE_MAIN_TYPE (thistype)->data_location.dwarf_block
10833 +#define TYPE_DATA_LOCATION_ADDR(thistype) TYPE_MAIN_TYPE (thistype)->data_location.addr
10834 +#define TYPE_ALLOCATED(thistype) TYPE_MAIN_TYPE (thistype)->allocated
10835 +#define TYPE_ASSOCIATED(thistype) TYPE_MAIN_TYPE (thistype)->associated
10836  
10837  #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
10838  #define TYPE_LOW_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 0)
10839  #define TYPE_HIGH_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 1)
10840 -
10841 -/* Moto-specific stuff for FORTRAN arrays */
10842 -
10843 -#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
10844 -   (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),1))
10845 +#define TYPE_BYTE_STRIDE(range_type) TYPE_FIELD_BITPOS (range_type, 2)
10846 +
10847 +/* Whether we should use TYPE_FIELD_DWARF_BLOCK (and not TYPE_FIELD_BITPOS).  */
10848 +#define TYPE_RANGE_BOUND_IS_DWARF_BLOCK(range_type, fieldno) \
10849 +  (TYPE_FIELD_LOC_KIND (range_type, fieldno) == FIELD_LOC_KIND_DWARF_BLOCK)
10850 +#define TYPE_RANGE_BOUND_SET_DWARF_BLOCK(range_type, fieldno) \
10851 +  (TYPE_FIELD_LOC_KIND (range_type, fieldno) = FIELD_LOC_KIND_DWARF_BLOCK)
10852 +#define TYPE_ARRAY_BOUND_IS_DWARF_BLOCK(array_type, fieldno) \
10853 +  TYPE_RANGE_BOUND_IS_DWARF_BLOCK (TYPE_INDEX_TYPE (array_type), fieldno)
10854 +
10855 +/* Unbound arrays, such as GCC array[]; at end of struct.  */
10856 +#define TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED(rangetype) \
10857 +   TYPE_FIELD_ARTIFICIAL((rangetype),0)
10858 +#define TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED(rangetype) \
10859 +   TYPE_FIELD_ARTIFICIAL((rangetype),1)
10860  #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
10861 -   (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),0))
10862 -
10863 -#define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
10864 -   (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
10865 +   TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED (TYPE_INDEX_TYPE (arraytype))
10866 +#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
10867 +   TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (TYPE_INDEX_TYPE (arraytype))
10868  
10869  #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
10870 -   (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype))))
10871 +  TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arraytype))
10872 +#define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
10873 +  TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (arraytype))
10874 +/* TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) with a fallback to the
10875 +   element size if no specific stride value is known.  */
10876 +#define TYPE_ARRAY_BYTE_STRIDE_VALUE(arraytype)                \
10877 +  (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) == 0 \
10878 +   ? TYPE_LENGTH (TYPE_TARGET_TYPE (arraytype))                \
10879 +   : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)))
10880  
10881  /* C++ */
10882  
10883 @@ -855,6 +949,7 @@ extern void allocate_cplus_struct_type (struct type *);
10884  #define TYPE_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
10885  #define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
10886  #define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.calling_convention
10887 +#define TYPE_MODULE_BLOCK(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.module_block
10888  #define TYPE_BASECLASS(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].type
10889  #define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
10890  #define TYPE_BASECLASS_NAME(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].name
10891 @@ -1131,7 +1226,7 @@ extern const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN
10892     Use alloc_type_arch to allocate a type owned by an architecture.
10893     Use alloc_type_copy to allocate a type with the same owner as a
10894     pre-existing template type, no matter whether objfile or gdbarch.  */
10895 -extern struct type *alloc_type (struct objfile *);
10896 +extern struct type *alloc_type (struct objfile *, struct type *);
10897  extern struct type *alloc_type_arch (struct gdbarch *);
10898  extern struct type *alloc_type_copy (const struct type *);
10899  
10900 @@ -1226,6 +1321,18 @@ extern struct type *create_array_type (struct type *, struct type *,
10901                                        struct type *);
10902  extern struct type *lookup_array_range_type (struct type *, int, int);
10903  
10904 +extern CORE_ADDR type_range_any_field_internal (struct type *range_type,
10905 +                                               int fieldno);
10906 +
10907 +extern int type_range_high_bound_internal (struct type *range_type);
10908 +
10909 +extern int type_range_count_bound_internal (struct type *range_type);
10910 +
10911 +extern CORE_ADDR type_range_byte_stride_internal (struct type *range_type,
10912 +                                                 struct type *element_type);
10913 +
10914 +extern void finalize_type (struct type *type);
10915 +
10916  extern struct type *create_string_type (struct type *, struct type *,
10917                                         struct type *);
10918  extern struct type *lookup_string_range_type (struct type *, int, int);
10919 @@ -1262,6 +1369,8 @@ extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *);
10920  
10921  extern int is_ancestor (struct type *, struct type *);
10922  
10923 +extern void type_mark_used (struct type *type);
10924 +
10925  /* Overload resolution */
10926  
10927  #define LENGTH_MATCH(bv) ((bv)->rank[0])
10928 @@ -1324,10 +1433,15 @@ extern void maintenance_print_type (char *, int);
10929  
10930  extern htab_t create_copied_types_hash (struct objfile *objfile);
10931  
10932 -extern struct type *copy_type_recursive (struct objfile *objfile,
10933 -                                        struct type *type,
10934 +extern struct type *copy_type_recursive (struct type *type,
10935                                          htab_t copied_types);
10936  
10937  extern struct type *copy_type (const struct type *type);
10938  
10939 +extern void free_all_types (void);
10940 +
10941 +extern void type_incref (struct type *type);
10942 +
10943 +extern void type_decref (struct type *type);
10944 +
10945  #endif /* GDBTYPES_H */
10946 diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
10947 index 0f9d44e..c910e88 100644
10948 --- a/gdb/gnu-v3-abi.c
10949 +++ b/gdb/gnu-v3-abi.c
10950 @@ -26,6 +26,7 @@
10951  #include "demangle.h"
10952  #include "objfiles.h"
10953  #include "valprint.h"
10954 +#include "c-lang.h"
10955  
10956  #include "gdb_assert.h"
10957  #include "gdb_string.h"
10958 @@ -459,10 +460,8 @@ gnuv3_find_method_in (struct type *domain, CORE_ADDR voffset,
10959                       LONGEST adjustment)
10960  {
10961    int i;
10962 -  const char *physname;
10963  
10964    /* Search this class first.  */
10965 -  physname = NULL;
10966    if (adjustment == 0)
10967      {
10968        int len;
10969 @@ -590,15 +589,24 @@ gnuv3_print_method_ptr (const gdb_byte *contents,
10970         {
10971           char *demangled_name = cplus_demangle (physname,
10972                                                  DMGL_ANSI | DMGL_PARAMS);
10973 -         if (demangled_name != NULL)
10974 +         fprintf_filtered (stream, "&virtual ");
10975 +         if (demangled_name == NULL)
10976 +           fputs_filtered (physname, stream);
10977 +         else
10978             {
10979 -             fprintf_filtered (stream, "&virtual ");
10980               fputs_filtered (demangled_name, stream);
10981               xfree (demangled_name);
10982 -             return;
10983             }
10984 +         return;
10985         }
10986      }
10987 +  else if (ptr_value != 0)
10988 +    {
10989 +      /* Found a non-virtual function: print out the type.  */
10990 +      fputs_filtered ("(", stream);
10991 +      c_print_type (type, "", stream, -1, 0);
10992 +      fputs_filtered (") ", stream);
10993 +    }
10994  
10995    /* We didn't find it; print the raw data.  */
10996    if (vbit)
10997 diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
10998 index fe848ff..170e6cd 100644
10999 --- a/gdb/i386-linux-nat.c
11000 +++ b/gdb/i386-linux-nat.c
11001 @@ -586,6 +586,8 @@ i386_linux_store_inferior_registers (struct target_ops *ops,
11002  
11003  static unsigned long i386_linux_dr[DR_CONTROL + 1];
11004  
11005 +/* Get debug register REGNUM value from only the one LWP of PTID.  */
11006 +
11007  static unsigned long
11008  i386_linux_dr_get (ptid_t ptid, int regnum)
11009  {
11010 @@ -614,6 +616,8 @@ i386_linux_dr_get (ptid_t ptid, int regnum)
11011    return value;
11012  }
11013  
11014 +/* Set debug register REGNUM to VALUE in only the one LWP of PTID.  */
11015 +
11016  static void
11017  i386_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
11018  {
11019 @@ -630,6 +634,8 @@ i386_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
11020      perror_with_name (_("Couldn't write debug register"));
11021  }
11022  
11023 +/* Set DR_CONTROL to ADDR in all LWPs of LWP_LIST.  */
11024 +
11025  static void
11026  i386_linux_dr_set_control (unsigned long control)
11027  {
11028 @@ -641,6 +647,8 @@ i386_linux_dr_set_control (unsigned long control)
11029      i386_linux_dr_set (ptid, DR_CONTROL, control);
11030  }
11031  
11032 +/* Set address REGNUM (zero based) to ADDR in all LWPs of LWP_LIST.  */
11033 +
11034  static void
11035  i386_linux_dr_set_addr (int regnum, CORE_ADDR addr)
11036  {
11037 @@ -654,18 +662,55 @@ i386_linux_dr_set_addr (int regnum, CORE_ADDR addr)
11038      i386_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr);
11039  }
11040  
11041 +/* Set address REGNUM (zero based) to zero in all LWPs of LWP_LIST.  */
11042 +
11043  static void
11044  i386_linux_dr_reset_addr (int regnum)
11045  {
11046    i386_linux_dr_set_addr (regnum, 0);
11047  }
11048  
11049 +/* Get DR_STATUS from only the one LWP of INFERIOR_PTID.  */
11050 +
11051  static unsigned long
11052  i386_linux_dr_get_status (void)
11053  {
11054    return i386_linux_dr_get (inferior_ptid, DR_STATUS);
11055  }
11056  
11057 +/* Unset VALUE bits in DR_STATUS in all LWPs of LWP_LIST.  */
11058 +
11059 +static void
11060 +i386_linux_dr_unset_status (unsigned long mask)
11061 +{
11062 +  struct lwp_info *lp;
11063 +  ptid_t ptid;
11064 +
11065 +  ALL_LWPS (lp, ptid)
11066 +    {
11067 +      unsigned long value;
11068 +      
11069 +      value = i386_linux_dr_get (ptid, DR_STATUS);
11070 +      value &= ~mask;
11071 +      i386_linux_dr_set (ptid, DR_STATUS, value);
11072 +    }
11073 +}
11074 +
11075 +/* See i386_dr_low_type.detach.  Do not use wrappers i386_linux_dr_set_control
11076 +   or i386_linux_dr_reset_addr as they would modify the register cache
11077 +   (i386_linux_dr).  */
11078 +
11079 +static void
11080 +i386_linux_dr_detach (void)
11081 +{
11082 +  int regnum;
11083 +
11084 +  i386_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
11085 +  i386_linux_dr_unset_status (~0UL);
11086 +  for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
11087 +    i386_linux_dr_set (inferior_ptid, regnum, 0);
11088 +}
11089 +
11090  static void
11091  i386_linux_new_thread (ptid_t ptid)
11092  {
11093 @@ -837,6 +882,8 @@ _initialize_i386_linux_nat (void)
11094    i386_dr_low.set_addr = i386_linux_dr_set_addr;
11095    i386_dr_low.reset_addr = i386_linux_dr_reset_addr;
11096    i386_dr_low.get_status = i386_linux_dr_get_status;
11097 +  i386_dr_low.unset_status = i386_linux_dr_unset_status;
11098 +  i386_dr_low.detach = i386_linux_dr_detach;
11099    i386_set_debug_register_length (4);
11100  
11101    /* Override the default ptrace resume method.  */
11102 diff --git a/gdb/i386-nat.c b/gdb/i386-nat.c
11103 index ab1bd8a..ee330b8 100644
11104 --- a/gdb/i386-nat.c
11105 +++ b/gdb/i386-nat.c
11106 @@ -137,8 +137,11 @@ struct i386_dr_low_type i386_dr_low;
11107  #define I386_DR_GET_RW_LEN(i) \
11108    ((dr_control_mirror >> (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))) & 0x0f)
11109  
11110 +/* Mask that this I'th watchpoint has triggered.  */
11111 +#define I386_DR_WATCH_MASK(i)  (1 << (i))
11112 +
11113  /* Did the watchpoint whose address is in the I'th register break?  */
11114 -#define I386_DR_WATCH_HIT(i)   (dr_status_mirror & (1 << (i)))
11115 +#define I386_DR_WATCH_HIT(i)   (dr_status_mirror & I386_DR_WATCH_MASK (i))
11116  
11117  /* A macro to loop over all debug registers.  */
11118  #define ALL_DEBUG_REGISTERS(i) for (i = 0; i < DR_NADDR; i++)
11119 @@ -358,6 +361,10 @@ i386_insert_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits)
11120    i386_dr_low.set_addr (i, addr);
11121    i386_dr_low.set_control (dr_control_mirror);
11122  
11123 +  /* Only a sanity check for leftover bits (set possibly only by inferior).  */
11124 +  if (i386_dr_low.unset_status)
11125 +    i386_dr_low.unset_status (I386_DR_WATCH_MASK (i));
11126 +
11127    return 0;
11128  }
11129  
11130 @@ -387,6 +394,11 @@ i386_remove_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits)
11131               i386_dr_low.set_control (dr_control_mirror);
11132               if (i386_dr_low.reset_addr)
11133                 i386_dr_low.reset_addr (i);
11134 +
11135 +             /* Status must be already queried for each LWP.  Otherwise it will
11136 +                be lost in all-stop mode + breakpoint always-inserted off.  */
11137 +             if (i386_dr_low.unset_status)
11138 +               i386_dr_low.unset_status (I386_DR_WATCH_MASK (i));
11139             }
11140           retval = 0;
11141         }
11142 @@ -520,6 +532,17 @@ i386_remove_watchpoint (CORE_ADDR addr, int len, int type)
11143    return retval;
11144  }
11145  
11146 +/* See target_detach_watchpoints.  */
11147 +
11148 +static int
11149 +i386_detach_watchpoints (void)
11150 +{
11151 +  if (i386_dr_low.detach)
11152 +    i386_dr_low.detach ();
11153 +
11154 +  return 0;
11155 +}
11156 +
11157  /* Return non-zero if we can watch a memory region that starts at
11158     address ADDR and whose length is LEN bytes.  */
11159  
11160 @@ -575,28 +598,7 @@ static int
11161  i386_stopped_by_watchpoint (void)
11162  {
11163    CORE_ADDR addr = 0;
11164 -  return i386_stopped_data_address (&current_target, &addr);
11165 -}
11166 -
11167 -/* Return non-zero if the inferior has some break/watchpoint that
11168 -   triggered.  */
11169 -
11170 -static int
11171 -i386_stopped_by_hwbp (void)
11172 -{
11173 -  int i;
11174 -
11175 -  dr_status_mirror = i386_dr_low.get_status ();
11176 -  if (maint_show_dr)
11177 -    i386_show_dr ("stopped_by_hwbp", 0, 0, hw_execute);
11178 -
11179 -  ALL_DEBUG_REGISTERS(i)
11180 -    {
11181 -      if (I386_DR_WATCH_HIT (i))
11182 -       return 1;
11183 -    }
11184 -
11185 -  return 0;
11186 +  return target_stopped_data_address (&current_target, &addr);
11187  }
11188  
11189  /* Insert a hardware-assisted breakpoint at BP_TGT->placed_address.
11190 @@ -690,6 +692,7 @@ i386_use_watchpoints (struct target_ops *t)
11191    t->to_stopped_data_address = i386_stopped_data_address;
11192    t->to_insert_watchpoint = i386_insert_watchpoint;
11193    t->to_remove_watchpoint = i386_remove_watchpoint;
11194 +  t->to_detach_watchpoints = i386_detach_watchpoints;
11195    t->to_insert_hw_breakpoint = i386_insert_hw_breakpoint;
11196    t->to_remove_hw_breakpoint = i386_remove_hw_breakpoint;
11197  }
11198 diff --git a/gdb/i386-nat.h b/gdb/i386-nat.h
11199 index f49b9f6..cd31958 100644
11200 --- a/gdb/i386-nat.h
11201 +++ b/gdb/i386-nat.h
11202 @@ -49,16 +49,23 @@ extern void i386_use_watchpoints (struct target_ops *);
11203     functions are:
11204  
11205        set_control              -- set the debug control (DR7)
11206 -                                 register to a given value
11207 +                                 register to a given value for all LWPs
11208  
11209        set_addr                 -- put an address into one debug
11210 -                                 register
11211 +                                 register for all LWPs
11212  
11213        reset_addr               -- reset the address stored in
11214 -                                 one debug register
11215 +                                 one debug register for all LWPs
11216  
11217        get_status               -- return the value of the debug
11218 -                                 status (DR6) register.
11219 +                                 status (DR6) register for current LWP
11220 +
11221 +      unset_status             -- unset the specified bits of the debug
11222 +                                 status (DR6) register for all LWPs
11223 +
11224 +      detach                   -- clear all debug registers of only the
11225 +                                 INFERIOR_PTID task without affecting any
11226 +                                 register caches.
11227  
11228     Additionally, the native file should set the debug_register_length
11229     field to 4 or 8 depending on the number of bytes used for
11230 @@ -70,6 +77,8 @@ struct i386_dr_low_type
11231      void (*set_addr) (int, CORE_ADDR);
11232      void (*reset_addr) (int);
11233      unsigned long (*get_status) (void);
11234 +    void (*unset_status) (unsigned long);
11235 +    void (*detach) (void);
11236      int debug_register_length;
11237    };
11238  
11239 diff --git a/gdb/infcmd.c b/gdb/infcmd.c
11240 index 9e98290..fab1892 100644
11241 --- a/gdb/infcmd.c
11242 +++ b/gdb/infcmd.c
11243 @@ -801,7 +801,7 @@ nexti_command (char *count_string, int from_tty)
11244    step_1 (1, 1, count_string);
11245  }
11246  
11247 -static void
11248 +void
11249  delete_longjmp_breakpoint_cleanup (void *arg)
11250  {
11251    int thread = * (int *) arg;
11252 @@ -841,10 +841,13 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
11253  
11254    if (!single_inst || skip_subroutines)                /* leave si command alone */
11255      {
11256 +      struct thread_info *tp = inferior_thread ();
11257 +
11258        if (in_thread_list (inferior_ptid))
11259         thread = pid_to_thread_id (inferior_ptid);
11260  
11261        set_longjmp_breakpoint (thread);
11262 +      tp->initiating_frame = get_frame_id (get_current_frame ());
11263  
11264        make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11265      }
11266 @@ -1193,6 +1196,15 @@ signal_command (char *signum_exp, int from_tty)
11267    proceed ((CORE_ADDR) -1, oursig, 0);
11268  }
11269  
11270 +/* A continuation callback for until_next_command.  */
11271 +
11272 +static void
11273 +until_next_continuation (void *arg)
11274 +{
11275 +  struct thread_info *tp = arg;
11276 +  delete_longjmp_breakpoint (tp->num);
11277 +}
11278 +
11279  /* Proceed until we reach a different source line with pc greater than
11280     our current one or exit the function.  We skip calls in both cases.
11281  
11282 @@ -1209,6 +1221,8 @@ until_next_command (int from_tty)
11283    struct symbol *func;
11284    struct symtab_and_line sal;
11285    struct thread_info *tp = inferior_thread ();
11286 +  int thread = tp->num;
11287 +  struct cleanup *old_chain;
11288  
11289    clear_proceed_status ();
11290    set_step_frame ();
11291 @@ -1244,7 +1258,19 @@ until_next_command (int from_tty)
11292  
11293    tp->step_multi = 0;          /* Only one call to proceed */
11294  
11295 +  set_longjmp_breakpoint (thread);
11296 +  tp->initiating_frame = get_frame_id (frame);
11297 +  old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11298 +
11299    proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
11300 +
11301 +  if (target_can_async_p () && is_running (inferior_ptid))
11302 +    {
11303 +      discard_cleanups (old_chain);
11304 +      add_continuation (tp, until_next_continuation, tp, NULL);
11305 +    }
11306 +  else
11307 +    do_cleanups (old_chain);
11308  }
11309  
11310  static void
11311 @@ -1421,6 +1447,7 @@ finish_command_continuation (void *arg)
11312    if (bs != NULL && tp->proceed_to_finish)
11313      observer_notify_normal_stop (bs, 1 /* print frame */);
11314    delete_breakpoint (a->breakpoint);
11315 +  delete_longjmp_breakpoint (inferior_thread ()->num);
11316  }
11317  
11318  static void
11319 @@ -1504,6 +1531,7 @@ finish_forward (struct symbol *function, struct frame_info *frame)
11320    struct breakpoint *breakpoint;
11321    struct cleanup *old_chain;
11322    struct finish_command_continuation_args *cargs;
11323 +  int thread = tp->num;
11324  
11325    sal = find_pc_line (get_frame_pc (frame), 0);
11326    sal.pc = get_frame_pc (frame);
11327 @@ -1514,6 +1542,10 @@ finish_forward (struct symbol *function, struct frame_info *frame)
11328  
11329    old_chain = make_cleanup_delete_breakpoint (breakpoint);
11330  
11331 +  set_longjmp_breakpoint (thread);
11332 +  tp->initiating_frame = get_frame_id (frame);
11333 +  make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11334 +
11335    tp->proceed_to_finish = 1;    /* We want stop_registers, please...  */
11336    proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
11337  
11338 diff --git a/gdb/inferior.h b/gdb/inferior.h
11339 index f1b5d17..31add7d 100644
11340 --- a/gdb/inferior.h
11341 +++ b/gdb/inferior.h
11342 @@ -272,6 +272,8 @@ extern void interrupt_target_command (char *args, int from_tty);
11343  
11344  extern void interrupt_target_1 (int all_threads);
11345  
11346 +extern void delete_longjmp_breakpoint_cleanup (void *arg);
11347 +
11348  extern void detach_command (char *, int);
11349  
11350  extern void notice_new_inferior (ptid_t, int, int);
11351 diff --git a/gdb/infrun.c b/gdb/infrun.c
11352 index 1a83a25..2ee2164 100644
11353 --- a/gdb/infrun.c
11354 +++ b/gdb/infrun.c
11355 @@ -45,6 +45,8 @@
11356  #include "language.h"
11357  #include "solib.h"
11358  #include "main.h"
11359 +#include "dictionary.h"
11360 +#include "block.h"
11361  #include "gdb_assert.h"
11362  #include "mi/mi-common.h"
11363  #include "event-top.h"
11364 @@ -1782,6 +1784,8 @@ static void insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
11365                                                   struct symtab_and_line sr_sal,
11366                                                   struct frame_id sr_id);
11367  static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
11368 +static void check_exception_resume (struct execution_control_state *,
11369 +                                   struct frame_info *, struct symbol *);
11370  
11371  static void stop_stepping (struct execution_control_state *ecs);
11372  static void prepare_to_wait (struct execution_control_state *ecs);
11373 @@ -2687,6 +2691,10 @@ handle_inferior_event (struct execution_control_state *ecs)
11374  
11375        stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
11376  
11377 +      /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
11378 +        confuse bpstat_stop_status and bpstat_explains_signal.  */
11379 +      watchpoints_triggered (&ecs->ws);
11380 +
11381        ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
11382  
11383        ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
11384 @@ -2724,6 +2732,10 @@ handle_inferior_event (struct execution_control_state *ecs)
11385  
11386        stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
11387  
11388 +      /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
11389 +        confuse bpstat_stop_status and bpstat_explains_signal.  */
11390 +      watchpoints_triggered (&ecs->ws);
11391 +
11392        /* This causes the eventpoints and symbol table to be reset.
11393           Must do this now, before trying to determine whether to
11394           stop.  */
11395 @@ -3468,23 +3480,33 @@ process_event_stop_test:
11396  
11397         ecs->event_thread->stepping_over_breakpoint = 1;
11398  
11399 -       if (!gdbarch_get_longjmp_target_p (gdbarch)
11400 -           || !gdbarch_get_longjmp_target (gdbarch, frame, &jmp_buf_pc))
11401 +       if (what.is_longjmp)
11402           {
11403 -           if (debug_infrun)
11404 -             fprintf_unfiltered (gdb_stdlog, "\
11405 +           if (!gdbarch_get_longjmp_target_p (gdbarch)
11406 +               || !gdbarch_get_longjmp_target (gdbarch,
11407 +                                               frame, &jmp_buf_pc))
11408 +             {
11409 +               if (debug_infrun)
11410 +                 fprintf_unfiltered (gdb_stdlog, "\
11411  infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
11412 -           keep_going (ecs);
11413 -           return;
11414 -         }
11415 +               keep_going (ecs);
11416 +               return;
11417 +             }
11418  
11419 -       /* We're going to replace the current step-resume breakpoint
11420 -          with a longjmp-resume breakpoint.  */
11421 -       delete_step_resume_breakpoint (ecs->event_thread);
11422 +           /* We're going to replace the current step-resume breakpoint
11423 +              with a longjmp-resume breakpoint.  */
11424 +           delete_step_resume_breakpoint (ecs->event_thread);
11425  
11426 -       /* Insert a breakpoint at resume address.  */
11427 -       insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
11428 +           /* Insert a breakpoint at resume address.  */
11429 +           insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
11430 +         }
11431 +       else
11432 +         {
11433 +           struct symbol *func = get_frame_function (frame);
11434  
11435 +           if (func)
11436 +             check_exception_resume (ecs, frame, func);
11437 +         }
11438         keep_going (ecs);
11439         return;
11440  
11441 @@ -3496,6 +3518,53 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
11442         gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
11443         delete_step_resume_breakpoint (ecs->event_thread);
11444  
11445 +       if (!what.is_longjmp)
11446 +         {
11447 +           /* There are several cases to consider.
11448 +              
11449 +              1. The initiating frame no longer exists.  In this case
11450 +              we must stop, because the exception has gone too far.
11451 +              
11452 +              2. The initiating frame exists, and is the same as the
11453 +              current frame.
11454 +              
11455 +              2.1. If we are stepping, defer to the stepping logic.
11456 +              
11457 +              2.2. Otherwise, we are not stepping, so we are doing a
11458 +              "finish" and we have reached the calling frame.  So,
11459 +              stop.
11460 +              
11461 +              3. The initiating frame exists and is different from
11462 +              the current frame.  This means the exception has been
11463 +              caught beneath the initiating frame, so keep going.  */
11464 +           struct frame_info *init_frame
11465 +             = frame_find_by_id (ecs->event_thread->initiating_frame);
11466 +           if (init_frame)
11467 +             {
11468 +               struct frame_id current_id
11469 +                 = get_frame_id (get_current_frame ());
11470 +               if (frame_id_eq (current_id,
11471 +                                ecs->event_thread->initiating_frame))
11472 +                 {
11473 +                   if (ecs->event_thread->step_range_start)
11474 +                     {
11475 +                       /* Case 2.1.  */
11476 +                       break;
11477 +                     }
11478 +                   else
11479 +                     {
11480 +                       /* Case 2.2: fall through.  */
11481 +                     }
11482 +                 }
11483 +               else
11484 +                 {
11485 +                   /* Case 3.  */
11486 +                   keep_going (ecs);
11487 +                   return;
11488 +                 }
11489 +             }
11490 +         }
11491 +
11492         ecs->event_thread->stop_step = 1;
11493         print_stop_reason (END_STEPPING_RANGE, 0);
11494         stop_stepping (ecs);
11495 @@ -4500,6 +4569,96 @@ insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
11496      set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
11497  }
11498  
11499 +/* Insert an exception resume breakpoint.  TP is the thread throwing
11500 +   the exception.  The block B is the block of the unwinder debug hook
11501 +   function.  FRAME is the frame corresponding to the call to this
11502 +   function.  SYM is the symbol of the function argument holding the
11503 +   target PC of the exception.  */
11504 +
11505 +static void
11506 +insert_exception_resume_breakpoint (struct thread_info *tp,
11507 +                                   struct block *b,
11508 +                                   struct frame_info *frame,
11509 +                                   struct symbol *sym)
11510 +{
11511 +  struct gdb_exception e;
11512 +
11513 +  /* We want to ignore errors here.  */
11514 +  TRY_CATCH (e, RETURN_MASK_ALL)
11515 +    {
11516 +      struct symbol *vsym;
11517 +      struct value *value;
11518 +      CORE_ADDR handler;
11519 +      struct breakpoint *bp;
11520 +
11521 +      vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
11522 +      value = read_var_value (vsym, frame);
11523 +      handler = value_as_address (value);
11524 +
11525 +      /* We're going to replace the current step-resume breakpoint
11526 +        with an exception-resume breakpoint.  */
11527 +      delete_step_resume_breakpoint (tp);
11528 +
11529 +      if (debug_infrun)
11530 +       fprintf_unfiltered (gdb_stdlog,
11531 +                           "infrun: exception resume at %lx\n",
11532 +                           (unsigned long) handler);
11533 +
11534 +      bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
11535 +                                          handler, bp_exception_resume);
11536 +      inferior_thread ()->step_resume_breakpoint = bp;
11537 +    }
11538 +}
11539 +
11540 +/* This is called when an exception has been intercepted.  Check to
11541 +   see whether the exception's destination is of interest, and if so,
11542 +   set an exception resume breakpoint there.  */
11543 +
11544 +static void
11545 +check_exception_resume (struct execution_control_state *ecs,
11546 +                       struct frame_info *frame, struct symbol *func)
11547 +{
11548 +  struct gdb_exception e;
11549 +
11550 +  TRY_CATCH (e, RETURN_MASK_ALL)
11551 +    {
11552 +      struct block *b;
11553 +      struct dict_iterator iter;
11554 +      struct symbol *sym;
11555 +      int argno = 0;
11556 +
11557 +      /* The exception breakpoint is a thread-specific breakpoint on
11558 +        the unwinder's debug hook, declared as:
11559 +        
11560 +        void _Unwind_DebugHook (void *cfa, void *handler);
11561 +        
11562 +        The CFA argument indicates the frame to which control is
11563 +        about to be transferred.  HANDLER is the destination PC.
11564 +        
11565 +        We ignore the CFA and set a temporary breakpoint at HANDLER.
11566 +        This is not extremely efficient but it avoids issues in gdb
11567 +        with computing the DWARF CFA, and it also works even in weird
11568 +        cases such as throwing an exception from inside a signal
11569 +        handler.  */
11570 +
11571 +      b = SYMBOL_BLOCK_VALUE (func);
11572 +      ALL_BLOCK_SYMBOLS (b, iter, sym)
11573 +       {
11574 +         if (!SYMBOL_IS_ARGUMENT (sym))
11575 +           continue;
11576 +
11577 +         if (argno == 0)
11578 +           ++argno;
11579 +         else
11580 +           {
11581 +             insert_exception_resume_breakpoint (ecs->event_thread,
11582 +                                                 b, frame, sym);
11583 +             break;
11584 +           }
11585 +       }
11586 +    }
11587 +}
11588 +
11589  static void
11590  stop_stepping (struct execution_control_state *ecs)
11591  {
11592 @@ -4568,6 +4727,8 @@ keep_going (struct execution_control_state *ecs)
11593             }
11594           if (e.reason < 0)
11595             {
11596 +             if (debug_infrun)
11597 +               exception_fprintf (gdb_stdlog, e, "infrun: exception while inserting breakpoints: ");
11598               stop_stepping (ecs);
11599               return;
11600             }
11601 diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
11602 index 6b68e7d..5095180 100644
11603 --- a/gdb/jv-lang.c
11604 +++ b/gdb/jv-lang.c
11605 @@ -1121,6 +1121,7 @@ const struct exp_descriptor exp_descriptor_java =
11606  {
11607    print_subexp_standard,
11608    operator_length_standard,
11609 +  operator_check_standard,
11610    op_name_standard,
11611    dump_subexp_body_standard,
11612    evaluate_subexp_java
11613 diff --git a/gdb/language.h b/gdb/language.h
11614 index c650e07..660fdf6 100644
11615 --- a/gdb/language.h
11616 +++ b/gdb/language.h
11617 @@ -237,7 +237,6 @@ struct language_defn
11618         variables.  */
11619  
11620      struct symbol *(*la_lookup_symbol_nonlocal) (const char *,
11621 -                                                const char *,
11622                                                  const struct block *,
11623                                                  const domain_enum);
11624  
11625 diff --git a/gdb/linespec.c b/gdb/linespec.c
11626 index 3e943a1..b96d425 100644
11627 --- a/gdb/linespec.c
11628 +++ b/gdb/linespec.c
11629 @@ -30,6 +30,7 @@
11630  #include "value.h"
11631  #include "completer.h"
11632  #include "cp-abi.h"
11633 +#include "cp-support.h"
11634  #include "parser-defs.h"
11635  #include "block.h"
11636  #include "objc-lang.h"
11637 @@ -839,13 +840,33 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
11638      }
11639    else if (paren_pointer != NULL)
11640      {
11641 -      p = paren_pointer + 1;
11642 +      /* We need to deal with method and function overloads
11643 +        with no parameters. Gdb and gcc (and who knows about other
11644 +        compilers) are very inconsistent with the keyword "void".
11645 +        Canonicalizing C++ types is insufficient in this case, since
11646 +        we still need to enforce the presence (or lack thereof) of
11647 +        "void". For simplicity, omit the keyword "void" if present. */
11648 +      if (strncmp (paren_pointer - 5, "(void)", 6) == 0)
11649 +       {
11650 +         char *a, *b;
11651 +         a = paren_pointer - 4;
11652 +         b = paren_pointer;
11653 +         while ((*(a++) = *(b++)) != '\0') ;
11654 +         *a = '\0';
11655 +         p = paren_pointer - 3;
11656 +       }
11657 +      else
11658 +       p = paren_pointer + 1;
11659      }
11660    else
11661      {
11662        p = skip_quoted (*argptr);
11663      }
11664  
11665 +  /* Make sure we keep important kewords like "const" */
11666 +  if (strncmp (p, " const", 6) == 0)
11667 +    p += 6;
11668 +
11669    /* Keep any template parameters */
11670    if (*p == '<')
11671      p = find_template_name_end (p);
11672 @@ -1257,6 +1278,9 @@ decode_compound (char **argptr, int funfirstline, char ***canonical,
11673        /* Move pointer ahead to next double-colon.  */
11674        while (*p && (p[0] != ' ') && (p[0] != '\t') && (p[0] != '\''))
11675         {
11676 +         if (current_language->la_language == language_cplus)
11677 +           p += cp_validate_operator (p);
11678 +
11679           if (p[0] == '<')
11680             {
11681               temp_end = find_template_name_end (p);
11682 @@ -1334,6 +1358,15 @@ decode_compound (char **argptr, int funfirstline, char ***canonical,
11683           while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p != ':')
11684             p++;
11685           /* At this point p->"".  String ended.  */
11686 +         /* Nope, C++ operators could have spaces in them
11687 +            ("foo::operator <" or "foo::operator delete []").
11688 +            I apologize, this is a bit hacky...  */
11689 +         if (current_language->la_language == language_cplus
11690 +             && *p == ' ' && p - 8 - *argptr + 1 > 0)
11691 +           {
11692 +             /* The above loop has already swallowed "operator".  */
11693 +             p += cp_validate_operator (p - 8) - 8;
11694 +           }
11695         }
11696  
11697        /* Allocate our own copy of the substring between argptr and
11698 @@ -1407,6 +1440,7 @@ lookup_prefix_sym (char **argptr, char *p)
11699  {
11700    char *p1;
11701    char *copy;
11702 +  struct symbol *sym;
11703  
11704    /* Extract the class name.  */
11705    p1 = p;
11706 @@ -1425,7 +1459,26 @@ lookup_prefix_sym (char **argptr, char *p)
11707    /* At this point p1->"::inA::fun", p->"inA::fun" copy->"AAA",
11708       argptr->"inA::fun" */
11709  
11710 -  return lookup_symbol (copy, 0, STRUCT_DOMAIN, 0);
11711 +  sym = lookup_symbol (copy, 0, STRUCT_DOMAIN, 0);
11712 +  if (sym == NULL)
11713 +    {
11714 +      /* Typedefs are in VAR_DOMAIN so the above symbol lookup will
11715 +        fail when the user attempts to lookup a method of a class
11716 +        via a typedef'd name (NOT via the classes name, which is already
11717 +        handled in symbol_matches_domain).  So try the lookup again
11718 +        using VAR_DOMAIN (where typedefs live) and double-check that we
11719 +        found a struct/class type.  */
11720 +      struct symbol *s = lookup_symbol (copy, 0, VAR_DOMAIN, 0);
11721 +      if (s != NULL)
11722 +       {
11723 +         struct type *t = SYMBOL_TYPE (s);
11724 +         CHECK_TYPEDEF (t);
11725 +         if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
11726 +           return s;
11727 +       }
11728 +    }
11729 +
11730 +  return sym;
11731  }
11732  
11733  /* This finds the method COPY in the class whose type is T and whose
11734 @@ -1474,26 +1527,16 @@ find_method (int funfirstline, char ***canonical, char *saved_arg,
11735      }
11736    else
11737      {
11738 -      char *tmp;
11739 -
11740 -      if (is_operator_name (copy))
11741 -       {
11742 -         tmp = (char *) alloca (strlen (copy + 3) + 9);
11743 -         strcpy (tmp, "operator ");
11744 -         strcat (tmp, copy + 3);
11745 -       }
11746 -      else
11747 -       tmp = copy;
11748        if (not_found_ptr)
11749          *not_found_ptr = 1;
11750 -      if (tmp[0] == '~')
11751 +      if (copy[0] == '~')
11752         cplusplus_error (saved_arg,
11753                          "the class `%s' does not have destructor defined\n",
11754                          SYMBOL_PRINT_NAME (sym_class));
11755        else
11756         cplusplus_error (saved_arg,
11757                          "the class %s does not have any method named %s\n",
11758 -                        SYMBOL_PRINT_NAME (sym_class), tmp);
11759 +                        SYMBOL_PRINT_NAME (sym_class), copy);
11760      }
11761  }
11762  
11763 @@ -1780,7 +1823,7 @@ symbol_found (int funfirstline, char ***canonical, char *copy,
11764         {
11765           struct blockvector *bv = BLOCKVECTOR (SYMBOL_SYMTAB (sym));
11766           struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
11767 -         if (lookup_block_symbol (b, copy, NULL, VAR_DOMAIN) != NULL)
11768 +         if (lookup_block_symbol (b, copy, VAR_DOMAIN) != NULL)
11769             build_canonical_line_spec (values.sals, copy, canonical);
11770         }
11771        return values;
11772 diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
11773 index 98f6347..0907f03 100644
11774 --- a/gdb/linux-nat.c
11775 +++ b/gdb/linux-nat.c
11776 @@ -1710,6 +1710,7 @@ resume_callback (struct lwp_info *lp, void *data)
11777        lp->stopped = 0;
11778        lp->step = 0;
11779        memset (&lp->siginfo, 0, sizeof (lp->siginfo));
11780 +      lp->watchpoint_hit_set = 0;
11781      }
11782    else if (lp->stopped && debug_linux_nat)
11783      fprintf_unfiltered (gdb_stdlog, "RC: Not resuming sibling %s (has pending)\n",
11784 @@ -1847,6 +1848,7 @@ linux_nat_resume (struct target_ops *ops,
11785  
11786    linux_ops->to_resume (linux_ops, ptid, step, signo);
11787    memset (&lp->siginfo, 0, sizeof (lp->siginfo));
11788 +  lp->watchpoint_hit_set = 0;
11789  
11790    if (debug_linux_nat)
11791      fprintf_unfiltered (gdb_stdlog,
11792 @@ -2286,6 +2288,78 @@ maybe_clear_ignore_sigint (struct lwp_info *lp)
11793      }
11794  }
11795  
11796 +/* Fetch the possible triggered data watchpoint info and store it to LP.
11797 +   The hardware data watchpoint trigger gets cleared during this fetch.  */
11798 +
11799 +static void
11800 +save_sigtrap (struct lwp_info *lp)
11801 +{
11802 +  struct cleanup *old_chain;
11803 +
11804 +  /* linux_nat_stopped_data_address is not even installed in this case.  */
11805 +  if (linux_ops->to_stopped_data_address == NULL)
11806 +    return;
11807 +
11808 +  old_chain = save_inferior_ptid ();
11809 +  inferior_ptid = lp->ptid;
11810 +
11811 +  lp->watchpoint_hit_set =
11812 +    linux_ops->to_stopped_data_address (&current_target, &lp->watchpoint_hit);
11813 +
11814 +  do_cleanups (old_chain);
11815 +}
11816 +
11817 +/* Wrap target_stopped_data_address where the GNU/Linux native target may be
11818 +   directed by the watchpoint/debug register number.  Base the reported value
11819 +   on the triggered data address instead.  During inferior stop the assignment
11820 +   of watchpoint/debug registers may change making the register number specific
11821 +   trigger info stale.  */
11822 +
11823 +static int
11824 +linux_nat_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
11825 +{
11826 +  struct lwp_info *lp = find_lwp_pid (inferior_ptid);
11827 +
11828 +  gdb_assert (lp != NULL);
11829 +
11830 +  *addr_p = lp->watchpoint_hit;
11831 +
11832 +  return lp->watchpoint_hit_set;
11833 +}
11834 +
11835 +/* In `set follow-fork-mode child' with multithreaded parent we need to detach
11836 +   watchpoints from all the LWPs.  In such case INFERIOR_PTID will be the
11837 +   non-threaded new child while LWP_LIST will still contain all the threads of
11838 +   the parent being detached.  */
11839 +
11840 +static int
11841 +linux_nat_detach_watchpoints (void)
11842 +{
11843 +  struct lwp_info *lp;
11844 +  int found = 0, retval = 0;
11845 +  ptid_t filter = pid_to_ptid (ptid_get_pid (inferior_ptid));
11846 +  struct cleanup *old_chain = save_inferior_ptid ();
11847 +
11848 +  for (lp = lwp_list; lp; lp = lp->next)
11849 +    if (ptid_match (lp->ptid, filter))
11850 +      {
11851 +       inferior_ptid = lp->ptid;
11852 +       retval |= linux_ops->to_detach_watchpoints ();
11853 +       found = 1;
11854 +      }
11855 +
11856 +  do_cleanups (old_chain);
11857 +
11858 +  if (!found)
11859 +    {
11860 +      gdb_assert (!is_lwp (inferior_ptid));
11861 +
11862 +      retval |= linux_ops->to_detach_watchpoints ();
11863 +    }
11864 +
11865 +  return retval;
11866 +}
11867 +
11868  /* Wait until LP is stopped.  */
11869  
11870  static int
11871 @@ -2337,6 +2411,8 @@ stop_wait_callback (struct lwp_info *lp, void *data)
11872               /* Save the trap's siginfo in case we need it later.  */
11873               save_siginfo (lp);
11874  
11875 +             save_sigtrap (lp);
11876 +
11877               /* Now resume this LWP and get the SIGSTOP event. */
11878               errno = 0;
11879               ptrace (PTRACE_CONT, GET_LWP (lp->ptid), 0, 0);
11880 @@ -2701,10 +2777,14 @@ linux_nat_filter_event (int lwpid, int status, int options)
11881        add_thread (lp->ptid);
11882      }
11883  
11884 -  /* Save the trap's siginfo in case we need it later.  */
11885    if (WIFSTOPPED (status)
11886        && (WSTOPSIG (status) == SIGTRAP || WSTOPSIG (status) == TRAP_IS_SYSCALL))
11887 -    save_siginfo (lp);
11888 +    {
11889 +      /* Save the trap's siginfo in case we need it later.  */
11890 +      save_siginfo (lp);
11891 +
11892 +      save_sigtrap (lp);
11893 +    }
11894  
11895    /* Handle GNU/Linux's extended waitstatus for trace events.
11896       It is necessary to check if WSTOPSIG is signaling that
11897 @@ -4999,6 +5079,10 @@ linux_nat_add_target (struct target_ops *t)
11898    t->to_thread_alive = linux_nat_thread_alive;
11899    t->to_pid_to_str = linux_nat_pid_to_str;
11900    t->to_has_thread_control = tc_schedlock;
11901 +  if (linux_ops->to_stopped_data_address)
11902 +    t->to_stopped_data_address = linux_nat_stopped_data_address;
11903 +  if (linux_ops->to_detach_watchpoints)
11904 +    t->to_detach_watchpoints = linux_nat_detach_watchpoints;
11905  
11906    t->to_can_async_p = linux_nat_can_async_p;
11907    t->to_is_async_p = linux_nat_is_async_p;
11908 diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h
11909 index eae74f3..73204fc 100644
11910 --- a/gdb/linux-nat.h
11911 +++ b/gdb/linux-nat.h
11912 @@ -62,6 +62,12 @@ struct lwp_info
11913       be the address of a hardware watchpoint.  */
11914    struct siginfo siginfo;
11915  
11916 +  /* WATCHPOINT_HIT_SET is non-zero if this LWP stopped with a trap and a data
11917 +     watchpoint has been found as triggered.  In such case WATCHPOINT_HIT
11918 +     contains data address of the triggered data watchpoint.  */
11919 +  unsigned watchpoint_hit_set : 1;
11920 +  CORE_ADDR watchpoint_hit;
11921 +
11922    /* Non-zero if we expect a duplicated SIGINT.  */
11923    int ignore_sigint;
11924  
11925 diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
11926 index 88c7e5e..2d0b3ca 100644
11927 --- a/gdb/m2-lang.c
11928 +++ b/gdb/m2-lang.c
11929 @@ -356,6 +356,7 @@ const struct exp_descriptor exp_descriptor_modula2 =
11930  {
11931    print_subexp_standard,
11932    operator_length_standard,
11933 +  operator_check_standard,
11934    op_name_standard,
11935    dump_subexp_body_standard,
11936    evaluate_subexp_modula2
11937 diff --git a/gdb/machoread.c b/gdb/machoread.c
11938 index 5f9a0fe..66fa067 100644
11939 --- a/gdb/machoread.c
11940 +++ b/gdb/machoread.c
11941 @@ -681,6 +681,7 @@ static struct sym_fns macho_sym_fns = {
11942    macho_new_init,               /* sym_new_init: init anything gbl to entire symtab */
11943    macho_symfile_init,           /* sym_init: read initial info, setup for sym_read() */
11944    macho_symfile_read,           /* sym_read: read a symbol file into symtab */
11945 +  NULL,                                /* sym_read_psymbols */
11946    macho_symfile_finish,         /* sym_finish: finished with file, cleanup */
11947    macho_symfile_offsets,        /* sym_offsets:  xlate external to internal form */
11948    NULL                          /* next: pointer to next struct sym_fns */
11949 diff --git a/gdb/main.c b/gdb/main.c
11950 index 55411a8..ac9a540 100644
11951 --- a/gdb/main.c
11952 +++ b/gdb/main.c
11953 @@ -40,6 +40,7 @@
11954  #include "interps.h"
11955  #include "main.h"
11956  
11957 +#include "python/python.h"
11958  #include "source.h"
11959  
11960  /* If nonzero, display time usage both at startup and for each command.  */
11961 @@ -259,6 +260,8 @@ captured_main (void *data)
11962    char *cdarg = NULL;
11963    char *ttyarg = NULL;
11964  
11965 +  int python_script = 0;
11966 +
11967    /* These are static so that we can take their address in an initializer.  */
11968    static int print_help;
11969    static int print_version;
11970 @@ -434,10 +437,14 @@ captured_main (void *data)
11971        {"args", no_argument, &set_args, 1},
11972       {"l", required_argument, 0, 'l'},
11973        {"return-child-result", no_argument, &return_child_result, 1},
11974 +#if HAVE_PYTHON
11975 +      {"python", no_argument, 0, 'P'},
11976 +      {"P", no_argument, 0, 'P'},
11977 +#endif
11978        {0, no_argument, 0, 0}
11979      };
11980  
11981 -    while (1)
11982 +    while (!python_script)
11983        {
11984         int option_index;
11985  
11986 @@ -455,6 +462,9 @@ captured_main (void *data)
11987           case 0:
11988             /* Long option that just sets a flag.  */
11989             break;
11990 +         case 'P':
11991 +           python_script = 1;
11992 +           break;
11993           case OPT_SE:
11994             symarg = optarg;
11995             execarg = optarg;
11996 @@ -631,7 +641,31 @@ extern int gdbtk_test (char *);
11997         use_windows = 0;
11998        }
11999  
12000 -    if (set_args)
12001 +    if (python_script)
12002 +      {
12003 +       /* The first argument is a python script to evaluate, and
12004 +          subsequent arguments are passed to the script for
12005 +          processing there.  */
12006 +       if (optind >= argc)
12007 +         {
12008 +           fprintf_unfiltered (gdb_stderr,
12009 +                               _("%s: Python script file name required\n"),
12010 +                               argv[0]);
12011 +           exit (1);
12012 +         }
12013 +
12014 +       /* FIXME: should handle inferior I/O intelligently here.
12015 +          E.g., should be possible to run gdb in pipeline and have
12016 +          Python (and gdb) output go to stderr or file; and if a
12017 +          prompt is needed, open the tty.  */
12018 +       quiet = 1;
12019 +       /* FIXME: should read .gdbinit if, and only if, a prompt is
12020 +          requested by the script.  Though... maybe this is not
12021 +          ideal?  */
12022 +       /* FIXME: likewise, reading in history.  */
12023 +       inhibit_gdbinit = 1;
12024 +      }
12025 +    else if (set_args)
12026        {
12027         /* The remaining options are the command-line options for the
12028            inferior.  The first one is the sym/exec file, and the rest
12029 @@ -864,7 +898,8 @@ Can't attach to process and specify a core file at the same time."));
12030    xfree (cmdarg);
12031  
12032    /* Read in the old history after all the command files have been read. */
12033 -  init_history ();
12034 +  if (!python_script)
12035 +    init_history ();
12036  
12037    if (batch)
12038      {
12039 @@ -893,13 +928,25 @@ Can't attach to process and specify a core file at the same time."));
12040  #endif
12041      }
12042  
12043 -  /* NOTE: cagney/1999-11-07: There is probably no reason for not
12044 -     moving this loop and the code found in captured_command_loop()
12045 -     into the command_loop() proper.  The main thing holding back that
12046 -     change - SET_TOP_LEVEL() - has been eliminated. */
12047 -  while (1)
12048 +#if HAVE_PYTHON
12049 +  if (python_script)
12050      {
12051 -      catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
12052 +      extern int pagination_enabled;
12053 +      pagination_enabled = 0;
12054 +      run_python_script (argc - optind, &argv[optind]);
12055 +      return 1;
12056 +    }
12057 +  else
12058 +#endif
12059 +    {
12060 +      /* NOTE: cagney/1999-11-07: There is probably no reason for not
12061 +        moving this loop and the code found in captured_command_loop()
12062 +        into the command_loop() proper.  The main thing holding back that
12063 +        change - SET_TOP_LEVEL() - has been eliminated. */
12064 +      while (1)
12065 +       {
12066 +         catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
12067 +       }
12068      }
12069    /* No exit -- exit is through quit_command.  */
12070  }
12071 @@ -931,7 +978,12 @@ print_gdb_help (struct ui_file *stream)
12072    fputs_unfiltered (_("\
12073  This is the GNU debugger.  Usage:\n\n\
12074      gdb [options] [executable-file [core-file or process-id]]\n\
12075 -    gdb [options] --args executable-file [inferior-arguments ...]\n\n\
12076 +    gdb [options] --args executable-file [inferior-arguments ...]\n"), stream);
12077 +#if HAVE_PYTHON
12078 +  fputs_unfiltered (_("\
12079 +    gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream);
12080 +#endif
12081 +  fputs_unfiltered (_("\n\
12082  Options:\n\n\
12083  "), stream);
12084    fputs_unfiltered (_("\
12085 @@ -969,7 +1021,13 @@ Options:\n\n\
12086    --nw              Do not use a window interface.\n\
12087    --nx               Do not read "), stream);
12088    fputs_unfiltered (gdbinit, stream);
12089 -  fputs_unfiltered (_(" file.\n\
12090 +  fputs_unfiltered (_(" file.\n"), stream);
12091 +#if HAVE_PYTHON
12092 +  fputs_unfiltered (_("\
12093 +  --python, -P       Following argument is Python script file; remaining\n\
12094 +                     arguments are passed to script.\n"), stream);
12095 +#endif
12096 +  fputs_unfiltered (_("\
12097    --quiet            Do not print version number on startup.\n\
12098    --readnow          Fully read symbol files on first access.\n\
12099  "), stream);
12100 diff --git a/gdb/maint.c b/gdb/maint.c
12101 index ecbae12..80fc36e 100644
12102 --- a/gdb/maint.c
12103 +++ b/gdb/maint.c
12104 @@ -914,4 +914,12 @@ When enabled GDB is profiled."),
12105                            show_maintenance_profile_p,
12106                            &maintenance_set_cmdlist,
12107                            &maintenance_show_cmdlist);
12108 +  add_setshow_filename_cmd ("gdb_datadir", class_maintenance,
12109 +                           &gdb_datadir, _("Set GDB's datadir path."),
12110 +                           _("Show GDB's datadir path."),
12111 +                           _("\
12112 +When set, GDB uses the specified path to search for data files."),
12113 +                           NULL, NULL,
12114 +                           &maintenance_set_cmdlist,
12115 +                           &maintenance_show_cmdlist);
12116  }
12117 diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
12118 index aac82e9..626292c 100644
12119 --- a/gdb/mdebugread.c
12120 +++ b/gdb/mdebugread.c
12121 @@ -4802,7 +4802,7 @@ new_type (char *name)
12122  {
12123    struct type *t;
12124  
12125 -  t = alloc_type (current_objfile);
12126 +  t = alloc_type (current_objfile, NULL);
12127    TYPE_NAME (t) = name;
12128    TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
12129    return t;
12130 diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
12131 index 0baaa83..94ebfeb 100644
12132 --- a/gdb/mi/mi-cmd-var.c
12133 +++ b/gdb/mi/mi-cmd-var.c
12134 @@ -697,7 +697,6 @@ mi_cmd_var_update (char *command, char **argv, int argc)
12135      }
12136    else
12137      {
12138 -      /* Get varobj handle, if a valid var obj name was specified */
12139        struct varobj *var = varobj_get_handle (name);
12140  
12141        varobj_update_one (var, print_values, 1 /* explicit */);
12142 diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
12143 index 857a5d5..6181002 100644
12144 --- a/gdb/mi/mi-main.c
12145 +++ b/gdb/mi/mi-main.c
12146 @@ -1130,7 +1130,7 @@ mi_cmd_list_features (char *command, char **argv, int argc)
12147        ui_out_field_string (uiout, NULL, "frozen-varobjs");
12148        ui_out_field_string (uiout, NULL, "pending-breakpoints");
12149        ui_out_field_string (uiout, NULL, "thread-info");
12150 -      
12151 +
12152  #if HAVE_PYTHON
12153        ui_out_field_string (uiout, NULL, "python");
12154  #endif
12155 diff --git a/gdb/mipsread.c b/gdb/mipsread.c
12156 index a84003f..924c1c5 100644
12157 --- a/gdb/mipsread.c
12158 +++ b/gdb/mipsread.c
12159 @@ -394,6 +394,7 @@ static struct sym_fns ecoff_sym_fns =
12160    mipscoff_new_init,           /* sym_new_init: init anything gbl to entire symtab */
12161    mipscoff_symfile_init,       /* sym_init: read initial info, setup for sym_read() */
12162    mipscoff_symfile_read,       /* sym_read: read a symbol file into symtab */
12163 +  NULL,                                /* sym_read_psymbols */
12164    mipscoff_symfile_finish,     /* sym_finish: finished with file, cleanup */
12165    default_symfile_offsets,     /* sym_offsets: dummy FIXME til implem sym reloc */
12166    default_symfile_segments,    /* sym_segments: Get segment information from
12167 diff --git a/gdb/objfiles.c b/gdb/objfiles.c
12168 index 8dcca70..4b25a5a 100644
12169 --- a/gdb/objfiles.c
12170 +++ b/gdb/objfiles.c
12171 @@ -731,6 +731,20 @@ have_partial_symbols (void)
12172      if (objfile_has_partial_symbols (ofp))
12173        return 1;
12174    }
12175 +
12176 +  /* Try again, after reading partial symbols.  We do this in two
12177 +     passes because objfiles are always added to the head of the list,
12178 +     and there might be a later objfile for which we've already read
12179 +     partial symbols.  */
12180 +  ALL_OBJFILES (ofp)
12181 +  {
12182 +    require_partial_symbols (ofp);
12183 +    if (ofp->psymtabs != NULL)
12184 +      {
12185 +       return 1;
12186 +      }
12187 +  }
12188 +
12189    return 0;
12190  }
12191  
12192 diff --git a/gdb/objfiles.h b/gdb/objfiles.h
12193 index 62fa498..1fc9c6a 100644
12194 --- a/gdb/objfiles.h
12195 +++ b/gdb/objfiles.h
12196 @@ -212,6 +212,11 @@ struct objfile
12197  
12198      struct partial_symtab *psymtabs;
12199  
12200 +    /* An address map that can be used to quickly determine if an
12201 +       address comes from this objfile.  This can be NULL.  */
12202 +
12203 +    struct addrmap *quick_addrmap;
12204 +
12205      /* Map addresses to the entries of PSYMTABS.  It would be more efficient to
12206         have a map per the whole process but ADDRMAP cannot selectively remove
12207         its items during FREE_OBJFILE.  This mapping is already present even for
12208 @@ -414,6 +419,15 @@ struct objfile
12209  
12210  #define OBJF_USERLOADED        (1 << 3)        /* User loaded */
12211  
12212 +/* Set if we have tried to read partial symtabs for this objfile.
12213 +   This is used to allow lazy reading of partial symtabs.  */
12214 +
12215 +#define OBJF_SYMTABS_READ (1 << 6)
12216 +
12217 +/* This flag is set for the main objfile.  */
12218 +
12219 +#define OBJF_MAIN (1 << 7)
12220 +
12221  /* The object file that the main symbol table was loaded from (e.g. the
12222     argument to the "symbol-file" or "file" command).  */
12223  
12224 @@ -568,6 +582,13 @@ extern void gdb_bfd_unref (struct bfd *abfd);
12225    ALL_OBJFILES (objfile)        \
12226      ALL_OBJFILE_PSYMTABS (objfile, p)
12227  
12228 +/* Like ALL_PSYMTABS, but ensure that partial symbols have been read
12229 +   before examining the objfile.  */
12230 +
12231 +#define ALL_PSYMTABS_REQUIRED(objfile, p)                      \
12232 +  ALL_OBJFILES (objfile)                                       \
12233 +    ALL_OBJFILE_PSYMTABS (require_partial_symbols (objfile), p)
12234 +
12235  /* Traverse all minimal symbols in all objfiles.  */
12236  
12237  #define        ALL_MSYMBOLS(objfile, m) \
12238 diff --git a/gdb/parse.c b/gdb/parse.c
12239 index ef938e3..c243bd8 100644
12240 --- a/gdb/parse.c
12241 +++ b/gdb/parse.c
12242 @@ -63,6 +63,7 @@ const struct exp_descriptor exp_descriptor_standard =
12243    {
12244      print_subexp_standard,
12245      operator_length_standard,
12246 +    operator_check_standard,
12247      op_name_standard,
12248      dump_subexp_body_standard,
12249      evaluate_subexp_standard
12250 @@ -837,6 +838,15 @@ operator_length_standard (struct expression *expr, int endpos,
12251        args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
12252        break;
12253  
12254 +    case TYPE_INSTANCE:
12255 +      oplen = 4 + longest_to_int (expr->elts[endpos - 2].longconst);
12256 +      args = 1;
12257 +      break;
12258 +
12259 +    case TYPE_INSTANCE_LOOKUP:
12260 +      oplen = 3;
12261 +      break;
12262 +
12263      case OP_OBJC_MSGCALL:      /* Objective C message (method) call */
12264        oplen = 4;
12265        args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
12266 @@ -1355,6 +1365,150 @@ parser_fprintf (FILE *x, const char *y, ...)
12267    va_end (args);
12268  }
12269  
12270 +/* Implementation of the exp_descriptor method operator_check.  */
12271 +
12272 +int
12273 +operator_check_standard (struct expression *exp, int pos,
12274 +                        int (*type_func) (struct type *type, void *data),
12275 +                        int (*objfile_func) (struct objfile *objfile,
12276 +                                             void *data),
12277 +                        void *data)
12278 +{
12279 +  const union exp_element *const elts = exp->elts;
12280 +  struct type *type = NULL;
12281 +  struct objfile *objfile = NULL;
12282 +
12283 +  /* Extended operators should have been already handled by exp_descriptor
12284 +     iterate method of its specific language.  */
12285 +  gdb_assert (elts[pos].opcode < OP_EXTENDED0);
12286 +
12287 +  /* Track the callers of write_exp_elt_type for this table.  */
12288 +
12289 +  switch (elts[pos].opcode)
12290 +    {
12291 +    case BINOP_VAL:
12292 +    case OP_COMPLEX:
12293 +    case OP_DECFLOAT:
12294 +    case OP_DOUBLE:
12295 +    case OP_LONG:
12296 +    case OP_SCOPE:
12297 +    case OP_TYPE:
12298 +    case UNOP_CAST:
12299 +    case UNOP_MAX:
12300 +    case UNOP_MEMVAL:
12301 +    case UNOP_MIN:
12302 +      type = elts[pos + 1].type;
12303 +      break;
12304 +
12305 +    case UNOP_MEMVAL_TLS:
12306 +      objfile = elts[pos + 1].objfile;
12307 +      type = elts[pos + 2].type;
12308 +      break;
12309 +
12310 +    case OP_VAR_VALUE:
12311 +      {
12312 +       const struct block *const block = elts[pos + 1].block;
12313 +       const struct symbol *const symbol = elts[pos + 2].symbol;
12314 +       const struct obj_section *const section = SYMBOL_OBJ_SECTION (symbol);
12315 +
12316 +       /* Check objfile where the variable itself is placed.  */
12317 +       if (section && objfile_func && (*objfile_func) (section->objfile, data))
12318 +         return 1;
12319 +
12320 +       /* Check objfile where is placed the code touching the variable.  */
12321 +       objfile = block_objfile (block);
12322 +
12323 +       type = SYMBOL_TYPE (symbol);
12324 +      }
12325 +      break;
12326 +    }
12327 +
12328 +  /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL.  */
12329 +
12330 +  if (type && type_func && (*type_func) (type, data))
12331 +    return 1;
12332 +  if (type && TYPE_OBJFILE (type) && objfile_func
12333 +      && (*objfile_func) (TYPE_OBJFILE (type), data))
12334 +    return 1;
12335 +  if (objfile && objfile_func && (*objfile_func) (objfile, data))
12336 +    return 1;
12337 +
12338 +  return 0;
12339 +}
12340 +
12341 +/* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
12342 +   referenced by EXP.  The functions are never called with NULL TYPE or NULL
12343 +   OBJFILE.  Functions get passed an arbitrary caller supplied DATA pointer.
12344 +   If any of the functions returns non-zero value then (any other) non-zero
12345 +   value is immediately returned to the caller.  Otherwise zero is returned
12346 +   after iterating through whole EXP.  */
12347 +
12348 +static int
12349 +exp_iterate (struct expression *exp,
12350 +            int (*type_func) (struct type *type, void *data),
12351 +            int (*objfile_func) (struct objfile *objfile, void *data),
12352 +            void *data)
12353 +{
12354 +  int endpos;
12355 +  const union exp_element *const elts = exp->elts;
12356 +
12357 +  for (endpos = exp->nelts; endpos > 0; )
12358 +    {
12359 +      int pos, args, oplen = 0;
12360 +
12361 +      exp->language_defn->la_exp_desc->operator_length (exp, endpos,
12362 +                                                       &oplen, &args);
12363 +      gdb_assert (oplen > 0);
12364 +
12365 +      pos = endpos - oplen;
12366 +      if (exp->language_defn->la_exp_desc->operator_check (exp, pos, type_func,
12367 +                                                          objfile_func, data))
12368 +       return 1;
12369 +
12370 +      endpos = pos;
12371 +    }
12372 +
12373 +  return 0;
12374 +}
12375 +
12376 +/* Helper for exp_uses_objfile.  */
12377 +
12378 +static int
12379 +exp_uses_objfile_iter (struct objfile *exp_objfile, void *objfile_voidp)
12380 +{
12381 +  struct objfile *objfile = objfile_voidp;
12382 +
12383 +  return exp_objfile == objfile;
12384 +}
12385 +
12386 +/* Return 1 if EXP uses OBJFILE (and will become dangling when OBJFILE
12387 +   is unloaded), otherwise return 0.  */
12388 +
12389 +int
12390 +exp_uses_objfile (struct expression *exp, struct objfile *objfile)
12391 +{
12392 +  return exp_iterate (exp, NULL, exp_uses_objfile_iter, objfile);
12393 +}
12394 +
12395 +/* Helper for exp_types_mark_used.  */
12396 +
12397 +static int
12398 +exp_types_mark_used_iter (struct type *type, void *unused)
12399 +{
12400 +  type_mark_used (type);
12401 +
12402 +  /* Continue the traversal.  */
12403 +  return 0;
12404 +}
12405 +
12406 +/* Call type_mark_used for any TYPE contained in EXP.  */
12407 +
12408 +void
12409 +exp_types_mark_used (struct expression *exp)
12410 +{
12411 +  exp_iterate (exp, exp_types_mark_used_iter, NULL, NULL);
12412 +}
12413 +
12414  void
12415  _initialize_parse (void)
12416  {
12417 diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
12418 index cbda9c3..a07e6f2 100644
12419 --- a/gdb/parser-defs.h
12420 +++ b/gdb/parser-defs.h
12421 @@ -189,6 +189,13 @@ extern void operator_length (struct expression *, int, int *, int *);
12422  
12423  extern void operator_length_standard (struct expression *, int, int *, int *);
12424  
12425 +extern int operator_check_standard (struct expression *exp, int pos,
12426 +                                   int (*type_func) (struct type *type,
12427 +                                                     void *data),
12428 +                                   int (*objfile_func)
12429 +                                     (struct objfile *objfile, void *data),
12430 +                                   void *data);
12431 +
12432  extern char *op_name_standard (enum exp_opcode);
12433  
12434  extern struct type *follow_types (struct type *);
12435 @@ -267,6 +274,20 @@ struct exp_descriptor
12436         the number of subexpressions it takes.  */
12437      void (*operator_length) (struct expression*, int, int*, int *);
12438  
12439 +    /* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
12440 +       referenced by the single operator of EXP at position POS.  Operator
12441 +       parameters are located at positive (POS + number) offsets in EXP.
12442 +       The functions should never be called with NULL TYPE or NULL OBJFILE.
12443 +       Functions should get passed an arbitrary caller supplied DATA pointer.
12444 +       If any of the functions returns non-zero value then (any other) non-zero
12445 +       value should be immediately returned to the caller.  Otherwise zero
12446 +       should be returned.  */
12447 +    int (*operator_check) (struct expression *exp, int pos,
12448 +                          int (*type_func) (struct type *type, void *data),
12449 +                          int (*objfile_func) (struct objfile *objfile,
12450 +                                               void *data),
12451 +                          void *data);
12452 +
12453      /* Name of this operator for dumping purposes.  */
12454      char *(*op_name) (enum exp_opcode);
12455  
12456 @@ -299,4 +320,8 @@ extern void print_subexp_standard (struct expression *, int *,
12457  
12458  extern void parser_fprintf (FILE *, const char *, ...) ATTR_FORMAT (printf, 2 ,3);
12459  
12460 +extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
12461 +
12462 +extern void exp_types_mark_used (struct expression *exp);
12463 +
12464  #endif /* PARSER_DEFS_H */
12465 diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
12466 index 47b74ad..22fb2fc 100644
12467 --- a/gdb/ppc-linux-nat.c
12468 +++ b/gdb/ppc-linux-nat.c
12469 @@ -1391,6 +1391,24 @@ ppc_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw)
12470    return 0;
12471  }
12472  
12473 +/* See target_detach_watchpoints.  Do not use wrapper
12474 +   ppc_linux_remove_watchpoint as it would modify the register cache
12475 +   (saved_dabr_value).  */
12476 +
12477 +static int
12478 +ppc_linux_detach_watchpoints (void)
12479 +{
12480 +  pid_t tid;
12481 +
12482 +  tid = TIDGET (inferior_ptid);
12483 +  if (tid == 0)
12484 +    tid = PIDGET (inferior_ptid);
12485 +
12486 +  if (ptrace (PTRACE_SET_DEBUGREG, tid, NULL, NULL) < 0)
12487 +    return -1;
12488 +  return 0;
12489 +}
12490 +
12491  static void
12492  ppc_linux_new_thread (ptid_t ptid)
12493  {
12494 @@ -1648,6 +1666,7 @@ _initialize_ppc_linux_nat (void)
12495    t->to_region_ok_for_hw_watchpoint = ppc_linux_region_ok_for_hw_watchpoint;
12496    t->to_insert_watchpoint = ppc_linux_insert_watchpoint;
12497    t->to_remove_watchpoint = ppc_linux_remove_watchpoint;
12498 +  t->to_detach_watchpoints = ppc_linux_detach_watchpoints;
12499    t->to_stopped_by_watchpoint = ppc_linux_stopped_by_watchpoint;
12500    t->to_stopped_data_address = ppc_linux_stopped_data_address;
12501    t->to_watchpoint_addr_within_range = ppc_linux_watchpoint_addr_within_range;
12502 diff --git a/gdb/printcmd.c b/gdb/printcmd.c
12503 index 5d8b936..fb0a455 100644
12504 --- a/gdb/printcmd.c
12505 +++ b/gdb/printcmd.c
12506 @@ -46,7 +46,6 @@
12507  #include "exceptions.h"
12508  #include "observer.h"
12509  #include "solist.h"
12510 -#include "solib.h"
12511  #include "parser-defs.h"
12512  #include "charset.h"
12513  
12514 @@ -900,6 +899,11 @@ print_command_1 (char *exp, int inspect, int voidprint)
12515    else
12516      val = access_value_history (0);
12517  
12518 +  /* Do not try to OBJECT_ADDRESS_SET here anything.  We are interested in the
12519 +     source variable base addresses as found by READ_VAR_VALUE.  The value here
12520 +     can be already a calculated expression address inappropriate for
12521 +     DW_OP_push_object_address.  */
12522 +
12523    if (voidprint || (val && value_type (val) &&
12524                     TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
12525      {
12526 @@ -1396,6 +1400,22 @@ x_command (char *exp, int from_tty)
12527         set_internalvar (lookup_internalvar ("__"), last_examine_value);
12528      }
12529  }
12530 +
12531 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
12532 +
12533 +static void
12534 +print_types_mark_used (void)
12535 +{
12536 +  struct display *d;
12537 +
12538 +  if (last_examine_value)
12539 +    type_mark_used (value_type (last_examine_value));
12540 +
12541 +  for (d = display_chain; d; d = d->next)
12542 +    if (d->exp)
12543 +      exp_types_mark_used (d->exp);
12544 +}
12545 +
12546  \f
12547  
12548  /* Add an expression to the auto-display chain.
12549 @@ -1798,50 +1818,6 @@ disable_display_command (char *args, int from_tty)
12550        }
12551  }
12552  
12553 -/* Return 1 if D uses SOLIB (and will become dangling when SOLIB
12554 -   is unloaded), otherwise return 0.  */
12555 -
12556 -static int
12557 -display_uses_solib_p (const struct display *d,
12558 -                     const struct so_list *solib)
12559 -{
12560 -  int endpos;
12561 -  struct expression *const exp = d->exp;
12562 -  const union exp_element *const elts = exp->elts;
12563 -
12564 -  if (d->block != NULL
12565 -      && solib_contains_address_p (solib, d->block->startaddr))
12566 -    return 1;
12567 -
12568 -  for (endpos = exp->nelts; endpos > 0; )
12569 -    {
12570 -      int i, args, oplen = 0;
12571 -
12572 -      exp->language_defn->la_exp_desc->operator_length (exp, endpos,
12573 -                                                       &oplen, &args);
12574 -      gdb_assert (oplen > 0);
12575 -
12576 -      i = endpos - oplen;
12577 -      if (elts[i].opcode == OP_VAR_VALUE)
12578 -       {
12579 -         const struct block *const block = elts[i + 1].block;
12580 -         const struct symbol *const symbol = elts[i + 2].symbol;
12581 -         const struct obj_section *const section =
12582 -           SYMBOL_OBJ_SECTION (symbol);
12583 -
12584 -         if (block != NULL
12585 -             && solib_contains_address_p (solib, block->startaddr))
12586 -           return 1;
12587 -
12588 -         if (section && section->objfile == solib->objfile)
12589 -           return 1;
12590 -       }
12591 -      endpos -= oplen;
12592 -    }
12593 -
12594 -  return 0;
12595 -}
12596 -
12597  /* display_chain items point to blocks and expressions.  Some expressions in
12598     turn may point to symbols.
12599     Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
12600 @@ -1853,18 +1829,20 @@ display_uses_solib_p (const struct display *d,
12601  static void
12602  clear_dangling_display_expressions (struct so_list *solib)
12603  {
12604 +  struct objfile *objfile = solib->objfile;
12605    struct display *d;
12606 -  struct objfile *objfile = NULL;
12607  
12608 -  for (d = display_chain; d; d = d->next)
12609 -    {
12610 -      if (d->exp && display_uses_solib_p (d, solib))
12611 -       {
12612 -         xfree (d->exp);
12613 -         d->exp = NULL;
12614 -         d->block = NULL;
12615 -       }
12616 -    }
12617 +  if (objfile == NULL)
12618 +    return;
12619 +
12620 +  for (d = display_chain; d != NULL; d = d->next)
12621 +    if (block_objfile (d->block) == objfile
12622 +       || (d->exp && exp_uses_objfile (d->exp, objfile)))
12623 +      {
12624 +       xfree (d->exp);
12625 +       d->exp = NULL;
12626 +       d->block = NULL;
12627 +      }
12628  }
12629  \f
12630  
12631 @@ -2749,4 +2727,6 @@ Show printing of source filename and line number with <symbol>."), NULL,
12632                            NULL,
12633                            show_print_symbol_filename,
12634                            &setprintlist, &showprintlist);
12635 +
12636 +  observer_attach_mark_used (print_types_mark_used);
12637  }
12638 diff --git a/gdb/python/lib/gdb/FrameIterator.py b/gdb/python/lib/gdb/FrameIterator.py
12639 new file mode 100644
12640 index 0000000..5654546
12641 --- /dev/null
12642 +++ b/gdb/python/lib/gdb/FrameIterator.py
12643 @@ -0,0 +1,33 @@
12644 +# Iterator over frames.
12645 +
12646 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
12647 +
12648 +# This program is free software; you can redistribute it and/or modify
12649 +# it under the terms of the GNU General Public License as published by
12650 +# the Free Software Foundation; either version 3 of the License, or
12651 +# (at your option) any later version.
12652 +#
12653 +# This program is distributed in the hope that it will be useful,
12654 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12655 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12656 +# GNU General Public License for more details.
12657 +#
12658 +# You should have received a copy of the GNU General Public License
12659 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12660 +
12661 +class FrameIterator:
12662 +    """An iterator that iterates over frames."""
12663 +
12664 +    def __init__ (self, frame):
12665 +        "Initialize a FrameIterator.  FRAME is the starting frame."
12666 +        self.frame = frame
12667 +
12668 +    def __iter__ (self):
12669 +        return self
12670 +
12671 +    def next (self):
12672 +        result = self.frame
12673 +        if result is None:
12674 +            raise StopIteration
12675 +        self.frame = result.older ()
12676 +        return result
12677 diff --git a/gdb/python/lib/gdb/FrameWrapper.py b/gdb/python/lib/gdb/FrameWrapper.py
12678 new file mode 100644
12679 index 0000000..b790a54
12680 --- /dev/null
12681 +++ b/gdb/python/lib/gdb/FrameWrapper.py
12682 @@ -0,0 +1,112 @@
12683 +# Wrapper API for frames.
12684 +
12685 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
12686 +
12687 +# This program is free software; you can redistribute it and/or modify
12688 +# it under the terms of the GNU General Public License as published by
12689 +# the Free Software Foundation; either version 3 of the License, or
12690 +# (at your option) any later version.
12691 +#
12692 +# This program is distributed in the hope that it will be useful,
12693 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12694 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12695 +# GNU General Public License for more details.
12696 +#
12697 +# You should have received a copy of the GNU General Public License
12698 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12699 +
12700 +import gdb
12701 +
12702 +# FIXME: arguably all this should be on Frame somehow.
12703 +class FrameWrapper:
12704 +    def __init__ (self, frame):
12705 +        self.frame = frame;
12706 +
12707 +    def write_symbol (self, stream, sym, block):
12708 +        if len (sym.linkage_name):
12709 +            nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
12710 +            if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
12711 +                sym = nsym
12712 +
12713 +        stream.write (sym.print_name + "=")
12714 +        try:
12715 +            val = self.read_var (sym)
12716 +            if val != None:
12717 +                val = str (val)
12718 +        # FIXME: would be nice to have a more precise exception here.
12719 +        except RuntimeError, text:
12720 +            val = text
12721 +        if val == None:
12722 +            stream.write ("???")
12723 +        else:
12724 +            stream.write (str (val))
12725 +
12726 +    def print_frame_locals (self, stream, func):
12727 +        if not func:
12728 +            return
12729 +
12730 +        first = True
12731 +        block = func.value
12732 +
12733 +        for sym in block:
12734 +            if sym.is_argument:
12735 +                continue;
12736 +
12737 +            self.write_symbol (stream, sym, block)
12738 +            stream.write ('\n')
12739 +
12740 +    def print_frame_args (self, stream, func):
12741 +        if not func:
12742 +            return
12743 +
12744 +        first = True
12745 +        block = func.value
12746 +
12747 +        for sym in block:
12748 +            if not sym.is_argument:
12749 +                continue;
12750 +
12751 +            if not first:
12752 +                stream.write (", ")
12753 +
12754 +            self.write_symbol (stream, sym, block)
12755 +            first = False
12756 +
12757 +    # FIXME: this should probably just be a method on gdb.Frame.
12758 +    # But then we need stream wrappers.
12759 +    def describe (self, stream, full):
12760 +        if self.type () == gdb.DUMMY_FRAME:
12761 +            stream.write (" <function called from gdb>\n")
12762 +        elif self.type () == gdb.SIGTRAMP_FRAME:
12763 +            stream.write (" <signal handler called>\n")
12764 +        else:
12765 +            sal = self.find_sal ()
12766 +            pc = self.pc ()
12767 +            name = self.name ()
12768 +            if not name:
12769 +                name = "??"
12770 +            if pc != sal.pc or not sal.symtab:
12771 +                stream.write (" 0x%08x in" % pc)
12772 +            stream.write (" " + name + " (")
12773 +
12774 +            func = self.function ()
12775 +            self.print_frame_args (stream, func)
12776 +
12777 +            stream.write (")")
12778 +
12779 +            if sal.symtab and sal.symtab.filename:
12780 +                stream.write (" at " + sal.symtab.filename)
12781 +                stream.write (":" + str (sal.line))
12782 +
12783 +            if not self.name () or (not sal.symtab or not sal.symtab.filename):
12784 +                lib = gdb.solib_address (pc)
12785 +                if lib:
12786 +                    stream.write (" from " + lib)
12787 +
12788 +            stream.write ("\n")
12789 +
12790 +            if full:
12791 +                self.print_frame_locals (stream, func)
12792 +
12793 +    def __getattr__ (self, name):
12794 +        return getattr (self.frame, name)
12795 diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
12796 new file mode 100644
12797 index 0000000..b375c68
12798 --- /dev/null
12799 +++ b/gdb/python/lib/gdb/__init__.py
12800 @@ -0,0 +1,19 @@
12801 +# Startup code.
12802 +
12803 +# Copyright (C) 2008 Free Software Foundation, Inc.
12804 +
12805 +# This program is free software; you can redistribute it and/or modify
12806 +# it under the terms of the GNU General Public License as published by
12807 +# the Free Software Foundation; either version 3 of the License, or
12808 +# (at your option) any later version.
12809 +#
12810 +# This program is distributed in the hope that it will be useful,
12811 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12812 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12813 +# GNU General Public License for more details.
12814 +#
12815 +# You should have received a copy of the GNU General Public License
12816 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12817 +
12818 +# Load the require command by default.
12819 +import gdb.command.require
12820 diff --git a/gdb/python/lib/gdb/backtrace.py b/gdb/python/lib/gdb/backtrace.py
12821 new file mode 100644
12822 index 0000000..2baab5f
12823 --- /dev/null
12824 +++ b/gdb/python/lib/gdb/backtrace.py
12825 @@ -0,0 +1,42 @@
12826 +# Filtering backtrace.
12827 +
12828 +# Copyright (C) 2008 Free Software Foundation, Inc.
12829 +
12830 +# This program is free software; you can redistribute it and/or modify
12831 +# it under the terms of the GNU General Public License as published by
12832 +# the Free Software Foundation; either version 3 of the License, or
12833 +# (at your option) any later version.
12834 +#
12835 +# This program is distributed in the hope that it will be useful,
12836 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12837 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12838 +# GNU General Public License for more details.
12839 +#
12840 +# You should have received a copy of the GNU General Public License
12841 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12842 +
12843 +import gdb
12844 +import itertools
12845 +
12846 +# Our only exports.
12847 +__all__ = ['push_frame_filter', 'create_frame_filter']
12848 +
12849 +frame_filter = None
12850 +
12851 +def push_frame_filter (constructor):
12852 +    """Register a new backtrace filter class with the 'backtrace' command.
12853 +The filter will be passed an iterator as an argument.  The iterator
12854 +will return gdb.Frame-like objects.  The filter should in turn act as
12855 +an iterator returning such objects."""
12856 +    global frame_filter
12857 +    if frame_filter == None:
12858 +        frame_filter = constructor
12859 +    else:
12860 +        frame_filter = lambda iterator: constructor (frame_filter (iterator))
12861 +
12862 +def create_frame_filter (iter):
12863 +    global frame_filter
12864 +    if frame_filter is None:
12865 +        return iter
12866 +    return frame_filter (iter)
12867 +
12868 diff --git a/gdb/python/lib/gdb/command/__init__.py b/gdb/python/lib/gdb/command/__init__.py
12869 new file mode 100644
12870 index 0000000..8b13789
12871 --- /dev/null
12872 +++ b/gdb/python/lib/gdb/command/__init__.py
12873 @@ -0,0 +1 @@
12874 +
12875 diff --git a/gdb/python/lib/gdb/command/alias.py b/gdb/python/lib/gdb/command/alias.py
12876 new file mode 100644
12877 index 0000000..96b6618
12878 --- /dev/null
12879 +++ b/gdb/python/lib/gdb/command/alias.py
12880 @@ -0,0 +1,59 @@
12881 +# Alias command.
12882 +
12883 +# Copyright (C) 2008 Free Software Foundation, Inc.
12884 +
12885 +# This program is free software; you can redistribute it and/or modify
12886 +# it under the terms of the GNU General Public License as published by
12887 +# the Free Software Foundation; either version 3 of the License, or
12888 +# (at your option) any later version.
12889 +#
12890 +# This program is distributed in the hope that it will be useful,
12891 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12892 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12893 +# GNU General Public License for more details.
12894 +#
12895 +# You should have received a copy of the GNU General Public License
12896 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12897 +
12898 +import gdb
12899 +
12900 +class AliasImplementation (gdb.Command):
12901 +    def __init__ (self, name, real, doc):
12902 +        # Have to set __doc__ before the super init call.
12903 +        # It would be nice if gdb's help looked up __doc__ dynamically.
12904 +        self.__doc__ = doc
12905 +        # Note: no good way to complete :(
12906 +        super (AliasImplementation, self).__init__ (name, gdb.COMMAND_NONE)
12907 +        self.real = real
12908 +
12909 +    def invoke(self, arg, from_tty):
12910 +        gdb.execute (self.real + ' ' + arg, from_tty)
12911 +
12912 +class AliasCommand (gdb.Command):
12913 +    """Alias one command to another.
12914 +In the simplest form, the first word is the name of the alias, and
12915 +the remaining words are the the expansion.
12916 +An '=' by itself can be used to define a multi-word alias; words
12917 +before the '=' are the name of the new command."""
12918 +
12919 +    def __init__ (self):
12920 +        # Completion is not quite right here.
12921 +        super (AliasCommand, self).__init__ ("alias", gdb.COMMAND_NONE,
12922 +                                             gdb.COMPLETE_COMMAND)
12923 +
12924 +    def invoke (self, arg, from_tty):
12925 +        self.dont_repeat ()
12926 +        # Without some form of quoting we can't alias a multi-word
12927 +        # command to another command.
12928 +        args = arg.split()
12929 +        try:
12930 +            start = args.index ('=')
12931 +            end = start + 1
12932 +        except ValueError:
12933 +            start = 1
12934 +            end = 1
12935 +        target = " ".join(args[end:])
12936 +        AliasImplementation (" ".join (args[0:start]), target,
12937 +                             "This command is an alias for '%s'." % target)
12938 +
12939 +AliasCommand()
12940 diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
12941 new file mode 100644
12942 index 0000000..ec9a527
12943 --- /dev/null
12944 +++ b/gdb/python/lib/gdb/command/backtrace.py
12945 @@ -0,0 +1,106 @@
12946 +# New backtrace command.
12947 +
12948 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
12949 +
12950 +# This program is free software; you can redistribute it and/or modify
12951 +# it under the terms of the GNU General Public License as published by
12952 +# the Free Software Foundation; either version 3 of the License, or
12953 +# (at your option) any later version.
12954 +#
12955 +# This program is distributed in the hope that it will be useful,
12956 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12957 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12958 +# GNU General Public License for more details.
12959 +#
12960 +# You should have received a copy of the GNU General Public License
12961 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12962 +
12963 +import gdb
12964 +import gdb.backtrace
12965 +import itertools
12966 +from gdb.FrameIterator import FrameIterator
12967 +from gdb.FrameWrapper import FrameWrapper
12968 +import sys
12969 +
12970 +class ReverseBacktraceParameter (gdb.Parameter):
12971 +    """The new-backtrace command can show backtraces in 'reverse' order.
12972 +This means that the innermost frame will be printed last.
12973 +Note that reverse backtraces are more expensive to compute."""
12974 +
12975 +    set_doc = "Enable or disable reverse backtraces."
12976 +    show_doc = "Show whether backtraces will be printed in reverse order."
12977 +
12978 +    def __init__(self):
12979 +        gdb.Parameter.__init__ (self, "reverse-backtrace",
12980 +                                gdb.COMMAND_STACK, gdb.PARAM_BOOLEAN)
12981 +        # Default to compatibility with gdb.
12982 +        self.value = False
12983 +
12984 +class FilteringBacktrace (gdb.Command):
12985 +    """Print backtrace of all stack frames, or innermost COUNT frames.
12986 +With a negative argument, print outermost -COUNT frames.
12987 +Use of the 'full' qualifier also prints the values of the local variables.
12988 +Use of the 'raw' qualifier avoids any filtering by loadable modules.
12989 +"""
12990 +
12991 +    def __init__ (self):
12992 +        # FIXME: this is not working quite well enough to replace
12993 +        # "backtrace" yet.
12994 +        gdb.Command.__init__ (self, "new-backtrace", gdb.COMMAND_STACK)
12995 +        self.reverse = ReverseBacktraceParameter()
12996 +
12997 +    def reverse_iter (self, iter):
12998 +        result = []
12999 +        for item in iter:
13000 +            result.append (item)
13001 +        result.reverse()
13002 +        return result
13003 +
13004 +    def final_n (self, iter, x):
13005 +        result = []
13006 +        for item in iter:
13007 +            result.append (item)
13008 +        return result[x:]
13009 +
13010 +    def invoke (self, arg, from_tty):
13011 +        i = 0
13012 +        count = 0
13013 +        filter = True
13014 +        full = False
13015 +
13016 +        for word in arg.split (" "):
13017 +            if word == '':
13018 +                continue
13019 +            elif word == 'raw':
13020 +                filter = False
13021 +            elif word == 'full':
13022 +                full = True
13023 +            else:
13024 +                count = int (word)
13025 +
13026 +        # FIXME: provide option to start at selected frame
13027 +        # However, should still number as if starting from newest
13028 +       newest_frame = gdb.selected_thread ().newest_frame ()
13029 +        iter = itertools.imap (FrameWrapper,
13030 +                               FrameIterator (newest_frame))
13031 +        if filter:
13032 +            iter = gdb.backtrace.create_frame_filter (iter)
13033 +
13034 +        # Now wrap in an iterator that numbers the frames.
13035 +        iter = itertools.izip (itertools.count (0), iter)
13036 +
13037 +        # Reverse if the user wanted that.
13038 +        if self.reverse.value:
13039 +            iter = self.reverse_iter (iter)
13040 +
13041 +        # Extract sub-range user wants.
13042 +        if count < 0:
13043 +            iter = self.final_n (iter, count)
13044 +        elif count > 0:
13045 +            iter = itertools.islice (iter, 0, count)
13046 +
13047 +        for pair in iter:
13048 +            sys.stdout.write ("#%-2d" % pair[0])
13049 +            pair[1].describe (sys.stdout, full)
13050 +
13051 +FilteringBacktrace()
13052 diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
13053 new file mode 100644
13054 index 0000000..6fa48ff
13055 --- /dev/null
13056 +++ b/gdb/python/lib/gdb/command/ignore_errors.py
13057 @@ -0,0 +1,37 @@
13058 +# Ignore errors in user commands.
13059 +
13060 +# Copyright (C) 2008 Free Software Foundation, Inc.
13061 +
13062 +# This program is free software; you can redistribute it and/or modify
13063 +# it under the terms of the GNU General Public License as published by
13064 +# the Free Software Foundation; either version 3 of the License, or
13065 +# (at your option) any later version.
13066 +#
13067 +# This program is distributed in the hope that it will be useful,
13068 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13069 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13070 +# GNU General Public License for more details.
13071 +#
13072 +# You should have received a copy of the GNU General Public License
13073 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13074 +
13075 +import gdb
13076 +
13077 +class IgnoreErrorsCommand (gdb.Command):
13078 +    """Execute a single command, ignoring all errors.
13079 +Only one-line commands are supported.
13080 +This is primarily useful in scripts."""
13081 +
13082 +    def __init__ (self):
13083 +        super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
13084 +                                                    gdb.COMMAND_OBSCURE,
13085 +                                                    # FIXME...
13086 +                                                    gdb.COMPLETE_COMMAND)
13087 +
13088 +    def invoke (self, arg, from_tty):
13089 +        try:
13090 +            gdb.execute (arg, from_tty)
13091 +        except:
13092 +            pass
13093 +
13094 +IgnoreErrorsCommand ()
13095 diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
13096 new file mode 100644
13097 index 0000000..21a0bf0
13098 --- /dev/null
13099 +++ b/gdb/python/lib/gdb/command/pahole.py
13100 @@ -0,0 +1,75 @@
13101 +# pahole command for gdb
13102 +
13103 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13104 +
13105 +# This program is free software; you can redistribute it and/or modify
13106 +# it under the terms of the GNU General Public License as published by
13107 +# the Free Software Foundation; either version 3 of the License, or
13108 +# (at your option) any later version.
13109 +#
13110 +# This program is distributed in the hope that it will be useful,
13111 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13112 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13113 +# GNU General Public License for more details.
13114 +#
13115 +# You should have received a copy of the GNU General Public License
13116 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13117 +
13118 +import gdb
13119 +
13120 +class Pahole (gdb.Command):
13121 +    """Show the holes in a structure.
13122 +This command takes a single argument, a type name.
13123 +It prints the type and displays comments showing where holes are."""
13124 +
13125 +    def __init__ (self):
13126 +        super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
13127 +                                       gdb.COMPLETE_SYMBOL)
13128 +
13129 +    def pahole (self, type, level, name):
13130 +        if name is None:
13131 +            name = ''
13132 +        tag = type.tag
13133 +        if tag is None:
13134 +            tag = ''
13135 +        print '%sstruct %s {' % (' ' * (2 * level), tag)
13136 +        bitpos = 0
13137 +        for field in type.fields ():
13138 +            # Skip static fields.
13139 +            if not hasattr (field, ('bitpos')):
13140 +                continue
13141 +
13142 +            ftype = field.type.strip_typedefs()
13143 +
13144 +            if bitpos != field.bitpos:
13145 +                hole = field.bitpos - bitpos
13146 +                print '  /* XXX %d bit hole, try to pack */' % hole
13147 +                bitpos = field.bitpos
13148 +            if field.bitsize > 0:
13149 +                fieldsize = field.bitsize
13150 +            else:
13151 +                # TARGET_CHAR_BIT here...
13152 +                fieldsize = 8 * ftype.sizeof
13153 +
13154 +            # TARGET_CHAR_BIT
13155 +            print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
13156 +            bitpos = bitpos + fieldsize
13157 +
13158 +            if ftype.code == gdb.TYPE_CODE_STRUCT:
13159 +                self.pahole (ftype, level + 1, field.name)
13160 +            else:
13161 +                print ' ' * (2 + 2 * level),
13162 +                print '%s %s' % (str (ftype), field.name)
13163 +
13164 +        print ' ' * (14 + 2 * level),
13165 +        print '} %s' % name
13166 +
13167 +    def invoke (self, arg, from_tty):
13168 +        type = gdb.lookup_type (arg)
13169 +        type = type.strip_typedefs ()
13170 +        if type.code != gdb.TYPE_CODE_STRUCT:
13171 +            raise TypeError, '%s is not a struct type' % arg
13172 +        print ' ' * 14,
13173 +        self.pahole (type, 0, '')
13174 +
13175 +Pahole()
13176 diff --git a/gdb/python/lib/gdb/command/require.py b/gdb/python/lib/gdb/command/require.py
13177 new file mode 100644
13178 index 0000000..1fbc1e8
13179 --- /dev/null
13180 +++ b/gdb/python/lib/gdb/command/require.py
13181 @@ -0,0 +1,57 @@
13182 +# Demand-loading commands.
13183 +
13184 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13185 +
13186 +# This program is free software; you can redistribute it and/or modify
13187 +# it under the terms of the GNU General Public License as published by
13188 +# the Free Software Foundation; either version 3 of the License, or
13189 +# (at your option) any later version.
13190 +#
13191 +# This program is distributed in the hope that it will be useful,
13192 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13193 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13194 +# GNU General Public License for more details.
13195 +#
13196 +# You should have received a copy of the GNU General Public License
13197 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13198 +
13199 +import gdb
13200 +import os
13201 +
13202 +class RequireCommand (gdb.Command):
13203 +    """Prefix command for requiring features."""
13204 +
13205 +    def __init__ (self):
13206 +        super (RequireCommand, self).__init__ ("require",
13207 +                                               gdb.COMMAND_SUPPORT,
13208 +                                               gdb.COMPLETE_NONE,
13209 +                                               True)
13210 +
13211 +class RequireSubcommand (gdb.Command):
13212 +    """Demand-load a command by name."""
13213 +
13214 +    def __init__ (self, name):
13215 +        self.__doc__ = "Demand-load a %s by name." % name
13216 +        super (RequireSubcommand, self).__init__ ("require %s" % name,
13217 +                                                  gdb.COMMAND_SUPPORT)
13218 +        self.name = name
13219 +
13220 +    def invoke (self, arg, from_tty):
13221 +        for cmd in arg.split():
13222 +            exec ('import gdb.' + self.name + '.' + cmd, globals ())
13223 +
13224 +    def complete (self, text, word):
13225 +        dir = gdb.pythondir + '/gdb/' + self.name
13226 +        result = []
13227 +        for file in os.listdir(dir):
13228 +            if not file.startswith (word) or not file.endswith ('.py'):
13229 +                continue
13230 +            feature = file[0:-3]
13231 +            if feature == 'require' or feature == '__init__':
13232 +                continue
13233 +            result.append (feature)
13234 +        return result
13235 +
13236 +RequireCommand()
13237 +RequireSubcommand("command")
13238 +RequireSubcommand("function")
13239 diff --git a/gdb/python/lib/gdb/command/save_breakpoints.py b/gdb/python/lib/gdb/command/save_breakpoints.py
13240 new file mode 100644
13241 index 0000000..6143187
13242 --- /dev/null
13243 +++ b/gdb/python/lib/gdb/command/save_breakpoints.py
13244 @@ -0,0 +1,65 @@
13245 +# Save breakpoints.
13246 +
13247 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13248 +
13249 +# This program is free software; you can redistribute it and/or modify
13250 +# it under the terms of the GNU General Public License as published by
13251 +# the Free Software Foundation; either version 3 of the License, or
13252 +# (at your option) any later version.
13253 +#
13254 +# This program is distributed in the hope that it will be useful,
13255 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13256 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13257 +# GNU General Public License for more details.
13258 +#
13259 +# You should have received a copy of the GNU General Public License
13260 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13261 +
13262 +from __future__ import with_statement
13263 +import gdb
13264 +
13265 +class SavePrefixCommand (gdb.Command):
13266 +  "Prefix command for saving things."
13267 +
13268 +  def __init__ (self):
13269 +    super (SavePrefixCommand, self).__init__ ("save",
13270 +                                              gdb.COMMAND_SUPPORT,
13271 +                                              gdb.COMPLETE_NONE, True)
13272 +
13273 +class SaveBreakpointsCommand (gdb.Command):
13274 +    """Save the current breakpoints to a file.
13275 +This command takes a single argument, a file name.
13276 +The breakpoints can be restored using the 'source' command."""
13277 +
13278 +    def __init__ (self):
13279 +        super (SaveBreakpointsCommand, self).__init__ ("save breakpoints",
13280 +                                                       gdb.COMMAND_SUPPORT,
13281 +                                                       gdb.COMPLETE_FILENAME)
13282 +
13283 +    def invoke (self, arg, from_tty):
13284 +        self.dont_repeat ()
13285 +        bps = gdb.breakpoints ()
13286 +        if bps is None:
13287 +            raise RuntimeError, 'No breakpoints to save'
13288 +        with open (arg.strip (), 'w') as f:
13289 +            for bp in bps:
13290 +                print >> f, "break", bp.location,
13291 +                if bp.thread is not None:
13292 +                    print >> f, " thread", bp.thread,
13293 +                if bp.condition is not None:
13294 +                    print >> f, " if", bp.condition,
13295 +                print >> f
13296 +                if not bp.enabled:
13297 +                    print >> f, "disable $bpnum"
13298 +                # Note: we don't save the ignore count; there doesn't
13299 +                # seem to be much point.
13300 +                commands = bp.commands
13301 +                if commands is not None:
13302 +                    print >> f, "commands"
13303 +                    # Note that COMMANDS has a trailing newline.
13304 +                    print >> f, commands,
13305 +                    print >> f, "end"
13306 +                print >> f
13307 +
13308 +SavePrefixCommand ()
13309 +SaveBreakpointsCommand ()
13310 diff --git a/gdb/python/lib/gdb/command/upto.py b/gdb/python/lib/gdb/command/upto.py
13311 new file mode 100644
13312 index 0000000..faf54ed
13313 --- /dev/null
13314 +++ b/gdb/python/lib/gdb/command/upto.py
13315 @@ -0,0 +1,129 @@
13316 +# upto command.
13317 +
13318 +# Copyright (C) 2009 Free Software Foundation, Inc.
13319 +
13320 +# This program is free software; you can redistribute it and/or modify
13321 +# it under the terms of the GNU General Public License as published by
13322 +# the Free Software Foundation; either version 3 of the License, or
13323 +# (at your option) any later version.
13324 +#
13325 +# This program is distributed in the hope that it will be useful,
13326 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13327 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13328 +# GNU General Public License for more details.
13329 +#
13330 +# You should have received a copy of the GNU General Public License
13331 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13332 +
13333 +import gdb
13334 +import re
13335 +from gdb.FrameIterator import FrameIterator
13336 +from gdb.FrameWrapper import FrameWrapper
13337 +
13338 +class UptoPrefix (gdb.Command):
13339 +    def __init__ (self):
13340 +        super (UptoPrefix, self).__init__ ("upto", gdb.COMMAND_STACK,
13341 +                                           prefix = True)
13342 +
13343 +class UptoImplementation (gdb.Command):
13344 +    def __init__ (self, subcommand):
13345 +        super (UptoImplementation, self).__init__ ("upto " + subcommand,
13346 +                                                   gdb.COMMAND_STACK)
13347 +
13348 +    def search (self):
13349 +        saved = gdb.selected_frame ()
13350 +        iter = FrameIterator (saved)
13351 +        found = False
13352 +        try:
13353 +            for frame in iter:
13354 +                frame.select ()
13355 +                try:
13356 +                    if self.filter (frame):
13357 +                        wrapper = FrameWrapper (frame)
13358 +                        wrapper.describe (sys.stdout, False)
13359 +                        return
13360 +                except:
13361 +                    pass
13362 +        except:
13363 +            pass
13364 +        saved.select ()
13365 +        raise RuntimeError, 'Could not find a matching frame'
13366 +
13367 +    def invoke (self, arg, from_tty):
13368 +        self.rx = re.compile (arg)
13369 +        self.search ()
13370 +
13371 +class UptoSymbolCommand (UptoImplementation):
13372 +    """Select and print some calling stack frame, based on symbol.
13373 +The argument is a regular expression.  This command moves up the
13374 +stack, stopping at the first frame whose symbol matches the regular
13375 +expression."""
13376 +
13377 +    def __init__ (self):
13378 +        super (UptoSymbolCommand, self).__init__ ("symbol")
13379 +
13380 +    def filter (self, frame):
13381 +        name = frame.name ()
13382 +        if name is not None:
13383 +            if self.rx.search (name) is not None:
13384 +                return True
13385 +        return False
13386 +
13387 +class UptoSourceCommand (UptoImplementation):
13388 +    """Select and print some calling stack frame, based on source file.
13389 +The argument is a regular expression.  This command moves up the
13390 +stack, stopping at the first frame whose source file name matches the
13391 +regular expression."""
13392 +
13393 +    def __init__ (self):
13394 +        super (UptoSourceCommand, self).__init__ ("source")
13395 +
13396 +    def filter (self, frame):
13397 +        name = frame.find_sal ().symtab.filename
13398 +        if name is not None:
13399 +            if self.rx.search (name) is not None:
13400 +                return True
13401 +        return False
13402 +
13403 +class UptoObjectCommand (UptoImplementation):
13404 +    """Select and print some calling stack frame, based on object file.
13405 +The argument is a regular expression.  This command moves up the
13406 +stack, stopping at the first frame whose object file name matches the
13407 +regular expression."""
13408 +
13409 +    def __init__ (self):
13410 +        super (UptoObjectCommand, self).__init__ ("object")
13411 +
13412 +    def filter (self, frame):
13413 +        name = frame.find_sal ().symtab.objfile.filename
13414 +        if name is not None:
13415 +            if self.rx.search (name) is not None:
13416 +                return True
13417 +        return False
13418 +
13419 +class UptoWhereCommand (UptoImplementation):
13420 +    """Select and print some calling stack frame, based on expression.
13421 +The argument is an expression.  This command moves up the stack,
13422 +parsing and evaluating the expression in each frame.  This stops when
13423 +the expression evaluates to a non-zero (true) value."""
13424 +
13425 +    def __init__ (self):
13426 +        super (UptoWhereCommand, self).__init__ ("where")
13427 +
13428 +    def filter (self, frame):
13429 +        try:
13430 +            if gdb.parse_and_eval (self.expression):
13431 +                return True
13432 +        except:
13433 +            pass
13434 +        return False
13435 +
13436 +    def invoke (self, arg, from_tty):
13437 +        self.expression = arg
13438 +        self.search ()
13439 +
13440 +UptoPrefix ()
13441 +UptoSymbolCommand ()
13442 +UptoSourceCommand ()
13443 +UptoObjectCommand ()
13444 +UptoWhereCommand ()
13445 diff --git a/gdb/python/lib/gdb/function/__init__.py b/gdb/python/lib/gdb/function/__init__.py
13446 new file mode 100644
13447 index 0000000..8b13789
13448 --- /dev/null
13449 +++ b/gdb/python/lib/gdb/function/__init__.py
13450 @@ -0,0 +1 @@
13451 +
13452 diff --git a/gdb/python/lib/gdb/function/caller_is.py b/gdb/python/lib/gdb/function/caller_is.py
13453 new file mode 100644
13454 index 0000000..2b9c5c7
13455 --- /dev/null
13456 +++ b/gdb/python/lib/gdb/function/caller_is.py
13457 @@ -0,0 +1,58 @@
13458 +# Caller-is functions.
13459 +
13460 +# Copyright (C) 2008 Free Software Foundation, Inc.
13461 +
13462 +# This program is free software; you can redistribute it and/or modify
13463 +# it under the terms of the GNU General Public License as published by
13464 +# the Free Software Foundation; either version 3 of the License, or
13465 +# (at your option) any later version.
13466 +#
13467 +# This program is distributed in the hope that it will be useful,
13468 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13469 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13470 +# GNU General Public License for more details.
13471 +#
13472 +# You should have received a copy of the GNU General Public License
13473 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13474 +
13475 +import gdb
13476 +import re
13477 +
13478 +class CallerIs (gdb.Function):
13479 +    """Return True if the calling function's name is equal to a string.
13480 +This function takes one or two arguments.
13481 +The first argument is the name of a function; if the calling function's
13482 +name is equal to this argument, this function returns True.
13483 +The optional second argument tells this function how many stack frames
13484 +to traverse to find the calling function.  The default is 1."""
13485 +
13486 +    def __init__ (self):
13487 +        super (CallerIs, self).__init__ ("caller_is")
13488 +
13489 +    def invoke (self, name, nframes = 1):
13490 +        frame = gdb.selected_frame ()
13491 +        while nframes > 0:
13492 +            frame = frame.older ()
13493 +            nframes = nframes - 1
13494 +        return frame.name () == name.string ()
13495 +
13496 +class CallerMatches (gdb.Function):
13497 +    """Return True if the calling function's name matches a string.
13498 +This function takes one or two arguments.
13499 +The first argument is a regular expression; if the calling function's
13500 +name is matched by this argument, this function returns True.
13501 +The optional second argument tells this function how many stack frames
13502 +to traverse to find the calling function.  The default is 1."""
13503 +
13504 +    def __init__ (self):
13505 +        super (CallerMatches, self).__init__ ("caller_matches")
13506 +
13507 +    def invoke (self, name, nframes = 1):
13508 +        frame = gdb.selected_frame ()
13509 +        while nframes > 0:
13510 +            frame = frame.older ()
13511 +            nframes = nframes - 1
13512 +        return re.match (name.string (), frame.name ()) is not None
13513 +
13514 +CallerIs()
13515 +CallerMatches()
13516 diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
13517 new file mode 100644
13518 index 0000000..debb3bb
13519 --- /dev/null
13520 +++ b/gdb/python/lib/gdb/function/in_scope.py
13521 @@ -0,0 +1,47 @@
13522 +# In-scope function.
13523 +
13524 +# Copyright (C) 2008 Free Software Foundation, Inc.
13525 +
13526 +# This program is free software; you can redistribute it and/or modify
13527 +# it under the terms of the GNU General Public License as published by
13528 +# the Free Software Foundation; either version 3 of the License, or
13529 +# (at your option) any later version.
13530 +#
13531 +# This program is distributed in the hope that it will be useful,
13532 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13533 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13534 +# GNU General Public License for more details.
13535 +#
13536 +# You should have received a copy of the GNU General Public License
13537 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13538 +
13539 +import gdb
13540 +
13541 +class InScope (gdb.Function):
13542 +    """Return True if all the given variables or macros are in scope.
13543 +Takes one argument for each variable name to be checked."""
13544 +
13545 +    def __init__ (self):
13546 +       super (InScope, self).__init__ ("in_scope")
13547 +
13548 +    def invoke (self, *vars):
13549 +        if len (vars) == 0:
13550 +           raise TypeError, "in_scope takes at least one argument"
13551 +
13552 +        # gdb.Value isn't hashable so it can't be put in a map.
13553 +       # Convert to string first.
13554 +       wanted = set (map (lambda x: x.string (), vars))
13555 +       found = set ()
13556 +       block = gdb.selected_frame ().block ()
13557 +       while block:
13558 +           for sym in block:
13559 +               if (sym.is_argument or sym.is_constant
13560 +                     or sym.is_function or sym.is_variable):
13561 +                   if sym.name in wanted:
13562 +                       found.add (sym.name)
13563 +
13564 +           block = block.superblock
13565 +
13566 +       return wanted == found
13567 +
13568 +InScope ()
13569 diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
13570 new file mode 100644
13571 index 0000000..8019e9d
13572 --- /dev/null
13573 +++ b/gdb/python/py-block.c
13574 @@ -0,0 +1,265 @@
13575 +/* Python interface to blocks.
13576 +
13577 +   Copyright (C) 2008 Free Software Foundation, Inc.
13578 +
13579 +   This file is part of GDB.
13580 +
13581 +   This program is free software; you can redistribute it and/or modify
13582 +   it under the terms of the GNU General Public License as published by
13583 +   the Free Software Foundation; either version 3 of the License, or
13584 +   (at your option) any later version.
13585 +
13586 +   This program is distributed in the hope that it will be useful,
13587 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
13588 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13589 +   GNU General Public License for more details.
13590 +
13591 +   You should have received a copy of the GNU General Public License
13592 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
13593 +
13594 +#include "defs.h"
13595 +#include "block.h"
13596 +#include "dictionary.h"
13597 +#include "symtab.h"
13598 +#include "python-internal.h"
13599 +
13600 +typedef struct {
13601 +  PyObject_HEAD
13602 +  struct block *block;
13603 +} block_object;
13604 +
13605 +typedef struct {
13606 +  PyObject_HEAD
13607 +  struct dictionary *dict;
13608 +  struct dict_iterator iter;
13609 +  int initialized_p;
13610 +} block_syms_iterator_object;
13611 +
13612 +static PyTypeObject block_syms_iterator_object_type;
13613 +
13614 +static PyObject *
13615 +blpy_iter (PyObject *self)
13616 +{
13617 +  block_syms_iterator_object *block_iter_obj;
13618 +
13619 +  block_iter_obj = PyObject_New (block_syms_iterator_object,
13620 +                           &block_syms_iterator_object_type);
13621 +  if (block_iter_obj == NULL)
13622 +    {
13623 +      PyErr_SetString (PyExc_MemoryError,
13624 +                      "Could not allocate iterator object.");
13625 +      return NULL;
13626 +    }
13627 +
13628 +  block_iter_obj->dict = BLOCK_DICT (((block_object *) self)->block);
13629 +  block_iter_obj->initialized_p = 0;
13630 +
13631 +  return (PyObject *) block_iter_obj;
13632 +}
13633 +
13634 +static PyObject *
13635 +blpy_get_start (PyObject *self, void *closure)
13636 +{
13637 +  block_object *self_block = (block_object *) self;
13638 +
13639 +  return PyLong_FromUnsignedLongLong (BLOCK_START (self_block->block));
13640 +}
13641 +
13642 +static PyObject *
13643 +blpy_get_end (PyObject *self, void *closure)
13644 +{
13645 +  block_object *self_block = (block_object *) self;
13646 +
13647 +  return PyLong_FromUnsignedLongLong (BLOCK_END (self_block->block));
13648 +}
13649 +
13650 +static PyObject *
13651 +blpy_get_function (PyObject *self, void *closure)
13652 +{
13653 +  block_object *self_block = (block_object *) self;
13654 +  struct symbol *sym;
13655 +
13656 +  sym = BLOCK_FUNCTION (self_block->block);
13657 +  if (sym)
13658 +    return symbol_to_symbol_object (sym);
13659 +
13660 +  Py_RETURN_NONE;
13661 +}
13662 +
13663 +static PyObject *
13664 +blpy_get_superblock (PyObject *self, void *closure)
13665 +{
13666 +  block_object *self_block = (block_object *) self;
13667 +  struct block *block;
13668 +
13669 +  block = BLOCK_SUPERBLOCK (self_block->block);
13670 +  if (block)
13671 +    return block_to_block_object (block);
13672 +
13673 +  Py_RETURN_NONE;
13674 +}
13675 +
13676 +PyObject *
13677 +block_to_block_object (struct block *block)
13678 +{
13679 +  block_object *block_obj;
13680 +
13681 +  block_obj = PyObject_New (block_object, &block_object_type);
13682 +  if (block_obj == NULL)
13683 +    {
13684 +      PyErr_SetString (PyExc_MemoryError, "Could not allocate block object.");
13685 +      return NULL;
13686 +    }
13687 +
13688 +  block_obj->block = block;
13689 +
13690 +  return (PyObject *) block_obj;
13691 +}
13692 +
13693 +struct block *
13694 +block_object_to_block (PyObject *obj)
13695 +{
13696 +  if (! PyObject_TypeCheck (obj, &block_object_type))
13697 +    return NULL;
13698 +  return ((block_object *) obj)->block;
13699 +}
13700 +
13701 +static PyObject *
13702 +blpy_block_syms_iter (PyObject *self)
13703 +{
13704 +  return self;
13705 +}
13706 +
13707 +static PyObject *
13708 +blpy_block_syms_iternext (PyObject *self)
13709 +{
13710 +  block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) self;
13711 +  struct symbol *sym;
13712 +
13713 +  if (!iter_obj->initialized_p)
13714 +    {
13715 +      sym = dict_iterator_first (iter_obj->dict,  &(iter_obj->iter));
13716 +      iter_obj->initialized_p = 1;
13717 +    }
13718 +  else
13719 +    sym = dict_iterator_next (&(iter_obj->iter));
13720 +
13721 +  return (sym == NULL)? NULL : symbol_to_symbol_object (sym);
13722 +}
13723 +
13724 +/* Return the innermost lexical block containing the specified pc value,
13725 +   or 0 if there is none.  */
13726 +
13727 +PyObject *
13728 +gdbpy_block_for_pc (PyObject *self, PyObject *args)
13729 +{
13730 +  unsigned PY_LONG_LONG pc;
13731 +  struct block *block;
13732 +  PyObject *sym_obj;
13733 +
13734 +  if (!PyArg_ParseTuple (args, "K", &pc))
13735 +    return NULL;
13736 +
13737 +  block = block_for_pc (pc);
13738 +  if (block)
13739 +    return block_to_block_object (block);
13740 +
13741 +  Py_RETURN_NONE;
13742 +}
13743 +
13744 +void
13745 +gdbpy_initialize_blocks (void)
13746 +{
13747 +  block_object_type.tp_new = PyType_GenericNew;
13748 +  if (PyType_Ready (&block_object_type) < 0)
13749 +    return;
13750 +
13751 +  block_syms_iterator_object_type.tp_new = PyType_GenericNew;
13752 +  if (PyType_Ready (&block_syms_iterator_object_type) < 0)
13753 +    return;
13754 +
13755 +  Py_INCREF (&block_object_type);
13756 +  PyModule_AddObject (gdb_module, "Block", (PyObject *) &block_object_type);
13757 +
13758 +  Py_INCREF (&block_syms_iterator_object_type);
13759 +  PyModule_AddObject (gdb_module, "BlockIterator",
13760 +                     (PyObject *) &block_syms_iterator_object_type);
13761 +}
13762 +
13763 +\f
13764 +
13765 +static PyGetSetDef block_object_getset[] = {
13766 +  { "start", blpy_get_start, NULL, "Start address of the block.", NULL },
13767 +  { "end", blpy_get_end, NULL, "End address of the block.", NULL },
13768 +  { "function", blpy_get_function, NULL,
13769 +    "Symbol that names the block, or None.", NULL },
13770 +  { "superblock", blpy_get_superblock, NULL,
13771 +    "Block containing the block, or None.", NULL },
13772 +  { NULL }  /* Sentinel */
13773 +};
13774 +
13775 +PyTypeObject block_object_type = {
13776 +  PyObject_HEAD_INIT (NULL)
13777 +  0,                             /*ob_size*/
13778 +  "gdb.Block",                   /*tp_name*/
13779 +  sizeof (block_object),         /*tp_basicsize*/
13780 +  0,                             /*tp_itemsize*/
13781 +  0,                             /*tp_dealloc*/
13782 +  0,                             /*tp_print*/
13783 +  0,                             /*tp_getattr*/
13784 +  0,                             /*tp_setattr*/
13785 +  0,                             /*tp_compare*/
13786 +  0,                             /*tp_repr*/
13787 +  0,                             /*tp_as_number*/
13788 +  0,                             /*tp_as_sequence*/
13789 +  0,                             /*tp_as_mapping*/
13790 +  0,                             /*tp_hash */
13791 +  0,                             /*tp_call*/
13792 +  0,                             /*tp_str*/
13793 +  0,                             /*tp_getattro*/
13794 +  0,                             /*tp_setattro*/
13795 +  0,                             /*tp_as_buffer*/
13796 +  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
13797 +  "GDB block object",            /* tp_doc */
13798 +  0,                             /* tp_traverse */
13799 +  0,                             /* tp_clear */
13800 +  0,                             /* tp_richcompare */
13801 +  0,                             /* tp_weaklistoffset */
13802 +  blpy_iter,                     /* tp_iter */
13803 +  0,                             /* tp_iternext */
13804 +  0,                             /* tp_methods */
13805 +  0,                             /* tp_members */
13806 +  block_object_getset            /* tp_getset */
13807 +};
13808 +
13809 +static PyTypeObject block_syms_iterator_object_type = {
13810 +  PyObject_HEAD_INIT (NULL)
13811 +  0,                             /*ob_size*/
13812 +  "gdb.BlockIterator",           /*tp_name*/
13813 +  sizeof (block_syms_iterator_object),       /*tp_basicsize*/
13814 +  0,                             /*tp_itemsize*/
13815 +  0,                             /*tp_dealloc*/
13816 +  0,                             /*tp_print*/
13817 +  0,                             /*tp_getattr*/
13818 +  0,                             /*tp_setattr*/
13819 +  0,                             /*tp_compare*/
13820 +  0,                             /*tp_repr*/
13821 +  0,                             /*tp_as_number*/
13822 +  0,                             /*tp_as_sequence*/
13823 +  0,                             /*tp_as_mapping*/
13824 +  0,                             /*tp_hash */
13825 +  0,                             /*tp_call*/
13826 +  0,                             /*tp_str*/
13827 +  0,                             /*tp_getattro*/
13828 +  0,                             /*tp_setattro*/
13829 +  0,                             /*tp_as_buffer*/
13830 +  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
13831 +  "GDB block syms iterator object",          /* tp_doc */
13832 +  0,                             /* tp_traverse */
13833 +  0,                             /* tp_clear */
13834 +  0,                             /* tp_richcompare */
13835 +  0,                             /* tp_weaklistoffset */
13836 +  blpy_block_syms_iter,                  /* tp_iter */
13837 +  blpy_block_syms_iternext,      /* tp_iternext */
13838 +  0                              /* tp_methods */
13839 +};
13840 diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
13841 new file mode 100644
13842 index 0000000..afa9526
13843 --- /dev/null
13844 +++ b/gdb/python/py-breakpoint.c
13845 @@ -0,0 +1,665 @@
13846 +/* Python interface to breakpoints
13847 +
13848 +   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13849 +
13850 +   This file is part of GDB.
13851 +
13852 +   This program is free software; you can redistribute it and/or modify
13853 +   it under the terms of the GNU General Public License as published by
13854 +   the Free Software Foundation; either version 3 of the License, or
13855 +   (at your option) any later version.
13856 +
13857 +   This program is distributed in the hope that it will be useful,
13858 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
13859 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13860 +   GNU General Public License for more details.
13861 +
13862 +   You should have received a copy of the GNU General Public License
13863 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
13864 +
13865 +#include "defs.h"
13866 +#include "value.h"
13867 +#include "exceptions.h"
13868 +#include "python-internal.h"
13869 +#include "charset.h"
13870 +#include "breakpoint.h"
13871 +#include "gdbcmd.h"
13872 +#include "gdbthread.h"
13873 +#include "observer.h"
13874 +
13875 +
13876 +/* From breakpoint.c.  */
13877 +extern struct breakpoint *breakpoint_chain;
13878 +
13879 +
13880 +typedef struct breakpoint_object breakpoint_object;
13881 +
13882 +static PyTypeObject breakpoint_object_type;
13883 +
13884 +/* A dynamically allocated vector of breakpoint objects.  Each
13885 +   breakpoint has a number.  A breakpoint is valid if its slot in this
13886 +   vector is non-null.  When a breakpoint is deleted, we drop our
13887 +   reference to it and zero its slot; this is how we let the Python
13888 +   object have a lifetime which is independent from that of the gdb
13889 +   breakpoint.  */
13890 +static breakpoint_object **bppy_breakpoints;
13891 +
13892 +/* Number of slots in bppy_breakpoints.  */
13893 +static int bppy_slots;
13894 +
13895 +/* Number of live breakpoints.  */
13896 +static int bppy_live;
13897 +
13898 +/* Variables used to pass information between the Breakpoint
13899 +   constructor and the breakpoint-created hook function.  */
13900 +static breakpoint_object *bppy_pending_object;
13901 +
13902 +struct breakpoint_object
13903 +{
13904 +  PyObject_HEAD
13905 +
13906 +  /* The breakpoint number according to gdb.  */
13907 +  int number;
13908 +
13909 +  /* The gdb breakpoint object, or NULL if the breakpoint has been
13910 +     deleted.  */
13911 +  struct breakpoint *bp;
13912 +};
13913 +
13914 +/* Evaluate to true if the breakpoint NUM is valid, false otherwise.  */
13915 +#define BPPY_VALID_P(Num)                      \
13916 +    ((Num) >= 0                                        \
13917 +     && (Num) < bppy_slots                     \
13918 +     && bppy_breakpoints[Num] != NULL)
13919 +
13920 +/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
13921 +   exception if it is invalid.  */
13922 +#define BPPY_REQUIRE_VALID(Breakpoint)                                 \
13923 +    do {                                                               \
13924 +      if (! BPPY_VALID_P ((Breakpoint)->number))                       \
13925 +       return PyErr_Format (PyExc_RuntimeError, "breakpoint %d is invalid", \
13926 +                            (Breakpoint)->number);                     \
13927 +    } while (0)
13928 +
13929 +/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
13930 +   exception if it is invalid.  This macro is for use in setter functions.  */
13931 +#define BPPY_SET_REQUIRE_VALID(Breakpoint)                             \
13932 +    do {                                                               \
13933 +      if (! BPPY_VALID_P ((Breakpoint)->number))                       \
13934 +        {                                                              \
13935 +         PyErr_Format (PyExc_RuntimeError, "breakpoint %d is invalid", \
13936 +                       (Breakpoint)->number);                          \
13937 +         return -1;                                                    \
13938 +       }                                                               \
13939 +    } while (0)
13940 +
13941 +/* Python function which checks the validity of a breakpoint object.  */
13942 +static PyObject *
13943 +bppy_is_valid (PyObject *self, PyObject *args)
13944 +{
13945 +  if (((breakpoint_object *) self)->bp)
13946 +    Py_RETURN_TRUE;
13947 +  Py_RETURN_FALSE;
13948 +}
13949 +
13950 +/* Python function to test whether or not the breakpoint is enabled.  */
13951 +static PyObject *
13952 +bppy_get_enabled (PyObject *self, void *closure)
13953 +{
13954 +  if (! ((breakpoint_object *) self)->bp)
13955 +    Py_RETURN_FALSE;
13956 +  /* Not clear what we really want here.  */
13957 +  if (((breakpoint_object *) self)->bp->enable_state == bp_enabled)
13958 +    Py_RETURN_TRUE;
13959 +  Py_RETURN_FALSE;
13960 +}
13961 +
13962 +/* Python function to test whether or not the breakpoint is silent.  */
13963 +static PyObject *
13964 +bppy_get_silent (PyObject *self, void *closure)
13965 +{
13966 +  BPPY_REQUIRE_VALID ((breakpoint_object *) self);
13967 +  if (((breakpoint_object *) self)->bp->silent)
13968 +    Py_RETURN_TRUE;
13969 +  Py_RETURN_FALSE;
13970 +}
13971 +
13972 +/* Python function to set the enabled state of a breakpoint.  */
13973 +static int
13974 +bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
13975 +{
13976 +  breakpoint_object *self_bp = (breakpoint_object *) self;
13977 +  int cmp;
13978 +
13979 +  BPPY_SET_REQUIRE_VALID (self_bp);
13980 +
13981 +  if (newvalue == NULL)
13982 +    {
13983 +      PyErr_SetString (PyExc_TypeError, "cannot delete `enabled' attribute");
13984 +      return -1;
13985 +    }
13986 +  else if (! PyBool_Check (newvalue))
13987 +    {
13988 +      PyErr_SetString (PyExc_TypeError,
13989 +                      "the value of `enabled' must be a boolean");
13990 +      return -1;
13991 +    }
13992 +
13993 +  cmp = PyObject_IsTrue (newvalue);
13994 +  if (cmp < 0)
13995 +    return -1;
13996 +  else if (cmp == 1)
13997 +    enable_breakpoint (self_bp->bp);
13998 +  else 
13999 +    disable_breakpoint (self_bp->bp);
14000 +  return 0;
14001 +}
14002 +
14003 +/* Python function to set the 'silent' state of a breakpoint.  */
14004 +static int
14005 +bppy_set_silent (PyObject *self, PyObject *newvalue, void *closure)
14006 +{
14007 +  breakpoint_object *self_bp = (breakpoint_object *) self;
14008 +  int cmp;
14009 +
14010 +  BPPY_SET_REQUIRE_VALID (self_bp);
14011 +
14012 +  if (newvalue == NULL)
14013 +    {
14014 +      PyErr_SetString (PyExc_TypeError, "cannot delete `silent' attribute");
14015 +      return -1;
14016 +    }
14017 +  else if (! PyBool_Check (newvalue))
14018 +    {
14019 +      PyErr_SetString (PyExc_TypeError,
14020 +                      "the value of `silent' must be a boolean");
14021 +      return -1;
14022 +    }
14023 +
14024 +  cmp = PyObject_IsTrue (newvalue);
14025 +  if (cmp < 0)
14026 +    return -1;
14027 +  else
14028 +    self_bp->bp->silent = cmp;
14029 +
14030 +  return 0;
14031 +}
14032 +
14033 +/* Python function to set the thread of a breakpoint.  */
14034 +static int
14035 +bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
14036 +{
14037 +  breakpoint_object *self_bp = (breakpoint_object *) self;
14038 +  int id;
14039 +
14040 +  BPPY_SET_REQUIRE_VALID (self_bp);
14041 +
14042 +  if (newvalue == NULL)
14043 +    {
14044 +      PyErr_SetString (PyExc_TypeError, "cannot delete `thread' attribute");
14045 +      return -1;
14046 +    }
14047 +  else if (PyInt_Check (newvalue))
14048 +    {
14049 +      id = (int) PyInt_AsLong (newvalue);
14050 +      if (! valid_thread_id (id))
14051 +       {
14052 +         PyErr_SetString (PyExc_RuntimeError, "invalid thread id");
14053 +         return -1;
14054 +       }
14055 +    }
14056 +  else if (newvalue == Py_None)
14057 +    id = -1;
14058 +  else
14059 +    {
14060 +      PyErr_SetString (PyExc_TypeError,
14061 +                      "the value of `thread' must be an integer or None");
14062 +      return -1;
14063 +    }
14064 +
14065 +  self_bp->bp->thread = id;
14066 +
14067 +  return 0;
14068 +}
14069 +
14070 +/* Python function to set the ignore count of a breakpoint.  */
14071 +static int
14072 +bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
14073 +{
14074 +  breakpoint_object *self_bp = (breakpoint_object *) self;
14075 +  long value;
14076 +
14077 +  BPPY_SET_REQUIRE_VALID (self_bp);
14078 +
14079 +  if (newvalue == NULL)
14080 +    {
14081 +      PyErr_SetString (PyExc_TypeError,
14082 +                      "cannot delete `ignore_count' attribute");
14083 +      return -1;
14084 +    }
14085 +  else if (! PyInt_Check (newvalue))
14086 +    {
14087 +      PyErr_SetString (PyExc_TypeError,
14088 +                      "the value of `ignore_count' must be an integer");
14089 +      return -1;
14090 +    }
14091 +
14092 +  value = PyInt_AsLong (newvalue);
14093 +  if (value < 0)
14094 +    value = 0;
14095 +  set_ignore_count (self_bp->number, (int) value, 0);
14096 +
14097 +  return 0;
14098 +}
14099 +
14100 +/* Python function to set the hit count of a breakpoint.  */
14101 +static int
14102 +bppy_set_hit_count (PyObject *self, PyObject *newvalue, void *closure)
14103 +{
14104 +  breakpoint_object *self_bp = (breakpoint_object *) self;
14105 +
14106 +  BPPY_SET_REQUIRE_VALID (self_bp);
14107 +
14108 +  if (newvalue == NULL)
14109 +    {
14110 +      PyErr_SetString (PyExc_TypeError, "cannot delete `hit_count' attribute");
14111 +      return -1;
14112 +    }
14113 +  else if (! PyInt_Check (newvalue) || PyInt_AsLong (newvalue) != 0)
14114 +    {
14115 +      PyErr_SetString (PyExc_AttributeError,
14116 +                      "the value of `hit_count' must be zero");
14117 +      return -1;
14118 +    }
14119 +
14120 +  self_bp->bp->hit_count = 0;
14121 +
14122 +  return 0;
14123 +}
14124 +
14125 +/* Python function to get the location of a breakpoint.  */
14126 +static PyObject *
14127 +bppy_get_location (PyObject *self, void *closure)
14128 +{
14129 +  char *str;
14130 +
14131 +  BPPY_REQUIRE_VALID ((breakpoint_object *) self);
14132 +  str = ((breakpoint_object *) self)->bp->addr_string;
14133 +  /* FIXME: watchpoints?  tracepoints?  */
14134 +  if (! str)
14135 +    str = "";
14136 +  return PyString_Decode (str, strlen (str), host_charset (), NULL);
14137 +}
14138 +
14139 +/* Python function to get the condition expression of a breakpoint.  */
14140 +static PyObject *
14141 +bppy_get_condition (PyObject *self, void *closure)
14142 +{
14143 +  char *str;
14144 +  BPPY_REQUIRE_VALID ((breakpoint_object *) self);
14145 +
14146 +  str = ((breakpoint_object *) self)->bp->cond_string;
14147 +  if (! str)
14148 +    Py_RETURN_NONE;
14149 +  return PyString_Decode (str, strlen (str), host_charset (), NULL);
14150 +}
14151 +
14152 +static int
14153 +bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
14154 +{
14155 +  char *exp;
14156 +  breakpoint_object *self_bp = (breakpoint_object *) self;
14157 +  volatile struct gdb_exception except;
14158 +
14159 +  BPPY_SET_REQUIRE_VALID (self_bp);
14160 +
14161 +  if (newvalue == NULL)
14162 +    {
14163 +      PyErr_SetString (PyExc_TypeError, "cannot delete `condition' attribute");
14164 +      return -1;
14165 +    }
14166 +  else if (newvalue == Py_None)
14167 +    exp = "";
14168 +  else
14169 +    {
14170 +      exp = python_string_to_host_string (newvalue);
14171 +      if (exp == NULL)
14172 +       return -1;
14173 +    }
14174 +
14175 +  TRY_CATCH (except, RETURN_MASK_ALL)
14176 +    {
14177 +      set_breakpoint_condition (self_bp->bp, exp, 0);
14178 +    }
14179 +  GDB_PY_SET_HANDLE_EXCEPTION (except);
14180 +
14181 +  return 0;
14182 +}
14183 +
14184 +/* Python function to get the commands attached to a breakpoint.  */
14185 +static PyObject *
14186 +bppy_get_commands (PyObject *self, void *closure)
14187 +{
14188 +  breakpoint_object *self_bp = (breakpoint_object *) self;
14189 +  long length;
14190 +  volatile struct gdb_exception except;
14191 +  struct ui_file *string_file;
14192 +  struct cleanup *chain;
14193 +  PyObject *result;
14194 +  char *cmdstr;
14195 +
14196 +  BPPY_REQUIRE_VALID (self_bp);
14197 +
14198 +  if (! self_bp->bp->commands)
14199 +    Py_RETURN_NONE;
14200 +
14201 +  string_file = mem_fileopen ();
14202 +  chain = make_cleanup_ui_file_delete (string_file);
14203 +
14204 +  TRY_CATCH (except, RETURN_MASK_ALL)
14205 +    {
14206 +      /* FIXME: this can fail.  Maybe we need to be making a new
14207 +        ui_out object here?  */
14208 +      ui_out_redirect (uiout, string_file);
14209 +      print_command_lines (uiout, self_bp->bp->commands, 0);
14210 +      ui_out_redirect (uiout, NULL);
14211 +    }
14212 +  cmdstr = ui_file_xstrdup (string_file, &length);
14213 +  GDB_PY_HANDLE_EXCEPTION (except);
14214 +
14215 +  result = PyString_Decode (cmdstr, strlen (cmdstr), host_charset (), NULL);
14216 +  do_cleanups (chain);
14217 +  xfree (cmdstr);
14218 +  return result;
14219 +}
14220 +
14221 +/* Python function to get the breakpoint's number.  */
14222 +static PyObject *
14223 +bppy_get_number (PyObject *self, void *closure)
14224 +{
14225 +  breakpoint_object *self_bp = (breakpoint_object *) self;
14226 +
14227 +  BPPY_REQUIRE_VALID (self_bp);
14228 +
14229 +  return PyInt_FromLong (self_bp->number);
14230 +}
14231 +
14232 +/* Python function to get the breakpoint's thread ID.  */
14233 +static PyObject *
14234 +bppy_get_thread (PyObject *self, void *closure)
14235 +{
14236 +  breakpoint_object *self_bp = (breakpoint_object *) self;
14237 +
14238 +  BPPY_REQUIRE_VALID (self_bp);
14239 +
14240 +  if (self_bp->bp->thread == -1)
14241 +    Py_RETURN_NONE;
14242 +
14243 +  return PyInt_FromLong (self_bp->bp->thread);
14244 +}
14245 +
14246 +/* Python function to get the breakpoint's hit count.  */
14247 +static PyObject *
14248 +bppy_get_hit_count (PyObject *self, void *closure)
14249 +{
14250 +  breakpoint_object *self_bp = (breakpoint_object *) self;
14251 +
14252 +  BPPY_REQUIRE_VALID (self_bp);
14253 +
14254 +  return PyInt_FromLong (self_bp->bp->hit_count);
14255 +}
14256 +
14257 +/* Python function to get the breakpoint's ignore count.  */
14258 +static PyObject *
14259 +bppy_get_ignore_count (PyObject *self, void *closure)
14260 +{
14261 +  breakpoint_object *self_bp = (breakpoint_object *) self;
14262 +
14263 +  BPPY_REQUIRE_VALID (self_bp);
14264 +
14265 +  return PyInt_FromLong (self_bp->bp->ignore_count);
14266 +}
14267 +
14268 +/* Python function to create a new breakpoint.  */
14269 +static PyObject *
14270 +bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
14271 +{
14272 +  PyObject *result;
14273 +  char *spec;
14274 +  volatile struct gdb_exception except;
14275 +
14276 +  /* FIXME: allow condition, thread, temporary, ... ? */
14277 +  if (! PyArg_ParseTuple (args, "s", &spec))
14278 +    return NULL;
14279 +  result = subtype->tp_alloc (subtype, 0);
14280 +  if (! result)
14281 +    return NULL;
14282 +  bppy_pending_object = (breakpoint_object *) result;
14283 +  bppy_pending_object->number = -1;
14284 +  bppy_pending_object->bp = NULL;
14285 +
14286 +  TRY_CATCH (except, RETURN_MASK_ALL)
14287 +    {
14288 +      set_breakpoint (python_gdbarch, spec, NULL, 0, 0, -1, 0,
14289 +                     AUTO_BOOLEAN_TRUE, 1);
14290 +    }
14291 +  if (except.reason < 0)
14292 +    {
14293 +      subtype->tp_free (result);
14294 +      return PyErr_Format (except.reason == RETURN_QUIT
14295 +                            ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
14296 +                            "%s", except.message);
14297 +    }
14298 +
14299 +  BPPY_REQUIRE_VALID ((breakpoint_object *) result);
14300 +  return result;
14301 +}
14302 +
14303 +\f
14304 +
14305 +/* Static function to return a tuple holding all breakpoints.  */
14306 +
14307 +PyObject *
14308 +gdbpy_breakpoints (PyObject *self, PyObject *args)
14309 +{
14310 +  PyObject *result;
14311 +
14312 +  if (bppy_live == 0)
14313 +    Py_RETURN_NONE;
14314 +
14315 +  result = PyTuple_New (bppy_live);
14316 +  if (result)
14317 +    {
14318 +      int i, out = 0;
14319 +      for (i = 0; out < bppy_live; ++i)
14320 +       {
14321 +         if (! bppy_breakpoints[i])
14322 +           continue;
14323 +         Py_INCREF (bppy_breakpoints[i]);
14324 +         PyTuple_SetItem (result, out, (PyObject *) bppy_breakpoints[i]);
14325 +         ++out;
14326 +       }
14327 +    }
14328 +  return result;
14329 +}
14330 +
14331 +\f
14332 +
14333 +/* Event callback functions.  */
14334 +
14335 +/* Callback that is used when a breakpoint is created.  This function
14336 +   will create a new Python breakpoint object.  */
14337 +static void
14338 +gdbpy_breakpoint_created (int num)
14339 +{
14340 +  breakpoint_object *newbp;
14341 +  struct breakpoint *bp;
14342 +  PyGILState_STATE state;
14343 +
14344 +  if (num < 0)
14345 +    return;
14346 +
14347 +  for (bp = breakpoint_chain; bp; bp = bp->next)
14348 +    if (bp->number == num)
14349 +      break;
14350 +  if (! bp)
14351 +    return;
14352 +
14353 +  if (num >= bppy_slots)
14354 +    {
14355 +      int old = bppy_slots;
14356 +      bppy_slots = bppy_slots * 2 + 10;
14357 +      bppy_breakpoints
14358 +       = (breakpoint_object **) xrealloc (bppy_breakpoints,
14359 +                                          (bppy_slots
14360 +                                           * sizeof (breakpoint_object *)));
14361 +      memset (&bppy_breakpoints[old], 0,
14362 +             (bppy_slots - old) * sizeof (PyObject *));
14363 +    }
14364 +
14365 +  ++bppy_live;
14366 +
14367 +  state = PyGILState_Ensure ();
14368 +
14369 +  if (bppy_pending_object)
14370 +    {
14371 +      newbp = bppy_pending_object;
14372 +      bppy_pending_object = NULL;
14373 +    }
14374 +  else
14375 +    newbp = PyObject_New (breakpoint_object, &breakpoint_object_type);
14376 +  if (newbp)
14377 +    {
14378 +      PyObject *hookfn;
14379 +
14380 +      newbp->number = num;
14381 +      newbp->bp = bp;
14382 +      bppy_breakpoints[num] = newbp;
14383 +
14384 +      hookfn = gdbpy_get_hook_function ("new_breakpoint");
14385 +      if (hookfn)
14386 +       {
14387 +         PyObject *result;
14388 +         result = PyObject_CallFunctionObjArgs (hookfn, newbp, NULL);
14389 +         if (result)
14390 +           {
14391 +             Py_DECREF (result);
14392 +           }
14393 +         Py_DECREF (hookfn);
14394 +       }
14395 +    }
14396 +
14397 +  /* Just ignore errors here.  */
14398 +  PyErr_Clear ();
14399 +
14400 +  PyGILState_Release (state);
14401 +}
14402 +
14403 +/* Callback that is used when a breakpoint is deleted.  This will
14404 +   invalidate the corresponding Python object.  */
14405 +static void
14406 +gdbpy_breakpoint_deleted (int num)
14407 +{
14408 +  PyGILState_STATE state;
14409 +
14410 +  state = PyGILState_Ensure ();
14411 +  if (BPPY_VALID_P (num))
14412 +    {
14413 +      bppy_breakpoints[num]->bp = NULL;
14414 +      Py_DECREF (bppy_breakpoints[num]);
14415 +      bppy_breakpoints[num] = NULL;
14416 +      --bppy_live;
14417 +    }
14418 +  PyGILState_Release (state);
14419 +}
14420 +
14421 +\f
14422 +
14423 +/* Initialize the Python breakpoint code.  */
14424 +void
14425 +gdbpy_initialize_breakpoints (void)
14426 +{
14427 +  breakpoint_object_type.tp_new = bppy_new;
14428 +  if (PyType_Ready (&breakpoint_object_type) < 0)
14429 +    return;
14430 +
14431 +  Py_INCREF (&breakpoint_object_type);
14432 +  PyModule_AddObject (gdb_module, "Breakpoint",
14433 +                     (PyObject *) &breakpoint_object_type);
14434 +
14435 +  observer_attach_breakpoint_created (gdbpy_breakpoint_created);
14436 +  observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
14437 +}
14438 +
14439 +\f
14440 +
14441 +static PyGetSetDef breakpoint_object_getset[] = {
14442 +  { "enabled", bppy_get_enabled, bppy_set_enabled,
14443 +    "Boolean telling whether the breakpoint is enabled.", NULL },
14444 +  { "silent", bppy_get_silent, bppy_set_silent,
14445 +    "Boolean telling whether the breakpoint is silent.", NULL },
14446 +  { "thread", bppy_get_thread, bppy_set_thread,
14447 +    "Thread ID for the breakpoint.\n\
14448 +If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
14449 +If the value is None, then this breakpoint not thread-specific.\n\
14450 +No other type of value can be used.", NULL },
14451 +  { "ignore_count", bppy_get_ignore_count, bppy_set_ignore_count,
14452 +    "Number of times this breakpoint should be automatically continued.",
14453 +    NULL },
14454 +  { "number", bppy_get_number, NULL,
14455 +    "Breakpoint's number assigned by GDB.", NULL },
14456 +  { "hit_count", bppy_get_hit_count, bppy_set_hit_count,
14457 +    "Number of times the breakpoint has been hit.\n\
14458 +Can be set to zero to clear the count. No other value is valid\n\
14459 +when setting this property.", NULL },
14460 +  { "location", bppy_get_location, NULL,
14461 +    "Location of the breakpoint, as specified by the user.", NULL},
14462 +  { "condition", bppy_get_condition, bppy_set_condition,
14463 +    "Condition of the breakpoint, as specified by the user,\
14464 +or None if no condition set."},
14465 +  { "commands", bppy_get_commands, NULL,
14466 +    "Commands of the breakpoint, as specified by the user."},
14467 +  { NULL }  /* Sentinel.  */
14468 +};
14469 +
14470 +static PyMethodDef breakpoint_object_methods[] =
14471 +{
14472 +  { "is_valid", bppy_is_valid, METH_NOARGS,
14473 +    "Return true if this breakpoint is valid, false if not." },
14474 +  { NULL } /* Sentinel.  */
14475 +};
14476 +
14477 +static PyTypeObject breakpoint_object_type =
14478 +{
14479 +  PyObject_HEAD_INIT (NULL)
14480 +  0,                             /*ob_size*/
14481 +  "gdb.Breakpoint",              /*tp_name*/
14482 +  sizeof (breakpoint_object),    /*tp_basicsize*/
14483 +  0,                             /*tp_itemsize*/
14484 +  0,                             /*tp_dealloc*/
14485 +  0,                             /*tp_print*/
14486 +  0,                             /*tp_getattr*/
14487 +  0,                             /*tp_setattr*/
14488 +  0,                             /*tp_compare*/
14489 +  0,                             /*tp_repr*/
14490 +  0,                             /*tp_as_number*/
14491 +  0,                             /*tp_as_sequence*/
14492 +  0,                             /*tp_as_mapping*/
14493 +  0,                             /*tp_hash */
14494 +  0,                             /*tp_call*/
14495 +  0,                             /*tp_str*/
14496 +  0,                             /*tp_getattro*/
14497 +  0,                             /*tp_setattro*/
14498 +  0,                             /*tp_as_buffer*/
14499 +  Py_TPFLAGS_DEFAULT,            /*tp_flags*/
14500 +  "GDB breakpoint object",       /* tp_doc */
14501 +  0,                             /* tp_traverse */
14502 +  0,                             /* tp_clear */
14503 +  0,                             /* tp_richcompare */
14504 +  0,                             /* tp_weaklistoffset */
14505 +  0,                             /* tp_iter */
14506 +  0,                             /* tp_iternext */
14507 +  breakpoint_object_methods,     /* tp_methods */
14508 +  0,                             /* tp_members */
14509 +  breakpoint_object_getset       /* tp_getset */
14510 +};
14511 diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
14512 index 528aca6..04b3fd1 100644
14513 --- a/gdb/python/py-cmd.c
14514 +++ b/gdb/python/py-cmd.c
14515 @@ -49,8 +49,7 @@ static struct cmdpy_completer completers[] =
14516  
14517  #define N_COMPLETERS (sizeof (completers) / sizeof (completers[0]))
14518  
14519 -/* A gdb command.  For the time being only ordinary commands (not
14520 -   set/show commands) are allowed.  */
14521 +/* A gdb command.  */
14522  struct cmdpy_object
14523  {
14524    PyObject_HEAD
14525 @@ -70,7 +69,6 @@ typedef struct cmdpy_object cmdpy_object;
14526  
14527  static PyTypeObject cmdpy_object_type;
14528  
14529 -
14530  /* Constants used by this module.  */
14531  static PyObject *invoke_cst;
14532  static PyObject *complete_cst;
14533 @@ -263,10 +261,13 @@ cmdpy_completer (struct cmd_list_element *command, char *text, char *word)
14534     *BASE_LIST is set to the final prefix command's list of
14535     *sub-commands.
14536     
14537 +   START_LIST is the list in which the search starts.
14538 +   
14539     This function returns the xmalloc()d name of the new command.  On
14540     error sets the Python error and returns NULL.  */
14541 -static char *
14542 -parse_command_name (char *text, struct cmd_list_element ***base_list)
14543 +char *
14544 +gdbpy_parse_command_name (char *text, struct cmd_list_element ***base_list,
14545 +                         struct cmd_list_element **start_list)
14546  {
14547    struct cmd_list_element *elt;
14548    int len = strlen (text);
14549 @@ -299,7 +300,7 @@ parse_command_name (char *text, struct cmd_list_element ***base_list)
14550      ;
14551    if (i < 0)
14552      {
14553 -      *base_list = &cmdlist;
14554 +      *base_list = start_list;
14555        return result;
14556      }
14557  
14558 @@ -308,7 +309,7 @@ parse_command_name (char *text, struct cmd_list_element ***base_list)
14559    prefix_text[i + 1] = '\0';
14560  
14561    text = prefix_text;
14562 -  elt = lookup_cmd_1 (&text, cmdlist, NULL, 1);
14563 +  elt = lookup_cmd_1 (&text, *start_list, NULL, 1);
14564    if (!elt || elt == (struct cmd_list_element *) -1)
14565      {
14566        PyErr_Format (PyExc_RuntimeError, _("could not find command prefix %s"),
14567 @@ -399,7 +400,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
14568        return -1;
14569      }
14570  
14571 -  cmd_name = parse_command_name (name, &cmd_list);
14572 +  cmd_name = gdbpy_parse_command_name (name, &cmd_list, &cmdlist);
14573    if (! cmd_name)
14574      return -1;
14575  
14576 diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
14577 index 279415c..5d8ce0a 100644
14578 --- a/gdb/python/py-frame.c
14579 +++ b/gdb/python/py-frame.c
14580 @@ -202,10 +202,59 @@ frapy_pc (PyObject *self, PyObject *args)
14581    return PyLong_FromUnsignedLongLong (pc);
14582  }
14583  
14584 +/* Implementation of gdb.Frame.block (self) -> gdb.Block.
14585 +   Returns the frame's code block.  */
14586 +
14587 +static PyObject *
14588 +frapy_block (PyObject *self, PyObject *args)
14589 +{
14590 +  struct frame_info *frame;
14591 +  struct block *block = NULL;
14592 +  volatile struct gdb_exception except;
14593 +
14594 +  TRY_CATCH (except, RETURN_MASK_ALL)
14595 +    {
14596 +      FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
14597 +
14598 +      block = block_for_pc (get_frame_address_in_block (frame));
14599 +    }
14600 +  GDB_PY_HANDLE_EXCEPTION (except);
14601 +
14602 +  if (block)
14603 +    return block_to_block_object (block);
14604 +
14605 +  Py_RETURN_NONE;
14606 +}
14607 +
14608 +
14609 +/* Implementation of gdb.Frame.function (self) -> gdb.Symbol.
14610 +   Returns the symbol for the function corresponding to this frame.  */
14611 +
14612 +static PyObject *
14613 +frapy_function (PyObject *self, PyObject *args)
14614 +{
14615 +  struct symbol *sym = NULL;
14616 +  struct frame_info *frame;
14617 +  volatile struct gdb_exception except;
14618 +
14619 +  TRY_CATCH (except, RETURN_MASK_ALL)
14620 +    {
14621 +      FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
14622 +
14623 +      sym = find_pc_function (get_frame_address_in_block (frame));
14624 +    }
14625 +  GDB_PY_HANDLE_EXCEPTION (except);
14626 +
14627 +  if (sym)
14628 +    return symbol_to_symbol_object (sym);
14629 +
14630 +  Py_RETURN_NONE;
14631 +}
14632 +
14633  /* Convert a frame_info struct to a Python Frame object.
14634     Sets a Python exception and returns NULL on error.  */
14635  
14636 -static frame_object *
14637 +PyObject *
14638  frame_info_to_frame_object (struct frame_info *frame)
14639  {
14640    frame_object *frame_obj;
14641 @@ -235,7 +284,7 @@ frame_info_to_frame_object (struct frame_info *frame)
14642  
14643    frame_obj->gdbarch = get_frame_arch (frame);
14644  
14645 -  return frame_obj;
14646 +  return (PyObject *) frame_obj;
14647  }
14648  
14649  /* Implementation of gdb.Frame.older (self) -> gdb.Frame.
14650 @@ -296,7 +345,30 @@ frapy_newer (PyObject *self, PyObject *args)
14651    return next_obj;
14652  }
14653  
14654 -/* Implementation of gdb.Frame.read_var_value (self, variable) -> gdb.Value.
14655 +/* Implementation of gdb.Frame.find_sal (self) -> gdb.Symtab_and_line.
14656 +   Returns the frame's symtab and line.  */
14657 +
14658 +static PyObject *
14659 +frapy_find_sal (PyObject *self, PyObject *args)
14660 +{
14661 +  struct frame_info *frame;
14662 +  struct symtab_and_line sal;
14663 +  volatile struct gdb_exception except;
14664 +  PyObject *sal_obj = NULL;   /* Initialize to appease gcc warning.  */
14665 +
14666 +  TRY_CATCH (except, RETURN_MASK_ALL)
14667 +    {
14668 +      FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
14669 +
14670 +      find_frame_sal (frame, &sal);
14671 +      sal_obj = symtab_and_line_to_sal_object (sal);
14672 +    }
14673 +  GDB_PY_HANDLE_EXCEPTION (except);
14674 +
14675 +  return sal_obj;
14676 +}
14677 +
14678 +/* Implementation of gdb.Frame.read_var (self, variable) -> gdb.Value.
14679     Returns the value of the given variable in this frame.  The argument must be
14680     a string.  Returns None if GDB can't find the specified variable.  */
14681  
14682 @@ -312,7 +384,9 @@ frapy_read_var (PyObject *self, PyObject *args)
14683    if (!PyArg_ParseTuple (args, "O", &sym_obj))
14684      return NULL;
14685  
14686 -  if (gdbpy_is_string (sym_obj))
14687 +  if (PyObject_TypeCheck (sym_obj, &symbol_object_type))
14688 +    var = symbol_object_to_symbol (sym_obj);
14689 +  else if (gdbpy_is_string (sym_obj))
14690      {
14691        char *var_name;
14692        struct block *block = NULL;
14693 @@ -365,6 +439,25 @@ frapy_read_var (PyObject *self, PyObject *args)
14694    Py_RETURN_NONE;
14695  }
14696  
14697 +/* Select this frame.  */
14698 +
14699 +static PyObject *
14700 +frapy_select (PyObject *self, PyObject *args)
14701 +{
14702 +  struct frame_info *fi;
14703 +  frame_object *frame = (frame_object *) self;
14704 +  volatile struct gdb_exception except;
14705 +
14706 +  TRY_CATCH (except, RETURN_MASK_ALL)
14707 +    {
14708 +      FRAPY_REQUIRE_VALID (frame, fi);
14709 +      select_frame (fi);
14710 +    }
14711 +  GDB_PY_HANDLE_EXCEPTION (except);
14712 +
14713 +  Py_RETURN_NONE;
14714 +}
14715 +
14716  /* Implementation of gdb.selected_frame () -> gdb.Frame.
14717     Returns the selected frame object.  */
14718  
14719 @@ -372,7 +465,7 @@ PyObject *
14720  gdbpy_selected_frame (PyObject *self, PyObject *args)
14721  {
14722    struct frame_info *frame;
14723 -  frame_object *frame_obj = NULL;   /* Initialize to appease gcc warning.  */
14724 +  PyObject *frame_obj = NULL;   /* Initialize to appease gcc warning.  */
14725    volatile struct gdb_exception except;
14726  
14727    TRY_CATCH (except, RETURN_MASK_ALL)
14728 @@ -382,7 +475,7 @@ gdbpy_selected_frame (PyObject *self, PyObject *args)
14729      }
14730    GDB_PY_HANDLE_EXCEPTION (except);
14731  
14732 -  return (PyObject *) frame_obj;
14733 +  return frame_obj;
14734  }
14735  
14736  /* Implementation of gdb.stop_reason_string (Integer) -> String.
14737 @@ -484,15 +577,26 @@ Return the reason why it's not possible to find frames older than this." },
14738    { "pc", frapy_pc, METH_NOARGS,
14739      "pc () -> Long.\n\
14740  Return the frame's resume address." },
14741 +  { "block", frapy_block, METH_NOARGS,
14742 +    "block () -> gdb.Block.\n\
14743 +Return the frame's code block." },
14744 +  { "function", frapy_function, METH_NOARGS,
14745 +    "function () -> gdb.Symbol.\n\
14746 +Returns the symbol for the function corresponding to this frame." },
14747    { "older", frapy_older, METH_NOARGS,
14748      "older () -> gdb.Frame.\n\
14749  Return the frame that called this frame." },
14750    { "newer", frapy_newer, METH_NOARGS,
14751      "newer () -> gdb.Frame.\n\
14752  Return the frame called by this frame." },
14753 +  { "find_sal", frapy_find_sal, METH_NOARGS,
14754 +    "find_sal () -> gdb.Symtab_and_line.\n\
14755 +Return the frame's symtab and line." },
14756    { "read_var", frapy_read_var, METH_VARARGS,
14757      "read_var (variable) -> gdb.Value.\n\
14758  Return the value of the variable in this frame." },
14759 +  { "select", frapy_select, METH_NOARGS,
14760 +    "Select this frame as the user's current frame." },
14761    {NULL}  /* Sentinel */
14762  };
14763  
14764 diff --git a/gdb/python/py-hooks.c b/gdb/python/py-hooks.c
14765 new file mode 100644
14766 index 0000000..a3140bc
14767 --- /dev/null
14768 +++ b/gdb/python/py-hooks.c
14769 @@ -0,0 +1,50 @@
14770 +/* Notifications from gdb to Python
14771 +
14772 +   Copyright (C) 2008 Free Software Foundation, Inc.
14773 +
14774 +   This file is part of GDB.
14775 +
14776 +   This program is free software; you can redistribute it and/or modify
14777 +   it under the terms of the GNU General Public License as published by
14778 +   the Free Software Foundation; either version 3 of the License, or
14779 +   (at your option) any later version.
14780 +
14781 +   This program is distributed in the hope that it will be useful,
14782 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
14783 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14784 +   GNU General Public License for more details.
14785 +
14786 +   You should have received a copy of the GNU General Public License
14787 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
14788 +
14789 +#include "defs.h"
14790 +#include "cli/cli-decode.h"
14791 +#include "charset.h"
14792 +#include "python.h"
14793 +#include "python-internal.h"
14794 +#include "observer.h"
14795 +
14796 +PyObject *
14797 +gdbpy_get_hook_function (const char *name)
14798 +{
14799 +  PyObject *hooks;
14800 +  PyObject *result;
14801 +
14802 +  if (! PyObject_HasAttrString (gdb_module, "hooks"))
14803 +    return NULL;
14804 +  hooks = PyObject_GetAttrString (gdb_module, "hooks");
14805 +  if (! hooks)
14806 +    return NULL;
14807 +  /* The cast is because the Python function doesn't declare const argument.
14808 +     This is a problem in Python version 2.4, but not in 2.5.  */
14809 +  if (! PyObject_HasAttrString (hooks, (char *) name))
14810 +    {
14811 +      Py_DECREF (hooks);
14812 +      return NULL;
14813 +    }
14814 +  /* The cast is because the Python function doesn't declare const argument.
14815 +     This is a problem in Python version 2.4, but not in 2.5.  */
14816 +  result = PyObject_GetAttrString (hooks, (char *) name);
14817 +  Py_DECREF (hooks);
14818 +  return result;
14819 +}
14820 diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
14821 new file mode 100644
14822 index 0000000..5e90cc2
14823 --- /dev/null
14824 +++ b/gdb/python/py-inferior.c
14825 @@ -0,0 +1,926 @@
14826 +/* Python interface to inferiors.
14827 +
14828 +   Copyright (C) 2009 Free Software Foundation, Inc.
14829 +
14830 +   This file is part of GDB.
14831 +
14832 +   This program is free software; you can redistribute it and/or modify
14833 +   it under the terms of the GNU General Public License as published by
14834 +   the Free Software Foundation; either version 3 of the License, or
14835 +   (at your option) any later version.
14836 +
14837 +   This program is distributed in the hope that it will be useful,
14838 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
14839 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14840 +   GNU General Public License for more details.
14841 +
14842 +   You should have received a copy of the GNU General Public License
14843 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
14844 +
14845 +#include "defs.h"
14846 +#include "exceptions.h"
14847 +#include "gdbcore.h"
14848 +#include "gdbthread.h"
14849 +#include "inferior.h"
14850 +#include "observer.h"
14851 +#include "python-internal.h"
14852 +#include "arch-utils.h"
14853 +#include "language.h"
14854 +
14855 +struct threadlist_entry {
14856 +  thread_object *thread_obj;
14857 +  struct threadlist_entry *next;
14858 +};
14859 +
14860 +typedef struct
14861 +{
14862 +  PyObject_HEAD
14863 +
14864 +  /* The inferior we represent.  */
14865 +  struct inferior *inferior;
14866 +
14867 +  /* thread_object instances under this inferior.  This list owns a reference
14868 +     to each object it contains. */
14869 +  struct threadlist_entry *threads;
14870 +
14871 +  /* Number of threads in the list.  */
14872 +  int nthreads;
14873 +} inferior_object;
14874 +
14875 +static PyTypeObject inferior_object_type;
14876 +
14877 +typedef struct {
14878 +  PyObject_HEAD
14879 +  void *buffer;
14880 +
14881 +  /* These are kept just for mbpy_str.  */
14882 +  CORE_ADDR addr;
14883 +  CORE_ADDR length;
14884 +} membuf_object;
14885 +
14886 +static PyTypeObject membuf_object_type;
14887 +
14888 +/* Require that INFERIOR be a valid inferior ID.  */
14889 +#define INFPY_REQUIRE_VALID(Inferior)                          \
14890 +  do {                                                         \
14891 +    if (!Inferior->inferior)                                   \
14892 +      {                                                                \
14893 +       PyErr_SetString (PyExc_RuntimeError,                    \
14894 +                        "inferior no longer exists");          \
14895 +       return NULL;                                            \
14896 +      }                                                                \
14897 +  } while (0)
14898 +
14899 +struct inflist_entry {
14900 +  inferior_object *inf_obj;
14901 +  struct inflist_entry *next;
14902 +};
14903 +
14904 +\f
14905 +
14906 +/* Inferior objects list.  */
14907 +
14908 +/* List containing inferior_objects.  This list owns a reference to each
14909 +   object it contains.  */
14910 +static struct inflist_entry *inferior_list;
14911 +
14912 +static int ninferiors;
14913 +
14914 +
14915 +/* An observer callback function that is called when an inferior has
14916 +   been created.  Creates a corresponding Python object for the inferior
14917 +   and adds it to the list.  */
14918 +static void
14919 +add_inferior_object (int pid)
14920 +{
14921 +  struct inferior *inf = find_inferior_pid (pid);
14922 +  inferior_object *inf_obj;
14923 +  struct inflist_entry *entry;
14924 +  struct cleanup *cleanup;
14925 +
14926 +  if (!inf)
14927 +    {
14928 +      warning (_("Can't create Python Inferior object."));
14929 +      return;
14930 +    }
14931 +
14932 +  cleanup = ensure_python_env (get_current_arch (), current_language);
14933 +
14934 +  inf_obj = PyObject_New (inferior_object, &inferior_object_type);
14935 +  if (!inf_obj)
14936 +    {
14937 +      warning (_("Can't create Python Inferior object."));
14938 +      gdbpy_print_stack ();
14939 +      do_cleanups (cleanup);
14940 +      return;
14941 +    }
14942 +
14943 +  inf_obj->inferior = inf;
14944 +  inf_obj->threads = NULL;
14945 +  inf_obj->nthreads = 0;
14946 +
14947 +  entry = xmalloc (sizeof (struct inflist_entry));
14948 +  entry->inf_obj = inf_obj;
14949 +  entry->next = inferior_list;
14950 +
14951 +  inferior_list = entry;
14952 +
14953 +  ninferiors++;
14954 +
14955 +  do_cleanups (cleanup);
14956 +}
14957 +
14958 +/* An observer callback function that is called when an inferior has
14959 +   been deleted.  Removes the corresponding Python object from the
14960 +   inferior list, and removes the list's reference to the object.  */
14961 +static void
14962 +delete_inferior_object (int pid)
14963 +{
14964 +  PyGILState_STATE state;
14965 +  struct inflist_entry **inf_entry, *inf_tmp;
14966 +  struct threadlist_entry *th_entry, *th_tmp;
14967 +
14968 +  /* Find inferior_object for the given PID.  */
14969 +  for (inf_entry = &inferior_list; *inf_entry != NULL;
14970 +       inf_entry = &(*inf_entry)->next)
14971 +    if ((*inf_entry)->inf_obj->inferior->pid == pid)
14972 +      break;
14973 +
14974 +  if (!*inf_entry)
14975 +    return;
14976 +
14977 +  state = PyGILState_Ensure ();
14978 +
14979 +  inf_tmp = *inf_entry;
14980 +  inf_tmp->inf_obj->inferior = NULL;
14981 +
14982 +  /* Deallocate threads list.  */
14983 +  for (th_entry = inf_tmp->inf_obj->threads; th_entry != NULL;)
14984 +    {
14985 +      Py_DECREF (th_entry->thread_obj);
14986 +
14987 +      th_tmp = th_entry;
14988 +      th_entry = th_entry->next;
14989 +      xfree (th_tmp);
14990 +    }
14991 +
14992 +  inf_tmp->inf_obj->nthreads = 0;
14993 +
14994 +  *inf_entry = (*inf_entry)->next;
14995 +  Py_DECREF (inf_tmp->inf_obj);
14996 +  xfree (inf_tmp);
14997 +
14998 +  ninferiors--;
14999 +
15000 +  PyGILState_Release (state);
15001 +}
15002 +
15003 +/* Finds the Python Inferior object for the given pid.  Returns a borrowed
15004 +   reference.  */
15005 +PyObject *
15006 +find_inferior_object (int pid)
15007 +{
15008 +  struct inflist_entry *p;
15009 +
15010 +  for (p = inferior_list; p != NULL; p = p->next)
15011 +    if (p->inf_obj->inferior->pid == pid)
15012 +      return (PyObject *) p->inf_obj;
15013 +
15014 +  return NULL;
15015 +}
15016 +
15017 +/* Finds the Python InferiorThread object for the given ptid.  Returns a
15018 +   borrowed reference.  */
15019 +thread_object *
15020 +find_thread_object (ptid_t ptid)
15021 +{
15022 +  int pid;
15023 +  struct inflist_entry *p;
15024 +  struct threadlist_entry *q;
15025 +
15026 +  pid = PIDGET (ptid);
15027 +  for (p = inferior_list; p != NULL; p = p->next)
15028 +    if (p->inf_obj->inferior->pid == pid)
15029 +      for (q = p->inf_obj->threads; q != NULL; q = q->next)
15030 +       if (ptid_equal (q->thread_obj->thread->ptid, ptid))
15031 +         return q->thread_obj;
15032 +
15033 +  return NULL;
15034 +}
15035 +
15036 +\f
15037 +
15038 +/* Inferior object.  */
15039 +
15040 +static void
15041 +add_thread_object (struct thread_info *tp)
15042 +{
15043 +  PyGILState_STATE state;
15044 +  thread_object *thread_obj;
15045 +  inferior_object *inf_obj;
15046 +  struct threadlist_entry *entry;
15047 +
15048 +  state = PyGILState_Ensure ();
15049 +
15050 +  thread_obj = create_thread_object (tp);
15051 +  if (!thread_obj)
15052 +    {
15053 +      warning (_("Can't create Python InferiorThread object."));
15054 +      gdbpy_print_stack ();
15055 +      PyGILState_Release (state);
15056 +      return;
15057 +    }
15058 +
15059 +  inf_obj = (inferior_object *) thread_obj->inf_obj;
15060 +
15061 +  entry = xmalloc (sizeof (struct threadlist_entry));
15062 +  entry->thread_obj = thread_obj;
15063 +  entry->next = inf_obj->threads;
15064 +
15065 +  inf_obj->threads = entry;
15066 +  inf_obj->nthreads++;
15067 +
15068 +  PyGILState_Release (state);
15069 +}
15070 +
15071 +static void
15072 +delete_thread_object (struct thread_info *tp, int ignore)
15073 +{
15074 +  PyGILState_STATE state;
15075 +  inferior_object *inf_obj;
15076 +  thread_object *thread_obj;
15077 +  struct threadlist_entry **entry, *tmp;
15078 +
15079 +  inf_obj = (inferior_object *) find_inferior_object (PIDGET(tp->ptid));
15080 +  if (!inf_obj)
15081 +    return;
15082 +
15083 +  /* Find thread entry in its inferior's thread_list.  */
15084 +  for (entry = &inf_obj->threads; *entry != NULL; entry = &(*entry)->next)
15085 +    if ((*entry)->thread_obj->thread == tp)
15086 +      break;
15087 +
15088 +  if (!*entry)
15089 +    return;
15090 +
15091 +  state = PyGILState_Ensure ();
15092 +
15093 +  tmp = *entry;
15094 +  tmp->thread_obj->thread = NULL;
15095 +
15096 +  *entry = (*entry)->next;
15097 +  inf_obj->nthreads--;
15098 +
15099 +  Py_DECREF (tmp->thread_obj);
15100 +  xfree (tmp);
15101 +
15102 +
15103 +  PyGILState_Release (state);
15104 +}
15105 +
15106 +static PyObject *
15107 +infpy_threads (PyObject *self, PyObject *args)
15108 +{
15109 +  int i;
15110 +  struct threadlist_entry *entry;
15111 +  inferior_object *inf_obj = (inferior_object *) self;
15112 +  PyObject *tuple;
15113 +
15114 +  INFPY_REQUIRE_VALID (inf_obj);
15115 +
15116 +
15117 +  tuple = PyTuple_New (inf_obj->nthreads);
15118 +  if (!tuple)
15119 +    return NULL;
15120 +
15121 +  /* The list is in reverse order of thread age (i.e., newest comes first),
15122 +     is this a problem?  */
15123 +  for (i = 0, entry = inf_obj->threads; i < inf_obj->nthreads;
15124 +       i++, entry = entry->next)
15125 +    {
15126 +      Py_INCREF (entry->thread_obj);
15127 +      PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->thread_obj);
15128 +    }
15129 +
15130 +  return tuple;
15131 +}
15132 +
15133 +static PyObject *
15134 +infpy_get_num (PyObject *self, void *closure)
15135 +{
15136 +  inferior_object *inf = (inferior_object *) self;
15137 +
15138 +  INFPY_REQUIRE_VALID (inf);
15139 +
15140 +  return PyLong_FromLong (inf->inferior->num);
15141 +}
15142 +
15143 +static PyObject *
15144 +infpy_get_pid (PyObject *self, void *closure)
15145 +{
15146 +  inferior_object *inf = (inferior_object *) self;
15147 +
15148 +  INFPY_REQUIRE_VALID (inf);
15149 +
15150 +  return PyLong_FromLong (inf->inferior->pid);
15151 +}
15152 +
15153 +static PyObject *
15154 +infpy_get_was_attached (PyObject *self, void *closure)
15155 +{
15156 +  inferior_object *inf = (inferior_object *) self;
15157 +  INFPY_REQUIRE_VALID (inf);
15158 +  if (inf->inferior->attach_flag)
15159 +    Py_RETURN_TRUE;
15160 +  Py_RETURN_FALSE;
15161 +}
15162 +
15163 +\f
15164 +
15165 +/* Implementation of gdb.inferiors () -> (gdb.Inferior, ...).
15166 +   Returns a list of all inferiors.  */
15167 +
15168 +PyObject *
15169 +gdbpy_inferiors (PyObject *unused, PyObject *unused2)
15170 +{
15171 +  int i;
15172 +  struct inflist_entry *entry;
15173 +  PyObject *tuple;
15174 +
15175 +  tuple = PyTuple_New (ninferiors);
15176 +  if (!tuple)
15177 +    return NULL;
15178 +
15179 +  /* The list is in reverse order of inferior age (i.e., newest comes first),
15180 +     is this a problem?  */
15181 +  for (i = 0, entry = inferior_list; i < ninferiors; i++, entry = entry->next)
15182 +    {
15183 +      Py_INCREF (entry->inf_obj);
15184 +      PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->inf_obj);
15185 +    }
15186 +
15187 +  return tuple;
15188 +}
15189 +
15190 +\f
15191 +
15192 +/* Membuf and memory manipulation.  */
15193 +
15194 +/* Implementation of gdb.read_memory (address, length).
15195 +   Returns a Python buffer object with LENGTH bytes of the inferior's memory
15196 +   at ADDRESS. Both arguments are integers.  */
15197 +
15198 +static PyObject *
15199 +infpy_read_memory (PyObject *self, PyObject *args)
15200 +{
15201 +  int error = 0;
15202 +  CORE_ADDR addr, length;
15203 +  void *buffer = NULL;
15204 +  membuf_object *membuf_obj;
15205 +  PyObject *addr_obj, *length_obj;
15206 +  struct cleanup *cleanups;
15207 +  volatile struct gdb_exception except;
15208 +
15209 +  if (! PyArg_ParseTuple (args, "OO", &addr_obj, &length_obj))
15210 +    return NULL;
15211 +
15212 +  cleanups = make_cleanup (null_cleanup, NULL);
15213 +
15214 +  TRY_CATCH (except, RETURN_MASK_ALL)
15215 +    {
15216 +      if (!get_addr_from_python (addr_obj, &addr)
15217 +         || !get_addr_from_python (length_obj, &length))
15218 +       {
15219 +         error = 1;
15220 +         break;
15221 +       }
15222 +
15223 +      buffer = xmalloc (length);
15224 +      make_cleanup (xfree, buffer);
15225 +
15226 +      read_memory (addr, buffer, length);
15227 +    }
15228 +  GDB_PY_HANDLE_EXCEPTION (except);
15229 +
15230 +  if (error)
15231 +    {
15232 +      do_cleanups (cleanups);
15233 +      return NULL;
15234 +    }
15235 +
15236 +  membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
15237 +  if (membuf_obj == NULL)
15238 +    {
15239 +      PyErr_SetString (PyExc_MemoryError,
15240 +                      "Could not allocate memory buffer object.");
15241 +      do_cleanups (cleanups);
15242 +      return NULL;
15243 +    }
15244 +
15245 +  discard_cleanups (cleanups);
15246 +
15247 +  membuf_obj->buffer = buffer;
15248 +  membuf_obj->addr = addr;
15249 +  membuf_obj->length = length;
15250 +
15251 +  return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
15252 +                                      Py_END_OF_BUFFER);
15253 +}
15254 +
15255 +/* Implementation of gdb.write_memory (address, buffer [, length]).
15256 +   Writes the contents of BUFFER (a Python object supporting the read buffer
15257 +   protocol) at ADDRESS in the inferior's memory.  Write LENGTH bytes from
15258 +   BUFFER, or its entire contents if the argument is not provided.  The
15259 +   function returns nothing.  */
15260 +
15261 +static PyObject *
15262 +infpy_write_memory (PyObject *self, PyObject *args)
15263 +{
15264 +  int buf_len, error = 0;
15265 +  const char *buffer;
15266 +  CORE_ADDR addr, length;
15267 +  PyObject *addr_obj, *length_obj = NULL;
15268 +  volatile struct gdb_exception except;
15269 +
15270 +  if (! PyArg_ParseTuple (args, "Os#|O", &addr_obj, &buffer, &buf_len,
15271 +                         &length_obj))
15272 +    return NULL;
15273 +
15274 +  TRY_CATCH (except, RETURN_MASK_ALL)
15275 +    {
15276 +      if (!get_addr_from_python (addr_obj, &addr))
15277 +       {
15278 +         error = 1;
15279 +         break;
15280 +       }
15281 +      
15282 +      if (!length_obj)
15283 +       length = buf_len;
15284 +      else if (!get_addr_from_python (length_obj, &length))
15285 +       {
15286 +         error = 1;
15287 +         break;
15288 +       }
15289 +
15290 +      write_memory (addr, buffer, length);
15291 +    }
15292 +  GDB_PY_HANDLE_EXCEPTION (except);
15293 +
15294 +  if (error)
15295 +    return NULL;
15296 +
15297 +  Py_RETURN_NONE;
15298 +}
15299 +
15300 +/* Destructor of Membuf objects.  */
15301 +
15302 +static void
15303 +mbpy_dealloc (PyObject *self)
15304 +{
15305 +  xfree (((membuf_object *) self)->buffer);
15306 +  self->ob_type->tp_free (self);
15307 +}
15308 +
15309 +/* Return a description of the Membuf object.  */
15310 +
15311 +static PyObject *
15312 +mbpy_str (PyObject *self)
15313 +{
15314 +  membuf_object *membuf_obj = (membuf_object *) self;
15315 +
15316 +  return PyString_FromFormat ("memory buffer for address %s, %s bytes long",
15317 +                             paddress (python_gdbarch, membuf_obj->addr),
15318 +                             pulongest (membuf_obj->length));
15319 +}
15320 +
15321 +static Py_ssize_t
15322 +get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
15323 +{
15324 +  membuf_object *membuf_obj = (membuf_object *) self;
15325 +
15326 +  if (segment)
15327 +    {
15328 +      PyErr_SetString (PyExc_SystemError,
15329 +                      "The memory buffer supports only one segment.");
15330 +      return -1;
15331 +    }
15332 +
15333 +  *ptrptr = membuf_obj->buffer;
15334 +
15335 +  return membuf_obj->length;
15336 +}
15337 +
15338 +static Py_ssize_t
15339 +get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
15340 +{
15341 +  return get_read_buffer (self, segment, ptrptr);
15342 +}
15343 +
15344 +static Py_ssize_t
15345 +get_seg_count (PyObject *self, Py_ssize_t *lenp)
15346 +{
15347 +  if (lenp)
15348 +    *lenp = ((membuf_object *) self)->length;
15349 +
15350 +  return 1;
15351 +}
15352 +
15353 +static Py_ssize_t
15354 +get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
15355 +{
15356 +  void *ptr = NULL;
15357 +  Py_ssize_t ret;
15358 +
15359 +  ret = get_read_buffer (self, segment, &ptr);
15360 +  *ptrptr = (char *) ptr;
15361 +
15362 +  return ret;
15363 +}
15364 +
15365 +/* Adds GDB value V to the pattern buffer in *PATTERN_BUF.  If SIZE is not zero,
15366 +   it specifies the number of bytes from V to copy to *PATTERN_BUF.  The
15367 +   function increases the size of *PATTERN_BUF as necessary, adjusting
15368 +   *PATTERN_BUF_END and *PATTERN_BUF_SIZE in the process.  */
15369 +
15370 +static void
15371 +add_value_pattern (struct value *v, int size, char **pattern_buf,
15372 +                  char **pattern_buf_end, ULONGEST *pattern_buf_size)
15373 +{
15374 +  int val_bytes;
15375 +
15376 +  if (size)
15377 +    {
15378 +      LONGEST x = value_as_long (v);
15379 +
15380 +      if (size == 1)
15381 +       *(*pattern_buf_end)++ = x;
15382 +      else
15383 +       {
15384 +         put_bits (x, *pattern_buf_end, size * 8,
15385 +                   gdbarch_byte_order (python_gdbarch) == BFD_ENDIAN_BIG);
15386 +         *pattern_buf_end += size;
15387 +       }
15388 +    }
15389 +  else
15390 +   {
15391 +     val_bytes = TYPE_LENGTH (value_type (v));
15392 +
15393 +     increase_pattern_buffer (pattern_buf, pattern_buf_end,
15394 +                             pattern_buf_size, val_bytes);
15395 +
15396 +     memcpy (*pattern_buf_end, value_contents_raw (v), val_bytes);
15397 +     *pattern_buf_end += val_bytes;
15398 +   }
15399 +}
15400 +
15401 +/* This function does the actual work of constructing the pattern buffer from
15402 +   OBJ.  If OBJ is an object which implements the read buffer protocol (such
15403 +   as a string, a byte array or gdb.Membuf), then its contents are directly
15404 +   copied to *PATTERN_BUF.  If it is a list, then this function is recursively
15405 +   called for each of its elements.  If OBJ is an object which can be converted
15406 +   to a GDB value, then the contents of the value are copied to PATTERN_BUF.
15407 +   If SIZE is different than zero, then it limits the number of bytes which
15408 +   are copied to the buffer in case OBJ is converted to a GDB value.  That
15409 +   means that SIZE influences only Python scalars and gdb.Value objects.
15410 +   The function increases the size of *PATTERN_BUF as necessary, adjusting
15411 +   *PATTERN_BUF_END and *PATTERN_BUF_SIZE in the process.
15412 +
15413 +   Returns 1 on success or 0 on failure, with a Python exception set.  This
15414 +   function can also throw GDB exceptions.  */
15415 +
15416 +static int
15417 +add_pattern_element (PyObject *obj, int size, char **pattern_buf,
15418 +                    char **pattern_buf_end, ULONGEST *pattern_buf_size)
15419 +{
15420 +  if (PyObject_CheckReadBuffer (obj))
15421 +    {
15422 +      /* Handle string, Unicode string, byte array, gdb.Membuf and any other
15423 +         object implementing the buffer protocol.  The SIZE parameter is
15424 +        ignored in this case.  */
15425 +
15426 +      Py_ssize_t val_bytes;
15427 +      const void *buffer;
15428 +
15429 +      if (PyObject_AsReadBuffer (obj, &buffer, &val_bytes) == -1)
15430 +       return 0;
15431 +
15432 +      increase_pattern_buffer (pattern_buf, pattern_buf_end,
15433 +                              pattern_buf_size, val_bytes);
15434 +
15435 +      memcpy (*pattern_buf_end, buffer, val_bytes);
15436 +      *pattern_buf_end += val_bytes;
15437 +    }
15438 +  else if (gdbpy_is_value_object (obj))
15439 +    add_value_pattern (value_object_to_value (obj), size, pattern_buf,
15440 +                      pattern_buf_end, pattern_buf_size);
15441 +  else if (PySequence_Check (obj))
15442 +    {
15443 +      /* Handle lists and tuples.  */
15444 +
15445 +      Py_ssize_t i, num_objs;
15446 +
15447 +      num_objs = PySequence_Size (obj);
15448 +      for (i = 0; i < num_objs; i++)
15449 +       if (!add_pattern_element (PySequence_GetItem (obj, i), size,
15450 +                                 pattern_buf, pattern_buf_end,
15451 +                                 pattern_buf_size))
15452 +         return 0;
15453 +    }
15454 +  else
15455 +    {
15456 +      /* See if we can convert from a Python object to a GDB value.  */
15457 +
15458 +      struct value *v = convert_value_from_python (obj);
15459 +
15460 +      if (v)
15461 +       add_value_pattern (v, size, pattern_buf, pattern_buf_end,
15462 +                          pattern_buf_size);
15463 +      else
15464 +       return 0;
15465 +    }
15466 +
15467 +  return 1;
15468 +}
15469 +
15470 +/* Constructs the search pattern from OBJ, putting it in *PATTERN_BUFP, and its
15471 +   size in *PATTERN_LENP.  See the function add_pattern_element to learn how
15472 +   the search pattern is obtained from OBJ.
15473 +
15474 +   Returns 1 on success or 0 on failure, with a Python exception set.  This
15475 +   function can also throw GDB exceptions.  */
15476 +
15477 +static int
15478 +get_search_pattern (PyObject *obj, int size, char **pattern_bufp,
15479 +                   ULONGEST *pattern_lenp)
15480 +{
15481 +  /* Buffer to hold the search pattern.  */
15482 +  char *pattern_buf;
15483 +  /* Current size of search pattern buffer.
15484 +     We realloc space as needed.  */
15485 +  ULONGEST pattern_buf_size;
15486 +  /* Pointer to one past the last in-use part of pattern_buf.  */
15487 +  char *pattern_buf_end;
15488 +  struct cleanup *old_cleanups;
15489 +
15490 +  allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
15491 +  old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
15492 +
15493 +  if (!add_pattern_element (obj, size, &pattern_buf, &pattern_buf_end,
15494 +                           &pattern_buf_size))
15495 +    {
15496 +      do_cleanups (old_cleanups);
15497 +
15498 +      return 0;
15499 +    }
15500 +
15501 +  *pattern_bufp = pattern_buf;
15502 +  *pattern_lenp = pattern_buf_end - pattern_buf;
15503 +
15504 +  discard_cleanups (old_cleanups);
15505 +
15506 +  return 1;
15507 +}
15508 +
15509 +/* Implementation of
15510 +   gdb.search_memory (address, length, pattern [, size] [, max_count]).
15511 +   The third argument may be either a pattern, or a list or tupple of patterns
15512 +   to be searched.  Size is the size in bytes of each search query value, either
15513 +   1, 2, 4 or 8.  Returns a list of the addresses where matches were found.  */
15514 +
15515 +static PyObject *
15516 +infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
15517 +{
15518 +  int size = 0;
15519 +  unsigned int found_count = 0;
15520 +  long max_count = 0;
15521 +  CORE_ADDR start_addr, length;
15522 +  char *pattern_buf;
15523 +  static char *keywords[] = { "address", "length", "pattern", "size",
15524 +                             "max_count", NULL };
15525 +  ULONGEST pattern_len, search_space_len;
15526 +  PyObject *pattern, *list = NULL, *start_addr_obj, *length_obj;
15527 +  volatile struct gdb_exception except;
15528 +
15529 +  if (! PyArg_ParseTupleAndKeywords (args, kw, "OOO|il", keywords,
15530 +                                    &start_addr_obj, &length_obj, &pattern,
15531 +                                    &size, &max_count))
15532 +    return NULL;
15533 +
15534 +  if (!max_count)
15535 +    max_count = LONG_MAX;
15536 +
15537 +  if (size != 0 && size != 1 && size != 2 && size != 4 && size != 8)
15538 +    {
15539 +      PyErr_SetString (PyExc_ValueError, "invalid pattern size");
15540 +      return NULL;
15541 +    }
15542 +
15543 +  TRY_CATCH (except, RETURN_MASK_ALL)
15544 +    {
15545 +      if (get_addr_from_python (start_addr_obj, &start_addr)
15546 +         && get_addr_from_python (length_obj, &length))
15547 +       {
15548 +         if (!length)
15549 +           {
15550 +             PyErr_SetString (PyExc_ValueError, "empty search range");
15551 +             break;
15552 +           }
15553 +         /* Watch for overflows.  */
15554 +         else if (length > CORE_ADDR_MAX
15555 +                  || (start_addr + length - 1) < start_addr)
15556 +           {
15557 +             PyErr_SetString (PyExc_ValueError, "search range too large");
15558 +             break;
15559 +           }
15560 +
15561 +         search_space_len = length;
15562 +
15563 +         if (get_search_pattern (pattern, size, &pattern_buf, &pattern_len))
15564 +           {
15565 +             /* Any cleanups get automatically executed on an exception.  */
15566 +             struct cleanup *cleanups = make_cleanup (xfree, pattern_buf);
15567 +
15568 +             list = PyList_New (0);
15569 +
15570 +             while (search_space_len >= pattern_len && found_count < max_count)
15571 +               {
15572 +                 CORE_ADDR found_addr;
15573 +                 int found;
15574 +
15575 +                 found = search_memory (&start_addr, &search_space_len,
15576 +                                        pattern_buf, pattern_len, &found_addr);
15577 +                 if (found <= 0)
15578 +                   break;
15579 +
15580 +                 PyList_Append (list, PyLong_FromUnsignedLong (found_addr));
15581 +                 ++found_count;
15582 +               }
15583 +
15584 +             do_cleanups (cleanups);
15585 +           }
15586 +       }
15587 +    }
15588 +  GDB_PY_HANDLE_EXCEPTION (except);
15589 +
15590 +  return list;
15591 +}
15592 +
15593 +\f
15594 +
15595 +void
15596 +gdbpy_initialize_inferior (void)
15597 +{
15598 +  if (PyType_Ready (&inferior_object_type) < 0)
15599 +    return;
15600 +
15601 +  Py_INCREF (&inferior_object_type);
15602 +  PyModule_AddObject (gdb_module, "Inferior",
15603 +                     (PyObject *) &inferior_object_type);
15604 +
15605 +  inferior_list = NULL;
15606 +  ninferiors = 0;
15607 +
15608 +  observer_attach_new_inferior (add_inferior_object);
15609 +  observer_attach_inferior_exit (delete_inferior_object);
15610 +  observer_attach_new_thread (add_thread_object);
15611 +  observer_attach_thread_exit (delete_thread_object);
15612 +
15613 +  if (PyType_Ready (&membuf_object_type) < 0)
15614 +    return;
15615 +
15616 +  Py_INCREF (&membuf_object_type);
15617 +  PyModule_AddObject (gdb_module, "Membuf", (PyObject *) &membuf_object_type);
15618 +}
15619 +
15620 +\f
15621 +
15622 +static PyGetSetDef inferior_object_getset[] =
15623 +{
15624 +  { "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL },
15625 +  { "pid", infpy_get_pid, NULL, "PID of inferior, as assigned by the OS.",
15626 +    NULL },
15627 +  { "was_attached", infpy_get_was_attached, NULL,
15628 +    "True if the inferior was created using 'attach'.", NULL },
15629 +
15630 +  { NULL }
15631 +};
15632 +
15633 +static PyMethodDef inferior_object_methods[] =
15634 +{
15635 +  { "threads", infpy_threads, METH_NOARGS,
15636 +    "Return all the threads of this inferior." },
15637 +
15638 +  { "read_memory", infpy_read_memory, METH_VARARGS,
15639 +    "read_memory (address, length) -> buffer\n\
15640 +Return a buffer object for reading from the inferior's memory." },
15641 +  { "write_memory", infpy_write_memory, METH_VARARGS,
15642 +    "write_memory (address, buffer [, length])\n\
15643 +Write the given buffer object to the inferior's memory." },
15644 +  { "search_memory", (PyCFunction) infpy_search_memory, METH_VARARGS | METH_KEYWORDS,
15645 +    "search_memory (address, length, pattern [, size] [, max_count]) -> list\n\
15646 +Return a list with the addresses where matches were found." },
15647 +
15648 +  { NULL }
15649 +};
15650 +
15651 +static PyTypeObject inferior_object_type =
15652 +{
15653 +  PyObject_HEAD_INIT (NULL)
15654 +  0,                             /* ob_size */
15655 +  "gdb.Inferior",                /* tp_name */
15656 +  sizeof (inferior_object),      /* tp_basicsize */
15657 +  0,                             /* tp_itemsize */
15658 +  0,                             /* tp_dealloc */
15659 +  0,                             /* tp_print */
15660 +  0,                             /* tp_getattr */
15661 +  0,                             /* tp_setattr */
15662 +  0,                             /* tp_compare */
15663 +  0,                             /* tp_repr */
15664 +  0,                             /* tp_as_number */
15665 +  0,                             /* tp_as_sequence */
15666 +  0,                             /* tp_as_mapping */
15667 +  0,                             /* tp_hash  */
15668 +  0,                             /* tp_call */
15669 +  0,                             /* tp_str */
15670 +  0,                             /* tp_getattro */
15671 +  0,                             /* tp_setattro */
15672 +  0,                             /* tp_as_buffer */
15673 +  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /* tp_flags */
15674 +  "GDB inferior object",         /* tp_doc */
15675 +  0,                             /* tp_traverse */
15676 +  0,                             /* tp_clear */
15677 +  0,                             /* tp_richcompare */
15678 +  0,                             /* tp_weaklistoffset */
15679 +  0,                             /* tp_iter */
15680 +  0,                             /* tp_iternext */
15681 +  inferior_object_methods,       /* tp_methods */
15682 +  0,                             /* tp_members */
15683 +  inferior_object_getset,        /* tp_getset */
15684 +  0,                             /* tp_base */
15685 +  0,                             /* tp_dict */
15686 +  0,                             /* tp_descr_get */
15687 +  0,                             /* tp_descr_set */
15688 +  0,                             /* tp_dictoffset */
15689 +  0,                             /* tp_init */
15690 +  0                              /* tp_alloc */
15691 +};
15692 +
15693 +\f
15694 +
15695 +/* Python doesn't provide a decent way to get compatibility here.  */
15696 +#if HAVE_LIBPYTHON2_4
15697 +#define CHARBUFFERPROC_NAME getcharbufferproc
15698 +#else
15699 +#define CHARBUFFERPROC_NAME charbufferproc
15700 +#endif
15701 +
15702 +static PyBufferProcs buffer_procs = {
15703 +  get_read_buffer,
15704 +  get_write_buffer,
15705 +  get_seg_count,
15706 +  /* The cast here works around a difference between Python 2.4 and
15707 +     Python 2.5.  */
15708 +  (CHARBUFFERPROC_NAME) get_char_buffer
15709 +};
15710 +
15711 +static PyTypeObject membuf_object_type = {
15712 +  PyObject_HEAD_INIT (NULL)
15713 +  0,                             /*ob_size*/
15714 +  "gdb.Membuf",                          /*tp_name*/
15715 +  sizeof (membuf_object),        /*tp_basicsize*/
15716 +  0,                             /*tp_itemsize*/
15717 +  mbpy_dealloc,                          /*tp_dealloc*/
15718 +  0,                             /*tp_print*/
15719 +  0,                             /*tp_getattr*/
15720 +  0,                             /*tp_setattr*/
15721 +  0,                             /*tp_compare*/
15722 +  0,                             /*tp_repr*/
15723 +  0,                             /*tp_as_number*/
15724 +  0,                             /*tp_as_sequence*/
15725 +  0,                             /*tp_as_mapping*/
15726 +  0,                             /*tp_hash */
15727 +  0,                             /*tp_call*/
15728 +  mbpy_str,                      /*tp_str*/
15729 +  0,                             /*tp_getattro*/
15730 +  0,                             /*tp_setattro*/
15731 +  &buffer_procs,                 /*tp_as_buffer*/
15732 +  Py_TPFLAGS_DEFAULT,            /*tp_flags*/
15733 +  "GDB memory buffer object",    /*tp_doc*/
15734 +  0,                             /* tp_traverse */
15735 +  0,                             /* tp_clear */
15736 +  0,                             /* tp_richcompare */
15737 +  0,                             /* tp_weaklistoffset */
15738 +  0,                             /* tp_iter */
15739 +  0,                             /* tp_iternext */
15740 +  0,                             /* tp_methods */
15741 +  0,                             /* tp_members */
15742 +  0,                             /* tp_getset */
15743 +  0,                             /* tp_base */
15744 +  0,                             /* tp_dict */
15745 +  0,                             /* tp_descr_get */
15746 +  0,                             /* tp_descr_set */
15747 +  0,                             /* tp_dictoffset */
15748 +  0,                             /* tp_init */
15749 +  0,                             /* tp_alloc */
15750 +  PyType_GenericNew              /* tp_new */
15751 +};
15752 diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
15753 new file mode 100644
15754 index 0000000..21e4eab
15755 --- /dev/null
15756 +++ b/gdb/python/py-infthread.c
15757 @@ -0,0 +1,285 @@
15758 +/* Python interface to inferior threads.
15759 +
15760 +   Copyright (C) 2009 Free Software Foundation, Inc.
15761 +
15762 +   This file is part of GDB.
15763 +
15764 +   This program is free software; you can redistribute it and/or modify
15765 +   it under the terms of the GNU General Public License as published by
15766 +   the Free Software Foundation; either version 3 of the License, or
15767 +   (at your option) any later version.
15768 +
15769 +   This program is distributed in the hope that it will be useful,
15770 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
15771 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15772 +   GNU General Public License for more details.
15773 +
15774 +   You should have received a copy of the GNU General Public License
15775 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
15776 +
15777 +#include "defs.h"
15778 +#include "exceptions.h"
15779 +#include "gdbthread.h"
15780 +#include "inferior.h"
15781 +#include "python-internal.h"
15782 +
15783 +static PyTypeObject thread_object_type;
15784 +
15785 +/* Require that INFERIOR be a valid inferior ID.  */
15786 +#define THPY_REQUIRE_VALID(Thread)                             \
15787 +  do {                                                         \
15788 +    if (!Thread->thread)                                       \
15789 +      {                                                                \
15790 +       PyErr_SetString (PyExc_RuntimeError,                    \
15791 +                        "thread no longer exists");            \
15792 +       return NULL;                                            \
15793 +      }                                                                \
15794 +  } while (0)
15795 +
15796 +\f
15797 +
15798 +thread_object *
15799 +create_thread_object (struct thread_info *tp)
15800 +{
15801 +  thread_object *thread_obj;
15802 +  
15803 +  thread_obj = PyObject_New (thread_object, &thread_object_type);
15804 +  if (!thread_obj)
15805 +    return NULL;
15806 +
15807 +  thread_obj->thread = tp;
15808 +  thread_obj->inf_obj = find_inferior_object (PIDGET (tp->ptid));
15809 +  Py_INCREF (thread_obj->inf_obj);
15810 +
15811 +  return thread_obj;
15812 +}
15813 +
15814 +\f
15815 +
15816 +static void
15817 +thpy_dealloc (PyObject *self)
15818 +{
15819 +  Py_DECREF (((thread_object *) self)->inf_obj);
15820 +  self->ob_type->tp_free (self);
15821 +}
15822 +
15823 +static PyObject *
15824 +thpy_get_num (PyObject *self, void *closure)
15825 +{
15826 +  thread_object *thread_obj = (thread_object *) self;
15827 +
15828 +  THPY_REQUIRE_VALID (thread_obj);
15829 +
15830 +  return PyLong_FromLong (thread_obj->thread->num);
15831 +}
15832 +
15833 +\f
15834 +
15835 +/* Implementation of Inferior.frames () -> (gdb.Frame, ...).
15836 +   Returns a tuple of all frame objects.  */
15837 +PyObject *
15838 +thpy_frames (PyObject *self, PyObject *args)
15839 +{
15840 +  int result = 0;
15841 +  struct frame_info *frame;
15842 +  PyObject *frame_obj;
15843 +  PyObject *list, *tuple;
15844 +  thread_object *thread_obj = (thread_object *) self;
15845 +  struct cleanup *cleanup;
15846 +  volatile struct gdb_exception except;
15847 +
15848 +  THPY_REQUIRE_VALID (thread_obj);
15849 +
15850 +  list = PyList_New (0);
15851 +  if (list == NULL)
15852 +    {
15853 +      PyErr_SetString (PyExc_MemoryError, "Could not allocate frames list.");
15854 +      return NULL;
15855 +    }
15856 +
15857 +  cleanup = make_cleanup_restore_current_thread ();
15858 +
15859 +  TRY_CATCH (except, RETURN_MASK_ALL)
15860 +    {
15861 +      switch_to_thread (thread_obj->thread->ptid);
15862 +
15863 +      for (frame = get_current_frame (); frame; frame = get_prev_frame (frame))
15864 +       {
15865 +         frame_obj = frame_info_to_frame_object (frame);
15866 +         if (frame_obj == NULL)
15867 +           {
15868 +             Py_DECREF (list);
15869 +             list = NULL;
15870 +             break;
15871 +           }
15872 +
15873 +         PyList_Append (list, frame_obj);
15874 +       }
15875 +    }
15876 +  if (except.reason < 0)
15877 +    {
15878 +      Py_DECREF (list);
15879 +      return PyErr_Format (except.reason == RETURN_QUIT
15880 +                          ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
15881 +                          "%s", except.message);
15882 +    }
15883 +
15884 +  do_cleanups (cleanup);
15885 +
15886 +  if (list)
15887 +    {
15888 +      tuple = PyList_AsTuple (list);
15889 +      Py_DECREF (list);
15890 +    }
15891 +  else
15892 +    tuple = NULL;
15893 +
15894 +  return tuple;
15895 +}
15896 +
15897 +/* Implementation of InferiorThread.newest_frame () -> gdb.Frame.
15898 +   Returns the newest frame object.  */
15899 +PyObject *
15900 +thpy_newest_frame (PyObject *self, PyObject *args)
15901 +{
15902 +  struct frame_info *frame;
15903 +  PyObject *frame_obj = NULL;   /* Initialize to appease gcc warning.  */
15904 +  thread_object *thread_obj = (thread_object *) self;
15905 +  struct cleanup *cleanup;
15906 +  volatile struct gdb_exception except;
15907 +
15908 +  THPY_REQUIRE_VALID (thread_obj);
15909 +
15910 +  cleanup = make_cleanup_restore_current_thread ();
15911 +
15912 +  TRY_CATCH (except, RETURN_MASK_ALL)
15913 +    {
15914 +      switch_to_thread (thread_obj->thread->ptid);
15915 +
15916 +      frame = get_current_frame ();
15917 +      frame_obj = frame_info_to_frame_object (frame);
15918 +    }
15919 +  GDB_PY_HANDLE_EXCEPTION (except);
15920 +
15921 +  do_cleanups (cleanup);
15922 +
15923 +  return frame_obj;
15924 +}
15925 +
15926 +/* Implementation of InferiorThread.switch ().
15927 +   Makes this the GDB selected thread.  */
15928 +static PyObject *
15929 +thpy_switch (PyObject *self, PyObject *args)
15930 +{
15931 +  thread_object *thread_obj = (thread_object *) self;
15932 +  struct cleanup *cleanup;
15933 +  volatile struct gdb_exception except;
15934 +
15935 +  THPY_REQUIRE_VALID (thread_obj);
15936 +
15937 +  TRY_CATCH (except, RETURN_MASK_ALL)
15938 +    {
15939 +      switch_to_thread (thread_obj->thread->ptid);
15940 +    }
15941 +  GDB_PY_HANDLE_EXCEPTION (except);
15942 +
15943 +  Py_RETURN_NONE;
15944 +}
15945 +
15946 +\f
15947 +
15948 +/* Implementation of gdb.selected_thread () -> gdb.InferiorThread.
15949 +   Returns the selected thread object.  */
15950 +PyObject *
15951 +gdbpy_selected_thread (PyObject *self, PyObject *args)
15952 +{
15953 +  PyObject *thread_obj;
15954 +  
15955 +  thread_obj = (PyObject *) find_thread_object (inferior_ptid);
15956 +  if (thread_obj)
15957 +    {
15958 +      Py_INCREF (thread_obj);
15959 +      return thread_obj;
15960 +    }
15961 +
15962 +  Py_RETURN_NONE;
15963 +}
15964 +
15965 +\f
15966 +
15967 +void
15968 +gdbpy_initialize_thread (void)
15969 +{
15970 +  if (PyType_Ready (&thread_object_type) < 0)
15971 +    return;
15972 +
15973 +  Py_INCREF (&thread_object_type);
15974 +  PyModule_AddObject (gdb_module, "InferiorThread",
15975 +                     (PyObject *) &thread_object_type);
15976 +}
15977 +
15978 +\f
15979 +
15980 +static PyGetSetDef thread_object_getset[] =
15981 +{
15982 +  { "num", thpy_get_num, NULL, "ID of the thread, as assigned by GDB.", NULL },
15983 +
15984 +  { NULL }
15985 +};
15986 +
15987 +static PyMethodDef thread_object_methods[] =
15988 +{
15989 +  { "frames", thpy_frames, METH_NOARGS,
15990 +    "frames () -> (gdb.Frame, ...)\n\
15991 +Return a tuple containing all frames in the thread." },
15992 +  { "newest_frame", thpy_newest_frame, METH_NOARGS,
15993 +    "newest_frame () -> gdb.Frame\n\
15994 +Return the newest frame in the thread." },
15995 +  { "switch", thpy_switch, METH_NOARGS,
15996 +    "switch ()\n\
15997 +Makes this the GDB selected thread." },
15998 +
15999 +  { NULL }
16000 +};
16001 +
16002 +static PyTypeObject thread_object_type =
16003 +{
16004 +  PyObject_HEAD_INIT (NULL)
16005 +  0,                             /*ob_size*/
16006 +  "gdb.InferiorThread",                  /*tp_name*/
16007 +  sizeof (thread_object),        /*tp_basicsize*/
16008 +  0,                             /*tp_itemsize*/
16009 +  thpy_dealloc,                          /*tp_dealloc*/
16010 +  0,                             /*tp_print*/
16011 +  0,                             /*tp_getattr*/
16012 +  0,                             /*tp_setattr*/
16013 +  0,                             /*tp_compare*/
16014 +  0,                             /*tp_repr*/
16015 +  0,                             /*tp_as_number*/
16016 +  0,                             /*tp_as_sequence*/
16017 +  0,                             /*tp_as_mapping*/
16018 +  0,                             /*tp_hash */
16019 +  0,                             /*tp_call*/
16020 +  0,                             /*tp_str*/
16021 +  0,                             /*tp_getattro*/
16022 +  0,                             /*tp_setattro*/
16023 +  0,                             /*tp_as_buffer*/
16024 +  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
16025 +  "GDB thread object",           /* tp_doc */
16026 +  0,                             /* tp_traverse */
16027 +  0,                             /* tp_clear */
16028 +  0,                             /* tp_richcompare */
16029 +  0,                             /* tp_weaklistoffset */
16030 +  0,                             /* tp_iter */
16031 +  0,                             /* tp_iternext */
16032 +  thread_object_methods,         /* tp_methods */
16033 +  0,                             /* tp_members */
16034 +  thread_object_getset,                  /* tp_getset */
16035 +  0,                             /* tp_base */
16036 +  0,                             /* tp_dict */
16037 +  0,                             /* tp_descr_get */
16038 +  0,                             /* tp_descr_set */
16039 +  0,                             /* tp_dictoffset */
16040 +  0,                             /* tp_init */
16041 +  0                              /* tp_alloc */
16042 +};
16043 diff --git a/gdb/python/py-membuf.c b/gdb/python/py-membuf.c
16044 new file mode 100644
16045 index 0000000..7bc294c
16046 --- /dev/null
16047 +++ b/gdb/python/py-membuf.c
16048 @@ -0,0 +1,268 @@
16049 +/* Python interface to the inferior memory.
16050 +
16051 +   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
16052 +
16053 +   This file is part of GDB.
16054 +
16055 +   This program is free software; you can redistribute it and/or modify
16056 +   it under the terms of the GNU General Public License as published by
16057 +   the Free Software Foundation; either version 3 of the License, or
16058 +   (at your option) any later version.
16059 +
16060 +   This program is distributed in the hope that it will be useful,
16061 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
16062 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16063 +   GNU General Public License for more details.
16064 +
16065 +   You should have received a copy of the GNU General Public License
16066 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16067 +
16068 +#include "defs.h"
16069 +#include "exceptions.h"
16070 +#include "gdbcore.h"
16071 +#include "python-internal.h"
16072 +
16073 +typedef struct {
16074 +  PyObject_HEAD
16075 +  void *buffer;
16076 +
16077 +  /* These are kept just for mbpy_str.  */
16078 +  CORE_ADDR addr;
16079 +  CORE_ADDR length;
16080 +} membuf_object;
16081 +
16082 +static PyTypeObject membuf_object_type;
16083 +
16084 +/* Implementation of gdb.read_memory (address, length).
16085 +   Returns a Python buffer object with LENGTH bytes of the inferior's memory
16086 +   at ADDRESS. Both arguments are integers.  */
16087 +
16088 +PyObject *
16089 +gdbpy_read_memory (PyObject *self, PyObject *args)
16090 +{
16091 +  int error = 0;
16092 +  CORE_ADDR addr, length;
16093 +  void *buffer = NULL;
16094 +  membuf_object *membuf_obj;
16095 +  PyObject *addr_obj, *length_obj;
16096 +  struct cleanup *cleanups = NULL;
16097 +  volatile struct gdb_exception except;
16098 +
16099 +  if (! PyArg_ParseTuple (args, "OO", &addr_obj, &length_obj))
16100 +    return NULL;
16101 +
16102 +  TRY_CATCH (except, RETURN_MASK_ALL)
16103 +    {
16104 +      if (!get_addr_from_python (addr_obj, &addr)
16105 +         || !get_addr_from_python (length_obj, &length))
16106 +       {
16107 +         error = 1;
16108 +         break;
16109 +       }
16110 +
16111 +      buffer = xmalloc (length);
16112 +      cleanups = make_cleanup (xfree, buffer);
16113 +
16114 +      read_memory (addr, buffer, length);
16115 +    }
16116 +  GDB_PY_HANDLE_EXCEPTION (except);
16117 +
16118 +  if (error)
16119 +    return NULL;
16120 +
16121 +  discard_cleanups (cleanups);
16122 +
16123 +  membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
16124 +  if (membuf_obj == NULL)
16125 +    {
16126 +      xfree (buffer);
16127 +      PyErr_SetString (PyExc_MemoryError,
16128 +                      "Could not allocate memory buffer object.");
16129 +      return NULL;
16130 +    }
16131 +
16132 +  membuf_obj->buffer = buffer;
16133 +  membuf_obj->addr = addr;
16134 +  membuf_obj->length = length;
16135 +
16136 +  return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
16137 +                                      Py_END_OF_BUFFER);
16138 +}
16139 +
16140 +/* Implementation of gdb.write_memory (address, buffer [, length]).
16141 +   Writes the contents of BUFFER (a Python object supporting the read buffer
16142 +   protocol) at ADDRESS in the inferior's memory.  Write LENGTH bytes from
16143 +   BUFFER, or its entire contents if the argument is not provided.  The
16144 +   function returns nothing.  */
16145 +
16146 +PyObject *
16147 +gdbpy_write_memory (PyObject *self, PyObject *args)
16148 +{
16149 +  int buf_len, error = 0;
16150 +  const char *buffer;
16151 +  CORE_ADDR addr, length;
16152 +  PyObject *addr_obj, *length_obj = NULL;
16153 +  volatile struct gdb_exception except;
16154 +
16155 +  if (! PyArg_ParseTuple (args, "Os#|O", &addr_obj, &buffer, &buf_len,
16156 +                         &length_obj))
16157 +    return NULL;
16158 +
16159 +  TRY_CATCH (except, RETURN_MASK_ALL)
16160 +    {
16161 +      if (!get_addr_from_python (addr_obj, &addr))
16162 +       {
16163 +         error = 1;
16164 +         break;
16165 +       }
16166 +      
16167 +      if (!length_obj)
16168 +       length = buf_len;
16169 +      else if (!get_addr_from_python (length_obj, &length))
16170 +       {
16171 +         error = 1;
16172 +         break;
16173 +       }
16174 +
16175 +      write_memory (addr, buffer, length);
16176 +    }
16177 +  GDB_PY_HANDLE_EXCEPTION (except);
16178 +
16179 +  if (error)
16180 +    return NULL;
16181 +
16182 +  Py_RETURN_NONE;
16183 +}
16184 +
16185 +/* Destructor of Membuf objects.  */
16186 +
16187 +static void
16188 +mbpy_dealloc (PyObject *self)
16189 +{
16190 +  xfree (((membuf_object *) self)->buffer);
16191 +  self->ob_type->tp_free (self);
16192 +}
16193 +
16194 +/* Return a description of the Membuf object.  */
16195 +
16196 +static PyObject *
16197 +mbpy_str (PyObject *self)
16198 +{
16199 +  membuf_object *membuf_obj = (membuf_object *) self;
16200 +
16201 +  return PyString_FromFormat ("memory buffer for address %s, %s bytes long",
16202 +                             paddress (membuf_obj->addr),
16203 +                             pulongest (membuf_obj->length));
16204 +}
16205 +
16206 +static Py_ssize_t
16207 +get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
16208 +{
16209 +  membuf_object *membuf_obj = (membuf_object *) self;
16210 +
16211 +  if (segment)
16212 +    {
16213 +      PyErr_SetString (PyExc_SystemError,
16214 +                      "The memory buffer supports only one segment.");
16215 +      return -1;
16216 +    }
16217 +
16218 +  *ptrptr = membuf_obj->buffer;
16219 +
16220 +  return membuf_obj->length;
16221 +}
16222 +
16223 +static Py_ssize_t
16224 +get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
16225 +{
16226 +  return get_read_buffer (self, segment, ptrptr);
16227 +}
16228 +
16229 +static Py_ssize_t
16230 +get_seg_count (PyObject *self, Py_ssize_t *lenp)
16231 +{
16232 +  if (lenp)
16233 +    *lenp = ((membuf_object *) self)->length;
16234 +
16235 +  return 1;
16236 +}
16237 +
16238 +static Py_ssize_t
16239 +get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
16240 +{
16241 +  void *ptr = NULL;
16242 +  Py_ssize_t ret;
16243 +
16244 +  ret = get_read_buffer (self, segment, &ptr);
16245 +  *ptrptr = (char *) ptr;
16246 +
16247 +  return ret;
16248 +}
16249 +
16250 +/* Python doesn't provide a decent way to get compatibility here.  */
16251 +#if HAVE_LIBPYTHON2_4
16252 +#define CHARBUFFERPROC_NAME getcharbufferproc
16253 +#else
16254 +#define CHARBUFFERPROC_NAME charbufferproc
16255 +#endif
16256 +
16257 +static PyBufferProcs buffer_procs = {
16258 +  get_read_buffer,
16259 +  get_write_buffer,
16260 +  get_seg_count,
16261 +  /* The cast here works around a difference between Python 2.4 and
16262 +     Python 2.5.  */
16263 +  (CHARBUFFERPROC_NAME) get_char_buffer
16264 +};
16265 +
16266 +static PyTypeObject membuf_object_type = {
16267 +  PyObject_HEAD_INIT (NULL)
16268 +  0,                             /*ob_size*/
16269 +  "gdb.Membuf",                          /*tp_name*/
16270 +  sizeof (membuf_object),        /*tp_basicsize*/
16271 +  0,                             /*tp_itemsize*/
16272 +  mbpy_dealloc,                          /*tp_dealloc*/
16273 +  0,                             /*tp_print*/
16274 +  0,                             /*tp_getattr*/
16275 +  0,                             /*tp_setattr*/
16276 +  0,                             /*tp_compare*/
16277 +  0,                             /*tp_repr*/
16278 +  0,                             /*tp_as_number*/
16279 +  0,                             /*tp_as_sequence*/
16280 +  0,                             /*tp_as_mapping*/
16281 +  0,                             /*tp_hash */
16282 +  0,                             /*tp_call*/
16283 +  mbpy_str,                      /*tp_str*/
16284 +  0,                             /*tp_getattro*/
16285 +  0,                             /*tp_setattro*/
16286 +  &buffer_procs,                 /*tp_as_buffer*/
16287 +  Py_TPFLAGS_DEFAULT,            /*tp_flags*/
16288 +  "GDB memory buffer object",    /*tp_doc*/
16289 +  0,                             /* tp_traverse */
16290 +  0,                             /* tp_clear */
16291 +  0,                             /* tp_richcompare */
16292 +  0,                             /* tp_weaklistoffset */
16293 +  0,                             /* tp_iter */
16294 +  0,                             /* tp_iternext */
16295 +  0,                             /* tp_methods */
16296 +  0,                             /* tp_members */
16297 +  0,                             /* tp_getset */
16298 +  0,                             /* tp_base */
16299 +  0,                             /* tp_dict */
16300 +  0,                             /* tp_descr_get */
16301 +  0,                             /* tp_descr_set */
16302 +  0,                             /* tp_dictoffset */
16303 +  0,                             /* tp_init */
16304 +  0,                             /* tp_alloc */
16305 +  PyType_GenericNew              /* tp_new */
16306 +};
16307 +
16308 +void
16309 +gdbpy_initialize_membuf (void)
16310 +{
16311 +  if (PyType_Ready (&membuf_object_type) < 0)
16312 +    return;
16313 +
16314 +  Py_INCREF (&membuf_object_type);
16315 +  PyModule_AddObject (gdb_module, "Membuf", (PyObject *) &membuf_object_type);
16316 +}
16317 diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
16318 new file mode 100644
16319 index 0000000..1f591a8
16320 --- /dev/null
16321 +++ b/gdb/python/py-param.c
16322 @@ -0,0 +1,606 @@
16323 +/* gdb parameters implemented in Python
16324 +
16325 +   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
16326 +
16327 +   This file is part of GDB.
16328 +
16329 +   This program is free software; you can redistribute it and/or modify
16330 +   it under the terms of the GNU General Public License as published by
16331 +   the Free Software Foundation; either version 3 of the License, or
16332 +   (at your option) any later version.
16333 +
16334 +   This program is distributed in the hope that it will be useful,
16335 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
16336 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16337 +   GNU General Public License for more details.
16338 +
16339 +   You should have received a copy of the GNU General Public License
16340 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16341 +
16342 +
16343 +#include "defs.h"
16344 +#include "value.h"
16345 +#include "exceptions.h"
16346 +#include "python-internal.h"
16347 +#include "charset.h"
16348 +#include "gdbcmd.h"
16349 +#include "cli/cli-decode.h"
16350 +#include "completer.h"
16351 +
16352 +/* Parameter constants and their values.  */
16353 +struct parm_constant
16354 +{
16355 +  char *name;
16356 +  int value;
16357 +};
16358 +
16359 +struct parm_constant parm_constants[] =
16360 +{
16361 +  { "PARAM_BOOLEAN", var_boolean },
16362 +  { "PARAM_AUTO_BOOLEAN", var_auto_boolean },
16363 +  { "PARAM_UINTEGER", var_uinteger },
16364 +  { "PARAM_INTEGER", var_integer },
16365 +  { "PARAM_STRING", var_string },
16366 +  { "PARAM_STRING_NOESCAPE", var_string_noescape },
16367 +  { "PARAM_OPTIONAL_FILENAME", var_optional_filename },
16368 +  { "PARAM_FILENAME", var_filename },
16369 +  { "PARAM_ZINTEGER", var_zinteger },
16370 +  { "PARAM_ENUM", var_enum },
16371 +  { NULL, 0 }
16372 +};
16373 +
16374 +/* A union that can hold anything described by enum var_types.  */
16375 +union parmpy_variable
16376 +{
16377 +  /* Hold an integer value, for boolean and integer types.  */
16378 +  int intval;
16379 +
16380 +  /* Hold an auto_boolean.  */
16381 +  enum auto_boolean autoboolval;
16382 +
16383 +  /* Hold an unsigned integer value, for uinteger.  */
16384 +  unsigned int uintval;
16385 +
16386 +  /* Hold a string, for the various string types.  */
16387 +  char *stringval;
16388 +
16389 +  /* Hold a string, for enums.  */
16390 +  const char *cstringval;
16391 +};
16392 +
16393 +/* A gdb parameter.  */
16394 +struct parmpy_object
16395 +{
16396 +  PyObject_HEAD
16397 +
16398 +  /* The type of the parameter.  */
16399 +  enum var_types type;
16400 +
16401 +  /* The value of the parameter.  */
16402 +  union parmpy_variable value;
16403 +
16404 +  /* For an enum command, the possible values.  The vector is
16405 +     allocated with xmalloc, as is each element.  It is
16406 +     NULL-terminated.  */
16407 +  const char **enumeration;
16408 +};
16409 +
16410 +typedef struct parmpy_object parmpy_object;
16411 +
16412 +static PyTypeObject parmpy_object_type;
16413 +
16414 +/* Some handy string constants.  */
16415 +static PyObject *set_doc_cst;
16416 +static PyObject *show_doc_cst;
16417 +
16418 +\f
16419 +
16420 +/* Get an attribute.  */
16421 +static PyObject *
16422 +get_attr (PyObject *obj, PyObject *attr_name)
16423 +{
16424 +  if (PyString_Check (attr_name)
16425 +      && ! strcmp (PyString_AsString (attr_name), "value"))
16426 +    {
16427 +      parmpy_object *self = (parmpy_object *) obj;
16428 +      return gdbpy_parameter_value (self->type, &self->value);
16429 +    }
16430 +
16431 +  return PyObject_GenericGetAttr (obj, attr_name);
16432 +}
16433 +
16434 +/* Set a parameter value from a Python value.  Return 0 on success, -1
16435 +   on failure.  */
16436 +static int
16437 +set_parameter_value (parmpy_object *self, PyObject *value)
16438 +{
16439 +  int cmp;
16440 +
16441 +  switch (self->type)
16442 +    {
16443 +    case var_string:
16444 +    case var_string_noescape:
16445 +    case var_optional_filename:
16446 +    case var_filename:
16447 +      if (! gdbpy_is_string (value)
16448 +         && (self->type == var_filename
16449 +             || value != Py_None))
16450 +       {
16451 +         PyErr_SetString (PyExc_RuntimeError, "string required");
16452 +         return -1;
16453 +       }
16454 +      if (self->value.stringval)
16455 +       xfree (self->value.stringval);
16456 +      if (value == Py_None)
16457 +       {
16458 +         if (self->type == var_optional_filename)
16459 +           self->value.stringval = xstrdup ("");
16460 +         else
16461 +           self->value.stringval = NULL;
16462 +       }
16463 +      else
16464 +       self->value.stringval = python_string_to_host_string (value);
16465 +      break;
16466 +
16467 +    case var_enum:
16468 +      {
16469 +       int i;
16470 +       char *str;
16471 +
16472 +       if (! gdbpy_is_string (value))
16473 +         {
16474 +           PyErr_SetString (PyExc_RuntimeError, "string required");
16475 +           return -1;
16476 +         }
16477 +
16478 +       str = python_string_to_host_string (value);
16479 +       for (i = 0; self->enumeration[i]; ++i)
16480 +         if (! strcmp (self->enumeration[i], str))
16481 +           break;
16482 +       xfree (str);
16483 +       if (! self->enumeration[i])
16484 +         {
16485 +           PyErr_SetString (PyExc_RuntimeError,
16486 +                            "value must be member of enumeration");
16487 +           return -1;
16488 +         }
16489 +       self->value.cstringval = self->enumeration[i];
16490 +       break;
16491 +      }
16492 +
16493 +    case var_boolean:
16494 +      if (! PyBool_Check (value))
16495 +       {
16496 +         PyErr_SetString (PyExc_RuntimeError, "boolean required");
16497 +         return -1;
16498 +       }
16499 +      cmp = PyObject_IsTrue (value);
16500 +      if (cmp < 0) 
16501 +         return -1;
16502 +      self->value.intval = cmp;
16503 +      break;
16504 +
16505 +    case var_auto_boolean:
16506 +      if (! PyBool_Check (value) && value != Py_None)
16507 +       {
16508 +         PyErr_SetString (PyExc_RuntimeError,
16509 +                          "boolean or None required");
16510 +         return -1;
16511 +       }
16512 +
16513 +      if (value == Py_None)
16514 +       self->value.autoboolval = AUTO_BOOLEAN_AUTO;
16515 +      else
16516 +       {
16517 +         cmp = PyObject_IsTrue (value);
16518 +         if (cmp < 0 )
16519 +           return -1;    
16520 +         if (cmp == 1)
16521 +           self->value.autoboolval = AUTO_BOOLEAN_TRUE;
16522 +         else 
16523 +           self->value.autoboolval = AUTO_BOOLEAN_FALSE;
16524 +
16525 +         break;
16526 +       }
16527 +
16528 +    case var_integer:
16529 +    case var_zinteger:
16530 +    case var_uinteger:
16531 +      {
16532 +       long l;
16533 +       int ok;
16534 +
16535 +       if (! PyInt_Check (value))
16536 +         {
16537 +           PyErr_SetString (PyExc_RuntimeError, "value must be integer");
16538 +           return -1;
16539 +         }
16540 +
16541 +       l = PyInt_AsLong (value);
16542 +       if (self->type == var_uinteger)
16543 +         {
16544 +           ok = (l >= 0 && l <= UINT_MAX);
16545 +           if (l == 0)
16546 +             l = UINT_MAX;
16547 +         }
16548 +       else if (self->type == var_integer)
16549 +         {
16550 +           ok = (l >= INT_MIN && l <= INT_MAX);
16551 +           if (l == 0)
16552 +             l = INT_MAX;
16553 +         }
16554 +       else
16555 +         ok = (l >= INT_MIN && l <= INT_MAX);
16556 +
16557 +       if (! ok)
16558 +         {
16559 +           PyErr_SetString (PyExc_RuntimeError, "range exceeded");
16560 +           return -1;
16561 +         }
16562 +
16563 +       self->value.intval = (int) l;
16564 +       break;
16565 +      }
16566 +
16567 +    default:
16568 +      PyErr_SetString (PyExc_RuntimeError, "programmer error: unhandled type");
16569 +      return -1;
16570 +    }
16571 +
16572 +  return 0;
16573 +}
16574 +
16575 +/* Set an attribute.  */
16576 +static int
16577 +set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
16578 +{
16579 +  if (PyString_Check (attr_name)
16580 +      && ! strcmp (PyString_AsString (attr_name), "value"))
16581 +    {
16582 +      if (!val)
16583 +       {
16584 +         PyErr_SetString (PyExc_RuntimeError,
16585 +                          "cannot delete a parameter's value");
16586 +         return -1;
16587 +       }
16588 +      return set_parameter_value ((parmpy_object *) obj, val);
16589 +    }
16590 +
16591 +  return PyObject_GenericSetAttr (obj, attr_name, val);
16592 +}
16593 +
16594 +\f
16595 +
16596 +/* A helper function that dispatches to the appropriate add_setshow
16597 +   function.  */
16598 +static void
16599 +add_setshow_generic (int parmclass, enum command_class cmdclass,
16600 +                    char *cmd_name, parmpy_object *self,
16601 +                    char *set_doc, char *show_doc, char *help_doc,
16602 +                    struct cmd_list_element **set_list,
16603 +                    struct cmd_list_element **show_list)
16604 +{
16605 +  switch (parmclass)
16606 +    {
16607 +    case var_boolean:
16608 +      add_setshow_boolean_cmd (cmd_name, cmdclass, &self->value.intval,
16609 +                              set_doc, show_doc, help_doc,
16610 +                              NULL, NULL, set_list, show_list);
16611 +      break;
16612 +
16613 +    case var_auto_boolean:
16614 +      add_setshow_auto_boolean_cmd (cmd_name, cmdclass,
16615 +                                   &self->value.autoboolval,
16616 +                                   set_doc, show_doc, help_doc,
16617 +                                   NULL, NULL, set_list, show_list);
16618 +      break;
16619 +
16620 +    case var_uinteger:
16621 +      add_setshow_uinteger_cmd (cmd_name, cmdclass, &self->value.uintval,
16622 +                               set_doc, show_doc, help_doc,
16623 +                               NULL, NULL, set_list, show_list);
16624 +      break;
16625 +
16626 +    case var_integer:
16627 +      add_setshow_integer_cmd (cmd_name, cmdclass, &self->value.intval,
16628 +                              set_doc, show_doc, help_doc,
16629 +                              NULL, NULL, set_list, show_list);
16630 +      break;
16631 +
16632 +    case var_string:
16633 +      add_setshow_string_cmd (cmd_name, cmdclass, &self->value.stringval,
16634 +                             set_doc, show_doc, help_doc,
16635 +                             NULL, NULL, set_list, show_list);
16636 +      break;
16637 +
16638 +    case var_string_noescape:
16639 +      add_setshow_string_noescape_cmd (cmd_name, cmdclass,
16640 +                                      &self->value.stringval,
16641 +                                      set_doc, show_doc, help_doc,
16642 +                                      NULL, NULL, set_list, show_list);
16643 +      break;
16644 +
16645 +    case var_optional_filename:
16646 +      add_setshow_optional_filename_cmd (cmd_name, cmdclass,
16647 +                                        &self->value.stringval,
16648 +                                        set_doc, show_doc, help_doc,
16649 +                                        NULL, NULL, set_list, show_list);
16650 +      break;
16651 +
16652 +    case var_filename:
16653 +      add_setshow_filename_cmd (cmd_name, cmdclass, &self->value.stringval,
16654 +                               set_doc, show_doc, help_doc,
16655 +                               NULL, NULL, set_list, show_list);
16656 +      break;
16657 +
16658 +    case var_zinteger:
16659 +      add_setshow_zinteger_cmd (cmd_name, cmdclass, &self->value.intval,
16660 +                               set_doc, show_doc, help_doc,
16661 +                               NULL, NULL, set_list, show_list);
16662 +      break;
16663 +
16664 +    case var_enum:
16665 +      add_setshow_enum_cmd (cmd_name, cmdclass, self->enumeration,
16666 +                           &self->value.cstringval,
16667 +                           set_doc, show_doc, help_doc,
16668 +                           NULL, NULL, set_list, show_list);
16669 +      /* Initialize the value, just in case.  */
16670 +      self->value.cstringval = self->enumeration[0];
16671 +      break;
16672 +    }
16673 +}
16674 +
16675 +/* A helper which computes enum values.  Returns 1 on success, 0 on
16676 +   error.  */
16677 +static int
16678 +compute_enum_values (parmpy_object *self, PyObject *enum_values)
16679 +{
16680 +  Py_ssize_t size, i;
16681 +
16682 +  if (! enum_values)
16683 +    {
16684 +      PyErr_SetString (PyExc_RuntimeError,
16685 +                      "enumeration required for PARAM_ENUM");
16686 +      return 0;
16687 +    }
16688 +
16689 +  if (! PySequence_Check (enum_values))
16690 +    {
16691 +      PyErr_SetString (PyExc_RuntimeError, "enumeration is not a sequence");
16692 +      return 0;
16693 +    }
16694 +
16695 +  size = PySequence_Size (enum_values);
16696 +  if (size < 0)
16697 +    return 0;
16698 +  if (size == 0)
16699 +    {
16700 +      PyErr_SetString (PyExc_RuntimeError, "empty enumeration");
16701 +      return 0;
16702 +    }
16703 +
16704 +  self->enumeration = xmalloc ((size + 1) * sizeof (char *));
16705 +  memset (self->enumeration, 0, (size + 1) * sizeof (char *));
16706 +
16707 +  for (i = 0; i < size; ++i)
16708 +    {
16709 +      PyObject *item = PySequence_GetItem (enum_values, i);
16710 +      if (! item)
16711 +       return 0;
16712 +      if (! gdbpy_is_string (item))
16713 +       {
16714 +         PyErr_SetString (PyExc_RuntimeError, "enumeration item not a string");
16715 +         return 0;
16716 +       }
16717 +      self->enumeration[i] = python_string_to_host_string (item);
16718 +    }
16719 +
16720 +  return 1;
16721 +}
16722 +
16723 +/* A helper function which returns a documentation string for an
16724 +   object.  */
16725 +static char *
16726 +get_doc_string (PyObject *object, PyObject *attr)
16727 +{
16728 +  char *result = NULL;
16729 +  if (PyObject_HasAttr (object, attr))
16730 +    {
16731 +      PyObject *ds_obj = PyObject_GetAttr (object, attr);
16732 +      if (ds_obj && gdbpy_is_string (ds_obj))
16733 +       result = python_string_to_host_string (ds_obj);
16734 +    }
16735 +  if (! result)
16736 +    result = xstrdup ("This command is not documented.");
16737 +  return result;
16738 +}
16739 +
16740 +/* Object initializer; sets up gdb-side structures for command.
16741 +
16742 +   Use: __init__(NAME, CMDCLASS, PARMCLASS, [ENUM])
16743 +
16744 +   NAME is the name of the parameter.  It may consist of multiple
16745 +   words, in which case the final word is the name of the new command,
16746 +   and earlier words must be prefix commands.
16747 +
16748 +   CMDCLASS is the kind of command.  It should be one of the COMMAND_*
16749 +   constants defined in the gdb module.
16750 +
16751 +   PARMCLASS is the type of the parameter.  It should be one of the
16752 +   PARAM_* constants defined in the gdb module.
16753 +
16754 +   If PARMCLASS is PARAM_ENUM, then the final argument should be a
16755 +   collection of strings.  These strings are the valid values for this
16756 +   parameter.
16757 +
16758 +   The documentation for the parameter is taken from the doc string
16759 +   for the python class.
16760 +   
16761 +*/
16762 +static int
16763 +parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
16764 +{
16765 +  parmpy_object *obj = (parmpy_object *) self;
16766 +  char *name;
16767 +  char *set_doc, *show_doc, *doc;
16768 +  char *cmd_name;
16769 +  int parmclass, cmdtype;
16770 +  PyObject *enum_values = NULL;
16771 +  struct cmd_list_element *cmd_list;
16772 +  struct cmd_list_element **set_list, **show_list;
16773 +  volatile struct gdb_exception except;
16774 +
16775 +  if (! PyArg_ParseTuple (args, "sii|O", &name, &cmdtype, &parmclass,
16776 +                         &enum_values))
16777 +    return -1;
16778 +
16779 +  if (cmdtype != no_class && cmdtype != class_run
16780 +      && cmdtype != class_vars && cmdtype != class_stack
16781 +      && cmdtype != class_files && cmdtype != class_support
16782 +      && cmdtype != class_info && cmdtype != class_breakpoint
16783 +      && cmdtype != class_trace && cmdtype != class_obscure
16784 +      && cmdtype != class_maintenance)
16785 +    {
16786 +      PyErr_Format (PyExc_RuntimeError, "invalid command class argument");
16787 +      return -1;
16788 +    }
16789 +
16790 +  if (parmclass != var_boolean && parmclass != var_auto_boolean
16791 +      && parmclass != var_uinteger && parmclass != var_integer
16792 +      && parmclass != var_string && parmclass != var_string_noescape
16793 +      && parmclass != var_optional_filename && parmclass != var_filename
16794 +      && parmclass != var_zinteger && parmclass != var_enum)
16795 +    {
16796 +      PyErr_SetString (PyExc_RuntimeError, "invalid parameter class argument");
16797 +      return -1;
16798 +    }
16799 +
16800 +  if (enum_values && parmclass != var_enum)
16801 +    {
16802 +      PyErr_SetString (PyExc_RuntimeError,
16803 +                      "only PARAM_ENUM accepts a fourth argument");
16804 +      return -1;
16805 +    }
16806 +  if (parmclass == var_enum)
16807 +    {
16808 +      if (! compute_enum_values (obj, enum_values))
16809 +       return -1;
16810 +    }
16811 +
16812 +  obj->type = (enum var_types) parmclass;
16813 +  memset (&obj->value, 0, sizeof (obj->value));
16814 +  obj->enumeration = NULL;
16815 +
16816 +  cmd_name = gdbpy_parse_command_name (name, &set_list, &setlist);
16817 +  if (! cmd_name)
16818 +    return -1;
16819 +  xfree (cmd_name);
16820 +  cmd_name = gdbpy_parse_command_name (name, &show_list, &showlist);
16821 +  if (! cmd_name)
16822 +    return -1;
16823 +
16824 +  /* FIXME: there is no way to register a destructor function for
16825 +     set/show commands.  So, these are leaked.  */
16826 +  set_doc = get_doc_string (self, set_doc_cst);
16827 +  show_doc = get_doc_string (self, show_doc_cst);
16828 +  doc = get_doc_string (self, gdbpy_doc_cst);
16829 +
16830 +  Py_INCREF (self);
16831 +
16832 +  TRY_CATCH (except, RETURN_MASK_ALL)
16833 +    {
16834 +      add_setshow_generic (parmclass, (enum command_class) cmdtype,
16835 +                          cmd_name, obj,
16836 +                          set_doc, show_doc,
16837 +                          doc, set_list, show_list);
16838 +    }
16839 +  if (except.reason < 0)
16840 +    {
16841 +      xfree (cmd_name);
16842 +      xfree (set_doc);
16843 +      xfree (show_doc);
16844 +      xfree (doc);
16845 +      Py_DECREF (self);
16846 +      PyErr_Format (except.reason == RETURN_QUIT
16847 +                   ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
16848 +                   "%s", except.message);
16849 +      return -1;
16850 +    }
16851 +  return 0;
16852 +}
16853 +
16854 +\f
16855 +
16856 +/* Initialize the 'parameters' module.  */
16857 +void
16858 +gdbpy_initialize_parameters (void)
16859 +{
16860 +  int i;
16861 +
16862 +  if (PyType_Ready (&parmpy_object_type) < 0)
16863 +    return;
16864 +
16865 +  set_doc_cst = PyString_FromString ("set_doc");
16866 +  if (! set_doc_cst)
16867 +    return;
16868 +  show_doc_cst = PyString_FromString ("show_doc");
16869 +  if (! show_doc_cst)
16870 +    return;
16871 +
16872 +  for (i = 0; parm_constants[i].name; ++i)
16873 +    {
16874 +      if (PyModule_AddIntConstant (gdb_module,
16875 +                                  parm_constants[i].name,
16876 +                                  parm_constants[i].value) < 0)
16877 +       return;
16878 +    }
16879 +
16880 +  Py_INCREF (&parmpy_object_type);
16881 +  PyModule_AddObject (gdb_module, "Parameter",
16882 +                     (PyObject *) &parmpy_object_type);
16883 +}
16884 +
16885 +\f
16886 +
16887 +static PyTypeObject parmpy_object_type =
16888 +{
16889 +  PyObject_HEAD_INIT (NULL)
16890 +  0,                             /*ob_size*/
16891 +  "gdb.Parameter",               /*tp_name*/
16892 +  sizeof (parmpy_object),        /*tp_basicsize*/
16893 +  0,                             /*tp_itemsize*/
16894 +  0,                             /*tp_dealloc*/
16895 +  0,                             /*tp_print*/
16896 +  0,                             /*tp_getattr*/
16897 +  0,                             /*tp_setattr*/
16898 +  0,                             /*tp_compare*/
16899 +  0,                             /*tp_repr*/
16900 +  0,                             /*tp_as_number*/
16901 +  0,                             /*tp_as_sequence*/
16902 +  0,                             /*tp_as_mapping*/
16903 +  0,                             /*tp_hash */
16904 +  0,                             /*tp_call*/
16905 +  0,                             /*tp_str*/
16906 +  get_attr,                      /*tp_getattro*/
16907 +  set_attr,                      /*tp_setattro*/
16908 +  0,                             /*tp_as_buffer*/
16909 +  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
16910 +  "GDB parameter object",        /* tp_doc */
16911 +  0,                             /* tp_traverse */
16912 +  0,                             /* tp_clear */
16913 +  0,                             /* tp_richcompare */
16914 +  0,                             /* tp_weaklistoffset */
16915 +  0,                             /* tp_iter */
16916 +  0,                             /* tp_iternext */
16917 +  0,                             /* tp_methods */
16918 +  0,                             /* tp_members */
16919 +  0,                             /* tp_getset */
16920 +  0,                             /* tp_base */
16921 +  0,                             /* tp_dict */
16922 +  0,                             /* tp_descr_get */
16923 +  0,                             /* tp_descr_set */
16924 +  0,                             /* tp_dictoffset */
16925 +  parmpy_init,                   /* tp_init */
16926 +  0,                             /* tp_alloc */
16927 +  PyType_GenericNew              /* tp_new */
16928 +};
16929 diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
16930 index 5d696c8..a6348ba 100644
16931 --- a/gdb/python/py-prettyprint.c
16932 +++ b/gdb/python/py-prettyprint.c
16933 @@ -121,6 +121,7 @@ find_pretty_printer (PyObject *value)
16934    
16935    return function;
16936  }
16937 +
16938  /* Pretty-print a single value, via the printer object PRINTER.
16939     If the function returns a string, a PyObject containing the string
16940     is returned.  Otherwise, if the function returns a value,
16941 @@ -141,10 +142,15 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
16942           if (! gdbpy_is_string (result))
16943             {
16944               *out_value = convert_value_from_python (result);
16945 -             if (PyErr_Occurred ())
16946 -               *out_value = NULL;
16947 -             Py_DECREF (result);
16948 -             result = NULL;
16949 +             if (PyErr_Occurred ())
16950 +               *out_value = NULL;
16951 +             else
16952 +               /* We must increment the value's refcount, because we
16953 +                  are about to decref RESULT, and this may result in
16954 +                  the value being destroyed.  */
16955 +               value_incref (*out_value);
16956 +             Py_DECREF (result);
16957 +             result = NULL;
16958             }
16959         }
16960      }
16961 @@ -556,14 +562,7 @@ gdbpy_get_varobj_pretty_printer (struct value *value)
16962  {
16963    PyObject *val_obj;
16964    PyObject *pretty_printer = NULL;
16965 -  volatile struct gdb_exception except;
16966  
16967 -  TRY_CATCH (except, RETURN_MASK_ALL)
16968 -    {
16969 -      value = value_copy (value);
16970 -    }
16971 -  GDB_PY_HANDLE_EXCEPTION (except);
16972 -  
16973    val_obj = value_to_value_object (value);
16974    if (! val_obj)
16975      return NULL;
16976 diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
16977 new file mode 100644
16978 index 0000000..03d43c1
16979 --- /dev/null
16980 +++ b/gdb/python/py-symbol.c
16981 @@ -0,0 +1,336 @@
16982 +/* Python interface to symbols.
16983 +
16984 +   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
16985 +
16986 +   This file is part of GDB.
16987 +
16988 +   This program is free software; you can redistribute it and/or modify
16989 +   it under the terms of the GNU General Public License as published by
16990 +   the Free Software Foundation; either version 3 of the License, or
16991 +   (at your option) any later version.
16992 +
16993 +   This program is distributed in the hope that it will be useful,
16994 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
16995 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16996 +   GNU General Public License for more details.
16997 +
16998 +   You should have received a copy of the GNU General Public License
16999 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17000 +
17001 +#include "defs.h"
17002 +#include "block.h"
17003 +#include "exceptions.h"
17004 +#include "frame.h"
17005 +#include "symtab.h"
17006 +#include "python-internal.h"
17007 +
17008 +typedef struct {
17009 +  PyObject_HEAD
17010 +  struct symbol *symbol;
17011 +} symbol_object;
17012 +
17013 +
17014 +static PyObject *
17015 +sympy_str (PyObject *self)
17016 +{
17017 +  int ret;
17018 +  char *s;
17019 +  PyObject *result;
17020 +
17021 +  ret = asprintf (&s, "symbol for %s",
17022 +                 SYMBOL_PRINT_NAME (((symbol_object *) self)->symbol));
17023 +  if (ret < 0)
17024 +    Py_RETURN_NONE;
17025 +
17026 +  result = PyString_FromString (s);
17027 +  xfree (s);
17028 +
17029 +  return result;
17030 +}
17031 +
17032 +static PyObject *
17033 +sympy_get_value (PyObject *self, void *closure)
17034 +{
17035 +  symbol_object *self_sym = (symbol_object *) self;
17036 +
17037 +  switch (SYMBOL_CLASS (self_sym->symbol))
17038 +    {
17039 +    case LOC_BLOCK:
17040 +      return block_to_block_object (SYMBOL_BLOCK_VALUE (self_sym->symbol));
17041 +    }
17042 +
17043 +  PyErr_SetString (PyExc_NotImplementedError,
17044 +                  "Symbol type not yet supported in Python scripts.");
17045 +  return NULL;
17046 +}
17047 +
17048 +static PyObject *
17049 +sympy_get_symtab (PyObject *self, void *closure)
17050 +{
17051 +  symbol_object *self_sym = (symbol_object *) self;
17052 +
17053 +  return symtab_to_symtab_object (SYMBOL_SYMTAB (self_sym->symbol));
17054 +}
17055 +
17056 +static PyObject *
17057 +sympy_get_name (PyObject *self, void *closure)
17058 +{
17059 +  symbol_object *self_sym = (symbol_object *) self;
17060 +
17061 +  return PyString_FromString (SYMBOL_NATURAL_NAME (self_sym->symbol));
17062 +}
17063 +
17064 +static PyObject *
17065 +sympy_get_linkage_name (PyObject *self, void *closure)
17066 +{
17067 +  symbol_object *self_sym = (symbol_object *) self;
17068 +
17069 +  return PyString_FromString (SYMBOL_LINKAGE_NAME (self_sym->symbol));
17070 +}
17071 +
17072 +static PyObject *
17073 +sympy_get_print_name (PyObject *self, void *closure)
17074 +{
17075 +  symbol_object *self_sym = (symbol_object *) self;
17076 +
17077 +  return PyString_FromString (SYMBOL_PRINT_NAME (self_sym->symbol));
17078 +}
17079 +
17080 +static PyObject *
17081 +sympy_get_addr_class (PyObject *self, void *closure)
17082 +{
17083 +  symbol_object *self_sym = (symbol_object *) self;
17084 +
17085 +  return PyInt_FromLong (SYMBOL_CLASS (self_sym->symbol));
17086 +}
17087 +
17088 +static PyObject *
17089 +sympy_is_argument (PyObject *self, void *closure)
17090 +{
17091 +  symbol_object *self_sym = (symbol_object *) self;
17092 +
17093 +  return PyBool_FromLong (SYMBOL_IS_ARGUMENT (self_sym->symbol));
17094 +}
17095 +
17096 +static PyObject *
17097 +sympy_is_constant (PyObject *self, void *closure)
17098 +{
17099 +  symbol_object *self_sym = (symbol_object *) self;
17100 +  enum address_class class = SYMBOL_CLASS (self_sym->symbol);
17101 +
17102 +  return PyBool_FromLong (class == LOC_CONST || class == LOC_CONST_BYTES);
17103 +}
17104 +
17105 +static PyObject *
17106 +sympy_is_function (PyObject *self, void *closure)
17107 +{
17108 +  symbol_object *self_sym = (symbol_object *) self;
17109 +  enum address_class class = SYMBOL_CLASS (self_sym->symbol);
17110 +
17111 +  return PyBool_FromLong (class == LOC_BLOCK);
17112 +}
17113 +
17114 +static PyObject *
17115 +sympy_is_variable (PyObject *self, void *closure)
17116 +{
17117 +  symbol_object *self_sym = (symbol_object *) self;
17118 +  enum address_class class = SYMBOL_CLASS (self_sym->symbol);
17119 +
17120 +  return PyBool_FromLong (!SYMBOL_IS_ARGUMENT (self_sym->symbol)
17121 +      && (class == LOC_LOCAL || class == LOC_REGISTER || class == LOC_STATIC
17122 +         || class == LOC_COMPUTED || class == LOC_OPTIMIZED_OUT));
17123 +}
17124 +
17125 +PyObject *
17126 +symbol_to_symbol_object (struct symbol *sym)
17127 +{
17128 +  symbol_object *sym_obj;
17129 +
17130 +  sym_obj = PyObject_New (symbol_object, &symbol_object_type);
17131 +  if (sym_obj == NULL)
17132 +    {
17133 +      PyErr_SetString (PyExc_MemoryError, "Could not allocate symbol object.");
17134 +      return NULL;
17135 +    }
17136 +
17137 +  sym_obj->symbol = sym;
17138 +
17139 +  return (PyObject *) sym_obj;
17140 +}
17141 +
17142 +struct symbol *
17143 +symbol_object_to_symbol (PyObject *obj)
17144 +{
17145 +  if (! PyObject_TypeCheck (obj, &symbol_object_type))
17146 +    return NULL;
17147 +  return ((symbol_object *) obj)->symbol;
17148 +}
17149 +
17150 +/* Implementation of
17151 +   gdb.lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)
17152 +   A tuple with 2 elements is always returned.  The first is the symbol
17153 +   object or None, the second is a boolean with the value of
17154 +   is_a_field_of_this (see comment in lookup_symbol_in_language).  */
17155 +
17156 +PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
17157 +{
17158 +  int domain = VAR_DOMAIN, is_a_field_of_this = 0;
17159 +  const char *name;
17160 +  static char *keywords[] = { "name", "block", "domain", NULL };
17161 +  struct symbol *symbol;
17162 +  PyObject *block_obj = NULL, *ret_tuple, *sym_obj, *bool_obj;
17163 +  struct block *block = NULL;
17164 +
17165 +  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
17166 +                                    &block_object_type, &block_obj, &domain))
17167 +    return NULL;
17168 +
17169 +  if (block_obj)
17170 +    block = block_object_to_block (block_obj);
17171 +  else
17172 +    {
17173 +      struct frame_info *selected_frame;
17174 +      volatile struct gdb_exception except;
17175 +
17176 +      TRY_CATCH (except, RETURN_MASK_ALL)
17177 +       {
17178 +         selected_frame  = get_selected_frame (_("No frame selected."));
17179 +         block = block_for_pc (get_frame_address_in_block (selected_frame));
17180 +       }
17181 +      GDB_PY_HANDLE_EXCEPTION (except);
17182 +    }
17183 +
17184 +  symbol = lookup_symbol (name, block, domain, &is_a_field_of_this);
17185 +
17186 +  ret_tuple = PyTuple_New (2);
17187 +  if (!ret_tuple)
17188 +    {
17189 +      PyErr_SetString (PyExc_MemoryError, "Could not allocate tuple object.");
17190 +      return NULL;
17191 +    }
17192 +
17193 +  if (symbol)
17194 +    {
17195 +      sym_obj = symbol_to_symbol_object (symbol);
17196 +      if (!sym_obj)
17197 +       {
17198 +         Py_DECREF (ret_tuple);
17199 +         return NULL;
17200 +       }
17201 +    }
17202 +  else
17203 +    {
17204 +      sym_obj = Py_None;
17205 +      Py_INCREF (Py_None);
17206 +    }
17207 +  PyTuple_SET_ITEM (ret_tuple, 0, sym_obj);
17208 +
17209 +  bool_obj = is_a_field_of_this? Py_True : Py_False;
17210 +  Py_INCREF (bool_obj);
17211 +  PyTuple_SET_ITEM (ret_tuple, 1, bool_obj);
17212 +
17213 +  return ret_tuple;
17214 +}
17215 +
17216 +void
17217 +gdbpy_initialize_symbols (void)
17218 +{
17219 +  if (PyType_Ready (&symbol_object_type) < 0)
17220 +    return;
17221 +
17222 +  /* FIXME: These would probably be best exposed as class attributes of Symbol,
17223 +     but I don't know how to do it except by messing with the type's dictionary.
17224 +     That seems too messy.  */
17225 +  /* FIXME 2: Some of these were removed from GDB since I first wrote this code,
17226 +     so it's probably a good idea not to expose them to Python.  */
17227 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF);
17228 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST", LOC_CONST);
17229 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC", LOC_STATIC);
17230 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER", LOC_REGISTER);
17231 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG", LOC_ARG);
17232 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG", LOC_REF_ARG);
17233 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL", LOC_LOCAL);
17234 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF", LOC_TYPEDEF);
17235 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL", LOC_LABEL);
17236 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK", LOC_BLOCK);
17237 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
17238 +                          LOC_CONST_BYTES);
17239 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED", LOC_UNRESOLVED);
17240 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
17241 +                          LOC_OPTIMIZED_OUT);
17242 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED", LOC_COMPUTED);
17243 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
17244 +                          LOC_REGPARM_ADDR);
17245 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN", UNDEF_DOMAIN);
17246 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN", VAR_DOMAIN);
17247 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN", STRUCT_DOMAIN);
17248 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN", LABEL_DOMAIN);
17249 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
17250 +                          VARIABLES_DOMAIN);
17251 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
17252 +                          FUNCTIONS_DOMAIN);
17253 +  PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN", TYPES_DOMAIN);
17254 +
17255 +  Py_INCREF (&symbol_object_type);
17256 +  PyModule_AddObject (gdb_module, "Symbol", (PyObject *) &symbol_object_type);
17257 +}
17258 +
17259 +\f
17260 +
17261 +static PyGetSetDef symbol_object_getset[] = {
17262 +  { "value", sympy_get_value, NULL, "Value of the symbol.", NULL },
17263 +  { "symtab", sympy_get_symtab, NULL,
17264 +    "Symbol table in which the symbol appears.", NULL },
17265 +  { "name", sympy_get_name, NULL,
17266 +    "Name of the symbol, as it appears in the source code.", NULL },
17267 +  { "linkage_name", sympy_get_linkage_name, NULL,
17268 +    "Name of the symbol, as used by the linker (i.e., may be mangled).", NULL },
17269 +  { "print_name", sympy_get_print_name, NULL,
17270 +    "Name of the symbol in a form suitable for output.\n\
17271 +This is either name or linkage_name, depending on whether the user asked GDB\n\
17272 +to display demangled or mangled names.", NULL },
17273 +  { "addr_class", sympy_get_addr_class, NULL, "Address class of the symbol." },
17274 +  { "is_argument", sympy_is_argument, NULL,
17275 +    "True if the symbol is an argument of a function." },
17276 +  { "is_constant", sympy_is_constant, NULL,
17277 +    "True if the symbol is a constant." },
17278 +  { "is_function", sympy_is_function, NULL,
17279 +    "True if the symbol is a function or method." },
17280 +  { "is_variable", sympy_is_variable, NULL,
17281 +    "True if the symbol is a variable." },
17282 +  { NULL }  /* Sentinel */
17283 +};
17284 +
17285 +PyTypeObject symbol_object_type = {
17286 +  PyObject_HEAD_INIT (NULL)
17287 +  0,                             /*ob_size*/
17288 +  "gdb.Symbol",                          /*tp_name*/
17289 +  sizeof (symbol_object),        /*tp_basicsize*/
17290 +  0,                             /*tp_itemsize*/
17291 +  0,                             /*tp_dealloc*/
17292 +  0,                             /*tp_print*/
17293 +  0,                             /*tp_getattr*/
17294 +  0,                             /*tp_setattr*/
17295 +  0,                             /*tp_compare*/
17296 +  0,                             /*tp_repr*/
17297 +  0,                             /*tp_as_number*/
17298 +  0,                             /*tp_as_sequence*/
17299 +  0,                             /*tp_as_mapping*/
17300 +  0,                             /*tp_hash */
17301 +  0,                             /*tp_call*/
17302 +  sympy_str,                     /*tp_str*/
17303 +  0,                             /*tp_getattro*/
17304 +  0,                             /*tp_setattro*/
17305 +  0,                             /*tp_as_buffer*/
17306 +  Py_TPFLAGS_DEFAULT,            /*tp_flags*/
17307 +  "GDB symbol object",           /* tp_doc */
17308 +  0,                             /* tp_traverse */
17309 +  0,                             /* tp_clear */
17310 +  0,                             /* tp_richcompare */
17311 +  0,                             /* tp_weaklistoffset */
17312 +  0,                             /* tp_iter */
17313 +  0,                             /* tp_iternext */
17314 +  0,                             /* tp_methods */
17315 +  0,                             /* tp_members */
17316 +  symbol_object_getset           /* tp_getset */
17317 +};
17318 diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
17319 new file mode 100644
17320 index 0000000..830e586
17321 --- /dev/null
17322 +++ b/gdb/python/py-symtab.c
17323 @@ -0,0 +1,322 @@
17324 +/* Python interface to symbol tables.
17325 +
17326 +   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
17327 +
17328 +   This file is part of GDB.
17329 +
17330 +   This program is free software; you can redistribute it and/or modify
17331 +   it under the terms of the GNU General Public License as published by
17332 +   the Free Software Foundation; either version 3 of the License, or
17333 +   (at your option) any later version.
17334 +
17335 +   This program is distributed in the hope that it will be useful,
17336 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
17337 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17338 +   GNU General Public License for more details.
17339 +
17340 +   You should have received a copy of the GNU General Public License
17341 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17342 +
17343 +#include "defs.h"
17344 +#include "charset.h"
17345 +#include "symtab.h"
17346 +#include "source.h"
17347 +#include "python-internal.h"
17348 +
17349 +typedef struct {
17350 +  PyObject_HEAD
17351 +  struct symtab *symtab;
17352 +} symtab_object;
17353 +
17354 +static PyTypeObject symtab_object_type;
17355 +
17356 +typedef struct {
17357 +  PyObject_HEAD
17358 +  symtab_object *symtab;
17359 +  struct symtab_and_line *sal;
17360 +} sal_object;
17361 +
17362 +static PyTypeObject sal_object_type;
17363 +
17364 +
17365 +static PyObject *
17366 +stpy_str (PyObject *self)
17367 +{
17368 +  int ret;
17369 +  char *s;
17370 +  PyObject *result;
17371 +
17372 +  ret = asprintf (&s, "symbol table for %s",
17373 +                 ((symtab_object *) self)->symtab->filename);
17374 +  if (ret < 0)
17375 +    Py_RETURN_NONE;
17376 +
17377 +  result = PyString_FromString (s);
17378 +  xfree (s);
17379 +
17380 +  return result;
17381 +}
17382 +
17383 +static PyObject *
17384 +stpy_get_filename (PyObject *self, void *closure)
17385 +{
17386 +  symtab_object *self_symtab = (symtab_object *) self;
17387 +  PyObject *str_obj;
17388 +
17389 +  /* FIXME: Can symtab->filename really be NULL?  */
17390 +  if (self_symtab->symtab->filename)
17391 +    str_obj = PyString_Decode (self_symtab->symtab->filename,
17392 +                              strlen (self_symtab->symtab->filename),
17393 +                              host_charset (), NULL);
17394 +  else
17395 +    {
17396 +      str_obj = Py_None;
17397 +      Py_INCREF (Py_None);
17398 +    }
17399 +
17400 +  return str_obj;
17401 +}
17402 +
17403 +static PyObject *
17404 +stpy_get_objfile (PyObject *self, void *closure)
17405 +{
17406 +  symtab_object *self_symtab = (symtab_object *) self;
17407 +  PyObject *result = objfile_to_objfile_object (self_symtab->symtab->objfile);
17408 +  Py_INCREF (result);
17409 +  return result;
17410 +}
17411 +
17412 +static PyObject *
17413 +stpy_fullname (PyObject *self, PyObject *args)
17414 +{
17415 +  char *fullname;
17416 +
17417 +  fullname = symtab_to_fullname (((symtab_object *) self)->symtab);
17418 +  if (fullname)
17419 +    return PyString_Decode (fullname, strlen (fullname), host_charset (), NULL);
17420 +
17421 +  Py_RETURN_NONE;
17422 +}
17423 +
17424 +static PyObject *
17425 +salpy_str (PyObject *self)
17426 +{
17427 +  int ret;
17428 +  char *s, *filename;
17429 +  sal_object *sal_obj;
17430 +  PyObject *result;
17431 +
17432 +  sal_obj = (sal_object *) self;
17433 +  filename = (sal_obj->symtab == (symtab_object *) Py_None)? "<unknown>" :
17434 +                                          sal_obj->symtab->symtab->filename;
17435 +  ret = asprintf (&s, "symbol and line for %s, line %d", filename,
17436 +                 sal_obj->sal->line);
17437 +  if (ret < 0)
17438 +    Py_RETURN_NONE;
17439 +
17440 +  result = PyString_FromString (s);
17441 +  xfree (s);
17442 +
17443 +  return result;
17444 +}
17445 +
17446 +static PyObject *
17447 +salpy_get_pc (PyObject *self, void *closure)
17448 +{
17449 +  return PyLong_FromUnsignedLongLong (((sal_object *) self)->sal->pc);
17450 +}
17451 +
17452 +static PyObject *
17453 +salpy_get_line (PyObject *self, void *closure)
17454 +{
17455 +  return PyLong_FromUnsignedLongLong (((sal_object *) self)->sal->line);
17456 +}
17457 +
17458 +static PyObject *
17459 +salpy_get_symtab (PyObject *self, void *closure)
17460 +{
17461 +  sal_object *self_sal = (sal_object *) self;
17462 +
17463 +  Py_INCREF (self_sal->symtab);
17464 +
17465 +  return (PyObject *) self_sal->symtab;
17466 +}
17467 +
17468 +static void 
17469 +salpy_dealloc (PyObject *self)
17470 +{
17471 +  sal_object *self_sal = (sal_object *) self;
17472 +
17473 +  Py_DECREF (self_sal->symtab);
17474 +  xfree (self_sal->sal);
17475 +  self_sal->ob_type->tp_free (self);
17476 +}
17477 +
17478 +PyObject *
17479 +symtab_and_line_to_sal_object (struct symtab_and_line sal)
17480 +{
17481 +  sal_object *sal_obj;
17482 +  symtab_object *symtab_obj;
17483 +
17484 +  sal_obj = PyObject_New (sal_object, &sal_object_type);
17485 +  if (sal_obj == NULL)
17486 +    {
17487 +      PyErr_SetString (PyExc_MemoryError,
17488 +                      "Could not allocate Symtab_and_line object.");
17489 +      return NULL;
17490 +    }
17491 +
17492 +  if (sal.symtab)
17493 +    {
17494 +      symtab_obj = (symtab_object *) symtab_to_symtab_object (sal.symtab);
17495 +      if (symtab_obj == NULL)
17496 +       {
17497 +         Py_DECREF (sal_obj);
17498 +         return NULL;
17499 +       }
17500 +
17501 +      symtab_obj->symtab = sal.symtab;
17502 +    }
17503 +  else
17504 +    {
17505 +      symtab_obj = (symtab_object *) Py_None;
17506 +      Py_INCREF (Py_None);
17507 +    }
17508 +
17509 +  sal_obj->sal = (struct symtab_and_line *)
17510 +                                   xmalloc (sizeof (struct symtab_and_line));
17511 +  *(sal_obj->sal) = sal;
17512 +  sal_obj->symtab = symtab_obj;
17513 +
17514 +  return (PyObject *) sal_obj;
17515 +}
17516 +
17517 +PyObject *
17518 +symtab_to_symtab_object (struct symtab *symtab)
17519 +{
17520 +  symtab_object *symtab_obj;
17521 +  
17522 +  symtab_obj = PyObject_New (symtab_object, &symtab_object_type);
17523 +  if (symtab_obj == NULL)
17524 +    {
17525 +      PyErr_SetString (PyExc_MemoryError,
17526 +         "Could not allocate Symtab object.");
17527 +
17528 +      return NULL;
17529 +    }
17530 +
17531 +  symtab_obj->symtab = symtab;
17532 +
17533 +  return (PyObject *) symtab_obj;
17534 +}
17535 +
17536 +void
17537 +gdbpy_initialize_symtabs (void)
17538 +{
17539 +  symtab_object_type.tp_new = PyType_GenericNew;
17540 +  if (PyType_Ready (&symtab_object_type) < 0)
17541 +    return;
17542 +
17543 +  sal_object_type.tp_new = PyType_GenericNew;
17544 +  if (PyType_Ready (&sal_object_type) < 0)
17545 +    return;
17546 +
17547 +  Py_INCREF (&symtab_object_type);
17548 +  PyModule_AddObject (gdb_module, "Symtab", (PyObject *) &symtab_object_type);
17549 +
17550 +  Py_INCREF (&sal_object_type);
17551 +  PyModule_AddObject (gdb_module, "Symtab_and_line",
17552 +                     (PyObject *) &sal_object_type);
17553 +}
17554 +
17555 +\f
17556 +
17557 +static PyGetSetDef symtab_object_getset[] = {
17558 +  { "filename", stpy_get_filename, NULL,
17559 +    "The symbol table's source filename.", NULL },
17560 +  { "objfile", stpy_get_objfile, NULL, "The symtab's objfile.",
17561 +    NULL },
17562 +  {NULL}  /* Sentinel */
17563 +};
17564 +
17565 +static PyMethodDef symtab_object_methods[] = {
17566 +  { "fullname", stpy_fullname, METH_NOARGS,
17567 +    "Return the symtab's full source filename." },
17568 +  {NULL}  /* Sentinel */
17569 +};
17570 +
17571 +static PyTypeObject symtab_object_type = {
17572 +  PyObject_HEAD_INIT (NULL)
17573 +  0,                             /*ob_size*/
17574 +  "gdb.Symtab",                          /*tp_name*/
17575 +  sizeof (symtab_object),        /*tp_basicsize*/
17576 +  0,                             /*tp_itemsize*/
17577 +  0,                             /*tp_dealloc*/
17578 +  0,                             /*tp_print*/
17579 +  0,                             /*tp_getattr*/
17580 +  0,                             /*tp_setattr*/
17581 +  0,                             /*tp_compare*/
17582 +  0,                             /*tp_repr*/
17583 +  0,                             /*tp_as_number*/
17584 +  0,                             /*tp_as_sequence*/
17585 +  0,                             /*tp_as_mapping*/
17586 +  0,                             /*tp_hash */
17587 +  0,                             /*tp_call*/
17588 +  stpy_str,                      /*tp_str*/
17589 +  0,                             /*tp_getattro*/
17590 +  0,                             /*tp_setattro*/
17591 +  0,                             /*tp_as_buffer*/
17592 +  Py_TPFLAGS_DEFAULT,            /*tp_flags*/
17593 +  "GDB symtab object",           /* tp_doc */
17594 +  0,                             /* tp_traverse */
17595 +  0,                             /* tp_clear */
17596 +  0,                             /* tp_richcompare */
17597 +  0,                             /* tp_weaklistoffset */
17598 +  0,                             /* tp_iter */
17599 +  0,                             /* tp_iternext */
17600 +  symtab_object_methods,         /* tp_methods */
17601 +  0,                             /* tp_members */
17602 +  symtab_object_getset           /* tp_getset */
17603 +};
17604 +
17605 +static PyGetSetDef sal_object_getset[] = {
17606 +  { "symtab", salpy_get_symtab, NULL, "Symtab object.", NULL },
17607 +  { "pc", salpy_get_pc, NULL, "Return the symtab_and_line's pc.", NULL },
17608 +  { "line", salpy_get_line, NULL,
17609 +    "Return the symtab_and_line's line.", NULL },
17610 +  {NULL}  /* Sentinel */
17611 +};
17612 +
17613 +static PyTypeObject sal_object_type = {
17614 +  PyObject_HEAD_INIT (NULL)
17615 +  0,                             /*ob_size*/
17616 +  "gdb.Symtab_and_line",         /*tp_name*/
17617 +  sizeof (sal_object),           /*tp_basicsize*/
17618 +  0,                             /*tp_itemsize*/
17619 +  salpy_dealloc,                 /*tp_dealloc*/
17620 +  0,                             /*tp_print*/
17621 +  0,                             /*tp_getattr*/
17622 +  0,                             /*tp_setattr*/
17623 +  0,                             /*tp_compare*/
17624 +  0,                             /*tp_repr*/
17625 +  0,                             /*tp_as_number*/
17626 +  0,                             /*tp_as_sequence*/
17627 +  0,                             /*tp_as_mapping*/
17628 +  0,                             /*tp_hash */
17629 +  0,                             /*tp_call*/
17630 +  salpy_str,                     /*tp_str*/
17631 +  0,                             /*tp_getattro*/
17632 +  0,                             /*tp_setattro*/
17633 +  0,                             /*tp_as_buffer*/
17634 +  Py_TPFLAGS_DEFAULT,            /*tp_flags*/
17635 +  "GDB symtab_and_line object",          /* tp_doc */
17636 +  0,                             /* tp_traverse */
17637 +  0,                             /* tp_clear */
17638 +  0,                             /* tp_richcompare */
17639 +  0,                             /* tp_weaklistoffset */
17640 +  0,                             /* tp_iter */
17641 +  0,                             /* tp_iternext */
17642 +  0,                             /* tp_methods */
17643 +  0,                             /* tp_members */
17644 +  sal_object_getset              /* tp_getset */
17645 +};
17646 diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
17647 index 590d90a..f512248 100644
17648 --- a/gdb/python/py-type.c
17649 +++ b/gdb/python/py-type.c
17650 @@ -27,6 +27,8 @@
17651  #include "demangle.h"
17652  #include "objfiles.h"
17653  #include "language.h"
17654 +#include "observer.h"
17655 +#include "gdb_assert.h"
17656  
17657  typedef struct pyty_type_object
17658  {
17659 @@ -35,11 +37,17 @@ typedef struct pyty_type_object
17660  
17661    /* If a Type object is associated with an objfile, it is kept on a
17662       doubly-linked list, rooted in the objfile.  This lets us copy the
17663 -     underlying struct type when the objfile is deleted.  */
17664 +     underlying struct type when the objfile is deleted.
17665 +
17666 +     With NULL objfile Type still can be doubly-linked in the list
17667 +     PYTY_OBJECTS_DISCARDABLE.  */
17668    struct pyty_type_object *prev;
17669    struct pyty_type_object *next;
17670  } type_object;
17671  
17672 +/* First element of a doubly-linked list of TYPE_DISCARDABLE Types.  */
17673 +static type_object *pyty_objects_discardable;
17674 +
17675  static PyTypeObject type_object_type;
17676  
17677  /* A Field object.  */
17678 @@ -169,6 +177,11 @@ convert_field (struct type *type, int field)
17679    if (PyObject_SetAttrString (result, "artificial", arg) < 0)
17680      goto failarg;
17681  
17682 +  arg = field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False;
17683 +  Py_INCREF (arg);
17684 +  if (PyObject_SetAttrString (result, "is_base_class", arg) < 0)
17685 +    goto failarg;
17686 +
17687    arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field));
17688    if (!arg)
17689      goto fail;
17690 @@ -361,7 +374,7 @@ typy_get_sizeof (PyObject *self, void *closure)
17691  }
17692  
17693  static struct type *
17694 -typy_lookup_typename (char *type_name)
17695 +typy_lookup_typename (char *type_name, struct block *block)
17696  {
17697    struct type *type = NULL;
17698    volatile struct gdb_exception except;
17699 @@ -375,7 +388,7 @@ typy_lookup_typename (char *type_name)
17700         type = lookup_enum (type_name + 5, NULL);
17701        else
17702         type = lookup_typename (python_language, python_gdbarch,
17703 -                               type_name, NULL, 0);
17704 +                               type_name, block, 0);
17705      }
17706    if (except.reason < 0)
17707      {
17708 @@ -389,7 +402,8 @@ typy_lookup_typename (char *type_name)
17709  }
17710  
17711  static struct type *
17712 -typy_lookup_type (struct demangle_component *demangled)
17713 +typy_lookup_type (struct demangle_component *demangled,
17714 +                 struct block *block)
17715  {
17716    struct type *type;
17717    char *type_name;
17718 @@ -404,7 +418,7 @@ typy_lookup_type (struct demangle_component *demangled)
17719        || demangled_type == DEMANGLE_COMPONENT_CONST
17720        || demangled_type == DEMANGLE_COMPONENT_VOLATILE)
17721      {
17722 -      type = typy_lookup_type (demangled->u.s_binary.left);
17723 +      type = typy_lookup_type (demangled->u.s_binary.left, block);
17724        if (! type)
17725         return NULL;
17726  
17727 @@ -422,7 +436,7 @@ typy_lookup_type (struct demangle_component *demangled)
17728      }
17729  
17730    type_name = cp_comp_to_string (demangled, 10);
17731 -  type = typy_lookup_typename (type_name);
17732 +  type = typy_lookup_typename (type_name, block);
17733    xfree (type_name);
17734  
17735    return type;
17736 @@ -436,10 +450,23 @@ typy_template_argument (PyObject *self, PyObject *args)
17737    struct demangle_component *demangled;
17738    const char *err;
17739    struct type *argtype;
17740 +  struct block *block = NULL;
17741 +  PyObject *block_obj = NULL;
17742  
17743 -  if (! PyArg_ParseTuple (args, "i", &argno))
17744 +  if (! PyArg_ParseTuple (args, "i|O", &argno, &block_obj))
17745      return NULL;
17746  
17747 +  if (block_obj)
17748 +    {
17749 +      block = block_object_to_block (block_obj);
17750 +      if (! block)
17751 +       {
17752 +         PyErr_SetString (PyExc_RuntimeError,
17753 +                          "second argument must be block");
17754 +         return NULL;
17755 +       }
17756 +    }
17757 +
17758    type = check_typedef (type);
17759    if (TYPE_CODE (type) == TYPE_CODE_REF)
17760      type = check_typedef (TYPE_TARGET_TYPE (type));
17761 @@ -482,7 +509,7 @@ typy_template_argument (PyObject *self, PyObject *args)
17762        return NULL;
17763      }
17764  
17765 -  argtype = typy_lookup_type (demangled->u.s_binary.left);
17766 +  argtype = typy_lookup_type (demangled->u.s_binary.left, block);
17767    if (! argtype)
17768      return NULL;
17769  
17770 @@ -524,8 +551,59 @@ typy_str (PyObject *self)
17771  
17772  \f
17773  
17774 +/* Key associated with each objfile pointing to the first element of
17775 +   a doubly-linked list of Types associated with this objfile.  */
17776  static const struct objfile_data *typy_objfile_data_key;
17777  
17778 +/* Link TYPE_OBJ to its appropriate list.  Either to its objfile associated one
17779 +   or at least to the global list for TYPE_DISCARDABLE Types.  Permanent types
17780 +   do not get linked anywhere.  */
17781 +static void
17782 +typy_link (type_object *type_obj)
17783 +{
17784 +  type_obj->prev = NULL;
17785 +
17786 +  if (type_obj->type && TYPE_OBJFILE (type_obj->type))
17787 +    {
17788 +      struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
17789 +
17790 +      type_obj->next = objfile_data (objfile, typy_objfile_data_key);
17791 +      if (type_obj->next)
17792 +       type_obj->next->prev = type_obj;
17793 +      set_objfile_data (objfile, typy_objfile_data_key, type_obj);
17794 +    }
17795 +  else if (type_obj->type && TYPE_DISCARDABLE (type_obj->type))
17796 +    {
17797 +      type_obj->next = pyty_objects_discardable;
17798 +      if (type_obj->next)
17799 +       type_obj->next->prev = type_obj;
17800 +      pyty_objects_discardable = type_obj;
17801 +    }
17802 +  else
17803 +    type_obj->next = NULL;
17804 +}
17805 +
17806 +/* Unlink TYPE_OBJ from its current list.  Permanent types are not linked
17807 +   anywhere and this function has no effect on them.  */
17808 +static void
17809 +typy_unlink (type_object *type_obj)
17810 +{
17811 +  if (type_obj->prev)
17812 +    type_obj->prev->next = type_obj->next;
17813 +  else if (type_obj->type && TYPE_OBJFILE (type_obj->type))
17814 +    {
17815 +      /* Must reset head of list.  */
17816 +      struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
17817 +
17818 +      set_objfile_data (objfile, typy_objfile_data_key, type_obj->next);
17819 +    }
17820 +  else if (pyty_objects_discardable == type_obj)
17821 +    pyty_objects_discardable = type_obj->next;
17822 +
17823 +  if (type_obj->next)
17824 +    type_obj->next->prev = type_obj->prev;
17825 +}
17826 +
17827  static void
17828  save_objfile_types (struct objfile *objfile, void *datum)
17829  {
17830 @@ -543,12 +621,13 @@ save_objfile_types (struct objfile *objfile, void *datum)
17831      {
17832        type_object *next = obj->next;
17833  
17834 -      htab_empty (copied_types);
17835 +      gdb_assert (TYPE_OBJFILE (obj->type) == objfile);
17836 +      typy_unlink (obj);
17837  
17838 -      obj->type = copy_type_recursive (objfile, obj->type, copied_types);
17839 +      obj->type = copy_type_recursive (obj->type, copied_types);
17840  
17841 -      obj->next = NULL;
17842 -      obj->prev = NULL;
17843 +      gdb_assert (TYPE_OBJFILE (obj->type) == NULL);
17844 +      typy_link (obj);
17845  
17846        obj = next;
17847      }
17848 @@ -559,41 +638,25 @@ save_objfile_types (struct objfile *objfile, void *datum)
17849  }
17850  
17851  static void
17852 -set_type (type_object *obj, struct type *type)
17853 +typy_dealloc (PyObject *obj)
17854  {
17855 -  obj->type = type;
17856 -  obj->prev = NULL;
17857 -  if (type && TYPE_OBJFILE (type))
17858 -    {
17859 -      struct objfile *objfile = TYPE_OBJFILE (type);
17860 +  type_object *type_obj = (type_object *) obj;
17861  
17862 -      obj->next = objfile_data (objfile, typy_objfile_data_key);
17863 -      if (obj->next)
17864 -       obj->next->prev = obj;
17865 -      set_objfile_data (objfile, typy_objfile_data_key, obj);
17866 -    }
17867 -  else
17868 -    obj->next = NULL;
17869 +  typy_unlink (type_obj);
17870 +
17871 +  type_obj->ob_type->tp_free (obj);
17872  }
17873  
17874 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
17875  static void
17876 -typy_dealloc (PyObject *obj)
17877 +typy_types_mark_used (void)
17878  {
17879 -  type_object *type = (type_object *) obj;
17880 -
17881 -  if (type->prev)
17882 -    type->prev->next = type->next;
17883 -  else if (type->type && TYPE_OBJFILE (type->type))
17884 -    {
17885 -      /* Must reset head of list.  */
17886 -      struct objfile *objfile = TYPE_OBJFILE (type->type);
17887 -      if (objfile)
17888 -       set_objfile_data (objfile, typy_objfile_data_key, type->next);
17889 -    }
17890 -  if (type->next)
17891 -    type->next->prev = type->prev;
17892 +  type_object *type_obj;
17893  
17894 -  type->ob_type->tp_free (type);
17895 +  for (type_obj = pyty_objects_discardable;
17896 +       type_obj != NULL;
17897 +       type_obj = type_obj->next)
17898 +    type_mark_used (type_obj->type);
17899  }
17900  
17901  /* Create a new Type referring to TYPE.  */
17902 @@ -604,7 +667,10 @@ type_to_type_object (struct type *type)
17903  
17904    type_obj = PyObject_New (type_object, &type_object_type);
17905    if (type_obj)
17906 -    set_type (type_obj, type);
17907 +    {
17908 +      type_obj->type = type;
17909 +      typy_link (type_obj);
17910 +    }
17911  
17912    return (PyObject *) type_obj;
17913  }
17914 @@ -623,14 +689,28 @@ type_object_to_type (PyObject *obj)
17915  PyObject *
17916  gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
17917  {
17918 -  static char *keywords[] = { "name", NULL };
17919 +  static char *keywords[] = { "name", "block", NULL };
17920    char *type_name = NULL;
17921    struct type *type = NULL;
17922 +  PyObject *block_obj = NULL;
17923 +  struct block *block = NULL;
17924  
17925 -  if (! PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &type_name))
17926 +  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
17927 +                                    &type_name, &block_obj))
17928      return NULL;
17929  
17930 -  type = typy_lookup_typename (type_name);
17931 +  if (block_obj)
17932 +    {
17933 +      block = block_object_to_block (block_obj);
17934 +      if (! block)
17935 +       {
17936 +         PyErr_SetString (PyExc_RuntimeError,
17937 +                          "'block' argument must be a Block");
17938 +         return NULL;
17939 +       }
17940 +    }
17941 +
17942 +  type = typy_lookup_typename (type_name, block);
17943    if (! type)
17944      return NULL;
17945  
17946 @@ -664,6 +744,8 @@ gdbpy_initialize_types (void)
17947  
17948    Py_INCREF (&field_object_type);
17949    PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
17950 +
17951 +  observer_attach_mark_used (typy_types_mark_used);
17952  }
17953  
17954  \f
17955 diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
17956 index 49c0437..84a476e 100644
17957 --- a/gdb/python/py-utils.c
17958 +++ b/gdb/python/py-utils.c
17959 @@ -19,6 +19,7 @@
17960  
17961  #include "defs.h"
17962  #include "charset.h"
17963 +#include "value.h"
17964  #include "python-internal.h"
17965  
17966  
17967 @@ -219,3 +220,48 @@ gdbpy_is_string (PyObject *obj)
17968  {
17969    return PyString_Check (obj) || PyUnicode_Check (obj);
17970  }
17971 +
17972 +/* Converts OBJ to a CORE_ADDR value.
17973 +
17974 +   Returns 1 on success or 0 on failure, with a Python exception set.  This
17975 +   function can also throw GDB exceptions.  */
17976 +
17977 +int
17978 +get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
17979 +{
17980 +  if (gdbpy_is_value_object (obj))
17981 +    *addr = value_as_address (value_object_to_value (obj));
17982 +  else if (PyLong_Check (obj))
17983 +    {
17984 +      /* Assume CORE_ADDR corresponds to unsigned long.  */
17985 +      *addr = PyLong_AsUnsignedLong (obj);
17986 +      if (PyErr_Occurred () != NULL)
17987 +       return 0;
17988 +    }
17989 +  else if (PyInt_Check (obj))
17990 +    {
17991 +      long val;
17992 +
17993 +      /* Assume CORE_ADDR corresponds to unsigned long.  */
17994 +      val = PyInt_AsLong (obj);
17995 +
17996 +      if (val >= 0)
17997 +       *addr = val;
17998 +      else
17999 +      {
18000 +       /* If no error ocurred, VAL is indeed negative.  */
18001 +       if (PyErr_Occurred () != NULL)
18002 +         return 0;
18003 +
18004 +       PyErr_SetString (PyExc_ValueError, "negative address");
18005 +       return 0;
18006 +      }
18007 +    }
18008 +  else
18009 +    {
18010 +      PyErr_SetString (PyExc_TypeError, "invalid type for address");
18011 +      return 0;
18012 +    }
18013 +
18014 +  return 1;
18015 +}
18016 diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
18017 index 58bcee3..b2e7b7d 100644
18018 --- a/gdb/python/py-value.c
18019 +++ b/gdb/python/py-value.c
18020 @@ -25,6 +25,7 @@
18021  #include "language.h"
18022  #include "dfp.h"
18023  #include "valprint.h"
18024 +#include "observer.h"
18025  
18026  #ifdef HAVE_PYTHON
18027  
18028 @@ -43,6 +44,10 @@
18029  /* Python's long type corresponds to C's long long type.  */
18030  #define builtin_type_pylong builtin_type (python_gdbarch)->builtin_long_long
18031  
18032 +/* Python's long type corresponds to C's long long type.  Unsigned version.  */
18033 +#define builtin_type_upylong builtin_type \
18034 +  (python_gdbarch)->builtin_unsigned_long_long
18035 +
18036  #define builtin_type_pybool \
18037    language_bool_type (python_language, python_gdbarch)
18038  
18039 @@ -913,7 +918,34 @@ convert_value_from_python (PyObject *obj)
18040         {
18041           LONGEST l = PyLong_AsLongLong (obj);
18042  
18043 -         if (! PyErr_Occurred ())
18044 +         if (PyErr_Occurred ())
18045 +           {
18046 +             /* If the error was an overflow, we can try converting to
18047 +                ULONGEST instead.  */
18048 +             if (PyErr_ExceptionMatches (PyExc_OverflowError))
18049 +               {
18050 +                 PyObject *etype, *evalue, *etraceback, *zero;
18051 +
18052 +                 PyErr_Fetch (&etype, &evalue, &etraceback);
18053 +                 zero = PyInt_FromLong (0);
18054 +
18055 +                 /* Check whether obj is positive.  */
18056 +                 if (PyObject_RichCompareBool (obj, zero, Py_GT) > 0)
18057 +                   {
18058 +                     ULONGEST ul;
18059 +
18060 +                     ul = PyLong_AsUnsignedLongLong (obj);
18061 +                     if (! PyErr_Occurred ())
18062 +                       value = value_from_ulongest (builtin_type_upylong, ul);
18063 +                   }
18064 +                 else
18065 +                   /* There's nothing we can do.  */
18066 +                   PyErr_Restore (etype, evalue, etraceback);
18067 +
18068 +                 Py_DECREF (zero);
18069 +               }
18070 +           }
18071 +         else
18072             value = value_from_longest (builtin_type_pylong, l);
18073         }
18074        else if (PyFloat_Check (obj))
18075 @@ -972,6 +1004,25 @@ gdbpy_history (PyObject *self, PyObject *args)
18076    return value_to_value_object (res_val);
18077  }
18078  
18079 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
18080 +
18081 +static void
18082 +python_types_mark_used (void)
18083 +{
18084 +  value_object *iter;
18085 +
18086 +  for (iter = values_in_python; iter; iter = iter->next)
18087 +    type_mark_used (value_type (iter->value));
18088 +}
18089 +
18090 +/* Returns 1 in OBJ is a gdb.Value object, 0 otherwise.  */
18091 +
18092 +int
18093 +gdbpy_is_value_object (PyObject *obj)
18094 +{
18095 +  return PyObject_TypeCheck (obj, &value_object_type);
18096 +}
18097 +
18098  void
18099  gdbpy_initialize_values (void)
18100  {
18101 @@ -982,6 +1033,8 @@ gdbpy_initialize_values (void)
18102    PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
18103  
18104    values_in_python = NULL;
18105 +
18106 +  observer_attach_mark_used (python_types_mark_used);
18107  }
18108  
18109  \f
18110 diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
18111 index 67a78af..47662d9 100644
18112 --- a/gdb/python/python-internal.h
18113 +++ b/gdb/python/python-internal.h
18114 @@ -61,33 +61,76 @@ typedef int Py_ssize_t;
18115  #define PyEval_ReleaseLock() 0
18116  #endif
18117  
18118 +#include "command.h"
18119 +
18120 +struct block;
18121 +struct symbol;
18122 +struct symtab_and_line;
18123  struct value;
18124  struct language_defn;
18125  
18126  extern PyObject *gdb_module;
18127 +extern PyTypeObject block_object_type;
18128  extern PyTypeObject value_object_type;
18129 +extern PyTypeObject symbol_object_type;
18130 +
18131 +/* Used in python-inferior.c.  */
18132 +typedef struct
18133 +{
18134 +  PyObject_HEAD
18135 +
18136 +  /* The thread we represent.  */
18137 +  struct thread_info *thread;
18138 +
18139 +  /* The Inferior object to which this thread belongs.  */
18140 +  PyObject *inf_obj;
18141 +} thread_object;
18142  
18143  PyObject *gdbpy_history (PyObject *self, PyObject *args);
18144 +PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
18145  PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
18146 +PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
18147  PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
18148 +PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
18149  PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
18150 +PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
18151 +PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
18152  
18153 +PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
18154 +PyObject *symtab_to_symtab_object (struct symtab *symtab);
18155 +PyObject *symbol_to_symbol_object (struct symbol *sym);
18156 +PyObject *block_to_block_object (struct block *block);
18157  PyObject *value_to_value_object (struct value *v);
18158  PyObject *type_to_type_object (struct type *);
18159  PyObject *objfile_to_objfile_object (struct objfile *);
18160 +PyObject *frame_info_to_frame_object (struct frame_info *frame);
18161 +thread_object *create_thread_object (struct thread_info *tp);
18162 +thread_object *find_thread_object (ptid_t ptid);
18163 +PyObject *find_inferior_object (int pid);
18164  
18165  PyObject *objfpy_get_printers (PyObject *, void *);
18166  
18167 +struct block *block_object_to_block (PyObject *obj);
18168 +struct symbol *symbol_object_to_symbol (PyObject *obj);
18169  struct value *value_object_to_value (PyObject *self);
18170  struct value *convert_value_from_python (PyObject *obj);
18171  struct type *type_object_to_type (PyObject *obj);
18172  
18173 +PyObject *gdbpy_get_hook_function (const char *);
18174 +
18175  void gdbpy_initialize_values (void);
18176 +void gdbpy_initialize_breakpoints (void);
18177  void gdbpy_initialize_frames (void);
18178 +void gdbpy_initialize_symtabs (void);
18179  void gdbpy_initialize_commands (void);
18180 +void gdbpy_initialize_symbols (void);
18181  void gdbpy_initialize_types (void);
18182 +void gdbpy_initialize_blocks (void);
18183  void gdbpy_initialize_functions (void);
18184  void gdbpy_initialize_objfile (void);
18185 +void gdbpy_initialize_parameters (void);
18186 +void gdbpy_initialize_thread (void);
18187 +void gdbpy_initialize_inferior (void);
18188  
18189  struct cleanup *make_cleanup_py_decref (PyObject *py);
18190  
18191 @@ -97,6 +140,12 @@ struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
18192  extern struct gdbarch *python_gdbarch;
18193  extern const struct language_defn *python_language;
18194  
18195 +char *gdbpy_parse_command_name (char *text,
18196 +                               struct cmd_list_element ***base_list,
18197 +                               struct cmd_list_element **start_list);
18198 +
18199 +PyObject *gdbpy_parameter_value (enum var_types, void *);
18200 +
18201  /* Use this after a TRY_EXCEPT to throw the appropriate Python
18202     exception.  */
18203  #define GDB_PY_HANDLE_EXCEPTION(Exception)                             \
18204 @@ -107,6 +156,19 @@ extern const struct language_defn *python_language;
18205                              "%s", Exception.message);                  \
18206      } while (0)
18207  
18208 +/* Use this after a TRY_EXCEPT to throw the appropriate Python
18209 +   exception.  This macro is for use inside setter functions.  */
18210 +#define GDB_PY_SET_HANDLE_EXCEPTION(Exception)                         \
18211 +    do {                                                               \
18212 +      if (Exception.reason < 0)                                                \
18213 +        {                                                              \
18214 +         PyErr_Format (Exception.reason == RETURN_QUIT                 \
18215 +                       ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, \
18216 +                       "%s", Exception.message);                       \
18217 +         return -1;                                                    \
18218 +       }                                                               \
18219 +    } while (0)
18220 +
18221  
18222  void gdbpy_print_stack (void);
18223  
18224 @@ -118,17 +180,22 @@ char *python_string_to_host_string (PyObject *obj);
18225  PyObject *target_string_to_unicode (const gdb_byte *str, int length);
18226  int gdbpy_is_string (PyObject *obj);
18227  
18228 +int gdbpy_is_value_object (PyObject *obj);
18229 +
18230  /* Note that these are declared here, and not in python.h with the
18231     other pretty-printer functions, because they refer to PyObject.  */
18232  PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
18233                                        struct value **replacement);
18234  PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
18235 +PyObject *gdbpy_instantiate_printer (PyObject *cons, PyObject *value);
18236  char *gdbpy_get_display_hint (PyObject *printer);
18237  PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
18238  
18239 -extern PyObject *gdbpy_doc_cst;
18240  extern PyObject *gdbpy_children_cst;
18241  extern PyObject *gdbpy_to_string_cst;
18242  extern PyObject *gdbpy_display_hint_cst;
18243 +extern PyObject *gdbpy_doc_cst;
18244 +
18245 +int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
18246  
18247  #endif /* GDB_PYTHON_INTERNAL_H */
18248 diff --git a/gdb/python/python.c b/gdb/python/python.c
18249 index 254bd28..5a2a9ae 100644
18250 --- a/gdb/python/python.c
18251 +++ b/gdb/python/python.c
18252 @@ -27,6 +27,7 @@
18253  #include "observer.h"
18254  #include "value.h"
18255  #include "language.h"
18256 +#include "event-loop.h"
18257  
18258  #include <ctype.h>
18259  
18260 @@ -45,11 +46,18 @@ static int gdbpy_auto_load = 1;
18261  #include "cli/cli-decode.h"
18262  #include "charset.h"
18263  #include "top.h"
18264 +#include "solib.h"
18265  #include "exceptions.h"
18266  #include "python-internal.h"
18267 +#include "linespec.h"
18268 +#include "symtab.h"
18269 +#include "source.h"
18270  #include "version.h"
18271 +#include "inferior.h"
18272 +#include "gdbthread.h"
18273  #include "target.h"
18274  #include "gdbthread.h"
18275 +#include "event-top.h"
18276  
18277  static PyMethodDef GdbMethods[];
18278  
18279 @@ -197,10 +205,10 @@ python_command (char *arg, int from_tty)
18280     NULL (and set a Python exception) on error.  Helper function for
18281     get_parameter.  */
18282  
18283 -static PyObject *
18284 -parameter_to_python (struct cmd_list_element *cmd)
18285 +PyObject *
18286 +gdbpy_parameter_value (enum var_types type, void *var)
18287  {
18288 -  switch (cmd->var_type)
18289 +  switch (type)
18290      {
18291      case var_string:
18292      case var_string_noescape:
18293 @@ -208,7 +216,7 @@ parameter_to_python (struct cmd_list_element *cmd)
18294      case var_filename:
18295      case var_enum:
18296        {
18297 -       char *str = * (char **) cmd->var;
18298 +       char *str = * (char **) var;
18299         if (! str)
18300           str = "";
18301         return PyString_Decode (str, strlen (str), host_charset (), NULL);
18302 @@ -216,7 +224,7 @@ parameter_to_python (struct cmd_list_element *cmd)
18303  
18304      case var_boolean:
18305        {
18306 -       if (* (int *) cmd->var)
18307 +       if (* (int *) var)
18308           Py_RETURN_TRUE;
18309         else
18310           Py_RETURN_FALSE;
18311 @@ -224,7 +232,7 @@ parameter_to_python (struct cmd_list_element *cmd)
18312  
18313      case var_auto_boolean:
18314        {
18315 -       enum auto_boolean ab = * (enum auto_boolean *) cmd->var;
18316 +       enum auto_boolean ab = * (enum auto_boolean *) var;
18317         if (ab == AUTO_BOOLEAN_TRUE)
18318           Py_RETURN_TRUE;
18319         else if (ab == AUTO_BOOLEAN_FALSE)
18320 @@ -234,15 +242,15 @@ parameter_to_python (struct cmd_list_element *cmd)
18321        }
18322  
18323      case var_integer:
18324 -      if ((* (int *) cmd->var) == INT_MAX)
18325 +      if ((* (int *) var) == INT_MAX)
18326         Py_RETURN_NONE;
18327        /* Fall through.  */
18328      case var_zinteger:
18329 -      return PyLong_FromLong (* (int *) cmd->var);
18330 +      return PyLong_FromLong (* (int *) var);
18331  
18332      case var_uinteger:
18333        {
18334 -       unsigned int val = * (unsigned int *) cmd->var;
18335 +       unsigned int val = * (unsigned int *) var;
18336         if (val == UINT_MAX)
18337           Py_RETURN_NONE;
18338         return PyLong_FromUnsignedLong (val);
18339 @@ -280,7 +288,7 @@ gdbpy_parameter (PyObject *self, PyObject *args)
18340  
18341    if (! cmd->var)
18342      return PyErr_Format (PyExc_RuntimeError, "`%s' is not a parameter", arg);
18343 -  return parameter_to_python (cmd);
18344 +  return gdbpy_parameter_value (cmd->var_type, cmd->var);
18345  }
18346  
18347  /* A Python function which evaluates a string using the gdb CLI.  */
18348 @@ -319,6 +327,233 @@ execute_gdb_command (PyObject *self, PyObject *args)
18349    Py_RETURN_NONE;
18350  }
18351  
18352 +/* Implementation of gdb.solib_address (Long) -> String.
18353 +   Returns the name of the shared library holding a given address, or None.  */
18354 +
18355 +static PyObject *
18356 +gdbpy_solib_address (PyObject *self, PyObject *args)
18357 +{
18358 +  unsigned long long pc;
18359 +  char *soname;
18360 +  PyObject *str_obj;
18361 +
18362 +  if (!PyArg_ParseTuple (args, "K", &pc))
18363 +    return NULL;
18364 +
18365 +  soname = solib_name_from_address (pc);
18366 +  if (soname)
18367 +    str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
18368 +  else
18369 +    {
18370 +      str_obj = Py_None;
18371 +      Py_INCREF (Py_None);
18372 +    }
18373 +
18374 +  return str_obj;
18375 +}
18376 +
18377 +/* A Python function which is a wrapper for decode_line_1.  */
18378 +
18379 +static PyObject *
18380 +gdbpy_decode_line (PyObject *self, PyObject *args)
18381 +{
18382 +  struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc.  */
18383 +  struct symtab_and_line sal;
18384 +  char *arg = NULL;
18385 +  int free_sals = 0, i;
18386 +  PyObject *result = NULL;
18387 +  volatile struct gdb_exception except;
18388 +
18389 +  if (! PyArg_ParseTuple (args, "|s", &arg))
18390 +    return NULL;
18391 +
18392 +  TRY_CATCH (except, RETURN_MASK_ALL)
18393 +    {
18394 +      if (arg)
18395 +       {
18396 +         char *copy;
18397 +
18398 +         arg = strdup (arg);
18399 +         copy = arg;
18400 +
18401 +         sals = decode_line_1 (&copy, 0, 0, 0, 0, 0);
18402 +         free_sals = 1;
18403 +       }
18404 +      else
18405 +       {
18406 +         set_default_source_symtab_and_line ();
18407 +         sal = get_current_source_symtab_and_line ();
18408 +         sals.sals = &sal;
18409 +         sals.nelts = 1;
18410 +       }
18411 +    }
18412 +  if (arg)
18413 +    xfree (arg);
18414 +
18415 +  if (except.reason < 0)
18416 +    {
18417 +      if (free_sals)
18418 +       xfree (sals.sals);
18419 +      /* We know this will always throw.  */
18420 +      GDB_PY_HANDLE_EXCEPTION (except);
18421 +    }
18422 +
18423 +  if (sals.nelts)
18424 +    {
18425 +      result = PyTuple_New (sals.nelts);
18426 +      for (i = 0; i < sals.nelts; ++i)
18427 +       {
18428 +         PyObject *obj;
18429 +         char *str;
18430 +
18431 +         obj = symtab_and_line_to_sal_object (sals.sals[i]);
18432 +         if (! obj)
18433 +           {
18434 +             Py_DECREF (result);
18435 +             result = NULL;
18436 +             break;
18437 +           }
18438 +
18439 +         PyTuple_SetItem (result, i, obj);
18440 +       }
18441 +    }
18442 +
18443 +  if (free_sals)
18444 +    xfree (sals.sals);
18445 +
18446 +  if (result)
18447 +    return result;
18448 +  Py_RETURN_NONE;
18449 +}
18450 +
18451 +/* Parse a string and evaluate it as an expression.  */
18452 +static PyObject *
18453 +gdbpy_parse_and_eval (PyObject *self, PyObject *args)
18454 +{
18455 +  char *expr_str;
18456 +  struct value *result = NULL;
18457 +  volatile struct gdb_exception except;
18458 +
18459 +  if (!PyArg_ParseTuple (args, "s", &expr_str))
18460 +    return NULL;
18461 +
18462 +  TRY_CATCH (except, RETURN_MASK_ALL)
18463 +    {
18464 +      result = parse_and_eval (expr_str);
18465 +    }
18466 +  GDB_PY_HANDLE_EXCEPTION (except);
18467 +
18468 +  return value_to_value_object (result);
18469 +}
18470 +
18471 +\f
18472 +
18473 +/* Posting and handling events.  */
18474 +
18475 +/* A single event.  */
18476 +struct gdbpy_event
18477 +{
18478 +  /* The Python event.  This is just a callable object.  */
18479 +  PyObject *event;
18480 +  /* The next event.  */
18481 +  struct gdbpy_event *next;
18482 +};
18483 +
18484 +/* All pending events.  */
18485 +static struct gdbpy_event *gdbpy_event_list;
18486 +/* The final link of the event list.  */
18487 +static struct gdbpy_event **gdbpy_event_list_end;
18488 +
18489 +/* We use a file handler, and not an async handler, so that we can
18490 +   wake up the main thread even when it is blocked in poll().  */
18491 +static int gdbpy_event_fds[2];
18492 +
18493 +/* The file handler callback.  This reads from the internal pipe, and
18494 +   then processes the Python event queue.  This will always be run in
18495 +   the main gdb thread.  */
18496 +static void
18497 +gdbpy_run_events (int err, gdb_client_data ignore)
18498 +{
18499 +  PyGILState_STATE state;
18500 +  char buffer[100];
18501 +  int r;
18502 +
18503 +  state = PyGILState_Ensure ();
18504 +
18505 +  /* Just read whatever is available on the fd.  It is relatively
18506 +     harmless if there are any bytes left over.  */
18507 +  r = read (gdbpy_event_fds[0], buffer, sizeof (buffer));
18508 +
18509 +  while (gdbpy_event_list)
18510 +    {
18511 +      /* Dispatching the event might push a new element onto the event
18512 +        loop, so we update here "atomically enough".  */
18513 +      struct gdbpy_event *item = gdbpy_event_list;
18514 +      gdbpy_event_list = gdbpy_event_list->next;
18515 +      if (gdbpy_event_list == NULL)
18516 +       gdbpy_event_list_end = &gdbpy_event_list;
18517 +
18518 +      /* Ignore errors.  */
18519 +      PyObject_CallObject (item->event, NULL);
18520 +
18521 +      Py_DECREF (item->event);
18522 +      xfree (item);
18523 +    }
18524 +
18525 +  PyGILState_Release (state);
18526 +}
18527 +
18528 +/* Submit an event to the gdb thread.  */
18529 +static PyObject *
18530 +gdbpy_post_event (PyObject *self, PyObject *args)
18531 +{
18532 +  struct gdbpy_event *event;
18533 +  PyObject *func;
18534 +  int wakeup;
18535 +
18536 +  if (!PyArg_ParseTuple (args, "O", &func))
18537 +    return NULL;
18538 +
18539 +  if (!PyCallable_Check (func))
18540 +    {
18541 +      PyErr_SetString (PyExc_RuntimeError, "Posted event is not callable");
18542 +      return NULL;
18543 +    }
18544 +
18545 +  Py_INCREF (func);
18546 +
18547 +  /* From here until the end of the function, we have the GIL, so we
18548 +     can operate on our global data structures without worrying.  */
18549 +  wakeup = gdbpy_event_list == NULL;
18550 +
18551 +  event = XNEW (struct gdbpy_event);
18552 +  event->event = func;
18553 +  event->next = NULL;
18554 +  *gdbpy_event_list_end = event;
18555 +  gdbpy_event_list_end = &event->next;
18556 +
18557 +  /* Wake up gdb when needed.  */
18558 +  if (wakeup)
18559 +    {
18560 +      char c = 'q';            /* Anything. */
18561 +      if (write (gdbpy_event_fds[1], &c, 1) != 1)
18562 +        return PyErr_SetFromErrno (PyExc_IOError);
18563 +    }
18564 +
18565 +  Py_RETURN_NONE;
18566 +}
18567 +
18568 +/* Initialize the Python event handler.  */
18569 +static void
18570 +gdbpy_initialize_events (void)
18571 +{
18572 +  if (!pipe (gdbpy_event_fds))
18573 +    {
18574 +      gdbpy_event_list_end = &gdbpy_event_list;
18575 +      add_file_handler (gdbpy_event_fds[0], gdbpy_run_events, NULL);
18576 +    }
18577 +}
18578 +
18579  \f
18580  
18581  /* Printing.  */
18582 @@ -357,6 +592,69 @@ gdbpy_print_stack (void)
18583  
18584  \f
18585  
18586 +/* Script interface.  */
18587 +
18588 +/* True if 'gdb -P' was used, false otherwise.  */
18589 +static int running_python_script;
18590 +
18591 +/* True if we are currently in a call to 'gdb.cli', false otherwise.  */
18592 +static int in_cli;
18593 +
18594 +/* Enter the command loop.  */
18595 +
18596 +static PyObject *
18597 +gdbpy_cli (PyObject *unused1, PyObject *unused2)
18598 +{
18599 +  if (! running_python_script || in_cli)
18600 +    return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively");
18601 +
18602 +  in_cli = 1;
18603 +  cli_command_loop ();
18604 +  in_cli = 0;
18605 +
18606 +  Py_RETURN_NONE;
18607 +}
18608 +
18609 +/* Set up the Python argument vector and evaluate a script.  This is
18610 +   used to implement 'gdb -P'.  */
18611 +
18612 +void
18613 +run_python_script (int argc, char **argv)
18614 +{
18615 +  FILE *input;
18616 +  PyGILState_STATE state;
18617 +
18618 +  /* We never free this, since we plan to exit at the end.  */
18619 +  state = PyGILState_Ensure ();
18620 +
18621 +  running_python_script = 1;
18622 +  PySys_SetArgv (argc - 1, argv + 1);
18623 +  input = fopen (argv[0], "r");
18624 +  if (! input)
18625 +    {
18626 +      fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno));
18627 +      exit (1);
18628 +    }
18629 +  PyRun_SimpleFile (input, argv[0]);
18630 +  fclose (input);
18631 +  exit (0);
18632 +}
18633 +
18634 +void
18635 +source_python_script (FILE *stream, char *file)
18636 +{
18637 +  PyGILState_STATE state;
18638 +
18639 +  state = PyGILState_Ensure ();
18640 +
18641 +  PyRun_SimpleFile (stream, file);
18642 +
18643 +  fclose (stream);
18644 +  PyGILState_Release (state);
18645 +}
18646 +
18647 +\f
18648 +
18649  /* The "current" objfile.  This is set when gdb detects that a new
18650     objfile has been loaded.  It is only set for the duration of a call
18651     to gdbpy_new_objfile; it is NULL at other times.  */
18652 @@ -501,6 +799,13 @@ eval_python_from_control_command (struct command_line *cmd)
18653    error (_("Python scripting is not supported in this copy of GDB."));
18654  }
18655  
18656 +void
18657 +source_python_script (FILE *stream)
18658 +{
18659 +  fclose (stream);
18660 +  error (_("Python scripting is not supported in this copy of GDB."));
18661 +}
18662 +
18663  #endif /* HAVE_PYTHON */
18664  
18665  \f
18666 @@ -592,13 +897,27 @@ Enables or disables auto-loading of Python code when an object is opened."),
18667    PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version);
18668    PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
18669    PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", (char*) target_name);
18670 +#ifdef PYTHONDIR
18671 +  PyModule_AddStringConstant (gdb_module, "pythondir", PYTHONDIR);
18672 +#else
18673 +  if (gdb_datadir)
18674 +    PyModule_AddStringConstant (gdb_module, "datadir", gdb_datadir);
18675 +#endif
18676  
18677    gdbpy_initialize_values ();
18678 +  gdbpy_initialize_breakpoints ();
18679    gdbpy_initialize_frames ();
18680 +  gdbpy_initialize_symtabs ();
18681    gdbpy_initialize_commands ();
18682 +  gdbpy_initialize_symbols ();
18683 +  gdbpy_initialize_blocks ();
18684    gdbpy_initialize_functions ();
18685    gdbpy_initialize_types ();
18686 +  gdbpy_initialize_parameters ();
18687    gdbpy_initialize_objfile ();
18688 +  gdbpy_initialize_thread ();
18689 +  gdbpy_initialize_inferior ();
18690 +  gdbpy_initialize_events ();
18691  
18692    PyRun_SimpleString ("import gdb");
18693    PyRun_SimpleString ("gdb.pretty_printers = []");
18694 @@ -634,6 +953,15 @@ class GdbOutputFile:\n\
18695  \n\
18696  sys.stderr = GdbOutputFile()\n\
18697  sys.stdout = GdbOutputFile()\n\
18698 +if hasattr (gdb, 'datadir'):\n\
18699 +  gdb.pythondir = gdb.datadir + '/python'\n\
18700 +if hasattr (gdb, 'pythondir'):\n\
18701 +  sys.path.insert(0, gdb.pythondir)\n\
18702 +  gdb.__path__ = [gdb.pythondir + '/gdb']\n\
18703 +  from os.path import exists\n\
18704 +  ipy = gdb.pythondir + '/gdb/__init__.py'\n\
18705 +  if exists (ipy):\n\
18706 +    execfile (ipy)\n\
18707  ");
18708  
18709    /* Release the GIL while gdb runs.  */
18710 @@ -653,9 +981,14 @@ static PyMethodDef GdbMethods[] =
18711      "Get a value from history" },
18712    { "execute", execute_gdb_command, METH_VARARGS,
18713      "Execute a gdb command" },
18714 +  { "cli", gdbpy_cli, METH_NOARGS,
18715 +    "Enter the gdb CLI" },
18716    { "parameter", gdbpy_parameter, METH_VARARGS,
18717      "Return a gdb parameter's value" },
18718  
18719 +  { "breakpoints", gdbpy_breakpoints, METH_NOARGS,
18720 +    "Return a tuple of all breakpoint objects" },
18721 +
18722    { "default_visualizer", gdbpy_default_visualizer, METH_VARARGS,
18723      "Find the default visualizer for a Value." },
18724  
18725 @@ -676,6 +1009,37 @@ Return a string explaining unwind stop reason." },
18726      "lookup_type (name [, block]) -> type\n\
18727  Return a Type corresponding to the given name." },
18728  
18729 +  { "lookup_symbol", (PyCFunction) gdbpy_lookup_symbol,
18730 +    METH_VARARGS | METH_KEYWORDS,
18731 +    "lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)\n\
18732 +Return a tuple with the symbol corresponding to the given name (or None) and\n\
18733 +a boolean indicating if name is a field of the current implied argument\n\
18734 +`this' (when the current language is object-oriented)." },
18735 +  { "solib_address", gdbpy_solib_address, METH_VARARGS,
18736 +    "solib_address (Long) -> String.\n\
18737 +Return the name of the shared library holding a given address, or None." },
18738 +
18739 +  { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
18740 +    "Return the block containing the given pc value, or None." },
18741 +
18742 +  { "decode_line", gdbpy_decode_line, METH_VARARGS,
18743 +    "Decode a string argument the way that 'break' or 'edit' does.\n\
18744 +Return a tuple holding the file name (or None) and line number (or None).\n\
18745 +Note: may later change to return an object." },
18746 +
18747 +  { "selected_thread", gdbpy_selected_thread, METH_NOARGS,
18748 +    "selected_thread () -> gdb.InferiorThread.\n\
18749 +Return the selected thread object." },
18750 +  { "inferiors", gdbpy_inferiors, METH_NOARGS,
18751 +    "inferiors () -> (gdb.Inferior, ...).\n\
18752 +Return a tuple containing all inferiors." },
18753 +
18754 +  { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
18755 +    "Parse a string as an expression, evaluate it, and return the result." },
18756 +
18757 +  { "post_event", gdbpy_post_event, METH_VARARGS,
18758 +    "Post an event into gdb's event loop." },
18759 +
18760    { "write", gdbpy_write, METH_VARARGS,
18761      "Write a string using gdb's filtered stream." },
18762    { "flush", gdbpy_flush, METH_NOARGS,
18763 diff --git a/gdb/python/python.h b/gdb/python/python.h
18764 index e970180..bbb6184 100644
18765 --- a/gdb/python/python.h
18766 +++ b/gdb/python/python.h
18767 @@ -24,6 +24,10 @@
18768  
18769  void eval_python_from_control_command (struct command_line *);
18770  
18771 +void source_python_script (FILE *stream, char *file);
18772 +
18773 +void run_python_script (int argc, char **argv);
18774 +
18775  int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
18776                               int embedded_offset, CORE_ADDR address,
18777                               struct ui_file *stream, int recurse,
18778 diff --git a/gdb/scm-lang.c b/gdb/scm-lang.c
18779 index de34894..07518b0 100644
18780 --- a/gdb/scm-lang.c
18781 +++ b/gdb/scm-lang.c
18782 @@ -233,6 +233,7 @@ const struct exp_descriptor exp_descriptor_scm =
18783  {
18784    print_subexp_standard,
18785    operator_length_standard,
18786 +  operator_check_standard,
18787    op_name_standard,
18788    dump_subexp_body_standard,
18789    evaluate_exp
18790 diff --git a/gdb/scm-valprint.c b/gdb/scm-valprint.c
18791 index cc3319a..d0d4702 100644
18792 --- a/gdb/scm-valprint.c
18793 +++ b/gdb/scm-valprint.c
18794 @@ -62,9 +62,9 @@ scm_inferior_print (struct type *type, LONGEST value, struct ui_file *stream,
18795      {
18796        /* XXX: Should we cache these symbols?  */
18797        gdb_output_sym =
18798 -       lookup_symbol_global ("gdb_output", NULL, NULL, VAR_DOMAIN);
18799 +       lookup_symbol_global ("gdb_output", NULL, VAR_DOMAIN);
18800        gdb_output_len_sym =
18801 -       lookup_symbol_global ("gdb_output_length", NULL, NULL, VAR_DOMAIN);
18802 +       lookup_symbol_global ("gdb_output_length", NULL, VAR_DOMAIN);
18803  
18804        if ((gdb_output_sym == NULL) || (gdb_output_len_sym == NULL))
18805         ret = -1;
18806 diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
18807 index 8b96a6f..9428d92 100644
18808 --- a/gdb/solib-darwin.c
18809 +++ b/gdb/solib-darwin.c
18810 @@ -389,7 +389,6 @@ darwin_relocate_section_addresses (struct so_list *so,
18811  static struct symbol *
18812  darwin_lookup_lib_symbol (const struct objfile *objfile,
18813                           const char *name,
18814 -                         const char *linkage_name,
18815                           const domain_enum domain)
18816  {
18817    return NULL;
18818 diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
18819 index 19e3212..9f06fa9 100644
18820 --- a/gdb/solib-spu.c
18821 +++ b/gdb/solib-spu.c
18822 @@ -334,16 +334,13 @@ spu_bfd_open (char *pathname)
18823  static struct symbol *
18824  spu_lookup_lib_symbol (const struct objfile *objfile,
18825                        const char *name,
18826 -                      const char *linkage_name,
18827                        const domain_enum domain)
18828  {
18829    if (bfd_get_arch (objfile->obfd) == bfd_arch_spu)
18830 -    return lookup_global_symbol_from_objfile (objfile, name, linkage_name,
18831 -                                             domain);
18832 +    return lookup_global_symbol_from_objfile (objfile, name, domain);
18833  
18834    if (svr4_so_ops.lookup_lib_global_symbol != NULL)
18835 -    return svr4_so_ops.lookup_lib_global_symbol (objfile, name, linkage_name,
18836 -                                                domain);
18837 +    return svr4_so_ops.lookup_lib_global_symbol (objfile, name, domain);
18838    return NULL;
18839  }
18840  
18841 diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
18842 index 6cfaa85..68aadc0 100644
18843 --- a/gdb/solib-svr4.c
18844 +++ b/gdb/solib-svr4.c
18845 @@ -1908,15 +1908,13 @@ struct target_so_ops svr4_so_ops;
18846  static struct symbol *
18847  elf_lookup_lib_symbol (const struct objfile *objfile,
18848                        const char *name,
18849 -                      const char *linkage_name,
18850                        const domain_enum domain)
18851  {
18852    if (objfile->obfd == NULL
18853       || scan_dyntag (DT_SYMBOLIC, objfile->obfd, NULL) != 1)
18854      return NULL;
18855  
18856 -  return lookup_global_symbol_from_objfile
18857 -               (objfile, name, linkage_name, domain);
18858 +  return lookup_global_symbol_from_objfile (objfile, name, domain);
18859  }
18860  
18861  extern initialize_file_ftype _initialize_svr4_solib; /* -Wmissing-prototypes */
18862 diff --git a/gdb/solib.c b/gdb/solib.c
18863 index a2ad0c4..3574e62 100644
18864 --- a/gdb/solib.c
18865 +++ b/gdb/solib.c
18866 @@ -1127,13 +1127,12 @@ show_auto_solib_add (struct ui_file *file, int from_tty,
18867  struct symbol *
18868  solib_global_lookup (const struct objfile *objfile,
18869                      const char *name,
18870 -                    const char *linkage_name,
18871                      const domain_enum domain)
18872  {
18873    struct target_so_ops *ops = solib_ops (target_gdbarch);
18874  
18875    if (ops->lookup_lib_global_symbol != NULL)
18876 -    return ops->lookup_lib_global_symbol (objfile, name, linkage_name, domain);
18877 +    return ops->lookup_lib_global_symbol (objfile, name, domain);
18878    return NULL;
18879  }
18880  
18881 diff --git a/gdb/solist.h b/gdb/solist.h
18882 index 63a6ba0..005e8f7 100644
18883 --- a/gdb/solist.h
18884 +++ b/gdb/solist.h
18885 @@ -114,7 +114,6 @@ struct target_so_ops
18886      /* Hook for looking up global symbols in a library-specific way.  */
18887      struct symbol * (*lookup_lib_global_symbol) (const struct objfile *objfile,
18888                                                  const char *name,
18889 -                                                const char *linkage_name,
18890                                                  const domain_enum domain);
18891  
18892      /* Given two so_list objects, one from the GDB thread list
18893 @@ -146,7 +145,6 @@ extern struct target_so_ops *current_target_so_ops;
18894  /* Handler for library-specific global symbol lookup in solib.c.  */
18895  struct symbol *solib_global_lookup (const struct objfile *objfile,
18896                                     const char *name,
18897 -                                   const char *linkage_name,
18898                                     const domain_enum domain);
18899  
18900  #endif
18901 diff --git a/gdb/somread.c b/gdb/somread.c
18902 index 36a2b28..4d5bda9 100644
18903 --- a/gdb/somread.c
18904 +++ b/gdb/somread.c
18905 @@ -435,6 +435,7 @@ static struct sym_fns som_sym_fns =
18906    som_new_init,                        /* sym_new_init: init anything gbl to entire symtab */
18907    som_symfile_init,            /* sym_init: read initial info, setup for sym_read() */
18908    som_symfile_read,            /* sym_read: read a symbol file into symtab */
18909 +  NULL,                                /* sym_read_psymbols */
18910    som_symfile_finish,          /* sym_finish: finished with file, cleanup */
18911    som_symfile_offsets,         /* sym_offsets:  Translate ext. to int. relocation */
18912    default_symfile_segments,    /* sym_segments: Get segment information from
18913 diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
18914 index 7e7ab9c..a014b7a 100644
18915 --- a/gdb/spu-tdep.c
18916 +++ b/gdb/spu-tdep.c
18917 @@ -1839,7 +1839,7 @@ spu_catch_start (struct objfile *objfile)
18918        struct symbol *sym;
18919        struct symtab_and_line sal;
18920  
18921 -      sym = lookup_block_symbol (block, "main", NULL, VAR_DOMAIN);
18922 +      sym = lookup_block_symbol (block, "main", VAR_DOMAIN);
18923        if (sym)
18924         {
18925           fixup_symbol_section (sym, objfile);
18926 diff --git a/gdb/stabsread.c b/gdb/stabsread.c
18927 index e62bb15..ad6568e 100644
18928 --- a/gdb/stabsread.c
18929 +++ b/gdb/stabsread.c
18930 @@ -322,7 +322,7 @@ dbx_alloc_type (int typenums[2], struct objfile *objfile)
18931  
18932    if (typenums[0] == -1)
18933      {
18934 -      return (alloc_type (objfile));
18935 +      return (alloc_type (objfile, NULL));
18936      }
18937  
18938    type_addr = dbx_lookup_type (typenums, objfile);
18939 @@ -332,7 +332,7 @@ dbx_alloc_type (int typenums[2], struct objfile *objfile)
18940       We will fill it in later if we find out how.  */
18941    if (*type_addr == 0)
18942      {
18943 -      *type_addr = alloc_type (objfile);
18944 +      *type_addr = alloc_type (objfile, NULL);
18945      }
18946  
18947    return (*type_addr);
18948 diff --git a/gdb/stack.c b/gdb/stack.c
18949 index 1c37801..594eb16 100644
18950 --- a/gdb/stack.c
18951 +++ b/gdb/stack.c
18952 @@ -1308,24 +1308,24 @@ backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
18953    else
18954      count = -1;
18955  
18956 -  if (info_verbose)
18957 -    {
18958 -      struct partial_symtab *ps;
18959 -
18960 -      /* Read in symbols for all of the frames.  Need to do this in a
18961 -         separate pass so that "Reading in symbols for xxx" messages
18962 -         don't screw up the appearance of the backtrace.  Also if
18963 -         people have strong opinions against reading symbols for
18964 -         backtrace this may have to be an option.  */
18965 -      i = count;
18966 -      for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
18967 -       {
18968 -         QUIT;
18969 -         ps = find_pc_psymtab (get_frame_address_in_block (fi));
18970 -         if (ps)
18971 -           PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in.  */
18972 -       }
18973 -    }
18974 +  {
18975 +    struct partial_symtab *ps;
18976 +
18977 +    /* Read in symbols for all of the frames.  Need to do this
18978 +       unconditionally to ensure that psymbols are read.  Also need to
18979 +       do this in a separate pass so that "Reading in symbols for xxx"
18980 +       messages don't screw up the appearance of the backtrace.  Also
18981 +       if people have strong opinions against reading symbols for
18982 +       backtrace this may have to be an option.  */
18983 +    i = count;
18984 +    for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
18985 +      {
18986 +       QUIT;
18987 +       ps = find_pc_psymtab (get_frame_address_in_block (fi));
18988 +       if (info_verbose && ps)
18989 +         PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in.  */
18990 +      }
18991 +  }
18992  
18993    for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
18994      {
18995 @@ -1473,6 +1473,8 @@ print_block_frame_locals (struct block *b, struct frame_info *frame,
18996         case LOC_COMPUTED:
18997           if (SYMBOL_IS_ARGUMENT (sym))
18998             break;
18999 +         if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
19000 +           break;
19001           values_printed = 1;
19002           print_variable_and_value (NULL, sym, frame, stream, 4 * num_tabs);
19003           break;
19004 diff --git a/gdb/symfile.c b/gdb/symfile.c
19005 index 2458201..c31b72a 100644
19006 --- a/gdb/symfile.c
19007 +++ b/gdb/symfile.c
19008 @@ -921,6 +921,17 @@ new_symfile_objfile (struct objfile *objfile, int add_flags)
19009    clear_complaints (&symfile_complaints, 0, add_flags & SYMFILE_VERBOSE);
19010  }
19011  
19012 +/* A helper function which returns true if OBJFILE has any debug
19013 +   symbols, and false otherwise.  */
19014 +static int
19015 +has_any_debug_symbols (struct objfile *objfile)
19016 +{
19017 +  return (objfile->psymtabs || objfile->quick_addrmap
19018 +         || (objfile->separate_debug_objfile
19019 +             && (objfile->separate_debug_objfile->psymtabs
19020 +                 || objfile->separate_debug_objfile->quick_addrmap)));
19021 +}
19022 +
19023  /* Process a symbol file, as either the main file or as a dynamically
19024     loaded file.
19025  
19026 @@ -958,13 +969,16 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19027    /* Give user a chance to burp if we'd be
19028       interactively wiping out any existing symbols.  */
19029  
19030 -  if ((have_full_symbols () || have_partial_symbols ())
19031 -      && (add_flags & SYMFILE_MAINLINE)
19032 +  if ((add_flags & SYMFILE_MAINLINE)
19033 +      && (have_full_symbols () || have_partial_symbols ())
19034        && from_tty
19035 +      && (have_full_symbols () || have_partial_symbols ())
19036        && !query (_("Load new symbol table from \"%s\"? "), name))
19037      error (_("Not confirmed."));
19038  
19039    objfile = allocate_objfile (abfd, flags);
19040 +  if (add_flags & SYMFILE_MAINLINE)
19041 +    objfile->flags |= OBJF_MAIN;
19042    discard_cleanups (my_cleanups);
19043  
19044    if (addrs)
19045 @@ -997,6 +1011,8 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19046  
19047    if ((flags & OBJF_READNOW) || readnow_symbol_files)
19048      {
19049 +      require_partial_symbols (objfile);
19050 +
19051        if (from_tty || info_verbose)
19052         {
19053           printf_unfiltered (_("expanding to full symbols..."));
19054 @@ -1015,7 +1031,7 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19055    /* If the file has its own symbol tables it has no separate debug info.
19056       `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to SYMTABS/PSYMTABS.
19057       `.gnu_debuglink' may no longer be present with `.note.gnu.build-id'.  */
19058 -  if (objfile->psymtabs == NULL)
19059 +  if (!has_any_debug_symbols (objfile))
19060      debugfile = find_separate_debug_file (objfile);
19061    if (debugfile)
19062      {
19063 @@ -1039,9 +1055,10 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19064        xfree (debugfile);
19065      }
19066  
19067 +  /* has_any_debug_symbols is not fully compatible with the former calls which
19068 +     would just be needlessly expensive here.  */
19069    if ((from_tty || info_verbose)
19070 -      && !objfile_has_partial_symbols (objfile)
19071 -      && !objfile_has_full_symbols (objfile))
19072 +      && !has_any_debug_symbols (objfile))
19073      {
19074        wrap_here ("");
19075        printf_unfiltered (_("(no debugging symbols found)..."));
19076 @@ -2422,14 +2439,15 @@ reread_symbols (void)
19077                  zero is OK since dbxread.c also does what it needs to do if
19078                  objfile->global_psymbols.size is 0.  */
19079               (*objfile->sf->sym_read) (objfile, 0);
19080 -             if (!objfile_has_partial_symbols (objfile)
19081 -                 && !objfile_has_full_symbols (objfile))
19082 +             if (!has_any_debug_symbols (objfile))
19083                 {
19084                   wrap_here ("");
19085                   printf_unfiltered (_("(no debugging symbols found)\n"));
19086                   wrap_here ("");
19087                 }
19088  
19089 +             objfile->flags &= ~OBJF_SYMTABS_READ;
19090 +
19091               /* We're done reading the symbol file; finish off complaints.  */
19092               clear_complaints (&symfile_complaints, 0, 1);
19093  
19094 @@ -2727,7 +2745,7 @@ allocate_symtab (char *filename, struct objfile *objfile)
19095  }
19096  
19097  struct partial_symtab *
19098 -allocate_psymtab (char *filename, struct objfile *objfile)
19099 +allocate_psymtab (const char *filename, struct objfile *objfile)
19100  {
19101    struct partial_symtab *psymtab;
19102  
19103 @@ -3041,7 +3059,8 @@ again2:
19104  
19105  struct partial_symtab *
19106  start_psymtab_common (struct objfile *objfile,
19107 -                     struct section_offsets *section_offsets, char *filename,
19108 +                     struct section_offsets *section_offsets,
19109 +                     const char *filename,
19110                       CORE_ADDR textlow, struct partial_symbol **global_syms,
19111                       struct partial_symbol **static_syms)
19112  {
19113 diff --git a/gdb/symfile.h b/gdb/symfile.h
19114 index 8c9249c..bf9d9e7 100644
19115 --- a/gdb/symfile.h
19116 +++ b/gdb/symfile.h
19117 @@ -140,6 +140,12 @@ struct sym_fns
19118  
19119    void (*sym_read) (struct objfile *, int);
19120  
19121 +  /* Read the partial symbols for an objfile.  This may be NULL, in
19122 +     which case gdb assumes that sym_read already read the partial
19123 +     symbols.  */
19124 +
19125 +  void (*sym_read_psymbols) (struct objfile *);
19126 +
19127    /* Called when we are finished with an objfile.  Should do all
19128       cleanup that is specific to the object file format for the
19129       particular objfile.  */
19130 @@ -266,7 +272,7 @@ extern void free_section_addr_info (struct section_addr_info *);
19131  
19132  extern struct partial_symtab *start_psymtab_common (struct objfile *,
19133                                                     struct section_offsets *,
19134 -                                                   char *, CORE_ADDR,
19135 +                                                   const char *, CORE_ADDR,
19136                                                     struct partial_symbol **,
19137                                                     struct partial_symbol **);
19138  
19139 @@ -309,7 +315,7 @@ extern int auto_solib_limit;
19140  
19141  extern void set_initial_language (void);
19142  
19143 -extern struct partial_symtab *allocate_psymtab (char *, struct objfile *);
19144 +extern struct partial_symtab *allocate_psymtab (const char *, struct objfile *);
19145  
19146  extern void discard_psymtab (struct partial_symtab *);
19147  
19148 @@ -378,7 +384,7 @@ void free_symfile_segment_data (struct symfile_segment_data *data);
19149  /* From dwarf2read.c */
19150  
19151  extern int dwarf2_has_info (struct objfile *);
19152 -
19153 +extern void dwarf2_create_quick_addrmap (struct objfile *);
19154  extern void dwarf2_build_psymtabs (struct objfile *, int);
19155  extern void dwarf2_build_frame_info (struct objfile *);
19156  
19157 diff --git a/gdb/symmisc.c b/gdb/symmisc.c
19158 index eb35369..dfd8c8c 100644
19159 --- a/gdb/symmisc.c
19160 +++ b/gdb/symmisc.c
19161 @@ -1128,7 +1128,7 @@ maintenance_check_symtabs (char *ignore, int from_tty)
19162      while (length--)
19163        {
19164         sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
19165 -                                  NULL, SYMBOL_DOMAIN (*psym));
19166 +                                  SYMBOL_DOMAIN (*psym));
19167         if (!sym)
19168           {
19169             printf_filtered ("Static symbol `");
19170 @@ -1145,7 +1145,7 @@ maintenance_check_symtabs (char *ignore, int from_tty)
19171      while (length--)
19172        {
19173         sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
19174 -                                  NULL, SYMBOL_DOMAIN (*psym));
19175 +                                  SYMBOL_DOMAIN (*psym));
19176         if (!sym)
19177           {
19178             printf_filtered ("Global symbol `");
19179 diff --git a/gdb/symtab.c b/gdb/symtab.c
19180 index 8d9d72c..82e0163 100644
19181 --- a/gdb/symtab.c
19182 +++ b/gdb/symtab.c
19183 @@ -42,6 +42,7 @@
19184  #include "ada-lang.h"
19185  #include "p-lang.h"
19186  #include "addrmap.h"
19187 +#include "cp-support.h"
19188  
19189  #include "hashtab.h"
19190  
19191 @@ -85,7 +86,6 @@ static int find_line_common (struct linetable *, int, int *);
19192  char *operator_chars (char *p, char **end);
19193  
19194  static struct symbol *lookup_symbol_aux (const char *name,
19195 -                                        const char *linkage_name,
19196                                          const struct block *block,
19197                                          const domain_enum domain,
19198                                          enum language language,
19199 @@ -93,20 +93,19 @@ static struct symbol *lookup_symbol_aux (const char *name,
19200  
19201  static
19202  struct symbol *lookup_symbol_aux_local (const char *name,
19203 -                                       const char *linkage_name,
19204                                         const struct block *block,
19205 -                                       const domain_enum domain);
19206 +                                       const domain_enum domain,
19207 +                                       enum language language,
19208 +                                       int *is_a_field_of_this);
19209  
19210  static
19211  struct symbol *lookup_symbol_aux_symtabs (int block_index,
19212                                           const char *name,
19213 -                                         const char *linkage_name,
19214                                           const domain_enum domain);
19215  
19216  static
19217  struct symbol *lookup_symbol_aux_psymtabs (int block_index,
19218                                            const char *name,
19219 -                                          const char *linkage_name,
19220                                            const domain_enum domain);
19221  
19222  static int file_matches (char *, char **, int);
19223 @@ -271,7 +270,7 @@ lookup_partial_symtab (const char *name)
19224        make_cleanup (xfree, real_path);
19225      }
19226  
19227 -  ALL_PSYMTABS (objfile, pst)
19228 +  ALL_PSYMTABS_REQUIRED (objfile, pst)
19229    {
19230      if (FILENAME_CMP (name, pst->filename) == 0)
19231        {
19232 @@ -414,7 +413,8 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
19233    gsymbol->language = language;
19234    if (gsymbol->language == language_cplus
19235        || gsymbol->language == language_java
19236 -      || gsymbol->language == language_objc)
19237 +      || gsymbol->language == language_objc
19238 +      || gsymbol->language == language_fortran)
19239      {
19240        gsymbol->language_specific.cplus_specific.demangled_name = NULL;
19241      }
19242 @@ -474,7 +474,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
19243        || gsymbol->language == language_auto)
19244      {
19245        demangled =
19246 -        cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
19247 +        cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE);
19248        if (demangled != NULL)
19249         {
19250           gsymbol->language = language_cplus;
19251 @@ -633,6 +633,7 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
19252      case language_cplus:
19253      case language_java:
19254      case language_objc:
19255 +    case language_fortran:
19256        if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
19257         return gsymbol->language_specific.cplus_specific.demangled_name;
19258        break;
19259 @@ -658,6 +659,7 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol)
19260      case language_cplus:
19261      case language_java:
19262      case language_objc:
19263 +    case language_fortran:
19264        if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
19265         return gsymbol->language_specific.cplus_specific.demangled_name;
19266        break;
19267 @@ -868,7 +870,13 @@ find_pc_sect_psymtab (CORE_ADDR pc, struct obj_section *section)
19268       than the later used TEXTLOW/TEXTHIGH one.  */
19269  
19270    ALL_OBJFILES (objfile)
19271 -    if (objfile->psymtabs_addrmap != NULL)
19272 +  {
19273 +    if (objfile->quick_addrmap)
19274 +      {
19275 +       if (!addrmap_find (objfile->quick_addrmap, pc))
19276 +         continue;
19277 +      }
19278 +    if (require_partial_symbols (objfile)->psymtabs_addrmap != NULL)
19279        {
19280         struct partial_symtab *pst;
19281  
19282 @@ -901,6 +909,7 @@ find_pc_sect_psymtab (CORE_ADDR pc, struct obj_section *section)
19283             return pst;
19284           }
19285        }
19286 +  }
19287  
19288    /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
19289       which still have no corresponding full SYMTABs read.  But it is not
19290 @@ -1168,6 +1177,22 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
19291    return psym;
19292  }
19293  
19294 +/* Ensure that the partial symbols for OBJFILE have been loaded.  This
19295 +   function always returns its argument, as a convenience.  */
19296 +
19297 +struct objfile *
19298 +require_partial_symbols (struct objfile *objfile)
19299 +{
19300 +  if ((objfile->flags & OBJF_SYMTABS_READ) == 0)
19301 +    {
19302 +      objfile->flags |= OBJF_SYMTABS_READ;
19303 +
19304 +      if (objfile->sf->sym_read_psymbols)
19305 +       (*objfile->sf->sym_read_psymbols) (objfile);
19306 +    }
19307 +  return objfile;
19308 +}
19309 +
19310  /* Find the definition for a specified symbol name NAME
19311     in domain DOMAIN, visible from lexical block BLOCK.
19312     Returns the struct symbol pointer, or zero if no symbol is found.
19313 @@ -1194,10 +1219,14 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19314  {
19315    char *demangled_name = NULL;
19316    const char *modified_name = NULL;
19317 -  const char *mangled_name = NULL;
19318    struct symbol *returnval;
19319    struct cleanup *cleanup = make_cleanup (null_cleanup, 0);
19320  
19321 +  if(strncmp(name, "::", 2) == 0){/* this must be a global name */
19322 +    name = name+2;
19323 +    block = NULL;
19324 +  }
19325 +  
19326    modified_name = name;
19327  
19328    /* If we are using C++ or Java, demangle the name before doing a lookup, so
19329 @@ -1207,7 +1236,6 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19330        demangled_name = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
19331        if (demangled_name)
19332         {
19333 -         mangled_name = name;
19334           modified_name = demangled_name;
19335           make_cleanup (xfree, demangled_name);
19336         }
19337 @@ -1229,7 +1257,6 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19338                                        DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
19339        if (demangled_name)
19340         {
19341 -         mangled_name = name;
19342           modified_name = demangled_name;
19343           make_cleanup (xfree, demangled_name);
19344         }
19345 @@ -1248,8 +1275,8 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19346        modified_name = copy;
19347      }
19348  
19349 -  returnval = lookup_symbol_aux (modified_name, mangled_name, block,
19350 -                                domain, lang, is_a_field_of_this);
19351 +  returnval = lookup_symbol_aux (modified_name, block, domain, lang,
19352 +                                is_a_field_of_this);
19353    do_cleanups (cleanup);
19354  
19355    return returnval;
19356 @@ -1273,9 +1300,9 @@ lookup_symbol (const char *name, const struct block *block,
19357     well.  */
19358  
19359  static struct symbol *
19360 -lookup_symbol_aux (const char *name, const char *linkage_name,
19361 -                  const struct block *block, const domain_enum domain,
19362 -                  enum language language, int *is_a_field_of_this)
19363 +lookup_symbol_aux (const char *name, const struct block *block,
19364 +                  const domain_enum domain, enum language language,
19365 +                  int *is_a_field_of_this)
19366  {
19367    struct symbol *sym;
19368    const struct language_defn *langdef;
19369 @@ -1291,55 +1318,19 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
19370    /* Search specified block and its superiors.  Don't search
19371       STATIC_BLOCK or GLOBAL_BLOCK.  */
19372  
19373 -  sym = lookup_symbol_aux_local (name, linkage_name, block, domain);
19374 +  sym = lookup_symbol_aux_local (name, block, domain, language, is_a_field_of_this);
19375    if (sym != NULL)
19376      return sym;
19377  
19378 -  /* If requested to do so by the caller and if appropriate for LANGUAGE,
19379 -     check to see if NAME is a field of `this'. */
19380 -
19381 -  langdef = language_def (language);
19382 -
19383 -  if (langdef->la_name_of_this != NULL && is_a_field_of_this != NULL
19384 -      && block != NULL)
19385 -    {
19386 -      struct symbol *sym = NULL;
19387 -      /* 'this' is only defined in the function's block, so find the
19388 -        enclosing function block.  */
19389 -      for (; block && !BLOCK_FUNCTION (block);
19390 -          block = BLOCK_SUPERBLOCK (block));
19391 -
19392 -      if (block && !dict_empty (BLOCK_DICT (block)))
19393 -       sym = lookup_block_symbol (block, langdef->la_name_of_this,
19394 -                                  NULL, VAR_DOMAIN);
19395 -      if (sym)
19396 -       {
19397 -         struct type *t = sym->type;
19398 -
19399 -         /* I'm not really sure that type of this can ever
19400 -            be typedefed; just be safe.  */
19401 -         CHECK_TYPEDEF (t);
19402 -         if (TYPE_CODE (t) == TYPE_CODE_PTR
19403 -             || TYPE_CODE (t) == TYPE_CODE_REF)
19404 -           t = TYPE_TARGET_TYPE (t);
19405 -
19406 -         if (TYPE_CODE (t) != TYPE_CODE_STRUCT
19407 -             && TYPE_CODE (t) != TYPE_CODE_UNION)
19408 -           error (_("Internal error: `%s' is not an aggregate"),
19409 -                  langdef->la_name_of_this);
19410 -
19411 -         if (check_field (t, name))
19412 -           {
19413 -             *is_a_field_of_this = 1;
19414 -             return NULL;
19415 -           }
19416 -       }
19417 -    }
19418 +  /* this symbol was found to be a member variable
19419 +     do not perform the global search. */
19420 +  if (is_a_field_of_this && *is_a_field_of_this)
19421 +    return NULL;
19422  
19423    /* Now do whatever is appropriate for LANGUAGE to look
19424       up static and global variables.  */
19425 -
19426 -  sym = langdef->la_lookup_symbol_nonlocal (name, linkage_name, block, domain);
19427 +  langdef = language_def (language);
19428 +  sym = langdef->la_lookup_symbol_nonlocal (name, block, domain);
19429    if (sym != NULL)
19430      return sym;
19431  
19432 @@ -1349,11 +1340,11 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
19433       desired name as a file-level static, then do psymtab-to-symtab
19434       conversion on the fly and return the found symbol. */
19435  
19436 -  sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, linkage_name, domain);
19437 +  sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain);
19438    if (sym != NULL)
19439      return sym;
19440  
19441 -  sym = lookup_symbol_aux_psymtabs (STATIC_BLOCK, name, linkage_name, domain);
19442 +  sym = lookup_symbol_aux_psymtabs (STATIC_BLOCK, name, domain);
19443    if (sym != NULL)
19444      return sym;
19445  
19446 @@ -1364,30 +1355,81 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
19447     Don't search STATIC_BLOCK or GLOBAL_BLOCK.  */
19448  
19449  static struct symbol *
19450 -lookup_symbol_aux_local (const char *name, const char *linkage_name,
19451 -                        const struct block *block,
19452 -                        const domain_enum domain)
19453 +lookup_symbol_aux_local (const char *name, const struct block *block,
19454 +                        const domain_enum domain, enum language language,
19455 +                        int *is_a_field_of_this)
19456  {
19457    struct symbol *sym;
19458 -  const struct block *static_block = block_static_block (block);
19459 +  const struct block *global_block = block_global_block (block);
19460 +  const struct block *block_iterator = block;
19461 +  const struct language_defn *langdef;
19462 +
19463 +  langdef = language_def (language);
19464  
19465    /* Check if either no block is specified or it's a global block.  */
19466  
19467 -  if (static_block == NULL)
19468 +  if (global_block == NULL)
19469      return NULL;
19470  
19471 -  while (block != static_block)
19472 +  while (block_iterator != global_block)
19473      {
19474 -      sym = lookup_symbol_aux_block (name, linkage_name, block, domain);
19475 +
19476 +      sym = lookup_symbol_aux_block (name, block_iterator, domain);
19477 +
19478        if (sym != NULL)
19479         return sym;
19480 -
19481 -      if (BLOCK_FUNCTION (block) != NULL && block_inlined_p (block))
19482 -       break;
19483 -      block = BLOCK_SUPERBLOCK (block);
19484 +    
19485 +      if (language == language_cplus )
19486 +        {
19487 +          sym = cp_lookup_symbol_imports (block_scope (block_iterator), name,
19488 +                                          block_iterator, domain, 1, 1);
19489 +
19490 +          if (sym != NULL)
19491 +            return sym;
19492 +        }
19493 +
19494 +      if (langdef->la_name_of_this != NULL && is_a_field_of_this != NULL
19495 +         && BLOCK_FUNCTION (block_iterator))
19496 +        {
19497 +          if (!dict_empty (BLOCK_DICT (block_iterator)))
19498 +            {
19499 +              sym = lookup_block_symbol (block_iterator,
19500 +                                        langdef->la_name_of_this,
19501 +                                        VAR_DOMAIN);
19502 +
19503 +
19504 +              if (sym)
19505 +                {
19506 +                  struct type *t = sym->type;
19507 +
19508 +                  /* I'm not really sure that type of this can ever
19509 +                     be typedefed; just be safe.  */
19510 +                  CHECK_TYPEDEF (t);
19511 +                  if (TYPE_CODE (t) == TYPE_CODE_PTR
19512 +                      || TYPE_CODE (t) == TYPE_CODE_REF)
19513 +                      t = TYPE_TARGET_TYPE (t);
19514 +
19515 +                  if (TYPE_CODE (t) != TYPE_CODE_STRUCT
19516 +                      && TYPE_CODE (t) != TYPE_CODE_UNION)
19517 +                    error (_("Internal error: `%s' is not an aggregate"),
19518 +                        langdef->la_name_of_this);
19519 +
19520 +                  if (check_field (t, name))
19521 +                    {
19522 +                      *is_a_field_of_this = 1;
19523 +                      return NULL;
19524 +                    }
19525 +                }
19526 +            }
19527 +        }
19528 +
19529 +      if (BLOCK_FUNCTION (block_iterator) != NULL && block_inlined_p (block_iterator))
19530 +        break;
19531 +
19532 +      block_iterator = BLOCK_SUPERBLOCK (block_iterator);
19533      }
19534  
19535 -  /* We've reached the edge of the function without finding a result.  */
19536 +  /* We've reached the global block without finding a result.  */
19537  
19538    return NULL;
19539  }
19540 @@ -1416,13 +1458,12 @@ lookup_objfile_from_block (const struct block *block)
19541     block_found appropriately.  */
19542  
19543  struct symbol *
19544 -lookup_symbol_aux_block (const char *name, const char *linkage_name,
19545 -                        const struct block *block,
19546 +lookup_symbol_aux_block (const char *name, const struct block *block,
19547                          const domain_enum domain)
19548  {
19549    struct symbol *sym;
19550  
19551 -  sym = lookup_block_symbol (block, name, linkage_name, domain);
19552 +  sym = lookup_block_symbol (block, name, domain);
19553    if (sym)
19554      {
19555        block_found = block;
19556 @@ -1438,7 +1479,6 @@ lookup_symbol_aux_block (const char *name, const char *linkage_name,
19557  struct symbol *
19558  lookup_global_symbol_from_objfile (const struct objfile *objfile,
19559                                    const char *name,
19560 -                                  const char *linkage_name,
19561                                    const domain_enum domain)
19562  {
19563    struct symbol *sym;
19564 @@ -1452,7 +1492,7 @@ lookup_global_symbol_from_objfile (const struct objfile *objfile,
19565    {
19566      bv = BLOCKVECTOR (s);
19567      block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19568 -    sym = lookup_block_symbol (block, name, linkage_name, domain);
19569 +    sym = lookup_block_symbol (block, name, domain);
19570      if (sym)
19571        {
19572         block_found = block;
19573 @@ -1461,23 +1501,23 @@ lookup_global_symbol_from_objfile (const struct objfile *objfile,
19574    }
19575  
19576    /* Now go through psymtabs.  */
19577 +  require_partial_symbols ((struct objfile *) objfile);
19578    ALL_OBJFILE_PSYMTABS (objfile, ps)
19579    {
19580      if (!ps->readin
19581 -       && lookup_partial_symbol (ps, name, linkage_name,
19582 -                                 1, domain))
19583 +       && lookup_partial_symbol (ps, name, 1, domain))
19584        {
19585         s = PSYMTAB_TO_SYMTAB (ps);
19586         bv = BLOCKVECTOR (s);
19587         block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19588 -       sym = lookup_block_symbol (block, name, linkage_name, domain);
19589 +       sym = lookup_block_symbol (block, name, domain);
19590         return fixup_symbol_section (sym, (struct objfile *)objfile);
19591        }
19592    }
19593  
19594    if (objfile->separate_debug_objfile)
19595      return lookup_global_symbol_from_objfile (objfile->separate_debug_objfile,
19596 -                                             name, linkage_name, domain);
19597 +                                             name, domain);
19598  
19599    return NULL;
19600  }
19601 @@ -1488,8 +1528,7 @@ lookup_global_symbol_from_objfile (const struct objfile *objfile,
19602     static symbols.  */
19603  
19604  static struct symbol *
19605 -lookup_symbol_aux_symtabs (int block_index,
19606 -                          const char *name, const char *linkage_name,
19607 +lookup_symbol_aux_symtabs (int block_index, const char *name,
19608                            const domain_enum domain)
19609  {
19610    struct symbol *sym;
19611 @@ -1502,7 +1541,7 @@ lookup_symbol_aux_symtabs (int block_index,
19612    {
19613      bv = BLOCKVECTOR (s);
19614      block = BLOCKVECTOR_BLOCK (bv, block_index);
19615 -    sym = lookup_block_symbol (block, name, linkage_name, domain);
19616 +    sym = lookup_block_symbol (block, name, domain);
19617      if (sym)
19618        {
19619         block_found = block;
19620 @@ -1520,7 +1559,6 @@ lookup_symbol_aux_symtabs (int block_index,
19621  
19622  static struct symbol *
19623  lookup_symbol_aux_psymtabs (int block_index, const char *name,
19624 -                           const char *linkage_name,
19625                             const domain_enum domain)
19626  {
19627    struct symbol *sym;
19628 @@ -1531,16 +1569,15 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name,
19629    struct symtab *s;
19630    const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
19631  
19632 -  ALL_PSYMTABS (objfile, ps)
19633 +  ALL_PSYMTABS_REQUIRED (objfile, ps)
19634    {
19635      if (!ps->readin
19636 -       && lookup_partial_symbol (ps, name, linkage_name,
19637 -                                 psymtab_index, domain))
19638 +       && lookup_partial_symbol (ps, name, psymtab_index, domain))
19639        {
19640         s = PSYMTAB_TO_SYMTAB (ps);
19641         bv = BLOCKVECTOR (s);
19642         block = BLOCKVECTOR_BLOCK (bv, block_index);
19643 -       sym = lookup_block_symbol (block, name, linkage_name, domain);
19644 +       sym = lookup_block_symbol (block, name, domain);
19645         if (!sym)
19646           {
19647             /* This shouldn't be necessary, but as a last resort try
19648 @@ -1557,7 +1594,7 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name,
19649             block = BLOCKVECTOR_BLOCK (bv,
19650                                        block_index == GLOBAL_BLOCK ?
19651                                        STATIC_BLOCK : GLOBAL_BLOCK);
19652 -           sym = lookup_block_symbol (block, name, linkage_name, domain);
19653 +           sym = lookup_block_symbol (block, name, domain);
19654             if (!sym)
19655               error (_("Internal: %s symbol `%s' found in %s psymtab but not in symtab.\n%s may be an inlined function, or may be a template function\n(if a template, try specifying an instantiation: %s<type>)."),
19656                      block_index == GLOBAL_BLOCK ? "global" : "static",
19657 @@ -1576,7 +1613,6 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name,
19658  
19659  struct symbol *
19660  basic_lookup_symbol_nonlocal (const char *name,
19661 -                             const char *linkage_name,
19662                               const struct block *block,
19663                               const domain_enum domain)
19664  {
19665 @@ -1610,11 +1646,11 @@ basic_lookup_symbol_nonlocal (const char *name,
19666       than that one, so I don't think we should worry about that for
19667       now.  */
19668  
19669 -  sym = lookup_symbol_static (name, linkage_name, block, domain);
19670 +  sym = lookup_symbol_static (name, block, domain);
19671    if (sym != NULL)
19672      return sym;
19673  
19674 -  return lookup_symbol_global (name, linkage_name, block, domain);
19675 +  return lookup_symbol_global (name, block, domain);
19676  }
19677  
19678  /* Lookup a symbol in the static block associated to BLOCK, if there
19679 @@ -1622,14 +1658,13 @@ basic_lookup_symbol_nonlocal (const char *name,
19680  
19681  struct symbol *
19682  lookup_symbol_static (const char *name,
19683 -                     const char *linkage_name,
19684                       const struct block *block,
19685                       const domain_enum domain)
19686  {
19687    const struct block *static_block = block_static_block (block);
19688  
19689    if (static_block != NULL)
19690 -    return lookup_symbol_aux_block (name, linkage_name, static_block, domain);
19691 +    return lookup_symbol_aux_block (name, static_block, domain);
19692    else
19693      return NULL;
19694  }
19695 @@ -1639,7 +1674,6 @@ lookup_symbol_static (const char *name,
19696  
19697  struct symbol *
19698  lookup_symbol_global (const char *name,
19699 -                     const char *linkage_name,
19700                       const struct block *block,
19701                       const domain_enum domain)
19702  {
19703 @@ -1649,15 +1683,15 @@ lookup_symbol_global (const char *name,
19704    /* Call library-specific lookup procedure.  */
19705    objfile = lookup_objfile_from_block (block);
19706    if (objfile != NULL)
19707 -    sym = solib_global_lookup (objfile, name, linkage_name, domain);
19708 +    sym = solib_global_lookup (objfile, name, domain);
19709    if (sym != NULL)
19710      return sym;
19711  
19712 -  sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, linkage_name, domain);
19713 +  sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, domain);
19714    if (sym != NULL)
19715      return sym;
19716  
19717 -  return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, linkage_name, domain);
19718 +  return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, domain);
19719  }
19720  
19721  int
19722 @@ -1681,14 +1715,11 @@ symbol_matches_domain (enum language symbol_language,
19723  }
19724  
19725  /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
19726 -   If LINKAGE_NAME is non-NULL, check in addition that the symbol's
19727 -   linkage name matches it.  Check the global symbols if GLOBAL, the
19728 -   static symbols if not */
19729 +   Check the global symbols if GLOBAL, the static symbols if not. */
19730  
19731  struct partial_symbol *
19732  lookup_partial_symbol (struct partial_symtab *pst, const char *name,
19733 -                      const char *linkage_name, int global,
19734 -                      domain_enum domain)
19735 +                      int global, domain_enum domain)
19736  {
19737    struct partial_symbol *temp;
19738    struct partial_symbol **start, **psym;
19739 @@ -1740,9 +1771,7 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
19740         internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
19741  
19742        while (top <= real_top
19743 -            && (linkage_name != NULL
19744 -                ? strcmp (SYMBOL_LINKAGE_NAME (*top), linkage_name) == 0
19745 -                : SYMBOL_MATCHES_SEARCH_NAME (*top,name)))
19746 +            && SYMBOL_MATCHES_SEARCH_NAME (*top, name))
19747         {
19748           if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
19749                                      SYMBOL_DOMAIN (*top), domain))
19750 @@ -1759,15 +1788,9 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
19751        for (psym = start; psym < start + length; psym++)
19752         {
19753           if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
19754 -                                    SYMBOL_DOMAIN (*psym), domain))
19755 -           {
19756 -             if (linkage_name != NULL
19757 -                 ? strcmp (SYMBOL_LINKAGE_NAME (*psym), linkage_name) == 0
19758 -                 : SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
19759 -               {
19760 -                 return (*psym);
19761 -               }
19762 -           }
19763 +                                    SYMBOL_DOMAIN (*psym), domain)
19764 +             && SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
19765 +           return (*psym);
19766         }
19767      }
19768  
19769 @@ -1809,22 +1832,25 @@ basic_lookup_transparent_type (const char *name)
19770    {
19771      bv = BLOCKVECTOR (s);
19772      block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19773 -    sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19774 +    sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19775      if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
19776        {
19777         return SYMBOL_TYPE (sym);
19778        }
19779    }
19780  
19781 -  ALL_PSYMTABS (objfile, ps)
19782 +  /* FIXME: .debug_pubnames should be read in.
19783 +     
19784 +     One may also try to the first pass without the require_partial_symbols
19785 +     call but that would behave nondeterministically.  */
19786 +  ALL_PSYMTABS_REQUIRED (objfile, ps)
19787    {
19788 -    if (!ps->readin && lookup_partial_symbol (ps, name, NULL,
19789 -                                             1, STRUCT_DOMAIN))
19790 +    if (!ps->readin && lookup_partial_symbol (ps, name, 1, STRUCT_DOMAIN))
19791        {
19792         s = PSYMTAB_TO_SYMTAB (ps);
19793         bv = BLOCKVECTOR (s);
19794         block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19795 -       sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19796 +       sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19797         if (!sym)
19798           {
19799             /* This shouldn't be necessary, but as a last resort
19800 @@ -1833,7 +1859,7 @@ basic_lookup_transparent_type (const char *name)
19801              * the psymtab gets it wrong in some cases.
19802              */
19803             block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
19804 -           sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19805 +           sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19806             if (!sym)
19807               error (_("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
19808  %s may be an inlined function, or may be a template function\n\
19809 @@ -1857,21 +1883,26 @@ basic_lookup_transparent_type (const char *name)
19810    {
19811      bv = BLOCKVECTOR (s);
19812      block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
19813 -    sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19814 +    sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19815      if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
19816        {
19817         return SYMBOL_TYPE (sym);
19818        }
19819    }
19820  
19821 -  ALL_PSYMTABS (objfile, ps)
19822 +  /* FIXME: Something like .debug_pubnames containing also static symbols
19823 +     should be read in.  Compiler needs to be taught to generate it first.
19824 +     
19825 +     One may also try to the first pass without the require_partial_symbols
19826 +     call but that would behave nondeterministically.  */
19827 +  ALL_PSYMTABS_REQUIRED (objfile, ps)
19828    {
19829 -    if (!ps->readin && lookup_partial_symbol (ps, name, NULL, 0, STRUCT_DOMAIN))
19830 +    if (!ps->readin && lookup_partial_symbol (ps, name, 0, STRUCT_DOMAIN))
19831        {
19832         s = PSYMTAB_TO_SYMTAB (ps);
19833         bv = BLOCKVECTOR (s);
19834         block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
19835 -       sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19836 +       sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19837         if (!sym)
19838           {
19839             /* This shouldn't be necessary, but as a last resort
19840 @@ -1880,7 +1911,7 @@ basic_lookup_transparent_type (const char *name)
19841              * the psymtab gets it wrong in some cases.
19842              */
19843             block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19844 -           sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19845 +           sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19846             if (!sym)
19847               error (_("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
19848  %s may be an inlined function, or may be a template function\n\
19849 @@ -1905,9 +1936,23 @@ find_main_psymtab (void)
19850    struct partial_symtab *pst;
19851    struct objfile *objfile;
19852  
19853 -  ALL_PSYMTABS (objfile, pst)
19854 +  ALL_OBJFILES (objfile)
19855 +  {
19856 +    if ((objfile->flags & OBJF_MAIN) == 0)
19857 +      continue;
19858 +    require_partial_symbols (objfile);
19859 +    ALL_OBJFILE_PSYMTABS (objfile, pst)
19860 +    {
19861 +      if (lookup_partial_symbol (pst, main_name (), 1, VAR_DOMAIN))
19862 +       {
19863 +         return pst;
19864 +       }
19865 +    }
19866 +  }
19867 +
19868 +  ALL_PSYMTABS_REQUIRED (objfile, pst)
19869    {
19870 -    if (lookup_partial_symbol (pst, main_name (), NULL, 1, VAR_DOMAIN))
19871 +    if (lookup_partial_symbol (pst, main_name (), 1, VAR_DOMAIN))
19872        {
19873         return (pst);
19874        }
19875 @@ -1925,14 +1970,10 @@ find_main_psymtab (void)
19876     search on the symbols.  Each symbol which is marked as being a ObjC/C++
19877     symbol (language_cplus or language_objc set) has both the encoded and
19878     non-encoded names tested for a match.
19879 -
19880 -   If LINKAGE_NAME is non-NULL, verify that any symbol we find has this
19881 -   particular mangled name.
19882  */
19883  
19884  struct symbol *
19885  lookup_block_symbol (const struct block *block, const char *name,
19886 -                    const char *linkage_name,
19887                      const domain_enum domain)
19888  {
19889    struct dict_iterator iter;
19890 @@ -1945,9 +1986,7 @@ lookup_block_symbol (const struct block *block, const char *name,
19891            sym = dict_iter_name_next (name, &iter))
19892         {
19893           if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
19894 -                                    SYMBOL_DOMAIN (sym), domain)
19895 -             && (linkage_name != NULL
19896 -                 ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1))
19897 +                                    SYMBOL_DOMAIN (sym), domain))
19898             return sym;
19899         }
19900        return NULL;
19901 @@ -1967,9 +2006,7 @@ lookup_block_symbol (const struct block *block, const char *name,
19902            sym = dict_iter_name_next (name, &iter))
19903         {
19904           if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
19905 -                                    SYMBOL_DOMAIN (sym), domain)
19906 -             && (linkage_name != NULL
19907 -                 ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1))
19908 +                                    SYMBOL_DOMAIN (sym), domain))
19909             {
19910               sym_found = sym;
19911               if (!SYMBOL_IS_ARGUMENT (sym))
19912 @@ -3172,7 +3209,7 @@ search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[],
19913       matching the regexp.  That way we don't have to reproduce all of
19914       the machinery below. */
19915  
19916 -  ALL_PSYMTABS (objfile, ps)
19917 +  ALL_PSYMTABS_REQUIRED (objfile, ps)
19918    {
19919      struct partial_symbol **bound, **gbound, **sbound;
19920      int keep_going = 1;
19921 diff --git a/gdb/symtab.h b/gdb/symtab.h
19922 index 740d4e0..461ff95 100644
19923 --- a/gdb/symtab.h
19924 +++ b/gdb/symtab.h
19925 @@ -171,9 +171,6 @@ extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
19926  #define SYMBOL_SECTION(symbol)         (symbol)->ginfo.section
19927  #define SYMBOL_OBJ_SECTION(symbol)     (symbol)->ginfo.obj_section
19928  
19929 -#define SYMBOL_CPLUS_DEMANGLED_NAME(symbol)    \
19930 -  (symbol)->ginfo.language_specific.cplus_specific.demangled_name
19931 -
19932  /* Initializes the language dependent portion of a symbol
19933     depending upon the language for the symbol. */
19934  #define SYMBOL_INIT_LANGUAGE_SPECIFIC(symbol,language) \
19935 @@ -394,7 +391,13 @@ typedef enum domain_enum_tag
19936    FUNCTIONS_DOMAIN,
19937  
19938    /* All defined types */
19939 -  TYPES_DOMAIN
19940 +  TYPES_DOMAIN,
19941 +
19942 +  /* Fortran common blocks.  Their naming must be separate from VAR_DOMAIN.  */
19943 +  COMMON_BLOCK_DOMAIN,
19944 +
19945 +  /* Fortran module.  Their naming must be separate.  */
19946 +  MODULE_DOMAIN
19947  }
19948  domain_enum;
19949  
19950 @@ -990,7 +993,6 @@ extern struct symbol *lookup_symbol (const char *, const struct block *,
19951     that can't think of anything better to do.  */
19952  
19953  extern struct symbol *basic_lookup_symbol_nonlocal (const char *,
19954 -                                                   const char *,
19955                                                     const struct block *,
19956                                                     const domain_enum);
19957  
19958 @@ -1001,7 +1003,6 @@ extern struct symbol *basic_lookup_symbol_nonlocal (const char *,
19959     is one; do nothing if BLOCK is NULL or a global block.  */
19960  
19961  extern struct symbol *lookup_symbol_static (const char *name,
19962 -                                           const char *linkage_name,
19963                                             const struct block *block,
19964                                             const domain_enum domain);
19965  
19966 @@ -1009,7 +1010,6 @@ extern struct symbol *lookup_symbol_static (const char *name,
19967     necessary).  */
19968  
19969  extern struct symbol *lookup_symbol_global (const char *name,
19970 -                                           const char *linkage_name,
19971                                             const struct block *block,
19972                                             const domain_enum domain);
19973  
19974 @@ -1018,21 +1018,18 @@ extern struct symbol *lookup_symbol_global (const char *name,
19975     will fix up the symbol if necessary.  */
19976  
19977  extern struct symbol *lookup_symbol_aux_block (const char *name,
19978 -                                              const char *linkage_name,
19979                                                const struct block *block,
19980                                                const domain_enum domain);
19981  
19982  /* Lookup a partial symbol.  */
19983  
19984  extern struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
19985 -                                                    const char *,
19986                                                      const char *, int,
19987                                                      domain_enum);
19988  
19989  /* lookup a symbol by name, within a specified block */
19990  
19991  extern struct symbol *lookup_block_symbol (const struct block *, const char *,
19992 -                                          const char *,
19993                                            const domain_enum);
19994  
19995  /* lookup a [struct, union, enum] by name, within a specified block */
19996 @@ -1062,6 +1059,8 @@ extern void clear_pc_function_cache (void);
19997  
19998  /* from symtab.c: */
19999  
20000 +struct objfile *require_partial_symbols (struct objfile *);
20001 +
20002  /* lookup partial symbol table by filename */
20003  
20004  extern struct partial_symtab *lookup_partial_symtab (const char *);
20005 @@ -1356,7 +1355,6 @@ extern /*const */ char *main_name (void);
20006  /* Check global symbols in objfile.  */
20007  struct symbol *lookup_global_symbol_from_objfile (const struct objfile *objfile,
20008                                                   const char *name,
20009 -                                                 const char *linkage_name,
20010                                                   const domain_enum domain);
20011  
20012  extern struct symtabs_and_lines
20013 diff --git a/gdb/target.c b/gdb/target.c
20014 index e5d14fd..37fab72 100644
20015 --- a/gdb/target.c
20016 +++ b/gdb/target.c
20017 @@ -124,6 +124,8 @@ static int debug_to_insert_watchpoint (CORE_ADDR, int, int);
20018  
20019  static int debug_to_remove_watchpoint (CORE_ADDR, int, int);
20020  
20021 +static int debug_to_detach_watchpoints (void);
20022 +
20023  static int debug_to_stopped_by_watchpoint (void);
20024  
20025  static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
20026 @@ -622,6 +624,7 @@ update_current_target (void)
20027        INHERIT (to_remove_hw_breakpoint, t);
20028        INHERIT (to_insert_watchpoint, t);
20029        INHERIT (to_remove_watchpoint, t);
20030 +      INHERIT (to_detach_watchpoints, t);
20031        INHERIT (to_stopped_data_address, t);
20032        INHERIT (to_have_steppable_watchpoint, t);
20033        INHERIT (to_have_continuable_watchpoint, t);
20034 @@ -733,6 +736,9 @@ update_current_target (void)
20035    de_fault (to_remove_watchpoint,
20036             (int (*) (CORE_ADDR, int, int))
20037             return_minus_one);
20038 +  de_fault (to_detach_watchpoints,
20039 +           (int (*) (void))
20040 +           return_zero);
20041    de_fault (to_stopped_by_watchpoint,
20042             (int (*) (void))
20043             return_zero);
20044 @@ -3173,6 +3179,19 @@ debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
20045    return retval;
20046  }
20047  
20048 +static int
20049 +debug_to_detach_watchpoints (void)
20050 +{
20051 +  int retval;
20052 +
20053 +  retval = debug_target.to_detach_watchpoints ();
20054 +
20055 +  fprintf_unfiltered (gdb_stdlog,
20056 +                     "target_detach_watchpoints () = %ld\n",
20057 +                     (unsigned long) retval);
20058 +  return retval;
20059 +}
20060 +
20061  static void
20062  debug_to_terminal_init (void)
20063  {
20064 @@ -3420,6 +3439,7 @@ setup_target_debug (void)
20065    current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
20066    current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
20067    current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
20068 +  current_target.to_detach_watchpoints = debug_to_detach_watchpoints;
20069    current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
20070    current_target.to_stopped_data_address = debug_to_stopped_data_address;
20071    current_target.to_watchpoint_addr_within_range = debug_to_watchpoint_addr_within_range;
20072 diff --git a/gdb/target.h b/gdb/target.h
20073 index b1cb852..adff946 100644
20074 --- a/gdb/target.h
20075 +++ b/gdb/target.h
20076 @@ -395,6 +395,7 @@ struct target_ops
20077      int (*to_remove_hw_breakpoint) (struct gdbarch *, struct bp_target_info *);
20078      int (*to_remove_watchpoint) (CORE_ADDR, int, int);
20079      int (*to_insert_watchpoint) (CORE_ADDR, int, int);
20080 +    int (*to_detach_watchpoints) (void);
20081      int (*to_stopped_by_watchpoint) (void);
20082      int to_have_steppable_watchpoint;
20083      int to_have_continuable_watchpoint;
20084 @@ -1166,6 +1167,15 @@ extern char *normal_pid_to_str (ptid_t ptid);
20085  #define        target_remove_watchpoint(addr, len, type)       \
20086       (*current_target.to_remove_watchpoint) (addr, len, type)
20087  
20088 +/* Clear all debug registers without affecting any register caches.  Function
20089 +   acts on INFERIOR_PTID which should be the forked-off process, either the
20090 +   non-threaded child one or the threaded parent one, depending on `set
20091 +   follow-fork-mode'.  Both watchpoints and hardware breakpoints get removed.
20092 +   Return 0 on success, -1 on failure.  */
20093 +
20094 +#define        target_detach_watchpoints()     \
20095 +     (*current_target.to_detach_watchpoints) ()
20096 +
20097  #define target_insert_hw_breakpoint(gdbarch, bp_tgt) \
20098       (*current_target.to_insert_hw_breakpoint) (gdbarch, bp_tgt)
20099  
20100 @@ -1203,6 +1213,20 @@ extern int target_search_memory (CORE_ADDR start_addr,
20101                                   ULONGEST pattern_len,
20102                                   CORE_ADDR *found_addrp);
20103  
20104 +/* Utility functions which can be used by search_memory implementations.  */
20105 +
20106 +void allocate_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
20107 +                             ULONGEST *pattern_buf_size);
20108 +
20109 +void increase_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
20110 +                             ULONGEST *pattern_buf_size, int val_bytes);
20111 +
20112 +int search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
20113 +                  const char *pattern_buf, ULONGEST pattern_len,
20114 +                  CORE_ADDR *found_addr);
20115 +
20116 +void put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p);
20117 +
20118  /* Command logging facility.  */
20119  
20120  #define target_log_command(p)                                          \
20121 @@ -1322,6 +1346,14 @@ extern struct target_ops *find_target_beneath (struct target_ops *);
20122  
20123  extern char *target_get_osdata (const char *type);
20124  
20125 +/* Read OS data object of type TYPE from the target, and return it in
20126 +   XML format.  The result is NUL-terminated and returned as a string,
20127 +   allocated using xmalloc.  If an error occurs or the transfer is
20128 +   unsupported, NULL is returned.  Empty objects are returned as
20129 +   allocated but empty strings.  */
20130 +
20131 +extern char *target_get_osdata (const char *type);
20132 +
20133  \f
20134  /* Stuff that should be shared among the various remote targets.  */
20135  
20136 diff --git a/gdb/testsuite/gdb.arch/powerpc-power7.exp b/gdb/testsuite/gdb.arch/powerpc-power7.exp
20137 new file mode 100644
20138 index 0000000..ae301db
20139 --- /dev/null
20140 +++ b/gdb/testsuite/gdb.arch/powerpc-power7.exp
20141 @@ -0,0 +1,175 @@
20142 +# Copyright 2009 Free Software Foundation, Inc.
20143 +
20144 +# This program is free software; you can redistribute it and/or modify
20145 +# it under the terms of the GNU General Public License as published by
20146 +# the Free Software Foundation; either version 2 of the License, or
20147 +# (at your option) any later version.
20148 +#
20149 +# This program is distributed in the hope that it will be useful,
20150 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
20151 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20152 +# GNU General Public License for more details.
20153 +#
20154 +# You should have received a copy of the GNU General Public License
20155 +# along with this program; if not, write to the Free Software
20156 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
20157 +
20158 +# Test PowerPC Power7 instructions disassembly.
20159 +
20160 +if {![istarget "powerpc*-*-*"]} then {
20161 +    verbose "Skipping PowerPC Power7 instructions disassembly."
20162 +    return
20163 +}
20164 +
20165 +set testfile "powerpc-power7"
20166 +set srcfile ${testfile}.s
20167 +set objfile ${objdir}/${subdir}/${testfile}.o
20168 +
20169 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug}] != "" } {
20170 +    untested "PowerPC Power7 instructions disassembly"
20171 +    return -1
20172 +}
20173 +
20174 +
20175 +gdb_exit
20176 +gdb_start
20177 +gdb_reinitialize_dir $srcdir/$subdir
20178 +gdb_load ${objfile}
20179
20180 +
20181 +# Disassemble the function.
20182 +
20183 +set test "disass func"
20184 +gdb_test_multiple $test $test {
20185 +    -re "\r\nDump of assembler code for function func:(\r\n.*\r\n)End of assembler dump.\r\n$gdb_prompt $" {
20186 +       set func $expect_out(1,string)
20187 +       pass $test
20188 +    }
20189 +}
20190 +
20191 +proc instr_to_patt {offset instr} {
20192 +    # 0x0000000000000018 <func+24>:    stxvd2x vs43,r4,r5
20193 +    return ".*\r\n[string map {0x 0x0*} $offset] <func\\+?\[0-9\]*>:\[ \t\]*[string map [list { } "\[ \t\]+" . {\.}] $instr]\[ \t\]*\r\n.*"
20194 +}
20195 +
20196 +# KFAIL strings would not exist if -Many would print the same as -Mpower7.
20197 +# That means the power7 form should be the preferred one.
20198 +# http://sourceware.org/ml/gdb-patches/2009-03/threads.html#00020
20199 +
20200 +proc func_check {offset instr {kfail ""}} {
20201 +    global func
20202 +
20203 +    set test "Found $offset: $instr"
20204 +    if [regexp -nocase -line [instr_to_patt $offset $instr] $func] {
20205 +       pass $test
20206 +    } elseif {$kfail != "" && [regexp -nocase -line [instr_to_patt $offset $kfail] $func]} {
20207 +       kfail gdb/NNNN $test
20208 +    } else {
20209 +       fail $test
20210 +    }
20211 +}
20212 +
20213 +func_check   0x0 "lxvd2x  vs3,r4,r5"
20214 +func_check   0x4 "lxvd2ux vs3,r4,r5"
20215 +func_check   0x8 "lxvd2x  vs43,r4,r5"
20216 +func_check   0xc "lxvd2ux vs43,r4,r5"
20217 +func_check  0x10 "stxvd2x vs3,r4,r5"
20218 +func_check  0x14 "stxvd2ux vs3,r4,r5"
20219 +func_check  0x18 "stxvd2x vs43,r4,r5"
20220 +func_check  0x1c "stxvd2ux vs43,r4,r5"
20221 +func_check  0x20 "xxmrghd vs3,vs4,vs5"
20222 +func_check  0x24 "xxmrghd vs43,vs44,vs45"
20223 +func_check  0x28 "xxmrgld vs3,vs4,vs5"
20224 +func_check  0x2c "xxmrgld vs43,vs44,vs45"
20225 +func_check  0x30 "xxmrghd vs3,vs4,vs5"
20226 +func_check  0x34 "xxmrghd vs43,vs44,vs45"
20227 +func_check  0x38 "xxmrgld vs3,vs4,vs5"
20228 +func_check  0x3c "xxmrgld vs43,vs44,vs45"
20229 +func_check  0x40 "xxpermdi vs3,vs4,vs5,1"
20230 +func_check  0x44 "xxpermdi vs43,vs44,vs45,1"
20231 +func_check  0x48 "xxpermdi vs3,vs4,vs5,2"
20232 +func_check  0x4c "xxpermdi vs43,vs44,vs45,2"
20233 +func_check  0x50 "xvmovdp vs3,vs4"
20234 +func_check  0x54 "xvmovdp vs43,vs44"
20235 +func_check  0x58 "xvmovdp vs3,vs4"
20236 +func_check  0x5c "xvmovdp vs43,vs44"
20237 +func_check  0x60 "xvcpsgndp vs3,vs4,vs5"
20238 +func_check  0x64 "xvcpsgndp vs43,vs44,vs45"
20239 +func_check  0x68 "wait"
20240 +func_check  0x6c "wait"
20241 +func_check  0x70 "waitrsv"
20242 +func_check  0x74 "waitrsv"
20243 +func_check  0x78 "waitimpl"
20244 +func_check  0x7c "waitimpl"
20245 +func_check  0x80 "doze"
20246 +func_check  0x84 "nap"
20247 +func_check  0x88 "sleep"
20248 +func_check  0x8c "rvwinkle"
20249 +func_check  0x90 "prtyw   r3,r4"
20250 +func_check  0x94 "prtyd   r13,r14"
20251 +func_check  0x98 "mfcfar  r10"           "mfspr   r10,28"
20252 +func_check  0x9c "mtcfar  r11"           "mtspr   28,r11"
20253 +func_check  0xa0 "cmpb    r3,r4,r5"
20254 +func_check  0xa4 "lwzcix  r10,r11,r12"
20255 +func_check  0xa8 "dadd    f16,f17,f18"
20256 +func_check  0xac "daddq   f20,f22,f24"
20257 +func_check  0xb0 "dss     3"
20258 +func_check  0xb4 "dssall"
20259 +func_check  0xb8 "dst     r5,r4,1"
20260 +func_check  0xbc "dstt    r8,r7,0"
20261 +func_check  0xc0 "dstst   r5,r6,3"
20262 +func_check  0xc4 "dststt  r4,r5,2"
20263 +func_check  0xc8 "divwe   r10,r11,r12"
20264 +func_check  0xcc "divwe.  r11,r12,r13"
20265 +func_check  0xd0 "divweo  r12,r13,r14"
20266 +func_check  0xd4 "divweo. r13,r14,r15"
20267 +func_check  0xd8 "divweu  r10,r11,r12"
20268 +func_check  0xdc "divweu. r11,r12,r13"
20269 +func_check  0xe0 "divweuo r12,r13,r14"
20270 +func_check  0xe4 "divweuo. r13,r14,r15"
20271 +func_check  0xe8 "bpermd  r7,r17,r27"
20272 +func_check  0xec "popcntw r10,r20"
20273 +func_check  0xf0 "popcntd r10,r20"
20274 +func_check  0xf4 "ldbrx   r20,r21,r22"
20275 +func_check  0xf8 "stdbrx  r20,r21,r22"
20276 +func_check  0xfc "lfiwzx  f10,0,r10"
20277 +func_check 0x100 "lfiwzx  f10,r9,r10"
20278 +func_check 0x104 "fcfids  f4,f5"
20279 +func_check 0x108 "fcfids. f4,f5"
20280 +func_check 0x10c "fcfidus f4,f5"
20281 +func_check 0x110 "fcfidus. f4,f5"
20282 +func_check 0x114 "fctiwu  f4,f5"
20283 +func_check 0x118 "fctiwu. f4,f5"
20284 +func_check 0x11c "fctiwuz f4,f5"
20285 +func_check 0x120 "fctiwuz. f4,f5"
20286 +func_check 0x124 "fctidu  f4,f5"
20287 +func_check 0x128 "fctidu. f4,f5"
20288 +func_check 0x12c "fctiduz f4,f5"
20289 +func_check 0x130 "fctiduz. f4,f5"
20290 +func_check 0x134 "fcfidu  f4,f5"
20291 +func_check 0x138 "fcfidu. f4,f5"
20292 +func_check 0x13c "ftdiv   cr0,f10,f11"
20293 +func_check 0x140 "ftdiv   cr7,f10,f11"
20294 +func_check 0x144 "ftsqrt  cr0,f10"
20295 +func_check 0x148 "ftsqrt  cr7,f10"
20296 +func_check 0x14c "dcbtt   r8,r9"         "dcbt    16,r8,r9"
20297 +func_check 0x150 "dcbtstt r8,r9"         "dcbtst  16,r8,r9"
20298 +func_check 0x154 "dcffix  f10,f12"
20299 +func_check 0x158 "dcffix. f20,f22"
20300 +func_check 0x15c "lbarx   r10,r11,r12"
20301 +func_check 0x160 "lbarx   r10,r11,r12"
20302 +func_check 0x164 "lbarx   r10,r11,r12,1"
20303 +func_check 0x168 "lharx   r20,r21,r22"
20304 +func_check 0x16c "lharx   r20,r21,r22"
20305 +func_check 0x170 "lharx   r20,r21,r22,1"
20306 +func_check 0x174 "stbcx.  r10,r11,r12"
20307 +func_check 0x178 "sthcx.  r10,r11,r12"
20308 +func_check 0x17c "fre     f14,f15"
20309 +func_check 0x180 "fre.    f14,f15"
20310 +func_check 0x184 "fres    f14,f15"
20311 +func_check 0x188 "fres.   f14,f15"
20312 +func_check 0x18c "frsqrte f14,f15"
20313 +func_check 0x190 "frsqrte. f14,f15"
20314 +func_check 0x194 "frsqrtes f14,f15"
20315 +func_check 0x198 "frsqrtes. f14,f15"
20316 +func_check 0x19c "isel    r2,r3,r4,28"
20317 diff --git a/gdb/testsuite/gdb.arch/powerpc-power7.s b/gdb/testsuite/gdb.arch/powerpc-power7.s
20318 new file mode 100644
20319 index 0000000..98b2e79
20320 --- /dev/null
20321 +++ b/gdb/testsuite/gdb.arch/powerpc-power7.s
20322 @@ -0,0 +1,107 @@
20323 +       .text
20324 +       .globl  func
20325 +func:
20326 +       .long   0x7c642e98      /*   0: lxvd2x  vs3,r4,r5         */
20327 +       .long   0x7c642ed8      /*   4: lxvd2ux vs3,r4,r5         */
20328 +       .long   0x7d642e99      /*   8: lxvd2x  vs43,r4,r5        */
20329 +       .long   0x7d642ed9      /*   c: lxvd2ux vs43,r4,r5        */
20330 +       .long   0x7c642f98      /*  10: stxvd2x vs3,r4,r5         */
20331 +       .long   0x7c642fd8      /*  14: stxvd2ux vs3,r4,r5        */
20332 +       .long   0x7d642f99      /*  18: stxvd2x vs43,r4,r5        */
20333 +       .long   0x7d642fd9      /*  1c: stxvd2ux vs43,r4,r5       */
20334 +       .long   0xf0642850      /*  20: xxmrghd vs3,vs4,vs5       */
20335 +       .long   0xf16c6857      /*  24: xxmrghd vs43,vs44,vs45    */
20336 +       .long   0xf0642b50      /*  28: xxmrgld vs3,vs4,vs5       */
20337 +       .long   0xf16c6b57      /*  2c: xxmrgld vs43,vs44,vs45    */
20338 +       .long   0xf0642850      /*  30: xxmrghd vs3,vs4,vs5       */
20339 +       .long   0xf16c6857      /*  34: xxmrghd vs43,vs44,vs45    */
20340 +       .long   0xf0642b50      /*  38: xxmrgld vs3,vs4,vs5       */
20341 +       .long   0xf16c6b57      /*  3c: xxmrgld vs43,vs44,vs45    */
20342 +       .long   0xf0642950      /*  40: xxpermdi vs3,vs4,vs5,1    */
20343 +       .long   0xf16c6957      /*  44: xxpermdi vs43,vs44,vs45,1 */
20344 +       .long   0xf0642a50      /*  48: xxpermdi vs3,vs4,vs5,2    */
20345 +       .long   0xf16c6a57      /*  4c: xxpermdi vs43,vs44,vs45,2 */
20346 +       .long   0xf0642780      /*  50: xvmovdp vs3,vs4           */
20347 +       .long   0xf16c6787      /*  54: xvmovdp vs43,vs44         */
20348 +       .long   0xf0642780      /*  58: xvmovdp vs3,vs4           */
20349 +       .long   0xf16c6787      /*  5c: xvmovdp vs43,vs44         */
20350 +       .long   0xf0642f80      /*  60: xvcpsgndp vs3,vs4,vs5     */
20351 +       .long   0xf16c6f87      /*  64: xvcpsgndp vs43,vs44,vs45  */
20352 +       .long   0x7c00007c      /*  68: wait                      */
20353 +       .long   0x7c00007c      /*  6c: wait                      */
20354 +       .long   0x7c20007c      /*  70: waitrsv                   */
20355 +       .long   0x7c20007c      /*  74: waitrsv                   */
20356 +       .long   0x7c40007c      /*  78: waitimpl                  */
20357 +       .long   0x7c40007c      /*  7c: waitimpl                  */
20358 +       .long   0x4c000324      /*  80: doze                      */
20359 +       .long   0x4c000364      /*  84: nap                       */
20360 +       .long   0x4c0003a4      /*  88: sleep                     */
20361 +       .long   0x4c0003e4      /*  8c: rvwinkle                  */
20362 +       .long   0x7c830134      /*  90: prtyw   r3,r4             */
20363 +       .long   0x7dcd0174      /*  94: prtyd   r13,r14           */
20364 +       .long   0x7d5c02a6      /*  98: mfcfar  r10               */
20365 +       .long   0x7d7c03a6      /*  9c: mtcfar  r11               */
20366 +       .long   0x7c832bf8      /*  a0: cmpb    r3,r4,r5          */
20367 +       .long   0x7d4b662a      /*  a4: lwzcix  r10,r11,r12       */
20368 +       .long   0xee119004      /*  a8: dadd    f16,f17,f18       */
20369 +       .long   0xfe96c004      /*  ac: daddq   f20,f22,f24       */
20370 +       .long   0x7c60066c      /*  b0: dss     3                 */
20371 +       .long   0x7e00066c      /*  b4: dssall                    */
20372 +       .long   0x7c2522ac      /*  b8: dst     r5,r4,1           */
20373 +       .long   0x7e083aac      /*  bc: dstt    r8,r7,0           */
20374 +       .long   0x7c6532ec      /*  c0: dstst   r5,r6,3           */
20375 +       .long   0x7e442aec      /*  c4: dststt  r4,r5,2           */
20376 +       .long   0x7d4b6356      /*  c8: divwe   r10,r11,r12       */
20377 +       .long   0x7d6c6b57      /*  cc: divwe.  r11,r12,r13       */
20378 +       .long   0x7d8d7756      /*  d0: divweo  r12,r13,r14       */
20379 +       .long   0x7dae7f57      /*  d4: divweo. r13,r14,r15       */
20380 +       .long   0x7d4b6316      /*  d8: divweu  r10,r11,r12       */
20381 +       .long   0x7d6c6b17      /*  dc: divweu. r11,r12,r13       */
20382 +       .long   0x7d8d7716      /*  e0: divweuo r12,r13,r14       */
20383 +       .long   0x7dae7f17      /*  e4: divweuo. r13,r14,r15      */
20384 +       .long   0x7e27d9f8      /*  e8: bpermd  r7,r17,r27        */
20385 +       .long   0x7e8a02f4      /*  ec: popcntw r10,r20           */
20386 +       .long   0x7e8a03f4      /*  f0: popcntd r10,r20           */
20387 +       .long   0x7e95b428      /*  f4: ldbrx   r20,r21,r22       */
20388 +       .long   0x7e95b528      /*  f8: stdbrx  r20,r21,r22       */
20389 +       .long   0x7d4056ee      /*  fc: lfiwzx  f10,0,r10         */
20390 +       .long   0x7d4956ee      /* 100: lfiwzx  f10,r9,r10        */
20391 +       .long   0xec802e9c      /* 104: fcfids  f4,f5             */
20392 +       .long   0xec802e9d      /* 108: fcfids. f4,f5             */
20393 +       .long   0xec802f9c      /* 10c: fcfidus f4,f5             */
20394 +       .long   0xec802f9d      /* 110: fcfidus. f4,f5            */
20395 +       .long   0xfc80291c      /* 114: fctiwu  f4,f5             */
20396 +       .long   0xfc80291d      /* 118: fctiwu. f4,f5             */
20397 +       .long   0xfc80291e      /* 11c: fctiwuz f4,f5             */
20398 +       .long   0xfc80291f      /* 120: fctiwuz. f4,f5            */
20399 +       .long   0xfc802f5c      /* 124: fctidu  f4,f5             */
20400 +       .long   0xfc802f5d      /* 128: fctidu. f4,f5             */
20401 +       .long   0xfc802f5e      /* 12c: fctiduz f4,f5             */
20402 +       .long   0xfc802f5f      /* 130: fctiduz. f4,f5            */
20403 +       .long   0xfc802f9c      /* 134: fcfidu  f4,f5             */
20404 +       .long   0xfc802f9d      /* 138: fcfidu. f4,f5             */
20405 +       .long   0xfc0a5900      /* 13c: ftdiv   cr0,f10,f11       */
20406 +       .long   0xff8a5900      /* 140: ftdiv   cr7,f10,f11       */
20407 +       .long   0xfc005140      /* 144: ftsqrt  cr0,f10           */
20408 +       .long   0xff805140      /* 148: ftsqrt  cr7,f10           */
20409 +       .long   0x7e084a2c      /* 14c: dcbtt   r8,r9             */
20410 +       .long   0x7e0849ec      /* 150: dcbtstt r8,r9             */
20411 +       .long   0xed406644      /* 154: dcffix  f10,f12           */
20412 +       .long   0xee80b645      /* 158: dcffix. f20,f22           */
20413 +       .long   0x7d4b6068      /* 15c: lbarx   r10,r11,r12       */
20414 +       .long   0x7d4b6068      /* 160: lbarx   r10,r11,r12       */
20415 +       .long   0x7d4b6069      /* 164: lbarx   r10,r11,r12,1     */
20416 +       .long   0x7e95b0e8      /* 168: lharx   r20,r21,r22       */
20417 +       .long   0x7e95b0e8      /* 16c: lharx   r20,r21,r22       */
20418 +       .long   0x7e95b0e9      /* 170: lharx   r20,r21,r22,1     */
20419 +       .long   0x7d4b656d      /* 174: stbcx.  r10,r11,r12       */
20420 +       .long   0x7d4b65ad      /* 178: sthcx.  r10,r11,r12       */
20421 +       .long   0xfdc07830      /* 17c: fre     f14,f15           */
20422 +       .long   0xfdc07831      /* 180: fre.    f14,f15           */
20423 +       .long   0xedc07830      /* 184: fres    f14,f15           */
20424 +       .long   0xedc07831      /* 188: fres.   f14,f15           */
20425 +       .long   0xfdc07834      /* 18c: frsqrte f14,f15           */
20426 +       .long   0xfdc07835      /* 190: frsqrte. f14,f15          */
20427 +       .long   0xedc07834      /* 194: frsqrtes f14,f15          */
20428 +       .long   0xedc07835      /* 198: frsqrtes. f14,f15         */
20429 +       .long   0x7c43271e      /* 19c: isel    r2,r3,r4,28       */
20430 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
20431 new file mode 100644
20432 index 0000000..66f7a39
20433 --- /dev/null
20434 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
20435 @@ -0,0 +1,455 @@
20436 +       .file   "x86_64-vla-typedef.c"
20437 +       .section        .debug_abbrev,"",@progbits
20438 +.Ldebug_abbrev0:
20439 +       .section        .debug_info,"",@progbits
20440 +.Ldebug_info0:
20441 +       .section        .debug_line,"",@progbits
20442 +.Ldebug_line0:
20443 +       .text
20444 +.Ltext0:
20445 +.globl foo
20446 +       .type   foo, @function
20447 +foo:
20448 +.LFB2:
20449 +       .file 1 "x86_64-vla-typedef.c"
20450 +       .loc 1 22 0
20451 +       pushq   %rbp
20452 +.LCFI0:
20453 +       movq    %rsp, %rbp
20454 +.LCFI1:
20455 +       subq    $64, %rsp
20456 +.LCFI2:
20457 +       movl    %edi, -36(%rbp)
20458 +       .loc 1 22 0
20459 +       movq    %rsp, %rax
20460 +       movq    %rax, -48(%rbp)
20461 +       .loc 1 23 0
20462 +       movl    -36(%rbp), %edx
20463 +       movslq  %edx,%rax
20464 +       subq    $1, %rax
20465 +       movq    %rax, -24(%rbp)
20466 +       .loc 1 24 0
20467 +       movslq  %edx,%rax
20468 +       addq    $15, %rax
20469 +       addq    $15, %rax
20470 +       shrq    $4, %rax
20471 +       salq    $4, %rax
20472 +       subq    %rax, %rsp
20473 +       movq    %rsp, -56(%rbp)
20474 +       movq    -56(%rbp), %rax
20475 +       addq    $15, %rax
20476 +       shrq    $4, %rax
20477 +       salq    $4, %rax
20478 +       movq    %rax, -56(%rbp)
20479 +       movq    -56(%rbp), %rax
20480 +       movq    %rax, -16(%rbp)
20481 +       .loc 1 27 0
20482 +       movl    $0, -4(%rbp)
20483 +       jmp     .L2
20484 +.L3:
20485 +       .loc 1 28 0
20486 +       movl    -4(%rbp), %esi
20487 +       movl    -4(%rbp), %eax
20488 +       movl    %eax, %ecx
20489 +       movq    -16(%rbp), %rdx
20490 +       movslq  %esi,%rax
20491 +       movb    %cl, (%rdx,%rax)
20492 +       .loc 1 27 0
20493 +       addl    $1, -4(%rbp)
20494 +.L2:
20495 +       movl    -4(%rbp), %eax
20496 +       cmpl    -36(%rbp), %eax
20497 +       jl      .L3
20498 +       .loc 1 30 0
20499 +       .globl  break_here
20500 +break_here:
20501 +       movq    -16(%rbp), %rax
20502 +       movb    $0, (%rax)
20503 +       movq    -48(%rbp), %rsp
20504 +       .loc 1 31 0
20505 +       leave
20506 +       ret
20507 +.LFE2:
20508 +       .size   foo, .-foo
20509 +       .section        .debug_frame,"",@progbits
20510 +.Lframe0:
20511 +       .long   .LECIE0-.LSCIE0
20512 +.LSCIE0:
20513 +       .long   0xffffffff
20514 +       .byte   0x1
20515 +       .string ""
20516 +       .uleb128 0x1
20517 +       .sleb128 -8
20518 +       .byte   0x10
20519 +       .byte   0xc
20520 +       .uleb128 0x7
20521 +       .uleb128 0x8
20522 +       .byte   0x90
20523 +       .uleb128 0x1
20524 +       .align 8
20525 +.LECIE0:
20526 +.LSFDE0:
20527 +       .long   .LEFDE0-.LASFDE0
20528 +.LASFDE0:
20529 +       .long   .Lframe0
20530 +       .quad   .LFB2
20531 +       .quad   .LFE2-.LFB2
20532 +       .byte   0x4
20533 +       .long   .LCFI0-.LFB2
20534 +       .byte   0xe
20535 +       .uleb128 0x10
20536 +       .byte   0x86
20537 +       .uleb128 0x2
20538 +       .byte   0x4
20539 +       .long   .LCFI1-.LCFI0
20540 +       .byte   0xd
20541 +       .uleb128 0x6
20542 +       .align 8
20543 +.LEFDE0:
20544 +       .section        .eh_frame,"a",@progbits
20545 +.Lframe1:
20546 +       .long   .LECIE1-.LSCIE1
20547 +.LSCIE1:
20548 +       .long   0x0
20549 +       .byte   0x1
20550 +       .string "zR"
20551 +       .uleb128 0x1
20552 +       .sleb128 -8
20553 +       .byte   0x10
20554 +       .uleb128 0x1
20555 +       .byte   0x3
20556 +       .byte   0xc
20557 +       .uleb128 0x7
20558 +       .uleb128 0x8
20559 +       .byte   0x90
20560 +       .uleb128 0x1
20561 +       .align 8
20562 +.LECIE1:
20563 +.LSFDE1:
20564 +       .long   .LEFDE1-.LASFDE1
20565 +.LASFDE1:
20566 +       .long   .LASFDE1-.Lframe1
20567 +       .long   .LFB2
20568 +       .long   .LFE2-.LFB2
20569 +       .uleb128 0x0
20570 +       .byte   0x4
20571 +       .long   .LCFI0-.LFB2
20572 +       .byte   0xe
20573 +       .uleb128 0x10
20574 +       .byte   0x86
20575 +       .uleb128 0x2
20576 +       .byte   0x4
20577 +       .long   .LCFI1-.LCFI0
20578 +       .byte   0xd
20579 +       .uleb128 0x6
20580 +       .align 8
20581 +.LEFDE1:
20582 +       .text
20583 +.Letext0:
20584 +       .section        .debug_loc,"",@progbits
20585 +.Ldebug_loc0:
20586 +.LLST0:
20587 +       .quad   .LFB2-.Ltext0
20588 +       .quad   .LCFI0-.Ltext0
20589 +       .value  0x2
20590 +       .byte   0x77
20591 +       .sleb128 8
20592 +       .quad   .LCFI0-.Ltext0
20593 +       .quad   .LCFI1-.Ltext0
20594 +       .value  0x2
20595 +       .byte   0x77
20596 +       .sleb128 16
20597 +       .quad   .LCFI1-.Ltext0
20598 +       .quad   .LFE2-.Ltext0
20599 +       .value  0x2
20600 +       .byte   0x76
20601 +       .sleb128 16
20602 +       .quad   0x0
20603 +       .quad   0x0
20604 +       .section        .debug_info
20605 +       .long   .Ldebug_end - .Ldebug_start
20606 +.Ldebug_start:
20607 +       .value  0x2
20608 +       .long   .Ldebug_abbrev0
20609 +       .byte   0x8
20610 +       .uleb128 0x1
20611 +       .long   .LASF2
20612 +       .byte   0x1
20613 +       .long   .LASF3
20614 +       .long   .LASF4
20615 +       .quad   .Ltext0
20616 +       .quad   .Letext0
20617 +       .long   .Ldebug_line0
20618 +       .uleb128 0x2
20619 +       .byte   0x1
20620 +       .string "foo"
20621 +       .byte   0x1
20622 +       .byte   0x16
20623 +       .byte   0x1
20624 +       .quad   .LFB2
20625 +       .quad   .LFE2
20626 +       .long   .LLST0
20627 +       .long   0x83
20628 +       .uleb128 0x3
20629 +       .long   .LASF5
20630 +       .byte   0x1
20631 +       .byte   0x15
20632 +       .long   0x83
20633 +       .byte   0x2
20634 +       .byte   0x91
20635 +       .sleb128 -52
20636 +.Ltag_typedef:
20637 +       .uleb128 0x4
20638 +       .long   .LASF6
20639 +       .byte   0x1
20640 +       .byte   0x17
20641 +       .long   .Ltag_array_type - .debug_info
20642 +       .uleb128 0x5    /* Abbrev Number: 5 (DW_TAG_variable) */
20643 +       .long   .LASF0
20644 +       .byte   0x1
20645 +       .byte   0x18
20646 +#if 1
20647 +       .long   .Ltag_typedef - .debug_info
20648 +#else
20649 +       /* Debugging only: Skip the typedef indirection.  */
20650 +       .long   .Ltag_array_type - .debug_info
20651 +#endif
20652 +       /* DW_AT_location: DW_FORM_block1: start */
20653 +       .byte   0x3
20654 +       .byte   0x91
20655 +       .sleb128 -32
20656 +#if 0
20657 +       .byte   0x6     /* DW_OP_deref */
20658 +#else
20659 +       .byte   0x96    /* DW_OP_nop */
20660 +#endif
20661 +       /* DW_AT_location: DW_FORM_block1: end */
20662 +       .uleb128 0x6
20663 +       .string "i"
20664 +       .byte   0x1
20665 +       .byte   0x19
20666 +       .long   0x83
20667 +       .byte   0x2
20668 +       .byte   0x91
20669 +       .sleb128 -20
20670 +       .byte   0x0
20671 +       .uleb128 0x7
20672 +       .byte   0x4
20673 +       .byte   0x5
20674 +       .string "int"
20675 +.Ltag_array_type:
20676 +       .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
20677 +       .long   0xa0 + (2f - 1f)        /* DW_AT_type: DW_FORM_ref4 */
20678 +       .long   0x9d + (2f - 1f)        /* DW_AT_sibling: DW_FORM_ref4 */
20679 +1:     /* DW_AT_data_location: DW_FORM_block1: start */
20680 +       .byte   2f - 3f /* length */
20681 +3:
20682 +       .byte   0x97    /* DW_OP_push_object_address */
20683 +       .byte   0x6     /* DW_OP_deref */
20684 +2:     /* DW_AT_data_location: DW_FORM_block1: end */
20685 +       .uleb128 0x9
20686 +       .long   0x9d + (2b - 1b)        /* DW_AT_type: DW_FORM_ref4 */
20687 +       .byte   0x3
20688 +       .byte   0x91
20689 +       .sleb128 -40
20690 +       .byte   0x6
20691 +       .byte   0x0
20692 +       .uleb128 0xa
20693 +       .byte   0x8
20694 +       .byte   0x7
20695 +       .uleb128 0xb
20696 +       .byte   0x1
20697 +       .byte   0x6
20698 +       .long   .LASF1
20699 +       .byte   0x0
20700 +.Ldebug_end:
20701 +       .section        .debug_abbrev
20702 +       .uleb128 0x1
20703 +       .uleb128 0x11
20704 +       .byte   0x1
20705 +       .uleb128 0x25
20706 +       .uleb128 0xe
20707 +       .uleb128 0x13
20708 +       .uleb128 0xb
20709 +       .uleb128 0x3
20710 +       .uleb128 0xe
20711 +       .uleb128 0x1b
20712 +       .uleb128 0xe
20713 +       .uleb128 0x11
20714 +       .uleb128 0x1
20715 +       .uleb128 0x12
20716 +       .uleb128 0x1
20717 +       .uleb128 0x10
20718 +       .uleb128 0x6
20719 +       .byte   0x0
20720 +       .byte   0x0
20721 +       .uleb128 0x2
20722 +       .uleb128 0x2e
20723 +       .byte   0x1
20724 +       .uleb128 0x3f
20725 +       .uleb128 0xc
20726 +       .uleb128 0x3
20727 +       .uleb128 0x8
20728 +       .uleb128 0x3a
20729 +       .uleb128 0xb
20730 +       .uleb128 0x3b
20731 +       .uleb128 0xb
20732 +       .uleb128 0x27
20733 +       .uleb128 0xc
20734 +       .uleb128 0x11
20735 +       .uleb128 0x1
20736 +       .uleb128 0x12
20737 +       .uleb128 0x1
20738 +       .uleb128 0x40
20739 +       .uleb128 0x6
20740 +       .uleb128 0x1
20741 +       .uleb128 0x13
20742 +       .byte   0x0
20743 +       .byte   0x0
20744 +       .uleb128 0x3
20745 +       .uleb128 0x5
20746 +       .byte   0x0
20747 +       .uleb128 0x3
20748 +       .uleb128 0xe
20749 +       .uleb128 0x3a
20750 +       .uleb128 0xb
20751 +       .uleb128 0x3b
20752 +       .uleb128 0xb
20753 +       .uleb128 0x49
20754 +       .uleb128 0x13
20755 +       .uleb128 0x2
20756 +       .uleb128 0xa
20757 +       .byte   0x0
20758 +       .byte   0x0
20759 +       .uleb128 0x4
20760 +       .uleb128 0x16
20761 +       .byte   0x0
20762 +       .uleb128 0x3
20763 +       .uleb128 0xe
20764 +       .uleb128 0x3a
20765 +       .uleb128 0xb
20766 +       .uleb128 0x3b
20767 +       .uleb128 0xb
20768 +       .uleb128 0x49
20769 +       .uleb128 0x13
20770 +       .byte   0x0
20771 +       .byte   0x0
20772 +       .uleb128 0x5
20773 +       .uleb128 0x34
20774 +       .byte   0x0
20775 +       .uleb128 0x3
20776 +       .uleb128 0xe
20777 +       .uleb128 0x3a
20778 +       .uleb128 0xb
20779 +       .uleb128 0x3b
20780 +       .uleb128 0xb
20781 +       .uleb128 0x49
20782 +       .uleb128 0x13
20783 +       .uleb128 0x2
20784 +       .uleb128 0xa
20785 +       .byte   0x0
20786 +       .byte   0x0
20787 +       .uleb128 0x6
20788 +       .uleb128 0x34
20789 +       .byte   0x0
20790 +       .uleb128 0x3
20791 +       .uleb128 0x8
20792 +       .uleb128 0x3a
20793 +       .uleb128 0xb
20794 +       .uleb128 0x3b
20795 +       .uleb128 0xb
20796 +       .uleb128 0x49
20797 +       .uleb128 0x13
20798 +       .uleb128 0x2
20799 +       .uleb128 0xa
20800 +       .byte   0x0
20801 +       .byte   0x0
20802 +       .uleb128 0x7
20803 +       .uleb128 0x24
20804 +       .byte   0x0
20805 +       .uleb128 0xb
20806 +       .uleb128 0xb
20807 +       .uleb128 0x3e
20808 +       .uleb128 0xb
20809 +       .uleb128 0x3
20810 +       .uleb128 0x8
20811 +       .byte   0x0
20812 +       .byte   0x0
20813 +       .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
20814 +       .uleb128 0x1
20815 +       .byte   0x1
20816 +       .uleb128 0x49   /* DW_AT_type */
20817 +       .uleb128 0x13   /* DW_FORM_ref4 */
20818 +       .uleb128 0x1    /* DW_AT_sibling */
20819 +       .uleb128 0x13   /* DW_FORM_ref4 */
20820 +       .uleb128 0x50   /* DW_AT_data_location */
20821 +       .uleb128 0xa    /* DW_FORM_block1 */
20822 +       .byte   0x0
20823 +       .byte   0x0
20824 +       .uleb128 0x9
20825 +       .uleb128 0x21
20826 +       .byte   0x0
20827 +       .uleb128 0x49   /* DW_AT_type */
20828 +       .uleb128 0x13   /* DW_FORM_ref4 */
20829 +       .uleb128 0x2f
20830 +       .uleb128 0xa
20831 +       .byte   0x0
20832 +       .byte   0x0
20833 +       .uleb128 0xa
20834 +       .uleb128 0x24
20835 +       .byte   0x0
20836 +       .uleb128 0xb
20837 +       .uleb128 0xb
20838 +       .uleb128 0x3e
20839 +       .uleb128 0xb
20840 +       .byte   0x0
20841 +       .byte   0x0
20842 +       .uleb128 0xb
20843 +       .uleb128 0x24
20844 +       .byte   0x0
20845 +       .uleb128 0xb
20846 +       .uleb128 0xb
20847 +       .uleb128 0x3e
20848 +       .uleb128 0xb
20849 +       .uleb128 0x3
20850 +       .uleb128 0xe
20851 +       .byte   0x0
20852 +       .byte   0x0
20853 +       .byte   0x0
20854 +       .section        .debug_pubnames,"",@progbits
20855 +       .long   0x16
20856 +       .value  0x2
20857 +       .long   .Ldebug_info0
20858 +       .long   0xa8
20859 +       .long   0x2d
20860 +       .string "foo"
20861 +       .long   0x0
20862 +       .section        .debug_aranges,"",@progbits
20863 +       .long   0x2c
20864 +       .value  0x2
20865 +       .long   .Ldebug_info0
20866 +       .byte   0x8
20867 +       .byte   0x0
20868 +       .value  0x0
20869 +       .value  0x0
20870 +       .quad   .Ltext0
20871 +       .quad   .Letext0-.Ltext0
20872 +       .quad   0x0
20873 +       .quad   0x0
20874 +       .section        .debug_str,"MS",@progbits,1
20875 +.LASF0:
20876 +       .string "array"
20877 +.LASF5:
20878 +       .string "size"
20879 +.LASF3:
20880 +       .string "x86_64-vla-typedef.c"
20881 +.LASF6:
20882 +       .string "array_t"
20883 +.LASF1:
20884 +       .string "char"
20885 +.LASF4:
20886 +       .string "gdb.arch"
20887 +.LASF2:
20888 +       .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
20889 +       .ident  "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
20890 +       .section        .note.GNU-stack,"",@progbits
20891 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
20892 new file mode 100644
20893 index 0000000..b809c4e
20894 --- /dev/null
20895 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
20896 @@ -0,0 +1,43 @@
20897 +/* This testcase is part of GDB, the GNU debugger.
20898 +
20899 +   Copyright 2008 Free Software Foundation, Inc.
20900 +
20901 +   This program is free software; you can redistribute it and/or modify
20902 +   it under the terms of the GNU General Public License as published by
20903 +   the Free Software Foundation; either version 3 of the License, or
20904 +   (at your option) any later version.
20905 +
20906 +   This program is distributed in the hope that it will be useful,
20907 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
20908 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20909 +   GNU General Public License for more details.
20910 +
20911 +   You should have received a copy of the GNU General Public License
20912 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20913 +
20914 +#if 0
20915 +
20916 +void
20917 +foo (int size)
20918 +{
20919 +  typedef char array_t[size];
20920 +  array_t array;
20921 +  int i;
20922 +
20923 +  for (i = 0; i < size; i++)
20924 +    array[i] = i;
20925 +
20926 +  array[0] = 0;        /* break-here */
20927 +}
20928 +
20929 +#else
20930 +
20931 +int
20932 +main (void)
20933 +{
20934 +  foo (26);
20935 +  foo (78);
20936 +  return 0;
20937 +}
20938 +
20939 +#endif
20940 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
20941 new file mode 100644
20942 index 0000000..b05411e
20943 --- /dev/null
20944 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
20945 @@ -0,0 +1,64 @@
20946 +# Copyright 2009 Free Software Foundation, Inc.
20947 +
20948 +# This program is free software; you can redistribute it and/or modify
20949 +# it under the terms of the GNU General Public License as published by
20950 +# the Free Software Foundation; either version 3 of the License, or
20951 +# (at your option) any later version.
20952 +#
20953 +# This program is distributed in the hope that it will be useful,
20954 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
20955 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20956 +# GNU General Public License for more details.
20957 +#
20958 +# You should have received a copy of the GNU General Public License
20959 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20960 +
20961 +# Test DW_AT_data_location accessed through DW_TAG_typedef intermediate.
20962 +
20963 +if ![istarget "x86_64-*-*"] then {
20964 +    verbose "Skipping over gdb.arch/x86_64-vla-typedef.exp test made only for x86_64."
20965 +    return
20966 +}
20967 +
20968 +set testfile x86_64-vla-typedef
20969 +set srcasmfile ${testfile}-foo.S
20970 +set srcfile ${testfile}.c
20971 +set binfile ${objdir}/${subdir}/${testfile}
20972 +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
20973 +if  { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
20974 +    untested "Couldn't compile test program"
20975 +    return -1
20976 +}
20977 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
20978 +    untested "Couldn't compile test program"
20979 +    return -1
20980 +}
20981 +
20982 +gdb_exit
20983 +gdb_start
20984 +gdb_reinitialize_dir $srcdir/$subdir
20985 +gdb_load ${binfile}
20986 +
20987 +if ![runto_main] {
20988 +    untested x86_64-vla-typedef
20989 +    return -1
20990 +}
20991 +
20992 +gdb_breakpoint "break_here"
20993 +
20994 +gdb_continue_to_breakpoint "break_here"
20995 +
20996 +gdb_test "whatis array" "type = array_t" "first: whatis array"
20997 +
20998 +gdb_test "ptype array" "type = char \\\[26\\\]" "first: ptype array"
20999 +
21000 +gdb_test "p array\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
21001 +gdb_test "p array\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
21002 +gdb_test "p array\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
21003 +gdb_test "p array\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
21004 +
21005 +gdb_continue_to_breakpoint "break_here"
21006 +
21007 +gdb_test "whatis array" "type = array_t" "second: whatis array"
21008 +
21009 +gdb_test "ptype array" "type = char \\\[78\\\]" "second: ptype array"
21010 diff --git a/gdb/testsuite/gdb.base/arrayidx.c b/gdb/testsuite/gdb.base/arrayidx.c
21011 index 98d4d35..f98a656 100644
21012 --- a/gdb/testsuite/gdb.base/arrayidx.c
21013 +++ b/gdb/testsuite/gdb.base/arrayidx.c
21014 @@ -17,6 +17,13 @@
21015  
21016  int array[] = {1, 2, 3, 4};
21017  
21018 +#ifdef __GNUC__
21019 +struct
21020 +  {
21021 +    int a[0];
21022 +  } unbound;
21023 +#endif
21024 +
21025  int
21026  main (void)
21027  {
21028 diff --git a/gdb/testsuite/gdb.base/arrayidx.exp b/gdb/testsuite/gdb.base/arrayidx.exp
21029 index 71ce4aa..af0e5f8 100644
21030 --- a/gdb/testsuite/gdb.base/arrayidx.exp
21031 +++ b/gdb/testsuite/gdb.base/arrayidx.exp
21032 @@ -59,4 +59,12 @@ gdb_test "print array" \
21033           "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
21034           "Print array with array-indexes on"
21035  
21036 -
21037 +set test "p unbound.a == &unbound.a\[0\]"
21038 +gdb_test_multiple $test $test {
21039 +    -re " = 1\r\n$gdb_prompt $" {
21040 +       pass $test
21041 +    }
21042 +    -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" {
21043 +       unsupported "$test (no GCC)"
21044 +    }
21045 +}
21046 diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp
21047 index d76cc36..496ff18 100644
21048 --- a/gdb/testsuite/gdb.base/help.exp
21049 +++ b/gdb/testsuite/gdb.base/help.exp
21050 @@ -606,7 +606,7 @@ gdb_test "help stepi" "Step one instruction exactly\.\[\r\n\]+Argument N means d
21051  gdb_test "help signal" "Continue program giving it signal.*" "help signal"
21052  # test help source
21053  # vxgdb reads .vxgdbinit
21054 -gdb_test "help source" "Read commands from a file named FILE\.\[\r\n\]+Optional -v switch \\(before the filename\\) causes each command in\[\r\n\]+FILE to be echoed as it is executed\.\[\r\n\]+Note that the file \"\[^\"\]*\" is read automatically in this way\[\r\n\]+when GDB is started\." "help source"
21055 +gdb_test "help source" "Read commands from a file named FILE\.\[\r\n\]+Optional -v switch \\(before the filename\\) causes each command in\[\r\n\]+FILE to be echoed as it is executed\.\[\r\n\]+Note that the file \"\[^\"\]*\" is read automatically in this way\[\r\n\]+when GDB is started\.\[\r\n\]+Optional -p switch \\(before the filename\\) causes FILE to be evaluated\[\r\n\]+as Python code\." "help source"
21056  # test help stack
21057  test_class_help "stack" {
21058      "Examining the stack\..*\[\r\n\]+"
21059 diff --git a/gdb/testsuite/gdb.base/lineno-makeup-func.c b/gdb/testsuite/gdb.base/lineno-makeup-func.c
21060 new file mode 100644
21061 index 0000000..1a0220e
21062 --- /dev/null
21063 +++ b/gdb/testsuite/gdb.base/lineno-makeup-func.c
21064 @@ -0,0 +1,21 @@
21065 +/* This testcase is part of GDB, the GNU debugger.
21066 +
21067 +   Copyright 2009 Free Software Foundation, Inc.
21068 +
21069 +   This program is free software; you can redistribute it and/or modify
21070 +   it under the terms of the GNU General Public License as published by
21071 +   the Free Software Foundation; either version 3 of the License, or
21072 +   (at your option) any later version.
21073 +
21074 +   This program is distributed in the hope that it will be useful,
21075 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
21076 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21077 +   GNU General Public License for more details.
21078 +
21079 +   You should have received a copy of the GNU General Public License
21080 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21081 +
21082 +void
21083 +func (void)
21084 +{
21085 +}
21086 diff --git a/gdb/testsuite/gdb.base/lineno-makeup.c b/gdb/testsuite/gdb.base/lineno-makeup.c
21087 new file mode 100644
21088 index 0000000..bb20e98
21089 --- /dev/null
21090 +++ b/gdb/testsuite/gdb.base/lineno-makeup.c
21091 @@ -0,0 +1,35 @@
21092 +/* This testcase is part of GDB, the GNU debugger.
21093 +
21094 +   Copyright 2009 Free Software Foundation, Inc.
21095 +
21096 +   This program is free software; you can redistribute it and/or modify
21097 +   it under the terms of the GNU General Public License as published by
21098 +   the Free Software Foundation; either version 3 of the License, or
21099 +   (at your option) any later version.
21100 +
21101 +   This program is distributed in the hope that it will be useful,
21102 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
21103 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21104 +   GNU General Public License for more details.
21105 +
21106 +   You should have received a copy of the GNU General Public License
21107 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21108 +
21109 +/* DW_AT_low_pc-DW_AT_high_pc should cover the function without line number
21110 +   information (.debug_line) so we cannot use an external object file.
21111 +   
21112 +   It must not be just a label as it would alias on the next function even for
21113 +   correct GDB.  Therefore some stub data must be placed there.
21114 +   
21115 +   We need to provide a real stub function body as at least s390
21116 +   (s390_analyze_prologue) would skip the whole body till reaching `main'.  */
21117 +
21118 +extern void func (void);
21119 +asm ("func: .incbin \"gdb.base/lineno-makeup-func.bin\"");
21120 +
21121 +int
21122 +main (void)
21123 +{
21124 +  func ();
21125 +  return 0;
21126 +}
21127 diff --git a/gdb/testsuite/gdb.base/lineno-makeup.exp b/gdb/testsuite/gdb.base/lineno-makeup.exp
21128 new file mode 100644
21129 index 0000000..0c75b84
21130 --- /dev/null
21131 +++ b/gdb/testsuite/gdb.base/lineno-makeup.exp
21132 @@ -0,0 +1,78 @@
21133 +# Copyright 2009 Free Software Foundation, Inc.
21134 +
21135 +# This program is free software; you can redistribute it and/or modify
21136 +# it under the terms of the GNU General Public License as published by
21137 +# the Free Software Foundation; either version 3 of the License, or
21138 +# (at your option) any later version.
21139 +#
21140 +# This program is distributed in the hope that it will be useful,
21141 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21142 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21143 +# GNU General Public License for more details.
21144 +#
21145 +# You should have received a copy of the GNU General Public License
21146 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21147 +
21148 +set testfile "lineno-makeup"
21149 +set srcfuncfile ${testfile}-func.c
21150 +set srcfile ${testfile}.c
21151 +set objfuncfile ${objdir}/${subdir}/${testfile}-func.o
21152 +set binfuncfile ${objdir}/${subdir}/${testfile}-func.bin
21153 +set binfile ${objdir}/${subdir}/${testfile}
21154 +
21155 +if { [gdb_compile "${srcdir}/${subdir}/${srcfuncfile}" "${objfuncfile}" object {}] != "" } {
21156 +    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
21157 +}
21158 +
21159 +set objcopy [catch "exec objcopy -O binary --only-section .text ${objfuncfile} ${binfuncfile}" output]
21160 +verbose -log "objcopy=$objcopy: $output"
21161 +if { $objcopy != 0 } {
21162 +    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
21163 +}
21164 +set binfuncfilesize [file size $binfuncfile]
21165 +verbose -log "file size $binfuncfile = $binfuncfilesize"
21166 +
21167 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21168 +    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
21169 +}
21170 +
21171 +gdb_exit
21172 +gdb_start
21173 +gdb_reinitialize_dir $srcdir/$subdir
21174 +gdb_load ${binfile}
21175 +
21176 +set b_addr ""
21177 +set test "break func"
21178 +gdb_test_multiple $test $test {
21179 +    -re "Breakpoint \[0-9\]+ at (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
21180 +       set b_addr $expect_out(1,string)
21181 +       pass $test
21182 +    }
21183 +    -re "Breakpoint \[0-9\]+ at (0x\[0-9a-f\]+): .*\r\n$gdb_prompt $" {
21184 +       set b_addr $expect_out(1,string)
21185 +       fail $test
21186 +    }
21187 +}
21188 +verbose -log "b_addr=<$b_addr>"
21189 +
21190 +set p_addr ""
21191 +set test "print func"
21192 +gdb_test_multiple $test $test {
21193 +    -re "\\$\[0-9\]+ = {<text variable, no debug info>} (0x\[0-9a-f\]+) <func>\r\n$gdb_prompt $" {
21194 +       set p_addr $expect_out(1,string)
21195 +       pass $test
21196 +    }
21197 +}
21198 +verbose -log "p_addr=<$p_addr>"
21199 +
21200 +set test "break address belongs to func"
21201 +if {$b_addr == $p_addr} {
21202 +    pass "$test (exact match)"
21203 +} else {
21204 +    set skip [expr $b_addr - $p_addr]
21205 +    if {$skip > 0 && $skip < $binfuncfilesize} {
21206 +       pass "$test (prologue skip by $skip bytes)"
21207 +    } else {
21208 +       fail $test
21209 +    }
21210 +}
21211 diff --git a/gdb/testsuite/gdb.base/macscp.exp b/gdb/testsuite/gdb.base/macscp.exp
21212 index 55c4d31..df25d3c 100644
21213 --- a/gdb/testsuite/gdb.base/macscp.exp
21214 +++ b/gdb/testsuite/gdb.base/macscp.exp
21215 @@ -33,6 +33,14 @@ if [test_compiler_info gcc*] {
21216      lappend options additional_flags=-g3
21217  }
21218  
21219 +# Workaround ccache making lineno non-zero for command-line definitions.
21220 +if {[find_gcc] == "gcc" && [file executable "/usr/bin/gcc"]} {
21221 +    set result [catch "exec which gcc" output]
21222 +    if {$result == 0 && [string first "/ccache/" $output] >= -1} {
21223 +       lappend options "compiler=/usr/bin/gcc"
21224 +    }
21225 +}
21226 +
21227  # Generate the intermediate object file.  This is required by Darwin to
21228  # have access to the .debug_macinfo section.
21229  if  {[gdb_compile "${srcdir}/${subdir}/macscp1.c" "${objfile}" \
21230 diff --git a/gdb/testsuite/gdb.base/radix.exp b/gdb/testsuite/gdb.base/radix.exp
21231 index 750fd23..dfdb929 100644
21232 --- a/gdb/testsuite/gdb.base/radix.exp
21233 +++ b/gdb/testsuite/gdb.base/radix.exp
21234 @@ -162,13 +162,6 @@ gdb_test "set radix" \
21235      "Input and output radices now set to decimal 10, hex a, octal 12\." \
21236      "Reset radices"
21237  
21238 -gdb_test "set input-radix 0" \
21239 -    "Nonsense input radix ``decimal 0''; input radix unchanged\\." \
21240 -    "Reject input-radix 0"
21241 -gdb_test "show input-radix" \
21242 -    "Default input radix for entering numbers is 10\\." \
21243 -    "Input radix unchanged after rejecting 0"
21244 -
21245  gdb_test "set input-radix 1" \
21246      "Nonsense input radix ``decimal 1''; input radix unchanged\\." \
21247      "Reject input-radix 1"
21248 diff --git a/gdb/testsuite/gdb.base/valgrind-attach.c b/gdb/testsuite/gdb.base/valgrind-attach.c
21249 new file mode 100644
21250 index 0000000..84b57db
21251 --- /dev/null
21252 +++ b/gdb/testsuite/gdb.base/valgrind-attach.c
21253 @@ -0,0 +1,28 @@
21254 +/* This testcase is part of GDB, the GNU debugger.
21255 +
21256 +   Copyright 2009 Free Software Foundation, Inc.
21257 +
21258 +   This program is free software; you can redistribute it and/or modify
21259 +   it under the terms of the GNU General Public License as published by
21260 +   the Free Software Foundation; either version 3 of the License, or
21261 +   (at your option) any later version.
21262 +
21263 +   This program is distributed in the hope that it will be useful,
21264 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
21265 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21266 +   GNU General Public License for more details.
21267 +
21268 +   You should have received a copy of the GNU General Public License
21269 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21270 +
21271 +#include <stdlib.h>
21272 +
21273 +int
21274 +main (void)
21275 +{
21276 +  int *a = malloc (1);
21277 +
21278 +  a[10] = 0;           /* crash-here */
21279 +
21280 +  return 0;
21281 +}
21282 diff --git a/gdb/testsuite/gdb.base/valgrind-attach.exp b/gdb/testsuite/gdb.base/valgrind-attach.exp
21283 new file mode 100644
21284 index 0000000..1f9b26e
21285 --- /dev/null
21286 +++ b/gdb/testsuite/gdb.base/valgrind-attach.exp
21287 @@ -0,0 +1,94 @@
21288 +# Copyright 2009 Free Software Foundation, Inc.
21289 +
21290 +# This program is free software; you can redistribute it and/or modify
21291 +# it under the terms of the GNU General Public License as published by
21292 +# the Free Software Foundation; either version 3 of the License, or
21293 +# (at your option) any later version.
21294 +#
21295 +# This program is distributed in the hope that it will be useful,
21296 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21297 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21298 +# GNU General Public License for more details.
21299 +#
21300 +# You should have received a copy of the GNU General Public License
21301 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21302 +
21303 +set testfile valgrind-attach
21304 +set shfile ${testfile}.sh
21305 +set srcfile ${testfile}.c
21306 +set binfile ${objdir}/${subdir}/${testfile}
21307 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21308 +    untested "Couldn't compile test program"
21309 +    return -1
21310 +}
21311 +
21312 +gdb_exit
21313 +gdb_stop_suppressing_tests;
21314 +
21315 +set VALGRIND "valgrind"
21316 +
21317 +# Syntax for ${shfile} is: <binfile> <valgrind> <db-command-arguments>
21318 +set VALGRIND_SPAWN "sh ${srcdir}/${subdir}/${shfile} $binfile $VALGRIND $GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"
21319 +
21320 +set test "spawn valgrind"
21321 +verbose "Spawning $VALGRIND_SPAWN"
21322 +
21323 +if [info exists gdb_spawn_id] {
21324 +    fail $test
21325 +    return -1
21326 +}
21327 +
21328 +if ![is_remote host] {
21329 +    if { [which $VALGRIND] == 0 } then {
21330 +       untested "Couldn't find $VALGRIND"
21331 +       return -1
21332 +    }
21333 +}
21334 +set res [remote_spawn host "$VALGRIND_SPAWN"]
21335 +if { $res < 0 || $res == "" } {
21336 +    perror "Spawning $VALGRIND_SPAWN failed."
21337 +    return -1
21338 +}
21339 +set gdb_spawn_id -1;
21340 +
21341 +gdb_expect {
21342 +    -re "---- Attach to debugger \\? --- \\\[Return/N/n/Y/y/C/c\\\] ---- $" {
21343 +       pass $test
21344 +    }
21345 +    eof {
21346 +       perror "(eof) $VALGRIND never initialized"
21347 +       remote_close host
21348 +       return -1
21349 +    }
21350 +    timeout {
21351 +       perror "(timeout) $VALGRIND never initialized"
21352 +       remote_close host
21353 +       return -1
21354 +    }
21355 +}
21356 +send_gdb "y\n"
21357 +
21358 +set test "spawn gdb"
21359 +set test2 "crash line caught"
21360 +gdb_expect {
21361 +    -re "starting debugger with cmd:.* in main .* crash-here .*\[\r\n\]$gdb_prompt $" {
21362 +       pass $test
21363 +       pass $test2
21364 +    }
21365 +    -re "starting debugger with cmd:.*\[\r\n\]$gdb_prompt $" {
21366 +       pass $test
21367 +       fail $test2
21368 +    }
21369 +    eof {
21370 +       perror "(eof) $GDB never initialized"
21371 +       remote_close host
21372 +       return -1
21373 +    }
21374 +    timeout {
21375 +       perror "(timeout) $GDB never initialized"
21376 +       remote_close host
21377 +       return -1
21378 +    }
21379 +}
21380 +
21381 +remote_close host
21382 diff --git a/gdb/testsuite/gdb.base/valgrind-attach.sh b/gdb/testsuite/gdb.base/valgrind-attach.sh
21383 new file mode 100755
21384 index 0000000..f02c6f7
21385 --- /dev/null
21386 +++ b/gdb/testsuite/gdb.base/valgrind-attach.sh
21387 @@ -0,0 +1,20 @@
21388 +#! /bin/sh
21389 +
21390 +# Copyright 2009 Free Software Foundation, Inc.
21391 +
21392 +# This program is free software; you can redistribute it and/or modify
21393 +# it under the terms of the GNU General Public License as published by
21394 +# the Free Software Foundation; either version 3 of the License, or
21395 +# (at your option) any later version.
21396 +#
21397 +# This program is distributed in the hope that it will be useful,
21398 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21399 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21400 +# GNU General Public License for more details.
21401 +#
21402 +# You should have received a copy of the GNU General Public License
21403 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21404 +
21405 +BINFILE="$1"; shift
21406 +VALGRIND="$1"; shift
21407 +"$VALGRIND" --db-attach=yes --db-command="$* %f %p" "$BINFILE"
21408 diff --git a/gdb/testsuite/gdb.base/vla-overflow.c b/gdb/testsuite/gdb.base/vla-overflow.c
21409 new file mode 100644
21410 index 0000000..c5d5ee0
21411 --- /dev/null
21412 +++ b/gdb/testsuite/gdb.base/vla-overflow.c
21413 @@ -0,0 +1,30 @@
21414 +/* This testcase is part of GDB, the GNU debugger.
21415 +
21416 +   Copyright 2008 Free Software Foundation, Inc.
21417 +
21418 +   This program is free software; you can redistribute it and/or modify
21419 +   it under the terms of the GNU General Public License as published by
21420 +   the Free Software Foundation; either version 3 of the License, or
21421 +   (at your option) any later version.
21422 +
21423 +   This program is distributed in the hope that it will be useful,
21424 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
21425 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21426 +   GNU General Public License for more details.
21427 +
21428 +   You should have received a copy of the GNU General Public License
21429 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21430 +
21431 +#include <stdlib.h>
21432 +
21433 +int
21434 +main (int argc, char **argv)
21435 +{
21436 +  int array[argc];
21437 +
21438 +  array[0] = array[0];
21439 +
21440 +  abort ();
21441 +
21442 +  return 0;
21443 +}
21444 diff --git a/gdb/testsuite/gdb.base/vla-overflow.exp b/gdb/testsuite/gdb.base/vla-overflow.exp
21445 new file mode 100644
21446 index 0000000..7203a48
21447 --- /dev/null
21448 +++ b/gdb/testsuite/gdb.base/vla-overflow.exp
21449 @@ -0,0 +1,108 @@
21450 +# Copyright 2008 Free Software Foundation, Inc.
21451 +
21452 +# This program is free software; you can redistribute it and/or modify
21453 +# it under the terms of the GNU General Public License as published by
21454 +# the Free Software Foundation; either version 3 of the License, or
21455 +# (at your option) any later version.
21456 +#
21457 +# This program is distributed in the hope that it will be useful,
21458 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21459 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21460 +# GNU General Public License for more details.
21461 +#
21462 +# You should have received a copy of the GNU General Public License
21463 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21464 +
21465 +# We could crash in:
21466 +# #0  block_linkage_function (bl=0x0) at ../../gdb/block.c:69
21467 +# #1  in dwarf_block_get_frame_base (...) at ../../gdb/dwarf2block.c:97
21468 +#   97   framefunc = block_linkage_function (get_frame_block (frame, NULL));
21469 +# #2  in execute_stack_op (...) at ../../gdb/dwarf2expr.c:496
21470 +# #3  in dwarf_block_exec_core () at ../../gdb/dwarf2block.c:156
21471 +# #4  dwarf_block_exec (...) at ../../gdb/dwarf2block.c:206
21472 +# #5  in range_type_count_bound_internal (...) at ../../gdb/gdbtypes.c:1430
21473 +# #6  in create_array_type (...) at ../../gdb/gdbtypes.c:840
21474 +# ...
21475 +# #21 in psymtab_to_symtab (...) at ../../gdb/symfile.c:292
21476 +# ...
21477 +# #29 in backtrace_command_1 () at ../../gdb/stack.c:1273
21478 +
21479 +set testfile vla-overflow
21480 +set shfile ${objdir}/${subdir}/${testfile}-gdb.sh
21481 +set srcfile ${testfile}.c
21482 +set binfile ${objdir}/${subdir}/${testfile}
21483 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21484 +    untested "Couldn't compile test program"
21485 +    return -1
21486 +}
21487 +
21488 +set f [open "|getconf PAGESIZE" "r"]
21489 +gets $f pagesize
21490 +close $f
21491 +
21492 +gdb_exit
21493 +gdb_start
21494 +gdb_reinitialize_dir $srcdir/$subdir
21495 +gdb_load ${binfile}
21496 +
21497 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
21498 +
21499 +if { [runto_main] < 0 } {
21500 +    untested vla-overflow
21501 +    return -1
21502 +}
21503 +
21504 +# Get the GDB memory size when we stay at main.
21505 +
21506 +proc memory_v_pages_get {} {
21507 +    global pid_of_gdb pagesize
21508 +    set fd [open "/proc/$pid_of_gdb/statm"]
21509 +    gets $fd line
21510 +    close $fd
21511 +    # number of pages of virtual memory
21512 +    scan $line "%d" drs
21513 +    return $drs
21514 +}
21515 +
21516 +set pages_found [memory_v_pages_get]
21517 +
21518 +set mb_reserve 10
21519 +verbose -log "pages_found = $pages_found, mb_reserve = $mb_reserve"
21520 +set kb_found [expr $pages_found * $pagesize / 1024]
21521 +set kb_permit [expr $kb_found + 1 * 1024 + $mb_reserve * 1024]
21522 +verbose -log "kb_found = $kb_found, kb_permit = $kb_permit"
21523 +
21524 +# Create the ulimit wrapper.
21525 +set f [open $shfile "w"]
21526 +puts $f "#! /bin/sh"
21527 +puts $f "ulimit -v $kb_permit"
21528 +puts $f "exec $GDB \"\$@\""
21529 +close $f
21530 +remote_exec host "chmod +x $shfile"
21531 +
21532 +gdb_exit
21533 +set GDBold $GDB
21534 +set GDB "$shfile"
21535 +gdb_start
21536 +set GDB $GDBold
21537 +
21538 +gdb_reinitialize_dir $srcdir/$subdir
21539 +gdb_load ${binfile}
21540 +
21541 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
21542 +
21543 +# Check the size again after the second run.
21544 +# We must not stop in main as it would cache `array' and never crash later.
21545 +
21546 +gdb_run_cmd
21547 +
21548 +verbose -log "kb_found before abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
21549 +
21550 +gdb_test "" "Program received signal SIGABRT, Aborted..*" "Enter abort()"
21551 +
21552 +verbose -log "kb_found in abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
21553 +
21554 +# `abort' can get expressed as `*__GI_abort'.
21555 +gdb_test "bt" "in \[^ \]*abort \\(.* in main \\(.*" "Backtrace after abort()"
21556 +
21557 +verbose -log "kb_found in bt after abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
21558 diff --git a/gdb/testsuite/gdb.base/vla.c b/gdb/testsuite/gdb.base/vla.c
21559 new file mode 100644
21560 index 0000000..e1f3ed1
21561 --- /dev/null
21562 +++ b/gdb/testsuite/gdb.base/vla.c
21563 @@ -0,0 +1,55 @@
21564 +/* This testcase is part of GDB, the GNU debugger.
21565 +
21566 +   Copyright 2008 Free Software Foundation, Inc.
21567 +
21568 +   This program is free software; you can redistribute it and/or modify
21569 +   it under the terms of the GNU General Public License as published by
21570 +   the Free Software Foundation; either version 3 of the License, or
21571 +   (at your option) any later version.
21572 +
21573 +   This program is distributed in the hope that it will be useful,
21574 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
21575 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21576 +   GNU General Public License for more details.
21577 +
21578 +   You should have received a copy of the GNU General Public License
21579 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21580 +
21581 +#include <string.h>
21582 +
21583 +void
21584 +marker (void)
21585 +{
21586 +}
21587 +
21588 +void
21589 +bar (char *a, char *b, char *c, int size)
21590 +{
21591 +  memset (a, '1', size);
21592 +  memset (b, '2', size);
21593 +  memset (c, '3', 48);
21594 +}
21595 +
21596 +void
21597 +foo (int size)
21598 +{
21599 +  char temp1[size];
21600 +  char temp3[48];
21601 +
21602 +  temp1[size - 1] = '\0';
21603 +  {
21604 +    char temp2[size];
21605 +
21606 +    bar (temp1, temp2, temp3, size);
21607 +
21608 +    marker (); /* break-here */
21609 +  }
21610 +}
21611 +
21612 +int
21613 +main (void)
21614 +{
21615 +  foo (26);
21616 +  foo (78);
21617 +  return 0;
21618 +}
21619 diff --git a/gdb/testsuite/gdb.base/vla.exp b/gdb/testsuite/gdb.base/vla.exp
21620 new file mode 100644
21621 index 0000000..5da7378
21622 --- /dev/null
21623 +++ b/gdb/testsuite/gdb.base/vla.exp
21624 @@ -0,0 +1,62 @@
21625 +# Copyright 2008 Free Software Foundation, Inc.
21626 +
21627 +# This program is free software; you can redistribute it and/or modify
21628 +# it under the terms of the GNU General Public License as published by
21629 +# the Free Software Foundation; either version 3 of the License, or
21630 +# (at your option) any later version.
21631 +#
21632 +# This program is distributed in the hope that it will be useful,
21633 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21634 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21635 +# GNU General Public License for more details.
21636 +#
21637 +# You should have received a copy of the GNU General Public License
21638 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21639 +
21640 +set testfile vla
21641 +set srcfile ${testfile}.c
21642 +set binfile ${objdir}/${subdir}/${testfile}
21643 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21644 +    untested "Couldn't compile test program"
21645 +    return -1
21646 +}
21647 +
21648 +gdb_exit
21649 +gdb_start
21650 +gdb_reinitialize_dir $srcdir/$subdir
21651 +gdb_load ${binfile}
21652 +
21653 +if ![runto_main] {
21654 +    untested vla
21655 +    return -1
21656 +}
21657 +
21658 +gdb_breakpoint [gdb_get_line_number "break-here"]
21659 +
21660 +gdb_continue_to_breakpoint "break-here"
21661 +
21662 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "first: whatis temp1"
21663 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "first: whatis temp2"
21664 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "first: whatis temp3"
21665 +
21666 +gdb_test "ptype temp1" "type = char \\\[26\\\]" "first: ptype temp1"
21667 +gdb_test "ptype temp2" "type = char \\\[26\\\]" "first: ptype temp2"
21668 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "first: ptype temp3"
21669 +
21670 +gdb_test "p temp1" " = '1' <repeats 26 times>" "first: print temp1"
21671 +gdb_test "p temp2" " = '2' <repeats 26 times>" "first: print temp2"
21672 +gdb_test "p temp3" " = '3' <repeats 48 times>" "first: print temp3"
21673 +
21674 +gdb_continue_to_breakpoint "break-here"
21675 +
21676 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "second: whatis temp1"
21677 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "second: whatis temp2"
21678 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "second: whatis temp3"
21679 +
21680 +gdb_test "ptype temp1" "type = char \\\[78\\\]" "second: ptype temp1"
21681 +gdb_test "ptype temp2" "type = char \\\[78\\\]" "second: ptype temp2"
21682 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "second: ptype temp3"
21683 +
21684 +gdb_test "p temp1" " = '1' <repeats 78 times>" "second: print temp1"
21685 +gdb_test "p temp2" " = '2' <repeats 78 times>" "second: print temp2"
21686 +gdb_test "p temp3" " = '3' <repeats 48 times>" "second: print temp3"
21687 diff --git a/gdb/testsuite/gdb.base/watchpoint-hw.c b/gdb/testsuite/gdb.base/watchpoint-hw.c
21688 index 8da9af5..e2de53a 100644
21689 --- a/gdb/testsuite/gdb.base/watchpoint-hw.c
21690 +++ b/gdb/testsuite/gdb.base/watchpoint-hw.c
21691 @@ -20,5 +20,11 @@ int watchee;
21692  int
21693  main (void)
21694  {
21695 +  volatile int dummy;
21696 +
21697 +  dummy = watchee;
21698 +  dummy = 1;
21699 +  dummy = 2;   /* break-at-exit */
21700 +
21701    return 0;
21702  }
21703 diff --git a/gdb/testsuite/gdb.base/watchpoint-hw.exp b/gdb/testsuite/gdb.base/watchpoint-hw.exp
21704 index a2bb731..d74d6c7 100644
21705 --- a/gdb/testsuite/gdb.base/watchpoint-hw.exp
21706 +++ b/gdb/testsuite/gdb.base/watchpoint-hw.exp
21707 @@ -21,19 +21,12 @@ if {(![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"]
21708      return
21709  }
21710  
21711 -set testfile watchpoint-hw
21712 -set srcfile ${testfile}.c
21713 -set binfile ${objdir}/${subdir}/${testfile}
21714 -if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21715 -    untested "Couldn't compile test program"
21716 +set test watchpoint-hw
21717 +set srcfile ${test}.c
21718 +if { [prepare_for_testing ${test}.exp ${test} ${srcfile}] } {
21719      return -1
21720  }
21721  
21722 -gdb_exit
21723 -gdb_start
21724 -gdb_reinitialize_dir $srcdir/$subdir
21725 -gdb_load ${binfile}
21726 -
21727  # Create the watchpoint before the inferior gets started.  Now the native CPU
21728  # target is still not active and its `to_can_use_hw_breakpoint' is not
21729  # installed, therefore only a software watchpoint gets created.
21730 @@ -43,10 +36,40 @@ gdb_test "watch watchee" "atchpoint 1: watchee"
21731  # `runto_main' or `runto main' would delete the watchpoint created above.
21732  
21733  if { [gdb_start_cmd] < 0 } {
21734 -    untested start
21735 +    untested ${test}.exp
21736      return -1
21737  }
21738  gdb_test "" "main .* at .*" "start"
21739  
21740  # Check it is really a `hw'-watchpoint.
21741  gdb_test "info watchpoints" "1 *hw watchpoint .* watchee"
21742 +
21743 +# Before the inferior gets started we would get:
21744 +#      Target does not support this type of hardware watchpoint.
21745 +gdb_test "delete 1"
21746 +gdb_test "rwatch watchee"
21747 +
21748 +set breakline [gdb_get_line_number "break-at-exit"]
21749 +gdb_breakpoint $breakline
21750 +
21751 +gdb_test "continue" "Continuing.\r\nHardware read watchpoint 3: watchee\r\n\r\nValue = 0\r\n.*"
21752 +
21753 +# Here should be no repeated notification of the read watchpoint.
21754 +gdb_test "continue" \
21755 +        "Continuing\\.\[ \r\n\]+Breakpoint \[0-9\]+, .*break-at-exit.*" \
21756 +        "continue to break-at-exit after rwatch"
21757 +
21758 +clean_restart ${test}
21759 +
21760 +if ![runto_main] {
21761 +    untested ${test}.exp
21762 +    return -1
21763 +}
21764 +
21765 +gdb_test "hbreak ${srcfile}:${breakline}" \
21766 +        "Hardware assisted breakpoint 2 at 0x\[0-9a-f\]+: file .*${srcfile}, line ${breakline}\\." \
21767 +        "hbreak"
21768 +
21769 +gdb_test "continue" \
21770 +        "Continuing\\.\[ \r\n\]+Breakpoint \[0-9\]+, .*break-at-exit.*" \
21771 +        "continue to break-at-exit after hbreak"
21772 diff --git a/gdb/testsuite/gdb.cp/Makefile.in b/gdb/testsuite/gdb.cp/Makefile.in
21773 index 0a087c7..b4880f2 100644
21774 --- a/gdb/testsuite/gdb.cp/Makefile.in
21775 +++ b/gdb/testsuite/gdb.cp/Makefile.in
21776 @@ -4,7 +4,7 @@ srcdir = @srcdir@
21777  EXECUTABLES = ambiguous annota2 anon-union cplusfuncs cttiadd \
21778         derivation inherit local member-ptr method misc \
21779          overload ovldbreak ref-typ ref-typ2 templates userdef virtfunc namespace \
21780 -       ref-types ref-params method2 pr9594 gdb2495
21781 +       ref-types ref-params method2 pr9594 gdb2495 gdb9593
21782  
21783  all info install-info dvi install uninstall installcheck check:
21784         @echo "Nothing to be done for $@..."
21785 diff --git a/gdb/testsuite/gdb.cp/cp-relocate.exp b/gdb/testsuite/gdb.cp/cp-relocate.exp
21786 index 4095ccf..03c07d5 100644
21787 --- a/gdb/testsuite/gdb.cp/cp-relocate.exp
21788 +++ b/gdb/testsuite/gdb.cp/cp-relocate.exp
21789 @@ -30,7 +30,7 @@ proc get_func_address { func } {
21790      global gdb_prompt hex
21791  
21792      set rfunc [string_to_regexp $func]
21793 -    gdb_test_multiple "print '${func}'" "get address of ${func}" {
21794 +    gdb_test_multiple "print ${func}" "get address of ${func}" {
21795         -re "\\\$\[0-9\]+ = \\{.*\\} (0|($hex) <${rfunc}>)\[\r\n\]+${gdb_prompt} $" {
21796             # $1 = {int ()} 0x24 <function_bar>
21797             # But if the function is at zero, the name may be omitted.
21798 @@ -130,7 +130,7 @@ gdb_test "add-symbol-file ${binfile} 0 -s ${func1_sec} 0x10000 -s ${func2_sec} 0
21799         "y"
21800  
21801  # Make sure the function addresses were updated.
21802 -gdb_test "break *'$func1_name'" \
21803 +gdb_test "break *$func1_name" \
21804      "Breakpoint $decimal at 0x1....: file .*"
21805 -gdb_test "break *'$func2_name'" \
21806 +gdb_test "break *$func2_name" \
21807      "Breakpoint $decimal at 0x2....: file .*"
21808 diff --git a/gdb/testsuite/gdb.cp/cplusfuncs.cc b/gdb/testsuite/gdb.cp/cplusfuncs.cc
21809 index 7f033d6..11dba06 100644
21810 --- a/gdb/testsuite/gdb.cp/cplusfuncs.cc
21811 +++ b/gdb/testsuite/gdb.cp/cplusfuncs.cc
21812 @@ -46,7 +46,9 @@ public:
21813    void  operator []     (foo&);
21814    void  operator ()     (foo&);
21815    void* operator new    (size_t) throw ();
21816 +  void* operator new[]  (size_t) throw ();
21817    void  operator delete (void *);
21818 +  void  operator delete[] (void *);
21819    /**/  operator int    ();
21820    /**/  operator char*  ();
21821  
21822 @@ -115,7 +117,9 @@ void  foo::operator ->*    (foo& afoo) { afoo.ifoo = 0; }
21823  void  foo::operator []     (foo& afoo) { afoo.ifoo = 0; }
21824  void  foo::operator ()     (foo& afoo) { afoo.ifoo = 0; }
21825  void* foo::operator new    (size_t ival) throw () { ival = 0; return 0; }
21826 +void* foo::operator new[]    (size_t ival) throw () { ival = 0; return 0; }
21827  void  foo::operator delete (void *ptr) { ptr = 0; }
21828 +void  foo::operator delete[] (void *ptr) { ptr = 0; }
21829  /**/  foo::operator int    () { return 0; }
21830  /**/  foo::operator char*  () { return 0; }
21831  
21832 @@ -191,6 +195,12 @@ char *     dm_type_char_star (char * p)            { return p; }
21833  int    dm_type_foo_ref (foo & foo)             { return foo.ifoo; }
21834  int *  dm_type_int_star (int * p)              { return p; }
21835  long * dm_type_long_star (long * p)            { return p; }
21836 +int    dm_type_short (short i)                 { return i; }
21837 +int    dm_type_long (long i)                   { return i; }
21838  int    dm_type_unsigned_int (unsigned int i)   { return i; }
21839 +int    dm_type_unsigned_short (unsigned short i)       { return i; }
21840 +int    dm_type_unsigned_long (unsigned long i) { return i; }
21841  int    dm_type_void (void)                     { return 0; }
21842  void * dm_type_void_star (void * p)            { return p; }
21843 +typedef int myint;
21844 +int    dm_type_typedef (myint i)               { return i; }
21845 diff --git a/gdb/testsuite/gdb.cp/cplusfuncs.exp b/gdb/testsuite/gdb.cp/cplusfuncs.exp
21846 index 5e08768..2ec50ca 100644
21847 --- a/gdb/testsuite/gdb.cp/cplusfuncs.exp
21848 +++ b/gdb/testsuite/gdb.cp/cplusfuncs.exp
21849 @@ -63,12 +63,28 @@ set dm_type_foo_ref                 "foo&"
21850  set dm_type_int_star           "int*"
21851  set dm_type_long_star          "long*"
21852  set dm_type_unsigned_int       "unsigned"
21853 -set dm_type_void               ""
21854 +set dm_type_void               "void"
21855  set dm_type_void_star          "void*"
21856  
21857 +# Some other vagaries of GDB's type printing machinery.  The integer types
21858 +# may have unsigned before or after their length, and may have "int"
21859 +# appended.  The char* conversion operator may have name "char*" even if
21860 +# the type is "char *", because the name comes from the debug information
21861 +# and the type from GDB.  Function types may not see through typedefs.
21862 +
21863 +set dm_type_short              "short"
21864 +set dm_type_long               "long"
21865 +set dm_type_unsigned_short     "unsigned short"
21866 +set dm_type_unsigned_long      "unsigned long"
21867 +set dm_operator_char_star      "char*"
21868 +set dm_operator_char_star_quoted       "char\\*"
21869 +set dm_type_typedef            0
21870 +
21871  proc probe_demangler { } {
21872      global gdb_prompt
21873      global dm_operator_comma
21874 +    global dm_operator_char_star
21875 +    global dm_operator_char_star_quoted
21876      global dm_type_char_star
21877      global dm_type_char_star_quoted
21878      global dm_type_foo_ref
21879 @@ -77,8 +93,13 @@ proc probe_demangler { } {
21880      global dm_type_unsigned_int
21881      global dm_type_void
21882      global dm_type_void_star
21883 +    global dm_type_short
21884 +    global dm_type_unsigned_short
21885 +    global dm_type_long
21886 +    global dm_type_unsigned_long
21887 +    global dm_type_typedef
21888  
21889 -    send_gdb "print &'foo::operator,(foo&)'\n"
21890 +    send_gdb "print &foo::operator,(foo&)\n"
21891      gdb_expect {
21892         -re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
21893             # v2 demangler
21894 @@ -97,6 +118,26 @@ proc probe_demangler { } {
21895         }
21896      }
21897  
21898 +    send_gdb "print &foo::operator char*($dm_type_void)\n"
21899 +    gdb_expect {
21900 +       -re ".*foo::operator char \\*\\(void\\).*\r\n$gdb_prompt $" {
21901 +           # v2 demangler or GDB type printer
21902 +           set dm_operator_char_star "char *"
21903 +           set dm_operator_char_star_quoted "char \\*"
21904 +           pass "detect dm_operator_char_star"
21905 +       }
21906 +       -re ".*foo::operator char\\*\\(\\).*\r\n$gdb_prompt $" {
21907 +           # v3 demangler
21908 +           pass "detect dm_operator_char_star"
21909 +       }
21910 +       -re ".*$gdb_prompt $" {
21911 +           fail "detect dm_operator_char_star"
21912 +       }
21913 +       timeout {
21914 +           fail "detect dm_operator_char_star"
21915 +       }
21916 +    }
21917 +
21918      send_gdb "print &'dm_type_char_star'\n"
21919      gdb_expect {
21920         -re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
21921 @@ -166,6 +207,11 @@ proc probe_demangler { } {
21922             # v3 demangler
21923             pass "detect dm_type_long_star"
21924         }
21925 +       -re ".*dm_type_long_star\\(long int \\*\\).*\r\n$gdb_prompt $" {
21926 +           # GCC v3 and GDB's type printer
21927 +           set dm_type_long_star "long int *"
21928 +           pass "detect dm_type_long_star"
21929 +       }
21930         -re ".*$gdb_prompt $" {
21931             fail "detect dm_type_long_star"
21932         }
21933 @@ -230,6 +276,101 @@ proc probe_demangler { } {
21934             fail "detect dm_type_void_star (timeout)"
21935         }
21936      }
21937 +
21938 +    send_gdb "print &'dm_type_short'\n"
21939 +    gdb_expect {
21940 +       -re ".*dm_type_short\\(short\\).*\r\n$gdb_prompt $" {
21941 +           # v2 and v3 demanglers
21942 +           pass "detect dm_type_short"
21943 +       }
21944 +       -re ".*dm_type_short\\(short int\\).*\r\n$gdb_prompt $" {
21945 +           # GDB type printer
21946 +           set dm_type_short "short int"
21947 +           pass "detect dm_type_short"
21948 +       }
21949 +       -re ".*$gdb_prompt $" {
21950 +           fail "detect dm_type_short"
21951 +       }
21952 +       timeout {
21953 +           fail "detect dm_type_short (timeout)"
21954 +       }
21955 +    }
21956 +
21957 +    send_gdb "print &'dm_type_unsigned_short'\n"
21958 +    gdb_expect {
21959 +       -re ".*dm_type_unsigned_short\\(unsigned short\\).*\r\n$gdb_prompt $" {
21960 +           # v2 and v3 demanglers
21961 +           pass "detect dm_type_unsigned_short"
21962 +       }
21963 +       -re ".*dm_type_unsigned_short\\(short unsigned int\\).*\r\n$gdb_prompt $" {
21964 +           # GDB type printer
21965 +           set dm_type_unsigned_short "short unsigned int"
21966 +           pass "detect dm_type_unsigned_short"
21967 +       }
21968 +       -re ".*$gdb_prompt $" {
21969 +           fail "detect dm_type_unsigned_short"
21970 +       }
21971 +       timeout {
21972 +           fail "detect dm_type_unsigned_short (timeout)"
21973 +       }
21974 +    }
21975 +
21976 +    send_gdb "print &'dm_type_long'\n"
21977 +    gdb_expect {
21978 +       -re ".*dm_type_long\\(long\\).*\r\n$gdb_prompt $" {
21979 +           # v2 and v3 demanglers
21980 +           pass "detect dm_type_long"
21981 +       }
21982 +       -re ".*dm_type_long\\(long int\\).*\r\n$gdb_prompt $" {
21983 +           # GDB type printer
21984 +           set dm_type_long "long int"
21985 +           pass "detect dm_type_long"
21986 +       }
21987 +       -re ".*$gdb_prompt $" {
21988 +           fail "detect dm_type_long"
21989 +       }
21990 +       timeout {
21991 +           fail "detect dm_type_long (timeout)"
21992 +       }
21993 +    }
21994 +
21995 +    send_gdb "print &'dm_type_unsigned_long'\n"
21996 +    gdb_expect {
21997 +       -re ".*dm_type_unsigned_long\\(unsigned long\\).*\r\n$gdb_prompt $" {
21998 +           # v2 and v3 demanglers
21999 +           pass "detect dm_type_unsigned_long"
22000 +       }
22001 +       -re ".*dm_type_unsigned_long\\(long unsigned int\\).*\r\n$gdb_prompt $" {
22002 +           # GDB type printer
22003 +           set dm_type_unsigned_long "long unsigned int"
22004 +           pass "detect dm_type_unsigned_long"
22005 +       }
22006 +       -re ".*$gdb_prompt $" {
22007 +           fail "detect dm_type_unsigned_long"
22008 +       }
22009 +       timeout {
22010 +           fail "detect dm_type_unsigned_long (timeout)"
22011 +       }
22012 +    }
22013 +
22014 +    send_gdb "print &'dm_type_typedef'\n"
22015 +    gdb_expect {
22016 +       -re ".*dm_type_typedef\\(int\\).*\r\n$gdb_prompt $" {
22017 +           # v2 and v3 demanglers
22018 +           pass "detect dm_type_typedef"
22019 +       }
22020 +       -re ".*dm_type_typedef\\(myint\\).*\r\n$gdb_prompt $" {
22021 +           # GDB type printer
22022 +           set dm_type_typedef 1
22023 +           pass "detect dm_type_typedef"
22024 +       }
22025 +       -re ".*$gdb_prompt $" {
22026 +           fail "detect dm_type_typedef"
22027 +       }
22028 +       timeout {
22029 +           fail "detect dm_type_typedef (timeout)"
22030 +       }
22031 +    }
22032  }
22033  
22034  #
22035 @@ -241,6 +382,7 @@ proc info_func_regexp { name demangled } {
22036      global gdb_prompt
22037  
22038      send_gdb "info function $name\n"
22039 +    set demangled [regsub {\\\(void\\\)} $demangled {\(\)}]
22040      gdb_expect {
22041         -re ".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
22042             pass "info function for \"$name\""
22043 @@ -277,16 +419,16 @@ proc print_addr_2 { name good } {
22044  
22045      set good_pattern [string_to_regexp $good]
22046  
22047 -    send_gdb "print &'$name'\n"
22048 +    send_gdb "print &$name\n"
22049      gdb_expect {
22050         -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
22051 -           pass "print &'$name'"
22052 +           pass "print &$name"
22053         }
22054         -re ".*$gdb_prompt $" {
22055 -           fail "print &'$name'"
22056 +           fail "print &$name"
22057         }
22058         timeout {
22059 -           fail "print &'$name' (timeout)"
22060 +           fail "print &$name (timeout)"
22061         }
22062      }
22063  }
22064 @@ -327,7 +469,12 @@ proc print_addr_2_kfail { name good bad bugid } {
22065  #
22066  
22067  proc print_addr { name } {
22068 -    print_addr_2 "$name" "$name"
22069 +    set expected [regsub {\(void\)} $name {()}]
22070 +    if {[string first "::" $name] == -1} {
22071 +       # C function -- must be qutoed
22072 +       set name "'$name'"
22073 +    }
22074 +    print_addr_2 "$name" $expected
22075  }
22076  
22077  #
22078 @@ -345,8 +492,9 @@ proc print_addr { name } {
22079  
22080  proc test_lookup_operator_functions {} {
22081      global dm_operator_comma
22082 +    global dm_operator_char_star
22083      global dm_type_char_star
22084 -    global dm_type_char_star_quoted
22085 +    global dm_operator_char_star_quoted
22086      global dm_type_foo_ref
22087      global dm_type_void
22088      global dm_type_void_star
22089 @@ -404,8 +552,8 @@ proc test_lookup_operator_functions {} {
22090  
22091      info_func "operator int("  "int foo::operator int($dm_type_void);"
22092      info_func "operator()("    "void foo::operator()($dm_type_foo_ref);"
22093 -    info_func "operator $dm_type_char_star_quoted\(" \
22094 -                               "char *foo::operator $dm_type_char_star\($dm_type_void);"
22095 +    info_func "operator $dm_operator_char_star_quoted\(" \
22096 +                               "char *foo::operator $dm_operator_char_star\($dm_type_void);"
22097  
22098  }
22099  
22100 @@ -420,6 +568,7 @@ proc test_paddr_operator_functions {} {
22101      global dm_type_unsigned_int
22102      global dm_type_void
22103      global dm_type_void_star
22104 +    global dm_operator_char_star
22105  
22106      print_addr "foo::operator*($dm_type_foo_ref)"
22107      print_addr "foo::operator%($dm_type_foo_ref)"
22108 @@ -460,17 +609,20 @@ proc test_paddr_operator_functions {} {
22109      print_addr "foo::operator\[\]($dm_type_foo_ref)"
22110      print_addr "foo::operator()($dm_type_foo_ref)"
22111  
22112 -    gdb_test "print &'foo::operator new'" \
22113 +    gdb_test "print &foo::operator new" \
22114         " = .* $hex <foo::operator new\\(.*\\)(| static)>"
22115 +    gdb_test "print &foo::operator new\[\]" \
22116 +       " = .* $hex <foo::operator new\\\[\\\]\\(.*\\)(| static)>"    
22117      if { !$hp_aCC_compiler } {
22118         print_addr "foo::operator delete($dm_type_void_star)"
22119 +       print_addr "foo::operator delete[]($dm_type_void_star)"
22120      } else {
22121         gdb_test "print &'foo::operator delete($dm_type_void_star) static'" \
22122             " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
22123      }
22124  
22125      print_addr "foo::operator int($dm_type_void)"
22126 -    print_addr "foo::operator $dm_type_char_star\($dm_type_void)"
22127 +    print_addr "foo::operator $dm_operator_char_star\($dm_type_void)"
22128  }
22129  
22130  #
22131 @@ -480,17 +632,21 @@ proc test_paddr_operator_functions {} {
22132  proc test_paddr_overloaded_functions {} {
22133      global dm_type_unsigned_int
22134      global dm_type_void
22135 +    global dm_type_short
22136 +    global dm_type_unsigned_short
22137 +    global dm_type_long
22138 +    global dm_type_unsigned_long
22139  
22140      print_addr "overload1arg($dm_type_void)"
22141      print_addr "overload1arg(char)"
22142      print_addr "overload1arg(signed char)"
22143      print_addr "overload1arg(unsigned char)"
22144 -    print_addr "overload1arg(short)"
22145 -    print_addr "overload1arg(unsigned short)"
22146 +    print_addr "overload1arg($dm_type_short)"
22147 +    print_addr "overload1arg($dm_type_unsigned_short)"
22148      print_addr "overload1arg(int)"
22149      print_addr "overload1arg($dm_type_unsigned_int)"
22150 -    print_addr "overload1arg(long)"
22151 -    print_addr "overload1arg(unsigned long)"
22152 +    print_addr "overload1arg($dm_type_long)"
22153 +    print_addr "overload1arg($dm_type_unsigned_long)"
22154      print_addr "overload1arg(float)"
22155      print_addr "overload1arg(double)"
22156  
22157 @@ -513,17 +669,31 @@ proc test_paddr_hairy_functions {} {
22158      global dm_type_char_star
22159      global dm_type_int_star
22160      global dm_type_long_star
22161 +    global dm_type_typedef
22162  
22163      print_addr_2 "hairyfunc1" "hairyfunc1(int)"
22164 -    print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
22165 -    print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
22166 -    print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
22167 -
22168 -    # gdb-gnats bug gdb/19:
22169 -    # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
22170 -    print_addr_2_kfail "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))" "hairyfunc5(int (*)(long) (*)(char*))" "gdb/19"
22171 -    print_addr_2_kfail "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))" "hairyfunc6(int (*)(long) (*)(int*))" "gdb/19"
22172 -    print_addr_2_kfail "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))" "hairyfunc7(int (*)(long) (*)(int (*)(char*)))" "gdb/19"
22173 +
22174 +    if {$dm_type_typedef == 0} {
22175 +       print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
22176 +       print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
22177 +       print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
22178 +
22179 +       # gdb-gnats bug gdb/19:
22180 +       # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
22181 +       print_addr_2_kfail "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))" "hairyfunc5(int (*)(long) (*)(char*))" "gdb/19"
22182 +       print_addr_2_kfail "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))" "hairyfunc6(int (*)(long) (*)(int*))" "gdb/19"
22183 +       print_addr_2_kfail "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))" "hairyfunc7(int (*)(long) (*)(int (*)(char*)))" "gdb/19"
22184 +    } else {
22185 +       print_addr_2 "hairyfunc2" "hairyfunc2(PFPc_i)"
22186 +       print_addr_2 "hairyfunc3" "hairyfunc3(PFPFPl_s_i)"
22187 +       print_addr_2 "hairyfunc4" "hairyfunc4(PFPFPc_s_i)"
22188 +
22189 +       # gdb-gnats bug gdb/19:
22190 +       # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
22191 +       print_addr_2 "hairyfunc5" "hairyfunc5(PFPc_PFl_i)"
22192 +       print_addr_2 "hairyfunc6" "hairyfunc6(PFPi_PFl_i)"
22193 +       print_addr_2 "hairyfunc7" "hairyfunc7(PFPFPc_i_PFl_i)"
22194 +    }
22195  }
22196  
22197  proc do_tests {} {
22198 @@ -534,6 +704,7 @@ proc do_tests {} {
22199      global srcdir
22200      global binfile
22201      global gdb_prompt
22202 +    global dm_type_int_star
22203  
22204      set prms_id 0
22205      set bug_id 0
22206 @@ -557,6 +728,10 @@ proc do_tests {} {
22207      test_paddr_operator_functions
22208      test_paddr_hairy_functions
22209      test_lookup_operator_functions
22210 +
22211 +    # A regression test on errors involving operators
22212 +    gdb_test "list foo::operator $dm_type_int_star" \
22213 +       ".*the class foo does not have any method named operator $dm_type_int_star.*"
22214  }
22215  
22216  do_tests
22217 diff --git a/gdb/testsuite/gdb.cp/expand-sals.exp b/gdb/testsuite/gdb.cp/expand-sals.exp
22218 index 3c302c3..cd0496d 100644
22219 --- a/gdb/testsuite/gdb.cp/expand-sals.exp
22220 +++ b/gdb/testsuite/gdb.cp/expand-sals.exp
22221 @@ -48,7 +48,7 @@ gdb_continue_to_breakpoint "caller" ".*caller-line.*"
22222  
22223  # Test GDB caught this return call and not the next one through B::B()
22224  gdb_test "bt" \
22225 -        "#0 \[^\r\n\]* A \[^\r\n\]*\r\n#1 \[^\r\n\]* main \[^\r\n\]*" \
22226 +        "#0 \[^\r\n\]* (A::)?A \[^\r\n\]*\r\n#1 \[^\r\n\]* main \[^\r\n\]*" \
22227          "bt from A"
22228  
22229  gdb_continue_to_breakpoint "next caller func" ".*func-line.*"
22230 diff --git a/gdb/testsuite/gdb.cp/gdb9593.cc b/gdb/testsuite/gdb.cp/gdb9593.cc
22231 new file mode 100644
22232 index 0000000..783c962
22233 --- /dev/null
22234 +++ b/gdb/testsuite/gdb.cp/gdb9593.cc
22235 @@ -0,0 +1,180 @@
22236 +/* This testcase is part of GDB, the GNU debugger.
22237 +
22238 +   Copyright 2008, 2009 Free Software Foundation, Inc.
22239 +
22240 +   This program is free software; you can redistribute it and/or modify
22241 +   it under the terms of the GNU General Public License as published by
22242 +   the Free Software Foundation; either version 3 of the License, or
22243 +   (at your option) any later version.
22244 +
22245 +   This program is distributed in the hope that it will be useful,
22246 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
22247 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22248 +   GNU General Public License for more details.
22249 +
22250 +   You should have received a copy of the GNU General Public License
22251 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.
22252 +   */
22253 +#include <iostream>
22254 +
22255 +using namespace std;
22256 +
22257 +class NextOverThrowDerivates
22258 +{
22259 +
22260 +public:
22261 +
22262 +
22263 +  // Single throw an exception in this function.
22264 +  void function1() 
22265 +  {
22266 +    throw 20;
22267 +  }
22268 +
22269 +  // Throw an exception in another function.
22270 +  void function2() 
22271 +  {
22272 +    function1();
22273 +  }
22274 +
22275 +  // Throw an exception in another function, but handle it
22276 +  // locally.
22277 +  void function3 () 
22278 +  {
22279 +    {
22280 +      try
22281 +       {
22282 +         function1 ();
22283 +       }
22284 +      catch (...) 
22285 +       {
22286 +         cout << "Caught and handled function1 exception" << endl;
22287 +       }
22288 +    }
22289 +  }
22290 +
22291 +  void rethrow ()
22292 +  {
22293 +    try
22294 +      {
22295 +       function1 ();
22296 +      }
22297 +    catch (...)
22298 +      {
22299 +       throw;
22300 +      }
22301 +  }
22302 +
22303 +  void finish ()
22304 +  {
22305 +    // We use this to test that a "finish" here does not end up in
22306 +    // this frame, but in the one above.
22307 +    try
22308 +      {
22309 +       function1 ();
22310 +      }
22311 +    catch (int x)
22312 +      {
22313 +      }
22314 +    function1 ();              // marker for until
22315 +  }
22316 +
22317 +  void until ()
22318 +  {
22319 +    function1 ();
22320 +    function1 ();              // until here
22321 +  }
22322 +
22323 +};
22324 +NextOverThrowDerivates next_cases;
22325 +
22326 +
22327 +int main () 
22328 +{ 
22329 +  try
22330 +    {
22331 +      next_cases.function1 ();
22332 +    }
22333 +  catch (...)
22334 +    {
22335 +      // Discard
22336 +    }
22337 +
22338 +  try
22339 +    {
22340 +      next_cases.function2 ();
22341 +    }
22342 +  catch (...)
22343 +    {
22344 +      // Discard
22345 +    }
22346 +
22347 +  try
22348 +    {
22349 +      // This is duplicated so we can next over one but step into
22350 +      // another.
22351 +      next_cases.function2 ();
22352 +    }
22353 +  catch (...)
22354 +    {
22355 +      // Discard
22356 +    }
22357 +
22358 +  next_cases.function3 ();
22359 +
22360 +  try
22361 +    {
22362 +      next_cases.rethrow ();
22363 +    }
22364 +  catch (...)
22365 +    {
22366 +      // Discard
22367 +    }
22368 +
22369 +  try
22370 +    {
22371 +      // Another duplicate so we can test "finish".
22372 +      next_cases.function2 ();
22373 +    }
22374 +  catch (...)
22375 +    {
22376 +      // Discard
22377 +    }
22378 +
22379 +  // Another test for "finish".
22380 +  try
22381 +    {
22382 +      next_cases.finish ();
22383 +    }
22384 +  catch (...)
22385 +    {
22386 +    }
22387 +
22388 +  // Test of "until".
22389 +  try
22390 +    {
22391 +      next_cases.finish ();
22392 +    }
22393 +  catch (...)
22394 +    {
22395 +    }
22396 +
22397 +  // Test of "until" with an argument.
22398 +  try
22399 +    {
22400 +      next_cases.until ();
22401 +    }
22402 +  catch (...)
22403 +    {
22404 +    }
22405 +
22406 +  // Test of "advance".
22407 +  try
22408 +    {
22409 +      next_cases.until ();
22410 +    }
22411 +  catch (...)
22412 +    {
22413 +    }
22414 +}
22415 +
22416 diff --git a/gdb/testsuite/gdb.cp/gdb9593.exp b/gdb/testsuite/gdb.cp/gdb9593.exp
22417 new file mode 100644
22418 index 0000000..ee9aeff
22419 --- /dev/null
22420 +++ b/gdb/testsuite/gdb.cp/gdb9593.exp
22421 @@ -0,0 +1,185 @@
22422 +# Copyright 2008, 2009 Free Software Foundation, Inc.
22423 +
22424 +# This program is free software; you can redistribute it and/or modify
22425 +# it under the terms of the GNU General Public License as published by
22426 +# the Free Software Foundation; either version 3 of the License, or
22427 +# (at your option) any later version.
22428 +#
22429 +# This program is distributed in the hope that it will be useful,
22430 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22431 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22432 +# GNU General Public License for more details.
22433 +#
22434 +# You should have received a copy of the GNU General Public License
22435 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22436 +
22437 +
22438 +if $tracelevel then {
22439 +    strace $tracelevel
22440 +}
22441 +
22442 +if { [skip_cplus_tests] } { continue }
22443 +
22444 +set prms_id 9593
22445 +set bug_id 0
22446 +
22447 +set testfile "gdb9593"
22448 +set srcfile ${testfile}.cc
22449 +set binfile $objdir/$subdir/$testfile
22450 +
22451 +# Create and source the file that provides information about the compiler
22452 +# used to compile the test case.
22453 +if [get_compiler_info ${binfile} "c++"] {
22454 +    untested gdb9593.exp
22455 +    return -1
22456 +}
22457 +
22458 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
22459 +    untested gdb9593.exp
22460 +    return -1
22461 +}
22462 +
22463 +# Some targets can't do function calls, so don't even bother with this
22464 +# test.
22465 +if [target_info exists gdb,cannot_call_functions] {
22466 +    setup_xfail "*-*-*" 9593
22467 +    fail "This target can not call functions"
22468 +    continue
22469 +}
22470 +
22471 +gdb_exit
22472 +gdb_start
22473 +gdb_reinitialize_dir $srcdir/$subdir
22474 +gdb_load ${binfile}
22475 +
22476 +if ![runto_main] then {
22477 +    perror "couldn't run to main"
22478 +    continue
22479 +} 
22480 +
22481 +# See whether we have the needed unwinder hooks.
22482 +set ok 1
22483 +gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
22484 +    -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
22485 +       pass "check for unwinder hook"
22486 +    }
22487 +    -re "No symbol .* in current context.\r\n$gdb_prompt $" {
22488 +       # Pass the test so we don't get bogus fails in the results.
22489 +       pass "check for unwinder hook"
22490 +       set ok 0
22491 +    }
22492 +}
22493 +if {!$ok} {
22494 +    untested gdb9593.exp
22495 +    return -1
22496 +}
22497 +
22498 +# See http://sourceware.org/bugzilla/show_bug.cgi?id=9593
22499 +
22500 +gdb_test "next" \
22501 +    ".*catch (...).*" \
22502 +    "next over a throw 1"
22503 +
22504 +gdb_test "next" \
22505 +  ".*next_cases.function2.*" \
22506 +  "next past catch 1"
22507 +
22508 +gdb_test "next" \
22509 +    ".*catch (...).*" \
22510 +    "next over a throw 2"
22511 +
22512 +gdb_test "next" \
22513 +  ".*next_cases.function2.*" \
22514 +  "next past catch 2"
22515 +
22516 +gdb_test "step" \
22517 +  ".*function1().*" \
22518 +  "step into function2 1"
22519 +
22520 +gdb_test "next" \
22521 +    ".*catch (...).*" \
22522 +    "next over a throw 3"
22523 +
22524 +gdb_test "next" \
22525 +  ".*next_cases.function3.*" \
22526 +  "next past catch 3"
22527 +
22528 +gdb_test "next" \
22529 +  ".*next_cases.rethrow.*" \
22530 +    "next over a throw 4"
22531 +
22532 +gdb_test "next" \
22533 +  ".*catch (...).*" \
22534 +  "next over a rethrow"
22535 +
22536 +gdb_test "next" \
22537 +  ".*next_cases.function2.*" \
22538 +  "next after a rethrow"
22539 +
22540 +gdb_test "step" \
22541 +  ".*function1().*" \
22542 +  "step into function2 2"
22543 +
22544 +gdb_test "finish" \
22545 +  ".*catch (...).*" \
22546 +  "finish 1"
22547 +
22548 +gdb_test "next" \
22549 +  ".*next_cases.finish ().*" \
22550 +  "next past catch 4"
22551 +
22552 +gdb_test "step" \
22553 +  ".*function1 ().*" \
22554 +  "step into finish method"
22555 +
22556 +gdb_test "finish" \
22557 +  ".*catch (...).*" \
22558 +  "finish 2"
22559 +
22560 +gdb_test "next" \
22561 +  ".*next_cases.finish ().*" \
22562 +  "next past catch 5"
22563 +
22564 +gdb_test "step" \
22565 +  ".*function1 ().*" \
22566 +  "step into finish, for until"
22567 +
22568 +gdb_test "until" \
22569 +  ".*catch .int x.*" \
22570 +  "until with no argument 1"
22571 +
22572 +set line [gdb_get_line_number "marker for until" $testfile.cc]
22573 +
22574 +gdb_test "until $line" \
22575 +  ".*function1 ().*" \
22576 +  "next past catch 6"
22577 +
22578 +gdb_test "until" \
22579 +  ".*catch (...).*" \
22580 +  "until with no argument 2"
22581 +
22582 +set line [gdb_get_line_number "until here" $testfile.cc]
22583 +
22584 +gdb_test "next" \
22585 +  ".*next_cases.until ().*" \
22586 +  "next past catch 6"
22587 +
22588 +gdb_test "step" \
22589 +  ".*function1 ().*" \
22590 +  "step into until"
22591 +
22592 +gdb_test "until $line" \
22593 +  ".*catch (...).*" \
22594 +  "until-over-throw"
22595 +
22596 +gdb_test "next" \
22597 +  ".*next_cases.until ().*" \
22598 +  "next past catch 7"
22599 +
22600 +gdb_test "step" \
22601 +  ".*function1 ().*" \
22602 +  "step into until, for advance"
22603 +
22604 +gdb_test "advance $line" \
22605 +  ".*catch (...).*" \
22606 +  "advance-over-throw"
22607 diff --git a/gdb/testsuite/gdb.cp/member-ptr.cc b/gdb/testsuite/gdb.cp/member-ptr.cc
22608 index 1dff70a..648b2af 100644
22609 --- a/gdb/testsuite/gdb.cp/member-ptr.cc
22610 +++ b/gdb/testsuite/gdb.cp/member-ptr.cc
22611 @@ -138,6 +138,7 @@ class Diamond : public Padding, public Left, public Right
22612  {
22613  public:
22614    virtual int vget_base ();
22615 +  int (*func_ptr) (int);
22616  };
22617  
22618  int Diamond::vget_base ()
22619 @@ -145,6 +146,12 @@ int Diamond::vget_base ()
22620    return this->Left::x + 2000;
22621  }
22622  
22623 +int
22624 +func (int x)
22625 +{
22626 +  return 19 + x;
22627 +}
22628 +
22629  int main ()
22630  {
22631    A a;
22632 @@ -162,6 +169,7 @@ int main ()
22633    int (Diamond::*right_vpmf) ();
22634    int (Base::*base_vpmf) ();
22635    int Diamond::*diamond_pmi;
22636 +  int (* Diamond::*diamond_pfunc_ptr) (int);
22637  
22638    PMI null_pmi;
22639    PMF null_pmf;
22640 @@ -179,6 +187,7 @@ int main ()
22641  
22642    diamond.Left::x = 77;
22643    diamond.Right::x = 88;
22644 +  diamond.func_ptr = func;
22645  
22646    /* Some valid pointer to members from a base class.  */
22647    left_pmf = (int (Diamond::*) ()) (int (Left::*) ()) (&Base::get_x);
22648 @@ -193,11 +202,19 @@ int main ()
22649    /* A pointer to data member from a base class.  */
22650    diamond_pmi = (int Diamond::*) (int Left::*) &Base::x;
22651  
22652 +  /* A pointer to data member, where the member is itself a pointer to
22653 +     a function.  */
22654 +  diamond_pfunc_ptr = (int (* Diamond::*) (int)) &Diamond::func_ptr;
22655 +
22656    null_pmi = NULL;
22657    null_pmf = NULL;
22658  
22659    pmi = NULL; /* Breakpoint 1 here.  */
22660  
22661 +  // Invalid (uses diamond_pfunc_ptr as a function):
22662 +  // diamond.*diamond_pfunc_ptr (20);
22663 +  (diamond.*diamond_pfunc_ptr) (20);
22664 +
22665    k = (a.*pmf)(3);
22666  
22667    pmi = &A::jj;
22668 diff --git a/gdb/testsuite/gdb.cp/member-ptr.exp b/gdb/testsuite/gdb.cp/member-ptr.exp
22669 index b69d4ad..83dd0d5 100644
22670 --- a/gdb/testsuite/gdb.cp/member-ptr.exp
22671 +++ b/gdb/testsuite/gdb.cp/member-ptr.exp
22672 @@ -390,6 +390,33 @@ gdb_test_multiple "print ((int) pmi) == ((char *) &a.j - (char *) & a)" $name {
22673      }
22674  }
22675  
22676 +# Check pointers to data members, which are themselves pointers to
22677 +# functions.  These behave like data members, not like pointers to
22678 +# member functions.
22679 +
22680 +gdb_test "ptype diamond_pfunc_ptr" \
22681 +    "type = int \\(\\*Diamond::\\*\\)\\(int\\)"
22682 +
22683 +gdb_test "ptype diamond.*diamond_pfunc_ptr" \
22684 +    "type = int \\(\\*\\)\\(int\\)"
22685 +
22686 +# This one is invalid; () binds more tightly than .*, so it tries to
22687 +# call the member pointer as a normal pointer-to-function.
22688 +
22689 +gdb_test "print diamond.*diamond_pfunc_ptr (20)" \
22690 +    "Invalid data type for function to be called."
22691 +
22692 +# With parentheses, it is valid.
22693 +
22694 +gdb_test "print (diamond.*diamond_pfunc_ptr) (20)" \
22695 +    "$vhn = 39"
22696 +
22697 +# Make sure that we do not interpret this as either a member pointer
22698 +# call or a member function call.
22699 +
22700 +gdb_test "print diamond.func_ptr (20)" \
22701 +    "$vhn = 39"
22702 +
22703  # ==========================
22704  # pointer to member function
22705  # ==========================
22706 @@ -420,7 +447,7 @@ gdb_test_multiple "ptype pmf" $name {
22707  
22708  set name "print pmf"
22709  gdb_test_multiple "print pmf" $name {
22710 -    -re "$vhn = $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" {
22711 +    -re "$vhn = \\(int \\(A::\\*\\)\\(A \\*, int\\)\\) $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" {
22712         pass $name
22713      }
22714      -re "$vhn = .*not supported with HP aCC.*\r\n$gdb_prompt $" {
22715 @@ -608,6 +635,9 @@ gdb_test_multiple "print (a.*pmf)(3)" $name {
22716      }
22717  }
22718  
22719 +gdb_test "ptype a.*pmf" "type = int \\(A \\*, int\\)"
22720 +gdb_test "ptype (a.*pmf)(3)" "type = int"
22721 +
22722  # Print out a pointer to data member which requires looking into
22723  # a base class.
22724  gdb_test "print diamond_pmi" "$vhn = &Base::x"
22725 @@ -658,5 +688,5 @@ gdb_test "print null_pmi = &A::j" "$vhn = &A::j"
22726  gdb_test "print null_pmi = 0" "$vhn = NULL"
22727  
22728  gdb_test "print null_pmf" "$vhn = NULL"
22729 -gdb_test "print null_pmf = &A::foo" "$vhn = $hex <A::foo ?\\(int\\)>"
22730 +gdb_test "print null_pmf = &A::foo" "$vhn = \\(int \\(A::\\*\\)\\(A \\*, int\\)\\) $hex <A::foo ?\\(int\\)>"
22731  gdb_test "print null_pmf = 0" "$vhn = NULL"
22732 diff --git a/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc b/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc
22733 new file mode 100644
22734 index 0000000..6b180d6
22735 --- /dev/null
22736 +++ b/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc
22737 @@ -0,0 +1,20 @@
22738 +namespace A {
22739 +  int x = 11;
22740 +  namespace{
22741 +    int xx = 22;
22742 +  }
22743 +}
22744 +
22745 +using namespace A;
22746 +
22747 +namespace{
22748 +  int xxx = 33;
22749 +};
22750 +
22751 +int main()
22752 +{
22753 +  x;
22754 +  xx;
22755 +  xxx;
22756 +  return 0;
22757 +}
22758 diff --git a/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp b/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp
22759 new file mode 100644
22760 index 0000000..e4bb9f8
22761 --- /dev/null
22762 +++ b/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp
22763 @@ -0,0 +1,49 @@
22764 +# Copyright 2008 Free Software Foundation, Inc.
22765 +
22766 +# This program is free software; you can redistribute it and/or modify
22767 +# it under the terms of the GNU General Public License as published by
22768 +# the Free Software Foundation; either version 3 of the License, or
22769 +# (at your option) any later version.
22770 +#
22771 +# This program is distributed in the hope that it will be useful,
22772 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22773 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22774 +# GNU General Public License for more details.
22775 +#
22776 +# You should have received a copy of the GNU General Public License
22777 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22778 +
22779 +if $tracelevel then {
22780 +    strace $tracelevel
22781 +}
22782 +
22783 +set prms_id 0
22784 +set bug_id 0
22785 +
22786 +set testfile namespace-multiple-imports
22787 +set srcfile ${testfile}.cc
22788 +set binfile ${objdir}/${subdir}/${testfile}
22789 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
22790 +    untested "Couldn't compile test program"
22791 +    return -1
22792 +}
22793 +
22794 +# Get things started.
22795 +
22796 +gdb_exit
22797 +gdb_start
22798 +gdb_reinitialize_dir $srcdir/$subdir
22799 +gdb_load ${binfile}
22800 +
22801 +############################################
22802 +# test printing of namespace imported within
22803 +# the function.
22804 +
22805 +if ![runto_main] then {
22806 +    perror "couldn't run to breakpoint main"
22807 +    continue
22808 +}
22809 +
22810 +gdb_test "print x" "\\$\[0-9\].* = 11"
22811 +gdb_test "print xx" "\\$\[0-9\].* = 22"
22812 +gdb_test "print xxx" "\\$\[0-9\].* = 33"
22813 diff --git a/gdb/testsuite/gdb.cp/namespace-nested-imports.cc b/gdb/testsuite/gdb.cp/namespace-nested-imports.cc
22814 new file mode 100644
22815 index 0000000..9723f87
22816 --- /dev/null
22817 +++ b/gdb/testsuite/gdb.cp/namespace-nested-imports.cc
22818 @@ -0,0 +1,36 @@
22819 +namespace A
22820 +{
22821 +  namespace B
22822 +  {
22823 +    int ab = 11;
22824 +  }
22825 +}
22826 +
22827 +namespace C
22828 +{
22829 +  namespace D
22830 +  {
22831 +    using namespace A::B;
22832 +
22833 +    int
22834 +    second()
22835 +    {
22836 +      ab;
22837 +      return 0;
22838 +    }
22839 +  }
22840 +
22841 +  int
22842 +  first()
22843 +  {
22844 +    //ab;
22845 +    return D::second();
22846 +  }
22847 +}
22848 +
22849 +int
22850 +main()
22851 +{
22852 +  //ab;
22853 +  return C::first();
22854 +}
22855 diff --git a/gdb/testsuite/gdb.cp/namespace-nested-imports.exp b/gdb/testsuite/gdb.cp/namespace-nested-imports.exp
22856 new file mode 100644
22857 index 0000000..d279fb5
22858 --- /dev/null
22859 +++ b/gdb/testsuite/gdb.cp/namespace-nested-imports.exp
22860 @@ -0,0 +1,57 @@
22861 +# Copyright 2008 Free Software Foundation, Inc.
22862 +
22863 +# This program is free software; you can redistribute it and/or modify
22864 +# it under the terms of the GNU General Public License as published by
22865 +# the Free Software Foundation; either version 3 of the License, or
22866 +# (at your option) any later version.
22867 +#
22868 +# This program is distributed in the hope that it will be useful,
22869 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22870 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22871 +# GNU General Public License for more details.
22872 +#
22873 +# You should have received a copy of the GNU General Public License
22874 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22875 +
22876 +if $tracelevel then {
22877 +    strace $tracelevel
22878 +}
22879 +
22880 +set prms_id 0
22881 +set bug_id 0
22882 +
22883 +set testfile namespace-nested-imports
22884 +set srcfile ${testfile}.cc
22885 +set binfile ${objdir}/${subdir}/${testfile}
22886 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
22887 +    untested "Couldn't compile test program"
22888 +    return -1
22889 +}
22890 +
22891 +# Get things started.
22892 +
22893 +gdb_exit
22894 +gdb_start
22895 +gdb_reinitialize_dir $srcdir/$subdir
22896 +gdb_load ${binfile}
22897 +
22898 +############################################
22899 +if ![runto_main] then {
22900 +    perror "couldn't run to breakpoint main"
22901 +    continue
22902 +}
22903 +
22904 +gdb_test "print ab" "No symbol .* in current context."
22905 +
22906 +############################################
22907 +gdb_breakpoint C::first
22908 +gdb_continue_to_breakpoint "C::first"
22909 +
22910 +gdb_test "print ab" "No symbol .* in current context."
22911 +gdb_test "print C::D::ab" "= 11"
22912 +
22913 +############################################
22914 +gdb_breakpoint C::D::second
22915 +gdb_continue_to_breakpoint "C::D::second"
22916 +
22917 +gdb_test "print ab" "= 11"
22918 diff --git a/gdb/testsuite/gdb.cp/namespace-no-imports.cc b/gdb/testsuite/gdb.cp/namespace-no-imports.cc
22919 new file mode 100644
22920 index 0000000..d1c68ab
22921 --- /dev/null
22922 +++ b/gdb/testsuite/gdb.cp/namespace-no-imports.cc
22923 @@ -0,0 +1,37 @@
22924 +
22925 +namespace A
22926 +{
22927 +  int _a = 11;
22928 +
22929 +  namespace B{
22930 +
22931 +    int ab = 22;
22932 +
22933 +    namespace C{
22934 +
22935 +      int abc = 33;
22936 +
22937 +      int second(){
22938 +        return 0;
22939 +      }
22940 +
22941 +    }
22942 +
22943 +    int first(){
22944 +      _a;
22945 +      ab;
22946 +      C::abc;
22947 +      return C::second();
22948 +    }
22949 +  }
22950 +}
22951 +
22952 +
22953 +int
22954 +main()
22955 +{
22956 +  A::_a;
22957 +  A::B::ab;
22958 +  A::B::C::abc;
22959 +  return A::B::first();
22960 +}
22961 diff --git a/gdb/testsuite/gdb.cp/namespace-no-imports.exp b/gdb/testsuite/gdb.cp/namespace-no-imports.exp
22962 new file mode 100644
22963 index 0000000..e508103
22964 --- /dev/null
22965 +++ b/gdb/testsuite/gdb.cp/namespace-no-imports.exp
22966 @@ -0,0 +1,76 @@
22967 +# Copyright 2008 Free Software Foundation, Inc.
22968 +
22969 +# This program is free software; you can redistribute it and/or modify
22970 +# it under the terms of the GNU General Public License as published by
22971 +# the Free Software Foundation; either version 3 of the License, or
22972 +# (at your option) any later version.
22973 +#
22974 +# This program is distributed in the hope that it will be useful,
22975 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22976 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22977 +# GNU General Public License for more details.
22978 +#
22979 +# You should have received a copy of the GNU General Public License
22980 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22981 +
22982 +if $tracelevel then {
22983 +    strace $tracelevel
22984 +}
22985 +
22986 +set prms_id 0
22987 +set bug_id 0
22988 +
22989 +set testfile namespace-no-imports
22990 +set srcfile ${testfile}.cc
22991 +set binfile ${objdir}/${subdir}/${testfile}
22992 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
22993 +    untested "Couldn't compile test program"
22994 +    return -1
22995 +}
22996 +
22997 +# Get things started.
22998 +
22999 +gdb_exit
23000 +gdb_start
23001 +gdb_reinitialize_dir $srcdir/$subdir
23002 +gdb_load ${binfile}
23003 +
23004 +############################################
23005 +if ![runto_main] then {
23006 +    perror "couldn't run to breakpoint main"
23007 +    continue
23008 +}
23009 +
23010 +gdb_test "print A::_a" "= 11"
23011 +gdb_test "print A::B::ab" "= 22"
23012 +gdb_test "print A::B::C::abc" "= 33"
23013 +
23014 +gdb_test "print _a" "No symbol .* in current context."
23015 +gdb_test "print ab" "No symbol .* in current context."
23016 +gdb_test "print abc" "No symbol .* in current context."
23017 +
23018 +############################################
23019 +gdb_breakpoint A::B::first
23020 +gdb_continue_to_breakpoint "A::B::first"
23021 +
23022 +gdb_test "print A::_a" "= 11"
23023 +gdb_test "print A::B::ab" "= 22"
23024 +gdb_test "print A::B::C::abc" "= 33"
23025 +
23026 +gdb_test "print _a" "= 11"
23027 +gdb_test "print ab" "= 22"
23028 +gdb_test "print C::abc" "= 33"
23029 +
23030 +gdb_test "print abc" "No symbol .* in current context."
23031 +
23032 +############################################
23033 +gdb_breakpoint A::B::C::second
23034 +gdb_continue_to_breakpoint "A::B::C::second"
23035 +
23036 +gdb_test "print A::_a" "= 11"
23037 +gdb_test "print A::B::ab" "= 22"
23038 +gdb_test "print A::B::C::abc" "= 33"
23039 +
23040 +gdb_test "print _a" "= 11"
23041 +gdb_test "print ab" "= 22"
23042 +gdb_test "print abc" "= 33"
23043 diff --git a/gdb/testsuite/gdb.cp/namespace-recursive.cc b/gdb/testsuite/gdb.cp/namespace-recursive.cc
23044 new file mode 100644
23045 index 0000000..46d4c18
23046 --- /dev/null
23047 +++ b/gdb/testsuite/gdb.cp/namespace-recursive.cc
23048 @@ -0,0 +1,47 @@
23049 +namespace A{
23050 +  int ax = 9;
23051 +}
23052 +
23053 +namespace B{
23054 +  using namespace A;
23055 +}
23056 +
23057 +namespace C{
23058 +  using namespace B;
23059 +}
23060 +
23061 +using namespace C;
23062 +
23063 +//---------------
23064 +namespace D{
23065 +  using namespace D;
23066 +  int dx = 99;
23067 +}
23068 +using namespace D;
23069 +
23070 +//---------------
23071 +namespace{
23072 +  namespace{
23073 +    int xx = 999;
23074 +  }
23075 +}
23076 +
23077 +//---------------
23078 +namespace E{
23079 +  int ex = 9999;
23080 +}
23081 +
23082 +namespace F{
23083 +  namespace FE = E;
23084 +}
23085 +
23086 +namespace G{
23087 +  namespace GF = F;
23088 +}
23089 +
23090 +//----------------
23091 +int main(){
23092 +  using namespace D;
23093 +  namespace GX = G;
23094 +  return ax + dx + xx + G::GF::FE::ex;
23095 +}
23096 diff --git a/gdb/testsuite/gdb.cp/namespace-recursive.exp b/gdb/testsuite/gdb.cp/namespace-recursive.exp
23097 new file mode 100644
23098 index 0000000..5543757
23099 --- /dev/null
23100 +++ b/gdb/testsuite/gdb.cp/namespace-recursive.exp
23101 @@ -0,0 +1,75 @@
23102 +# Copyright 2008 Free Software Foundation, Inc.
23103 +
23104 +# This program is free software; you can redistribute it and/or modify
23105 +# it under the terms of the GNU General Public License as published by
23106 +# the Free Software Foundation; either version 3 of the License, or
23107 +# (at your option) any later version.
23108 +#
23109 +# This program is distributed in the hope that it will be useful,
23110 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23111 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23112 +# GNU General Public License for more details.
23113 +#
23114 +# You should have received a copy of the GNU General Public License
23115 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
23116 +
23117 +if $tracelevel then {
23118 +    strace $tracelevel
23119 +}
23120 +
23121 +set prms_id 0
23122 +set bug_id 0
23123 +
23124 +set testfile namespace-recursive
23125 +set srcfile ${testfile}.cc
23126 +set binfile ${objdir}/${subdir}/${testfile}
23127 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23128 +    untested "Couldn't compile test program"
23129 +    return -1
23130 +}
23131 +
23132 +if [get_compiler_info ${binfile}] {
23133 +    return -1;
23134 +}
23135 +
23136 +
23137 +# Get things started.
23138 +
23139 +gdb_exit
23140 +gdb_start
23141 +gdb_reinitialize_dir $srcdir/$subdir
23142 +gdb_load ${binfile}
23143 +
23144 +if ![runto_main] then {
23145 +    perror "couldn't run to breakpoint main"
23146 +    continue
23147 +}
23148 +
23149 +############################################
23150 +# test printing from namespace imported into
23151 +# imported namespace
23152 +
23153 +gdb_test "print ax" "= 9"
23154 +
23155 +############################################
23156 +# test that gdb can print without falling 
23157 +# into search loop
23158 +
23159 +gdb_test "print dx" "= 99"
23160 +
23161 +############################################
23162 +# test printing from namespace imported into
23163 +# imported namespace where imports are implicit
23164 +# anonymous namespace imports.
23165 +
23166 +gdb_test "print xx" "= 999"
23167 +
23168 +############################################
23169 +# Test printing using recursive namespace
23170 +# aliases.
23171 +
23172 +setup_kfail "gdb/10541" "*-*-*"
23173 +gdb_test "ptype G::GF" "= namespace F"
23174 +
23175 +setup_kfail "gdb/10541" "*-*-*"
23176 +gdb_test "print G::GF::FE::ex" "= 9999"
23177 diff --git a/gdb/testsuite/gdb.cp/namespace-stress.cc b/gdb/testsuite/gdb.cp/namespace-stress.cc
23178 new file mode 100644
23179 index 0000000..f34083e
23180 --- /dev/null
23181 +++ b/gdb/testsuite/gdb.cp/namespace-stress.cc
23182 @@ -0,0 +1,60 @@
23183 +
23184 +namespace A{ int x; }
23185 +namespace B{ int x; }
23186 +namespace C{ int x; }
23187 +namespace D{ int x; }
23188 +namespace E{ int x; }
23189 +namespace F{ int x; }
23190 +namespace G{ int x; }
23191 +namespace H{ int x; }
23192 +namespace I{ int x; }
23193 +namespace J{ int x; }
23194 +namespace K{ int x; }
23195 +namespace L{ int x; }
23196 +namespace M{ int x; }
23197 +namespace N{ int x; }
23198 +namespace O{ int x; }
23199 +namespace P{ int x; }
23200 +namespace Q{ int x; }
23201 +namespace R{ int x; }
23202 +namespace S{ int x; }
23203 +namespace T{ int x; }
23204 +namespace U{ int x; }
23205 +namespace V{ int x; }
23206 +namespace W{ int x; }
23207 +namespace X{ int x; }
23208 +namespace Y{ int x; }
23209 +namespace Z{ int x; }
23210 +
23211 +
23212 +int main(){
23213 +
23214 +  using namespace A;
23215 +  using namespace B;
23216 +  using namespace C;
23217 +  using namespace D;
23218 +  using namespace E;
23219 +  using namespace F;
23220 +  using namespace G;
23221 +  using namespace H;
23222 +  using namespace I;
23223 +  using namespace J;
23224 +  using namespace K;
23225 +  using namespace L;
23226 +  using namespace M;
23227 +  using namespace N;
23228 +  using namespace O;
23229 +  using namespace P;
23230 +  using namespace Q;
23231 +  using namespace R;
23232 +  using namespace S;
23233 +  using namespace T;
23234 +  using namespace U;
23235 +  using namespace V;
23236 +  using namespace W;
23237 +  using namespace X;
23238 +  using namespace Y;
23239 +  using namespace Z;
23240 +
23241 +  return 0;
23242 +}
23243 \ No newline at end of file
23244 diff --git a/gdb/testsuite/gdb.cp/namespace-stress.exp b/gdb/testsuite/gdb.cp/namespace-stress.exp
23245 new file mode 100644
23246 index 0000000..1806523
23247 --- /dev/null
23248 +++ b/gdb/testsuite/gdb.cp/namespace-stress.exp
23249 @@ -0,0 +1,50 @@
23250 +# Copyright 2008 Free Software Foundation, Inc.
23251 +
23252 +# This program is free software; you can redistribute it and/or modify
23253 +# it under the terms of the GNU General Public License as published by
23254 +# the Free Software Foundation; either version 3 of the License, or
23255 +# (at your option) any later version.
23256 +#
23257 +# This program is distributed in the hope that it will be useful,
23258 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23259 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23260 +# GNU General Public License for more details.
23261 +#
23262 +# You should have received a copy of the GNU General Public License
23263 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
23264 +
23265 +if $tracelevel then {
23266 +    strace $tracelevel
23267 +}
23268 +
23269 +set prms_id 0
23270 +set bug_id 0
23271 +
23272 +set testfile namespace-stress
23273 +set srcfile ${testfile}.cc
23274 +set binfile ${objdir}/${subdir}/${testfile}
23275 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23276 +    untested "Couldn't compile test program"
23277 +    return -1
23278 +}
23279 +
23280 +if [get_compiler_info ${binfile}] {
23281 +    return -1;
23282 +}
23283 +
23284 +# Get things started.
23285 +
23286 +gdb_exit
23287 +gdb_start
23288 +gdb_reinitialize_dir $srcdir/$subdir
23289 +gdb_load ${binfile}
23290 +
23291 +if ![runto_main] then {
23292 +    perror "couldn't run to breakpoint main"
23293 +    continue
23294 +}
23295 +
23296 +############################################
23297 +# Test that the search can fail efficiently 
23298 +
23299 +gdb_test "print y" "No symbol \"y\" in current context."
23300 diff --git a/gdb/testsuite/gdb.cp/namespace-using.cc b/gdb/testsuite/gdb.cp/namespace-using.cc
23301 index 4786fd5..8ff5622 100644
23302 --- a/gdb/testsuite/gdb.cp/namespace-using.cc
23303 +++ b/gdb/testsuite/gdb.cp/namespace-using.cc
23304 @@ -1,26 +1,129 @@
23305 +namespace M
23306 +{
23307 +  int x = 911;
23308 +}
23309 +
23310 +namespace N
23311 +{
23312 +  int x = 912;
23313 +}
23314 +
23315 +int marker10 ()
23316 +{
23317 +  using namespace M;
23318 +  int y = x + 1;       // marker10 stop
23319 +  using namespace N;
23320 +  return y;
23321 +}
23322 +
23323 +namespace J
23324 +{
23325 +  int jx = 44;
23326 +}
23327 +
23328 +namespace K
23329 +{
23330 +  int
23331 +  marker9 ()
23332 +  {
23333 +    //x;
23334 +    return marker10 ();
23335 +  }
23336 +}
23337 +
23338 +namespace L
23339 +{
23340 +  using namespace J;
23341 +  int
23342 +  marker8 ()
23343 +  {
23344 +    jx;
23345 +    return K::marker9 ();
23346 +  }
23347 +}
23348 +
23349 +namespace G
23350 +{
23351 +  namespace H
23352 +  {
23353 +    int ghx = 6;
23354 +  }
23355 +}
23356 +
23357 +namespace I
23358 +{  
23359 +  int
23360 +  marker7 ()
23361 +  {
23362 +    using namespace G::H;
23363 +    ghx;
23364 +    return L::marker8 ();
23365 +  }
23366 +}
23367 +
23368 +namespace E
23369 +{
23370 +  namespace F
23371 +  {
23372 +    int efx = 5;
23373 +  }
23374 +}
23375 +
23376 +using namespace E::F;
23377 +int
23378 +marker6 ()
23379 +{
23380 +  efx;
23381 +  return I::marker7 ();
23382 +}
23383 +
23384  namespace A
23385  {
23386    int _a = 1;
23387    int x = 2;
23388  }
23389  
23390 -int marker4(){
23391 -       using A::x;
23392 -       return 0;
23393 +namespace C
23394 +{
23395 +  int cc = 3;
23396 +}
23397 +
23398 +namespace D
23399 +{
23400 +  int dx = 4;
23401 +}
23402 +
23403 +using namespace C;
23404 +int
23405 +marker5 ()
23406 +{
23407 +  cc;
23408 +  return marker6 ();
23409 +}
23410 +
23411 +int
23412 +marker4 ()
23413 +{
23414 +  using D::dx;
23415 +  return marker5 ();
23416  }
23417  
23418 -int marker3(){
23419 -       return marker4();
23420 +int
23421 +marker3 ()
23422 +{
23423 +  return marker4 ();
23424  }
23425  
23426 -int marker2()
23427 +int
23428 +marker2 ()
23429  {
23430    namespace B = A;
23431    B::_a;
23432 -  return marker3();
23433 +  return marker3 ();
23434  }
23435  
23436 -int marker1()
23437 +int
23438 +marker1 ()
23439  {
23440    int total = 0;
23441    {
23442 @@ -29,17 +132,18 @@ int marker1()
23443        using namespace A;
23444        int c = 2;
23445        {
23446 -        int d = 3;
23447 -        total = _a + b + c + d + marker2(); // marker1 stop
23448 +       int d = 3;
23449 +       total = _a + b + c + d + marker2 (); // marker1 stop
23450        }
23451      }
23452    }
23453    return total;
23454  }
23455  
23456 -int main()
23457 +int
23458 +main ()
23459  {
23460    using namespace A;
23461    _a;
23462 -  return marker1();
23463 +  return marker1 ();
23464  }
23465 diff --git a/gdb/testsuite/gdb.cp/namespace-using.exp b/gdb/testsuite/gdb.cp/namespace-using.exp
23466 index f24973f..fc23115 100644
23467 --- a/gdb/testsuite/gdb.cp/namespace-using.exp
23468 +++ b/gdb/testsuite/gdb.cp/namespace-using.exp
23469 @@ -28,6 +28,11 @@ if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
23470      return -1
23471  }
23472  
23473 +if [get_compiler_info ${binfile}] {
23474 +    return -1;
23475 +}
23476 +
23477 +
23478  # Get things started.
23479  
23480  gdb_exit
23481 @@ -46,42 +51,155 @@ if ![runto_main] then {
23482  
23483  gdb_test "print _a" "= 1"
23484  
23485 +# Test that names are not printed when they 
23486 +# are not imported
23487 +
23488 +gdb_breakpoint marker3
23489 +gdb_continue_to_breakpoint "marker3"
23490 +
23491 +#send_gdb "break marker3\n"
23492 +#send_gdb "continue\n"
23493 +
23494 +gdb_test "print _a" "No symbol \"_a\" in current context." "Print _a without import"
23495 +
23496 +gdb_exit
23497 +gdb_start
23498 +gdb_reinitialize_dir $srcdir/$subdir
23499 +gdb_load ${binfile}
23500 +
23501 +
23502  ############################################
23503  # test printing of namespace imported into 
23504  # a scope containing the pc.
23505  
23506 +if ![runto_main] then {
23507 +    perror "couldn't run to breakpoint main"
23508 +    continue
23509 +}
23510 +
23511  gdb_breakpoint [gdb_get_line_number "marker1 stop"]
23512  gdb_continue_to_breakpoint "marker1 stop"
23513  
23514  gdb_test "print _a" "= 1" "print _a in a nested scope"
23515  
23516 +
23517 +gdb_exit
23518 +gdb_start
23519 +gdb_reinitialize_dir $srcdir/$subdir
23520 +gdb_load ${binfile}
23521 +
23522 +############################################
23523 +# test printing of namespace imported into 
23524 +# file scope.
23525 +
23526 +
23527 +if ![runto marker5] then {
23528 +    perror "couldn't run to breakpoint marker5"
23529 +    continue
23530 +}
23531 +
23532 +gdb_test "print cc" "= 3"
23533 +
23534 +gdb_exit
23535 +gdb_start
23536 +gdb_reinitialize_dir $srcdir/$subdir
23537 +gdb_load ${binfile}
23538 +
23539 +
23540  ############################################
23541  # Test printing of namespace aliases
23542  
23543 -setup_kfail "gdb/7935" "*-*-*"
23544  if ![runto marker2] then {
23545      perror "couldn't run to breakpoint marker2"
23546      continue
23547  }
23548  
23549 -gdb_test "print B::a" "= 1"
23550 +gdb_test "print B::_a" "= 1"
23551 +
23552 +gdb_test "print _a" "No symbol \"_a\" in current context." "print _a in namespace alias scope"
23553 +gdb_test "print x" "No symbol \"x\" in current context." "print x in namespace alias scope"
23554 +
23555 +gdb_exit
23556 +gdb_start
23557 +gdb_reinitialize_dir $srcdir/$subdir
23558 +gdb_load ${binfile}
23559 +
23560  
23561  ############################################
23562  # Test that names are not printed when they 
23563  # are not imported
23564  
23565 -gdb_breakpoint "marker3"
23566 -gdb_continue_to_breakpoint "marker3"
23567 +if {![runto marker3]} {
23568 +    perror "couldn't run to breakpoint marker3"
23569 +}
23570  
23571 -gdb_test "print _a" "No symbol \"_a\" in current context." "Print a without import"
23572 +# gcc-4-3 puts import statements for aliases in
23573 +# the global scope instead of the corresponding
23574 +# function scope. These wrong import statements throw
23575 +# this test off. This is fixed in gcc-4-4.
23576 +if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* }
23577 +
23578 +gdb_test "print _a" "No symbol \"_a\" in current context." "Print _a without import"
23579  
23580  ############################################
23581  # Test printing of individually imported elements
23582  
23583 -setup_kfail "gdb/7936" "*-*-*"
23584  if ![runto marker4] then {
23585      perror "couldn't run to breakpoint marker4"
23586      continue
23587  }
23588  
23589 -gdb_test "print x" "= 2"
23590 +gdb_test "print dx" "= 4"
23591 +
23592 +############################################
23593 +# Test printing of namespace aliases
23594 +
23595 +if ![runto marker5] then {
23596 +    perror "couldn't run to marker5"
23597 +    continue
23598 +}
23599 +
23600 +gdb_test "print efx" "= 5"
23601 +
23602 +############################################
23603 +# Test printing of variables imported from
23604 +# nested namespaces
23605 +
23606 +if ![runto I::marker7] then {
23607 +    perror "couldn't run to breakpoint I::marker7"
23608 +    continue
23609 +}
23610 +
23611 +gdb_test "print ghx" "= 6"
23612 +
23613 +############################################
23614 +# Test that variables are not printed in a namespace
23615 +# that is sibling to the namespace containing an import
23616 +
23617 +if ![runto L::marker8] then {
23618 +    perror "couldn't run to breakpoint L::marker8"
23619 +    continue
23620 +}
23621 +
23622 +gdb_test "print jx" "= 44"
23623 +
23624 +gdb_breakpoint "K::marker9"
23625 +gdb_continue_to_breakpoint "K::marker9"
23626 +
23627 +gdb_test "print jx" "No symbol \"jx\" in current context."
23628 +
23629 +############################################
23630 +# Test that variables are only printed after the line
23631 +# containing the import
23632 +
23633 +if ![runto_main] then {
23634 +    perror "couldn't run to breakpoint main"
23635 +    continue
23636 +}
23637 +
23638 +gdb_breakpoint [gdb_get_line_number "marker10 stop"]
23639 +gdb_continue_to_breakpoint "marker10 stop"
23640 +
23641 +# Assert that M::x is printed and not N::x
23642 +gdb_test "print x" "= 911" "print x (from M::x)"
23643 +
23644 diff --git a/gdb/testsuite/gdb.cp/namespace.exp b/gdb/testsuite/gdb.cp/namespace.exp
23645 index 76b1b82..2042db2 100644
23646 --- a/gdb/testsuite/gdb.cp/namespace.exp
23647 +++ b/gdb/testsuite/gdb.cp/namespace.exp
23648 @@ -24,6 +24,7 @@
23649  # for namespaces.
23650  # Note: As of 2000-06-03, they passed under g++ - djb
23651  
23652 +load_lib "cp-support.exp"
23653  
23654  if $tracelevel then {
23655          strace $tracelevel
23656 @@ -259,11 +260,16 @@ gdb_test "ptype E" "type = namespace C::D::E"
23657  gdb_test "ptype CClass" "type = (class C::CClass \{\r\n  public:|struct C::CClass \{)\r\n    int x;\r\n\}"
23658  gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n  public:|struct C::CClass::NestedClass \{)\r\n    int y;\r\n\}"
23659  gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context."
23660 -setup_kfail "gdb/1448" "*-*-*"
23661 -gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n  public:\r\n    int x;\r\n\}"
23662 -setup_kfail "gdb/1448" "*-*-*"
23663 -gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n  public:\r\n    int y;\r\n\}"
23664 -setup_kfail "gdb/1448" "*-*-*"
23665 +cp_test_ptype_class \
23666 +       "ptype ::C::CClass" "" "class" "C::CClass" \
23667 +       {
23668 +           { field public "int x;" }
23669 +       }
23670 +cp_test_ptype_class \
23671 +       "ptype ::C::CClass::NestedClass" "" "class" "C::CClass::NestedClass" \
23672 +       {
23673 +           { field public "int y;" }
23674 +       }
23675  gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"."
23676  gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"."
23677  gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"."
23678 @@ -273,8 +279,11 @@ gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"
23679  
23680  gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
23681  gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n  public:|struct C::OtherFileClass \{)\r\n    int z;\r\n\}"
23682 -setup_kfail "gdb/1448" "*-*-*"
23683 -gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n\}"
23684 +cp_test_ptype_class \
23685 +       "ptype ::C::OtherFileClass" "" "class" "C::OtherFileClass" \
23686 +       {
23687 +           { field public "int z;" }
23688 +       }
23689  gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
23690  
23691  # Some anonymous namespace tests.
23692 diff --git a/gdb/testsuite/gdb.cp/overload.exp b/gdb/testsuite/gdb.cp/overload.exp
23693 index 24025a2..a72932e 100644
23694 --- a/gdb/testsuite/gdb.cp/overload.exp
23695 +++ b/gdb/testsuite/gdb.cp/overload.exp
23696 @@ -74,12 +74,12 @@ set re_methods      "${re_methods}${ws}int overload1arg\\((void|)\\);"
23697  set re_methods "${re_methods}${ws}int overload1arg\\(char\\);"
23698  set re_methods "${re_methods}${ws}int overload1arg\\(signed char\\);"
23699  set re_methods "${re_methods}${ws}int overload1arg\\(unsigned char\\);"
23700 -set re_methods "${re_methods}${ws}int overload1arg\\(short\\);"
23701 -set re_methods "${re_methods}${ws}int overload1arg\\(unsigned short\\);"
23702 +set re_methods "${re_methods}${ws}int overload1arg\\(short( int)?\\);"
23703 +set re_methods "${re_methods}${ws}int overload1arg\\((unsigned short|short unsigned)( int)?\\);"
23704  set re_methods "${re_methods}${ws}int overload1arg\\(int\\);"
23705  set re_methods "${re_methods}${ws}int overload1arg\\(unsigned int\\);"
23706 -set re_methods "${re_methods}${ws}int overload1arg\\(long\\);"
23707 -set re_methods "${re_methods}${ws}int overload1arg\\(unsigned long\\);"
23708 +set re_methods "${re_methods}${ws}int overload1arg\\(long( int)?\\);"
23709 +set re_methods "${re_methods}${ws}int overload1arg\\((unsigned long|long unsigned)( int)?\\);"
23710  set re_methods "${re_methods}${ws}int overload1arg\\(float\\);"
23711  set re_methods "${re_methods}${ws}int overload1arg\\(double\\);"
23712  set re_methods "${re_methods}${ws}int overloadfnarg\\((void|)\\);"
23713 diff --git a/gdb/testsuite/gdb.cp/ovldbreak.exp b/gdb/testsuite/gdb.cp/ovldbreak.exp
23714 index 8a6b795..9997a45 100644
23715 --- a/gdb/testsuite/gdb.cp/ovldbreak.exp
23716 +++ b/gdb/testsuite/gdb.cp/ovldbreak.exp
23717 @@ -127,10 +127,24 @@ proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumber} {
23718  }
23719  
23720  # This is the expected menu for overload1arg.
23721 -# Note the arg type variations on lines 6 and 13.
23722 +# Note the arg type variations for void and integer types.
23723  # This accommodates different versions of g++.
23724  
23725 -set menu_overload1arg "\\\[0\\\] cancel\r\n\\\[1\\\] all\r\n\\\[2\\\] foo::overload1arg\\(double\\) at.*$srcfile:121\r\n\\\[3\\\] foo::overload1arg\\(float\\) at.*$srcfile:120\r\n\\\[4\\\] foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r\n\\\[5\\\] foo::overload1arg\\(long\\) at.*$srcfile:118\r\n\\\[6\\\] foo::overload1arg\\((unsigned int|unsigned)\\) at.*$srcfile:117\r\n\\\[7\\\] foo::overload1arg\\(int\\) at.*$srcfile:116\r\n\\\[8\\\] foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r\n\\\[9\\\] foo::overload1arg\\(short\\) at.*$srcfile:114\r\n\\\[10\\\] foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r\n\\\[11\\\] foo::overload1arg\\(signed char\\) at.*$srcfile:112\r\n\\\[12\\\] foo::overload1arg\\(char\\) at.*$srcfile:111\r\n\\\[13\\\] foo::overload1arg\\((void|)\\) at.*$srcfile:110\r\n> $"
23726 +set    menu_overload1arg "\\\[0\\\] cancel\r\n"
23727 +append menu_overload1arg "\\\[1\\\] all\r\n"
23728 +append menu_overload1arg "\\\[2\\\] foo::overload1arg\\(double\\) at.*$srcfile:121\r\n"
23729 +append menu_overload1arg "\\\[3\\\] foo::overload1arg\\(float\\) at.*$srcfile:120\r\n"
23730 +append menu_overload1arg "\\\[4\\\] foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r\n"
23731 +append menu_overload1arg "\\\[5\\\] foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r\n"
23732 +append menu_overload1arg "\\\[6\\\] foo::overload1arg\\((unsigned int|unsigned)\\) at.*$srcfile:117\r\n"
23733 +append menu_overload1arg "\\\[7\\\] foo::overload1arg\\(int\\) at.*$srcfile:116\r\n"
23734 +append menu_overload1arg "\\\[8\\\] foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r\n"
23735 +append menu_overload1arg "\\\[9\\\] foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r\n"
23736 +append menu_overload1arg "\\\[10\\\] foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r\n"
23737 +append menu_overload1arg "\\\[11\\\] foo::overload1arg\\(signed char\\) at.*$srcfile:112\r\n"
23738 +append menu_overload1arg "\\\[12\\\] foo::overload1arg\\(char\\) at.*$srcfile:111\r\n"
23739 +append menu_overload1arg "\\\[13\\\] foo::overload1arg\\((void|)\\) at.*$srcfile:110\r\n"
23740 +append menu_overload1arg "> $"
23741  
23742  # Set multiple-symbols to "ask", to allow us to test the use
23743  # of the multiple-choice menu when breaking on an overloaded method.
23744 @@ -157,17 +171,17 @@ set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 13   13 110
23745  
23746  gdb_test "info break" \
23747      "Num     Type\[\t \]+Disp Enb Address\[\t \]+What.*
23748 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in main at.*$srcfile:49\r
23749 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\r
23750  \[\t \]+breakpoint already hit 1 time\r
23751  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
23752  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
23753  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
23754 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
23755 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
23756 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
23757 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
23758  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
23759  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
23760 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
23761 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
23762 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
23763 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
23764  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
23765  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
23766  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
23767 @@ -215,17 +229,17 @@ gdb_expect {
23768  
23769  gdb_test "info break" \
23770      "Num     Type\[\t \]+Disp Enb Address\[\t \]+What.*
23771 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in main at.*$srcfile:49\r
23772 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\r
23773  \[\t \]+breakpoint already hit 1 time\r
23774  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
23775  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
23776  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
23777 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
23778 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
23779 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
23780 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
23781  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
23782  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
23783 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
23784 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
23785 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
23786 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
23787  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
23788  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
23789  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
23790 @@ -296,12 +310,12 @@ gdb_test "info break" \
23791      "Num     Type\[\t \]+Disp Enb Address\[\t \]+What.*
23792  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
23793  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
23794 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
23795 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
23796 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
23797 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
23798  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
23799  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
23800 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
23801 -\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
23802 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
23803 +\[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
23804  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
23805  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
23806  \[0-9\]+\[\t \]+breakpoint     keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
23807 diff --git a/gdb/testsuite/gdb.cp/shadowing.cc b/gdb/testsuite/gdb.cp/shadowing.cc
23808 new file mode 100644
23809 index 0000000..6d9c2f1
23810 --- /dev/null
23811 +++ b/gdb/testsuite/gdb.cp/shadowing.cc
23812 @@ -0,0 +1,48 @@
23813 +namespace A
23814 +{
23815 +  int x = 11;
23816 +}
23817 +
23818 +int x = 22;
23819 +int y = 0;
23820 +
23821 +class B
23822 +{
23823 +public:
23824 +  int x;
23825 +
23826 +  int
23827 +  func()
23828 +  {
23829 +    x = 33;
23830 +    y+=x; // marker1
23831 +
23832 +      {
23833 +        int x = 44;
23834 +        y+=x; // marker2
23835 +
23836 +          {
23837 +            int x = 55;
23838 +            y+=x; // marker3
23839 +
23840 +              {
23841 +                int z = x; //prevent gcc from optimizing away this scope
23842 +                using namespace A;
23843 +                y+=x; // marker4
23844 +
23845 +                using A::x;
23846 +                y+=x; // marker5
23847 +                
23848 +                return this->x;
23849 +              }
23850 +          }
23851 +      }
23852 +  }
23853 +};
23854 +
23855 +int
23856 +main()
23857 +{
23858 +  B theB;
23859 +  return theB.func();
23860 +}
23861 diff --git a/gdb/testsuite/gdb.cp/shadowing.exp b/gdb/testsuite/gdb.cp/shadowing.exp
23862 new file mode 100644
23863 index 0000000..6922eed
23864 --- /dev/null
23865 +++ b/gdb/testsuite/gdb.cp/shadowing.exp
23866 @@ -0,0 +1,91 @@
23867 +# Copyright 2008 Free Software Foundation, Inc.
23868 +
23869 +# This program is free software; you can redistribute it and/or modify
23870 +# it under the terms of the GNU General Public License as published by
23871 +# the Free Software Foundation; either version 3 of the License, or
23872 +# (at your option) any later version.
23873 +#
23874 +# This program is distributed in the hope that it will be useful,
23875 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23876 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23877 +# GNU General Public License for more details.
23878 +#
23879 +# You should have received a copy of the GNU General Public License
23880 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
23881 +
23882 +if $tracelevel then {
23883 +    strace $tracelevel
23884 +}
23885 +
23886 +set prms_id 0
23887 +set bug_id 0
23888 +
23889 +set testfile shadowing
23890 +set srcfile ${testfile}.cc
23891 +set binfile ${objdir}/${subdir}/${testfile}
23892 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23893 +    untested "Couldn't compile test program"
23894 +    return -1
23895 +}
23896 +
23897 +if [get_compiler_info ${binfile}] {
23898 +    return -1;
23899 +}
23900 +
23901 +# Get things started.
23902 +
23903 +gdb_exit
23904 +gdb_start
23905 +gdb_reinitialize_dir $srcdir/$subdir
23906 +gdb_load ${binfile}
23907 +
23908 +if ![runto_main] then {
23909 +    perror "couldn't run to breakpoint main"
23910 +    continue
23911 +}
23912 +
23913 +############################################
23914 +# Test printing of class variable is not shadowed
23915 +# by global variable
23916 +
23917 +gdb_breakpoint [gdb_get_line_number "marker1"]
23918 +gdb_continue_to_breakpoint "marker1"
23919 +
23920 +gdb_test "print x" "= 33" "Print class x shadowing global x"
23921 +
23922 +
23923 +############################################
23924 +# Test printing local variable is not shadowed
23925 +# by class variable
23926 +
23927 +gdb_breakpoint [gdb_get_line_number "marker2"]
23928 +gdb_continue_to_breakpoint "marker2"
23929 +
23930 +gdb_test "print x" "= 44" "Print local x shadowing class x"
23931 +
23932 +############################################
23933 +# Test inner scope x is printed not outer scope
23934 +
23935 +gdb_breakpoint [gdb_get_line_number "marker3"]
23936 +gdb_continue_to_breakpoint "marker3"
23937 +
23938 +gdb_test "print x" "= 55" "Print inner scope x"
23939 +
23940 +############################################
23941 +# Test printing local variable is not shadowed
23942 +# by namespace variable
23943 +
23944 +gdb_breakpoint [gdb_get_line_number "marker4"]
23945 +gdb_continue_to_breakpoint "marker4"
23946 +
23947 +gdb_test "print x" "= 55" "Print local x not namespace x"
23948 +
23949 +############################################
23950 +# Test imported namespace element is printed
23951 +
23952 +gdb_breakpoint [gdb_get_line_number "marker5"]
23953 +gdb_continue_to_breakpoint "marker5"
23954 +
23955 +if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* }
23956 +
23957 +gdb_test "print x" "= 11" "Print imported namespace x"
23958 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.S b/gdb/testsuite/gdb.dwarf2/dw2-aranges.S
23959 new file mode 100644
23960 index 0000000..d5b9ca5
23961 --- /dev/null
23962 +++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.S
23963 @@ -0,0 +1,140 @@
23964 +/* This testcase is part of GDB, the GNU debugger.
23965 +
23966 +   Copyright 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
23967 +
23968 +   This program is free software; you can redistribute it and/or modify
23969 +   it under the terms of the GNU General Public License as published by
23970 +   the Free Software Foundation; either version 3 of the License, or
23971 +   (at your option) any later version.
23972 +
23973 +   This program is distributed in the hope that it will be useful,
23974 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
23975 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23976 +   GNU General Public License for more details.
23977 +
23978 +   You should have received a copy of the GNU General Public License
23979 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
23980 +
23981 +/* Test .debug_aranges containing zero address_size.  */
23982 +
23983 +/* Dummy function to provide debug information for.  */
23984 +
23985 +       .text
23986 +.Lbegin_text1:
23987 +       .globl main
23988 +       .type main, %function
23989 +main:
23990 +.Lbegin_main:
23991 +       .int 0
23992 +.Lend_main:
23993 +       .size main, .-main
23994 +.Lend_text1:
23995 +
23996 +/* Debug information */
23997 +
23998 +       .section .debug_info
23999 +.Lcu1_begin:
24000 +       /* CU header */
24001 +       .4byte  .Lcu1_end - .Lcu1_start         /* Length of Compilation Unit */
24002 +.Lcu1_start:
24003 +       .2byte  2                               /* DWARF Version */
24004 +       .4byte  .Labbrev1_begin                 /* Offset into abbrev section */
24005 +       .byte   4                               /* Pointer size */
24006 +
24007 +       /* CU die */
24008 +       .uleb128 1                              /* Abbrev: DW_TAG_compile_unit */
24009 +       .4byte  .Lend_text1                     /* DW_AT_high_pc */
24010 +       .4byte  .Lbegin_text1                   /* DW_AT_low_pc */
24011 +       .ascii  "file1.txt\0"                   /* DW_AT_name */
24012 +       .ascii  "GNU C 3.3.3\0"                 /* DW_AT_producer */
24013 +       .byte   1                               /* DW_AT_language (C) */
24014 +
24015 +       /* main */
24016 +       .uleb128        2                       /* Abbrev: DW_TAG_subprogram */
24017 +       .byte           1                       /* DW_AT_external */
24018 +       .byte           1                       /* DW_AT_decl_file */
24019 +       .byte           2                       /* DW_AT_decl_line */
24020 +       .ascii          "main\0"                /* DW_AT_name */
24021 +       .4byte          .Ltype_int-.Lcu1_begin  /* DW_AT_type */
24022 +       .4byte          .Lbegin_main    /* DW_AT_low_pc */
24023 +       .4byte          .Lend_main              /* DW_AT_high_pc */
24024 +       .byte           1                       /* DW_AT_frame_base: length */
24025 +       .byte           0x55                    /* DW_AT_frame_base: DW_OP_reg5 */
24026 +
24027 +.Ltype_int:
24028 +       .uleb128        3                       /* Abbrev: DW_TAG_base_type */
24029 +       .ascii          "int\0"                 /* DW_AT_name */
24030 +       .byte           4                       /* DW_AT_byte_size */
24031 +       .byte           5                       /* DW_AT_encoding */
24032 +
24033 +       .byte           0                       /* End of children of CU */
24034 +
24035 +.Lcu1_end:
24036 +
24037 +/* Abbrev table */
24038 +       .section .debug_abbrev
24039 +.Labbrev1_begin:
24040 +       .uleb128        1                       /* Abbrev code */
24041 +       .uleb128        0x11                    /* DW_TAG_compile_unit */
24042 +       .byte           1                       /* has_children */
24043 +       .uleb128        0x12                    /* DW_AT_high_pc */
24044 +       .uleb128        0x1                     /* DW_FORM_addr */
24045 +       .uleb128        0x11                    /* DW_AT_low_pc */
24046 +       .uleb128        0x1                     /* DW_FORM_addr */
24047 +       .uleb128        0x3                     /* DW_AT_name */
24048 +       .uleb128        0x8                     /* DW_FORM_string */
24049 +       .uleb128        0x25                    /* DW_AT_producer */
24050 +       .uleb128        0x8                     /* DW_FORM_string */
24051 +       .uleb128        0x13                    /* DW_AT_language */
24052 +       .uleb128        0xb                     /* DW_FORM_data1 */
24053 +       .byte           0x0                     /* Terminator */
24054 +       .byte           0x0                     /* Terminator */
24055 +
24056 +       .uleb128        2                       /* Abbrev code */
24057 +       .uleb128        0x2e                    /* DW_TAG_subprogram */
24058 +       .byte           0                       /* has_children */
24059 +       .uleb128        0x3f                    /* DW_AT_external */
24060 +       .uleb128        0xc                     /* DW_FORM_flag */
24061 +       .uleb128        0x3a                    /* DW_AT_decl_file */
24062 +       .uleb128        0xb                     /* DW_FORM_data1 */
24063 +       .uleb128        0x3b                    /* DW_AT_decl_line */
24064 +       .uleb128        0xb                     /* DW_FORM_data1 */
24065 +       .uleb128        0x3                     /* DW_AT_name */
24066 +       .uleb128        0x8                     /* DW_FORM_string */
24067 +       .uleb128        0x49                    /* DW_AT_type */
24068 +       .uleb128        0x13                    /* DW_FORM_ref4 */
24069 +       .uleb128        0x11                    /* DW_AT_low_pc */
24070 +       .uleb128        0x1                     /* DW_FORM_addr */
24071 +       .uleb128        0x12                    /* DW_AT_high_pc */
24072 +       .uleb128        0x1                     /* DW_FORM_addr */
24073 +       .uleb128        0x40                    /* DW_AT_frame_base */
24074 +       .uleb128        0xa                     /* DW_FORM_block1 */
24075 +       .byte           0x0                     /* Terminator */
24076 +       .byte           0x0                     /* Terminator */
24077 +
24078 +       .uleb128        3                       /* Abbrev code */
24079 +       .uleb128        0x24                    /* DW_TAG_base_type */
24080 +       .byte           0                       /* has_children */
24081 +       .uleb128        0x3                     /* DW_AT_name */
24082 +       .uleb128        0x8                     /* DW_FORM_string */
24083 +       .uleb128        0xb                     /* DW_AT_byte_size */
24084 +       .uleb128        0xb                     /* DW_FORM_data1 */
24085 +       .uleb128        0x3e                    /* DW_AT_encoding */
24086 +       .uleb128        0xb                     /* DW_FORM_data1 */
24087 +       .byte           0x0                     /* Terminator */
24088 +       .byte           0x0                     /* Terminator */
24089 +
24090 +       .byte           0x0                     /* Terminator */
24091 +       .byte           0x0                     /* Terminator */
24092 +
24093 +/* aranges table */
24094 +       .section .debug_aranges
24095 +       .long   .Laranges_end - 1f
24096 +1:
24097 +       .2byte  2                               /* aranges Version */
24098 +       .4byte  .Lcu1_begin - .debug_info       /* Offset into .debug_info section */
24099 +       /* The GDB crasher is this zero value.  */
24100 +       .byte           0                       /* aranges address_size */
24101 +       .byte           0                       /* aranges segment_size */
24102 +
24103 +.Laranges_end:
24104 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
24105 new file mode 100644
24106 index 0000000..39632d5
24107 --- /dev/null
24108 +++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
24109 @@ -0,0 +1,40 @@
24110 +# Copyright 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
24111 +
24112 +# This program is free software; you can redistribute it and/or modify
24113 +# it under the terms of the GNU General Public License as published by
24114 +# the Free Software Foundation; either version 3 of the License, or
24115 +# (at your option) any later version.
24116 +#
24117 +# This program is distributed in the hope that it will be useful,
24118 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24119 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24120 +# GNU General Public License for more details.
24121 +#
24122 +# You should have received a copy of the GNU General Public License
24123 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
24124 +
24125 +# Test .debug_aranges containing zero address_size.
24126 +
24127 +# This test can only be run on targets which support DWARF-2 and use gas.
24128 +# For now pick a sampling of likely targets.
24129 +if {![istarget *-*-linux*]
24130 +    && ![istarget *-*-gnu*]
24131 +    && ![istarget *-*-elf*]
24132 +    && ![istarget *-*-openbsd*]
24133 +    && ![istarget arm-*-eabi*]
24134 +    && ![istarget powerpc-*-eabi*]} {
24135 +    return 0  
24136 +}
24137 +
24138 +set testfile "dw2-aranges"
24139 +set srcfile ${testfile}.S
24140 +set binfile ${objdir}/${subdir}/${testfile}
24141 +
24142 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {nodebug}] != "" } {
24143 +    return -1
24144 +}
24145 +
24146 +clean_restart $testfile
24147 +
24148 +# Failed gdb_load would abort the testcase execution earlier.
24149 +pass "file loaded"
24150 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.c b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
24151 new file mode 100644
24152 index 0000000..1f02d90
24153 --- /dev/null
24154 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
24155 @@ -0,0 +1,42 @@
24156 +/* This testcase is part of GDB, the GNU debugger.
24157 +
24158 +   Copyright 2004 Free Software Foundation, Inc.
24159 +
24160 +   This program is free software; you can redistribute it and/or modify
24161 +   it under the terms of the GNU General Public License as published by
24162 +   the Free Software Foundation; either version 2 of the License, or
24163 +   (at your option) any later version.
24164 +
24165 +   This program is distributed in the hope that it will be useful,
24166 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
24167 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24168 +   GNU General Public License for more details.
24169
24170 +   You should have received a copy of the GNU General Public License
24171 +   along with this program; if not, write to the Free Software
24172 +   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
24173 +   USA.  */
24174 +
24175 +
24176 +/* The function `func1' traced into must have debug info on offset > 0;
24177 +   (DW_UNSND (attr)).  This is the reason of `func0' existence.  */
24178 +
24179 +void
24180 +func0(int a, int b)
24181 +{
24182 +}
24183 +
24184 +/* `func1' being traced into must have some arguments to dump.  */
24185 +
24186 +void
24187 +func1(int a, int b)
24188 +{
24189 +  func0 (a,b);
24190 +}
24191 +
24192 +int
24193 +main(void)
24194 +{
24195 +  func1 (1, 2);
24196 +  return 0;
24197 +}
24198 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
24199 new file mode 100644
24200 index 0000000..1c6e84a
24201 --- /dev/null
24202 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
24203 @@ -0,0 +1,79 @@
24204 +# Copyright 2006 Free Software Foundation, Inc.
24205 +
24206 +# This program is free software; you can redistribute it and/or modify
24207 +# it under the terms of the GNU General Public License as published by
24208 +# the Free Software Foundation; either version 2 of the License, or
24209 +# (at your option) any later version.
24210 +# 
24211 +# This program is distributed in the hope that it will be useful,
24212 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24213 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24214 +# GNU General Public License for more details.
24215 +# 
24216 +# You should have received a copy of the GNU General Public License
24217 +# along with this program; if not, write to the Free Software
24218 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24219 +
24220 +# Minimal DWARF-2 unit test
24221 +
24222 +# This test can only be run on targets which support DWARF-2.
24223 +# For now pick a sampling of likely targets.
24224 +if {![istarget *-*-linux*]
24225 +    && ![istarget *-*-gnu*]
24226 +    && ![istarget *-*-elf*]
24227 +    && ![istarget *-*-openbsd*]
24228 +    && ![istarget arm-*-eabi*]
24229 +    && ![istarget powerpc-*-eabi*]} {
24230 +    return 0  
24231 +}
24232 +
24233 +set testfile "dw2-stripped"
24234 +set srcfile ${testfile}.c
24235 +set binfile ${objdir}/${subdir}/${testfile}.x
24236 +
24237 +remote_exec build "rm -f ${binfile}"
24238 +
24239 +# get the value of gcc_compiled
24240 +if [get_compiler_info ${binfile}] {
24241 +    return -1
24242 +}
24243 +
24244 +# This test can only be run on gcc as we use additional_flags=FIXME
24245 +if {$gcc_compiled == 0} {
24246 +    return 0
24247 +}
24248 +
24249 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-ggdb3}] != "" } {
24250 +    return -1
24251 +}
24252 +
24253 +remote_exec build "objcopy -R .debug_loc ${binfile}"
24254 +set strip_output [remote_exec build "objdump -h ${binfile}"]
24255 +
24256 +set test "stripping test file preservation"
24257 +if [ regexp ".debug_info " $strip_output]  {
24258 +    pass "$test (.debug_info preserved)"
24259 +} else {
24260 +    fail "$test (.debug_info got also stripped)"
24261 +}
24262 +
24263 +set test "stripping test file functionality"
24264 +if [ regexp ".debug_loc " $strip_output]  {
24265 +    fail "$test (.debug_loc still present)"
24266 +} else {
24267 +    pass "$test (.debug_loc stripped)"
24268 +}
24269 +
24270 +gdb_exit
24271 +gdb_start
24272 +gdb_reinitialize_dir $srcdir/$subdir
24273 +gdb_load ${binfile}
24274 +
24275 +# For C programs, "start" should stop in main().
24276 +
24277 +gdb_test "start" \
24278 +         ".*main \\(\\) at .*" \
24279 +         "start"
24280 +gdb_test "step" \
24281 +         "func.* \\(.*\\) at .*" \
24282 +         "step"
24283 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
24284 new file mode 100644
24285 index 0000000..5fcdd84
24286 --- /dev/null
24287 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
24288 @@ -0,0 +1,83 @@
24289 +/* This testcase is part of GDB, the GNU debugger.
24290 +
24291 +   Copyright 2009 Free Software Foundation, Inc.
24292 +
24293 +   This program is free software; you can redistribute it and/or modify
24294 +   it under the terms of the GNU General Public License as published by
24295 +   the Free Software Foundation; either version 3 of the License, or
24296 +   (at your option) any later version.
24297 +
24298 +   This program is distributed in the hope that it will be useful,
24299 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
24300 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24301 +   GNU General Public License for more details.
24302 +
24303 +   You should have received a copy of the GNU General Public License
24304 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
24305 +
24306 +/* Debug information */
24307 +
24308 +       .section .debug_info
24309 +.Lcu1_begin:
24310 +       /* CU header */
24311 +       .4byte  .Lcu1_end - .Lcu1_start         /* Length of Compilation Unit */
24312 +.Lcu1_start:
24313 +       .2byte  2                               /* DWARF Version */
24314 +       .4byte  .Labbrev1_begin                 /* Offset into abbrev section */
24315 +       .byte   4                               /* Pointer size */
24316 +
24317 +       /* CU die */
24318 +       .uleb128 1                              /* Abbrev: DW_TAG_compile_unit */
24319 +       .ascii  "dw2-struct-member-data-location.c\0"   /* DW_AT_name */
24320 +       .ascii  "GNU C 4.3.2\0"                 /* DW_AT_producer */
24321 +       .byte   1                               /* DW_AT_language (C) */
24322 +
24323 +.Ltype_uchar:
24324 +       .uleb128        2                       /* Abbrev: DW_TAG_structure_type */
24325 +       .ascii          "some_struct\0"         /* DW_AT_name */
24326 +
24327 +       .uleb128        3                       /* Abbrev: DW_TAG_member */
24328 +       .ascii          "field\0"               /* DW_AT_name */
24329 +       .byte           0                       /* DW_AT_data_member_location */
24330 +
24331 +       .byte           0                       /* End of children of some_struct */
24332 +
24333 +       .byte           0                       /* End of children of CU */
24334 +
24335 +.Lcu1_end:
24336 +
24337 +/* Abbrev table */
24338 +       .section .debug_abbrev
24339 +.Labbrev1_begin:
24340 +       .uleb128        1                       /* Abbrev code */
24341 +       .uleb128        0x11                    /* DW_TAG_compile_unit */
24342 +       .byte           1                       /* has_children */
24343 +       .uleb128        0x3                     /* DW_AT_name */
24344 +       .uleb128        0x8                     /* DW_FORM_string */
24345 +       .uleb128        0x25                    /* DW_AT_producer */
24346 +       .uleb128        0x8                     /* DW_FORM_string */
24347 +       .uleb128        0x13                    /* DW_AT_language */
24348 +       .uleb128        0xb                     /* DW_FORM_data1 */
24349 +       .byte           0x0                     /* Terminator */
24350 +       .byte           0x0                     /* Terminator */
24351 +
24352 +       .uleb128        2                       /* Abbrev code */
24353 +       .uleb128        0x13                    /* DW_TAG_structure_type */
24354 +       .byte           1                       /* has_children */
24355 +       .uleb128        0x3                     /* DW_AT_name */
24356 +       .uleb128        0x8                     /* DW_FORM_string */
24357 +       .byte           0x0                     /* Terminator */
24358 +       .byte           0x0                     /* Terminator */
24359 +
24360 +       .uleb128        3                       /* Abbrev code */
24361 +       .uleb128        0x0d                    /* DW_TAG_member */
24362 +       .byte           0                       /* has_children */
24363 +       .uleb128        0x3                     /* DW_AT_name */
24364 +       .uleb128        0x8                     /* DW_FORM_string */
24365 +       .uleb128        0x38                    /* DW_AT_data_member_location */
24366 +       .uleb128        0x0b                    /* DW_FORM_data1 */
24367 +       .byte           0x0                     /* Terminator */
24368 +       .byte           0x0                     /* Terminator */
24369 +
24370 +       .byte           0x0                     /* Terminator */
24371 +       .byte           0x0                     /* Terminator */
24372 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
24373 new file mode 100644
24374 index 0000000..c41151c
24375 --- /dev/null
24376 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
24377 @@ -0,0 +1,37 @@
24378 +# Copyright 2009 Free Software Foundation, Inc.
24379 +
24380 +# This program is free software; you can redistribute it and/or modify
24381 +# it under the terms of the GNU General Public License as published by
24382 +# the Free Software Foundation; either version 3 of the License, or
24383 +# (at your option) any later version.
24384 +#
24385 +# This program is distributed in the hope that it will be useful,
24386 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24387 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24388 +# GNU General Public License for more details.
24389 +#
24390 +# You should have received a copy of the GNU General Public License
24391 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
24392 +
24393 +# This test can only be run on targets which support DWARF-2 and use gas.
24394 +# For now pick a sampling of likely targets.
24395 +if {![istarget *-*-linux*]
24396 +    && ![istarget *-*-gnu*]
24397 +    && ![istarget *-*-elf*]
24398 +    && ![istarget *-*-openbsd*]
24399 +    && ![istarget arm-*-eabi*]
24400 +    && ![istarget powerpc-*-eabi*]} {
24401 +    return 0  
24402 +}
24403 +
24404 +set testfile "dw2-struct-member-data-location"
24405 +set srcfile ${testfile}.S
24406 +set binfile ${testfile}.x
24407 +
24408 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } {
24409 +    return -1
24410 +}
24411 +
24412 +clean_restart $binfile
24413 +
24414 +gdb_test "ptype struct some_struct" "type = struct some_struct {\[\r\n \t\]*void field;\[\r\n \t\]*}"
24415 diff --git a/gdb/testsuite/gdb.fortran/common-block.exp b/gdb/testsuite/gdb.fortran/common-block.exp
24416 new file mode 100644
24417 index 0000000..888f6c3
24418 --- /dev/null
24419 +++ b/gdb/testsuite/gdb.fortran/common-block.exp
24420 @@ -0,0 +1,101 @@
24421 +# Copyright 2008 Free Software Foundation, Inc.
24422 +
24423 +# This program is free software; you can redistribute it and/or modify
24424 +# it under the terms of the GNU General Public License as published by
24425 +# the Free Software Foundation; either version 2 of the License, or
24426 +# (at your option) any later version.
24427 +# 
24428 +# This program is distributed in the hope that it will be useful,
24429 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24430 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24431 +# GNU General Public License for more details.
24432 +# 
24433 +# You should have received a copy of the GNU General Public License
24434 +# along with this program; if not, write to the Free Software
24435 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
24436 +
24437 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
24438 +
24439 +set testfile "common-block"
24440 +set srcfile ${testfile}.f90
24441 +set binfile ${objdir}/${subdir}/${testfile}
24442 +
24443 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
24444 +    untested "Couldn't compile ${srcfile}"
24445 +    return -1
24446 +}
24447 +
24448 +gdb_exit
24449 +gdb_start
24450 +gdb_reinitialize_dir $srcdir/$subdir
24451 +gdb_load ${binfile}
24452 +
24453 +if ![runto MAIN__] then {
24454 +    perror "couldn't run to breakpoint MAIN__"
24455 +    continue
24456 +}
24457 +
24458 +gdb_breakpoint [gdb_get_line_number "stop-here-out"]
24459 +gdb_continue_to_breakpoint "stop-here-out"
24460 +
24461 +# Common block naming with source name /foo/:
24462 +#                .symtab  DW_TAG_common_block's DW_AT_name
24463 +# Intel Fortran  foo_     foo_
24464 +# GNU Fortran    foo_     foo
24465 +#set suffix "_"
24466 +set suffix ""
24467 +
24468 +set int4 {(integer\(kind=4\)|INTEGER\(4\))}
24469 +set real4 {(real\(kind=4\)|REAL\(4\))}
24470 +set real8 {(real\(kind=8\)|REAL\(8\))}
24471 +
24472 +gdb_test "whatis foo$suffix" "No symbol \"foo$suffix\" in current context."
24473 +gdb_test "ptype foo$suffix" "No symbol \"foo$suffix\" in current context."
24474 +gdb_test "p foo$suffix" "No symbol \"foo$suffix\" in current context."
24475 +gdb_test "whatis fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
24476 +gdb_test "ptype fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
24477 +gdb_test "p fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
24478 +
24479 +gdb_test "info locals" "ix_x = 11\r\niy_y = 22\r\niz_z = 33\r\nix = 1\r\niy = 2\r\niz = 3" "info locals out"
24480 +gdb_test "info common" "Contents of F77 COMMON block 'fo_o':\r\nix_x = 11\r\niy_y = 22\r\niz_z = 33\r\n\r\nContents of F77 COMMON block 'foo':\r\nix = 1\r\niy = 2\r\niz = 3" "info common out"
24481 +
24482 +gdb_test "ptype ix" "type = $int4" "ptype ix out"
24483 +gdb_test "ptype iy" "type = $real4" "ptype iy out"
24484 +gdb_test "ptype iz" "type = $real8" "ptype iz out"
24485 +gdb_test "ptype ix_x" "type = $int4" "ptype ix_x out"
24486 +gdb_test "ptype iy_y" "type = $real4" "ptype iy_y out"
24487 +gdb_test "ptype iz_z" "type = $real8" "ptype iz_z out"
24488 +
24489 +gdb_test "p ix" " = 1 *" "p ix out"
24490 +gdb_test "p iy" " = 2 *" "p iy out"
24491 +gdb_test "p iz" " = 3 *" "p iz out"
24492 +gdb_test "p ix_x" " = 11 *" "p ix_x out"
24493 +gdb_test "p iy_y" " = 22 *" "p iy_y out"
24494 +gdb_test "p iz_z" " = 33 *" "p iz_z out"
24495 +
24496 +gdb_breakpoint [gdb_get_line_number "stop-here-in"]
24497 +gdb_continue_to_breakpoint "stop-here-in"
24498 +
24499 +gdb_test "whatis foo$suffix" "No symbol \"foo$suffix\" in current context." "whatis foo$suffix in"
24500 +gdb_test "ptype foo$suffix" "No symbol \"foo$suffix\" in current context." "ptype foo$suffix in"
24501 +gdb_test "p foo$suffix" "No symbol \"foo$suffix\" in current context." "p foo$suffix in"
24502 +gdb_test "whatis fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "whatis fo_o$suffix in"
24503 +gdb_test "ptype fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "ptype fo_o$suffix in"
24504 +gdb_test "p fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "p fo_o$suffix in"
24505 +
24506 +gdb_test "info locals" "ix = 11\r\niy2 = 22\r\niz = 33\r\nix_x = 1\r\niy_y = 2\r\niz_z2 = 3\r\niy = 5\r\niz_z = 55" "info locals in"
24507 +gdb_test "info common" "Contents of F77 COMMON block 'fo_o':\r\nix = 11\r\niy2 = 22\r\niz = 33\r\n\r\nContents of F77 COMMON block 'foo':\r\nix_x = 1\r\niy_y = 2\r\niz_z2 = 3" "info common in"
24508 +
24509 +gdb_test "ptype ix" "type = $int4" "ptype ix in"
24510 +gdb_test "ptype iy2" "type = $real4" "ptype iy2 in"
24511 +gdb_test "ptype iz" "type = $real8" "ptype iz in"
24512 +gdb_test "ptype ix_x" "type = $int4" "ptype ix_x in"
24513 +gdb_test "ptype iy_y" "type = $real4" "ptype iy_y in"
24514 +gdb_test "ptype iz_z2" "type = $real8" "ptype iz_z2 in"
24515 +
24516 +gdb_test "p ix" " = 11 *" "p ix in"
24517 +gdb_test "p iy2" " = 22 *" "p iy2 in"
24518 +gdb_test "p iz" " = 33 *" "p iz in"
24519 +gdb_test "p ix_x" " = 1 *" "p ix_x in"
24520 +gdb_test "p iy_y" " = 2 *" "p iy_y in"
24521 +gdb_test "p iz_z2" " = 3 *" "p iz_z2 in"
24522 diff --git a/gdb/testsuite/gdb.fortran/common-block.f90 b/gdb/testsuite/gdb.fortran/common-block.f90
24523 new file mode 100644
24524 index 0000000..b614e8a
24525 --- /dev/null
24526 +++ b/gdb/testsuite/gdb.fortran/common-block.f90
24527 @@ -0,0 +1,67 @@
24528 +! Copyright 2008 Free Software Foundation, Inc.
24529 +!
24530 +! This program is free software; you can redistribute it and/or modify
24531 +! it under the terms of the GNU General Public License as published by
24532 +! the Free Software Foundation; either version 2 of the License, or
24533 +! (at your option) any later version.
24534 +!
24535 +! This program is distributed in the hope that it will be useful,
24536 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24537 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24538 +! GNU General Public License for more details.
24539 +!
24540 +! You should have received a copy of the GNU General Public License
24541 +! along with this program; if not, write to the Free Software
24542 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24543 +!
24544 +! Ihis file is the Fortran source file for dynamic.exp.
24545 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
24546 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
24547 +
24548 +subroutine in
24549 +
24550 +   INTEGER*4            ix
24551 +   REAL*4               iy2
24552 +   REAL*8               iz
24553 +
24554 +   INTEGER*4            ix_x
24555 +   REAL*4               iy_y
24556 +   REAL*8               iz_z2
24557 +
24558 +   common /fo_o/ix,iy2,iz
24559 +   common /foo/ix_x,iy_y,iz_z2
24560 +
24561 +   iy = 5
24562 +   iz_z = 55
24563 +
24564 +   if (ix .ne. 11 .or. iy2 .ne. 22.0 .or. iz .ne. 33.0) call abort
24565 +   if (ix_x .ne. 1 .or. iy_y .ne. 2.0 .or. iz_z2 .ne. 3.0) call abort
24566 +
24567 +   ix = 0                                      ! stop-here-in
24568 +
24569 +end subroutine in
24570 +
24571 +program common_test
24572 +
24573 +   INTEGER*4            ix
24574 +   REAL*4               iy
24575 +   REAL*8               iz
24576 +
24577 +   INTEGER*4            ix_x
24578 +   REAL*4               iy_y
24579 +   REAL*8               iz_z
24580 +
24581 +   common /foo/ix,iy,iz
24582 +   common /fo_o/ix_x,iy_y,iz_z
24583 +
24584 +   ix = 1
24585 +   iy = 2.0
24586 +   iz = 3.0
24587 +
24588 +   ix_x = 11
24589 +   iy_y = 22.0
24590 +   iz_z = 33.0
24591 +
24592 +   call in                                     ! stop-here-out
24593 +
24594 +end program common_test
24595 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.exp b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
24596 new file mode 100644
24597 index 0000000..cd3486b
24598 --- /dev/null
24599 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
24600 @@ -0,0 +1,42 @@
24601 +# Copyright 2009 Free Software Foundation, Inc.
24602 +
24603 +# This program is free software; you can redistribute it and/or modify
24604 +# it under the terms of the GNU General Public License as published by
24605 +# the Free Software Foundation; either version 2 of the License, or
24606 +# (at your option) any later version.
24607 +# 
24608 +# This program is distributed in the hope that it will be useful,
24609 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24610 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24611 +# GNU General Public License for more details.
24612 +# 
24613 +# You should have received a copy of the GNU General Public License
24614 +# along with this program; if not, write to the Free Software
24615 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
24616 +
24617 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
24618 +
24619 +# This file is part of the gdb testsuite.  Array element stride must not be
24620 +# specified in the number of elements but in a number of bytes instead.
24621 +# Original problem:
24622 +# (gdb) p c40pt(1)
24623 +# $1 = '0-hello', ' ' <repeats 33 times>
24624 +# (gdb) p c40pt(2)
24625 +# warning: Fortran array stride not divisible by the element size
24626 +
24627 +set testfile dwarf-stride
24628 +set srcfile ${testfile}.f90
24629 +
24630 +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f77}] } {
24631 +    return -1
24632 +}
24633 +
24634 +if ![runto MAIN__] then {
24635 +    perror "couldn't run to breakpoint MAIN__"
24636 +    continue
24637 +}
24638 +
24639 +gdb_breakpoint [gdb_get_line_number "break-here"]
24640 +gdb_continue_to_breakpoint "break-here" ".*break-here.*"
24641 +gdb_test "p c40pt(1)" " = '0-hello.*"
24642 +gdb_test "p c40pt(2)" " = '1-hello.*"
24643 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.f90 b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
24644 new file mode 100644
24645 index 0000000..e492b3a
24646 --- /dev/null
24647 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
24648 @@ -0,0 +1,40 @@
24649 +! Copyright 2009 Free Software Foundation, Inc.
24650 +!
24651 +! This program is free software; you can redistribute it and/or modify
24652 +! it under the terms of the GNU General Public License as published by
24653 +! the Free Software Foundation; either version 2 of the License, or
24654 +! (at your option) any later version.
24655 +!
24656 +! This program is distributed in the hope that it will be useful,
24657 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24658 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24659 +! GNU General Public License for more details.
24660 +!
24661 +! You should have received a copy of the GNU General Public License
24662 +! along with this program; if not, write to the Free Software
24663 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24664 +!
24665 +! File written by Alan Matsuoka.
24666 +
24667 +program repro
24668 +
24669 +  type small_stride
24670 +     character*40 long_string
24671 +     integer      small_pad
24672 +  end type small_stride
24673 +
24674 +  type(small_stride), dimension (20), target :: unpleasant
24675 +  character*40, pointer, dimension(:):: c40pt
24676 +
24677 +  integer i
24678 +
24679 +  do i = 0,19
24680 +     unpleasant(i+1)%small_pad = i+1
24681 +     unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello'
24682 +  end do
24683 +
24684 +  c40pt => unpleasant%long_string
24685 +
24686 +  print *, c40pt  ! break-here
24687 +
24688 +end program repro
24689 diff --git a/gdb/testsuite/gdb.fortran/dynamic.exp b/gdb/testsuite/gdb.fortran/dynamic.exp
24690 new file mode 100644
24691 index 0000000..0ccebe0
24692 --- /dev/null
24693 +++ b/gdb/testsuite/gdb.fortran/dynamic.exp
24694 @@ -0,0 +1,145 @@
24695 +# Copyright 2007 Free Software Foundation, Inc.
24696 +
24697 +# This program is free software; you can redistribute it and/or modify
24698 +# it under the terms of the GNU General Public License as published by
24699 +# the Free Software Foundation; either version 2 of the License, or
24700 +# (at your option) any later version.
24701 +# 
24702 +# This program is distributed in the hope that it will be useful,
24703 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24704 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24705 +# GNU General Public License for more details.
24706 +# 
24707 +# You should have received a copy of the GNU General Public License
24708 +# along with this program; if not, write to the Free Software
24709 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
24710 +
24711 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
24712 +
24713 +# This file is part of the gdb testsuite.  It contains tests for dynamically
24714 +# allocated Fortran arrays.
24715 +# It depends on the GCC dynamic Fortran arrays DWARF support:
24716 +#      http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22244
24717 +
24718 +set testfile "dynamic"
24719 +set srcfile ${testfile}.f90
24720 +set binfile ${objdir}/${subdir}/${testfile}
24721 +
24722 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
24723 +    untested "Couldn't compile ${srcfile}"
24724 +    return -1
24725 +}
24726 +
24727 +gdb_exit
24728 +gdb_start
24729 +gdb_reinitialize_dir $srcdir/$subdir
24730 +gdb_load ${binfile}
24731 +
24732 +if ![runto MAIN__] then {
24733 +    perror "couldn't run to breakpoint MAIN__"
24734 +    continue
24735 +}
24736 +
24737 +gdb_breakpoint [gdb_get_line_number "varx-init"]
24738 +gdb_continue_to_breakpoint "varx-init"
24739 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx unallocated"
24740 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx unallocated"
24741 +gdb_test "p varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17) unallocated"
24742 +gdb_test "p varx(1,5,17)=1" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17)=1 unallocated"
24743 +gdb_test "ptype varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "ptype varx(1,5,17) unallocated"
24744 +
24745 +gdb_breakpoint [gdb_get_line_number "varx-allocated"]
24746 +gdb_continue_to_breakpoint "varx-allocated"
24747 +# $1 = (( ( 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0) --- , 0) ) ( ( 0, 0, ...) ...) ...)
24748 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx allocated"
24749 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
24750 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varx allocated"
24751 +
24752 +gdb_breakpoint [gdb_get_line_number "varx-filled"]
24753 +gdb_continue_to_breakpoint "varx-filled"
24754 +gdb_test "p varx(2, 5, 17)" "\\$\[0-9\]* = 6"
24755 +gdb_test "p varx(1, 5, 17)" "\\$\[0-9\]* = 7"
24756 +gdb_test "p varx(2, 6, 18)" "\\$\[0-9\]* = 8"
24757 +gdb_test "p varx(6, 15, 28)" "\\$\[0-9\]* = 9"
24758 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
24759 +gdb_test "p varv" "\\$\[0-9\]* = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "p varv unassociated"
24760 +gdb_test "ptype varv" "type = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "ptype varv unassociated"
24761 +
24762 +gdb_breakpoint [gdb_get_line_number "varv-associated"]
24763 +gdb_continue_to_breakpoint "varv-associated"
24764 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 6" "p varx(3, 7, 19) with varv associated"
24765 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 6" "p varv(3, 7, 19) associated"
24766 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
24767 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varv associated"
24768 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx with varv associated"
24769 +# Intel Fortran Compiler 10.1.008 uses the pointer type.
24770 +gdb_test "ptype varv" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)\\)?" "ptype varv associated"
24771 +
24772 +gdb_breakpoint [gdb_get_line_number "varv-filled"]
24773 +gdb_continue_to_breakpoint "varv-filled"
24774 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 10" "p varx(3, 7, 19) with varv filled"
24775 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 10" "p varv(3, 7, 19) filled"
24776 +
24777 +gdb_breakpoint [gdb_get_line_number "varv-deassociated"]
24778 +gdb_continue_to_breakpoint "varv-deassociated"
24779 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
24780 +gdb_test "p varv" "\\$\[0-9\]* = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "p varv deassociated"
24781 +gdb_test "ptype varv" "type = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "ptype varv deassociated"
24782 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varv deassociated"
24783 +gdb_test "p varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
24784 +gdb_test "ptype varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
24785 +
24786 +gdb_breakpoint [gdb_get_line_number "varx-deallocated"]
24787 +gdb_continue_to_breakpoint "varx-deallocated"
24788 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx deallocated"
24789 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx deallocated"
24790 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varx deallocated"
24791 +gdb_test "p varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17) deallocated"
24792 +gdb_test "ptype varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "ptype varx(1,5,17) deallocated"
24793 +
24794 +gdb_breakpoint [gdb_get_line_number "vary-passed"]
24795 +gdb_continue_to_breakpoint "vary-passed"
24796 +# $1 = (( ( 1, 1, 1, 1, 1, 1) ( 1, 1, 1, 1, 1, 1) --- , 1) ) ( ( 1, 1, ...) ...) ...)
24797 +gdb_test "p vary" "\\$\[0-9\]* = \\(\[()1, .\]*\\)"
24798 +
24799 +gdb_breakpoint [gdb_get_line_number "vary-filled"]
24800 +gdb_continue_to_breakpoint "vary-filled"
24801 +gdb_test "ptype vary" "type = real(\\(kind=4\\)|\\*4) \\(10,10\\)"
24802 +gdb_test "p vary(1, 1)" "\\$\[0-9\]* = 8"
24803 +gdb_test "p vary(2, 2)" "\\$\[0-9\]* = 9"
24804 +gdb_test "p vary(1, 3)" "\\$\[0-9\]* = 10"
24805 +# $1 = (( ( 3, 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3, 3) --- , 3) ) ( ( 3, 3, ...) ...) ...)
24806 +gdb_test "p varw" "\\$\[0-9\]* = \\(\[()3, .\]*\\)"
24807 +
24808 +gdb_breakpoint [gdb_get_line_number "varw-almostfilled"]
24809 +gdb_continue_to_breakpoint "varw-almostfilled"
24810 +gdb_test "ptype varw" "type = real(\\(kind=4\\)|\\*4) \\(5,4,3\\)"
24811 +gdb_test "p varw(3,1,1)=1" "\\$\[0-9\]* = 1"
24812 +# $1 = (( ( 6, 5, 1, 5, 5, 5) ( 5, 5, 5, 5, 5, 5) --- , 5) ) ( ( 5, 5, ...) ...) ...)
24813 +gdb_test "p varw" "\\$\[0-9\]* = \\( *\\( *\\( *6, *5, *1,\[()5, .\]*\\)" "p varw filled"
24814 +# "up" works with GCC but other Fortran compilers may copy the values into the
24815 +# outer function only on the exit of the inner function.
24816 +# We need both variants as depending on the arch we optionally may still be
24817 +# executing the caller line or not after `finish'.
24818 +gdb_test "finish" ".*(call bar \\(y, x\\)|call foo \\(x, z\\(2:6, 4:7, 6:8\\)\\))"
24819 +gdb_test "p z(2,4,5)" "\\$\[0-9\]* = 3"
24820 +gdb_test "p z(2,4,6)" "\\$\[0-9\]* = 6"
24821 +gdb_test "p z(2,4,7)" "\\$\[0-9\]* = 5"
24822 +gdb_test "p z(4,4,6)" "\\$\[0-9\]* = 1"
24823 +
24824 +gdb_breakpoint [gdb_get_line_number "varz-almostfilled"]
24825 +gdb_continue_to_breakpoint "varz-almostfilled"
24826 +# GCC uses the pointer type here, Intel Fortran Compiler 10.1.008 does not.
24827 +gdb_test "ptype varz" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(\\*\\)\\)?"
24828 +# Intel Fortran Compiler 10.1.008 has a bug here - (2:11,7:7)
24829 +# as it produces DW_AT_lower_bound == DW_AT_upper_bound == 7.
24830 +gdb_test "ptype vart" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(2:11,7:\\*\\)\\)?"
24831 +gdb_test "p varz" "\\$\[0-9\]* = \\(\\)"
24832 +gdb_test "p vart" "\\$\[0-9\]* = \\(\\)"
24833 +gdb_test "p varz(3)" "\\$\[0-9\]* = 4"
24834 +# maps to foo::vary(1,1)
24835 +gdb_test "p vart(2,7)" "\\$\[0-9\]* = 8"
24836 +# maps to foo::vary(2,2)
24837 +gdb_test "p vart(3,8)" "\\$\[0-9\]* = 9"
24838 +# maps to foo::vary(1,3)
24839 +gdb_test "p vart(2,9)" "\\$\[0-9\]* = 10"
24840 diff --git a/gdb/testsuite/gdb.fortran/dynamic.f90 b/gdb/testsuite/gdb.fortran/dynamic.f90
24841 new file mode 100644
24842 index 0000000..0f43564
24843 --- /dev/null
24844 +++ b/gdb/testsuite/gdb.fortran/dynamic.f90
24845 @@ -0,0 +1,98 @@
24846 +! Copyright 2007 Free Software Foundation, Inc.
24847 +!
24848 +! This program is free software; you can redistribute it and/or modify
24849 +! it under the terms of the GNU General Public License as published by
24850 +! the Free Software Foundation; either version 2 of the License, or
24851 +! (at your option) any later version.
24852 +!
24853 +! This program is distributed in the hope that it will be useful,
24854 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24855 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24856 +! GNU General Public License for more details.
24857 +!
24858 +! You should have received a copy of the GNU General Public License
24859 +! along with this program; if not, write to the Free Software
24860 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24861 +!
24862 +! Ihis file is the Fortran source file for dynamic.exp.
24863 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
24864 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
24865 +
24866 +subroutine baz
24867 +  real, target, allocatable :: varx (:, :, :)
24868 +  real, pointer :: varv (:, :, :)
24869 +  real, target :: varu (1, 2, 3)
24870 +  logical :: l
24871 +  allocate (varx (1:6, 5:15, 17:28))            ! varx-init
24872 +  l = allocated (varx)
24873 +  varx(:, :, :) = 6                             ! varx-allocated
24874 +  varx(1, 5, 17) = 7
24875 +  varx(2, 6, 18) = 8
24876 +  varx(6, 15, 28) = 9
24877 +  varv => varx                                  ! varx-filled
24878 +  l = associated (varv)
24879 +  varv(3, 7, 19) = 10                           ! varv-associated
24880 +  varv => null ()                               ! varv-filled
24881 +  l = associated (varv)
24882 +  deallocate (varx)                             ! varv-deassociated
24883 +  l = allocated (varx)
24884 +  varu(:, :, :) = 10                            ! varx-deallocated
24885 +  allocate (varv (1:6, 5:15, 17:28))
24886 +  l = associated (varv)
24887 +  varv(:, :, :) = 6
24888 +  varv(1, 5, 17) = 7
24889 +  varv(2, 6, 18) = 8
24890 +  varv(6, 15, 28) = 9
24891 +  deallocate (varv)
24892 +  l = associated (varv)
24893 +  varv => varu
24894 +  varv(1, 1, 1) = 6
24895 +  varv(1, 2, 3) = 7
24896 +  l = associated (varv)
24897 +end subroutine baz
24898 +subroutine foo (vary, varw)
24899 +  real :: vary (:, :)
24900 +  real :: varw (:, :, :)
24901 +  vary(:, :) = 4                                ! vary-passed
24902 +  vary(1, 1) = 8
24903 +  vary(2, 2) = 9
24904 +  vary(1, 3) = 10
24905 +  varw(:, :, :) = 5                             ! vary-filled
24906 +  varw(1, 1, 1) = 6
24907 +  varw(2, 2, 2) = 7                             ! varw-almostfilled
24908 +end subroutine foo
24909 +subroutine bar (varz, vart)
24910 +  real :: varz (*)
24911 +  real :: vart (2:11, 7:*)
24912 +  varz(1:3) = 4
24913 +  varz(2) = 5                                   ! varz-almostfilled
24914 +  vart(2,7) = vart(2,7)
24915 +end subroutine bar
24916 +program test
24917 +  interface
24918 +    subroutine foo (vary, varw)
24919 +    real :: vary (:, :)
24920 +    real :: varw (:, :, :)
24921 +    end subroutine
24922 +  end interface
24923 +  interface
24924 +    subroutine bar (varz, vart)
24925 +    real :: varz (*)
24926 +    real :: vart (2:11, 7:*)
24927 +    end subroutine
24928 +  end interface
24929 +  real :: x (10, 10), y (5), z(8, 8, 8)
24930 +  x(:,:) = 1
24931 +  y(:) = 2
24932 +  z(:,:,:) = 3
24933 +  call baz
24934 +  call foo (x, z(2:6, 4:7, 6:8))
24935 +  call bar (y, x)
24936 +  if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
24937 +  if (x (1, 3) .ne. 10) call abort
24938 +  if (z (2, 4, 6) .ne. 6 .or. z (3, 5, 7) .ne. 7 .or. z (2, 4, 7) .ne. 5) call abort
24939 +  if (any (y .ne. (/4, 5, 4, 2, 2/))) call abort
24940 +  call foo (transpose (x), z)
24941 +  if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
24942 +  if (x (3, 1) .ne. 10) call abort
24943 +end
24944 diff --git a/gdb/testsuite/gdb.fortran/library-module-lib.f90 b/gdb/testsuite/gdb.fortran/library-module-lib.f90
24945 new file mode 100644
24946 index 0000000..6369d34
24947 --- /dev/null
24948 +++ b/gdb/testsuite/gdb.fortran/library-module-lib.f90
24949 @@ -0,0 +1,28 @@
24950 +! Copyright 2009 Free Software Foundation, Inc.
24951 +! 
24952 +! This program is free software; you can redistribute it and/or modify
24953 +! it under the terms of the GNU General Public License as published by
24954 +! the Free Software Foundation; either version 3 of the License, or
24955 +! (at your option) any later version.
24956 +! 
24957 +! This program is distributed in the hope that it will be useful,
24958 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24959 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24960 +! GNU General Public License for more details.
24961 +! 
24962 +! You should have received a copy of the GNU General Public License
24963 +! along with this program.  If not, see <http://www.gnu.org/licenses/>.
24964 +
24965 +module lib
24966 +        integer :: var_i = 1
24967 +contains
24968 +        subroutine lib_func
24969 +        if (var_i .ne. 1) call abort
24970 +        var_i = 2
24971 +        end subroutine lib_func
24972 +end module lib
24973 +
24974 +module libmany
24975 +        integer :: var_j = 3
24976 +        integer :: var_k = 4
24977 +end module libmany
24978 diff --git a/gdb/testsuite/gdb.fortran/library-module-main.f90 b/gdb/testsuite/gdb.fortran/library-module-main.f90
24979 new file mode 100644
24980 index 0000000..de63a65
24981 --- /dev/null
24982 +++ b/gdb/testsuite/gdb.fortran/library-module-main.f90
24983 @@ -0,0 +1,23 @@
24984 +! Copyright 2009 Free Software Foundation, Inc.
24985 +! 
24986 +! This program is free software; you can redistribute it and/or modify
24987 +! it under the terms of the GNU General Public License as published by
24988 +! the Free Software Foundation; either version 3 of the License, or
24989 +! (at your option) any later version.
24990 +! 
24991 +! This program is distributed in the hope that it will be useful,
24992 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24993 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24994 +! GNU General Public License for more details.
24995 +! 
24996 +! You should have received a copy of the GNU General Public License
24997 +! along with this program.  If not, see <http://www.gnu.org/licenses/>.
24998 +
24999 +        use lib
25000 +       use libmany, only: var_j
25001 +        if (var_i .ne. 1) call abort
25002 +       call lib_func
25003 +        if (var_i .ne. 2) call abort
25004 +        if (var_j .ne. 3) call abort
25005 +        var_i = var_i                 ! i-is-2
25006 +end
25007 diff --git a/gdb/testsuite/gdb.fortran/library-module.exp b/gdb/testsuite/gdb.fortran/library-module.exp
25008 new file mode 100644
25009 index 0000000..4b4ea4c
25010 --- /dev/null
25011 +++ b/gdb/testsuite/gdb.fortran/library-module.exp
25012 @@ -0,0 +1,53 @@
25013 +# Copyright 2009 Free Software Foundation, Inc.
25014 +
25015 +# This program is free software; you can redistribute it and/or modify
25016 +# it under the terms of the GNU General Public License as published by
25017 +# the Free Software Foundation; either version 3 of the License, or
25018 +# (at your option) any later version.
25019 +#
25020 +# This program is distributed in the hope that it will be useful,
25021 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25022 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25023 +# GNU General Public License for more details.
25024 +#
25025 +# You should have received a copy of the GNU General Public License
25026 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
25027 +
25028 +set testfile "library-module"
25029 +set srcfile ${testfile}-main.f90
25030 +set srclibfile ${testfile}-lib.f90
25031 +set libfile ${testfile}-lib.so
25032 +set binfile ${testfile}
25033 +
25034 +# Required for -fPIC by gdb_compile_shlib.
25035 +if [get_compiler_info not-used] {
25036 +   warning "Could not get compiler info"
25037 +   return -1
25038 +}
25039 +
25040 +if  { [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfile}" $objdir/$subdir/$libfile {debug f77}] != "" } {
25041 +    untested "Couldn't compile ${srclibfile}"
25042 +    return -1
25043 +}
25044 +
25045 +# prepare_for_testing cannot be used as linking with $libfile cannot be passed
25046 +# just for the linking phase (and not the source compilation phase).  And any
25047 +# warnings on ignored $libfile abort the process.
25048 +
25049 +if  { [gdb_compile [list $srcdir/$subdir/$srcfile $objdir/$subdir/$libfile] $objdir/$subdir/$binfile executable {debug f77}] != "" } {
25050 +    untested "Couldn't compile ${srcfile}"
25051 +    return -1
25052 +}
25053 +
25054 +clean_restart $binfile
25055 +
25056 +if ![runto MAIN__] then {
25057 +    perror "couldn't run to breakpoint MAIN__"
25058 +    continue
25059 +}
25060 +
25061 +gdb_breakpoint [gdb_get_line_number "i-is-2"]
25062 +gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
25063 +gdb_test "print var_i" " = 2"
25064 +gdb_test "print var_j" " = 3"
25065 +gdb_test "print var_k" "No symbol \"var_k\" in current context\\."
25066 diff --git a/gdb/testsuite/gdb.fortran/logical.exp b/gdb/testsuite/gdb.fortran/logical.exp
25067 new file mode 100644
25068 index 0000000..ef76f43
25069 --- /dev/null
25070 +++ b/gdb/testsuite/gdb.fortran/logical.exp
25071 @@ -0,0 +1,44 @@
25072 +# Copyright 2007 Free Software Foundation, Inc.
25073 +
25074 +# This program is free software; you can redistribute it and/or modify
25075 +# it under the terms of the GNU General Public License as published by
25076 +# the Free Software Foundation; either version 2 of the License, or
25077 +# (at your option) any later version.
25078 +# 
25079 +# This program is distributed in the hope that it will be useful,
25080 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25081 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25082 +# GNU General Public License for more details.
25083 +# 
25084 +# You should have received a copy of the GNU General Public License
25085 +# along with this program; if not, write to the Free Software
25086 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
25087 +
25088 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
25089 +
25090 +set testfile "logical"
25091 +set srcfile ${testfile}.f90
25092 +set binfile ${objdir}/${subdir}/${testfile}
25093 +
25094 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
25095 +    untested "Couldn't compile ${srcfile}"
25096 +    return -1
25097 +}
25098 +
25099 +gdb_exit
25100 +gdb_start
25101 +gdb_reinitialize_dir $srcdir/$subdir
25102 +gdb_load ${binfile}
25103 +
25104 +if ![runto MAIN__] then {
25105 +    perror "couldn't run to breakpoint MAIN__"
25106 +    continue
25107 +}
25108 +
25109 +gdb_breakpoint [gdb_get_line_number "stop-here"]
25110 +gdb_continue_to_breakpoint "stop-here"
25111 +gdb_test "p l" " = \\.TRUE\\."
25112 +gdb_test "p l1" " = \\.TRUE\\."
25113 +gdb_test "p l2" " = \\.TRUE\\."
25114 +gdb_test "p l4" " = \\.TRUE\\."
25115 +gdb_test "p l8" " = \\.TRUE\\."
25116 diff --git a/gdb/testsuite/gdb.fortran/logical.f90 b/gdb/testsuite/gdb.fortran/logical.f90
25117 new file mode 100644
25118 index 0000000..4229304
25119 --- /dev/null
25120 +++ b/gdb/testsuite/gdb.fortran/logical.f90
25121 @@ -0,0 +1,33 @@
25122 +! Copyright 2008 Free Software Foundation, Inc.
25123 +!
25124 +! This program is free software; you can redistribute it and/or modify
25125 +! it under the terms of the GNU General Public License as published by
25126 +! the Free Software Foundation; either version 2 of the License, or
25127 +! (at your option) any later version.
25128 +!
25129 +! This program is distributed in the hope that it will be useful,
25130 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25131 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25132 +! GNU General Public License for more details.
25133 +!
25134 +! You should have received a copy of the GNU General Public License
25135 +! along with this program; if not, write to the Free Software
25136 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25137 +!
25138 +! Ihis file is the Fortran source file for dynamic.exp.
25139 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
25140 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
25141 +
25142 +program test
25143 +  logical :: l
25144 +  logical (kind=1) :: l1
25145 +  logical (kind=2) :: l2
25146 +  logical (kind=4) :: l4
25147 +  logical (kind=8) :: l8
25148 +  l = .TRUE.
25149 +  l1 = .TRUE.
25150 +  l2 = .TRUE.
25151 +  l4 = .TRUE.
25152 +  l8 = .TRUE.
25153 +  l = .FALSE.                                  ! stop-here
25154 +end
25155 diff --git a/gdb/testsuite/gdb.fortran/module.exp b/gdb/testsuite/gdb.fortran/module.exp
25156 index 342ccee..c836c3c 100644
25157 --- a/gdb/testsuite/gdb.fortran/module.exp
25158 +++ b/gdb/testsuite/gdb.fortran/module.exp
25159 @@ -15,21 +15,31 @@
25160  
25161  set testfile "module"
25162  set srcfile ${testfile}.f90
25163 -set binfile ${objdir}/${subdir}/${testfile}
25164  
25165 -if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
25166 -    untested "Couldn't compile ${srcfile}"
25167 +if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug f77}] } {
25168      return -1
25169  }
25170  
25171 -gdb_exit
25172 -gdb_start
25173 -gdb_reinitialize_dir $srcdir/$subdir
25174 -gdb_load ${binfile}
25175 -
25176  if ![runto MAIN__] then {
25177      perror "couldn't run to breakpoint MAIN__"
25178      continue
25179  }
25180  
25181 -gdb_test "print i" " = 42"
25182 +# Do not use simple single-letter names as GDB would pick up for expectedly
25183 +# nonexisting symbols some static variables from system libraries debuginfos.
25184 +
25185 +gdb_breakpoint [gdb_get_line_number "i-is-1"]
25186 +gdb_continue_to_breakpoint "i-is-1" ".*i-is-1.*"
25187 +gdb_test "print var_i" " = 1" "print var_i value 1"
25188 +
25189 +gdb_breakpoint [gdb_get_line_number "i-is-2"]
25190 +gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
25191 +gdb_test "print var_i" " = 2" "print var_i value 2"
25192 +
25193 +gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
25194 +gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
25195 +gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
25196 +gdb_test "print var_b" " = 11"
25197 +gdb_test "print var_c" "No symbol \"var_c\" in current context\\."
25198 +gdb_test "print var_d" " = 12"
25199 +gdb_test "print var_i" " = 14" "print var_i value 14"
25200 diff --git a/gdb/testsuite/gdb.fortran/module.f90 b/gdb/testsuite/gdb.fortran/module.f90
25201 index 501ccc8..118931d 100644
25202 --- a/gdb/testsuite/gdb.fortran/module.f90
25203 +++ b/gdb/testsuite/gdb.fortran/module.f90
25204 @@ -13,10 +13,37 @@
25205  ! You should have received a copy of the GNU General Public License
25206  ! along with this program.  If not, see <http://www.gnu.org/licenses/>.
25207  
25208 -module mod
25209 -        integer :: i = 42
25210 -end module mod
25211 +module mod1
25212 +        integer :: var_i = 1
25213 +end module mod1
25214  
25215 -        use mod
25216 -        print *, i
25217 +module mod2
25218 +        integer :: var_i = 2
25219 +end module mod2
25220 +
25221 +module modmany
25222 +        integer :: var_a = 10, var_b = 11, var_c = 12, var_i = 14
25223 +end module modmany
25224 +
25225 +        subroutine sub1
25226 +        use mod1
25227 +        if (var_i .ne. 1) call abort
25228 +        var_i = var_i                         ! i-is-1
25229 +        end
25230 +
25231 +        subroutine sub2
25232 +        use mod2
25233 +        if (var_i .ne. 2) call abort
25234 +        var_i = var_i                         ! i-is-2
25235 +        end
25236 +
25237 +        use modmany, only: var_b, var_d => var_c, var_i
25238 +
25239 +        call sub1
25240 +        call sub2
25241 +
25242 +        if (var_b .ne. 11) call abort
25243 +        if (var_d .ne. 12) call abort
25244 +        if (var_i .ne. 14) call abort
25245 +        var_b = var_b                         ! a-b-c-d
25246  end
25247 diff --git a/gdb/testsuite/gdb.fortran/string.exp b/gdb/testsuite/gdb.fortran/string.exp
25248 new file mode 100644
25249 index 0000000..b1120c3
25250 --- /dev/null
25251 +++ b/gdb/testsuite/gdb.fortran/string.exp
25252 @@ -0,0 +1,59 @@
25253 +# Copyright 2008 Free Software Foundation, Inc.
25254 +
25255 +# This program is free software; you can redistribute it and/or modify
25256 +# it under the terms of the GNU General Public License as published by
25257 +# the Free Software Foundation; either version 2 of the License, or
25258 +# (at your option) any later version.
25259 +# 
25260 +# This program is distributed in the hope that it will be useful,
25261 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25262 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25263 +# GNU General Public License for more details.
25264 +# 
25265 +# You should have received a copy of the GNU General Public License
25266 +# along with this program; if not, write to the Free Software
25267 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
25268 +
25269 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
25270 +
25271 +# This file is part of the gdb testsuite.  It contains tests for Fortran
25272 +# strings with dynamic length.
25273 +
25274 +set testfile "string"
25275 +set srcfile ${testfile}.f90
25276 +set binfile ${objdir}/${subdir}/${testfile}
25277 +
25278 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
25279 +    untested "Couldn't compile ${srcfile}"
25280 +    return -1
25281 +}
25282 +
25283 +gdb_exit
25284 +gdb_start
25285 +gdb_reinitialize_dir $srcdir/$subdir
25286 +gdb_load ${binfile}
25287 +
25288 +if ![runto MAIN__] then {
25289 +    perror "couldn't run to breakpoint MAIN__"
25290 +    continue
25291 +}
25292 +
25293 +gdb_breakpoint [gdb_get_line_number "var-init"]
25294 +gdb_continue_to_breakpoint "var-init"
25295 +gdb_test "ptype c" "type = character(\\(kind=1\\)|\\*1)"
25296 +gdb_test "ptype d" "type = character(\\(kind=8\\)|\\*8)"
25297 +gdb_test "ptype e" "type = character(\\(kind=4\\)|\\*4)"
25298 +gdb_test "ptype f" "type = character(\\(kind=4\\)|\\*4) \\(7,8:10\\)"
25299 +gdb_test "ptype *e" "Attempt to take contents of a non-pointer value."
25300 +gdb_test "ptype *f" "type = character(\\(kind=4\\)|\\*4) \\(7\\)"
25301 +gdb_test "p c" "\\$\[0-9\]* = 'c'"
25302 +gdb_test "p d" "\\$\[0-9\]* = 'd       '"
25303 +gdb_test "p e" "\\$\[0-9\]* = 'g   '"
25304 +gdb_test "p f" "\\$\[0-9\]* = \\(\\( 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   '\\) \\( 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   '\\) \\( 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   '\\) \\)"
25305 +gdb_test "p *e" "Attempt to take contents of a non-pointer value."
25306 +gdb_test "p *f" "Attempt to take contents of a non-pointer value."
25307 +
25308 +gdb_breakpoint [gdb_get_line_number "var-finish"]
25309 +gdb_continue_to_breakpoint "var-finish"
25310 +gdb_test "p e" "\\$\[0-9\]* = 'e   '" "p e re-set"
25311 +gdb_test "p f" "\\$\[0-9\]* = \\(\\( 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   '\\) \\( 'f2  ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   '\\) \\( 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   '\\) \\)" "p *f re-set"
25312 diff --git a/gdb/testsuite/gdb.fortran/string.f90 b/gdb/testsuite/gdb.fortran/string.f90
25313 new file mode 100644
25314 index 0000000..226dc5d
25315 --- /dev/null
25316 +++ b/gdb/testsuite/gdb.fortran/string.f90
25317 @@ -0,0 +1,37 @@
25318 +! Copyright 2008 Free Software Foundation, Inc.
25319 +!
25320 +! This program is free software; you can redistribute it and/or modify
25321 +! it under the terms of the GNU General Public License as published by
25322 +! the Free Software Foundation; either version 2 of the License, or
25323 +! (at your option) any later version.
25324 +!
25325 +! This program is distributed in the hope that it will be useful,
25326 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25327 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25328 +! GNU General Public License for more details.
25329 +!
25330 +! You should have received a copy of the GNU General Public License
25331 +! along with this program; if not, write to the Free Software
25332 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25333 +!
25334 +! Ihis file is the Fortran source file for dynamic.exp.
25335 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
25336 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
25337 +
25338 +subroutine foo (e, f)
25339 +  character (len=1) :: c
25340 +  character (len=8) :: d
25341 +  character (len=*) :: e
25342 +  character (len=*) :: f (1:7, 8:10)
25343 +  c = 'c'
25344 +  d = 'd'
25345 +  e = 'e'                                       ! var-init
25346 +  f = 'f'
25347 +  f(1,9) = 'f2'
25348 +  c = 'c'                                       ! var-finish
25349 +end subroutine foo
25350 +  character (len=4) :: g, h (1:7, 8:10)
25351 +  g = 'g'
25352 +  h = 'h'
25353 +  call foo (g, h)
25354 +end
25355 diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
25356 index 495ae45..d08d7a4 100644
25357 --- a/gdb/testsuite/gdb.gdb/selftest.exp
25358 +++ b/gdb/testsuite/gdb.gdb/selftest.exp
25359 @@ -95,6 +95,10 @@ proc do_steps_and_nexts {} {
25360                 set description "step over ttyarg initialization"
25361                 set command "step"
25362             }
25363 +           -re ".*python_script = 0.*$gdb_prompt $" {
25364 +               set description "step over python_script initialization"
25365 +               set command "step"
25366 +           }
25367             -re ".*time_at_startup = get_run_time.*$gdb_prompt $" {
25368                 set description "next over get_run_time and everything it calls"
25369                 set command "next"
25370 diff --git a/gdb/testsuite/gdb.java/jnpe.exp b/gdb/testsuite/gdb.java/jnpe.exp
25371 new file mode 100644
25372 index 0000000..74d4d58
25373 --- /dev/null
25374 +++ b/gdb/testsuite/gdb.java/jnpe.exp
25375 @@ -0,0 +1,72 @@
25376 +# Copyright 2009 Free Software Foundation, Inc.
25377 +
25378 +# This program is free software; you can redistribute it and/or modify
25379 +# it under the terms of the GNU General Public License as published by
25380 +# the Free Software Foundation; either version 3 of the License, or
25381 +# (at your option) any later version.
25382 +#
25383 +# This program is distributed in the hope that it will be useful,
25384 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25385 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25386 +# GNU General Public License for more details.
25387 +#
25388 +# You should have received a copy of the GNU General Public License
25389 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
25390 +
25391 +if $tracelevel then {
25392 +  strace $tracelevel
25393 +}
25394 +
25395 +load_lib "java.exp"
25396 +
25397 +set testfile "jnpe"
25398 +set srcfile ${srcdir}/$subdir/${testfile}.java
25399 +set binfile ${objdir}/${subdir}/${testfile}
25400 +if  { [compile_java_from_source ${srcfile} ${binfile} "-g"] != "" } {
25401 +    untested "Couldn't compile ${srcfile}"
25402 +    return -1
25403 +}
25404 +
25405 +set prms_id 0
25406 +set bug_id 0
25407 +
25408 +# Start with a fresh gdb.
25409 +
25410 +gdb_exit
25411 +gdb_start
25412 +gdb_reinitialize_dir $srcdir/$subdir
25413 +gdb_load ${binfile}
25414 +
25415 +set line [gdb_get_line_number "break here" $testfile.java]
25416 +gdb_test "break $testfile.java:$line" ""
25417 +
25418 +gdb_test "run" \
25419 +  "Current language.*java" \
25420 +  "run java next-over-throw"
25421 +
25422 +# See whether we have the needed unwinder hooks.
25423 +set ok 1
25424 +gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook in java" {
25425 +    -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
25426 +       pass "check for unwinder hook in java"
25427 +    }
25428 +    -re "No symbol .* in current context.\r\n$gdb_prompt $" {
25429 +       # Pass the test so we don't get bogus fails in the results.
25430 +       pass "check for unwinder hook in java"
25431 +       set ok 0
25432 +    }
25433 +}
25434 +if {!$ok} {
25435 +    untested jnpe.exp
25436 +    return -1
25437 +}
25438 +
25439 +gdb_test "handle SIGSEGV nostop noprint" \
25440 +  "SIGSEGV.*fault" \
25441 +  "disable SIGSEGV for next-over-NPE"
25442 +
25443 +# We sometimes stop at line 37, not line 35.  This seems to be a gcj
25444 +# oddity -- another next will solve it.
25445 +gdb_test "next" \
25446 +  "3\[57\].*" \
25447 +  "next over NPE"
25448 diff --git a/gdb/testsuite/gdb.java/jnpe.java b/gdb/testsuite/gdb.java/jnpe.java
25449 new file mode 100644
25450 index 0000000..ffca3ab
25451 --- /dev/null
25452 +++ b/gdb/testsuite/gdb.java/jnpe.java
25453 @@ -0,0 +1,38 @@
25454 +// Test next-over-NPE.
25455 +/* This testcase is part of GDB, the GNU debugger.
25456 +
25457 +   Copyright 2009 Free Software Foundation, Inc.
25458 +
25459 +   This program is free software; you can redistribute it and/or modify
25460 +   it under the terms of the GNU General Public License as published by
25461 +   the Free Software Foundation; either version 3 of the License, or
25462 +   (at your option) any later version.
25463 +
25464 +   This program is distributed in the hope that it will be useful,
25465 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
25466 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25467 +   GNU General Public License for more details.
25468 +
25469 +   You should have received a copy of the GNU General Public License
25470 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.
25471 +   */
25472 +
25473 +public class jnpe
25474 +{
25475 +  public static String npe ()
25476 +  {
25477 +    return ((Object) null).toString();
25478 +  }
25479 +
25480 +  public static void main (String[] args)
25481 +  {
25482 +    try
25483 +      {
25484 +       System.out.println (npe ()); // break here
25485 +      }
25486 +    catch (NullPointerException n)
25487 +      {
25488 +       System.out.println ("success");
25489 +      }
25490 +  }
25491 +}
25492 diff --git a/gdb/testsuite/gdb.opt/array-from-register-func.c b/gdb/testsuite/gdb.opt/array-from-register-func.c
25493 new file mode 100644
25494 index 0000000..729f457
25495 --- /dev/null
25496 +++ b/gdb/testsuite/gdb.opt/array-from-register-func.c
25497 @@ -0,0 +1,22 @@
25498 +/* This file is part of GDB, the GNU debugger.
25499 +
25500 +   Copyright 2009 Free Software Foundation, Inc.
25501 +
25502 +   This program is free software; you can redistribute it and/or modify
25503 +   it under the terms of the GNU General Public License as published by
25504 +   the Free Software Foundation; either version 3 of the License, or
25505 +   (at your option) any later version.
25506 +
25507 +   This program is distributed in the hope that it will be useful,
25508 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
25509 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25510 +   GNU General Public License for more details.
25511 +
25512 +   You should have received a copy of the GNU General Public License
25513 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
25514 +
25515 +int
25516 +func (int *arr)
25517 +{
25518 +  return arr[0];
25519 +}
25520 diff --git a/gdb/testsuite/gdb.opt/array-from-register.c b/gdb/testsuite/gdb.opt/array-from-register.c
25521 new file mode 100644
25522 index 0000000..3090e7e
25523 --- /dev/null
25524 +++ b/gdb/testsuite/gdb.opt/array-from-register.c
25525 @@ -0,0 +1,28 @@
25526 +/* This file is part of GDB, the GNU debugger.
25527 +
25528 +   Copyright 2009 Free Software Foundation, Inc.
25529 +
25530 +   This program is free software; you can redistribute it and/or modify
25531 +   it under the terms of the GNU General Public License as published by
25532 +   the Free Software Foundation; either version 3 of the License, or
25533 +   (at your option) any later version.
25534 +
25535 +   This program is distributed in the hope that it will be useful,
25536 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
25537 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25538 +   GNU General Public License for more details.
25539 +
25540 +   You should have received a copy of the GNU General Public License
25541 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
25542 +
25543 +extern int func (int *arr);
25544 +
25545 +int
25546 +main (void)
25547 +{
25548 +  int arr[] = { 42 };
25549 +
25550 +  func (arr);
25551 +
25552 +  return 0;
25553 +}
25554 diff --git a/gdb/testsuite/gdb.opt/array-from-register.exp b/gdb/testsuite/gdb.opt/array-from-register.exp
25555 new file mode 100644
25556 index 0000000..f2de718
25557 --- /dev/null
25558 +++ b/gdb/testsuite/gdb.opt/array-from-register.exp
25559 @@ -0,0 +1,33 @@
25560 +# Copyright 2009 Free Software Foundation, Inc.
25561 +#
25562 +# This program is free software; you can redistribute it and/or modify
25563 +# it under the terms of the GNU General Public License as published by
25564 +# the Free Software Foundation; either version 2 of the License, or
25565 +# (at your option) any later version.
25566 +#
25567 +# This program is distributed in the hope that it will be useful,
25568 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25569 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25570 +# GNU General Public License for more details.
25571 +#
25572 +# You should have received a copy of the GNU General Public License
25573 +# along with this program; if not, write to the Free Software
25574 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25575 +#
25576 +# This file is part of the gdb testsuite.
25577 +
25578 +if { [prepare_for_testing array-from-register.exp "array-from-register"      \
25579 +                         {array-from-register.c array-from-register-func.c} \
25580 +                         {debug optimize=-O2}] } {
25581 +    return -1
25582 +}
25583 +
25584 +if ![runto func] then {
25585 +    return -1
25586 +}
25587 +
25588 +gdb_test "p arr" "\\$\[0-9\]+ = \\(int \\*\\) *0x\[0-9a-f\]+"
25589 +
25590 +# Seen regression:
25591 +# Address requested for identifier "arr" which is in register $rdi
25592 +gdb_test "p arr\[0\]" "\\$\[0-9\]+ = 42"
25593 diff --git a/gdb/testsuite/gdb.opt/fortran-string.exp b/gdb/testsuite/gdb.opt/fortran-string.exp
25594 new file mode 100644
25595 index 0000000..f997eec
25596 --- /dev/null
25597 +++ b/gdb/testsuite/gdb.opt/fortran-string.exp
25598 @@ -0,0 +1,41 @@
25599 +# Copyright 2009 Free Software Foundation, Inc.
25600 +
25601 +# This program is free software; you can redistribute it and/or modify
25602 +# it under the terms of the GNU General Public License as published by
25603 +# the Free Software Foundation; either version 2 of the License, or
25604 +# (at your option) any later version.
25605 +# 
25606 +# This program is distributed in the hope that it will be useful,
25607 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25608 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25609 +# GNU General Public License for more details.
25610 +# 
25611 +# You should have received a copy of the GNU General Public License
25612 +# along with this program; if not, write to the Free Software
25613 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
25614 +
25615 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
25616 +
25617 +# Test GDB can cope with Fortran strings having their length present in a CPU
25618 +# register.  With -O0 the string length is passed on the stack.  To make this
25619 +# test meaningful the follow assertion should pass.  It is not being checked
25620 +# here as the "_s" symbol is compiler dependent:
25621 +#   (gdb) info address _s
25622 +#   Symbol "_s" is a variable in register XX.
25623 +
25624 +set test fortran-string
25625 +set srcfile ${test}.f90
25626 +if { [prepare_for_testing ${test}.exp ${test} ${srcfile} {debug f77 additional_flags=-O2}] } {
25627 +    return -1
25628 +}
25629 +
25630 +if ![runto MAIN__] then {
25631 +    perror "couldn't run to breakpoint MAIN__"
25632 +    continue
25633 +}
25634 +
25635 +gdb_breakpoint [gdb_get_line_number "s = s"]
25636 +gdb_continue_to_breakpoint "s = s"
25637 +gdb_test "frame" ".*s='foo'.*"
25638 +gdb_test "ptype s" "type = character\\*3"
25639 +gdb_test "p s" "\\$\[0-9\]* = 'foo'"
25640 diff --git a/gdb/testsuite/gdb.opt/fortran-string.f90 b/gdb/testsuite/gdb.opt/fortran-string.f90
25641 new file mode 100644
25642 index 0000000..e48d520
25643 --- /dev/null
25644 +++ b/gdb/testsuite/gdb.opt/fortran-string.f90
25645 @@ -0,0 +1,28 @@
25646 +! Copyright 2009 Free Software Foundation, Inc.
25647 +!
25648 +! This program is free software; you can redistribute it and/or modify
25649 +! it under the terms of the GNU General Public License as published by
25650 +! the Free Software Foundation; either version 2 of the License, or
25651 +! (at your option) any later version.
25652 +!
25653 +! This program is distributed in the hope that it will be useful,
25654 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25655 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25656 +! GNU General Public License for more details.
25657 +!
25658 +! You should have received a copy of the GNU General Public License
25659 +! along with this program; if not, write to the Free Software
25660 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25661 +!
25662 +! Ihis file is the Fortran source file for dynamic.exp.
25663 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
25664 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
25665 +
25666 +  subroutine f(s)
25667 +  character*(*) s
25668 +  s = s
25669 +  end
25670 +
25671 +  program main
25672 +  call f ('foo')
25673 +  end
25674 diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp
25675 index f6ef938..1032a2d 100644
25676 --- a/gdb/testsuite/gdb.python/py-cmd.exp
25677 +++ b/gdb/testsuite/gdb.python/py-cmd.exp
25678 @@ -20,36 +20,15 @@ if $tracelevel then {
25679      strace $tracelevel
25680  }
25681  
25682 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
25683 -# Run a test named NAME, consisting of multiple lines of input.
25684 -# After each input line INPUT, search for result line RESULT.
25685 -# Succeed if all results are seen; fail otherwise.
25686 -proc gdb_py_test_multiple {name args} {
25687 -    global gdb_prompt
25688 -    foreach {input result} $args {
25689 -       if {[gdb_test_multiple $input "$name - $input" {
25690 -           -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
25691 -               pass "$name - $input"
25692 -           }
25693 -       }]} {
25694 -           return 1
25695 -       }
25696 -    }
25697 -    return 0
25698 -}
25699 -
25700  # Start with a fresh gdb.
25701  
25702  gdb_exit
25703  gdb_start
25704  gdb_reinitialize_dir $srcdir/$subdir
25705  
25706 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
25707 -    -re "not supported.*$gdb_prompt $" {
25708 -      unsupported "python support is disabled"
25709 -      return -1
25710 -    }
25711 -    -re "$gdb_prompt $"        {}
25712 +if ![python_supported] then {
25713 +  unsupported "python support is disabled"
25714 +  return -1
25715  }
25716  
25717  # Test a simple command.
25718 diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
25719 index a67eaa3..5380c0f 100644
25720 --- a/gdb/testsuite/gdb.python/py-frame.exp
25721 +++ b/gdb/testsuite/gdb.python/py-frame.exp
25722 @@ -20,40 +20,28 @@ if $tracelevel then {
25723      strace $tracelevel
25724  }
25725  
25726 +# Start with a fresh gdb.
25727 +
25728 +gdb_exit
25729 +gdb_start
25730 +gdb_reinitialize_dir $srcdir/$subdir
25731 +
25732 +if ![python_supported] then {
25733 +  unsupported "python support is disabled"
25734 +  return -1
25735 +}
25736 +
25737  set testfile "py-frame"
25738  set srcfile ${testfile}.c
25739  set binfile ${objdir}/${subdir}/${testfile}
25740 +
25741  if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
25742      untested "Couldn't compile ${srcfile}"
25743      return -1
25744  }
25745  
25746 -# Run a command in GDB, and report a failure if a Python exception is thrown.
25747 -# If report_pass is true, report a pass if no exception is thrown.
25748 -proc gdb_py_test_silent_cmd {cmd name report_pass} {
25749 -  global gdb_prompt
25750 -
25751 -  gdb_test_multiple $cmd $name {
25752 -      -re "Traceback.*$gdb_prompt $"  { fail $name }
25753 -      -re "$gdb_prompt $"            { if $report_pass { pass $name } }
25754 -  }
25755 -}
25756 -
25757 -# Start with a fresh gdb.
25758 -
25759 -gdb_exit
25760 -gdb_start
25761 -gdb_reinitialize_dir $srcdir/$subdir
25762  gdb_load ${binfile}
25763  
25764 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
25765 -    -re "not supported.*$gdb_prompt $" {
25766 -      unsupported "python support is disabled"
25767 -      return -1
25768 -    }
25769 -    -re "$gdb_prompt $"        {}
25770 -}
25771 -
25772  # The following tests require execution.
25773  
25774  if ![runto_main] then {
25775 @@ -65,19 +53,20 @@ gdb_breakpoint "f2"
25776  gdb_continue_to_breakpoint "breakpoint at f2"
25777  gdb_test "up" "" ""
25778  
25779 -gdb_py_test_silent_cmd "python f1 = gdb.selected_frame ()" "get second frame" 0
25780 -gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
25781 +gdb_py_test_silent_cmd "python frames = gdb.selected_thread ().frames ()" "get frames list" 1
25782 +gdb_test "python print frames" "\\(<gdb.Frame object at 0x\[\[:xdigit:\]\]+>, <gdb.Frame object at 0x\[\[:xdigit:\]\]+>, <gdb.Frame object at 0x\[\[:xdigit:\]\]+>\\)" "verify frames list"
25783 +gdb_py_test_silent_cmd "python f0 = frames\[0\]" "get first frame" 0
25784 +gdb_py_test_silent_cmd "python f1 = frames\[1\]" "get second frame" 0
25785  
25786  gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
25787  gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
25788 -gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
25789 -gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
25790  gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
25791  gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
25792  gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"
25793  gdb_test "python print 'result =', f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON" " = True" "test Frame.type"
25794  gdb_test "python print 'result =', gdb.frame_stop_reason_string (gdb.FRAME_UNWIND_INNER_ID)" " = previous frame inner to this frame \\(corrupt stack\\?\\)" "test gdb.frame_stop_reason_string"
25795  gdb_test "python print 'result =', f0.pc ()" " = \[0-9\]+" "test Frame.pc"
25796 +gdb_test "python print 'result =', f0.function ()" " = symbol for f2" "test Frame.function"
25797  gdb_test "python print 'result =', f0.older () == f1" " = True" "test Frame.older"
25798  gdb_test "python print 'result =', f1.newer () == f0" " = True" "test Frame.newer"
25799  gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_exist')" \
25800 @@ -85,4 +74,7 @@ gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_ex
25801    "test Frame.read_var - error"
25802  gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"
25803  
25804 +gdb_test "python print 'result =', gdb.selected_thread ().newest_frame () == f0" " = True" "test gdb.newest_frame"
25805  gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame"
25806 +
25807 +gdb_test "python print 'result =', f0.block ()" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
25808 diff --git a/gdb/testsuite/gdb.python/py-function.exp b/gdb/testsuite/gdb.python/py-function.exp
25809 index 30fde7d..14cd90c 100644
25810 --- a/gdb/testsuite/gdb.python/py-function.exp
25811 +++ b/gdb/testsuite/gdb.python/py-function.exp
25812 @@ -20,36 +20,15 @@ if $tracelevel then {
25813      strace $tracelevel
25814  }
25815  
25816 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
25817 -# Run a test named NAME, consisting of multiple lines of input.
25818 -# After each input line INPUT, search for result line RESULT.
25819 -# Succeed if all results are seen; fail otherwise.
25820 -proc gdb_py_test_multiple {name args} {
25821 -    global gdb_prompt
25822 -    foreach {input result} $args {
25823 -       if {[gdb_test_multiple $input "$name - $input" {
25824 -           -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
25825 -               pass "$name - $input"
25826 -           }
25827 -       }]} {
25828 -           return 1
25829 -       }
25830 -    }
25831 -    return 0
25832 -}
25833 -
25834  # Start with a fresh gdb.
25835  
25836  gdb_exit
25837  gdb_start
25838  gdb_reinitialize_dir $srcdir/$subdir
25839  
25840 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
25841 -    -re "not supported.*$gdb_prompt $" {
25842 -      unsupported "python support is disabled"
25843 -      return -1
25844 -    }
25845 -    -re "$gdb_prompt $"        {}
25846 +if ![python_supported] then {
25847 +  unsupported "python support is disabled"
25848 +  return -1
25849  }
25850  
25851  gdb_py_test_multiple "input convenience function" \
25852 diff --git a/gdb/testsuite/gdb.python/py-inferior.c b/gdb/testsuite/gdb.python/py-inferior.c
25853 new file mode 100644
25854 index 0000000..0b48299
25855 --- /dev/null
25856 +++ b/gdb/testsuite/gdb.python/py-inferior.c
25857 @@ -0,0 +1,49 @@
25858 +#include <stdio.h>
25859 +#include <stdlib.h>
25860 +#include <stdint.h>
25861 +#include <string.h>
25862 +
25863 +#define CHUNK_SIZE 16000 /* same as findcmd.c's */
25864 +#define BUF_SIZE (2 * CHUNK_SIZE) /* at least two chunks */
25865 +
25866 +static int8_t int8_search_buf[100];
25867 +static int16_t int16_search_buf[100];
25868 +static int32_t int32_search_buf[100];
25869 +static int64_t int64_search_buf[100];
25870 +
25871 +static char *search_buf;
25872 +static int search_buf_size;
25873 +
25874 +static int x;
25875 +
25876 +
25877 +int f2 (int a)
25878 +{
25879 +  char *str = "hello, testsuite";
25880 +
25881 +  puts (str);  /* Break here.  */
25882 +
25883 +  return ++a;
25884 +}
25885 +
25886 +int f1 (int a, int b)
25887 +{
25888 +  return f2(a) + b;
25889 +}
25890 +
25891 +static void
25892 +init_bufs ()
25893 +{
25894 +  search_buf_size = BUF_SIZE;
25895 +  search_buf = malloc (search_buf_size);
25896 +  if (search_buf == NULL)
25897 +    exit (1);
25898 +  memset (search_buf, 'x', search_buf_size);
25899 +}
25900 +
25901 +int main (int argc, char *argv[])
25902 +{
25903 +  init_bufs ();
25904 +
25905 +  return f1 (1, 2);
25906 +}
25907 diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
25908 new file mode 100644
25909 index 0000000..719b178
25910 --- /dev/null
25911 +++ b/gdb/testsuite/gdb.python/py-inferior.exp
25912 @@ -0,0 +1,201 @@
25913 +# Copyright (C) 2009 Free Software Foundation, Inc.
25914 +
25915 +# This program is free software; you can redistribute it and/or modify
25916 +# it under the terms of the GNU General Public License as published by
25917 +# the Free Software Foundation; either version 3 of the License, or
25918 +# (at your option) any later version.
25919 +#
25920 +# This program is distributed in the hope that it will be useful,
25921 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25922 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25923 +# GNU General Public License for more details.
25924 +#
25925 +# You should have received a copy of the GNU General Public License
25926 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
25927 +
25928 +# This file is part of the GDB testsuite.  It tests the mechanism
25929 +# exposing inferiors to Python.
25930 +
25931 +if $tracelevel then {
25932 +    strace $tracelevel
25933 +}
25934 +
25935 +# Start with a fresh gdb.
25936 +
25937 +gdb_exit
25938 +gdb_start
25939 +gdb_reinitialize_dir $srcdir/$subdir
25940 +
25941 +if ![python_supported] then {
25942 +  unsupported "python support is disabled"
25943 +  return -1
25944 +}
25945 +
25946 +set testfile "py-inferior"
25947 +set srcfile ${testfile}.c
25948 +set binfile ${objdir}/${subdir}/${testfile}
25949 +
25950 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
25951 +    untested "Couldn't compile ${srcfile}"
25952 +    return -1
25953 +}
25954 +
25955 +gdb_load ${binfile}
25956 +
25957 +# The following tests require execution.
25958 +
25959 +if ![runto_main] then {
25960 +    fail "Can't run to main"
25961 +    return 0
25962 +}
25963 +
25964 +runto [gdb_get_line_number "Break here."]
25965 +
25966 +# Test basic gdb.Inferior attributes and methods.
25967 +
25968 +gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1
25969 +gdb_test "python print inferiors" "\\(<gdb.Inferior object at 0x\[\[:xdigit:\]\]+>,\\)" "verify inferiors list"
25970 +gdb_py_test_silent_cmd "python i0 = inferiors\[0\]" "get first inferior" 0
25971 +
25972 +gdb_test "python print 'result =', i0 == inferiors\[0\]" " = True" "test equality comparison (true)"
25973 +gdb_test "python print 'result =', i0.num" " = \[0-9\]+" "test Inferior.num"
25974 +gdb_test "python print 'result =', i0.pid" " = \[0-9\]+" "test Inferior.pid"
25975 +gdb_test "python print 'result =', i0.was_attached" " = False" "test Inferior.was_attached"
25976 +gdb_test "python print i0.threads ()" "\\(<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
25977 +
25978 +# Test memory read and write operations.
25979 +
25980 +gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
25981 +  "read str address" 0
25982 +gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5)" \
25983 +  "read str contents" 1
25984 +gdb_py_test_silent_cmd "python str\[1\] = 'a'" "change str" 0
25985 +gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \
25986 +  "write str" 1
25987 +gdb_test "print str" " = 0x\[\[:xdigit:\]\]+ \"hallo, testsuite\"" \
25988 +  "ensure str was changed in the inferior"
25989 +
25990 +# Test memory search.
25991 +
25992 +set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*}
25993 +set dec_number {[0-9]+}
25994 +set history_prefix {[$][0-9]* = }
25995 +set newline {[\r\n]+}
25996 +set pattern_not_found "${newline}.]"
25997 +set one_pattern_found "${newline}.${dec_number}L]"
25998 +set two_patterns_found "${newline}.${dec_number}L, ${dec_number}L]"
25999 +
26000 +# Test string pattern.
26001 +
26002 +gdb_test "set *(int32_t*) &int8_search_buf\[10\] = 0x61616161" "" ""
26003 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int8_search_buf')" "" ""
26004 +gdb_test "py start_addr = search_buf.address" "" ""
26005 +gdb_test "py length = search_buf.type.sizeof" "" ""
26006 +
26007 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 'aaa')" \
26008 +  "${two_patterns_found}" "find string pattern"
26009 +
26010 +# Test not finding pattern because search range too small, with
26011 +# potential find at the edge of the range.
26012 +
26013 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 10+3, 'aaaa')" \
26014 +  "${pattern_not_found}" "pattern not found at end of range"
26015 +
26016 +# Increase the search range by 1 and we should find the pattern.
26017 +
26018 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 10+3+1, \['a', 'a', 'a', 'a'\])" \
26019 +  "${one_pattern_found}" "pattern found at end of range"
26020 +
26021 +# Test max-count with size, with different parameter position
26022 +
26023 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], 1, 1)" \
26024 +  "${one_pattern_found}" "size = 1, max_count = 1"
26025 +
26026 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], 1, 2)" \
26027 +  "${two_patterns_found}" "size = 1, max_count = 2, normal ordering"
26028 +
26029 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], size = 1, max_count = 2)" \
26030 +  "${two_patterns_found}" "size = 1, max_count = 2, normal ordering, with keywords"
26031 +
26032 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], max_count = 2, size = 1)" \
26033 +  "${two_patterns_found}" "size = 1, max_count = 2, inverted ordering"
26034 +
26035 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \['a', 'a'\], max_count = 2)" \
26036 +  "${two_patterns_found}" "max_count = 2, with keyword"
26037 +
26038 +# Test 16-bit pattern.
26039 +
26040 +gdb_test "set int16_search_buf\[10\] = 0x1234" "" ""
26041 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int16_search_buf')" "" ""
26042 +gdb_test "py start_addr = search_buf.address" "" ""
26043 +gdb_test "py length = search_buf.type.sizeof" "" ""
26044 +gdb_test "py pattern = gdb.parse_and_eval ('(int16_t) 0x1234')" "" ""
26045 +
26046 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0x1234, 2)" \
26047 +  "${one_pattern_found}" "find 16-bit pattern, with python pattern"
26048 +
26049 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
26050 +  "${one_pattern_found}" "find 16-bit pattern, with value pattern"
26051 +
26052 +# Test 32-bit pattern.
26053 +
26054 +gdb_test "set int32_search_buf\[10\] = 0x12345678" "" ""
26055 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int32_search_buf')" "" ""
26056 +gdb_test "py start_addr = search_buf.address" "" ""
26057 +gdb_test "py length = search_buf.type.sizeof" "" ""
26058 +gdb_test "py pattern = gdb.parse_and_eval ('(int32_t) 0x12345678')" "" ""
26059 +
26060 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0x12345678, 4)" \
26061 +  "${one_pattern_found}" "find 32-bit pattern, with python pattern"
26062 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
26063 +  "${one_pattern_found}" "find 32-bit pattern, with value pattern"
26064 +
26065 +# Test 64-bit pattern.
26066 +
26067 +gdb_test "set int64_search_buf\[10\] = 0xfedcba9876543210LL" "" ""
26068 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int64_search_buf')" "" ""
26069 +gdb_test "py start_addr = search_buf.address" "" ""
26070 +gdb_test "py length = search_buf.type.sizeof" "" ""
26071 +gdb_test "py pattern = gdb.parse_and_eval ('(int64_t) 0xfedcba9876543210LL')" "" ""
26072 +
26073 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0xfedcba9876543210, 8)" \
26074 +  "${one_pattern_found}" "find 64-bit pattern, with python pattern"
26075 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
26076 +  "${one_pattern_found}" "find 64-bit pattern, with value pattern"
26077 +
26078 +# Test mixed-sized patterns.
26079 +
26080 +gdb_test "set *(int8_t*) &search_buf\[10\] = 0x62" "" ""
26081 +gdb_test "set *(int16_t*) &search_buf\[11\] = 0x6363" "" ""
26082 +gdb_test "set *(int32_t*) &search_buf\[13\] = 0x64646464" "" ""
26083 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('search_buf')" "" ""
26084 +gdb_test "py start_addr = search_buf\[0\].address" "" ""
26085 +gdb_test "py pattern1 = gdb.parse_and_eval ('(int8_t) 0x62')" "" ""
26086 +gdb_test "py pattern2 = gdb.parse_and_eval ('(int16_t) 0x6363')" "" ""
26087 +gdb_test "py pattern3 = gdb.parse_and_eval ('(int32_t) 0x64646464')" "" ""
26088 +
26089 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, \[pattern1, pattern2, pattern3\])" \
26090 +    "${one_pattern_found}" "find mixed-sized pattern"
26091 +
26092 +# Test search spanning a large range, in the particular case of native
26093 +# targets, test the search spanning multiple chunks.
26094 +# Remote targets may implement the search differently.
26095 +
26096 +set CHUNK_SIZE 16000 ;
26097 +
26098 +gdb_test "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
26099 +gdb_test "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
26100 +gdb_test "py start_addr = gdb.selected_frame ().read_var ('search_buf')" "" ""
26101 +gdb_test "py length = gdb.selected_frame ().read_var ('search_buf_size')" "" ""
26102 +
26103 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0x12345678, 4)" \
26104 +  "${two_patterns_found}" "search spanning large range"
26105 +
26106 +# For native targets, test a pattern straddling a chunk boundary.
26107 +
26108 +if [isnative] {
26109 +    gdb_test "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531" "" ""
26110 +
26111 +    gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0xfdb97531, 4)" \
26112 +      "${one_pattern_found}" "find pattern straddling chunk boundary"
26113 +}
26114 diff --git a/gdb/testsuite/gdb.python/py-infthread.c b/gdb/testsuite/gdb.python/py-infthread.c
26115 new file mode 100644
26116 index 0000000..22eb9f2
26117 --- /dev/null
26118 +++ b/gdb/testsuite/gdb.python/py-infthread.c
26119 @@ -0,0 +1,14 @@
26120 +int f2 (int a)
26121 +{
26122 +  return ++a;
26123 +}
26124 +
26125 +int f1 (int a, int b)
26126 +{
26127 +  return f2(a) + b;
26128 +}
26129 +
26130 +int main (int argc, char *argv[])
26131 +{
26132 +  return f1 (1, 2);
26133 +}
26134 diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp
26135 new file mode 100644
26136 index 0000000..e9d18b7
26137 --- /dev/null
26138 +++ b/gdb/testsuite/gdb.python/py-infthread.exp
26139 @@ -0,0 +1,58 @@
26140 +# Copyright (C) 2009 Free Software Foundation, Inc.
26141 +
26142 +# This program is free software; you can redistribute it and/or modify
26143 +# it under the terms of the GNU General Public License as published by
26144 +# the Free Software Foundation; either version 3 of the License, or
26145 +# (at your option) any later version.
26146 +#
26147 +# This program is distributed in the hope that it will be useful,
26148 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
26149 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26150 +# GNU General Public License for more details.
26151 +#
26152 +# You should have received a copy of the GNU General Public License
26153 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
26154 +
26155 +# This file is part of the GDB testsuite.  It tests the mechanism
26156 +# exposing inferior threads to Python.
26157 +
26158 +if $tracelevel then {
26159 +    strace $tracelevel
26160 +}
26161 +
26162 +# Start with a fresh gdb.
26163 +
26164 +gdb_exit
26165 +gdb_start
26166 +gdb_reinitialize_dir $srcdir/$subdir
26167 +
26168 +if ![python_supported] then {
26169 +  unsupported "python support is disabled"
26170 +  return -1
26171 +}
26172 +
26173 +set testfile "py-infthread"
26174 +set srcfile ${testfile}.c
26175 +set binfile ${objdir}/${subdir}/${testfile}
26176 +
26177 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
26178 +    untested "Couldn't compile ${srcfile}"
26179 +    return -1
26180 +}
26181 +
26182 +gdb_load ${binfile}
26183 +
26184 +# The following tests require execution.
26185 +
26186 +if ![runto_main] then {
26187 +    fail "Can't run to main"
26188 +    return 0
26189 +}
26190 +
26191 +runto [gdb_get_line_number "Break here."]
26192 +
26193 +# Test basic gdb.Inferior attributes and methods.
26194 +
26195 +gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test gdb.selected_thread" 1
26196 +gdb_test "python print t0" "\\<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>" "verify InferiorThread object"
26197 +gdb_test "python print 'result =', t0.num" " = \[0-9\]+" "test Inferior.num"
26198 diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
26199 index b4b3776..359c4ed 100644
26200 --- a/gdb/testsuite/gdb.python/py-prettyprint.exp
26201 +++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
26202 @@ -27,12 +27,20 @@ set binfile ${objdir}/${subdir}/${testfile}
26203  # Start with a fresh gdb.
26204  gdb_exit
26205  gdb_start
26206 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
26207 -    -re "not supported.*$gdb_prompt $" {
26208 -      unsupported "python support is disabled"
26209 -      return -1
26210 -    }
26211 -    -re "$gdb_prompt $"        {}
26212 +if ![python_supported] then {
26213 +  unsupported "python support is disabled"
26214 +  return -1
26215 +}
26216 +
26217 +# Run a command in GDB, and report a failure if a Python exception is thrown.
26218 +# If report_pass is true, report a pass if no exception is thrown.
26219 +proc gdb_py_test_silent_cmd {cmd name report_pass} {
26220 +  global gdb_prompt
26221 +
26222 +  gdb_test_multiple $cmd $name {
26223 +      -re "Traceback.*$gdb_prompt $"  { fail $name }
26224 +      -re "$gdb_prompt $"            { if $report_pass { pass $name } }
26225 +  }
26226  }
26227  
26228  # Run a command in GDB, and report a failure if a Python exception is thrown.
26229 @@ -102,6 +110,8 @@ proc run_lang_tests {lang} {
26230  
26231      gdb_test "print c" " = container $hex \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
26232  
26233 +    gdb_test "print nullstr" "RuntimeError: Error reading string from inferior.*"
26234 +
26235      gdb_test "continue" "Program exited normally\."
26236  }
26237  
26238 diff --git a/gdb/testsuite/gdb.python/py-template.exp b/gdb/testsuite/gdb.python/py-template.exp
26239 index cea6ae0..c9a63d4 100644
26240 --- a/gdb/testsuite/gdb.python/py-template.exp
26241 +++ b/gdb/testsuite/gdb.python/py-template.exp
26242 @@ -20,6 +20,17 @@ if $tracelevel then {
26243      strace $tracelevel
26244  }
26245  
26246 +# Start with a fresh gdb.
26247 +
26248 +gdb_exit
26249 +gdb_start
26250 +gdb_reinitialize_dir $srcdir/$subdir
26251 +
26252 +if ![python_supported] then {
26253 +  unsupported "python support is disabled"
26254 +  return -1
26255 +}
26256 +
26257  set testfile "py-template"
26258  set srcfile ${testfile}.cc
26259  set binfile ${objdir}/${subdir}/${testfile}
26260 @@ -29,20 +40,6 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
26261      return -1
26262  }
26263  
26264 -# Start with a fresh gdb.
26265 -
26266 -gdb_exit
26267 -gdb_start
26268 -gdb_reinitialize_dir $srcdir/$subdir
26269 -
26270 -gdb_test_multiple "python print 23" "verify python support" {
26271 -    -re "not supported.*$gdb_prompt $" {
26272 -      unsupported "python support is disabled"
26273 -      return -1
26274 -    }
26275 -    -re "$gdb_prompt $"        {}
26276 -}
26277 -
26278  proc test_template_arg {type} {
26279      global testfile srcdir subdir srcfile binfile
26280      if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
26281 diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
26282 index 2958233..0de1cae 100644
26283 --- a/gdb/testsuite/gdb.python/py-value.exp
26284 +++ b/gdb/testsuite/gdb.python/py-value.exp
26285 @@ -292,6 +292,15 @@ proc test_value_after_death {} {
26286      "print value's type"
26287  }
26288  
26289 +# Regression test for a cast failure.  The bug was that if we cast a
26290 +# value to its own type, gdb could crash.  This happened because we
26291 +# could end up double-freeing a struct value.
26292 +proc test_cast_regression {} {
26293 +  gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
26294 +  gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
26295 +  gdb_test "python print v" "5" "print value for cast test"
26296 +}
26297 +
26298  # Regression test for invalid subscript operations.  The bug was that
26299  # the type of the value was not being checked before allowing a
26300  # subscript operation to proceed.
26301 @@ -366,16 +375,23 @@ proc test_subscript_regression {lang} {
26302  gdb_exit
26303  gdb_start
26304  gdb_reinitialize_dir $srcdir/$subdir
26305 -gdb_load ${binfile}
26306  
26307 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
26308 -    -re "not supported.*$gdb_prompt $" {
26309 -      unsupported "python support is disabled"
26310 -      return -1
26311 -    }
26312 -    -re "$gdb_prompt $"        {}
26313 +if ![python_supported] then {
26314 +  unsupported "python support is disabled"
26315 +  return -1
26316  }
26317  
26318 +set testfile "py-value"
26319 +set srcfile ${testfile}.c
26320 +set binfile ${objdir}/${subdir}/${testfile}
26321 +
26322 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
26323 +    untested "Couldn't compile ${srcfile}"
26324 +    return -1
26325 +}
26326 +
26327 +gdb_load ${binfile}
26328 +
26329  test_value_creation
26330  test_value_numeric_ops
26331  test_value_boolean
26332 @@ -391,6 +407,7 @@ if ![runto_main] then {
26333  
26334  test_value_in_inferior
26335  test_value_after_death
26336 +test_cast_regression
26337  
26338  # The following test recompiles the binary to test either C or C++
26339  # values. 
26340 diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
26341 index 5223fc8..03e1eab 100644
26342 --- a/gdb/testsuite/gdb.python/python.exp
26343 +++ b/gdb/testsuite/gdb.python/python.exp
26344 @@ -26,30 +26,9 @@ gdb_exit
26345  gdb_start
26346  gdb_reinitialize_dir $srcdir/$subdir
26347  
26348 -gdb_test_multiple "python print 23" "verify python support" {
26349 -    -re "not supported.*$gdb_prompt $" {
26350 -      unsupported "python support is disabled"
26351 -      return -1
26352 -    }
26353 -    -re "$gdb_prompt $"        {}
26354 -}
26355 -
26356 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
26357 -# Run a test named NAME, consisting of multiple lines of input.
26358 -# After each input line INPUT, search for result line RESULT.
26359 -# Succeed if all results are seen; fail otherwise.
26360 -proc gdb_py_test_multiple {name args} {
26361 -    global gdb_prompt
26362 -    foreach {input result} $args {
26363 -       if {[gdb_test_multiple $input "$name - $input" {
26364 -           -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
26365 -               pass "$name - $input"
26366 -           }
26367 -       }]} {
26368 -           return 1
26369 -       }
26370 -    }
26371 -    return 0
26372 +if ![python_supported] then {
26373 +  unsupported "python support is disabled"
26374 +  return -1
26375  }
26376  
26377  gdb_py_test_multiple "multi-line python command" \
26378 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
26379 new file mode 100644
26380 index 0000000..4dc308b
26381 --- /dev/null
26382 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
26383 @@ -0,0 +1,175 @@
26384 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
26385 +
26386 +   Copyright 2008, 2009 Free Software Foundation, Inc.
26387 +
26388 +   This file is part of GDB.
26389 +
26390 +   This program is free software; you can redistribute it and/or modify
26391 +   it under the terms of the GNU General Public License as published by
26392 +   the Free Software Foundation; either version 2 of the License, or
26393 +   (at your option) any later version.
26394 +
26395 +   This program is distributed in the hope that it will be useful,
26396 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
26397 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26398 +   GNU General Public License for more details.
26399 +
26400 +   You should have received a copy of the GNU General Public License
26401 +   along with this program; if not, write to the Free Software
26402 +   Foundation, Inc., 59 Temple Place - Suite 330,
26403 +   Boston, MA 02111-1307, USA.  */
26404 +
26405 +#include <string.h>
26406 +#include <errno.h>
26407 +
26408 +static void
26409 +delay (void)
26410 +{
26411 +  int i = usleep (1000000 / 100);
26412 +  assert (i == 0 || errno == EINTR);
26413 +}
26414 +
26415 +#if defined FOLLOW_PARENT
26416 +
26417 +static void
26418 +forkoff (int nr)
26419 +{
26420 +  pid_t child, pid_got;
26421 +  int exit_code = 42 + nr;
26422 +  int status, i;
26423 +
26424 +  child = fork ();
26425 +  switch (child)
26426 +    {
26427 +    case -1:
26428 +      assert (0);
26429 +    case 0:
26430 +      printf ("child%d: %d\n", nr, (int) getpid ());
26431 +      /* Delay to get both the "child%d" and "parent%d" message printed without
26432 +        a race breaking expect by its endless wait on `$gdb_prompt$':
26433 +        Breakpoint 3, breakpoint () at ../../../gdb/testsuite/gdb.threads/watchpoint-fork.c:33
26434 +        33      }
26435 +        (gdb) parent2: 14223  */
26436 +      i = sleep (1);
26437 +      assert (i == 0);
26438 +
26439 +      /* We must not get caught here (against a forgotten breakpoint).  */
26440 +      var++;
26441 +      breakpoint ();
26442 +
26443 +      _exit (exit_code);
26444 +    default:
26445 +      printf ("parent%d: %d\n", nr, (int) child);
26446 +      /* Delay to get both the "child%d" and "parent%d" message printed, see
26447 +        above.  */
26448 +      i = sleep (1);
26449 +      assert (i == 0);
26450 +
26451 +      pid_got = wait (&status);
26452 +      assert (pid_got == child);
26453 +      assert (WIFEXITED (status));
26454 +      assert (WEXITSTATUS (status) == exit_code);
26455 +
26456 +      /* We must get caught here (against a false watchpoint removal).  */
26457 +      breakpoint ();
26458 +    }
26459 +}
26460 +
26461 +#elif defined FOLLOW_CHILD
26462 +
26463 +static volatile int usr1_got;
26464 +
26465 +static void
26466 +handler_usr1 (int signo)
26467 +{
26468 +  usr1_got++;
26469 +}
26470 +
26471 +static void
26472 +forkoff (int nr)
26473 +{
26474 +  pid_t child;
26475 +  int i, loop;
26476 +  struct sigaction act, oldact;
26477 +#ifdef THREAD
26478 +  void *thread_result;
26479 +#endif
26480 +
26481 +  memset (&act, 0, sizeof act);
26482 +  act.sa_flags = SA_RESTART;
26483 +  act.sa_handler = handler_usr1;
26484 +  sigemptyset (&act.sa_mask);
26485 +  i = sigaction (SIGUSR1, &act, &oldact);
26486 +  assert (i == 0);
26487 +
26488 +  child = fork ();
26489 +  switch (child)
26490 +    {
26491 +    case -1:
26492 +      assert (0);
26493 +    default:
26494 +      printf ("parent%d: %d\n", nr, (int) child);
26495 +
26496 +      /* Sleep for a while to possibly get incorrectly ATTACH_THREADed by GDB
26497 +        tracing the child fork with no longer valid thread/lwp entries of the
26498 +        parent.  */
26499 +
26500 +      i = sleep (2);
26501 +      assert (i == 0);
26502 +
26503 +      /* We must not get caught here (against a forgotten breakpoint).  */
26504 +
26505 +      var++;
26506 +      breakpoint ();
26507 +
26508 +#ifdef THREAD
26509 +      /* And neither got caught our thread.  */
26510 +
26511 +      step = 99;
26512 +      i = pthread_join (thread, &thread_result);
26513 +      assert (i == 0);
26514 +      assert (thread_result == (void *) 99UL);
26515 +#endif
26516 +
26517 +      /* Be sure our child knows we did not get caught above.  */
26518 +
26519 +      i = kill (child, SIGUSR1);
26520 +      assert (i == 0);
26521 +
26522 +      /* Sleep for a while to check GDB's `info threads' no longer tracks us in
26523 +        the child fork.  */
26524 +
26525 +      i = sleep (2);
26526 +      assert (i == 0);
26527 +
26528 +      _exit (0);
26529 +    case 0:
26530 +      printf ("child%d: %d\n", nr, (int) getpid ());
26531 +
26532 +      /* Let the parent signal us about its success.  Be careful of races.  */
26533 +
26534 +      for (loop = 0; loop < 1000; loop++)
26535 +       {
26536 +         /* Parent either died (and USR1_GOT is zero) or it succeeded.  */
26537 +         if (kill (getppid (), 0) != 0)
26538 +           break;
26539 +         /* Parent succeeded?  */
26540 +         if (usr1_got)
26541 +           break;
26542 +
26543 +         delay ();
26544 +       }
26545 +      assert (usr1_got);
26546 +
26547 +      /* We must get caught here (against a false watchpoint removal).  */
26548 +
26549 +      breakpoint ();
26550 +    }
26551 +
26552 +  i = sigaction (SIGUSR1, &oldact, NULL);
26553 +  assert (i == 0);
26554 +}
26555 +
26556 +#else
26557 +# error "!FOLLOW_PARENT && !FOLLOW_CHILD"
26558 +#endif
26559 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
26560 new file mode 100644
26561 index 0000000..edacfc0
26562 --- /dev/null
26563 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
26564 @@ -0,0 +1,157 @@
26565 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
26566 +
26567 +   Copyright 2008, 2009 Free Software Foundation, Inc.
26568 +
26569 +   This file is part of GDB.
26570 +
26571 +   This program is free software; you can redistribute it and/or modify
26572 +   it under the terms of the GNU General Public License as published by
26573 +   the Free Software Foundation; either version 2 of the License, or
26574 +   (at your option) any later version.
26575 +
26576 +   This program is distributed in the hope that it will be useful,
26577 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
26578 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26579 +   GNU General Public License for more details.
26580 +
26581 +   You should have received a copy of the GNU General Public License
26582 +   along with this program; if not, write to the Free Software
26583 +   Foundation, Inc., 59 Temple Place - Suite 330,
26584 +   Boston, MA 02111-1307, USA.  */
26585 +
26586 +#include <assert.h>
26587 +#include <unistd.h>
26588 +#include <sys/wait.h>
26589 +#include <stdio.h>
26590 +#include <stdlib.h>
26591 +#include <pthread.h>
26592 +
26593 +#include <asm/unistd.h>
26594 +#include <unistd.h>
26595 +#define gettid() syscall (__NR_gettid)
26596 +
26597 +/* Non-atomic `var++' should not hurt as we synchronize the threads by the STEP
26598 +   variable.  Hit-comments need to be duplicite there to catch both at-stops
26599 +   and behind-stops, depending on the target.  */
26600 +
26601 +static volatile int var;
26602 +
26603 +static void
26604 +dummy (void)
26605 +{
26606 +}
26607 +
26608 +static void
26609 +breakpoint (void)
26610 +{
26611 +}
26612 +
26613 +/* Include here the functions:
26614 +   static void forkoff (int nr);
26615 +   static void delay (void);  */
26616 +
26617 +static pthread_t thread;
26618 +static volatile int step;
26619 +#define THREAD
26620 +
26621 +#include "watchpoint-fork-forkoff.c"
26622 +
26623 +static void *
26624 +start (void *arg)
26625 +{
26626 +  if (step >= 3)
26627 +    goto step_3;
26628 +
26629 +  while (step != 1)
26630 +    delay ();
26631 +
26632 +  var++;       /* validity-thread-B */
26633 +  dummy ();    /* validity-thread-B */
26634 +  step = 2;
26635 +  while (step != 3)
26636 +    {
26637 +      if (step == 99)
26638 +       goto step_99;
26639 +      delay ();
26640 +    }
26641 +
26642 +step_3:
26643 +  if (step >= 5)
26644 +    goto step_5;
26645 +
26646 +  var++;       /* after-fork1-B */
26647 +  dummy ();    /* after-fork1-B */
26648 +  step = 4;
26649 +  while (step != 5)
26650 +    {
26651 +      if (step == 99)
26652 +       goto step_99;
26653 +      delay ();
26654 +    }
26655 +
26656 +step_5:
26657 +  var++;       /* after-fork2-B */
26658 +  dummy ();    /* after-fork2-B */
26659 +  return (void *) 5UL;
26660 +
26661 +step_99:
26662 +  /* We must not get caught here (against a forgotten breakpoint).  */
26663 +  var++;
26664 +  breakpoint ();
26665 +  return (void *) 99UL;
26666 +}
26667 +
26668 +int
26669 +main (void)
26670 +{
26671 +  int i;
26672 +  void *thread_result;
26673 +
26674 +  setbuf (stdout, NULL);
26675 +  printf ("main: %d\n", (int) gettid ());
26676 +
26677 +  /* General watchpoints validity.  */
26678 +  var++;       /* validity-first */
26679 +  dummy ();    /* validity-first */
26680 +
26681 +  i = pthread_create (&thread, NULL, start, NULL);
26682 +  assert (i == 0);
26683 +
26684 +  var++;       /* validity-thread-A */
26685 +  dummy ();    /* validity-thread-A */
26686 +  step = 1;
26687 +  while (step != 2)
26688 +    delay ();
26689 +
26690 +  /* Hardware watchpoints got disarmed here.  */
26691 +  forkoff (1);
26692 +
26693 +  var++;       /* after-fork1-A */
26694 +  dummy ();    /* after-fork1-A */
26695 +  step = 3;
26696 +#ifdef FOLLOW_CHILD
26697 +  /* Spawn new thread as it was deleted in the child of FORK.  */
26698 +  i = pthread_create (&thread, NULL, start, NULL);
26699 +  assert (i == 0);
26700 +#endif
26701 +  while (step != 4)
26702 +    delay ();
26703 +
26704 +  /* A sanity check for double hardware watchpoints removal.  */
26705 +  forkoff (2);
26706 +
26707 +  var++;       /* after-fork2-A */
26708 +  dummy ();    /* after-fork2-A */
26709 +  step = 5;
26710 +#ifdef FOLLOW_CHILD
26711 +  /* Spawn new thread as it was deleted in the child of FORK.  */
26712 +  i = pthread_create (&thread, NULL, start, NULL);
26713 +  assert (i == 0);
26714 +#endif
26715 +
26716 +  i = pthread_join (thread, &thread_result);
26717 +  assert (i == 0);
26718 +  assert (thread_result == (void *) 5UL);
26719 +
26720 +  return 0;
26721 +}
26722 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.c b/gdb/testsuite/gdb.threads/watchpoint-fork.c
26723 new file mode 100644
26724 index 0000000..5f62e7f
26725 --- /dev/null
26726 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.c
26727 @@ -0,0 +1,57 @@
26728 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
26729 +
26730 +   Copyright 2008, 2009 Free Software Foundation, Inc.
26731 +
26732 +   This file is part of GDB.
26733 +
26734 +   This program is free software; you can redistribute it and/or modify
26735 +   it under the terms of the GNU General Public License as published by
26736 +   the Free Software Foundation; either version 2 of the License, or
26737 +   (at your option) any later version.
26738 +
26739 +   This program is distributed in the hope that it will be useful,
26740 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
26741 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26742 +   GNU General Public License for more details.
26743 +
26744 +   You should have received a copy of the GNU General Public License
26745 +   along with this program; if not, write to the Free Software
26746 +   Foundation, Inc., 59 Temple Place - Suite 330,
26747 +   Boston, MA 02111-1307, USA.  */
26748 +
26749 +#include <assert.h>
26750 +#include <unistd.h>
26751 +#include <sys/wait.h>
26752 +#include <stdio.h>
26753 +#include <stdlib.h>
26754 +
26755 +static volatile int var;
26756 +
26757 +static void
26758 +breakpoint (void)
26759 +{
26760 +}
26761 +
26762 +/* Include here the function:
26763 +   static void forkoff (int nr);  */
26764 +
26765 +#include "watchpoint-fork-forkoff.c"
26766 +
26767 +int
26768 +main (void)
26769 +{
26770 +  setbuf (stdout, NULL);
26771 +  printf ("main: %d\n", (int) getpid ());
26772 +
26773 +  /* General watchpoints validity.  */
26774 +  var++;
26775 +  /* Hardware watchpoints got disarmed here.  */
26776 +  forkoff (1);
26777 +  /* This watchpoint got lost before.  */
26778 +  var++;
26779 +  /* A sanity check for double hardware watchpoints removal.  */
26780 +  forkoff (2);
26781 +  var++;
26782 +
26783 +  return 0;
26784 +}
26785 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.exp b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
26786 new file mode 100644
26787 index 0000000..1dc93ab
26788 --- /dev/null
26789 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
26790 @@ -0,0 +1,130 @@
26791 +# Copyright 2008, 2009 Free Software Foundation, Inc.
26792 +
26793 +# This program is free software; you can redistribute it and/or modify
26794 +# it under the terms of the GNU General Public License as published by
26795 +# the Free Software Foundation; either version 3 of the License, or
26796 +# (at your option) any later version.
26797 +#
26798 +# This program is distributed in the hope that it will be useful,
26799 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
26800 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26801 +# GNU General Public License for more details.
26802 +#
26803 +# You should have received a copy of the GNU General Public License
26804 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
26805 +
26806 +# Test case for forgotten hw-watchpoints after fork()-off of a process.
26807 +
26808 +proc test {type symbol} {
26809 +    global objdir subdir srcdir
26810 +
26811 +    set test watchpoint-fork
26812 +
26813 +    global pf_prefix
26814 +    set prefix_test $pf_prefix
26815 +    lappend pf_prefix "$type:"
26816 +    set prefix_mt $pf_prefix
26817 +
26818 +    # no threads
26819 +
26820 +    set pf_prefix $prefix_mt
26821 +    lappend pf_prefix "singlethreaded:"
26822 +
26823 +    set executable ${test}-${type}
26824 +    if { [gdb_compile ${srcdir}/${subdir}/${test}.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
26825 +       untested ${test}.exp
26826 +       return -1
26827 +    }
26828 +    clean_restart $executable
26829 +
26830 +    gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on."
26831 +    gdb_test "set follow-fork-mode $type"
26832 +    gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"."
26833 +    # Testcase uses it for the `follow-fork-mode child' type.
26834 +    gdb_test "handle SIGUSR1 nostop noprint pass"
26835 +
26836 +    if { ![runto_main] } then {
26837 +       gdb_suppress_tests
26838 +       return
26839 +    }
26840 +
26841 +    # Install the watchpoint only after getting into MAIN - workaround some PPC
26842 +    # problem.
26843 +    gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
26844 +
26845 +    # It is never hit but it should not be left over in the fork()ed-off child.
26846 +    gdb_breakpoint "breakpoint"
26847 +
26848 +    gdb_test "continue" \
26849 +            "atchpoint 2: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work"
26850 +    gdb_test "continue" \
26851 +            "reakpoint 3, breakpoint.*" "breakpoint after the first fork"
26852 +    gdb_test "continue" \
26853 +            "atchpoint 2: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork"
26854 +    gdb_test "continue" \
26855 +            "reakpoint 3, breakpoint.*" "breakpoint after the second fork"
26856 +    gdb_test "continue" \
26857 +            "atchpoint 2: var.*Old value = 2.*New value = 3.*return *0;" "watchpoint after the second fork"
26858 +    gdb_test "continue" "Continuing..*Program exited normally." "finish"
26859 +
26860 +
26861 +    # threads
26862 +
26863 +    set pf_prefix $prefix_mt
26864 +    lappend pf_prefix "multithreaded:"
26865 +
26866 +    set executable ${test}-mt-${type}
26867 +    if { [gdb_compile_pthreads ${srcdir}/${subdir}/${test}-mt.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
26868 +       untested ${test}.exp
26869 +       return -1
26870 +    }
26871 +    clean_restart $executable
26872 +
26873 +    gdb_test "set follow-fork-mode $type"
26874 +    # Testcase uses it for the `follow-fork-mode child' type.
26875 +    gdb_test "handle SIGUSR1 nostop noprint pass"
26876 +
26877 +    if { ![runto_main] } then {
26878 +       gdb_suppress_tests
26879 +       return
26880 +    }
26881 +
26882 +    # Install the watchpoint only after getting into MAIN - workaround some PPC
26883 +    # problem.
26884 +    gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
26885 +
26886 +    # It is never hit but it should not be left over in the fork()ed-off child.
26887 +    gdb_breakpoint "breakpoint"
26888 +
26889 +    gdb_test "continue" \
26890 +            "atchpoint 2: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work"
26891 +    gdb_test "continue" \
26892 +            "atchpoint 2: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A"
26893 +    gdb_test "continue" \
26894 +            "atchpoint 2: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B"
26895 +    gdb_test "continue" \
26896 +            "reakpoint 3, breakpoint.*" "breakpoint (A) after the first fork"
26897 +    gdb_test "continue" \
26898 +            "atchpoint 2: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork"
26899 +    gdb_test "continue" \
26900 +            "atchpoint 2: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork"
26901 +    gdb_test "continue" \
26902 +            "reakpoint 3, breakpoint.*" "breakpoint (A) after the second fork"
26903 +    gdb_test "continue" \
26904 +            "atchpoint 2: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork"
26905 +    gdb_test "continue" \
26906 +            "atchpoint 2: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork"
26907 +    gdb_test "continue" "Continuing..*Program exited normally." "finish"
26908 +
26909 +
26910 +    # cleanup
26911 +
26912 +    set pf_prefix $prefix_test
26913 +}
26914 +
26915 +test parent FOLLOW_PARENT
26916 +
26917 +# Only GNU/Linux is known to support `set follow-fork-mode child'.
26918 +if {[istarget "*-*-linux*"]} {
26919 +    test child FOLLOW_CHILD
26920 +}
26921 diff --git a/gdb/testsuite/gdb.threads/watchthreads-reorder.c b/gdb/testsuite/gdb.threads/watchthreads-reorder.c
26922 new file mode 100644
26923 index 0000000..14f42d6
26924 --- /dev/null
26925 +++ b/gdb/testsuite/gdb.threads/watchthreads-reorder.c
26926 @@ -0,0 +1,366 @@
26927 +/* This testcase is part of GDB, the GNU debugger.
26928 +
26929 +   Copyright 2009 Free Software Foundation, Inc.
26930 +
26931 +   This program is free software; you can redistribute it and/or modify
26932 +   it under the terms of the GNU General Public License as published by
26933 +   the Free Software Foundation; either version 3 of the License, or
26934 +   (at your option) any later version.
26935 +
26936 +   This program is distributed in the hope that it will be useful,
26937 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
26938 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26939 +   GNU General Public License for more details.
26940 +
26941 +   You should have received a copy of the GNU General Public License
26942 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
26943 +
26944 +#define _GNU_SOURCE
26945 +#include <pthread.h>
26946 +#include <stdio.h>
26947 +#include <limits.h>
26948 +#include <errno.h>
26949 +#include <stdlib.h>
26950 +#include <string.h>
26951 +#include <assert.h>
26952 +#include <sys/types.h>
26953 +#include <signal.h>
26954 +#include <unistd.h>
26955 +#include <asm/unistd.h>
26956 +
26957 +#define gettid() syscall (__NR_gettid)
26958 +
26959 +/* Terminate always in the main task, it can lock up with SIGSTOPped GDB
26960 +   otherwise.  */
26961 +#define TIMEOUT (gettid () == getpid() ? 10 : 15)
26962 +
26963 +static pthread_mutex_t gdbstop_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
26964 +
26965 +static pid_t thread1_tid;
26966 +static pthread_cond_t thread1_tid_cond = PTHREAD_COND_INITIALIZER;
26967 +static pthread_mutex_t thread1_tid_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
26968 +
26969 +static pid_t thread2_tid;
26970 +static pthread_cond_t thread2_tid_cond = PTHREAD_COND_INITIALIZER;
26971 +static pthread_mutex_t thread2_tid_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
26972 +
26973 +static pthread_mutex_t terminate_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
26974 +
26975 +static volatile int thread1_rwatch;
26976 +static volatile int thread2_rwatch;
26977 +
26978 +static int unused1_rwatch;
26979 +static int unused2_rwatch;
26980 +
26981 +/* Do not use alarm as it would create a ptrace event which would hang up us if
26982 + * we are being traced by GDB which we stopped ourselves.  */
26983 +
26984 +static void timed_mutex_lock (pthread_mutex_t *mutex)
26985 +{
26986 +  int i;
26987 +  struct timespec start, now;
26988 +
26989 +  i = clock_gettime (CLOCK_MONOTONIC, &start);
26990 +  assert (i == 0);
26991 +
26992 +  do
26993 +    {
26994 +      i = pthread_mutex_trylock (mutex);
26995 +      if (i == 0)
26996 +       return;
26997 +      assert (i == EBUSY);
26998 +
26999 +      i = clock_gettime (CLOCK_MONOTONIC, &now);
27000 +      assert (i == 0);
27001 +      assert (now.tv_sec >= start.tv_sec);
27002 +    }
27003 +  while (now.tv_sec - start.tv_sec < TIMEOUT);
27004 +
27005 +  fprintf (stderr, "Timed out waiting for internal lock!\n");
27006 +  exit (EXIT_FAILURE);
27007 +}
27008 +
27009 +static void *
27010 +thread1_func (void *unused)
27011 +{
27012 +  int i;
27013 +  volatile int rwatch_store;
27014 +
27015 +  thread1_tid = gettid ();
27016 +  i = pthread_cond_signal (&thread1_tid_cond);
27017 +  assert (i == 0);
27018 +
27019 +  /* Be sure GDB is already stopped before continuing.  */
27020 +  timed_mutex_lock (&gdbstop_mutex);
27021 +  i = pthread_mutex_unlock (&gdbstop_mutex);
27022 +  assert (i == 0);
27023 +
27024 +  rwatch_store = thread1_rwatch;
27025 +
27026 +  /* Be sure the "T (tracing stop)" test can proceed for both threads.  */
27027 +  timed_mutex_lock (&terminate_mutex);
27028 +  i = pthread_mutex_unlock (&terminate_mutex);
27029 +  assert (i == 0);
27030 +
27031 +  return NULL;
27032 +}
27033 +
27034 +static void *
27035 +thread2_func (void *unused)
27036 +{
27037 +  int i;
27038 +  volatile int rwatch_store;
27039 +
27040 +  thread2_tid = gettid ();
27041 +  i = pthread_cond_signal (&thread2_tid_cond);
27042 +  assert (i == 0);
27043 +
27044 +  /* Be sure GDB is already stopped before continuing.  */
27045 +  timed_mutex_lock (&gdbstop_mutex);
27046 +  i = pthread_mutex_unlock (&gdbstop_mutex);
27047 +  assert (i == 0);
27048 +
27049 +  rwatch_store = thread2_rwatch;
27050 +
27051 +  /* Be sure the "T (tracing stop)" test can proceed for both threads.  */
27052 +  timed_mutex_lock (&terminate_mutex);
27053 +  i = pthread_mutex_unlock (&terminate_mutex);
27054 +  assert (i == 0);
27055 +
27056 +  return NULL;
27057 +}
27058 +
27059 +static const char *
27060 +proc_string (const char *filename, const char *line)
27061 +{
27062 +  FILE *f;
27063 +  static char buf[LINE_MAX];
27064 +  size_t line_len = strlen (line);
27065 +
27066 +  f = fopen (filename, "r");
27067 +  if (f == NULL)
27068 +    {
27069 +      fprintf (stderr, "fopen (\"%s\") for \"%s\": %s\n", filename, line,
27070 +              strerror (errno));
27071 +      exit (EXIT_FAILURE);
27072 +    }
27073 +  while (errno = 0, fgets (buf, sizeof (buf), f))
27074 +    {
27075 +      char *s;
27076 +
27077 +      s = strchr (buf, '\n');
27078 +      assert (s != NULL);
27079 +      *s = 0;
27080 +
27081 +      if (strncmp (buf, line, line_len) != 0)
27082 +       continue;
27083 +
27084 +      if (fclose (f))
27085 +       {
27086 +         fprintf (stderr, "fclose (\"%s\") for \"%s\": %s\n", filename, line,
27087 +                  strerror (errno));
27088 +         exit (EXIT_FAILURE);
27089 +       }
27090 +
27091 +      return &buf[line_len];
27092 +    }
27093 +  if (errno != 0)
27094 +    {
27095 +      fprintf (stderr, "fgets (\"%s\": %s\n", filename, strerror (errno));
27096 +      exit (EXIT_FAILURE);
27097 +    }
27098 +  fprintf (stderr, "\"%s\": No line \"%s\" found.\n", filename, line);
27099 +  exit (EXIT_FAILURE);
27100 +}
27101 +
27102 +static unsigned long
27103 +proc_ulong (const char *filename, const char *line)
27104 +{
27105 +  const char *s = proc_string (filename, line);
27106 +  long retval;
27107 +  char *end;
27108 +
27109 +  errno = 0;
27110 +  retval = strtol (s, &end, 10);
27111 +  if (retval < 0 || retval >= LONG_MAX || (end && *end))
27112 +    {
27113 +      fprintf (stderr, "\"%s\":\"%s\": %ld, %s\n", filename, line, retval,
27114 +              strerror (errno));
27115 +      exit (EXIT_FAILURE);
27116 +    }
27117 +  return retval;
27118 +}
27119 +
27120 +static void
27121 +state_wait (pid_t process, const char *wanted)
27122 +{
27123 +  char *filename;
27124 +  int i;
27125 +  struct timespec start, now;
27126 +  const char *state;
27127 +
27128 +  i = asprintf (&filename, "/proc/%lu/status", (unsigned long) process);
27129 +  assert (i > 0);
27130 +
27131 +  i = clock_gettime (CLOCK_MONOTONIC, &start);
27132 +  assert (i == 0);
27133 +
27134 +  do
27135 +    {
27136 +      state = proc_string (filename, "State:\t");
27137 +      if (strcmp (state, wanted) == 0)
27138 +       {
27139 +         free (filename);
27140 +         return;
27141 +       }
27142 +
27143 +      if (sched_yield ())
27144 +       {
27145 +         perror ("sched_yield()");
27146 +         exit (EXIT_FAILURE);
27147 +       }
27148 +
27149 +      i = clock_gettime (CLOCK_MONOTONIC, &now);
27150 +      assert (i == 0);
27151 +      assert (now.tv_sec >= start.tv_sec);
27152 +    }
27153 +  while (now.tv_sec - start.tv_sec < TIMEOUT);
27154 +
27155 +  fprintf (stderr, "Timed out waiting for PID %lu \"%s\" (now it is \"%s\")!\n",
27156 +          (unsigned long) process, wanted, state);
27157 +  exit (EXIT_FAILURE);
27158 +}
27159 +
27160 +static volatile pid_t tracer = 0;
27161 +static pthread_t thread1, thread2;
27162 +
27163 +static void
27164 +cleanup (void)
27165 +{
27166 +  printf ("Resuming GDB PID %lu.\n", (unsigned long) tracer);
27167 +
27168 +  if (tracer)
27169 +    {
27170 +      int i;
27171 +      int tracer_save = tracer;
27172 +
27173 +      tracer = 0;
27174 +
27175 +      i = kill (tracer_save, SIGCONT);
27176 +      assert (i == 0);
27177 +    }
27178 +}
27179 +
27180 +int
27181 +main (int argc, char **argv)
27182 +{
27183 +  int i;
27184 +  int standalone = 0;
27185 +
27186 +  if (argc == 2 && strcmp (argv[1], "-s") == 0)
27187 +    standalone = 1;
27188 +  else
27189 +    assert (argc == 1);
27190 +
27191 +  setbuf (stdout, NULL);
27192 +
27193 +  timed_mutex_lock (&gdbstop_mutex);
27194 +
27195 +  timed_mutex_lock (&terminate_mutex);
27196 +
27197 +  i = pthread_create (&thread1, NULL, thread1_func, NULL);
27198 +  assert (i == 0);
27199 +
27200 +  i = pthread_create (&thread2, NULL, thread2_func, NULL);
27201 +  assert (i == 0);
27202 +
27203 +  if (!standalone)
27204 +    {
27205 +      tracer = proc_ulong ("/proc/self/status", "TracerPid:\t");
27206 +      if (tracer == 0)
27207 +       {
27208 +         fprintf (stderr, "The testcase must be run by GDB!\n");
27209 +         exit (EXIT_FAILURE);
27210 +       }
27211 +      if (tracer != getppid ())
27212 +       {
27213 +         fprintf (stderr, "The testcase parent must be our GDB tracer!\n");
27214 +         exit (EXIT_FAILURE);
27215 +       }
27216 +    }
27217 +
27218 +  /* SIGCONT our debugger in the case of our crash as we would deadlock
27219 +     otherwise.  */
27220 +
27221 +  atexit (cleanup);
27222 +
27223 +  printf ("Stopping GDB PID %lu.\n", (unsigned long) tracer);
27224 +
27225 +  if (tracer)
27226 +    {
27227 +      i = kill (tracer, SIGSTOP);
27228 +      assert (i == 0);
27229 +      state_wait (tracer, "T (stopped)");
27230 +    }
27231 +
27232 +  timed_mutex_lock (&thread1_tid_mutex);
27233 +  timed_mutex_lock (&thread2_tid_mutex);
27234 +
27235 +  /* Let the threads start.  */
27236 +  i = pthread_mutex_unlock (&gdbstop_mutex);
27237 +  assert (i == 0);
27238 +
27239 +  printf ("Waiting till the threads initialize their TIDs.\n");
27240 +
27241 +  if (thread1_tid == 0)
27242 +    {
27243 +      i = pthread_cond_wait (&thread1_tid_cond, &thread1_tid_mutex);
27244 +      assert (i == 0);
27245 +
27246 +      assert (thread1_tid > 0);
27247 +    }
27248 +
27249 +  if (thread2_tid == 0)
27250 +    {
27251 +      i = pthread_cond_wait (&thread2_tid_cond, &thread2_tid_mutex);
27252 +      assert (i == 0);
27253 +
27254 +      assert (thread2_tid > 0);
27255 +    }
27256 +
27257 +  printf ("Thread 1 TID = %lu, thread 2 TID = %lu, PID = %lu.\n",
27258 +         (unsigned long) thread1_tid, (unsigned long) thread2_tid,
27259 +         (unsigned long) getpid ());
27260 +
27261 +  printf ("Waiting till the threads get trapped by the watchpoints.\n");
27262 +
27263 +  if (tracer)
27264 +    {
27265 +      /* s390x-unknown-linux-gnu will fail with "R (running)".  */
27266 +
27267 +      state_wait (thread1_tid, "T (tracing stop)");
27268 +
27269 +      state_wait (thread2_tid, "T (tracing stop)");
27270 +    }
27271 +
27272 +  cleanup ();
27273 +
27274 +  printf ("Joining the threads.\n");
27275 +
27276 +  i = pthread_mutex_unlock (&terminate_mutex);
27277 +  assert (i == 0);
27278 +
27279 +  i = pthread_join (thread1, NULL);
27280 +  assert (i == 0);
27281 +
27282 +  i = pthread_join (thread2, NULL);
27283 +  assert (i == 0);
27284 +
27285 +  printf ("Exiting.\n");       /* break-at-exit */
27286 +
27287 +  /* Just prevent compiler `warning: \e$B!F\e(BunusedX_rwatch\e$B!G\e(B defined but not used'.  */
27288 +  unused1_rwatch = 1;
27289 +  unused2_rwatch = 2;
27290 +
27291 +  return EXIT_SUCCESS;
27292 +}
27293 diff --git a/gdb/testsuite/gdb.threads/watchthreads-reorder.exp b/gdb/testsuite/gdb.threads/watchthreads-reorder.exp
27294 new file mode 100644
27295 index 0000000..8f65364
27296 --- /dev/null
27297 +++ b/gdb/testsuite/gdb.threads/watchthreads-reorder.exp
27298 @@ -0,0 +1,101 @@
27299 +# This testcase is part of GDB, the GNU debugger.
27300 +
27301 +# Copyright 2009 Free Software Foundation, Inc.
27302 +
27303 +# This program is free software; you can redistribute it and/or modify
27304 +# it under the terms of the GNU General Public License as published by
27305 +# the Free Software Foundation; either version 3 of the License, or
27306 +# (at your option) any later version.
27307 +#
27308 +# This program is distributed in the hope that it will be useful,
27309 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
27310 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27311 +# GNU General Public License for more details.
27312 +#
27313 +# You should have received a copy of the GNU General Public License
27314 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
27315 +
27316 +# Test GDB can cope with two watchpoints being hit by different threads at the
27317 +# same time, GDB reports one of them and after "continue" to report the other
27318 +# one GDB should not be confused by differently set watchpoints that time.
27319 +# This is the goal of "reorder1".  "reorder0" tests the basic functionality of
27320 +# two watchpoint being hit at the same time, without reordering them during the
27321 +# stop.  The formerly broken functionality is due to the all-stop mode default
27322 +# "show breakpoint always-inserted" being "off".  Formerly the remembered hit
27323 +# could be assigned during continuation of a thread with pending SIGTRAP to the
27324 +# different/new watchpoint, just based on the watchpoint/debug register number.
27325 +
27326 +if {[target_info exists gdb,no_hardware_watchpoints]
27327 +    || ![istarget *-*-linux*]} {
27328 +    return 0;
27329 +}
27330 +
27331 +set testfile "watchthreads-reorder"
27332 +set srcfile ${testfile}.c
27333 +set binfile ${objdir}/${subdir}/${testfile}
27334 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" ${binfile} executable [list debug additional_flags=-lrt]] != "" } {
27335 +    return -1
27336 +}
27337 +
27338 +foreach reorder {0 1} {
27339 +
27340 +    global pf_prefix
27341 +    set prefix_test $pf_prefix
27342 +    lappend pf_prefix "reorder$reorder:"
27343 +
27344 +    clean_restart $testfile
27345 +
27346 +    gdb_test "set can-use-hw-watchpoints 1"
27347 +
27348 +    if ![runto_main] {
27349 +       gdb_suppress_tests
27350 +    }
27351 +
27352 +    # Use "rwatch" as "watch" would report the watchpoint changed just based on its
27353 +    # read memory value during a stop by unrelated event.  We are interested to not
27354 +    # to lose the hardware watchpoint trigger.
27355 +
27356 +    gdb_test "rwatch thread1_rwatch" "Hardware read watchpoint \[0-9\]+: thread1_rwatch"
27357 +    gdb_test {set $rwatch1=$bpnum}
27358 +    set test "rwatch thread2_rwatch"
27359 +    gdb_test_multiple $test $test {
27360 +       -re "Target does not support this type of hardware watchpoint\\.\r\n$gdb_prompt $" {
27361 +           # ppc64 supports at most 1 hw watchpoints.
27362 +           unsupported $test
27363 +           return
27364 +       }
27365 +       -re "Hardware read watchpoint \[0-9\]+: thread2_rwatch\r\n$gdb_prompt $" {
27366 +           pass $test
27367 +       }
27368 +    }
27369 +    gdb_test {set $rwatch2=$bpnum}
27370 +    gdb_breakpoint [gdb_get_line_number "break-at-exit"]
27371 +
27372 +    # The watchpoints can happen in arbitrary order depending on random:
27373 +    # SEL: Found 2 SIGTRAP events, selecting #[01]
27374 +    # As GDB contains no srand() on the specific host/OS it will behave always the
27375 +    # same.  Such order cannot be guaranteed for GDB in general.
27376 +
27377 +    gdb_test "continue" \
27378 +            "Hardware read watchpoint \[0-9\]+: thread\[12\]_rwatch\r\n\r\nValue = 0\r\n0x\[0-9a-f\]+ in thread\[12\]_func .*" \
27379 +            "continue a"
27380 +
27381 +    if $reorder {
27382 +       gdb_test {delete $rwatch1}
27383 +       gdb_test {delete $rwatch2}
27384 +
27385 +       gdb_test "rwatch unused1_rwatch" "Hardware read watchpoint \[0-9\]+: unused1_rwatch"
27386 +       gdb_test "rwatch unused2_rwatch" "Hardware read watchpoint \[0-9\]+: unused2_rwatch"
27387 +
27388 +       gdb_test "rwatch thread1_rwatch" "Hardware read watchpoint \[0-9\]+: thread1_rwatch"
27389 +       gdb_test "rwatch thread2_rwatch" "Hardware read watchpoint \[0-9\]+: thread2_rwatch"
27390 +    }
27391 +
27392 +    gdb_test "continue" \
27393 +            "Hardware read watchpoint \[0-9\]+: thread\[12\]_rwatch\r\n\r\nValue = 0\r\n0x\[0-9a-f\]+ in thread\[12\]_func .*" \
27394 +            "continue b"
27395 +
27396 +    gdb_continue_to_breakpoint "break-at-exit" ".*break-at-exit.*"
27397 +
27398 +    set pf_prefix $prefix_test
27399 +}
27400 diff --git a/gdb/testsuite/lib/cp-support.exp b/gdb/testsuite/lib/cp-support.exp
27401 index dbd2f59..44e1b51 100644
27402 --- a/gdb/testsuite/lib/cp-support.exp
27403 +++ b/gdb/testsuite/lib/cp-support.exp
27404 @@ -222,7 +222,7 @@ proc cp_test_ptype_class { in_command in_testname in_key in_tag in_class_table {
27405  
27406      set parse_okay 0
27407      gdb_test_multiple "$in_command" "$in_testname // parse failed" {
27408 -       -re "type = (struct|class)${wsopt}(\[A-Za-z0-9_\]*)${wsopt}((:\[^\{\]*)?)${wsopt}\{(.*)\}${wsopt}(\[^\r\n\]*)\[\r\n\]+$gdb_prompt $" {
27409 +       -re "type = (struct|class)${wsopt}(\[A-Za-z0-9_:\]*)${wsopt}((:\[^\{\]*)?)${wsopt}\{(.*)\}${wsopt}(\[^\r\n\]*)\[\r\n\]+$gdb_prompt $" {
27410             set parse_okay          1
27411             set actual_key          $expect_out(1,string)
27412             set actual_tag          $expect_out(2,string)
27413 @@ -231,6 +231,7 @@ proc cp_test_ptype_class { in_command in_testname in_key in_tag in_class_table {
27414             set actual_tail         $expect_out(6,string)
27415         }
27416      }
27417 +    
27418      if { ! $parse_okay } then { return }
27419  
27420      # Check the actual key.  It would be nice to require that it match
27421 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
27422 index 0c93a73..d0c3493 100644
27423 --- a/gdb/testsuite/lib/gdb.exp
27424 +++ b/gdb/testsuite/lib/gdb.exp
27425 @@ -27,6 +27,7 @@ if {$tool == ""} {
27426  }
27427  
27428  load_lib libgloss.exp
27429 +load_lib python-support.exp
27430  
27431  global GDB
27432  
27433 diff --git a/gdb/testsuite/lib/python-support.exp b/gdb/testsuite/lib/python-support.exp
27434 new file mode 100644
27435 index 0000000..b8e9836
27436 --- /dev/null
27437 +++ b/gdb/testsuite/lib/python-support.exp
27438 @@ -0,0 +1,53 @@
27439 +global python_supported_saved
27440 +
27441 +# Return 1 if Python scripting is supported in GDB, 0 if not.
27442 +proc python_supported { } {
27443 +  global gdb_prompt
27444 +  global python_supported_saved
27445 +
27446 +  if [info exists python_supported_saved] {
27447 +      verbose "python_supported:  returning saved $python_supported_saved" 2
27448 +      return $python_supported_saved
27449 +  }
27450 +
27451 +  gdb_test_multiple "python print 'hello, world!'" "verify python support" {
27452 +    -re "not supported.*$gdb_prompt $" {
27453 +      return [set python_supported_saved 0]
27454 +    }
27455 +    -re "$gdb_prompt $"        {
27456 +      return [set python_supported_saved 1]
27457 +    }
27458 +  }
27459 +
27460 +  return [set python_supported_saved 0]
27461 +}
27462 +
27463 +# Run a command in GDB, and report a failure if a Python exception is thrown.
27464 +# If report_pass is true, report a pass if no exception is thrown.
27465 +proc gdb_py_test_silent_cmd {cmd name report_pass} {
27466 +  global gdb_prompt
27467 +
27468 +  gdb_test_multiple $cmd $name {
27469 +      -re "Traceback.*$gdb_prompt $"  { fail $name }
27470 +      -re "$gdb_prompt $"            { if $report_pass { pass $name } }
27471 +  }
27472 +}
27473 +
27474 +# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
27475 +# Run a test named NAME, consisting of multiple lines of input.
27476 +# After each input line INPUT, search for result line RESULT.
27477 +# Succeed if all results are seen; fail otherwise.
27478 +proc gdb_py_test_multiple {name args} {
27479 +    global gdb_prompt
27480 +
27481 +    foreach {input result} $args {
27482 +       if {[gdb_test_multiple $input "$name - $input" {
27483 +           -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
27484 +               pass "$name - $input"
27485 +           }
27486 +       }]} {
27487 +           return 1
27488 +       }
27489 +    }
27490 +    return 0
27491 +}
27492 diff --git a/gdb/thread.c b/gdb/thread.c
27493 index 55b4b96..e0ad2d3 100644
27494 --- a/gdb/thread.c
27495 +++ b/gdb/thread.c
27496 @@ -61,7 +61,6 @@ static int thread_alive (struct thread_info *);
27497  static void info_threads_command (char *, int);
27498  static void thread_apply_command (char *, int);
27499  static void restore_current_thread (ptid_t);
27500 -static void prune_threads (void);
27501  
27502  /* Frontend view of the thread state.  Possible extensions: stepping,
27503     finishing, until(ling),...  */
27504 @@ -497,16 +496,23 @@ thread_alive (struct thread_info *tp)
27505    return 1;
27506  }
27507  
27508 -static void
27509 +void
27510  prune_threads (void)
27511  {
27512 -  struct thread_info *tp, *next;
27513 +  struct thread_info *tp;
27514 +  struct thread_info **prevp = &thread_list;
27515  
27516 -  for (tp = thread_list; tp; tp = next)
27517 +  for (tp = *prevp; tp; tp = *prevp)
27518      {
27519 -      next = tp->next;
27520 +      /* If the thread has died, free it and unlink it from the list.
27521 +        Otherwise, advance to the next thread.  */
27522        if (!thread_alive (tp))
27523 -       delete_thread (tp->ptid);
27524 +       {
27525 +         *prevp = tp->next;
27526 +         free_thread (tp);
27527 +       }
27528 +      else
27529 +       prevp = &tp->next;
27530      }
27531  }
27532  
27533 diff --git a/gdb/top.c b/gdb/top.c
27534 index 1b4aa9d..3cfe57e 100644
27535 --- a/gdb/top.c
27536 +++ b/gdb/top.c
27537 @@ -349,6 +349,7 @@ void
27538  prepare_execute_command (void)
27539  {
27540    free_all_values ();
27541 +  free_all_types ();
27542  
27543    /* With multiple threads running while the one we're examining is stopped,
27544       the dcache can get stale without us being able to detect it.
27545 diff --git a/gdb/typeprint.c b/gdb/typeprint.c
27546 index f090231..fc15ec1 100644
27547 --- a/gdb/typeprint.c
27548 +++ b/gdb/typeprint.c
27549 @@ -35,6 +35,8 @@
27550  #include "gdb_string.h"
27551  #include "exceptions.h"
27552  #include "valprint.h"
27553 +#include "dwarf2loc.h"
27554 +
27555  #include <errno.h>
27556  
27557  extern void _initialize_typeprint (void);
27558 @@ -76,6 +78,9 @@ void
27559  type_print (struct type *type, char *varstring, struct ui_file *stream,
27560             int show)
27561  {
27562 +  if (show >= 0)
27563 +    type = check_typedef (type);
27564 +
27565    LA_PRINT_TYPE (type, varstring, stream, show, 0);
27566  }
27567  
27568 @@ -114,7 +119,8 @@ whatis_exp (char *exp, int show)
27569  {
27570    struct expression *expr;
27571    struct value *val;
27572 -  struct cleanup *old_chain = NULL;
27573 +  /* Required at least for the object_address_set call.  */
27574 +  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
27575    struct type *real_type = NULL;
27576    struct type *type;
27577    int full = 0;
27578 @@ -125,12 +131,13 @@ whatis_exp (char *exp, int show)
27579    if (exp)
27580      {
27581        expr = parse_expression (exp);
27582 -      old_chain = make_cleanup (free_current_contents, &expr);
27583 +      make_cleanup (free_current_contents, &expr);
27584        val = evaluate_type (expr);
27585      }
27586    else
27587      val = access_value_history (0);
27588  
27589 +  object_address_set (value_raw_address (val));
27590    type = value_type (val);
27591  
27592    get_user_print_options (&opts);
27593 @@ -167,8 +174,7 @@ whatis_exp (char *exp, int show)
27594    type_print (type, "", gdb_stdout, show);
27595    printf_filtered ("\n");
27596  
27597 -  if (exp)
27598 -    do_cleanups (old_chain);
27599 +  do_cleanups (old_chain);
27600  }
27601  
27602  static void
27603 diff --git a/gdb/typeprint.h b/gdb/typeprint.h
27604 index f561310..d261c79 100644
27605 --- a/gdb/typeprint.h
27606 +++ b/gdb/typeprint.h
27607 @@ -20,10 +20,13 @@
27608  #ifndef TYPEPRINT_H
27609  #define TYPEPRINT_H
27610  
27611 +enum language;
27612  struct ui_file;
27613  
27614  void print_type_scalar (struct type * type, LONGEST, struct ui_file *);
27615  
27616  void c_type_print_varspec_suffix (struct type *, struct ui_file *, int,
27617                                   int, int);
27618 +
27619 +void c_type_print_args (struct type *, struct ui_file *, int, enum language);
27620  #endif
27621 diff --git a/gdb/ui-file.c b/gdb/ui-file.c
27622 index 527917c..07d959a 100644
27623 --- a/gdb/ui-file.c
27624 +++ b/gdb/ui-file.c
27625 @@ -22,6 +22,7 @@
27626  
27627  #include "defs.h"
27628  #include "ui-file.h"
27629 +#include "gdb_obstack.h"
27630  #include "gdb_string.h"
27631  
27632  #include <errno.h>
27633 @@ -263,7 +264,7 @@ set_ui_file_data (struct ui_file *file, void *data,
27634  }
27635  
27636  /* ui_file utility function for converting a ``struct ui_file'' into
27637 -   a memory buffer''. */
27638 +   a memory buffer. */
27639  
27640  struct accumulated_ui_file
27641  {
27642 @@ -297,6 +298,23 @@ ui_file_xstrdup (struct ui_file *file, long *length)
27643      *length = acc.length;
27644    return acc.buffer;
27645  }
27646 +
27647 +static void
27648 +do_ui_file_obsavestring (void *context, const char *buffer, long length)
27649 +{
27650 +  struct obstack *obstack = (struct obstack *) context;
27651 +  obstack_grow (obstack, buffer, length);
27652 +}
27653 +
27654 +char *
27655 +ui_file_obsavestring (struct ui_file *file, struct obstack *obstack,
27656 +                     long *length)
27657 +{
27658 +  ui_file_put (file, do_ui_file_obsavestring, obstack);
27659 +  *length = obstack_object_size (obstack);
27660 +  obstack_1grow (obstack, '\0');
27661 +  return obstack_finish (obstack);
27662 +}
27663  \f
27664  /* A pure memory based ``struct ui_file'' that can be used an output
27665     buffer. The buffers accumulated contents are available via
27666 diff --git a/gdb/ui-file.h b/gdb/ui-file.h
27667 index bf9915c..233206c 100644
27668 --- a/gdb/ui-file.h
27669 +++ b/gdb/ui-file.h
27670 @@ -19,6 +19,7 @@
27671  #ifndef UI_FILE_H
27672  #define UI_FILE_H
27673  
27674 +struct obstack;
27675  struct ui_file;
27676  
27677  /* Create a generic ui_file object with null methods. */
27678 @@ -77,7 +78,10 @@ extern void ui_file_put (struct ui_file *src, ui_file_put_method_ftype *write, v
27679     minus that appended NUL. */
27680  extern char *ui_file_xstrdup (struct ui_file *file, long *length);
27681  
27682 -
27683 +/* Similar to ui_file_xstrdup, but return a new string allocated on
27684 +   OBSTACK.  */
27685 +extern char *ui_file_obsavestring (struct ui_file *file,
27686 +                                  struct obstack *obstack, long *length);
27687  
27688  extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
27689  
27690 diff --git a/gdb/utils.c b/gdb/utils.c
27691 index 16ad084..3021a43 100644
27692 --- a/gdb/utils.c
27693 +++ b/gdb/utils.c
27694 @@ -2610,7 +2610,10 @@ fprintf_symbol_filtered (struct ui_file *stream, char *name,
27695     As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
27696     This "feature" is useful when searching for matching C++ function names
27697     (such as if the user types 'break FOO', where FOO is a mangled C++
27698 -   function). */
27699 +   function).
27700 +
27701 +   As an extra-special hack, we do the same with ' ', so that
27702 +   "FOO(ARGS) const" can match "FOO", too.  */
27703  
27704  int
27705  strcmp_iw (const char *string1, const char *string2)
27706 @@ -2635,7 +2638,7 @@ strcmp_iw (const char *string1, const char *string2)
27707           string2++;
27708         }
27709      }
27710 -  return (*string1 != '\0' && *string1 != '(') || (*string2 != '\0');
27711 +  return (*string1 != ' ' && *string1 != '\0' && *string1 != '(') || (*string2 != '\0' && *string2 != '(');
27712  }
27713  
27714  /* This is like strcmp except that it ignores whitespace and treats
27715 diff --git a/gdb/valarith.c b/gdb/valarith.c
27716 index a9c875d..12f6f07 100644
27717 --- a/gdb/valarith.c
27718 +++ b/gdb/valarith.c
27719 @@ -139,7 +139,6 @@ an integer nor a pointer of the same type."));
27720  struct value *
27721  value_subscript (struct value *array, LONGEST index)
27722  {
27723 -  struct value *bound;
27724    int c_style = current_language->c_style_arrays;
27725    struct type *tarray;
27726  
27727 @@ -154,12 +153,26 @@ value_subscript (struct value *array, LONGEST index)
27728        get_discrete_bounds (range_type, &lowerbound, &upperbound);
27729  
27730        if (VALUE_LVAL (array) != lval_memory)
27731 -       return value_subscripted_rvalue (array, index, lowerbound);
27732 +       {
27733 +         if (index >= lowerbound && index <= upperbound)
27734 +           {
27735 +             CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
27736 +             CORE_ADDR offset = (index - lowerbound) * element_size;
27737 +
27738 +             return value_subscripted_rvalue (array, offset);
27739 +           }
27740 +         error (_("array or string index out of range"));
27741 +       }
27742  
27743        if (c_style == 0)
27744         {
27745           if (index >= lowerbound && index <= upperbound)
27746 -           return value_subscripted_rvalue (array, index, lowerbound);
27747 +           {
27748 +             CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
27749 +             CORE_ADDR offset = (index - lowerbound) * element_size;
27750 +
27751 +             return value_subscripted_rvalue (array, offset);
27752 +           }
27753           /* Emit warning unless we have an array of unknown size.
27754              An array of unknown size has lowerbound 0 and upperbound -1.  */
27755           if (upperbound > -1)
27756 @@ -178,33 +191,37 @@ value_subscript (struct value *array, LONGEST index)
27757      error (_("not an array or string"));
27758  }
27759  
27760 -/* Return the value of EXPR[IDX], expr an aggregate rvalue
27761 -   (eg, a vector register).  This routine used to promote floats
27762 -   to doubles, but no longer does.  */
27763 +/* Return the value of *((void *) ARRAY + ELEMENT), ARRAY an aggregate rvalue
27764 +   (eg, a vector register).  This routine used to promote floats to doubles,
27765 +   but no longer does.  OFFSET is zero-based with 0 for the lowermost existing
27766 +   element, it must be expressed in bytes (therefore multiplied by
27767 +   check_typedef (TYPE_TARGET_TYPE (array_type)).  */
27768  
27769  struct value *
27770 -value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
27771 +value_subscripted_rvalue (struct value *array, CORE_ADDR offset)
27772  {
27773    struct type *array_type = check_typedef (value_type (array));
27774    struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
27775 -  unsigned int elt_size = TYPE_LENGTH (elt_type);
27776 -  unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
27777    struct value *v;
27778  
27779 -  if (index < lowerbound || elt_offs >= TYPE_LENGTH (array_type))
27780 -    error (_("no such vector element"));
27781 +  /* Do not check TYPE_LENGTH (array_type) as we may have been given the
27782 +     innermost dimension of a multi-dimensional Fortran array where its length
27783 +     is shorter than the possibly accessed element offset.  */
27784  
27785    v = allocate_value (elt_type);
27786    if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
27787      set_value_lazy (v, 1);
27788    else
27789 -    memcpy (value_contents_writeable (v),
27790 -           value_contents (array) + elt_offs, elt_size);
27791 +    {
27792 +      unsigned int elt_size = TYPE_LENGTH (elt_type);
27793 +      memcpy (value_contents_writeable (v),
27794 +             value_contents (array) + offset, elt_size);
27795 +    }
27796  
27797    set_value_component_location (v, array);
27798    VALUE_REGNUM (v) = VALUE_REGNUM (array);
27799    VALUE_FRAME_ID (v) = VALUE_FRAME_ID (array);
27800 -  set_value_offset (v, value_offset (array) + elt_offs);
27801 +  set_value_offset (v, value_offset (array) + offset);
27802    return v;
27803  }
27804  
27805 diff --git a/gdb/valops.c b/gdb/valops.c
27806 index b64cb21..b7d31cc 100644
27807 --- a/gdb/valops.c
27808 +++ b/gdb/valops.c
27809 @@ -38,6 +38,7 @@
27810  #include "cp-support.h"
27811  #include "dfp.h"
27812  #include "user-regs.h"
27813 +#include "dwarf2loc.h"
27814  
27815  #include <errno.h>
27816  #include "gdb_string.h"
27817 @@ -369,8 +370,6 @@ value_cast (struct type *type, struct value *arg2)
27818           new_length = val_length / element_length;
27819           if (val_length % element_length != 0)
27820             warning (_("array element type size does not divide object size in cast"));
27821 -         /* FIXME-type-allocation: need a way to free this type when
27822 -            we are done with it.  */
27823           range_type = create_range_type ((struct type *) NULL,
27824                                           TYPE_TARGET_TYPE (range_type),
27825                                           low_bound,
27826 @@ -565,6 +564,64 @@ value_one (struct type *type, enum lval_type lv)
27827    return val;
27828  }
27829  
27830 +/* object_address_set must be already called before this function.  */
27831 +
27832 +const char *
27833 +object_address_data_not_valid (struct type *type)
27834 +{
27835 +  /* Attributes are present only at the target type of a typedef.  Make the
27836 +     call conditional as it would otherwise loop through type_length_get.  */
27837 +  if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
27838 +    CHECK_TYPEDEF (type);
27839 +
27840 +  /* DW_AT_associated has a preference over DW_AT_allocated.  */
27841 +  if (TYPE_NOT_ASSOCIATED (type)
27842 +      || (TYPE_ASSOCIATED (type) != NULL
27843 +         && 0 == dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (type))))
27844 +    return N_("object is not associated");
27845 +
27846 +  if (TYPE_NOT_ALLOCATED (type)
27847 +      || (TYPE_ALLOCATED (type) != NULL
27848 +         && 0 == dwarf_locexpr_baton_eval (TYPE_ALLOCATED (type))))
27849 +    return N_("object is not allocated");
27850 +
27851 +  return NULL;
27852 +}
27853 +
27854 +/* Return non-zero if the variable is valid.  If it is valid the function
27855 +   may store the data address (DW_AT_DATA_LOCATION) of TYPE at *ADDRESS_RETURN.
27856 +   You must set *ADDRESS_RETURN from value_raw_address (VAL) before calling this
27857 +   function.  If no DW_AT_DATA_LOCATION is present for TYPE the address at
27858 +   *ADDRESS_RETURN is left unchanged.  ADDRESS_RETURN must not be NULL, use
27859 +   object_address_data_not_valid () for just the data validity check.  */
27860 +
27861 +int
27862 +object_address_get_data (struct type *type, CORE_ADDR *address_return)
27863 +{
27864 +  gdb_assert (address_return != NULL);
27865 +
27866 +  object_address_set (*address_return);
27867 +
27868 +  /* TYPE_DATA_LOCATION_DWARF_BLOCK / TYPE_DATA_LOCATION_ADDR are present only
27869 +     at the target type of a typedef.  */
27870 +  CHECK_TYPEDEF (type);
27871 +
27872 +  if (object_address_data_not_valid (type) != NULL)
27873 +    {
27874 +      /* Do not try to evaluate DW_AT_data_location as it may even crash
27875 +        (it would just return the value zero in the gfortran case).  */
27876 +      return 0;
27877 +    }
27878 +
27879 +  if (TYPE_DATA_LOCATION_IS_ADDR (type))
27880 +    *address_return = TYPE_DATA_LOCATION_ADDR (type);
27881 +  else if (TYPE_DATA_LOCATION_DWARF_BLOCK (type) != NULL)
27882 +    *address_return
27883 +      = dwarf_locexpr_baton_eval (TYPE_DATA_LOCATION_DWARF_BLOCK (type));
27884 +
27885 +  return 1;
27886 +}
27887 +
27888  /* Helper function for value_at, value_at_lazy, and value_at_lazy_stack.  */
27889  
27890  static struct value *
27891 @@ -656,15 +713,21 @@ value_fetch_lazy (struct value *val)
27892      }
27893    else if (VALUE_LVAL (val) == lval_memory)
27894      {
27895 -      CORE_ADDR addr = value_address (val);
27896 -      int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
27897 +      CORE_ADDR addr = value_raw_address (val);
27898  
27899 -      if (length)
27900 +      if (object_address_get_data (value_type (val), &addr))
27901         {
27902 -         if (value_stack (val))
27903 -           read_stack (addr, value_contents_all_raw (val), length);
27904 -         else
27905 -           read_memory (addr, value_contents_all_raw (val), length);
27906 +         struct type *type = value_enclosing_type (val);
27907 +         int length = TYPE_LENGTH (check_typedef (type));
27908 +
27909 +         if (length)
27910 +           {
27911 +             addr += value_offset (val);
27912 +             if (value_stack (val))
27913 +               read_stack (addr, value_contents_all_raw (val), length);
27914 +             else
27915 +               read_memory (addr, value_contents_all_raw (val), length);
27916 +           }
27917         }
27918      }
27919    else if (VALUE_LVAL (val) == lval_register)
27920 @@ -1070,7 +1133,18 @@ address_of_variable (struct symbol *var, struct block *b)
27921    if ((VALUE_LVAL (val) == lval_memory && value_lazy (val))
27922        || TYPE_CODE (type) == TYPE_CODE_FUNC)
27923      {
27924 -      CORE_ADDR addr = value_address (val);
27925 +      CORE_ADDR addr;
27926 +
27927 +      if (VALUE_LVAL (val) == lval_memory)
27928 +       {
27929 +         addr = value_raw_address (val);
27930 +         if (!object_address_get_data (type, &addr))
27931 +           error (_("Can't take address of memory lvalue \"%s\"."),
27932 +                  SYMBOL_PRINT_NAME (var));
27933 +         set_value_address (val, addr);
27934 +       }
27935 +
27936 +      addr = value_address (val);
27937        return value_from_pointer (lookup_pointer_type (type), addr);
27938      }
27939  
27940 @@ -1176,6 +1250,7 @@ struct value *
27941  value_coerce_array (struct value *arg1)
27942  {
27943    struct type *type = check_typedef (value_type (arg1));
27944 +  CORE_ADDR address;
27945  
27946    /* If the user tries to do something requiring a pointer with an
27947       array that has not yet been pushed to the target, then this would
27948 @@ -1185,8 +1260,12 @@ value_coerce_array (struct value *arg1)
27949    if (VALUE_LVAL (arg1) != lval_memory)
27950      error (_("Attempt to take address of value not located in memory."));
27951  
27952 +  address = value_raw_address (arg1);
27953 +  if (!object_address_get_data (type, &address))
27954 +    error (_("Attempt to take address of non-valid value."));
27955 +
27956    return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
27957 -                            value_address (arg1));
27958 +                            address + value_offset (arg1));
27959  }
27960  
27961  /* Given a value which is a function, return a value which is a pointer
27962 @@ -2069,12 +2148,25 @@ find_overload_match (struct type **arg_types, int nargs,
27963    if (method)
27964      {
27965        gdb_assert (obj);
27966 +
27967 +      /* OBJ may be a pointer value rather than the object itself.  */
27968 +      obj = coerce_ref (obj);
27969 +      while (TYPE_CODE (check_typedef (value_type (obj))) == TYPE_CODE_PTR)
27970 +       obj = coerce_ref (value_ind (obj));
27971        obj_type_name = TYPE_NAME (value_type (obj));
27972 -      /* Hack: evaluate_subexp_standard often passes in a pointer
27973 -         value rather than the object itself, so try again.  */
27974 -      if ((!obj_type_name || !*obj_type_name) 
27975 -         && (TYPE_CODE (value_type (obj)) == TYPE_CODE_PTR))
27976 -       obj_type_name = TYPE_NAME (TYPE_TARGET_TYPE (value_type (obj)));
27977 +
27978 +      /* First check whether this is a data member, e.g. a pointer to
27979 +        a function.  */
27980 +      if (TYPE_CODE (check_typedef (value_type (obj))) == TYPE_CODE_STRUCT)
27981 +       {
27982 +         *valp = search_struct_field (name, obj, 0,
27983 +                                      check_typedef (value_type (obj)), 0);
27984 +         if (*valp)
27985 +           {
27986 +             *staticp = 1;
27987 +             return 0;
27988 +           }
27989 +       }
27990  
27991        fns_ptr = value_find_oload_method_list (&temp, name, 
27992                                               0, &num_fns, 
27993 @@ -2094,16 +2186,29 @@ find_overload_match (struct type **arg_types, int nargs,
27994      }
27995    else
27996      {
27997 -      const char *qualified_name = SYMBOL_CPLUS_DEMANGLED_NAME (fsym);
27998 +      const char *qualified_name = SYMBOL_NATURAL_NAME (fsym);
27999 +
28000 +      /* If we have a function with a C++ name, try to extract just
28001 +        the function part.  Do not try this for non-functions (e.g.
28002 +        function pointers).  */
28003 +      if (qualified_name
28004 +         && TYPE_CODE (check_typedef (SYMBOL_TYPE (fsym))) == TYPE_CODE_FUNC)
28005 +       {
28006 +         func_name = cp_func_name (qualified_name);
28007  
28008 -      /* If we have a C++ name, try to extract just the function
28009 -        part.  */
28010 -      if (qualified_name)
28011 -       func_name = cp_func_name (qualified_name);
28012 +         /* If cp_func_name did not remove anything, the name of the
28013 +            symbol did not include scope or argument types - it was
28014 +            probably a C-style function.  */
28015 +         if (func_name && strcmp (func_name, qualified_name) == 0)
28016 +           {
28017 +             xfree (func_name);
28018 +             func_name = NULL;
28019 +           }
28020 +       }
28021  
28022 -      /* If there was no C++ name, this must be a C-style function.
28023 -        Just return the same symbol.  Do the same if cp_func_name
28024 -        fails for some reason.  */
28025 +      /* If there was no C++ name, this must be a C-style function or
28026 +        not a function at all.  Just return the same symbol.  Do the
28027 +        same if cp_func_name fails for some reason.  */
28028        if (func_name == NULL)
28029          {
28030           *symp = fsym;
28031 @@ -2534,8 +2639,8 @@ check_field (struct type *type, const char *name)
28032     the comment before value_struct_elt_for_reference.  */
28033  
28034  struct value *
28035 -value_aggregate_elt (struct type *curtype,
28036 -                    char *name, int want_address,
28037 +value_aggregate_elt (struct type *curtype, char *name,
28038 +                    struct type *expect_type, int want_address,
28039                      enum noside noside)
28040  {
28041    switch (TYPE_CODE (curtype))
28042 @@ -2543,7 +2648,7 @@ value_aggregate_elt (struct type *curtype,
28043      case TYPE_CODE_STRUCT:
28044      case TYPE_CODE_UNION:
28045        return value_struct_elt_for_reference (curtype, 0, curtype, 
28046 -                                            name, NULL,
28047 +                                            name, expect_type,
28048                                              want_address, noside);
28049      case TYPE_CODE_NAMESPACE:
28050        return value_namespace_elt (curtype, name, 
28051 @@ -2554,6 +2659,56 @@ value_aggregate_elt (struct type *curtype,
28052      }
28053  }
28054  
28055 +/* Compares the two method/function types T1 and T2 for "equality" 
28056 +   with respect to the the methods' parameters. If the types of the
28057 +   two parameter lists are the same, returns 1; 0 otherwise. This
28058 +   comparison may ignore any artificial parameters in T1 if
28059 +   SKIP_ARTIFICIAL is non-zero. This function will ALWAYS skip
28060 +   the first artificial parameter in T1, assumed to be a 'this' pointer.
28061 +
28062 +   The type T2 is expected to have come from make_params (in eval.c). */
28063 +static int
28064 +compare_parameters (struct type *t1, struct type *t2, int skip_artificial)
28065 +{
28066 +  int start = 0;
28067 +
28068 +  if (TYPE_FIELD_ARTIFICIAL (t1, 0))
28069 +    ++start;
28070 +
28071 +  /* If skipping artificial fields, find the first real field
28072 +     in T1. */
28073 +  if (skip_artificial)
28074 +    {
28075 +      while (start < TYPE_NFIELDS (t1)
28076 +            && TYPE_FIELD_ARTIFICIAL (t1, start))
28077 +       ++start;
28078 +    }
28079 +
28080 +  /* Now compare parameters */
28081 +
28082 +  /* Special case: a method taking void. T1 will contain no
28083 +     non-artificial fields, and T2 will contain TYPE_CODE_VOID. */
28084 +  if ((TYPE_NFIELDS (t1) - start) == 0 && TYPE_NFIELDS (t2) == 1
28085 +      && TYPE_CODE (TYPE_FIELD_TYPE (t2, 0)) == TYPE_CODE_VOID)
28086 +    return 1;
28087 +
28088 +  if ((TYPE_NFIELDS (t1) - start) == TYPE_NFIELDS (t2))
28089 +    {
28090 +      int i;
28091 +      for (i = 0; i < TYPE_NFIELDS (t2); ++i)
28092 +       {
28093 +         if (rank_one_type (TYPE_FIELD_TYPE (t1, start + i),
28094 +                             TYPE_FIELD_TYPE (t2, i))
28095 +             != 0)
28096 +           return 0;
28097 +       }
28098 +
28099 +      return 1;
28100 +    }
28101 +
28102 +  return 0;
28103 +}
28104 +
28105  /* C++: Given an aggregate type CURTYPE, and a member name NAME,
28106     return the address of this member as a "pointer to member" type.
28107     If INTYPE is non-null, then it will be the type of the member we
28108 @@ -2631,23 +2786,46 @@ value_struct_elt_for_reference (struct type *domain, int offset,
28109         }
28110        if (t_field_name && strcmp (t_field_name, name) == 0)
28111         {
28112 -         int j = TYPE_FN_FIELDLIST_LENGTH (t, i);
28113 +         int j;
28114 +         int len = TYPE_FN_FIELDLIST_LENGTH (t, i);
28115           struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
28116  
28117           check_stub_method_group (t, i);
28118  
28119 -         if (intype == 0 && j > 1)
28120 -           error (_("non-unique member `%s' requires type instantiation"), name);
28121           if (intype)
28122             {
28123 -             while (j--)
28124 -               if (TYPE_FN_FIELD_TYPE (f, j) == intype)
28125 -                 break;
28126 -             if (j < 0)
28127 -               error (_("no member function matches that type instantiation"));
28128 -           }
28129 +             for (j = 0; j < len; ++j)
28130 +               {
28131 +                 if (compare_parameters (TYPE_FN_FIELD_TYPE (f, j), intype, 0)
28132 +                     || compare_parameters (TYPE_FN_FIELD_TYPE (f, j), intype, 1))
28133 +                   break;
28134 +               }
28135 +
28136 +             if (j == len)
28137 +               error (_("no member function matches that type instantiation"));            }
28138           else
28139 -           j = 0;
28140 +           {
28141 +             int ii;
28142 +             /* Skip artificial methods. This is necessary if, for example,
28143 +                the user wants to "print subclass::subclass" with only
28144 +                one defined user constructor. There is no ambiguity in this
28145 +                case. */
28146 +             for (ii = 0; ii < TYPE_FN_FIELDLIST_LENGTH (t, i);
28147 +                  ++ii)
28148 +               {
28149 +                 if (TYPE_FN_FIELD_ARTIFICIAL (f, ii))
28150 +                   --len;
28151 +               }
28152 +
28153 +             /* Desired method is ambiguous if more than one method is
28154 +                defined. */
28155 +             if (len > 1)
28156 +               error (_("non-unique member `%s' requires type instantiation"), name);
28157 +
28158 +             /* This assumes, of course, that all artificial methods appear
28159 +                BEFORE any concrete methods. */
28160 +             j = TYPE_FN_FIELDLIST_LENGTH (t, i) - 1;
28161 +           }
28162  
28163           if (TYPE_FN_FIELD_STATIC_P (f, j))
28164             {
28165 @@ -2761,7 +2939,7 @@ value_maybe_namespace_elt (const struct type *curtype,
28166    struct symbol *sym;
28167    struct value *result;
28168  
28169 -  sym = cp_lookup_symbol_namespace (namespace_name, name, NULL,
28170 +  sym = cp_lookup_symbol_namespace(namespace_name, name,
28171                                     get_selected_block (0), 
28172                                     VAR_DOMAIN);
28173  
28174 @@ -2905,7 +3083,7 @@ value_of_local (const char *name, int complain)
28175  
28176    /* Calling lookup_block_symbol is necessary to get the LOC_REGISTER
28177       symbol instead of the LOC_ARG one (if both exist).  */
28178 -  sym = lookup_block_symbol (b, name, NULL, VAR_DOMAIN);
28179 +  sym = lookup_block_symbol (b, name, VAR_DOMAIN);
28180    if (sym == NULL)
28181      {
28182        if (complain)
28183 @@ -2959,8 +3137,6 @@ value_slice (struct value *array, int lowbound, int length)
28184        || lowbound + length - 1 > upperbound)
28185      error (_("slice out of range"));
28186  
28187 -  /* FIXME-type-allocation: need a way to free this type when we are
28188 -     done with it.  */
28189    slice_range_type = create_range_type ((struct type *) NULL,
28190                                         TYPE_TARGET_TYPE (range_type),
28191                                         lowbound, 
28192 diff --git a/gdb/valprint.c b/gdb/valprint.c
28193 index cbb5d94..f9634ea 100644
28194 --- a/gdb/valprint.c
28195 +++ b/gdb/valprint.c
28196 @@ -236,7 +236,6 @@ scalar_type_p (struct type *type)
28197      case TYPE_CODE_STRUCT:
28198      case TYPE_CODE_UNION:
28199      case TYPE_CODE_SET:
28200 -    case TYPE_CODE_STRING:
28201      case TYPE_CODE_BITSTRING:
28202        return 0;
28203      default:
28204 @@ -1153,6 +1152,7 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
28205  
28206    for (; i < len && things_printed < options->print_max; i++)
28207      {
28208 +      size_t elt_offset = i * eltlen;
28209        if (i != 0)
28210         {
28211           if (options->prettyprint_arrays)
28212 @@ -1172,7 +1172,7 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
28213        rep1 = i + 1;
28214        reps = 1;
28215        while ((rep1 < len) &&
28216 -            !memcmp (valaddr + i * eltlen, valaddr + rep1 * eltlen, eltlen))
28217 +            !memcmp (valaddr + elt_offset, valaddr + rep1 * eltlen, eltlen))
28218         {
28219           ++reps;
28220           ++rep1;
28221 diff --git a/gdb/value.c b/gdb/value.c
28222 index 589e03b..66013b7 100644
28223 --- a/gdb/value.c
28224 +++ b/gdb/value.c
28225 @@ -37,8 +37,10 @@
28226  #include "block.h"
28227  #include "dfp.h"
28228  #include "objfiles.h"
28229 +#include "cli/cli-decode.h"
28230  #include "valprint.h"
28231  #include "cli/cli-decode.h"
28232 +#include "observer.h"
28233  
28234  #include "python/python.h"
28235  
28236 @@ -170,6 +172,14 @@ struct value
28237       taken off this list.  */
28238    struct value *next;
28239  
28240 +  /* The reference count.  A value that is still on the `all_values'
28241 +     list will have a reference count of 0.  A call to `release_value'
28242 +     will increment the reference count (and remove the value from the
28243 +     list, the first time).  A call to `value_free' will decrement the
28244 +     reference count, and will free the value when there are no more
28245 +     references.  */
28246 +  int refcount;
28247 +
28248    /* Register number if the value is from a register.  */
28249    short regnum;
28250  
28251 @@ -261,7 +271,9 @@ allocate_value_lazy (struct type *type)
28252    val->next = all_values;
28253    all_values = val;
28254    val->type = type;
28255 +  type_incref (type);
28256    val->enclosing_type = type;
28257 +  type_incref (type);
28258    VALUE_LVAL (val) = not_lval;
28259    val->location.address = 0;
28260    VALUE_FRAME_ID (val) = null_frame_id;
28261 @@ -346,6 +358,8 @@ value_type (struct value *value)
28262  void
28263  deprecated_set_value_type (struct value *value, struct type *type)
28264  {
28265 +  type_incref (type);
28266 +  type_decref (value->type);
28267    value->type = type;
28268  }
28269  
28270 @@ -624,6 +638,9 @@ value_free (struct value *val)
28271        if (val->parent != NULL)
28272         value_free (val->parent);
28273  
28274 +      type_decref (val->type);
28275 +      type_decref (val->enclosing_type);
28276 +
28277        if (VALUE_LVAL (val) == lval_computed)
28278         {
28279           struct lval_funcs *funcs = val->location.computed.funcs;
28280 @@ -728,6 +745,9 @@ value_copy (struct value *arg)
28281      val = allocate_value_lazy (encl_type);
28282    else
28283      val = allocate_value (encl_type);
28284 +
28285 +  type_incref (arg->type);
28286 +  type_decref (val->type);
28287    val->type = arg->type;
28288    VALUE_LVAL (val) = VALUE_LVAL (arg);
28289    val->location = arg->location;
28290 @@ -763,12 +783,15 @@ value_copy (struct value *arg)
28291  void
28292  set_value_component_location (struct value *component, struct value *whole)
28293  {
28294 +  CORE_ADDR addr;
28295 +
28296    if (VALUE_LVAL (whole) == lval_internalvar)
28297      VALUE_LVAL (component) = lval_internalvar_component;
28298    else
28299      VALUE_LVAL (component) = VALUE_LVAL (whole);
28300  
28301    component->location = whole->location;
28302 +
28303    if (VALUE_LVAL (whole) == lval_computed)
28304      {
28305        struct lval_funcs *funcs = whole->location.computed.funcs;
28306 @@ -776,6 +799,10 @@ set_value_component_location (struct value *component, struct value *whole)
28307        if (funcs->copy_closure)
28308          component->location.computed.closure = funcs->copy_closure (whole);
28309      }
28310 +
28311 +  addr = value_raw_address (component);
28312 +  object_address_get_data (value_type (whole), &addr);
28313 +  set_value_address (component, addr);
28314  }
28315  
28316  \f
28317 @@ -906,6 +933,29 @@ show_values (char *num_exp, int from_tty)
28318        num_exp[1] = '\0';
28319      }
28320  }
28321 +
28322 +/* Sanity check for memory leaks and proper types reference counting.  */
28323 +
28324 +static void
28325 +value_history_cleanup (void *unused)
28326 +{
28327 +  while (value_history_chain)
28328 +    {
28329 +      struct value_history_chunk *chunk = value_history_chain;
28330 +      int i;
28331 +
28332 +      for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
28333 +       value_free (chunk->values[i]);
28334 +
28335 +      value_history_chain = chunk->next;
28336 +      xfree (chunk);
28337 +    }
28338 +  value_history_count = 0;
28339 +
28340 +  /* Free the unreferenced types above.  */
28341 +  free_all_values ();
28342 +  free_all_types ();
28343 +}
28344  \f
28345  /* Internal variables.  These are variables within the debugger
28346     that hold values assigned by debugger commands.
28347 @@ -1381,6 +1431,40 @@ call_internal_function (struct gdbarch *gdbarch,
28348    return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv);
28349  }
28350  
28351 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
28352 +
28353 +static void
28354 +value_types_mark_used (void)
28355 +{
28356 +  struct internalvar *var;
28357 +  struct value_history_chunk *chunk;
28358 +
28359 +  for (var = internalvars; var != NULL; var = var->next)
28360 +    switch (var->kind)
28361 +      {
28362 +      case INTERNALVAR_VALUE:
28363 +       type_mark_used (value_type (var->u.value));
28364 +       break;
28365 +
28366 +      case INTERNALVAR_INTEGER:
28367 +       type_mark_used (var->u.integer.type);
28368 +       break;
28369 +
28370 +      case INTERNALVAR_POINTER:
28371 +       type_mark_used (var->u.pointer.type);
28372 +       break;
28373 +      }
28374 +
28375 +  for (chunk = value_history_chain; chunk != NULL; chunk = chunk->next)
28376 +    {
28377 +      int i;
28378 +
28379 +      for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
28380 +       if (chunk->values[i])
28381 +         type_mark_used (value_type (chunk->values[i]));
28382 +    }
28383 +}
28384 +
28385  /* The 'function' command.  This does nothing -- it is just a
28386     placeholder to let "help function NAME" work.  This is also used as
28387     the implementation of the sub-command that is created when
28388 @@ -1428,11 +1512,10 @@ preserve_one_value (struct value *value, struct objfile *objfile,
28389                     htab_t copied_types)
28390  {
28391    if (TYPE_OBJFILE (value->type) == objfile)
28392 -    value->type = copy_type_recursive (objfile, value->type, copied_types);
28393 +    value->type = copy_type_recursive (value->type, copied_types);
28394  
28395    if (TYPE_OBJFILE (value->enclosing_type) == objfile)
28396 -    value->enclosing_type = copy_type_recursive (objfile,
28397 -                                                value->enclosing_type,
28398 +    value->enclosing_type = copy_type_recursive (value->enclosing_type,
28399                                                  copied_types);
28400  }
28401  
28402 @@ -1447,13 +1530,13 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
28403      case INTERNALVAR_INTEGER:
28404        if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
28405         var->u.integer.type
28406 -         = copy_type_recursive (objfile, var->u.integer.type, copied_types);
28407 +         = copy_type_recursive (var->u.integer.type, copied_types);
28408        break;
28409  
28410      case INTERNALVAR_POINTER:
28411        if (TYPE_OBJFILE (var->u.pointer.type) == objfile)
28412         var->u.pointer.type
28413 -         = copy_type_recursive (objfile, var->u.pointer.type, copied_types);
28414 +         = copy_type_recursive (var->u.pointer.type, copied_types);
28415        break;
28416  
28417      case INTERNALVAR_VALUE:
28418 @@ -1855,6 +1938,8 @@ value_change_enclosing_type (struct value *val, struct type *new_encl_type)
28419      val->contents =
28420        (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
28421  
28422 +  type_incref (new_encl_type);
28423 +  type_decref (val->enclosing_type);
28424    val->enclosing_type = new_encl_type;
28425    return val;
28426  }
28427 @@ -1919,6 +2004,8 @@ value_primitive_field (struct value *arg1, int offset,
28428           memcpy (value_contents_all_raw (v), value_contents_all_raw (arg1),
28429                   TYPE_LENGTH (value_enclosing_type (arg1)));
28430         }
28431 +      type_incref (type);
28432 +      type_decref (v->type);
28433        v->type = type;
28434        v->offset = value_offset (arg1);
28435        v->embedded_offset = (offset + value_embedded_offset (arg1)
28436 @@ -2177,6 +2264,42 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num)
28437  }
28438  
28439  
28440 +/* Pack NUM into BUF using a target format of TYPE.  */
28441 +
28442 +void
28443 +pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num)
28444 +{
28445 +  enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
28446 +  int len;
28447 +
28448 +  type = check_typedef (type);
28449 +  len = TYPE_LENGTH (type);
28450 +
28451 +  switch (TYPE_CODE (type))
28452 +    {
28453 +    case TYPE_CODE_INT:
28454 +    case TYPE_CODE_CHAR:
28455 +    case TYPE_CODE_ENUM:
28456 +    case TYPE_CODE_FLAGS:
28457 +    case TYPE_CODE_BOOL:
28458 +    case TYPE_CODE_RANGE:
28459 +    case TYPE_CODE_MEMBERPTR:
28460 +      store_unsigned_integer (buf, len, byte_order, num);
28461 +      break;
28462 +
28463 +    case TYPE_CODE_REF:
28464 +    case TYPE_CODE_PTR:
28465 +      store_typed_address (buf, type, (CORE_ADDR) num);
28466 +      break;
28467 +
28468 +    default:
28469 +      error (_("\
28470 +Unexpected type (%d) encountered for unsigned integer constant."),
28471 +            TYPE_CODE (type));
28472 +    }
28473 +}
28474 +
28475 +
28476  /* Convert C numbers into newly allocated values.  */
28477  
28478  struct value *
28479 @@ -2190,6 +2313,19 @@ value_from_longest (struct type *type, LONGEST num)
28480  }
28481  
28482  
28483 +/* Convert C unsigned numbers into newly allocated values.  */
28484 +
28485 +struct value *
28486 +value_from_ulongest (struct type *type, ULONGEST num)
28487 +{
28488 +  struct value *val = allocate_value (type);
28489 +
28490 +  pack_unsigned_long (value_contents_raw (val), type, num);
28491 +
28492 +  return val;
28493 +}
28494 +
28495 +
28496  /* Create a value representing a pointer of type TYPE to the address
28497     ADDR.  */
28498  struct value *
28499 @@ -2348,4 +2484,8 @@ VARIABLE is already initialized."));
28500    add_prefix_cmd ("function", no_class, function_command, _("\
28501  Placeholder command for showing help on convenience functions."),
28502                   &functionlist, "function ", 0, &cmdlist);
28503 +
28504 +  make_final_cleanup (value_history_cleanup, NULL);
28505 +
28506 +  observer_attach_mark_used (value_types_mark_used);
28507  }
28508 diff --git a/gdb/value.h b/gdb/value.h
28509 index 51e6960..48b30e4 100644
28510 --- a/gdb/value.h
28511 +++ b/gdb/value.h
28512 @@ -342,11 +342,16 @@ extern LONGEST unpack_field_as_long (struct type *type,
28513  extern void pack_long (gdb_byte *buf, struct type *type, LONGEST num);
28514  
28515  extern struct value *value_from_longest (struct type *type, LONGEST num);
28516 +extern struct value *value_from_ulongest (struct type *type, ULONGEST num);
28517  extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
28518  extern struct value *value_from_double (struct type *type, DOUBLEST num);
28519  extern struct value *value_from_decfloat (struct type *type,
28520                                           const gdb_byte *decbytes);
28521  
28522 +extern const char *object_address_data_not_valid (struct type *type);
28523 +extern int object_address_get_data (struct type *type,
28524 +                                   CORE_ADDR *address_return);
28525 +
28526  extern struct value *value_at (struct type *type, CORE_ADDR addr);
28527  extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
28528  
28529 @@ -436,6 +441,7 @@ extern struct value *value_struct_elt (struct value **argp,
28530  
28531  extern struct value *value_aggregate_elt (struct type *curtype,
28532                                           char *name,
28533 +                                         struct type *expect_type,
28534                                           int want_address,
28535                                           enum noside noside);
28536  
28537 @@ -681,7 +687,7 @@ extern struct value *value_allocate_space_in_inferior (int);
28538  extern struct value *value_of_local (const char *name, int complain);
28539  
28540  extern struct value *value_subscripted_rvalue (struct value *array,
28541 -                                              LONGEST index, int lowerbound);
28542 +                                              CORE_ADDR offset);
28543  
28544  /* User function handler.  */
28545  
28546 diff --git a/gdb/varobj.c b/gdb/varobj.c
28547 index 8f22156..8fe72ca 100644
28548 --- a/gdb/varobj.c
28549 +++ b/gdb/varobj.c
28550 @@ -26,6 +26,8 @@
28551  #include "gdbcmd.h"
28552  #include "block.h"
28553  #include "valprint.h"
28554 +#include "objfiles.h"
28555 +#include "parser-defs.h"
28556  
28557  #include "gdb_assert.h"
28558  #include "gdb_string.h"
28559 @@ -253,6 +255,8 @@ static void free_variable (struct varobj *var);
28560  
28561  static struct cleanup *make_cleanup_free_variable (struct varobj *var);
28562  
28563 +static struct cleanup *make_cleanup_uninstall_variable (struct varobj *var);
28564 +
28565  static struct type *get_type (struct varobj *var);
28566  
28567  static struct type *get_value_type (struct varobj *var);
28568 @@ -480,6 +484,8 @@ is_root_p (struct varobj *var)
28569  struct cleanup *
28570  varobj_ensure_python_env (struct varobj *var)
28571  {
28572 +  gdb_assert (var->root->is_valid);
28573 +
28574    return ensure_python_env (var->root->exp->gdbarch,
28575                             var->root->exp->language_defn);
28576  }
28577 @@ -651,6 +657,7 @@ varobj_create (char *objname,
28578           do_cleanups (old_chain);
28579           return NULL;
28580         }
28581 +      make_cleanup_uninstall_variable (var);
28582      }
28583  
28584    discard_cleanups (old_chain);
28585 @@ -821,7 +828,12 @@ varobj_get_display_hint (struct varobj *var)
28586    char *result = NULL;
28587  
28588  #if HAVE_PYTHON
28589 -  struct cleanup *back_to = varobj_ensure_python_env (var);
28590 +  struct cleanup *back_to;
28591 +  
28592 +  if (!var->root->is_valid)
28593 +    return NULL;
28594 +
28595 +  back_to = varobj_ensure_python_env (var);
28596  
28597    if (var->pretty_printer)
28598      result = gdbpy_get_display_hint (var->pretty_printer);
28599 @@ -2186,6 +2198,18 @@ make_cleanup_free_variable (struct varobj *var)
28600    return make_cleanup (do_free_variable_cleanup, var);
28601  }
28602  
28603 +static void
28604 +do_uninstall_variable_cleanup (void *var)
28605 +{
28606 +  uninstall_variable (var);
28607 +}
28608 +
28609 +static struct cleanup *
28610 +make_cleanup_uninstall_variable (struct varobj *var)
28611 +{
28612 +  return make_cleanup (do_uninstall_variable_cleanup, var);
28613 +}
28614 +
28615  /* This returns the type of the variable. It also skips past typedefs
28616     to return the real type of the variable.
28617  
28618 @@ -3442,6 +3466,19 @@ java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
28619    return cplus_value_of_variable (var, format);
28620  }
28621  
28622 +/* Iterate all the existing VAROBJs and call the FUNC callback for them with an
28623 +   arbitrary caller supplied DATA pointer.  */
28624 +
28625 +static void
28626 +all_varobjs (void (*func) (struct varobj *var, void *data), void *data)
28627 +{
28628 +  struct vlist **vlp, *vl;
28629 +
28630 +  for (vlp = varobj_table; vlp < varobj_table + VAROBJ_TABLE_SIZE; vlp++)
28631 +    for (vl = *vlp; vl != NULL; vl = vl->next)
28632 +      (*func) (vl->var, data);
28633 +}
28634 +
28635  /* Iterate all the existing _root_ VAROBJs and call the FUNC callback for them
28636     with an arbitrary caller supplied DATA pointer.  */
28637  
28638 @@ -3459,6 +3496,43 @@ all_root_varobjs (void (*func) (struct varobj *var, void *data), void *data)
28639        (*func) (var_root->rootvar, data);
28640      }
28641  }
28642 +
28643 +/* Helper for varobj_types_mark_used.  Call type_mark_used for any TYPEs
28644 +   referenced from this VAR.  */
28645 +
28646 +static void
28647 +varobj_types_mark_used_iter (struct varobj *var, void *unused)
28648 +{
28649 +  /* Even FLOATING or IS_INVALID VARs with non-NULL TYPE references will
28650 +     free them in free_variable.  Still EXP may also reference TYPEs
28651 +     but these belong to SYMBOLs which should be always associated with
28652 +     an OBJFILE (and therefore not useful to be type_mark_used).  */
28653 +
28654 +  type_mark_used (var->type);
28655 +  if (var->value)
28656 +    type_mark_used (value_type (var->value));
28657 +
28658 +  /* Check VAROBJROOTs only once during the varobj_types_mark_used pass.  */
28659 +
28660 +  if (var->root->rootvar == var)
28661 +    {
28662 +      if (var->root->exp)
28663 +       exp_types_mark_used (var->root->exp);
28664 +    }
28665 +}
28666 +
28667 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
28668 +
28669 +static void
28670 +varobj_types_mark_used (void)
28671 +{
28672 +  /* Check all the VAROBJs, even non-root ones.  Child VAROBJs can reference
28673 +     types from other OBJFILEs through TYPE_IS_OPAQUE resolutions by
28674 +     check_typedef.  Such types references will not be interconnected into the
28675 +     same TYPE_GROUP.  */
28676 +
28677 +  all_varobjs (varobj_types_mark_used_iter, NULL);
28678 +}
28679  \f
28680  extern void _initialize_varobj (void);
28681  void
28682 diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
28683 index c56ab86..dacf913 100644
28684 --- a/gdb/xcoffread.c
28685 +++ b/gdb/xcoffread.c
28686 @@ -3038,6 +3038,7 @@ static struct sym_fns xcoff_sym_fns =
28687    xcoff_new_init,              /* sym_new_init: init anything gbl to entire symtab */
28688    xcoff_symfile_init,          /* sym_init: read initial info, setup for sym_read() */
28689    xcoff_initial_scan,          /* sym_read: read a symbol file into symtab */
28690 +  NULL,                                /* sym_read_psymbols */
28691    xcoff_symfile_finish,                /* sym_finish: finished with file, cleanup */
28692    xcoff_symfile_offsets,       /* sym_offsets: xlate offsets ext->int form */
28693    default_symfile_segments,    /* sym_segments: Get segment information from
This page took 2.598736 seconds and 3 git commands to generate.